diff options
author | gbillock@chromium.org <gbillock@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-14 23:19:39 +0000 |
---|---|---|
committer | gbillock@chromium.org <gbillock@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-14 23:19:39 +0000 |
commit | ddddfda8583100f3cb9dbba4ee1bc5ca5e87a770 (patch) | |
tree | d60bd03b926882020583f7feefc0026cd0697b03 /chrome/test/ui_test_utils.cc | |
parent | d252e84a8be5a8e373e7dc860c10eb841e6bfbb7 (diff) | |
download | chromium_src-ddddfda8583100f3cb9dbba4ee1bc5ca5e87a770.zip chromium_src-ddddfda8583100f3cb9dbba4ee1bc5ca5e87a770.tar.gz chromium_src-ddddfda8583100f3cb9dbba4ee1bc5ca5e87a770.tar.bz2 |
Change history, downloads, bookmarks to also load over NTP.
Change tests away from racy code.
R=jhawkins@chromium.org,phajdan.jr@chromium.org
BUG=22951
TEST=BrowserNavigatorTest
Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=92289
Review URL: http://codereview.chromium.org/7233021
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@92621 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test/ui_test_utils.cc')
-rw-r--r-- | chrome/test/ui_test_utils.cc | 83 |
1 files changed, 76 insertions, 7 deletions
diff --git a/chrome/test/ui_test_utils.cc b/chrome/test/ui_test_utils.cc index 1fb3d3e..bc6733d 100644 --- a/chrome/test/ui_test_utils.cc +++ b/chrome/test/ui_test_utils.cc @@ -26,6 +26,7 @@ #include "chrome/browser/tab_contents/thumbnail_generator.h" #include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser_list.h" +#include "chrome/browser/ui/browser_navigator.h" #include "chrome/browser/ui/browser_window.h" #include "chrome/browser/ui/find_bar/find_notification_details.h" #include "chrome/browser/ui/find_bar/find_tab_helper.h" @@ -35,7 +36,6 @@ #include "chrome/common/extensions/extension_action.h" #include "chrome/test/automation/javascript_execution_controller.h" #include "chrome/test/bookmark_load_observer.h" -#include "chrome/test/test_navigation_observer.h" #include "content/browser/renderer_host/render_process_host.h" #include "content/browser/renderer_host/render_view_host.h" #include "content/browser/tab_contents/navigation_controller.h" @@ -56,6 +56,67 @@ namespace ui_test_utils { namespace { +// Used to block until a navigation completes. +class NavigationNotificationObserver : public NotificationObserver { + public: + NavigationNotificationObserver(const NotificationSource& source, + int number_of_navigations) + : navigation_started_(false), + navigations_completed_(0), + number_of_navigations_(number_of_navigations), + running_(false), + done_(false) { + registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, source); + registrar_.Add(this, content::NOTIFICATION_LOAD_START, source); + registrar_.Add(this, content::NOTIFICATION_LOAD_STOP, source); + } + + void Run() { + if (!done_) { + running_ = true; + RunMessageLoop(); + } + } + + virtual void Observe(int type, + const NotificationSource& source, + const NotificationDetails& details) { + if (type == content::NOTIFICATION_NAV_ENTRY_COMMITTED || + type == content::NOTIFICATION_LOAD_START) { + navigation_started_ = true; + } else if (type == content::NOTIFICATION_LOAD_STOP) { + if (navigation_started_ && + ++navigations_completed_ == number_of_navigations_) { + navigation_started_ = false; + done_ = true; + if (running_) + MessageLoopForUI::current()->Quit(); + } + } + } + + private: + NotificationRegistrar registrar_; + + // 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_; + + // Calls to Observe() can happen early, before the user calls Run(), or + // after. When we've seen all the navigations we're looking for, we set + // done_ to true; then when Run() is called we'll never need to run the + // event loop. Also, we don't need to quit the event loop when we're + // done if we never had to start an event loop. + bool running_; + bool done_; + DISALLOW_COPY_AND_ASSIGN(NavigationNotificationObserver); +}; + class DOMOperationObserver : public NotificationObserver { public: explicit DOMOperationObserver(RenderViewHost* render_view_host) @@ -274,8 +335,9 @@ void WaitForNavigation(NavigationController* controller) { void WaitForNavigations(NavigationController* controller, int number_of_navigations) { - TestNavigationObserver observer(controller, NULL, number_of_navigations); - observer.WaitForObservation(); + NavigationNotificationObserver observer( + Source<NavigationController>(controller), number_of_navigations); + observer.Run(); } void WaitForNewTab(Browser* browser) { @@ -326,6 +388,12 @@ void OpenURLOffTheRecord(Profile* profile, const GURL& url) { WaitForNavigations(&browser->GetSelectedTabContents()->controller(), 1); } +void NavigateToURL(browser::NavigateParams* params) { + NavigationNotificationObserver observer(NotificationService::AllSources(), 1); + browser::Navigate(params); + observer.Run(); +} + void NavigateToURL(Browser* browser, const GURL& url) { NavigateToURLWithDisposition(browser, url, CURRENT_TAB, BROWSER_TEST_WAIT_FOR_NAVIGATION); @@ -341,9 +409,10 @@ static void NavigateToURLWithDispositionBlockUntilNavigationsComplete( int number_of_navigations, WindowOpenDisposition disposition, int browser_test_flags) { - TestNavigationObserver - same_tab_observer(&browser->GetSelectedTabContents()->controller(), - NULL, number_of_navigations); + NavigationNotificationObserver same_tab_observer( + Source<NavigationController>( + &browser->GetSelectedTabContents()->controller()), + number_of_navigations); std::set<Browser*> initial_browsers; for (std::vector<Browser*>::const_iterator iter = BrowserList::begin(); @@ -375,7 +444,7 @@ static void NavigateToURLWithDispositionBlockUntilNavigationsComplete( tab_contents = browser->GetSelectedTabContents(); } if (disposition == CURRENT_TAB) { - same_tab_observer.WaitForObservation(); + same_tab_observer.Run(); return; } else if (tab_contents) { NavigationController* controller = &tab_contents->controller(); |