| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/test/base/ui_test_utils.h" | 5 #include "chrome/test/base/ui_test_utils.h" |
| 6 | 6 |
| 7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
| 8 #include <windows.h> | 8 #include <windows.h> |
| 9 #endif | 9 #endif |
| 10 | 10 |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 using content::RenderWidgetHost; | 88 using content::RenderWidgetHost; |
| 89 using content::Referrer; | 89 using content::Referrer; |
| 90 using content::WebContents; | 90 using content::WebContents; |
| 91 | 91 |
| 92 static const int kDefaultWsPort = 8880; | 92 static const int kDefaultWsPort = 8880; |
| 93 | 93 |
| 94 namespace ui_test_utils { | 94 namespace ui_test_utils { |
| 95 | 95 |
| 96 namespace { | 96 namespace { |
| 97 | 97 |
| 98 // Helper class to Quit the message loop only once. Subsequent calls to Quit |
| 99 // are ignored. |
| 100 class MessageLoopQuitter { |
| 101 public: |
| 102 MessageLoopQuitter() : did_quit_(false) { } |
| 103 void Quit() { |
| 104 if (did_quit_) |
| 105 return; |
| 106 did_quit_ = true; |
| 107 MessageLoopForUI::current()->QuitAfterPending(); |
| 108 } |
| 109 private: |
| 110 bool did_quit_; |
| 111 }; |
| 112 |
| 98 class DOMOperationObserver : public content::NotificationObserver, | 113 class DOMOperationObserver : public content::NotificationObserver, |
| 99 public content::WebContentsObserver { | 114 public content::WebContentsObserver { |
| 100 public: | 115 public: |
| 101 explicit DOMOperationObserver(RenderViewHost* render_view_host) | 116 explicit DOMOperationObserver(RenderViewHost* render_view_host) |
| 102 : content::WebContentsObserver( | 117 : content::WebContentsObserver( |
| 103 WebContents::FromRenderViewHost(render_view_host)), | 118 WebContents::FromRenderViewHost(render_view_host)), |
| 104 did_respond_(false) { | 119 did_respond_(false) { |
| 105 registrar_.Add(this, content::NOTIFICATION_DOM_OPERATION_RESPONSE, | 120 registrar_.Add(this, content::NOTIFICATION_DOM_OPERATION_RESPONSE, |
| 106 content::Source<RenderViewHost>(render_view_host)); | 121 content::Source<RenderViewHost>(render_view_host)); |
| 107 ui_test_utils::RunMessageLoop(); | 122 ui_test_utils::RunMessageLoop(); |
| 108 } | 123 } |
| 109 | 124 |
| 110 virtual void Observe(int type, | 125 virtual void Observe(int type, |
| 111 const content::NotificationSource& source, | 126 const content::NotificationSource& source, |
| 112 const content::NotificationDetails& details) OVERRIDE { | 127 const content::NotificationDetails& details) OVERRIDE { |
| 113 DCHECK(type == content::NOTIFICATION_DOM_OPERATION_RESPONSE); | 128 DCHECK(type == content::NOTIFICATION_DOM_OPERATION_RESPONSE); |
| 114 content::Details<DomOperationNotificationDetails> dom_op_details(details); | 129 content::Details<DomOperationNotificationDetails> dom_op_details(details); |
| 115 response_ = dom_op_details->json; | 130 response_ = dom_op_details->json; |
| 116 did_respond_ = true; | 131 did_respond_ = true; |
| 117 MessageLoopForUI::current()->Quit(); | 132 message_loop_quitter_.Quit(); |
| 118 } | 133 } |
| 119 | 134 |
| 120 // Overridden from content::WebContentsObserver: | 135 // Overridden from content::WebContentsObserver: |
| 121 virtual void RenderViewGone(base::TerminationStatus status) OVERRIDE { | 136 virtual void RenderViewGone(base::TerminationStatus status) OVERRIDE { |
| 122 MessageLoopForUI::current()->Quit(); | 137 message_loop_quitter_.Quit(); |
| 123 } | 138 } |
| 124 | 139 |
| 125 bool GetResponse(std::string* response) WARN_UNUSED_RESULT { | 140 bool GetResponse(std::string* response) WARN_UNUSED_RESULT { |
| 126 *response = response_; | 141 *response = response_; |
| 127 return did_respond_; | 142 return did_respond_; |
| 128 } | 143 } |
| 129 | 144 |
| 130 private: | 145 private: |
| 131 content::NotificationRegistrar registrar_; | 146 content::NotificationRegistrar registrar_; |
| 132 std::string response_; | 147 std::string response_; |
| 133 bool did_respond_; | 148 bool did_respond_; |
| 149 MessageLoopQuitter message_loop_quitter_; |
| 134 | 150 |
| 135 DISALLOW_COPY_AND_ASSIGN(DOMOperationObserver); | 151 DISALLOW_COPY_AND_ASSIGN(DOMOperationObserver); |
| 136 }; | 152 }; |
| 137 | 153 |
| 138 class FindInPageNotificationObserver : public content::NotificationObserver { | 154 class FindInPageNotificationObserver : public content::NotificationObserver { |
| 139 public: | 155 public: |
| 140 explicit FindInPageNotificationObserver(TabContentsWrapper* parent_tab) | 156 explicit FindInPageNotificationObserver(TabContentsWrapper* parent_tab) |
| 141 : parent_tab_(parent_tab), | 157 : parent_tab_(parent_tab), |
| 142 active_match_ordinal_(-1), | 158 active_match_ordinal_(-1), |
| 143 number_of_matches_(0) { | 159 number_of_matches_(0) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 156 const content::NotificationDetails& details) { | 172 const content::NotificationDetails& details) { |
| 157 if (type == chrome::NOTIFICATION_FIND_RESULT_AVAILABLE) { | 173 if (type == chrome::NOTIFICATION_FIND_RESULT_AVAILABLE) { |
| 158 content::Details<FindNotificationDetails> find_details(details); | 174 content::Details<FindNotificationDetails> find_details(details); |
| 159 if (find_details->request_id() == current_find_request_id_) { | 175 if (find_details->request_id() == current_find_request_id_) { |
| 160 // We get multiple responses and one of those will contain the ordinal. | 176 // We get multiple responses and one of those will contain the ordinal. |
| 161 // This message comes to us before the final update is sent. | 177 // This message comes to us before the final update is sent. |
| 162 if (find_details->active_match_ordinal() > -1) | 178 if (find_details->active_match_ordinal() > -1) |
| 163 active_match_ordinal_ = find_details->active_match_ordinal(); | 179 active_match_ordinal_ = find_details->active_match_ordinal(); |
| 164 if (find_details->final_update()) { | 180 if (find_details->final_update()) { |
| 165 number_of_matches_ = find_details->number_of_matches(); | 181 number_of_matches_ = find_details->number_of_matches(); |
| 166 MessageLoopForUI::current()->Quit(); | 182 message_loop_quitter_.Quit(); |
| 167 } else { | 183 } else { |
| 168 DVLOG(1) << "Ignoring, since we only care about the final message"; | 184 DVLOG(1) << "Ignoring, since we only care about the final message"; |
| 169 } | 185 } |
| 170 } | 186 } |
| 171 } else { | 187 } else { |
| 172 NOTREACHED(); | 188 NOTREACHED(); |
| 173 } | 189 } |
| 174 } | 190 } |
| 175 | 191 |
| 176 private: | 192 private: |
| 177 content::NotificationRegistrar registrar_; | 193 content::NotificationRegistrar registrar_; |
| 178 TabContentsWrapper* parent_tab_; | 194 TabContentsWrapper* parent_tab_; |
| 179 // We will at some point (before final update) be notified of the ordinal and | 195 // We will at some point (before final update) be notified of the ordinal and |
| 180 // we need to preserve it so we can send it later. | 196 // we need to preserve it so we can send it later. |
| 181 int active_match_ordinal_; | 197 int active_match_ordinal_; |
| 182 int number_of_matches_; | 198 int number_of_matches_; |
| 183 // The id of the current find request, obtained from WebContents. Allows us | 199 // The id of the current find request, obtained from WebContents. Allows us |
| 184 // to monitor when the search completes. | 200 // to monitor when the search completes. |
| 185 int current_find_request_id_; | 201 int current_find_request_id_; |
| 202 MessageLoopQuitter message_loop_quitter_; |
| 186 | 203 |
| 187 DISALLOW_COPY_AND_ASSIGN(FindInPageNotificationObserver); | 204 DISALLOW_COPY_AND_ASSIGN(FindInPageNotificationObserver); |
| 188 }; | 205 }; |
| 189 | 206 |
| 190 class InProcessJavaScriptExecutionController | 207 class InProcessJavaScriptExecutionController |
| 191 : public base::RefCounted<InProcessJavaScriptExecutionController>, | 208 : public base::RefCounted<InProcessJavaScriptExecutionController>, |
| 192 public JavaScriptExecutionController { | 209 public JavaScriptExecutionController { |
| 193 public: | 210 public: |
| 194 explicit InProcessJavaScriptExecutionController( | 211 explicit InProcessJavaScriptExecutionController( |
| 195 RenderViewHost* render_view_host) | 212 RenderViewHost* render_view_host) |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 result->reset(reader.ReadToValue(json)); | 272 result->reset(reader.ReadToValue(json)); |
| 256 if (!result->get()) { | 273 if (!result->get()) { |
| 257 DLOG(ERROR) << reader.GetErrorMessage(); | 274 DLOG(ERROR) << reader.GetErrorMessage(); |
| 258 return false; | 275 return false; |
| 259 } | 276 } |
| 260 | 277 |
| 261 return true; | 278 return true; |
| 262 } | 279 } |
| 263 | 280 |
| 264 void RunAllPendingMessageAndSendQuit(content::BrowserThread::ID thread_id) { | 281 void RunAllPendingMessageAndSendQuit(content::BrowserThread::ID thread_id) { |
| 265 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); | 282 MessageLoop::current()->PostTask(FROM_HERE, |
| 283 MessageLoop::QuitWhenIdleClosure()); |
| 266 RunMessageLoop(); | 284 RunMessageLoop(); |
| 267 content::BrowserThread::PostTask(thread_id, FROM_HERE, | 285 content::BrowserThread::PostTask(thread_id, FROM_HERE, |
| 268 MessageLoop::QuitClosure()); | 286 MessageLoop::QuitAfterPendingClosure()); |
| 269 } | 287 } |
| 270 | 288 |
| 271 } // namespace | 289 } // namespace |
| 272 | 290 |
| 273 void RunMessageLoop() { | 291 void RunMessageLoop() { |
| 274 MessageLoop* loop = MessageLoop::current(); | 292 MessageLoop* loop = MessageLoop::current(); |
| 275 MessageLoopForUI* ui_loop = | 293 MessageLoopForUI* ui_loop = |
| 276 content::BrowserThread::CurrentlyOn(content::BrowserThread::UI) ? | 294 content::BrowserThread::CurrentlyOn(content::BrowserThread::UI) ? |
| 277 MessageLoopForUI::current() : NULL; | 295 MessageLoopForUI::current() : NULL; |
| 278 MessageLoop::ScopedNestableTaskAllower allow(loop); | 296 MessageLoop::ScopedNestableTaskAllower allow(loop); |
| 279 if (ui_loop) { | 297 if (ui_loop) { |
| 280 #if defined(USE_AURA) | 298 #if defined(USE_AURA) |
| 281 ui_loop->Run(); | 299 ui_loop->Run(); |
| 282 #elif defined(TOOLKIT_VIEWS) | 300 #elif defined(TOOLKIT_VIEWS) |
| 283 views::AcceleratorHandler handler; | 301 views::AcceleratorHandler handler; |
| 284 ui_loop->RunWithDispatcher(&handler); | 302 ui_loop->RunWithDispatcher(&handler); |
| 285 #elif defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) | 303 #elif defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) |
| 286 ui_loop->RunWithDispatcher(NULL); | 304 ui_loop->RunWithDispatcher(NULL); |
| 287 #else | 305 #else |
| 288 ui_loop->Run(); | 306 ui_loop->Run(); |
| 289 #endif | 307 #endif |
| 290 } else { | 308 } else { |
| 291 loop->Run(); | 309 loop->Run(); |
| 292 } | 310 } |
| 293 } | 311 } |
| 294 | 312 |
| 295 void RunAllPendingInMessageLoop() { | 313 void RunAllPendingInMessageLoop() { |
| 296 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); | 314 MessageLoop::current()->PostTask(FROM_HERE, |
| 315 MessageLoop::QuitWhenIdleClosure()); |
| 297 ui_test_utils::RunMessageLoop(); | 316 ui_test_utils::RunMessageLoop(); |
| 298 } | 317 } |
| 299 | 318 |
| 300 void RunAllPendingInMessageLoop(content::BrowserThread::ID thread_id) { | 319 void RunAllPendingInMessageLoop(content::BrowserThread::ID thread_id) { |
| 301 if (content::BrowserThread::CurrentlyOn(thread_id)) { | 320 if (content::BrowserThread::CurrentlyOn(thread_id)) { |
| 302 RunAllPendingInMessageLoop(); | 321 RunAllPendingInMessageLoop(); |
| 303 return; | 322 return; |
| 304 } | 323 } |
| 305 content::BrowserThread::ID current_thread_id; | 324 content::BrowserThread::ID current_thread_id; |
| 306 if (!content::BrowserThread::GetCurrentThreadIdentifier(¤t_thread_id)) { | 325 if (!content::BrowserThread::GetCurrentThreadIdentifier(¤t_thread_id)) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 324 return true; | 343 return true; |
| 325 } | 344 } |
| 326 | 345 |
| 327 void WaitForNavigations(NavigationController* controller, | 346 void WaitForNavigations(NavigationController* controller, |
| 328 int number_of_navigations) { | 347 int number_of_navigations) { |
| 329 content::TestNavigationObserver observer( | 348 content::TestNavigationObserver observer( |
| 330 content::Source<NavigationController>(controller), NULL, | 349 content::Source<NavigationController>(controller), NULL, |
| 331 number_of_navigations); | 350 number_of_navigations); |
| 332 observer.WaitForObservation( | 351 observer.WaitForObservation( |
| 333 base::Bind(&ui_test_utils::RunMessageLoop), | 352 base::Bind(&ui_test_utils::RunMessageLoop), |
| 334 base::Bind(&MessageLoop::Quit, | 353 MessageLoop::QuitAfterPendingClosure()); |
| 335 base::Unretained(MessageLoopForUI::current()))); | |
| 336 } | 354 } |
| 337 | 355 |
| 338 void WaitForNewTab(Browser* browser) { | 356 void WaitForNewTab(Browser* browser) { |
| 339 WindowedNotificationObserver observer( | 357 WindowedNotificationObserver observer( |
| 340 chrome::NOTIFICATION_TAB_ADDED, | 358 chrome::NOTIFICATION_TAB_ADDED, |
| 341 content::Source<content::WebContentsDelegate>(browser)); | 359 content::Source<content::WebContentsDelegate>(browser)); |
| 342 observer.Wait(); | 360 observer.Wait(); |
| 343 } | 361 } |
| 344 | 362 |
| 345 void WaitForBrowserActionUpdated(ExtensionAction* browser_action) { | 363 void WaitForBrowserActionUpdated(ExtensionAction* browser_action) { |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 384 profile->GetOffTheRecordProfile(), false); | 402 profile->GetOffTheRecordProfile(), false); |
| 385 WaitForNavigations(&browser->GetSelectedWebContents()->GetController(), 1); | 403 WaitForNavigations(&browser->GetSelectedWebContents()->GetController(), 1); |
| 386 } | 404 } |
| 387 | 405 |
| 388 void NavigateToURL(browser::NavigateParams* params) { | 406 void NavigateToURL(browser::NavigateParams* params) { |
| 389 content::TestNavigationObserver observer( | 407 content::TestNavigationObserver observer( |
| 390 content::NotificationService::AllSources(), NULL, 1); | 408 content::NotificationService::AllSources(), NULL, 1); |
| 391 browser::Navigate(params); | 409 browser::Navigate(params); |
| 392 observer.WaitForObservation( | 410 observer.WaitForObservation( |
| 393 base::Bind(&ui_test_utils::RunMessageLoop), | 411 base::Bind(&ui_test_utils::RunMessageLoop), |
| 394 base::Bind(&MessageLoop::Quit, | 412 MessageLoop::QuitAfterPendingClosure()); |
| 395 base::Unretained(MessageLoopForUI::current()))); | |
| 396 | 413 |
| 397 } | 414 } |
| 398 | 415 |
| 399 void NavigateToURL(Browser* browser, const GURL& url) { | 416 void NavigateToURL(Browser* browser, const GURL& url) { |
| 400 NavigateToURLWithDisposition(browser, url, CURRENT_TAB, | 417 NavigateToURLWithDisposition(browser, url, CURRENT_TAB, |
| 401 BROWSER_TEST_WAIT_FOR_NAVIGATION); | 418 BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 402 } | 419 } |
| 403 | 420 |
| 404 // Navigates the specified tab (via |disposition|) of |browser| to |url|, | 421 // Navigates the specified tab (via |disposition|) of |browser| to |url|, |
| 405 // blocking until the |number_of_navigations| specified complete. | 422 // blocking until the |number_of_navigations| specified complete. |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 458 return; | 475 return; |
| 459 } else if ((disposition == CURRENT_TAB) || | 476 } else if ((disposition == CURRENT_TAB) || |
| 460 (disposition == NEW_FOREGROUND_TAB) || | 477 (disposition == NEW_FOREGROUND_TAB) || |
| 461 (disposition == SINGLETON_TAB)) { | 478 (disposition == SINGLETON_TAB)) { |
| 462 // The currently selected tab is the right one. | 479 // The currently selected tab is the right one. |
| 463 web_contents = browser->GetSelectedWebContents(); | 480 web_contents = browser->GetSelectedWebContents(); |
| 464 } | 481 } |
| 465 if (disposition == CURRENT_TAB) { | 482 if (disposition == CURRENT_TAB) { |
| 466 same_tab_observer.WaitForObservation( | 483 same_tab_observer.WaitForObservation( |
| 467 base::Bind(&ui_test_utils::RunMessageLoop), | 484 base::Bind(&ui_test_utils::RunMessageLoop), |
| 468 base::Bind(&MessageLoop::Quit, | 485 MessageLoop::QuitAfterPendingClosure()); |
| 469 base::Unretained(MessageLoopForUI::current()))); | |
| 470 return; | 486 return; |
| 471 } else if (web_contents) { | 487 } else if (web_contents) { |
| 472 NavigationController* controller = &web_contents->GetController(); | 488 NavigationController* controller = &web_contents->GetController(); |
| 473 WaitForNavigations(controller, number_of_navigations); | 489 WaitForNavigations(controller, number_of_navigations); |
| 474 return; | 490 return; |
| 475 } | 491 } |
| 476 EXPECT_TRUE(NULL != web_contents) << " Unable to wait for navigation to \"" | 492 EXPECT_TRUE(NULL != web_contents) << " Unable to wait for navigation to \"" |
| 477 << url.spec() << "\"" | 493 << url.spec() << "\"" |
| 478 << " because we can't get the tab contents"; | 494 << " because we can't get the tab contents"; |
| 479 } | 495 } |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 766 bool control, | 782 bool control, |
| 767 bool shift, | 783 bool shift, |
| 768 bool alt, | 784 bool alt, |
| 769 bool command) { | 785 bool command) { |
| 770 gfx::NativeWindow window = NULL; | 786 gfx::NativeWindow window = NULL; |
| 771 if (!GetNativeWindow(browser, &window)) | 787 if (!GetNativeWindow(browser, &window)) |
| 772 return false; | 788 return false; |
| 773 | 789 |
| 774 bool result; | 790 bool result; |
| 775 result = ui_controls::SendKeyPressNotifyWhenDone( | 791 result = ui_controls::SendKeyPressNotifyWhenDone( |
| 776 window, key, control, shift, alt, command, MessageLoop::QuitClosure()); | 792 window, key, control, shift, alt, command, |
| 793 MessageLoop::QuitAfterPendingClosure()); |
| 777 #if defined(OS_WIN) | 794 #if defined(OS_WIN) |
| 778 if (!result && BringBrowserWindowToFront(browser)) { | 795 if (!result && BringBrowserWindowToFront(browser)) { |
| 779 result = ui_controls::SendKeyPressNotifyWhenDone( | 796 result = ui_controls::SendKeyPressNotifyWhenDone( |
| 780 window, key, control, shift, alt, command, MessageLoop::QuitClosure()); | 797 window, key, control, shift, alt, command, |
| 798 MessageLoop::QuitAfterPendingClosure()); |
| 781 } | 799 } |
| 782 #endif | 800 #endif |
| 783 if (!result) { | 801 if (!result) { |
| 784 LOG(ERROR) << "ui_controls::SendKeyPressNotifyWhenDone failed"; | 802 LOG(ERROR) << "ui_controls::SendKeyPressNotifyWhenDone failed"; |
| 785 return false; | 803 return false; |
| 786 } | 804 } |
| 787 | 805 |
| 788 // Run the message loop. It'll stop running when either the key was received | 806 // Run the message loop. It'll stop running when either the key was received |
| 789 // or the test timed out (in which case testing::Test::HasFatalFailure should | 807 // or the test timed out (in which case testing::Test::HasFatalFailure should |
| 790 // be set). | 808 // be set). |
| (...skipping 12 matching lines...) Expand all Loading... |
| 803 WindowedNotificationObserver observer(type, source); | 821 WindowedNotificationObserver observer(type, source); |
| 804 | 822 |
| 805 if (!SendKeyPressSync(browser, key, control, shift, alt, command)) | 823 if (!SendKeyPressSync(browser, key, control, shift, alt, command)) |
| 806 return false; | 824 return false; |
| 807 | 825 |
| 808 observer.Wait(); | 826 observer.Wait(); |
| 809 return !testing::Test::HasFatalFailure(); | 827 return !testing::Test::HasFatalFailure(); |
| 810 } | 828 } |
| 811 | 829 |
| 812 bool SendMouseMoveSync(const gfx::Point& location) { | 830 bool SendMouseMoveSync(const gfx::Point& location) { |
| 813 if (!ui_controls::SendMouseMoveNotifyWhenDone(location.x(), location.y(), | 831 if (!ui_controls::SendMouseMoveNotifyWhenDone( |
| 814 MessageLoop::QuitClosure())) { | 832 location.x(), location.y(), MessageLoop::QuitAfterPendingClosure())) { |
| 815 return false; | 833 return false; |
| 816 } | 834 } |
| 817 RunMessageLoop(); | 835 RunMessageLoop(); |
| 818 return !testing::Test::HasFatalFailure(); | 836 return !testing::Test::HasFatalFailure(); |
| 819 } | 837 } |
| 820 | 838 |
| 821 bool SendMouseEventsSync(ui_controls::MouseButton type, int state) { | 839 bool SendMouseEventsSync(ui_controls::MouseButton type, int state) { |
| 822 if (!ui_controls::SendMouseEventsNotifyWhenDone( | 840 if (!ui_controls::SendMouseEventsNotifyWhenDone( |
| 823 type, state, MessageLoop::QuitClosure())) { | 841 type, state, MessageLoop::QuitAfterPendingClosure())) { |
| 824 return false; | 842 return false; |
| 825 } | 843 } |
| 826 RunMessageLoop(); | 844 RunMessageLoop(); |
| 827 return !testing::Test::HasFatalFailure(); | 845 return !testing::Test::HasFatalFailure(); |
| 828 } | 846 } |
| 829 | 847 |
| 830 TimedMessageLoopRunner::TimedMessageLoopRunner() | 848 TimedMessageLoopRunner::TimedMessageLoopRunner() |
| 831 : loop_(new MessageLoopForUI()), | 849 : loop_(new MessageLoopForUI()), |
| 832 owned_(true), | 850 owned_(true) { |
| 833 quit_loop_invoked_(false) { | |
| 834 } | 851 } |
| 835 | 852 |
| 836 TimedMessageLoopRunner::~TimedMessageLoopRunner() { | 853 TimedMessageLoopRunner::~TimedMessageLoopRunner() { |
| 837 if (owned_) | 854 if (owned_) |
| 838 delete loop_; | 855 delete loop_; |
| 839 } | 856 } |
| 840 | 857 |
| 841 void TimedMessageLoopRunner::RunFor(int ms) { | 858 void TimedMessageLoopRunner::RunFor(int ms) { |
| 842 QuitAfter(ms); | 859 loop_->PostDelayedTask( |
| 843 quit_loop_invoked_ = false; | 860 FROM_HERE, |
| 861 MessageLoop::QuitAfterPendingClosure(), |
| 862 base::TimeDelta::FromMilliseconds(ms)); |
| 844 loop_->Run(); | 863 loop_->Run(); |
| 845 } | 864 } |
| 846 | 865 |
| 847 void TimedMessageLoopRunner::Quit() { | |
| 848 quit_loop_invoked_ = true; | |
| 849 loop_->PostTask(FROM_HERE, MessageLoop::QuitClosure()); | |
| 850 } | |
| 851 | |
| 852 void TimedMessageLoopRunner::QuitAfter(int ms) { | |
| 853 quit_loop_invoked_ = true; | |
| 854 loop_->PostDelayedTask( | |
| 855 FROM_HERE, | |
| 856 MessageLoop::QuitClosure(), | |
| 857 base::TimeDelta::FromMilliseconds(ms)); | |
| 858 } | |
| 859 | |
| 860 TestWebSocketServer::TestWebSocketServer() | 866 TestWebSocketServer::TestWebSocketServer() |
| 861 : started_(false), | 867 : started_(false), |
| 862 port_(kDefaultWsPort), | 868 port_(kDefaultWsPort), |
| 863 secure_(false) { | 869 secure_(false) { |
| 864 #if defined(OS_POSIX) | 870 #if defined(OS_POSIX) |
| 865 process_group_id_ = base::kNullProcessHandle; | 871 process_group_id_ = base::kNullProcessHandle; |
| 866 #endif | 872 #endif |
| 867 } | 873 } |
| 868 | 874 |
| 869 int TestWebSocketServer::UseRandomPort() { | 875 int TestWebSocketServer::UseRandomPort() { |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1026 void WindowedNotificationObserver::Observe( | 1032 void WindowedNotificationObserver::Observe( |
| 1027 int type, | 1033 int type, |
| 1028 const content::NotificationSource& source, | 1034 const content::NotificationSource& source, |
| 1029 const content::NotificationDetails& details) { | 1035 const content::NotificationDetails& details) { |
| 1030 source_ = source; | 1036 source_ = source; |
| 1031 details_ = details; | 1037 details_ = details; |
| 1032 seen_ = true; | 1038 seen_ = true; |
| 1033 if (!running_) | 1039 if (!running_) |
| 1034 return; | 1040 return; |
| 1035 | 1041 |
| 1036 MessageLoopForUI::current()->Quit(); | 1042 MessageLoopForUI::current()->QuitAfterPending(); |
| 1037 running_ = false; | 1043 running_ = false; |
| 1038 } | 1044 } |
| 1039 | 1045 |
| 1040 WindowedTabAddedNotificationObserver::WindowedTabAddedNotificationObserver( | 1046 WindowedTabAddedNotificationObserver::WindowedTabAddedNotificationObserver( |
| 1041 const content::NotificationSource& source) | 1047 const content::NotificationSource& source) |
| 1042 : WindowedNotificationObserver(chrome::NOTIFICATION_TAB_ADDED, source), | 1048 : WindowedNotificationObserver(chrome::NOTIFICATION_TAB_ADDED, source), |
| 1043 added_tab_(NULL) { | 1049 added_tab_(NULL) { |
| 1044 } | 1050 } |
| 1045 | 1051 |
| 1046 void WindowedTabAddedNotificationObserver::Observe( | 1052 void WindowedTabAddedNotificationObserver::Observe( |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1103 } | 1109 } |
| 1104 | 1110 |
| 1105 std::vector<string16>::const_iterator it = | 1111 std::vector<string16>::const_iterator it = |
| 1106 std::find(expected_titles_.begin(), | 1112 std::find(expected_titles_.begin(), |
| 1107 expected_titles_.end(), | 1113 expected_titles_.end(), |
| 1108 web_contents_->GetTitle()); | 1114 web_contents_->GetTitle()); |
| 1109 if (it == expected_titles_.end()) | 1115 if (it == expected_titles_.end()) |
| 1110 return; | 1116 return; |
| 1111 observed_title_ = *it; | 1117 observed_title_ = *it; |
| 1112 expected_title_observed_ = true; | 1118 expected_title_observed_ = true; |
| 1113 if (quit_loop_on_observation_) | 1119 if (quit_loop_on_observation_) { |
| 1114 MessageLoopForUI::current()->Quit(); | 1120 // Only call Quit once, on first Observe: |
| 1121 quit_loop_on_observation_ = false; |
| 1122 MessageLoopForUI::current()->QuitAfterPending(); |
| 1123 } |
| 1115 } | 1124 } |
| 1116 | 1125 |
| 1117 BrowserAddedObserver::BrowserAddedObserver() | 1126 BrowserAddedObserver::BrowserAddedObserver() |
| 1118 : notification_observer_( | 1127 : notification_observer_( |
| 1119 chrome::NOTIFICATION_BROWSER_OPENED, | 1128 chrome::NOTIFICATION_BROWSER_OPENED, |
| 1120 content::NotificationService::AllSources()) { | 1129 content::NotificationService::AllSources()) { |
| 1121 original_browsers_.insert(BrowserList::begin(), BrowserList::end()); | 1130 original_browsers_.insert(BrowserList::begin(), BrowserList::end()); |
| 1122 } | 1131 } |
| 1123 | 1132 |
| 1124 BrowserAddedObserver::~BrowserAddedObserver() { | 1133 BrowserAddedObserver::~BrowserAddedObserver() { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1139 DOMMessageQueue::~DOMMessageQueue() {} | 1148 DOMMessageQueue::~DOMMessageQueue() {} |
| 1140 | 1149 |
| 1141 void DOMMessageQueue::Observe(int type, | 1150 void DOMMessageQueue::Observe(int type, |
| 1142 const content::NotificationSource& source, | 1151 const content::NotificationSource& source, |
| 1143 const content::NotificationDetails& details) { | 1152 const content::NotificationDetails& details) { |
| 1144 content::Details<DomOperationNotificationDetails> dom_op_details(details); | 1153 content::Details<DomOperationNotificationDetails> dom_op_details(details); |
| 1145 content::Source<RenderViewHost> sender(source); | 1154 content::Source<RenderViewHost> sender(source); |
| 1146 message_queue_.push(dom_op_details->json); | 1155 message_queue_.push(dom_op_details->json); |
| 1147 if (waiting_for_message_) { | 1156 if (waiting_for_message_) { |
| 1148 waiting_for_message_ = false; | 1157 waiting_for_message_ = false; |
| 1149 MessageLoopForUI::current()->Quit(); | 1158 MessageLoopForUI::current()->QuitAfterPending(); |
| 1150 } | 1159 } |
| 1151 } | 1160 } |
| 1152 | 1161 |
| 1153 void DOMMessageQueue::ClearQueue() { | 1162 void DOMMessageQueue::ClearQueue() { |
| 1154 message_queue_ = std::queue<std::string>(); | 1163 message_queue_ = std::queue<std::string>(); |
| 1155 } | 1164 } |
| 1156 | 1165 |
| 1157 bool DOMMessageQueue::WaitForMessage(std::string* message) { | 1166 bool DOMMessageQueue::WaitForMessage(std::string* message) { |
| 1158 if (message_queue_.empty()) { | 1167 if (message_queue_.empty()) { |
| 1159 waiting_for_message_ = true; | 1168 waiting_for_message_ = true; |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1214 // Take the snapshot. | 1223 // Take the snapshot. |
| 1215 gfx::Size page_size(width, height); | 1224 gfx::Size page_size(width, height); |
| 1216 return TakeRenderWidgetSnapshot(rvh, page_size, page_size, bitmap); | 1225 return TakeRenderWidgetSnapshot(rvh, page_size, page_size, bitmap); |
| 1217 } | 1226 } |
| 1218 | 1227 |
| 1219 private: | 1228 private: |
| 1220 // Called when the ThumbnailGenerator has taken the snapshot. | 1229 // Called when the ThumbnailGenerator has taken the snapshot. |
| 1221 void OnSnapshotTaken(const SkBitmap& bitmap) { | 1230 void OnSnapshotTaken(const SkBitmap& bitmap) { |
| 1222 *bitmap_ = bitmap; | 1231 *bitmap_ = bitmap; |
| 1223 snapshot_taken_ = true; | 1232 snapshot_taken_ = true; |
| 1224 MessageLoop::current()->Quit(); | 1233 MessageLoop::current()->QuitNow(); |
| 1225 } | 1234 } |
| 1226 | 1235 |
| 1227 SkBitmap* bitmap_; | 1236 SkBitmap* bitmap_; |
| 1228 // Whether the snapshot was actually taken and received by this SnapshotTaker. | 1237 // Whether the snapshot was actually taken and received by this SnapshotTaker. |
| 1229 // This will be false if the test times out. | 1238 // This will be false if the test times out. |
| 1230 bool snapshot_taken_; | 1239 bool snapshot_taken_; |
| 1231 | 1240 |
| 1232 DISALLOW_COPY_AND_ASSIGN(SnapshotTaker); | 1241 DISALLOW_COPY_AND_ASSIGN(SnapshotTaker); |
| 1233 }; | 1242 }; |
| 1234 | 1243 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1247 } | 1256 } |
| 1248 | 1257 |
| 1249 void OverrideGeolocation(double latitude, double longitude) { | 1258 void OverrideGeolocation(double latitude, double longitude) { |
| 1250 content::Geoposition position; | 1259 content::Geoposition position; |
| 1251 position.latitude = latitude; | 1260 position.latitude = latitude; |
| 1252 position.longitude = longitude; | 1261 position.longitude = longitude; |
| 1253 position.altitude = 0.; | 1262 position.altitude = 0.; |
| 1254 position.accuracy = 0.; | 1263 position.accuracy = 0.; |
| 1255 position.timestamp = base::Time::Now(); | 1264 position.timestamp = base::Time::Now(); |
| 1256 content::OverrideLocationForTesting(position, | 1265 content::OverrideLocationForTesting(position, |
| 1257 base::Bind(MessageLoop::QuitClosure())); | 1266 MessageLoop::QuitAfterPendingClosure()); |
| 1258 RunMessageLoop(); | 1267 RunMessageLoop(); |
| 1259 } | 1268 } |
| 1260 | 1269 |
| 1261 namespace internal { | 1270 namespace internal { |
| 1262 | 1271 |
| 1263 void ClickTask(ui_controls::MouseButton button, | 1272 void ClickTask(ui_controls::MouseButton button, |
| 1264 int state, | 1273 int state, |
| 1265 const base::Closure& followup) { | 1274 const base::Closure& followup) { |
| 1266 if (!followup.is_null()) | 1275 if (!followup.is_null()) |
| 1267 ui_controls::SendMouseEventsNotifyWhenDone(button, state, followup); | 1276 ui_controls::SendMouseEventsNotifyWhenDone(button, state, followup); |
| 1268 else | 1277 else |
| 1269 ui_controls::SendMouseEvents(button, state); | 1278 ui_controls::SendMouseEvents(button, state); |
| 1270 } | 1279 } |
| 1271 | 1280 |
| 1272 } // namespace internal | 1281 } // namespace internal |
| 1273 } // namespace ui_test_utils | 1282 } // namespace ui_test_utils |
| OLD | NEW |