OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/ui_test_utils.h" | 5 #include "chrome/test/ui_test_utils.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
61 int number_of_navigations) | 61 int number_of_navigations) |
62 : navigation_started_(false), | 62 : navigation_started_(false), |
63 navigations_completed_(0), | 63 navigations_completed_(0), |
64 number_of_navigations_(number_of_navigations) { | 64 number_of_navigations_(number_of_navigations) { |
65 registrar_.Add(this, NotificationType::NAV_ENTRY_COMMITTED, | 65 registrar_.Add(this, NotificationType::NAV_ENTRY_COMMITTED, |
66 Source<NavigationController>(controller)); | 66 Source<NavigationController>(controller)); |
67 registrar_.Add(this, NotificationType::LOAD_START, | 67 registrar_.Add(this, NotificationType::LOAD_START, |
68 Source<NavigationController>(controller)); | 68 Source<NavigationController>(controller)); |
69 registrar_.Add(this, NotificationType::LOAD_STOP, | 69 registrar_.Add(this, NotificationType::LOAD_STOP, |
70 Source<NavigationController>(controller)); | 70 Source<NavigationController>(controller)); |
71 } | |
72 | |
73 void Run() { | |
71 RunMessageLoop(); | 74 RunMessageLoop(); |
72 } | 75 } |
73 | 76 |
74 virtual void Observe(NotificationType type, | 77 virtual void Observe(NotificationType type, |
75 const NotificationSource& source, | 78 const NotificationSource& source, |
76 const NotificationDetails& details) { | 79 const NotificationDetails& details) { |
77 if (type == NotificationType::NAV_ENTRY_COMMITTED || | 80 if (type == NotificationType::NAV_ENTRY_COMMITTED || |
78 type == NotificationType::LOAD_START) { | 81 type == NotificationType::LOAD_START) { |
79 navigation_started_ = true; | 82 navigation_started_ = true; |
80 } else if (type == NotificationType::LOAD_STOP) { | 83 } else if (type == NotificationType::LOAD_STOP) { |
81 if (navigation_started_ && | 84 if (navigation_started_ && |
82 ++navigations_completed_ == number_of_navigations_) { | 85 ++navigations_completed_ == number_of_navigations_) { |
83 navigation_started_ = false; | 86 navigation_started_ = false; |
84 MessageLoopForUI::current()->Quit(); | 87 MessageLoopForUI::current()->Quit(); |
sky
2011/03/09 21:52:50
Doesn't this mean Quit may be invoked before Run?
| |
85 } | 88 } |
86 } | 89 } |
87 } | 90 } |
88 | 91 |
89 private: | 92 private: |
90 NotificationRegistrar registrar_; | 93 NotificationRegistrar registrar_; |
91 | 94 |
92 // If true the navigation has started. | 95 // If true the navigation has started. |
93 bool navigation_started_; | 96 bool navigation_started_; |
94 | 97 |
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
405 return true; | 408 return true; |
406 } | 409 } |
407 | 410 |
408 void WaitForNavigation(NavigationController* controller) { | 411 void WaitForNavigation(NavigationController* controller) { |
409 WaitForNavigations(controller, 1); | 412 WaitForNavigations(controller, 1); |
410 } | 413 } |
411 | 414 |
412 void WaitForNavigations(NavigationController* controller, | 415 void WaitForNavigations(NavigationController* controller, |
413 int number_of_navigations) { | 416 int number_of_navigations) { |
414 NavigationNotificationObserver observer(controller, number_of_navigations); | 417 NavigationNotificationObserver observer(controller, number_of_navigations); |
418 observer.Run(); | |
415 } | 419 } |
416 | 420 |
417 void WaitForNewTab(Browser* browser) { | 421 void WaitForNewTab(Browser* browser) { |
418 TestNotificationObserver observer; | 422 TestNotificationObserver observer; |
419 RegisterAndWait(&observer, NotificationType::TAB_ADDED, | 423 RegisterAndWait(&observer, NotificationType::TAB_ADDED, |
420 Source<Browser>(browser)); | 424 Source<Browser>(browser)); |
421 } | 425 } |
422 | 426 |
423 void WaitForBrowserActionUpdated(ExtensionAction* browser_action) { | 427 void WaitForBrowserActionUpdated(ExtensionAction* browser_action) { |
424 TestNotificationObserver observer; | 428 TestNotificationObserver observer; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
465 // Navigates the specified tab (via |disposition|) of |browser| to |url|, | 469 // Navigates the specified tab (via |disposition|) of |browser| to |url|, |
466 // blocking until the |number_of_navigations| specified complete. | 470 // blocking until the |number_of_navigations| specified complete. |
467 // |disposition| indicates what tab the download occurs in, and | 471 // |disposition| indicates what tab the download occurs in, and |
468 // |browser_test_flags| controls what to wait for before continuing. | 472 // |browser_test_flags| controls what to wait for before continuing. |
469 static void NavigateToURLWithDispositionBlockUntilNavigationsComplete( | 473 static void NavigateToURLWithDispositionBlockUntilNavigationsComplete( |
470 Browser* browser, | 474 Browser* browser, |
471 const GURL& url, | 475 const GURL& url, |
472 int number_of_navigations, | 476 int number_of_navigations, |
473 WindowOpenDisposition disposition, | 477 WindowOpenDisposition disposition, |
474 int browser_test_flags) { | 478 int browser_test_flags) { |
479 NavigationNotificationObserver | |
480 same_tab_observer(&browser->GetSelectedTabContents()->controller(), | |
481 number_of_navigations); | |
482 | |
475 std::set<Browser*> initial_browsers; | 483 std::set<Browser*> initial_browsers; |
476 for (std::vector<Browser*>::const_iterator iter = BrowserList::begin(); | 484 for (std::vector<Browser*>::const_iterator iter = BrowserList::begin(); |
477 iter != BrowserList::end(); | 485 iter != BrowserList::end(); |
478 ++iter) { | 486 ++iter) { |
479 initial_browsers.insert(*iter); | 487 initial_browsers.insert(*iter); |
480 } | 488 } |
481 browser->OpenURL(url, GURL(), disposition, PageTransition::TYPED); | 489 browser->OpenURL(url, GURL(), disposition, PageTransition::TYPED); |
482 if (browser_test_flags & BROWSER_TEST_WAIT_FOR_BROWSER) | 490 if (browser_test_flags & BROWSER_TEST_WAIT_FOR_BROWSER) |
483 browser = WaitForBrowserNotInSet(initial_browsers); | 491 browser = WaitForBrowserNotInSet(initial_browsers); |
484 if (browser_test_flags & BROWSER_TEST_WAIT_FOR_TAB) | 492 if (browser_test_flags & BROWSER_TEST_WAIT_FOR_TAB) |
485 WaitForNotification(NotificationType::TAB_ADDED); | 493 WaitForNotification(NotificationType::TAB_ADDED); |
486 if (!(browser_test_flags & BROWSER_TEST_WAIT_FOR_NAVIGATION)) { | 494 if (!(browser_test_flags & BROWSER_TEST_WAIT_FOR_NAVIGATION)) { |
487 // Some other flag caused the wait prior to this. | 495 // Some other flag caused the wait prior to this. |
488 return; | 496 return; |
489 } | 497 } |
490 TabContents* tab_contents = NULL; | 498 TabContents* tab_contents = NULL; |
491 if (disposition == NEW_BACKGROUND_TAB) { | 499 if (disposition == NEW_BACKGROUND_TAB) { |
492 // We've opened up a new tab, but not selected it. | 500 // We've opened up a new tab, but not selected it. |
493 tab_contents = browser->GetTabContentsAt(browser->selected_index() + 1); | 501 tab_contents = browser->GetTabContentsAt(browser->selected_index() + 1); |
494 EXPECT_TRUE(tab_contents != NULL) | 502 EXPECT_TRUE(tab_contents != NULL) |
495 << " Unable to wait for navigation to \"" << url.spec() | 503 << " Unable to wait for navigation to \"" << url.spec() |
496 << "\" because the new tab is not available yet"; | 504 << "\" because the new tab is not available yet"; |
497 return; | 505 return; |
498 } else if ((disposition == CURRENT_TAB) || | 506 } else if ((disposition == CURRENT_TAB) || |
499 (disposition == NEW_FOREGROUND_TAB) || | 507 (disposition == NEW_FOREGROUND_TAB) || |
500 (disposition == SINGLETON_TAB)) { | 508 (disposition == SINGLETON_TAB)) { |
501 // The currently selected tab is the right one. | 509 // The currently selected tab is the right one. |
502 tab_contents = browser->GetSelectedTabContents(); | 510 tab_contents = browser->GetSelectedTabContents(); |
503 } | 511 } |
504 if (tab_contents) { | 512 if (disposition == CURRENT_TAB) { |
513 same_tab_observer.Run(); | |
514 return; | |
515 } else if (tab_contents) { | |
505 NavigationController* controller = &tab_contents->controller(); | 516 NavigationController* controller = &tab_contents->controller(); |
506 WaitForNavigations(controller, number_of_navigations); | 517 WaitForNavigations(controller, number_of_navigations); |
507 return; | 518 return; |
508 } | 519 } |
509 EXPECT_TRUE(NULL != tab_contents) << " Unable to wait for navigation to \"" | 520 EXPECT_TRUE(NULL != tab_contents) << " Unable to wait for navigation to \"" |
510 << url.spec() << "\"" | 521 << url.spec() << "\"" |
511 << " because we can't get the tab contents"; | 522 << " because we can't get the tab contents"; |
512 } | 523 } |
513 | 524 |
514 void NavigateToURLWithDisposition(Browser* browser, | 525 void NavigateToURLWithDisposition(Browser* browser, |
(...skipping 530 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1045 return taker.TakeRenderWidgetSnapshot(rwh, page_size, page_size, bitmap); | 1056 return taker.TakeRenderWidgetSnapshot(rwh, page_size, page_size, bitmap); |
1046 } | 1057 } |
1047 | 1058 |
1048 bool TakeEntirePageSnapshot(RenderViewHost* rvh, SkBitmap* bitmap) { | 1059 bool TakeEntirePageSnapshot(RenderViewHost* rvh, SkBitmap* bitmap) { |
1049 DCHECK(bitmap); | 1060 DCHECK(bitmap); |
1050 SnapshotTaker taker; | 1061 SnapshotTaker taker; |
1051 return taker.TakeEntirePageSnapshot(rvh, bitmap); | 1062 return taker.TakeEntirePageSnapshot(rvh, bitmap); |
1052 } | 1063 } |
1053 | 1064 |
1054 } // namespace ui_test_utils | 1065 } // namespace ui_test_utils |
OLD | NEW |