Commit 30975ed3 authored by gbillock@chromium.org's avatar gbillock@chromium.org

Fix up various browser tests not to use WaitForNavigation.

Convenience methods for WindowedNotificationObserver.

R=phajdan.jr@chromium.org
BUG=various
TEST=none


Review URL: http://codereview.chromium.org/7489019

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@96593 0039d316-1c4b-4281-b951-d872f2087c98
parent c62b7a56
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "chrome/browser/tabs/tab_strip_model.h" #include "chrome/browser/tabs/tab_strip_model.h"
#include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_window.h" #include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
#include "chrome/browser/ui/view_ids.h" #include "chrome/browser/ui/view_ids.h"
#include "chrome/common/chrome_notification_types.h" #include "chrome/common/chrome_notification_types.h"
#include "chrome/common/chrome_paths.h" #include "chrome/common/chrome_paths.h"
...@@ -847,11 +848,23 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, FocusOnReload) { ...@@ -847,11 +848,23 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, FocusOnReload) {
ASSERT_TRUE(test_server()->Start()); ASSERT_TRUE(test_server()->Start());
// Open the new tab, reload. // Open the new tab, reload.
browser()->NewTab(); {
ui_test_utils::WindowedNotificationObserver observer(
content::NOTIFICATION_LOAD_STOP,
NotificationService::AllSources());
browser()->NewTab();
observer.Wait();
}
ui_test_utils::RunAllPendingInMessageLoop(); ui_test_utils::RunAllPendingInMessageLoop();
browser()->Reload(CURRENT_TAB); {
ASSERT_TRUE(ui_test_utils::WaitForNavigationInCurrentTab(browser())); ui_test_utils::WindowedNotificationObserver observer(
content::NOTIFICATION_LOAD_STOP,
Source<NavigationController>(
&browser()->GetSelectedTabContentsWrapper()->controller()));
browser()->Reload(CURRENT_TAB);
observer.Wait();
}
// Focus should stay on the location bar. // Focus should stay on the location bar.
ASSERT_TRUE(IsViewFocused(VIEW_ID_LOCATION_BAR)); ASSERT_TRUE(IsViewFocused(VIEW_ID_LOCATION_BAR));
...@@ -859,8 +872,14 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, FocusOnReload) { ...@@ -859,8 +872,14 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, FocusOnReload) {
ui_test_utils::NavigateToURL(browser(), test_server()->GetURL(kSimplePage)); ui_test_utils::NavigateToURL(browser(), test_server()->GetURL(kSimplePage));
browser()->FocusLocationBar(); browser()->FocusLocationBar();
ASSERT_TRUE(IsViewFocused(VIEW_ID_LOCATION_BAR)); ASSERT_TRUE(IsViewFocused(VIEW_ID_LOCATION_BAR));
browser()->Reload(CURRENT_TAB); {
ASSERT_TRUE(ui_test_utils::WaitForNavigationInCurrentTab(browser())); ui_test_utils::WindowedNotificationObserver observer(
content::NOTIFICATION_LOAD_STOP,
Source<NavigationController>(
&browser()->GetSelectedTabContentsWrapper()->controller()));
browser()->Reload(CURRENT_TAB);
observer.Wait();
}
// Focus should now be on the tab contents. // Focus should now be on the tab contents.
browser()->ShowDownloadsTab(); browser()->ShowDownloadsTab();
...@@ -875,8 +894,14 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, DISABLED_FocusOnReloadCrashedTab) { ...@@ -875,8 +894,14 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, DISABLED_FocusOnReloadCrashedTab) {
// Open a regular page, crash, reload. // Open a regular page, crash, reload.
ui_test_utils::NavigateToURL(browser(), test_server()->GetURL(kSimplePage)); ui_test_utils::NavigateToURL(browser(), test_server()->GetURL(kSimplePage));
ui_test_utils::CrashTab(browser()->GetSelectedTabContents()); ui_test_utils::CrashTab(browser()->GetSelectedTabContents());
browser()->Reload(CURRENT_TAB); {
ASSERT_TRUE(ui_test_utils::WaitForNavigationInCurrentTab(browser())); ui_test_utils::WindowedNotificationObserver observer(
content::NOTIFICATION_LOAD_STOP,
Source<NavigationController>(
&browser()->GetSelectedTabContentsWrapper()->controller()));
browser()->Reload(CURRENT_TAB);
observer.Wait();
}
// Focus should now be on the tab contents. // Focus should now be on the tab contents.
browser()->ShowDownloadsTab(); browser()->ShowDownloadsTab();
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "base/file_path.h" #include "base/file_path.h"
#include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
#include "chrome/common/url_constants.h" #include "chrome/common/url_constants.h"
#include "chrome/test/base/in_process_browser_test.h" #include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h" #include "chrome/test/base/ui_test_utils.h"
...@@ -15,12 +16,12 @@ ...@@ -15,12 +16,12 @@
namespace { namespace {
void SimulateRendererCrash(Browser* browser) { void SimulateRendererCrash(Browser* browser) {
ui_test_utils::WindowedNotificationObserver observer(
content::NOTIFICATION_TAB_CONTENTS_DISCONNECTED,
NotificationService::AllSources());
browser->OpenURL(GURL(chrome::kChromeUICrashURL), GURL(), CURRENT_TAB, browser->OpenURL(GURL(chrome::kChromeUICrashURL), GURL(), CURRENT_TAB,
PageTransition::TYPED); PageTransition::TYPED);
LOG(ERROR) << "SimulateRendererCrash, before WaitForNotification"; observer.Wait();
ui_test_utils::WaitForNotification(
content::NOTIFICATION_TAB_CONTENTS_DISCONNECTED);
LOG(ERROR) << "SimulateRendererCrash, after WaitForNotification";
} }
} // namespace } // namespace
...@@ -42,10 +43,12 @@ IN_PROC_BROWSER_TEST_F(CrashRecoveryBrowserTest, Reload) { ...@@ -42,10 +43,12 @@ IN_PROC_BROWSER_TEST_F(CrashRecoveryBrowserTest, Reload) {
ASSERT_TRUE(ui_test_utils::GetCurrentTabTitle(browser(), ASSERT_TRUE(ui_test_utils::GetCurrentTabTitle(browser(),
&title_before_crash)); &title_before_crash));
SimulateRendererCrash(browser()); SimulateRendererCrash(browser());
ui_test_utils::WindowedNotificationObserver observer(
content::NOTIFICATION_LOAD_STOP,
Source<NavigationController>(
&browser()->GetSelectedTabContentsWrapper()->controller()));
browser()->Reload(CURRENT_TAB); browser()->Reload(CURRENT_TAB);
LOG(ERROR) << "Before WaitForNavigationInCurrentTab"; observer.Wait();
ASSERT_TRUE(ui_test_utils::WaitForNavigationInCurrentTab(browser()));
LOG(ERROR) << "After WaitForNavigationInCurrentTab";
ASSERT_TRUE(ui_test_utils::GetCurrentTabTitle(browser(), ASSERT_TRUE(ui_test_utils::GetCurrentTabTitle(browser(),
&title_after_crash)); &title_after_crash));
EXPECT_NE(title_before_crash, title_after_crash); EXPECT_NE(title_before_crash, title_after_crash);
...@@ -69,10 +72,12 @@ IN_PROC_BROWSER_TEST_F(CrashRecoveryBrowserTest, LoadInNewTab) { ...@@ -69,10 +72,12 @@ IN_PROC_BROWSER_TEST_F(CrashRecoveryBrowserTest, LoadInNewTab) {
ASSERT_TRUE(ui_test_utils::GetCurrentTabTitle(browser(), ASSERT_TRUE(ui_test_utils::GetCurrentTabTitle(browser(),
&title_before_crash)); &title_before_crash));
SimulateRendererCrash(browser()); SimulateRendererCrash(browser());
ui_test_utils::WindowedNotificationObserver observer(
content::NOTIFICATION_LOAD_STOP,
Source<NavigationController>(
&browser()->GetSelectedTabContentsWrapper()->controller()));
browser()->Reload(CURRENT_TAB); browser()->Reload(CURRENT_TAB);
LOG(ERROR) << "Before WaitForNavigationInCurrentTab"; observer.Wait();
ASSERT_TRUE(ui_test_utils::WaitForNavigationInCurrentTab(browser()));
LOG(ERROR) << "After WaitForNavigationInCurrentTab";
ASSERT_TRUE(ui_test_utils::GetCurrentTabTitle(browser(), ASSERT_TRUE(ui_test_utils::GetCurrentTabTitle(browser(),
&title_after_crash)); &title_after_crash));
EXPECT_EQ(title_before_crash, title_after_crash); EXPECT_EQ(title_before_crash, title_after_crash);
......
...@@ -317,11 +317,17 @@ class GeolocationBrowserTest : public InProcessBrowserTest { ...@@ -317,11 +317,17 @@ class GeolocationBrowserTest : public InProcessBrowserTest {
size_t state_map_size = settings_state.state_map().size(); size_t state_map_size = settings_state.state_map().size();
ASSERT_TRUE(infobar_); ASSERT_TRUE(infobar_);
LOG(WARNING) << "will set infobar response"; LOG(WARNING) << "will set infobar response";
if (allowed) {
infobar_->AsConfirmInfoBarDelegate()->Accept(); ui_test_utils::WindowedNotificationObserver observer(
else content::NOTIFICATION_LOAD_STOP,
infobar_->AsConfirmInfoBarDelegate()->Cancel(); Source<NavigationController>(&tab_contents_wrapper->controller()));
WaitForNavigation(); if (allowed)
infobar_->AsConfirmInfoBarDelegate()->Accept();
else
infobar_->AsConfirmInfoBarDelegate()->Cancel();
observer.Wait();
}
tab_contents_wrapper->RemoveInfoBar(infobar_); tab_contents_wrapper->RemoveInfoBar(infobar_);
LOG(WARNING) << "infobar response set"; LOG(WARNING) << "infobar response set";
infobar_ = NULL; infobar_ = NULL;
......
...@@ -336,12 +336,16 @@ IN_PROC_BROWSER_TEST_F(PDFBrowserTest, MAYBE_OnLoadAndReload) { ...@@ -336,12 +336,16 @@ IN_PROC_BROWSER_TEST_F(PDFBrowserTest, MAYBE_OnLoadAndReload) {
GURL url = pdf_test_server()->GetURL("files/onload_reload.html"); GURL url = pdf_test_server()->GetURL("files/onload_reload.html");
ui_test_utils::NavigateToURL(browser(), url); ui_test_utils::NavigateToURL(browser(), url);
ui_test_utils::WindowedNavigationObserver observer(
content::NOTIFICATION_LOAD_STOP,
Source<NavigationController>(
&browser()->GetSelectedTabContents()->controller()));
ASSERT_TRUE(ui_test_utils::ExecuteJavaScript( ASSERT_TRUE(ui_test_utils::ExecuteJavaScript(
browser()->GetSelectedTabContents()->render_view_host(), browser()->GetSelectedTabContents()->render_view_host(),
std::wstring(), std::wstring(),
L"reloadPDF();")); L"reloadPDF();"));
observer.Wait();
ASSERT_TRUE(ui_test_utils::WaitForNavigationInCurrentTab(browser()));
ASSERT_EQ("success", browser()->GetSelectedTabContents()->GetURL().query()); ASSERT_EQ("success", browser()->GetSelectedTabContents()->GetURL().query());
} }
......
...@@ -72,13 +72,11 @@ class SidebarTest : public ExtensionBrowserTest { ...@@ -72,13 +72,11 @@ class SidebarTest : public ExtensionBrowserTest {
SidebarManager* sidebar_manager = SidebarManager::GetInstance(); SidebarManager* sidebar_manager = SidebarManager::GetInstance();
ui_test_utils::WindowedNotificationObserver observer(
content::NOTIFICATION_LOAD_STOP,
Source<NavigationController>(&tab->controller()));
sidebar_manager->NavigateSidebar(tab, content_id_, url); sidebar_manager->NavigateSidebar(tab, content_id_, url);
observer.Wait();
SidebarContainer* sidebar_container =
sidebar_manager->GetSidebarContainerFor(tab, content_id_);
TabContents* client_contents = sidebar_container->sidebar_contents();
ui_test_utils::WaitForNavigation(&client_contents->controller());
} }
void ShowSidebar(TabContents* tab) { void ShowSidebar(TabContents* tab) {
...@@ -199,4 +197,3 @@ IN_PROC_BROWSER_TEST_F(SidebarTest, SidebarNavigate) { ...@@ -199,4 +197,3 @@ IN_PROC_BROWSER_TEST_F(SidebarTest, SidebarNavigate) {
} }
} // namespace } // namespace
This diff is collapsed.
...@@ -581,8 +581,12 @@ IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindDisappearOnNavigate) { ...@@ -581,8 +581,12 @@ IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindDisappearOnNavigate) {
EXPECT_TRUE(fully_visible); EXPECT_TRUE(fully_visible);
// Reload the tab and make sure Find window doesn't go away. // Reload the tab and make sure Find window doesn't go away.
ui_test_utils::WindowedNotificationObserver observer(
content::NOTIFICATION_LOAD_STOP,
Source<NavigationController>(
&browser()->GetSelectedTabContentsWrapper()->controller()));
browser()->Reload(CURRENT_TAB); browser()->Reload(CURRENT_TAB);
ui_test_utils::WaitForNavigationInCurrentTab(browser()); observer.Wait();
EXPECT_TRUE(GetFindBarWindowInfo(&position, &fully_visible)); EXPECT_TRUE(GetFindBarWindowInfo(&position, &fully_visible));
EXPECT_TRUE(fully_visible); EXPECT_TRUE(fully_visible);
...@@ -1048,9 +1052,10 @@ IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, MAYBE_NoIncognitoPrepopulate) { ...@@ -1048,9 +1052,10 @@ IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, MAYBE_NoIncognitoPrepopulate) {
// Open a new incognito window and navigate to the same page. // Open a new incognito window and navigate to the same page.
Profile* incognito_profile = browser()->profile()->GetOffTheRecordProfile(); Profile* incognito_profile = browser()->profile()->GetOffTheRecordProfile();
Browser* incognito_browser = Browser::Create(incognito_profile); Browser* incognito_browser = Browser::Create(incognito_profile);
ui_test_utils::WindowedNotificationObserver observer(
content::NOTIFICATION_LOAD_STOP, NotificationService::AllSources());
incognito_browser->AddSelectedTabWithURL(url, PageTransition::START_PAGE); incognito_browser->AddSelectedTabWithURL(url, PageTransition::START_PAGE);
ui_test_utils::WaitForNavigation( observer.Wait();
&incognito_browser->GetSelectedTabContents()->controller());
incognito_browser->window()->Show(); incognito_browser->window()->Show();
// Open the find box and make sure that it is prepopulated with "page". // Open the find box and make sure that it is prepopulated with "page".
...@@ -1093,8 +1098,11 @@ IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, ActivateLinkNavigatesPage) { ...@@ -1093,8 +1098,11 @@ IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, ActivateLinkNavigatesPage) {
EXPECT_EQ(ordinal, 1); EXPECT_EQ(ordinal, 1);
// End the find session, click on the link. // End the find session, click on the link.
ui_test_utils::WindowedNotificationObserver observer(
content::NOTIFICATION_LOAD_STOP,
Source<NavigationController>(&tab->controller()));
tab->find_tab_helper()->StopFinding(FindBarController::kActivateSelection); tab->find_tab_helper()->StopFinding(FindBarController::kActivateSelection);
EXPECT_TRUE(ui_test_utils::WaitForNavigationInCurrentTab(browser())); observer.Wait();
} }
// Tests that FindBar fits within a narrow browser window. // Tests that FindBar fits within a narrow browser window.
...@@ -1102,12 +1110,12 @@ IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FitWindow) { ...@@ -1102,12 +1110,12 @@ IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FitWindow) {
Browser::CreateParams params(Browser::TYPE_POPUP, browser()->profile()); Browser::CreateParams params(Browser::TYPE_POPUP, browser()->profile());
params.initial_bounds = gfx::Rect(0, 0, 250, 500); params.initial_bounds = gfx::Rect(0, 0, 250, 500);
Browser* popup = Browser::CreateWithParams(params); Browser* popup = Browser::CreateWithParams(params);
ui_test_utils::WindowedNotificationObserver observer(
content::NOTIFICATION_LOAD_STOP, NotificationService::AllSources());
popup->AddSelectedTabWithURL(GURL(chrome::kAboutBlankURL), popup->AddSelectedTabWithURL(GURL(chrome::kAboutBlankURL),
PageTransition::LINK); PageTransition::LINK);
// Wait for the page to finish loading. // Wait for the page to finish loading.
ui_test_utils::WaitForNavigation( observer.Wait();
&popup->GetSelectedTabContents()->controller());
popup->window()->Show(); popup->window()->Show();
// On GTK, bounds change is asynchronous. // On GTK, bounds change is asynchronous.
......
...@@ -57,6 +57,7 @@ namespace ui_test_utils { ...@@ -57,6 +57,7 @@ namespace ui_test_utils {
namespace { namespace {
// Used to block until a navigation completes. // Used to block until a navigation completes.
// TODO(gbillock): this should be merged with TestNavigationObserver
class NavigationNotificationObserver : public NotificationObserver { class NavigationNotificationObserver : public NotificationObserver {
public: public:
NavigationNotificationObserver(const NotificationSource& source, NavigationNotificationObserver(const NotificationSource& source,
......
...@@ -230,10 +230,14 @@ bool IsViewFocused(const Browser* browser, ViewID vid); ...@@ -230,10 +230,14 @@ bool IsViewFocused(const Browser* browser, ViewID vid);
void ClickOnView(const Browser* browser, ViewID vid); void ClickOnView(const Browser* browser, ViewID vid);
// Blocks until a notification for given |type| is received. // Blocks until a notification for given |type| is received.
// TODO(gbillock): remove this race hazard.
// Use WindowedNotificationObserver instead.
void WaitForNotification(int type); void WaitForNotification(int type);
// Blocks until a notification for given |type| from the specified |source| // Blocks until a notification for given |type| from the specified |source|
// is received. // is received.
// TODO(gbillock): remove this race hazard.
// Use WindowedNotificationObserver instead.
void WaitForNotificationFrom(int type, void WaitForNotificationFrom(int type,
const NotificationSource& source); const NotificationSource& source);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment