| Index: chrome/test/ui_test_utils.cc
|
| ===================================================================
|
| --- chrome/test/ui_test_utils.cc (revision 13436)
|
| +++ chrome/test/ui_test_utils.cc (working copy)
|
| @@ -20,8 +20,11 @@
|
| // Used to block until a navigation completes.
|
| class NavigationNotificationObserver : public NotificationObserver {
|
| public:
|
| - explicit NavigationNotificationObserver(NavigationController* controller)
|
| - : navigation_started_(false) {
|
| + NavigationNotificationObserver(NavigationController* controller,
|
| + int number_of_navigations)
|
| + : navigation_started_(false),
|
| + navigations_completed_(0),
|
| + number_of_navigations_(number_of_navigations) {
|
| registrar_.Add(this, NotificationType::NAV_ENTRY_COMMITTED,
|
| Source<NavigationController>(controller));
|
| registrar_.Add(this, NotificationType::LOAD_START,
|
| @@ -38,7 +41,8 @@
|
| type == NotificationType::LOAD_START) {
|
| navigation_started_ = true;
|
| } else if (type == NotificationType::LOAD_STOP) {
|
| - if (navigation_started_) {
|
| + if (navigation_started_ &&
|
| + ++navigations_completed_ == number_of_navigations_) {
|
| navigation_started_ = false;
|
| MessageLoopForUI::current()->Quit();
|
| }
|
| @@ -51,6 +55,12 @@
|
| // If true the navigation has started.
|
| bool navigation_started_;
|
|
|
| + // The number of navigations that have been completed.
|
| + int navigations_completed_;
|
| +
|
| + // The number of navigations to wait for.
|
| + int number_of_navigations_;
|
| +
|
| DISALLOW_COPY_AND_ASSIGN(NavigationNotificationObserver);
|
| };
|
|
|
| @@ -66,15 +76,26 @@
|
| }
|
|
|
| void WaitForNavigation(NavigationController* controller) {
|
| - NavigationNotificationObserver observer(controller);
|
| + WaitForNavigations(controller, 1);
|
| }
|
|
|
| +void WaitForNavigations(NavigationController* controller,
|
| + int number_of_navigations) {
|
| + NavigationNotificationObserver observer(controller, number_of_navigations);
|
| +}
|
| +
|
| void NavigateToURL(Browser* browser, const GURL& url) {
|
| + NavigateToURLBlockUntilNavigationsComplete(browser, url, 1);
|
| +}
|
| +
|
| +void NavigateToURLBlockUntilNavigationsComplete(Browser* browser,
|
| + const GURL& url,
|
| + int number_of_navigations) {
|
| NavigationController* controller =
|
| browser->GetSelectedTabContents()->controller();
|
| browser->OpenURLFromTab(browser->GetSelectedTabContents(), url, GURL(),
|
| CURRENT_TAB, PageTransition::TYPED);
|
| - WaitForNavigation(controller);
|
| + WaitForNavigations(controller, number_of_navigations);
|
| }
|
|
|
| } // namespace ui_test_utils
|
|
|