diff options
author | phajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-06-05 19:49:46 +0000 |
---|---|---|
committer | phajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-06-05 19:49:46 +0000 |
commit | cbb1ef59113ed769bb779553e68eafa7ec593852 (patch) | |
tree | 366cb8a021a0287ececd15c1193c65f8f0312863 | |
parent | dc00f4ffea2d2274b50671690580683ba1226f6b (diff) | |
download | chromium_src-cbb1ef59113ed769bb779553e68eafa7ec593852.zip chromium_src-cbb1ef59113ed769bb779553e68eafa7ec593852.tar.gz chromium_src-cbb1ef59113ed769bb779553e68eafa7ec593852.tar.bz2 |
content: Remove usage of NOTIFICATION_NAV_ENTRY_COMMITTED from content
BUG=170921
R=avi@chromium.org, jam@chromium.org
Review URL: https://codereview.chromium.org/16273003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@204320 0039d316-1c4b-4281-b951-d872f2087c98
34 files changed, 424 insertions, 264 deletions
diff --git a/chrome/browser/browser_encoding_browsertest.cc b/chrome/browser/browser_encoding_browsertest.cc index f793170..976c4b1 100644 --- a/chrome/browser/browser_encoding_browsertest.cc +++ b/chrome/browser/browser_encoding_browsertest.cc @@ -195,9 +195,7 @@ IN_PROC_BROWSER_TEST_F(BrowserEncodingTest, TestOverrideEncoding) { // Override the encoding to "gb18030". const std::string selected_encoding = CharacterEncoding::GetCanonicalEncodingNameByAliasName("gb18030"); - content::TestNavigationObserver navigation_observer( - content::Source<content::NavigationController>( - &web_contents->GetController())); + content::TestNavigationObserver navigation_observer(web_contents); web_contents->SetOverrideEncoding(selected_encoding); navigation_observer.Wait(); EXPECT_EQ("gb18030", web_contents->GetEncoding()); @@ -316,9 +314,7 @@ IN_PROC_BROWSER_TEST_F(BrowserEncodingTest, MAYBE_TestEncodingAutoDetect) { browser()->profile()->GetPrefs()->SetBoolean( prefs::kWebKitUsesUniversalDetector, true); - content::TestNavigationObserver observer( - content::Source<content::NavigationController>( - &web_contents->GetController())); + content::TestNavigationObserver observer(web_contents); chrome::Reload(browser(), CURRENT_TAB); observer.Wait(); diff --git a/chrome/browser/download/download_browsertest.cc b/chrome/browser/download/download_browsertest.cc index fdf9ba5..1265bec 100644 --- a/chrome/browser/download/download_browsertest.cc +++ b/chrome/browser/download/download_browsertest.cc @@ -1177,10 +1177,7 @@ IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadResourceThrottleCancels) { // Try to start the download via Javascript and wait for the corresponding // load stop event. - content::TestNavigationObserver observer( - content::Source<content::NavigationController>( - &web_contents->GetController()), - 1); + content::TestNavigationObserver observer(web_contents); bool download_assempted; ASSERT_TRUE(content::ExecuteScriptAndExtractBool( browser()->tab_strip_model()->GetActiveWebContents(), diff --git a/chrome/browser/errorpage_browsertest.cc b/chrome/browser/errorpage_browsertest.cc index 5195a7e..bc9f725 100644 --- a/chrome/browser/errorpage_browsertest.cc +++ b/chrome/browser/errorpage_browsertest.cc @@ -96,9 +96,7 @@ class ErrorPageTest : public InProcessBrowserTest { ASCIIToUTF16(expected_title)); content::TestNavigationObserver test_navigation_observer( - content::Source<NavigationController>( - &browser()->tab_strip_model()->GetActiveWebContents()-> - GetController()), + browser()->tab_strip_model()->GetActiveWebContents(), num_navigations); if (direction == HISTORY_NAVIGATE_BACK) { chrome::GoBack(browser(), CURRENT_TAB); diff --git a/chrome/browser/extensions/app_process_apitest.cc b/chrome/browser/extensions/app_process_apitest.cc index 42151e1..545f94b 100644 --- a/chrome/browser/extensions/app_process_apitest.cc +++ b/chrome/browser/extensions/app_process_apitest.cc @@ -676,8 +676,9 @@ IN_PROC_BROWSER_TEST_F(AppApiTest, ServerRedirectToAppFromExtension) { // 2. The app's URL (which includes a server redirect). // Note that the server redirect does not generate a navigation event. content::TestNavigationObserver test_navigation_observer( - content::NotificationService::AllSources(), + browser()->tab_strip_model()->GetActiveWebContents(), 2); + test_navigation_observer.StartWatchingNewWebContents(); // Load the launcher extension, which should launch the app. ui_test_utils::NavigateToURLWithDisposition( @@ -717,8 +718,9 @@ IN_PROC_BROWSER_TEST_F(AppApiTest, ClientRedirectToAppFromExtension) { // 2. The URL that the extension launches, which client redirects. // 3. The app's URL. content::TestNavigationObserver test_navigation_observer( - content::NotificationService::AllSources(), + browser()->tab_strip_model()->GetActiveWebContents(), 3); + test_navigation_observer.StartWatchingNewWebContents(); // Load the launcher extension, which should launch the app. ui_test_utils::NavigateToURLWithDisposition( diff --git a/chrome/browser/history/redirect_browsertest.cc b/chrome/browser/history/redirect_browsertest.cc index 0948696..527767f 100644 --- a/chrome/browser/history/redirect_browsertest.cc +++ b/chrome/browser/history/redirect_browsertest.cc @@ -162,9 +162,7 @@ IN_PROC_BROWSER_TEST_F(RedirectTest, ClientCancelled) { content::WebContents* web_contents = browser()->tab_strip_model()->GetActiveWebContents(); - content::TestNavigationObserver navigation_observer( - content::Source<content::NavigationController>( - &web_contents->GetController())); + content::TestNavigationObserver navigation_observer(web_contents); // Simulate a click to force to make a user-initiated location change; // otherwise, a non user-initiated in-page location change will be treated @@ -279,10 +277,7 @@ IN_PROC_BROWSER_TEST_F(RedirectTest, content::WebContents* web_contents = browser()->tab_strip_model()->GetActiveWebContents(); - content::TestNavigationObserver observer( - content::Source<content::NavigationController>( - &web_contents->GetController()), - 2); + content::TestNavigationObserver observer(web_contents, 2); ui_test_utils::NavigateToURLWithDisposition( browser(), first_url, CURRENT_TAB, ui_test_utils::BROWSER_TEST_NONE); diff --git a/chrome/browser/managed_mode/managed_mode_resource_throttle_browsertest.cc b/chrome/browser/managed_mode/managed_mode_resource_throttle_browsertest.cc index 407f775..46ab88f 100644 --- a/chrome/browser/managed_mode/managed_mode_resource_throttle_browsertest.cc +++ b/chrome/browser/managed_mode/managed_mode_resource_throttle_browsertest.cc @@ -62,8 +62,7 @@ IN_PROC_BROWSER_TEST_F(ManagedModeResourceThrottleTest, scoped_ptr<WebContents> web_contents( WebContents::Create(WebContents::CreateParams(profile))); NavigationController& controller = web_contents->GetController(); - content::TestNavigationObserver observer( - content::Source<NavigationController>(&controller), 1); + content::TestNavigationObserver observer(web_contents.get()); controller.LoadURL(GURL("http://www.example.com"), content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); observer.Wait(); diff --git a/chrome/browser/performance_monitor/performance_monitor_browsertest.cc b/chrome/browser/performance_monitor/performance_monitor_browsertest.cc index 425d755..535bb34 100644 --- a/chrome/browser/performance_monitor/performance_monitor_browsertest.cc +++ b/chrome/browser/performance_monitor/performance_monitor_browsertest.cc @@ -371,12 +371,12 @@ class PerformanceMonitorSessionRestoreBrowserTest observer.Wait(); // Create a new window, which should trigger session restore. + content::TestNavigationObserver restore_observer(NULL, expected_tab_count); + restore_observer.StartWatchingNewWebContents(); ui_test_utils::BrowserAddedObserver window_observer; - content::TestNavigationObserver navigation_observer( - content::NotificationService::AllSources(), expected_tab_count); chrome::NewEmptyWindow(profile, chrome::HOST_DESKTOP_TYPE_NATIVE); Browser* new_browser = window_observer.WaitForSingleNewBrowser(); - navigation_observer.Wait(); + restore_observer.Wait(); g_browser_process->ReleaseModule(); return new_browser; diff --git a/chrome/browser/policy/policy_browsertest.cc b/chrome/browser/policy/policy_browsertest.cc index 5f2c495..b4b36c27 100644 --- a/chrome/browser/policy/policy_browsertest.cc +++ b/chrome/browser/policy/policy_browsertest.cc @@ -807,7 +807,7 @@ IN_PROC_BROWSER_TEST_F(PolicyTest, ForceSafeSearch) { // First check that nothing happens. content::TestNavigationObserver no_safesearch_observer( - content::NotificationService::AllSources()); + browser()->tab_strip_model()->GetActiveWebContents()); chrome::FocusLocationBar(browser()); LocationBar* location_bar = browser()->window()->GetLocationBar(); ui_test_utils::SendToOmniboxAndSubmit(location_bar, "http://google.com/"); @@ -833,7 +833,7 @@ IN_PROC_BROWSER_TEST_F(PolicyTest, ForceSafeSearch) { EXPECT_TRUE(prefs->GetBoolean(prefs::kForceSafeSearch)); content::TestNavigationObserver safesearch_observer( - content::NotificationService::AllSources()); + browser()->tab_strip_model()->GetActiveWebContents()); // Verify that searching from google.com works. chrome::FocusLocationBar(browser()); diff --git a/chrome/browser/prerender/prerender_browsertest.cc b/chrome/browser/prerender/prerender_browsertest.cc index 39a211f..6503a7c 100644 --- a/chrome/browser/prerender/prerender_browsertest.cc +++ b/chrome/browser/prerender/prerender_browsertest.cc @@ -1195,7 +1195,8 @@ class PrerenderBrowserTest : virtual public InProcessBrowserTest { // We don't expect to pick up a running prerender, so instead // observe one navigation. content::TestNavigationObserver observer( - content::NotificationService::AllSources(), 1); + current_browser()->tab_strip_model()->GetActiveWebContents()); + observer.StartWatchingNewWebContents(); base::RunLoop run_loop; observer.WaitForObservation( base::Bind(&content::RunThisRunLoop, diff --git a/chrome/browser/repost_form_warning_browsertest.cc b/chrome/browser/repost_form_warning_browsertest.cc index c13bed6..eab3f1a 100644 --- a/chrome/browser/repost_form_warning_browsertest.cc +++ b/chrome/browser/repost_form_warning_browsertest.cc @@ -85,8 +85,7 @@ IN_PROC_BROWSER_TEST_F(RepostFormWarningTest, TestLoginAfterRepost) { // Navigate away from the page. We can't use ui_test_utils:NavigateToURL // because that waits for the current page to stop loading first, which won't // happen while the auth dialog is up. - content::Source<content::NavigationController> source(&controller); - content::TestNavigationObserver navigation_observer(source); + content::TestNavigationObserver navigation_observer(web_contents); browser()->OpenURL(content::OpenURLParams( test_server()->GetURL("bar"), content::Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_TYPED, false)); diff --git a/chrome/browser/sessions/session_restore.cc b/chrome/browser/sessions/session_restore.cc index 3f353c6..44331cf 100644 --- a/chrome/browser/sessions/session_restore.cc +++ b/chrome/browser/sessions/session_restore.cc @@ -301,6 +301,15 @@ void TabLoader::LoadNextTab() { base::TimeDelta::FromMilliseconds(force_load_delay_), this, &TabLoader::ForceLoadTimerFired); } + + // When the session restore is done synchronously, notification is sent from + // SessionRestoreImpl::Restore . + if (tabs_to_load_.empty() && !SessionRestore::IsRestoringSynchronously()) { + content::NotificationService::current()->Notify( + chrome::NOTIFICATION_SESSION_RESTORE_DONE, + content::NotificationService::AllSources(), + content::NotificationService::NoDetails()); + } } void TabLoader::Observe(int type, diff --git a/chrome/browser/sessions/session_restore_browsertest.cc b/chrome/browser/sessions/session_restore_browsertest.cc index 32dff96..03f5349 100644 --- a/chrome/browser/sessions/session_restore_browsertest.cc +++ b/chrome/browser/sessions/session_restore_browsertest.cc @@ -132,8 +132,9 @@ class SessionRestoreTest : public InProcessBrowserTest { // Create a new window, which should trigger session restore. ui_test_utils::BrowserAddedObserver window_observer; - content::TestNavigationObserver navigation_observer( - content::NotificationService::AllSources(), expected_tab_count); + content::WindowedNotificationObserver restore_observer( + chrome::NOTIFICATION_SESSION_RESTORE_DONE, + content::NotificationService::AllSources()); if (url.is_empty()) { chrome::NewEmptyWindow(profile, chrome::HOST_DESKTOP_TYPE_NATIVE); } else { @@ -143,24 +144,22 @@ class SessionRestoreTest : public InProcessBrowserTest { chrome::Navigate(¶ms); } Browser* new_browser = window_observer.WaitForSingleNewBrowser(); - navigation_observer.Wait(); + restore_observer.Wait(); g_browser_process->ReleaseModule(); return new_browser; } void GoBack(Browser* browser) { - content::WindowedNotificationObserver observer( - content::NOTIFICATION_LOAD_STOP, - content::NotificationService::AllSources()); + content::TestNavigationObserver observer( + browser->tab_strip_model()->GetActiveWebContents()); chrome::GoBack(browser, CURRENT_TAB); observer.Wait(); } void GoForward(Browser* browser) { - content::WindowedNotificationObserver observer( - content::NOTIFICATION_LOAD_STOP, - content::NotificationService::AllSources()); + content::TestNavigationObserver observer( + browser->tab_strip_model()->GetActiveWebContents()); chrome::GoForward(browser, CURRENT_TAB); observer.Wait(); } diff --git a/chrome/browser/ui/browser_browsertest.cc b/chrome/browser/ui/browser_browsertest.cc index a0b07ad..364d620 100644 --- a/chrome/browser/ui/browser_browsertest.cc +++ b/chrome/browser/ui/browser_browsertest.cc @@ -2023,11 +2023,7 @@ class ClickModifierTest : public InProcessBrowserTest { if (disposition == CURRENT_TAB) { content::WebContents* web_contents = browser->tab_strip_model()->GetActiveWebContents(); - NavigationController* controller = - web_contents ? &web_contents->GetController() : NULL; - content::TestNavigationObserver same_tab_observer( - content::Source<NavigationController>(controller), - 1); + content::TestNavigationObserver same_tab_observer(web_contents); SimulateMouseClick(web_contents, modifiers, button); base::RunLoop run_loop; same_tab_observer.WaitForObservation( diff --git a/chrome/browser/ui/fullscreen/fullscreen_controller_test.cc b/chrome/browser/ui/fullscreen/fullscreen_controller_test.cc index 1880eee..09afc17 100644 --- a/chrome/browser/ui/fullscreen/fullscreen_controller_test.cc +++ b/chrome/browser/ui/fullscreen/fullscreen_controller_test.cc @@ -86,19 +86,15 @@ void FullscreenControllerTest::DenyCurrentFullscreenOrMouseLockRequest() { void FullscreenControllerTest::GoBack() { content::TestNavigationObserver observer( - content::NotificationService::AllSources(), 1); - + browser()->tab_strip_model()->GetActiveWebContents(), 1); chrome::GoBack(browser(), CURRENT_TAB); - observer.Wait(); } void FullscreenControllerTest::Reload() { content::TestNavigationObserver observer( - content::NotificationService::AllSources(), 1); - + browser()->tab_strip_model()->GetActiveWebContents(), 1); chrome::Reload(browser(), CURRENT_TAB); - observer.Wait(); } diff --git a/chrome/browser/ui/webui/bookmarks_ui_browsertest.cc b/chrome/browser/ui/webui/bookmarks_ui_browsertest.cc index 2053948..fd0161c 100644 --- a/chrome/browser/ui/webui/bookmarks_ui_browsertest.cc +++ b/chrome/browser/ui/webui/bookmarks_ui_browsertest.cc @@ -22,7 +22,8 @@ class BookmarksTest : public InProcessBrowserTest { void OpenBookmarksManager() { content::TestNavigationObserver navigation_observer( - content::NotificationService::AllSources(), 2); + browser()->tab_strip_model()->GetActiveWebContents(), 2); + navigation_observer.StartWatchingNewWebContents(); // Bring up the bookmarks manager tab. chrome::ShowBookmarkManager(browser()); @@ -92,7 +93,7 @@ IN_PROC_BROWSER_TEST_F(BookmarksTest, IN_PROC_BROWSER_TEST_F(BookmarksTest, TwoCommandsOneTab) { content::TestNavigationObserver navigation_observer( - content::NotificationService::AllSources()); + browser()->tab_strip_model()->GetActiveWebContents()); chrome::ShowBookmarkManager(browser()); chrome::ShowBookmarkManager(browser()); navigation_observer.Wait(); diff --git a/chrome/browser/ui/webui/ntp/new_tab_ui_browsertest.cc b/chrome/browser/ui/webui/ntp/new_tab_ui_browsertest.cc index 3b571c9..6a7f072 100644 --- a/chrome/browser/ui/webui/ntp/new_tab_ui_browsertest.cc +++ b/chrome/browser/ui/webui/ntp/new_tab_ui_browsertest.cc @@ -158,7 +158,7 @@ IN_PROC_BROWSER_TEST_F(NewTabUIProcessPerTabTest, NavBeforeNTPCommits) { // We don't use ui_test_utils::NavigateToURLWithDisposition because that waits // for current loading to stop. content::TestNavigationObserver observer( - content::NotificationService::AllSources()); + browser()->tab_strip_model()->GetActiveWebContents()); browser()->OpenURL(OpenURLParams( GURL("data:text/html,hello world"), Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_TYPED, false)); diff --git a/chrome/browser/ui/webui/print_preview/print_preview_ui_browsertest.cc b/chrome/browser/ui/webui/print_preview/print_preview_ui_browsertest.cc index 2c59b1e..9f3b0b9 100644 --- a/chrome/browser/ui/webui/print_preview/print_preview_ui_browsertest.cc +++ b/chrome/browser/ui/webui/print_preview/print_preview_ui_browsertest.cc @@ -56,7 +56,7 @@ IN_PROC_BROWSER_TEST_F(PrintPreviewTest, PrintCommands) { ASSERT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ADVANCED_PRINT)); content::TestNavigationObserver reload_observer( - content::NotificationService::AllSources()); + browser()->tab_strip_model()->GetActiveWebContents()); chrome::Reload(browser(), CURRENT_TAB); reload_observer.Wait(); diff --git a/chrome/test/base/in_process_browser_test.cc b/chrome/test/base/in_process_browser_test.cc index d48f2b6..5cdbf8f 100644 --- a/chrome/test/base/in_process_browser_test.cc +++ b/chrome/test/base/in_process_browser_test.cc @@ -220,15 +220,12 @@ void InProcessBrowserTest::AddTabAtIndexToBrowser( int index, const GURL& url, content::PageTransition transition) { - content::TestNavigationObserver observer( - content::NotificationService::AllSources(), 1); - chrome::NavigateParams params(browser, url, transition); params.tabstrip_index = index; params.disposition = NEW_FOREGROUND_TAB; chrome::Navigate(¶ms); - observer.Wait(); + content::WaitForLoadStop(params.target_contents); } void InProcessBrowserTest::AddTabAtIndex( diff --git a/chrome/test/base/test_tab_strip_model_observer.cc b/chrome/test/base/test_tab_strip_model_observer.cc index 2b01c39..00cc3fc 100644 --- a/chrome/test/base/test_tab_strip_model_observer.cc +++ b/chrome/test/base/test_tab_strip_model_observer.cc @@ -38,7 +38,7 @@ class TestTabStripModelObserver::RenderViewHostInitializedObserver TestTabStripModelObserver::TestTabStripModelObserver( TabStripModel* tab_strip_model, content::JsInjectionReadyObserver* js_injection_ready_observer) - : TestNavigationObserver(1), + : TestNavigationObserver(NULL, 1), tab_strip_model_(tab_strip_model), rvh_created_callback_( base::Bind(&TestTabStripModelObserver::RenderViewHostCreated, @@ -79,6 +79,5 @@ void TestTabStripModelObserver::ObservePrintPreviewDialog( dialog_controller->GetPrintPreviewForContents(contents); if (!preview_dialog) return; - RegisterAsObserver(content::Source<content::NavigationController>( - &preview_dialog->GetController())); + RegisterAsObserver(preview_dialog); } diff --git a/chrome/test/base/ui_test_utils.cc b/chrome/test/base/ui_test_utils.cc index a30ad1c..a9c7458 100644 --- a/chrome/test/base/ui_test_utils.cc +++ b/chrome/test/base/ui_test_utils.cc @@ -193,9 +193,8 @@ bool GetCurrentTabTitle(const Browser* browser, string16* title) { void WaitForNavigations(NavigationController* controller, int number_of_navigations) { - content::TestNavigationObserver observer( - content::Source<NavigationController>(controller), - number_of_navigations); + content::TestNavigationObserver observer(controller->GetWebContents(), + number_of_navigations); base::RunLoop run_loop; observer.WaitForObservation( base::Bind(&content::RunThisRunLoop, base::Unretained(&run_loop)), @@ -226,13 +225,8 @@ Browser* OpenURLOffTheRecord(Profile* profile, const GURL& url) { } void NavigateToURL(chrome::NavigateParams* params) { - content::TestNavigationObserver observer( - content::NotificationService::AllSources(), 1); chrome::Navigate(params); - base::RunLoop run_loop; - observer.WaitForObservation( - base::Bind(&content::RunThisRunLoop, base::Unretained(&run_loop)), - content::GetQuitTaskForRunLoop(&run_loop)); + content::WaitForLoadStop(params->target_contents); } void NavigateToURL(Browser* browser, const GURL& url) { @@ -253,11 +247,8 @@ static void NavigateToURLWithDispositionBlockUntilNavigationsComplete( TabStripModel* tab_strip = browser->tab_strip_model(); if (disposition == CURRENT_TAB && tab_strip->GetActiveWebContents()) content::WaitForLoadStop(tab_strip->GetActiveWebContents()); - NavigationController* controller = - tab_strip->GetActiveWebContents() ? - &tab_strip->GetActiveWebContents()->GetController() : NULL; content::TestNavigationObserver same_tab_observer( - content::Source<NavigationController>(controller), + tab_strip->GetActiveWebContents(), number_of_navigations); std::set<Browser*> initial_browsers; diff --git a/chrome/test/base/web_ui_browsertest.cc b/chrome/test/base/web_ui_browsertest.cc index 082338b..3c72a52 100644 --- a/chrome/test/base/web_ui_browsertest.cc +++ b/chrome/test/base/web_ui_browsertest.cc @@ -267,10 +267,7 @@ void WebUIBrowserTest::PreLoadJavascriptLibraries( void WebUIBrowserTest::BrowsePreload(const GURL& browse_to) { WebUIJsInjectionReadyObserver injection_observer(this); content::TestNavigationObserver navigation_observer( - content::Source<NavigationController>( - &browser()->tab_strip_model()-> - GetActiveWebContents()->GetController()), - 1); + browser()->tab_strip_model()->GetActiveWebContents()); chrome::NavigateParams params(browser(), GURL(browse_to), content::PAGE_TRANSITION_TYPED); params.disposition = CURRENT_TAB; diff --git a/content/browser/renderer_host/render_view_host_manager_browsertest.cc b/content/browser/renderer_host/render_view_host_manager_browsertest.cc index 15f7a43..85ecdd4 100644 --- a/content/browser/renderer_host/render_view_host_manager_browsertest.cc +++ b/content/browser/renderer_host/render_view_host_manager_browsertest.cc @@ -23,6 +23,7 @@ #include "content/public/browser/web_contents_observer.h" #include "content/public/common/url_constants.h" #include "content/public/test/browser_test_utils.h" +#include "content/public/test/test_navigation_observer.h" #include "content/public/test/test_utils.h" #include "content/shell/shell.h" #include "content/test/content_browser_test.h" @@ -388,10 +389,7 @@ IN_PROC_BROWSER_TEST_F(RenderViewHostManagerTest, EXPECT_NE(orig_site_instance, new_site_instance); // Clicking the original link in the first tab should cause us to swap back. - WindowedNotificationObserver navigation_observer( - NOTIFICATION_NAV_ENTRY_COMMITTED, - Source<NavigationController>( - &new_shell->web_contents()->GetController())); + TestNavigationObserver navigation_observer(new_shell->web_contents()); EXPECT_TRUE(ExecuteScriptAndExtractBool( shell()->web_contents(), "window.domAutomationController.send(clickSameSiteTargetedLink());", @@ -476,10 +474,7 @@ IN_PROC_BROWSER_TEST_F(RenderViewHostManagerTest, DisownOpener) { // Go back and ensure the opener is still null. { - WindowedNotificationObserver back_nav_load_observer( - NOTIFICATION_NAV_ENTRY_COMMITTED, - Source<NavigationController>( - &new_shell->web_contents()->GetController())); + TestNavigationObserver back_nav_load_observer(new_shell->web_contents()); new_shell->web_contents()->GetController().GoBack(); back_nav_load_observer.Wait(); } @@ -716,10 +711,7 @@ IN_PROC_BROWSER_TEST_F(RenderViewHostManagerTest, EXPECT_NE(orig_site_instance, new_site_instance); // The opened tab should be able to navigate the opener back to its process. - WindowedNotificationObserver navigation_observer( - NOTIFICATION_NAV_ENTRY_COMMITTED, - Source<NavigationController>( - &orig_contents->GetController())); + TestNavigationObserver navigation_observer(orig_contents); EXPECT_TRUE(ExecuteScriptAndExtractBool( new_shell->web_contents(), "window.domAutomationController.send(navigateOpener());", @@ -1000,66 +992,48 @@ IN_PROC_BROWSER_TEST_F(RenderViewHostManagerTest, BackForwardNotStale) { // Go back three times to first site. { - WindowedNotificationObserver back_nav_load_observer( - NOTIFICATION_NAV_ENTRY_COMMITTED, - Source<NavigationController>( - &contents->GetController())); + TestNavigationObserver back_nav_load_observer(shell()->web_contents()); shell()->web_contents()->GetController().GoBack(); back_nav_load_observer.Wait(); } { - WindowedNotificationObserver back_nav_load_observer( - NOTIFICATION_NAV_ENTRY_COMMITTED, - Source<NavigationController>( - &contents->GetController())); + TestNavigationObserver back_nav_load_observer(shell()->web_contents()); shell()->web_contents()->GetController().GoBack(); back_nav_load_observer.Wait(); } { - WindowedNotificationObserver back_nav_load_observer( - NOTIFICATION_NAV_ENTRY_COMMITTED, - Source<NavigationController>(&contents->GetController())); + TestNavigationObserver back_nav_load_observer(shell()->web_contents()); shell()->web_contents()->GetController().GoBack(); back_nav_load_observer.Wait(); } // Now go forward twice to B2. Shouldn't be left spinning. { - WindowedNotificationObserver forward_nav_load_observer( - NOTIFICATION_NAV_ENTRY_COMMITTED, - Source<NavigationController>(&contents->GetController())); + TestNavigationObserver forward_nav_load_observer(shell()->web_contents()); shell()->web_contents()->GetController().GoForward(); forward_nav_load_observer.Wait(); } { - WindowedNotificationObserver forward_nav_load_observer( - NOTIFICATION_NAV_ENTRY_COMMITTED, - Source<NavigationController>(&contents->GetController())); + TestNavigationObserver forward_nav_load_observer(shell()->web_contents()); shell()->web_contents()->GetController().GoForward(); forward_nav_load_observer.Wait(); } // Go back twice to first site. { - WindowedNotificationObserver back_nav_load_observer( - NOTIFICATION_NAV_ENTRY_COMMITTED, - Source<NavigationController>(&contents->GetController())); + TestNavigationObserver back_nav_load_observer(shell()->web_contents()); shell()->web_contents()->GetController().GoBack(); back_nav_load_observer.Wait(); } { - WindowedNotificationObserver back_nav_load_observer( - NOTIFICATION_NAV_ENTRY_COMMITTED, - Source<NavigationController>(&contents->GetController())); + TestNavigationObserver back_nav_load_observer(shell()->web_contents()); shell()->web_contents()->GetController().GoBack(); back_nav_load_observer.Wait(); } // Now go forward directly to B3. Shouldn't be left spinning. { - WindowedNotificationObserver forward_nav_load_observer( - NOTIFICATION_NAV_ENTRY_COMMITTED, - Source<NavigationController>(&contents->GetController())); + TestNavigationObserver forward_nav_load_observer(shell()->web_contents()); shell()->web_contents()->GetController().GoToIndex(4); forward_nav_load_observer.Wait(); } @@ -1123,10 +1097,7 @@ IN_PROC_BROWSER_TEST_F(RenderViewHostManagerTest, // Going back should make the previously swapped-out view to become visible // again. { - WindowedNotificationObserver back_nav_load_observer( - NOTIFICATION_NAV_ENTRY_COMMITTED, - Source<NavigationController>( - &new_shell->web_contents()->GetController())); + TestNavigationObserver back_nav_load_observer(new_shell->web_contents()); new_shell->web_contents()->GetController().GoBack(); back_nav_load_observer.Wait(); } diff --git a/content/browser/web_contents/interstitial_page_impl.cc b/content/browser/web_contents/interstitial_page_impl.cc index 6543051..1c4c89f 100644 --- a/content/browser/web_contents/interstitial_page_impl.cc +++ b/content/browser/web_contents/interstitial_page_impl.cc @@ -225,8 +225,6 @@ void InterstitialPageImpl::Show() { net::EscapePath(delegate_->GetHTMLContents()); render_view_host_->NavigateToURL(GURL(data_url)); - notification_registrar_.Add(this, NOTIFICATION_NAV_ENTRY_COMMITTED, - Source<NavigationController>(&web_contents_->GetController())); notification_registrar_.Add(this, NOTIFICATION_NAV_ENTRY_PENDING, Source<NavigationController>(&web_contents_->GetController())); notification_registrar_.Add( @@ -322,9 +320,6 @@ void InterstitialPageImpl::Observe( TakeActionOnResourceDispatcher(CANCEL); } break; - case NOTIFICATION_NAV_ENTRY_COMMITTED: - OnNavigatingAwayOrTabClosing(); - break; case NOTIFICATION_DOM_OPERATION_RESPONSE: if (enabled()) { Details<DomOperationNotificationDetails> dom_op_details( @@ -337,6 +332,11 @@ void InterstitialPageImpl::Observe( } } +void InterstitialPageImpl::NavigationEntryCommitted( + const LoadCommittedDetails& load_details) { + OnNavigatingAwayOrTabClosing(); +} + void InterstitialPageImpl::WebContentsDestroyed(WebContents* web_contents) { OnNavigatingAwayOrTabClosing(); } diff --git a/content/browser/web_contents/interstitial_page_impl.h b/content/browser/web_contents/interstitial_page_impl.h index 476b062..8b5526e 100644 --- a/content/browser/web_contents/interstitial_page_impl.h +++ b/content/browser/web_contents/interstitial_page_impl.h @@ -93,6 +93,8 @@ class CONTENT_EXPORT InterstitialPageImpl // WebContentsObserver implementation: virtual void WebContentsDestroyed(WebContents* web_contents) OVERRIDE; + virtual void NavigationEntryCommitted( + const LoadCommittedDetails& load_details) OVERRIDE; // RenderViewHostDelegate implementation: virtual RenderViewHostDelegateView* GetDelegateView() OVERRIDE; diff --git a/content/browser/web_contents/navigation_controller_impl.cc b/content/browser/web_contents/navigation_controller_impl.cc index 7b90935..54c34e9 100644 --- a/content/browser/web_contents/navigation_controller_impl.cc +++ b/content/browser/web_contents/navigation_controller_impl.cc @@ -1581,6 +1581,8 @@ void NavigationControllerImpl::NotifyNavigationEntryCommitted( // notification below instead. web_contents_->NotifyNavigationStateChanged(kInvalidateAll); + web_contents_->NotifyNavigationEntryCommitted(*details); + NotificationService::current()->Notify( NOTIFICATION_NAV_ENTRY_COMMITTED, Source<NavigationController>(this), diff --git a/content/browser/web_contents/navigation_controller_impl_unittest.cc b/content/browser/web_contents/navigation_controller_impl_unittest.cc index 5298053..1a5a8fe 100644 --- a/content/browser/web_contents/navigation_controller_impl_unittest.cc +++ b/content/browser/web_contents/navigation_controller_impl_unittest.cc @@ -32,6 +32,7 @@ #include "content/public/browser/render_view_host.h" #include "content/public/browser/render_view_host_observer.h" #include "content/public/browser/web_contents_delegate.h" +#include "content/public/browser/web_contents_observer.h" #include "content/public/common/page_state.h" #include "content/public/test/mock_render_process_host.h" #include "content/public/test/test_notification_tracker.h" @@ -185,19 +186,36 @@ TEST(TimeSmoother, ClockBackwardsJump) { // NavigationControllerTest ---------------------------------------------------- -class NavigationControllerTest : public RenderViewHostImplTestHarness { +class NavigationControllerTest + : public RenderViewHostImplTestHarness, + public WebContentsObserver { public: - NavigationControllerTest() {} + NavigationControllerTest() : navigation_entry_committed_counter_(0) { + } + + virtual void SetUp() OVERRIDE { + RenderViewHostImplTestHarness::SetUp(); + WebContents* web_contents = RenderViewHostImplTestHarness::web_contents(); + ASSERT_TRUE(web_contents); // The WebContents should be created by now. + WebContentsObserver::Observe(web_contents); + } + + // WebContentsObserver: + virtual void NavigationEntryCommitted( + const LoadCommittedDetails& load_details) OVERRIDE { + navigation_entry_committed_counter_++; + } NavigationControllerImpl& controller_impl() { return static_cast<NavigationControllerImpl&>(controller()); } + + protected: + size_t navigation_entry_committed_counter_; }; void RegisterForAllNavNotifications(TestNotificationTracker* tracker, NavigationController* controller) { - tracker->ListenFor(NOTIFICATION_NAV_ENTRY_COMMITTED, - Source<NavigationController>(controller)); tracker->ListenFor(NOTIFICATION_NAV_LIST_PRUNED, Source<NavigationController>(controller)); tracker->ListenFor(NOTIFICATION_NAV_ENTRY_CHANGED, @@ -256,7 +274,8 @@ TEST_F(NavigationControllerTest, GoToOffset) { } test_rvh()->SendNavigate(0, urls[0]); - EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); + EXPECT_EQ(1U, navigation_entry_committed_counter_); + navigation_entry_committed_counter_ = 0; EXPECT_EQ(urls[0], controller.GetActiveEntry()->GetVirtualURL()); EXPECT_FALSE(controller.CanGoBack()); EXPECT_FALSE(controller.CanGoForward()); @@ -264,7 +283,8 @@ TEST_F(NavigationControllerTest, GoToOffset) { for (int i = 1; i <= 4; ++i) { test_rvh()->SendNavigate(i, urls[i]); - EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); + EXPECT_EQ(1U, navigation_entry_committed_counter_); + navigation_entry_committed_counter_ = 0; EXPECT_EQ(urls[i], controller.GetActiveEntry()->GetVirtualURL()); EXPECT_TRUE(controller.CanGoToOffset(-i)); EXPECT_FALSE(controller.CanGoToOffset(-(i + 1))); @@ -298,7 +318,8 @@ TEST_F(NavigationControllerTest, GoToOffset) { // Check that the GoToOffset will land on the expected page. EXPECT_EQ(urls[url_index], controller.GetPendingEntry()->GetVirtualURL()); test_rvh()->SendNavigate(url_index, urls[url_index]); - EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); + EXPECT_EQ(1U, navigation_entry_committed_counter_); + navigation_entry_committed_counter_ = 0; // Check that we can go to any valid offset into the history. for (size_t j = 0; j < urls.size(); ++j) EXPECT_TRUE(controller.CanGoToOffset(j - url_index)); @@ -340,7 +361,8 @@ TEST_F(NavigationControllerTest, LoadURL) { EXPECT_EQ(0U, notifications.size()); test_rvh()->SendNavigate(0, url1); - EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); + EXPECT_EQ(1U, navigation_entry_committed_counter_); + navigation_entry_committed_counter_ = 0; // The load should now be committed. EXPECT_EQ(controller.GetEntryCount(), 1); @@ -382,7 +404,8 @@ TEST_F(NavigationControllerTest, LoadURL) { test_rvh()->SendShouldCloseACK(true); static_cast<TestRenderViewHost*>( contents()->GetPendingRenderViewHost())->SendNavigate(1, url2); - EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); + EXPECT_EQ(1U, navigation_entry_committed_counter_); + navigation_entry_committed_counter_ = 0; // The load should now be committed. EXPECT_EQ(controller.GetEntryCount(), 2); @@ -422,7 +445,8 @@ TEST_F(NavigationControllerTest, LoadURLSameTime) { controller.LoadURL(url1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); test_rvh()->SendNavigate(0, url1); - EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); + EXPECT_EQ(1U, navigation_entry_committed_counter_); + navigation_entry_committed_counter_ = 0; // Load another... controller.LoadURL(url2, Referrer(), PAGE_TRANSITION_TYPED, std::string()); @@ -431,7 +455,8 @@ TEST_F(NavigationControllerTest, LoadURLSameTime) { // commit. test_rvh()->SendShouldCloseACK(true); test_rvh()->SendNavigate(1, url2); - EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); + EXPECT_EQ(1U, navigation_entry_committed_counter_); + navigation_entry_committed_counter_ = 0; // The two loads should now be committed. ASSERT_EQ(controller.GetEntryCount(), 2); @@ -553,7 +578,8 @@ TEST_F(NavigationControllerTest, LoadURL_SamePage) { controller.LoadURL(url1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); EXPECT_EQ(0U, notifications.size()); test_rvh()->SendNavigate(0, url1); - EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); + EXPECT_EQ(1U, navigation_entry_committed_counter_); + navigation_entry_committed_counter_ = 0; ASSERT_TRUE(controller.GetActiveEntry()); const base::Time timestamp = controller.GetActiveEntry()->GetTimestamp(); @@ -562,7 +588,8 @@ TEST_F(NavigationControllerTest, LoadURL_SamePage) { controller.LoadURL(url1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); EXPECT_EQ(0U, notifications.size()); test_rvh()->SendNavigate(0, url1); - EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); + EXPECT_EQ(1U, navigation_entry_committed_counter_); + navigation_entry_committed_counter_ = 0; // We should not have produced a new session history entry. EXPECT_EQ(controller.GetEntryCount(), 1); @@ -593,7 +620,8 @@ TEST_F(NavigationControllerTest, LoadURL_Discarded) { controller.LoadURL(url1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); EXPECT_EQ(0U, notifications.size()); test_rvh()->SendNavigate(0, url1); - EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); + EXPECT_EQ(1U, navigation_entry_committed_counter_); + navigation_entry_committed_counter_ = 0; ASSERT_TRUE(controller.GetActiveEntry()); const base::Time timestamp = controller.GetActiveEntry()->GetTimestamp(); @@ -629,7 +657,8 @@ TEST_F(NavigationControllerTest, LoadURL_NoPending) { controller.LoadURL( kExistingURL1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); test_rvh()->SendNavigate(0, kExistingURL1); - EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); + EXPECT_EQ(1U, navigation_entry_committed_counter_); + navigation_entry_committed_counter_ = 0; // Do a new navigation without making a pending one. const GURL kNewURL("http://see"); @@ -637,7 +666,8 @@ TEST_F(NavigationControllerTest, LoadURL_NoPending) { // There should no longer be any pending entry, and the third navigation we // just made should be committed. - EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); + EXPECT_EQ(1U, navigation_entry_committed_counter_); + navigation_entry_committed_counter_ = 0; EXPECT_EQ(-1, controller.GetPendingEntryIndex()); EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); EXPECT_EQ(kNewURL, controller.GetActiveEntry()->GetURL()); @@ -657,7 +687,8 @@ TEST_F(NavigationControllerTest, LoadURL_NewPending) { controller.LoadURL( kExistingURL1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); test_rvh()->SendNavigate(0, kExistingURL1); - EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); + EXPECT_EQ(1U, navigation_entry_committed_counter_); + navigation_entry_committed_counter_ = 0; // Make a pending entry to somewhere new. const GURL kExistingURL2("http://bee"); @@ -673,7 +704,8 @@ TEST_F(NavigationControllerTest, LoadURL_NewPending) { // There should no longer be any pending entry, and the third navigation we // just made should be committed. - EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); + EXPECT_EQ(1U, navigation_entry_committed_counter_); + navigation_entry_committed_counter_ = 0; EXPECT_EQ(-1, controller.GetPendingEntryIndex()); EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); EXPECT_EQ(kNewURL, controller.GetActiveEntry()->GetURL()); @@ -692,13 +724,15 @@ TEST_F(NavigationControllerTest, LoadURL_ExistingPending) { controller.LoadURL( kExistingURL1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); test_rvh()->SendNavigate(0, kExistingURL1); - EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); + EXPECT_EQ(1U, navigation_entry_committed_counter_); + navigation_entry_committed_counter_ = 0; const GURL kExistingURL2("http://foo/bee"); controller.LoadURL( kExistingURL2, Referrer(), PAGE_TRANSITION_TYPED, std::string()); test_rvh()->SendNavigate(1, kExistingURL2); - EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); + EXPECT_EQ(1U, navigation_entry_committed_counter_); + navigation_entry_committed_counter_ = 0; // Now make a pending back/forward navigation. The zeroth entry should be // pending. @@ -714,7 +748,8 @@ TEST_F(NavigationControllerTest, LoadURL_ExistingPending) { // There should no longer be any pending entry, and the third navigation we // just made should be committed. - EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); + EXPECT_EQ(1U, navigation_entry_committed_counter_); + navigation_entry_committed_counter_ = 0; EXPECT_EQ(-1, controller.GetPendingEntryIndex()); EXPECT_EQ(2, controller.GetLastCommittedEntryIndex()); EXPECT_EQ(kNewURL, controller.GetActiveEntry()->GetURL()); @@ -735,7 +770,8 @@ TEST_F(NavigationControllerTest, LoadURL_PrivilegedPending) { // Pretend it has bindings so we can tell if we incorrectly copy it. test_rvh()->AllowBindings(2); test_rvh()->SendNavigate(0, kExistingURL1); - EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); + EXPECT_EQ(1U, navigation_entry_committed_counter_); + navigation_entry_committed_counter_ = 0; // Navigate cross-process to a second URL. const GURL kExistingURL2("http://foo/eh"); @@ -745,7 +781,8 @@ TEST_F(NavigationControllerTest, LoadURL_PrivilegedPending) { TestRenderViewHost* foo_rvh = static_cast<TestRenderViewHost*>( contents()->GetPendingRenderViewHost()); foo_rvh->SendNavigate(1, kExistingURL2); - EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); + EXPECT_EQ(1U, navigation_entry_committed_counter_); + navigation_entry_committed_counter_ = 0; // Now make a pending back/forward navigation to a privileged entry. // The zeroth entry should be pending. @@ -764,7 +801,8 @@ TEST_F(NavigationControllerTest, LoadURL_PrivilegedPending) { // There should no longer be any pending entry, and the third navigation we // just made should be committed. - EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); + EXPECT_EQ(1U, navigation_entry_committed_counter_); + navigation_entry_committed_counter_ = 0; EXPECT_EQ(-1, controller.GetPendingEntryIndex()); EXPECT_EQ(2, controller.GetLastCommittedEntryIndex()); EXPECT_EQ(kNewURL, controller.GetActiveEntry()->GetURL()); @@ -785,13 +823,15 @@ TEST_F(NavigationControllerTest, LoadURL_BackPreemptsPending) { controller.LoadURL( kExistingURL1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); test_rvh()->SendNavigate(0, kExistingURL1); - EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); + EXPECT_EQ(1U, navigation_entry_committed_counter_); + navigation_entry_committed_counter_ = 0; const GURL kExistingURL2("http://foo/bee"); controller.LoadURL( kExistingURL2, Referrer(), PAGE_TRANSITION_TYPED, std::string()); test_rvh()->SendNavigate(1, kExistingURL2); - EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); + EXPECT_EQ(1U, navigation_entry_committed_counter_); + navigation_entry_committed_counter_ = 0; // Now make a pending new navigation. const GURL kNewURL("http://foo/see"); @@ -806,7 +846,8 @@ TEST_F(NavigationControllerTest, LoadURL_BackPreemptsPending) { // There should no longer be any pending entry, and the back navigation we // just made should be committed. - EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); + EXPECT_EQ(1U, navigation_entry_committed_counter_); + navigation_entry_committed_counter_ = 0; EXPECT_EQ(-1, controller.GetPendingEntryIndex()); EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); EXPECT_EQ(kExistingURL1, controller.GetActiveEntry()->GetURL()); @@ -918,8 +959,8 @@ TEST_F(NavigationControllerTest, LoadURL_RedirectAbortDoesntShowPendingURL) { controller.LoadURL(kExistingURL, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); test_rvh()->SendNavigate(0, kExistingURL); - EXPECT_TRUE(notifications.Check1AndReset( - content::NOTIFICATION_NAV_ENTRY_COMMITTED)); + EXPECT_EQ(1U, navigation_entry_committed_counter_); + navigation_entry_committed_counter_ = 0; // Set a WebContentsDelegate to listen for state changes. scoped_ptr<TestWebContentsDelegate> delegate(new TestWebContentsDelegate()); @@ -1038,7 +1079,8 @@ TEST_F(NavigationControllerTest, Reload) { controller.LoadURL(url1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); EXPECT_EQ(0U, notifications.size()); test_rvh()->SendNavigate(0, url1); - EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); + EXPECT_EQ(1U, navigation_entry_committed_counter_); + navigation_entry_committed_counter_ = 0; ASSERT_TRUE(controller.GetActiveEntry()); controller.GetActiveEntry()->SetTitle(ASCIIToUTF16("Title")); controller.Reload(true); @@ -1061,7 +1103,8 @@ TEST_F(NavigationControllerTest, Reload) { EXPECT_TRUE(controller.GetActiveEntry()->GetTitle().empty()); test_rvh()->SendNavigate(0, url1); - EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); + EXPECT_EQ(1U, navigation_entry_committed_counter_); + navigation_entry_committed_counter_ = 0; // Now the reload is committed. EXPECT_EQ(controller.GetEntryCount(), 1); @@ -1088,13 +1131,15 @@ TEST_F(NavigationControllerTest, Reload_GeneratesNewPage) { controller.LoadURL(url1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); test_rvh()->SendNavigate(0, url1); - EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); + EXPECT_EQ(1U, navigation_entry_committed_counter_); + navigation_entry_committed_counter_ = 0; controller.Reload(true); EXPECT_EQ(0U, notifications.size()); test_rvh()->SendNavigate(1, url2); - EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); + EXPECT_EQ(1U, navigation_entry_committed_counter_); + navigation_entry_committed_counter_ = 0; // Now the reload is committed. EXPECT_EQ(controller.GetEntryCount(), 2); @@ -1140,7 +1185,8 @@ TEST_F(NavigationControllerTest, ReloadOriginalRequestURL) { original_url, Referrer(), PAGE_TRANSITION_TYPED, std::string()); EXPECT_EQ(0U, notifications.size()); test_rvh()->SendNavigateWithOriginalRequestURL(0, final_url, original_url); - EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); + EXPECT_EQ(1U, navigation_entry_committed_counter_); + navigation_entry_committed_counter_ = 0; // The NavigationEntry should save both the original URL and the final // redirected URL. @@ -1169,7 +1215,8 @@ TEST_F(NavigationControllerTest, ReloadOriginalRequestURL) { // Send that the navigation has proceeded; say it got redirected again. test_rvh()->SendNavigate(0, final_url); - EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); + EXPECT_EQ(1U, navigation_entry_committed_counter_); + navigation_entry_committed_counter_ = 0; // Now the reload is committed. EXPECT_EQ(controller.GetEntryCount(), 1); @@ -1191,11 +1238,13 @@ TEST_F(NavigationControllerTest, Back) { const GURL url1("http://foo1"); test_rvh()->SendNavigate(0, url1); - EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); + EXPECT_EQ(1U, navigation_entry_committed_counter_); + navigation_entry_committed_counter_ = 0; const GURL url2("http://foo2"); test_rvh()->SendNavigate(1, url2); - EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); + EXPECT_EQ(1U, navigation_entry_committed_counter_); + navigation_entry_committed_counter_ = 0; controller.GoBack(); EXPECT_EQ(0U, notifications.size()); @@ -1218,7 +1267,8 @@ TEST_F(NavigationControllerTest, Back) { controller.GetEntryAtIndex(0)->GetTimestamp()); test_rvh()->SendNavigate(0, url2); - EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); + EXPECT_EQ(1U, navigation_entry_committed_counter_); + navigation_entry_committed_counter_ = 0; // The back navigation completed successfully. EXPECT_EQ(controller.GetEntryCount(), 2); @@ -1251,12 +1301,13 @@ TEST_F(NavigationControllerTest, Back_GeneratesNewPage) { controller.LoadURL( url1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); test_rvh()->SendNavigate(0, url1); - EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); + EXPECT_EQ(1U, navigation_entry_committed_counter_); + navigation_entry_committed_counter_ = 0; controller.LoadURL(url2, Referrer(), PAGE_TRANSITION_TYPED, std::string()); test_rvh()->SendNavigate(1, url2); - EXPECT_TRUE(notifications.Check1AndReset( - NOTIFICATION_NAV_ENTRY_COMMITTED)); + EXPECT_EQ(1U, navigation_entry_committed_counter_); + navigation_entry_committed_counter_ = 0; controller.GoBack(); EXPECT_EQ(0U, notifications.size()); @@ -1271,7 +1322,8 @@ TEST_F(NavigationControllerTest, Back_GeneratesNewPage) { EXPECT_TRUE(controller.CanGoForward()); test_rvh()->SendNavigate(2, url3); - EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); + EXPECT_EQ(1U, navigation_entry_committed_counter_); + navigation_entry_committed_counter_ = 0; // The back navigation resulted in a completely new navigation. // TODO(darin): perhaps this behavior will be confusing to users? @@ -1296,11 +1348,13 @@ TEST_F(NavigationControllerTest, Back_NewPending) { // First navigate two places so we have some back history. test_rvh()->SendNavigate(0, kUrl1); - EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); + EXPECT_EQ(1U, navigation_entry_committed_counter_); + navigation_entry_committed_counter_ = 0; // controller.LoadURL(kUrl2, PAGE_TRANSITION_TYPED); test_rvh()->SendNavigate(1, kUrl2); - EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); + EXPECT_EQ(1U, navigation_entry_committed_counter_); + navigation_entry_committed_counter_ = 0; // Now start a new pending navigation and go back before it commits. controller.LoadURL(kUrl3, Referrer(), PAGE_TRANSITION_TYPED, std::string()); @@ -1373,14 +1427,17 @@ TEST_F(NavigationControllerTest, Forward) { const GURL url2("http://foo2"); test_rvh()->SendNavigate(0, url1); - EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); + EXPECT_EQ(1U, navigation_entry_committed_counter_); + navigation_entry_committed_counter_ = 0; test_rvh()->SendNavigate(1, url2); - EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); + EXPECT_EQ(1U, navigation_entry_committed_counter_); + navigation_entry_committed_counter_ = 0; controller.GoBack(); test_rvh()->SendNavigate(0, url1); - EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); + EXPECT_EQ(1U, navigation_entry_committed_counter_); + navigation_entry_committed_counter_ = 0; controller.GoForward(); @@ -1403,7 +1460,8 @@ TEST_F(NavigationControllerTest, Forward) { controller.GetEntryAtIndex(1)->GetTimestamp()); test_rvh()->SendNavigate(1, url2); - EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); + EXPECT_EQ(1U, navigation_entry_committed_counter_); + navigation_entry_committed_counter_ = 0; // The forward navigation completed successfully. EXPECT_EQ(controller.GetEntryCount(), 2); @@ -1434,13 +1492,16 @@ TEST_F(NavigationControllerTest, Forward_GeneratesNewPage) { const GURL url3("http://foo3"); test_rvh()->SendNavigate(0, url1); - EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); + EXPECT_EQ(1U, navigation_entry_committed_counter_); + navigation_entry_committed_counter_ = 0; test_rvh()->SendNavigate(1, url2); - EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); + EXPECT_EQ(1U, navigation_entry_committed_counter_); + navigation_entry_committed_counter_ = 0; controller.GoBack(); test_rvh()->SendNavigate(0, url1); - EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); + EXPECT_EQ(1U, navigation_entry_committed_counter_); + navigation_entry_committed_counter_ = 0; controller.GoForward(); EXPECT_EQ(0U, notifications.size()); @@ -1455,9 +1516,9 @@ TEST_F(NavigationControllerTest, Forward_GeneratesNewPage) { EXPECT_FALSE(controller.CanGoForward()); test_rvh()->SendNavigate(2, url3); - EXPECT_TRUE(notifications.Check2AndReset( - NOTIFICATION_NAV_LIST_PRUNED, - NOTIFICATION_NAV_ENTRY_COMMITTED)); + EXPECT_EQ(1U, navigation_entry_committed_counter_); + navigation_entry_committed_counter_ = 0; + EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_LIST_PRUNED)); EXPECT_EQ(controller.GetEntryCount(), 2); EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); @@ -1483,7 +1544,8 @@ TEST_F(NavigationControllerTest, Redirect) { EXPECT_EQ(0U, notifications.size()); test_rvh()->SendNavigate(0, url2); - EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); + EXPECT_EQ(1U, navigation_entry_committed_counter_); + navigation_entry_committed_counter_ = 0; // Second request controller.LoadURL(url1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); @@ -1507,7 +1569,8 @@ TEST_F(NavigationControllerTest, Redirect) { EXPECT_EQ(0U, notifications.size()); EXPECT_TRUE(controller.RendererDidNavigate(params, &details)); - EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); + EXPECT_EQ(1U, navigation_entry_committed_counter_); + navigation_entry_committed_counter_ = 0; EXPECT_TRUE(details.type == NAVIGATION_TYPE_SAME_PAGE); EXPECT_EQ(controller.GetEntryCount(), 1); @@ -1538,7 +1601,8 @@ TEST_F(NavigationControllerTest, PostThenRedirect) { EXPECT_EQ(0U, notifications.size()); test_rvh()->SendNavigate(0, url2); - EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); + EXPECT_EQ(1U, navigation_entry_committed_counter_); + navigation_entry_committed_counter_ = 0; // Second request controller.LoadURL(url1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); @@ -1562,7 +1626,8 @@ TEST_F(NavigationControllerTest, PostThenRedirect) { EXPECT_EQ(0U, notifications.size()); EXPECT_TRUE(controller.RendererDidNavigate(params, &details)); - EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); + EXPECT_EQ(1U, navigation_entry_committed_counter_); + navigation_entry_committed_counter_ = 0; EXPECT_TRUE(details.type == NAVIGATION_TYPE_SAME_PAGE); EXPECT_EQ(controller.GetEntryCount(), 1); @@ -1608,7 +1673,8 @@ TEST_F(NavigationControllerTest, ImmediateRedirect) { EXPECT_EQ(0U, notifications.size()); EXPECT_TRUE(controller.RendererDidNavigate(params, &details)); - EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); + EXPECT_EQ(1U, navigation_entry_committed_counter_); + navigation_entry_committed_counter_ = 0; EXPECT_TRUE(details.type == NAVIGATION_TYPE_NEW_PAGE); EXPECT_EQ(controller.GetEntryCount(), 1); @@ -1631,7 +1697,8 @@ TEST_F(NavigationControllerTest, NewSubframe) { const GURL url1("http://foo1"); test_rvh()->SendNavigate(0, url1); - EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); + EXPECT_EQ(1U, navigation_entry_committed_counter_); + navigation_entry_committed_counter_ = 0; const GURL url2("http://foo2"); ViewHostMsg_FrameNavigate_Params params; @@ -1645,7 +1712,8 @@ TEST_F(NavigationControllerTest, NewSubframe) { LoadCommittedDetails details; EXPECT_TRUE(controller.RendererDidNavigate(params, &details)); - EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); + EXPECT_EQ(1U, navigation_entry_committed_counter_); + navigation_entry_committed_counter_ = 0; EXPECT_EQ(url1, details.previous_url); EXPECT_FALSE(details.is_in_page); EXPECT_FALSE(details.is_main_frame); @@ -1692,7 +1760,8 @@ TEST_F(NavigationControllerTest, AutoSubframe) { const GURL url1("http://foo1"); test_rvh()->SendNavigate(0, url1); - EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); + EXPECT_EQ(1U, navigation_entry_committed_counter_); + navigation_entry_committed_counter_ = 0; const GURL url2("http://foo2"); ViewHostMsg_FrameNavigate_Params params; @@ -1722,7 +1791,8 @@ TEST_F(NavigationControllerTest, BackSubframe) { // Main page. const GURL url1("http://foo1"); test_rvh()->SendNavigate(0, url1); - EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); + EXPECT_EQ(1U, navigation_entry_committed_counter_); + navigation_entry_committed_counter_ = 0; // First manual subframe navigation. const GURL url2("http://foo2"); @@ -1738,7 +1808,8 @@ TEST_F(NavigationControllerTest, BackSubframe) { // This should generate a new entry. LoadCommittedDetails details; EXPECT_TRUE(controller.RendererDidNavigate(params, &details)); - EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); + EXPECT_EQ(1U, navigation_entry_committed_counter_); + navigation_entry_committed_counter_ = 0; EXPECT_EQ(2, controller.GetEntryCount()); // Second manual subframe navigation should also make a new entry. @@ -1746,7 +1817,8 @@ TEST_F(NavigationControllerTest, BackSubframe) { params.page_id = 2; params.url = url3; EXPECT_TRUE(controller.RendererDidNavigate(params, &details)); - EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); + EXPECT_EQ(1U, navigation_entry_committed_counter_); + navigation_entry_committed_counter_ = 0; EXPECT_EQ(3, controller.GetEntryCount()); EXPECT_EQ(2, controller.GetCurrentEntryIndex()); @@ -1755,7 +1827,8 @@ TEST_F(NavigationControllerTest, BackSubframe) { params.url = url2; params.page_id = 1; EXPECT_TRUE(controller.RendererDidNavigate(params, &details)); - EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); + EXPECT_EQ(1U, navigation_entry_committed_counter_); + navigation_entry_committed_counter_ = 0; EXPECT_EQ(3, controller.GetEntryCount()); EXPECT_EQ(1, controller.GetCurrentEntryIndex()); EXPECT_EQ(-1, controller.GetPendingEntryIndex()); @@ -1766,7 +1839,8 @@ TEST_F(NavigationControllerTest, BackSubframe) { params.url = url1; params.page_id = 0; EXPECT_TRUE(controller.RendererDidNavigate(params, &details)); - EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); + EXPECT_EQ(1U, navigation_entry_committed_counter_); + navigation_entry_committed_counter_ = 0; EXPECT_EQ(3, controller.GetEntryCount()); EXPECT_EQ(0, controller.GetCurrentEntryIndex()); EXPECT_EQ(-1, controller.GetPendingEntryIndex()); @@ -1782,10 +1856,12 @@ TEST_F(NavigationControllerTest, LinkClick) { const GURL url2("http://foo2"); test_rvh()->SendNavigate(0, url1); - EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); + EXPECT_EQ(1U, navigation_entry_committed_counter_); + navigation_entry_committed_counter_ = 0; test_rvh()->SendNavigate(1, url2); - EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); + EXPECT_EQ(1U, navigation_entry_committed_counter_); + navigation_entry_committed_counter_ = 0; // Should not have produced a new session history entry. EXPECT_EQ(controller.GetEntryCount(), 2); @@ -1805,7 +1881,8 @@ TEST_F(NavigationControllerTest, InPage) { // Main page. const GURL url1("http://foo"); test_rvh()->SendNavigate(0, url1); - EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); + EXPECT_EQ(1U, navigation_entry_committed_counter_); + navigation_entry_committed_counter_ = 0; // Ensure main page navigation to same url respects the was_within_same_page // hint provided in the params. @@ -1821,7 +1898,8 @@ TEST_F(NavigationControllerTest, InPage) { LoadCommittedDetails details; EXPECT_TRUE(controller.RendererDidNavigate(self_params, &details)); - EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); + EXPECT_EQ(1U, navigation_entry_committed_counter_); + navigation_entry_committed_counter_ = 0; EXPECT_TRUE(details.is_in_page); EXPECT_TRUE(details.did_replace_entry); EXPECT_EQ(1, controller.GetEntryCount()); @@ -1839,7 +1917,8 @@ TEST_F(NavigationControllerTest, InPage) { // This should generate a new entry. EXPECT_TRUE(controller.RendererDidNavigate(params, &details)); - EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); + EXPECT_EQ(1U, navigation_entry_committed_counter_); + navigation_entry_committed_counter_ = 0; EXPECT_TRUE(details.is_in_page); EXPECT_FALSE(details.did_replace_entry); EXPECT_EQ(2, controller.GetEntryCount()); @@ -1850,7 +1929,8 @@ TEST_F(NavigationControllerTest, InPage) { back_params.url = url1; back_params.page_id = 0; EXPECT_TRUE(controller.RendererDidNavigate(back_params, &details)); - EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); + EXPECT_EQ(1U, navigation_entry_committed_counter_); + navigation_entry_committed_counter_ = 0; // is_in_page is false in that case but should be true. // See comment in AreURLsInPageNavigation() in navigation_controller.cc // EXPECT_TRUE(details.is_in_page); @@ -1864,7 +1944,8 @@ TEST_F(NavigationControllerTest, InPage) { forward_params.url = url2; forward_params.page_id = 1; EXPECT_TRUE(controller.RendererDidNavigate(forward_params, &details)); - EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); + EXPECT_EQ(1U, navigation_entry_committed_counter_); + navigation_entry_committed_counter_ = 0; EXPECT_TRUE(details.is_in_page); EXPECT_EQ(2, controller.GetEntryCount()); EXPECT_EQ(1, controller.GetCurrentEntryIndex()); @@ -1886,9 +1967,10 @@ TEST_F(NavigationControllerTest, InPage) { const GURL url3("http://bar"); params.page_id = 2; params.url = url3; - notifications.Reset(); + navigation_entry_committed_counter_ = 0; EXPECT_TRUE(controller.RendererDidNavigate(params, &details)); - EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); + EXPECT_EQ(1U, navigation_entry_committed_counter_); + navigation_entry_committed_counter_ = 0; EXPECT_FALSE(details.is_in_page); EXPECT_EQ(3, controller.GetEntryCount()); EXPECT_EQ(2, controller.GetCurrentEntryIndex()); @@ -1902,7 +1984,8 @@ TEST_F(NavigationControllerTest, InPage_Replace) { // Main page. const GURL url1("http://foo"); test_rvh()->SendNavigate(0, url1); - EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); + EXPECT_EQ(1U, navigation_entry_committed_counter_); + navigation_entry_committed_counter_ = 0; // First navigation. const GURL url2("http://foo#a"); @@ -1918,7 +2001,8 @@ TEST_F(NavigationControllerTest, InPage_Replace) { // This should NOT generate a new entry, nor prune the list. LoadCommittedDetails details; EXPECT_TRUE(controller.RendererDidNavigate(params, &details)); - EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); + EXPECT_EQ(1U, navigation_entry_committed_counter_); + navigation_entry_committed_counter_ = 0; EXPECT_TRUE(details.is_in_page); EXPECT_TRUE(details.did_replace_entry); EXPECT_EQ(1, controller.GetEntryCount()); @@ -1939,14 +2023,16 @@ TEST_F(NavigationControllerTest, ClientRedirectAfterInPageNavigation) { { const GURL url("http://foo/"); test_rvh()->SendNavigate(0, url); - EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); + EXPECT_EQ(1U, navigation_entry_committed_counter_); + navigation_entry_committed_counter_ = 0; } // Navigate to a new page. { const GURL url("http://foo2/"); test_rvh()->SendNavigate(1, url); - EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); + EXPECT_EQ(1U, navigation_entry_committed_counter_); + navigation_entry_committed_counter_ = 0; } // Navigate within the page. @@ -1965,7 +2051,8 @@ TEST_F(NavigationControllerTest, ClientRedirectAfterInPageNavigation) { // This should NOT generate a new entry, nor prune the list. LoadCommittedDetails details; EXPECT_TRUE(controller.RendererDidNavigate(params, &details)); - EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); + EXPECT_EQ(1U, navigation_entry_committed_counter_); + navigation_entry_committed_counter_ = 0; EXPECT_TRUE(details.is_in_page); EXPECT_TRUE(details.did_replace_entry); EXPECT_EQ(2, controller.GetEntryCount()); @@ -1988,7 +2075,8 @@ TEST_F(NavigationControllerTest, ClientRedirectAfterInPageNavigation) { // This SHOULD generate a new entry. LoadCommittedDetails details; EXPECT_TRUE(controller.RendererDidNavigate(params, &details)); - EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); + EXPECT_EQ(1U, navigation_entry_committed_counter_); + navigation_entry_committed_counter_ = 0; EXPECT_FALSE(details.is_in_page); EXPECT_EQ(3, controller.GetEntryCount()); } @@ -1998,8 +2086,8 @@ TEST_F(NavigationControllerTest, ClientRedirectAfterInPageNavigation) { const GURL url("http://foo2/"); controller.GoBack(); test_rvh()->SendNavigate(1, url); - EXPECT_TRUE(notifications.Check1AndReset( - NOTIFICATION_NAV_ENTRY_COMMITTED)); + EXPECT_EQ(1U, navigation_entry_committed_counter_); + navigation_entry_committed_counter_ = 0; EXPECT_EQ(url, controller.GetActiveEntry()->GetURL()); } } @@ -3386,7 +3474,8 @@ TEST_F(NavigationControllerTest, IsInitialNavigation) { // After commit, it stays false. const GURL url1("http://foo1"); test_rvh()->SendNavigate(0, url1); - EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); + EXPECT_EQ(1U, navigation_entry_committed_counter_); + navigation_entry_committed_counter_ = 0; EXPECT_FALSE(controller.IsInitialNavigation()); // After starting a new navigation, it stays false. @@ -3408,8 +3497,8 @@ TEST_F(NavigationControllerTest, ClearFaviconOnRedirect) { RegisterForAllNavNotifications(¬ifications, &controller); test_rvh()->SendNavigate(0, kPageWithFavicon); - EXPECT_TRUE(notifications.Check1AndReset( - NOTIFICATION_NAV_ENTRY_COMMITTED)); + EXPECT_EQ(1U, navigation_entry_committed_counter_); + navigation_entry_committed_counter_ = 0; NavigationEntry* entry = controller.GetLastCommittedEntry(); EXPECT_TRUE(entry); @@ -3426,8 +3515,8 @@ TEST_F(NavigationControllerTest, ClearFaviconOnRedirect) { 0, // same page ID. kPageWithoutFavicon, PAGE_TRANSITION_CLIENT_REDIRECT); - EXPECT_TRUE(notifications.Check1AndReset( - NOTIFICATION_NAV_ENTRY_COMMITTED)); + EXPECT_EQ(1U, navigation_entry_committed_counter_); + navigation_entry_committed_counter_ = 0; entry = controller.GetLastCommittedEntry(); EXPECT_TRUE(entry); @@ -3448,7 +3537,8 @@ TEST_F(NavigationControllerTest, BackNavigationDoesNotClearFavicon) { RegisterForAllNavNotifications(¬ifications, &controller); test_rvh()->SendNavigate(0, kUrl1); - EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); + EXPECT_EQ(1U, navigation_entry_committed_counter_); + navigation_entry_committed_counter_ = 0; // Simulate Chromium having set the favicon for |kUrl1|. gfx::Image favicon_image = CreateImage(SK_ColorWHITE); @@ -3461,12 +3551,14 @@ TEST_F(NavigationControllerTest, BackNavigationDoesNotClearFavicon) { // Navigate to another page and go back to the original page. test_rvh()->SendNavigate(1, kUrl2); - EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); + EXPECT_EQ(1U, navigation_entry_committed_counter_); + navigation_entry_committed_counter_ = 0; test_rvh()->SendNavigateWithTransition( 0, kUrl1, PAGE_TRANSITION_FORWARD_BACK); - EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_COMMITTED)); + EXPECT_EQ(1U, navigation_entry_committed_counter_); + navigation_entry_committed_counter_ = 0; // Verify that the favicon for the page at |kUrl1| was not cleared. entry = controller.GetEntryAtIndex(0); diff --git a/content/browser/web_contents/web_contents_impl.cc b/content/browser/web_contents/web_contents_impl.cc index 9208da1..2ed02cb 100644 --- a/content/browser/web_contents/web_contents_impl.cc +++ b/content/browser/web_contents/web_contents_impl.cc @@ -7,6 +7,7 @@ #include <utility> #include "base/command_line.h" +#include "base/lazy_instance.h" #include "base/logging.h" #include "base/metrics/histogram.h" #include "base/metrics/stats_counters.h" @@ -153,6 +154,9 @@ const int kSyncWaitDelay = 40; const char kDotGoogleDotCom[] = ".google.com"; +base::LazyInstance<std::vector<WebContents::CreatedCallback> > +g_created_callbacks = LAZY_INSTANCE_INITIALIZER; + static int StartDownload(content::RenderViewHost* rvh, const GURL& url, bool is_favicon, @@ -281,6 +285,19 @@ WebContents* WebContents::CreateWithSessionStorage( return new_contents; } +void WebContents::AddCreatedCallback(const CreatedCallback& callback) { + g_created_callbacks.Get().push_back(callback); +} + +void WebContents::RemoveCreatedCallback(const CreatedCallback& callback) { + for (size_t i = 0; i < g_created_callbacks.Get().size(); ++i) { + if (g_created_callbacks.Get().at(i).Equals(callback)) { + g_created_callbacks.Get().erase(g_created_callbacks.Get().begin() + i); + return; + } + } +} + WebContents* WebContents::FromRenderViewHost(const RenderViewHost* rvh) { return rvh->GetDelegate()->GetAsWebContents(); } @@ -340,6 +357,8 @@ WebContentsImpl::WebContentsImpl( color_chooser_identifier_(0), message_source_(NULL), fullscreen_widget_routing_id_(MSG_ROUTING_NONE) { + for (size_t i = 0; i < g_created_callbacks.Get().size(); i++) + g_created_callbacks.Get().at(i).Run(this); } WebContentsImpl::~WebContentsImpl() { @@ -2753,6 +2772,12 @@ void WebContentsImpl::NotifyDisconnected() { NotificationService::NoDetails()); } +void WebContentsImpl::NotifyNavigationEntryCommitted( + const LoadCommittedDetails& load_details) { + FOR_EACH_OBSERVER( + WebContentsObserver, observers_, NavigationEntryCommitted(load_details)); +} + RenderViewHostDelegateView* WebContentsImpl::GetDelegateView() { return render_view_host_delegate_view_; } diff --git a/content/browser/web_contents/web_contents_impl.h b/content/browser/web_contents/web_contents_impl.h index a533ea1..1e62606 100644 --- a/content/browser/web_contents/web_contents_impl.h +++ b/content/browser/web_contents/web_contents_impl.h @@ -716,6 +716,7 @@ class CONTENT_EXPORT WebContentsImpl void NotifySwapped(RenderViewHost* old_render_view_host); void NotifyConnected(); void NotifyDisconnected(); + void NotifyNavigationEntryCommitted(const LoadCommittedDetails& load_details); void SetEncoding(const std::string& encoding); diff --git a/content/browser/web_contents/web_contents_impl_browsertest.cc b/content/browser/web_contents/web_contents_impl_browsertest.cc index 000da0e..0cb9fe2 100644 --- a/content/browser/web_contents/web_contents_impl_browsertest.cc +++ b/content/browser/web_contents/web_contents_impl_browsertest.cc @@ -10,6 +10,7 @@ #include "content/public/browser/notification_details.h" #include "content/public/browser/notification_observer.h" #include "content/public/browser/notification_types.h" +#include "content/public/browser/web_contents_observer.h" #include "content/public/common/content_paths.h" #include "content/public/test/browser_test_utils.h" #include "content/public/test/test_utils.h" @@ -58,25 +59,22 @@ class LoadStopNotificationObserver : public WindowedNotificationObserver { // Starts a new navigation as soon as the current one commits, but does not // wait for it to complete. This allows us to observe DidStopLoading while // a pending entry is present. -class NavigateOnCommitObserver : public WindowedNotificationObserver { +class NavigateOnCommitObserver : public WebContentsObserver { public: NavigateOnCommitObserver(Shell* shell, GURL url) - : WindowedNotificationObserver( - NOTIFICATION_NAV_ENTRY_COMMITTED, - Source<NavigationController>( - &shell->web_contents()->GetController())), + : WebContentsObserver(shell->web_contents()), shell_(shell), url_(url), done_(false) { } - virtual void Observe(int type, - const NotificationSource& source, - const NotificationDetails& details) OVERRIDE { - if (type == NOTIFICATION_NAV_ENTRY_COMMITTED && !done_) { + + // WebContentsObserver: + virtual void NavigationEntryCommitted( + const LoadCommittedDetails& load_details) OVERRIDE { + if (!done_) { done_ = true; shell_->LoadURL(url_); } - WindowedNotificationObserver::Observe(type, source, details); } Shell* shell_; @@ -114,7 +112,6 @@ IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, NavigateOnCommitObserver commit_observer( shell(), embedded_test_server()->GetURL("/title2.html")); NavigateToURL(shell(), embedded_test_server()->GetURL("/title1.html")); - commit_observer.Wait(); load_observer.Wait(); EXPECT_EQ("/title1.html", load_observer.url_.path()); diff --git a/content/public/browser/web_contents.h b/content/public/browser/web_contents.h index 062dfec..f2146f5 100644 --- a/content/public/browser/web_contents.h +++ b/content/public/browser/web_contents.h @@ -105,6 +105,13 @@ class WebContents : public PageNavigator, const CreateParams& params, const SessionStorageNamespaceMap& session_storage_namespace_map); + // Adds/removes a callback called on creation of each new WebContents. + typedef base::Callback<void(WebContents*)> CreatedCallback; + CONTENT_EXPORT static void AddCreatedCallback( + const CreatedCallback& callback); + CONTENT_EXPORT static void RemoveCreatedCallback( + const CreatedCallback& callback); + // Returns a WebContents that wraps the RenderViewHost, or NULL if the // render view host's delegate isn't a WebContents. CONTENT_EXPORT static WebContents* FromRenderViewHost( diff --git a/content/public/browser/web_contents_observer.h b/content/public/browser/web_contents_observer.h index e0bd1ae..0a01171 100644 --- a/content/public/browser/web_contents_observer.h +++ b/content/public/browser/web_contents_observer.h @@ -166,6 +166,13 @@ class CONTENT_EXPORT WebContentsObserver : public IPC::Listener, const string16& error_description, RenderViewHost* render_view_host) {} + // This method is invoked when a new non-pending navigation entry is created. + // This corresponds to one NavigationController entry being created + // (in the case of new navigations) or renavigated to (for back/forward + // navigations). + virtual void NavigationEntryCommitted( + const LoadCommittedDetails& load_details) {} + // This method is invoked when a new WebContents was created in response to // an action in the observed WebContents, e.g. a link with target=_blank was // clicked. The |source_frame_id| indicates in which frame the action took diff --git a/content/public/test/test_navigation_observer.cc b/content/public/test/test_navigation_observer.cc index 970d82d..c9d3d77 100644 --- a/content/public/test/test_navigation_observer.cc +++ b/content/public/test/test_navigation_observer.cc @@ -7,35 +7,76 @@ #include "base/bind.h" #include "base/message_loop.h" #include "base/run_loop.h" +#include "base/stl_util.h" #include "content/public/browser/notification_service.h" #include "content/public/browser/notification_types.h" +#include "content/public/browser/web_contents_observer.h" #include "content/public/test/test_utils.h" #include "testing/gtest/include/gtest/gtest.h" namespace content { +class TestNavigationObserver::TestWebContentsObserver + : public WebContentsObserver { + public: + TestWebContentsObserver(TestNavigationObserver* parent, + WebContents* web_contents) + : WebContentsObserver(web_contents), + parent_(parent) { + } + + private: + // WebContentsObserver: + virtual void NavigationEntryCommitted( + const LoadCommittedDetails& load_details) OVERRIDE { + parent_->OnNavigationEntryCommitted(this, web_contents(), load_details); + } + + virtual void WebContentsDestroyed(WebContents* web_contents) OVERRIDE { + parent_->OnWebContentsDestroyed(this, web_contents); + } + + TestNavigationObserver* parent_; + + DISALLOW_COPY_AND_ASSIGN(TestWebContentsObserver); +}; + TestNavigationObserver::TestNavigationObserver( - const NotificationSource& source, + WebContents* web_contents, int number_of_navigations) : navigation_started_(false), navigations_completed_(0), number_of_navigations_(number_of_navigations), done_(false), - running_(false) { - RegisterAsObserver(source); + running_(false), + web_contents_created_callback_( + base::Bind( + &TestNavigationObserver::OnWebContentsCreated, + base::Unretained(this))) { + if (web_contents) + RegisterAsObserver(web_contents); } TestNavigationObserver::TestNavigationObserver( - const NotificationSource& source) + WebContents* web_contents) : navigation_started_(false), navigations_completed_(0), number_of_navigations_(1), done_(false), - running_(false) { - RegisterAsObserver(source); + running_(false), + web_contents_created_callback_( + base::Bind( + &TestNavigationObserver::OnWebContentsCreated, + base::Unretained(this))) { + if (web_contents) + RegisterAsObserver(web_contents); } TestNavigationObserver::~TestNavigationObserver() { + StopWatchingNewWebContents(); + + STLDeleteContainerPointers(web_contents_observers_.begin(), + web_contents_observers_.end()); } void TestNavigationObserver::WaitForObservation( @@ -58,30 +99,29 @@ void TestNavigationObserver::Wait() { GetQuitTaskForRunLoop(&run_loop)); } -TestNavigationObserver::TestNavigationObserver( - int number_of_navigations) - : navigation_started_(false), - navigations_completed_(0), - number_of_navigations_(number_of_navigations), - done_(false), - running_(false) { +void TestNavigationObserver::StartWatchingNewWebContents() { + WebContents::AddCreatedCallback(web_contents_created_callback_); +} + +void TestNavigationObserver::StopWatchingNewWebContents() { + WebContents::RemoveCreatedCallback(web_contents_created_callback_); } void TestNavigationObserver::RegisterAsObserver( - const NotificationSource& source) { - // Register for events to know when we've finished loading the page and are - // ready to quit the current message loop to return control back to the - // waiting test. - registrar_.Add(this, NOTIFICATION_NAV_ENTRY_COMMITTED, source); - registrar_.Add(this, NOTIFICATION_LOAD_START, source); - registrar_.Add(this, NOTIFICATION_LOAD_STOP, source); + WebContents* web_contents) { + web_contents_observers_.insert( + new TestWebContentsObserver(this, web_contents)); + + NotificationSource notification_source = + Source<NavigationController>(&web_contents->GetController()); + registrar_.Add(this, NOTIFICATION_LOAD_START, notification_source); + registrar_.Add(this, NOTIFICATION_LOAD_STOP, notification_source); } void TestNavigationObserver::Observe( int type, const NotificationSource& source, const NotificationDetails& details) { switch (type) { - case NOTIFICATION_NAV_ENTRY_COMMITTED: case NOTIFICATION_LOAD_START: navigation_started_ = true; break; @@ -101,4 +141,27 @@ void TestNavigationObserver::Observe( } } +void TestNavigationObserver::OnWebContentsCreated(WebContents* web_contents) { + RegisterAsObserver(web_contents); +} + +void TestNavigationObserver::OnWebContentsDestroyed( + TestWebContentsObserver* observer, + WebContents* web_contents) { + web_contents_observers_.erase(observer); + delete observer; + + NotificationSource notification_source = + Source<NavigationController>(&web_contents->GetController()); + registrar_.Remove(this, NOTIFICATION_LOAD_START, notification_source); + registrar_.Remove(this, NOTIFICATION_LOAD_STOP, notification_source); +} + +void TestNavigationObserver::OnNavigationEntryCommitted( + TestWebContentsObserver* observer, + WebContents* web_contents, + const LoadCommittedDetails& load_details) { + navigation_started_ = true; +} + } // namespace content diff --git a/content/public/test/test_navigation_observer.h b/content/public/test/test_navigation_observer.h index e7c2f86..132c5f2 100644 --- a/content/public/test/test_navigation_observer.h +++ b/content/public/test/test_navigation_observer.h @@ -10,18 +10,22 @@ #include "base/memory/scoped_ptr.h" #include "content/public/browser/notification_observer.h" #include "content/public/browser/notification_registrar.h" +#include "content/public/browser/web_contents.h" namespace content { +struct LoadCommittedDetails; + // For browser_tests, which run on the UI thread, run a second // MessageLoop and quit when the navigation completes loading. class TestNavigationObserver : public NotificationObserver { public: - // Create and register a new TestNavigationObserver against the |source|. - TestNavigationObserver(const NotificationSource& source, + // Create and register a new TestNavigationObserver against the + // |web_contents|. + TestNavigationObserver(WebContents* web_contents, int number_of_navigations); // Like above but waits for one navigation. - explicit TestNavigationObserver(const NotificationSource& source); + explicit TestNavigationObserver(WebContents* web_contents); virtual ~TestNavigationObserver(); @@ -31,17 +35,30 @@ class TestNavigationObserver : public NotificationObserver { // Convenient version of the above that runs a nested message loop and waits. void Wait(); - protected: - explicit TestNavigationObserver(int number_of_navigations); + // Start/stop watching newly created WebContents. + void StartWatchingNewWebContents(); + void StopWatchingNewWebContents(); - // Register this TestNavigationObserver as an observer of the |source|. - void RegisterAsObserver(const NotificationSource& source); + protected: + // Register this TestNavigationObserver as an observer of the |web_contents|. + void RegisterAsObserver(WebContents* web_contents); // NotificationObserver: virtual void Observe(int type, const NotificationSource& source, const NotificationDetails& details) OVERRIDE; private: + class TestWebContentsObserver; + + // Callbacks for WebContents-related events. + void OnWebContentsCreated(WebContents* web_contents); + void OnWebContentsDestroyed(TestWebContentsObserver* observer, + WebContents* web_contents); + void OnNavigationEntryCommitted( + TestWebContentsObserver* observer, + WebContents* web_contents, + const LoadCommittedDetails& load_details); + NotificationRegistrar registrar_; // If true the navigation has started. @@ -56,12 +73,18 @@ class TestNavigationObserver : public NotificationObserver { // |done_| will get set when this object observes a TabStripModel event. bool done_; + // |running_| will be true during WaitForObservation until |done_| is true. + bool running_; + // |done_callback_| will be set while |running_| is true and will be called // when navigation completes. base::Closure done_callback_; - // |running_| will be true during WaitForObservation until |done_| is true. - bool running_; + // Callback invoked on WebContents creation. + WebContents::CreatedCallback web_contents_created_callback_; + + // Living TestWebContentsObservers created by this observer. + std::set<TestWebContentsObserver*> web_contents_observers_; DISALLOW_COPY_AND_ASSIGN(TestNavigationObserver); }; diff --git a/content/test/content_browser_test_utils.cc b/content/test/content_browser_test_utils.cc index 1ac37da..aec5661 100644 --- a/content/test/content_browser_test_utils.cc +++ b/content/test/content_browser_test_utils.cc @@ -36,10 +36,8 @@ void NavigateToURLBlockUntilNavigationsComplete(Shell* window, const GURL& url, int number_of_navigations) { WaitForLoadStop(window->web_contents()); - NavigationController* controller = &window->web_contents()->GetController(); - TestNavigationObserver same_tab_observer( - Source<NavigationController>(controller), - number_of_navigations); + TestNavigationObserver same_tab_observer(window->web_contents(), + number_of_navigations); window->LoadURL(url); |