diff options
Diffstat (limited to 'chrome/browser')
-rw-r--r-- | chrome/browser/autocomplete/autocomplete_browsertest.cc | 20 | ||||
-rw-r--r-- | chrome/browser/browser_browsertest.cc | 7 | ||||
-rw-r--r-- | chrome/browser/browser_init_browsertest.cc | 5 | ||||
-rw-r--r-- | chrome/browser/crash_recovery_browsertest.cc | 36 | ||||
-rw-r--r-- | chrome/browser/download/save_page_browsertest.cc | 52 | ||||
-rw-r--r-- | chrome/browser/extensions/extension_apitest.cc | 15 | ||||
-rw-r--r-- | chrome/browser/extensions/extension_browsertest.cc | 49 | ||||
-rw-r--r-- | chrome/browser/extensions/extension_devtools_browsertest.h | 4 | ||||
-rw-r--r-- | chrome/browser/extensions/extension_startup_unittest.cc | 42 |
9 files changed, 63 insertions, 167 deletions
diff --git a/chrome/browser/autocomplete/autocomplete_browsertest.cc b/chrome/browser/autocomplete/autocomplete_browsertest.cc index 29a9b30..f54e535 100644 --- a/chrome/browser/autocomplete/autocomplete_browsertest.cc +++ b/chrome/browser/autocomplete/autocomplete_browsertest.cc @@ -12,8 +12,6 @@ #include "chrome/browser/location_bar.h" #include "chrome/browser/profile.h" #include "chrome/browser/tab_contents/tab_contents.h" -#include "chrome/common/notification_registrar.h" -#include "chrome/common/notification_service.h" #include "chrome/common/notification_type.h" #include "chrome/common/url_constants.h" #include "chrome/test/in_process_browser_test.h" @@ -36,8 +34,7 @@ std::wstring AutocompleteResultAsString(const AutocompleteResult& result) { } // namespace -class AutocompleteBrowserTest : public InProcessBrowserTest, - public NotificationObserver { +class AutocompleteBrowserTest : public InProcessBrowserTest { protected: LocationBar* GetLocationBar() const { return browser()->window()->GetLocationBar(); @@ -51,19 +48,8 @@ class AutocompleteBrowserTest : public InProcessBrowserTest, void WaitForHistoryBackendToLoad() { HistoryService* history_service = browser()->profile()->GetHistoryService(Profile::EXPLICIT_ACCESS); - if (!history_service->BackendLoaded()) { - NotificationRegistrar registrar; - registrar.Add(this, NotificationType::HISTORY_LOADED, - NotificationService::AllSources()); - ui_test_utils::RunMessageLoop(); - } - } - - virtual void Observe(NotificationType type, - const NotificationSource& source, - const NotificationDetails& details) { - DCHECK(type == NotificationType::HISTORY_LOADED); - MessageLoop::current()->Quit(); + if (!history_service->BackendLoaded()) + ui_test_utils::WaitForNotification(NotificationType::HISTORY_LOADED); } }; diff --git a/chrome/browser/browser_browsertest.cc b/chrome/browser/browser_browsertest.cc index 66922f5..ee51d90 100644 --- a/chrome/browser/browser_browsertest.cc +++ b/chrome/browser/browser_browsertest.cc @@ -364,7 +364,7 @@ IN_PROC_BROWSER_TEST_F(BrowserTest, CommandCreateAppShortcut) { ui_test_utils::NavigateToURL(browser(), blank_url); EXPECT_FALSE(command_updater->IsCommandEnabled(IDC_CREATE_SHORTCUTS)); } -#endif +#endif // !defined(OS_MACOSX) // Test RenderView correctly send back favicon url for web page that redirects // to an anchor in javascript body.onload handler. @@ -452,8 +452,7 @@ IN_PROC_BROWSER_TEST_F(BrowserTest, AppTabRemovedWhenExtensionUninstalled) { // The uninstall should have removed the tab. ASSERT_EQ(1, browser()->tab_count()); } - -#endif +#endif // !defined(OS_MACOSX) // Tests that the CLD (Compact Language Detection) works properly. IN_PROC_BROWSER_TEST_F(BrowserTest, PageLanguageDetection) { @@ -551,4 +550,4 @@ IN_PROC_BROWSER_TEST_F(BrowserTest, RestorePinnedTabs) { EXPECT_TRUE(new_model->GetTabContentsAt(0)->app_extension() == app_extension); } -#endif +#endif // !defined(OS_CHROMEOS) diff --git a/chrome/browser/browser_init_browsertest.cc b/chrome/browser/browser_init_browsertest.cc index 94aa2f2..1ee9e50 100644 --- a/chrome/browser/browser_init_browsertest.cc +++ b/chrome/browser/browser_init_browsertest.cc @@ -58,10 +58,10 @@ IN_PROC_BROWSER_TEST_F(BrowserInitTest, OpenURLsPopup) { // Test that we prevent openning potentially dangerous schemes from the // command line. -// jschuh: DISABLED because the process doesn't have sufficient time +// TODO(jschuh): FLAKY because the process doesn't have sufficient time // to start on most BuildBot runs and I don't want to add longer delays to // the test. I'll circle back and make this work properly when i get a chance. -IN_PROC_BROWSER_TEST_F(BrowserInitTest, DISABLED_BlockBadURLs) { +IN_PROC_BROWSER_TEST_F(BrowserInitTest, FLAKY_BlockBadURLs) { const std::wstring testurlstr(L"http://localhost/"); const GURL testurl(WideToUTF16Hack(testurlstr)); CommandLine cmdline(CommandLine::ARGUMENTS_ONLY); @@ -85,5 +85,4 @@ IN_PROC_BROWSER_TEST_F(BrowserInitTest, DISABLED_BlockBadURLs) { ASSERT_EQ(browser()->tab_count(), 3); } - } // namespace diff --git a/chrome/browser/crash_recovery_browsertest.cc b/chrome/browser/crash_recovery_browsertest.cc index 846ddfe..1ee4cc4 100644 --- a/chrome/browser/crash_recovery_browsertest.cc +++ b/chrome/browser/crash_recovery_browsertest.cc @@ -6,8 +6,7 @@ #include "chrome/browser/browser.h" #include "chrome/browser/tab_contents/navigation_entry.h" #include "chrome/browser/tab_contents/tab_contents.h" -#include "chrome/common/notification_registrar.h" -#include "chrome/common/notification_service.h" +#include "chrome/common/notification_type.h" #include "chrome/common/page_transition_types.h" #include "chrome/common/url_constants.h" #include "chrome/test/in_process_browser_test.h" @@ -17,40 +16,11 @@ namespace { -// Used to block until a navigation completes. -class RendererCrashObserver : public NotificationObserver { - public: - RendererCrashObserver() {} - - void WaitForRendererCrash() { - registrar_.Add(this, NotificationType::TAB_CONTENTS_DISCONNECTED, - NotificationService::AllSources()); - ui_test_utils::RunMessageLoop(); - } - - virtual void Observe(NotificationType type, - const NotificationSource& source, - const NotificationDetails& details) { - if (type == NotificationType::TAB_CONTENTS_DISCONNECTED) { - registrar_.Remove(this, NotificationType::TAB_CONTENTS_DISCONNECTED, - NotificationService::AllSources()); - MessageLoopForUI::current()->Quit(); - } else { - NOTREACHED(); - } - } - - private: - NotificationRegistrar registrar_; - - DISALLOW_COPY_AND_ASSIGN(RendererCrashObserver); -}; - void SimulateRendererCrash(Browser* browser) { browser->OpenURL(GURL(chrome::kAboutCrashURL), GURL(), CURRENT_TAB, PageTransition::TYPED); - RendererCrashObserver crash_observer; - crash_observer.WaitForRendererCrash(); + ui_test_utils::WaitForNotification( + NotificationType::TAB_CONTENTS_DISCONNECTED); } } // namespace diff --git a/chrome/browser/download/save_page_browsertest.cc b/chrome/browser/download/save_page_browsertest.cc index 70b1822..99648b4 100644 --- a/chrome/browser/download/save_page_browsertest.cc +++ b/chrome/browser/download/save_page_browsertest.cc @@ -16,6 +16,8 @@ #include "chrome/test/ui_test_utils.h" #include "testing/gtest/include/gtest/gtest.h" +namespace { + static const FilePath::CharType* kTestDir = FILE_PATH_LITERAL("save_page"); static const char* kAppendedExtension = @@ -25,37 +27,6 @@ static const char* kAppendedExtension = ".html"; #endif -namespace { - -class SavePageFinishedObserver : public NotificationObserver { - public: - SavePageFinishedObserver() { - registrar_.Add(this, NotificationType::SAVE_PACKAGE_SUCCESSFULLY_FINISHED, - NotificationService::AllSources()); - ui_test_utils::RunMessageLoop(); - } - - GURL page_url() const { return page_url_; } - - virtual void Observe(NotificationType type, - const NotificationSource& source, - const NotificationDetails& details) { - if (type == NotificationType::SAVE_PACKAGE_SUCCESSFULLY_FINISHED) { - page_url_ = *Details<GURL>(details).ptr(); - MessageLoopForUI::current()->Quit(); - } else { - NOTREACHED(); - } - } - - private: - NotificationRegistrar registrar_; - - GURL page_url_; - - DISALLOW_COPY_AND_ASSIGN(SavePageFinishedObserver); -}; - class SavePageBrowserTest : public InProcessBrowserTest { protected: void SetUp() { @@ -64,6 +35,14 @@ class SavePageBrowserTest : public InProcessBrowserTest { InProcessBrowserTest::SetUp(); } + GURL WaitForSavePackageToFinish() { + ui_test_utils::TestNotificationObserver observer; + ui_test_utils::RegisterAndWait(&observer, + NotificationType::SAVE_PACKAGE_SUCCESSFULLY_FINISHED, + NotificationService::AllSources()); + return *Details<GURL>(observer.details()).ptr(); + } + // Path to directory containing test data. FilePath test_dir_; @@ -85,9 +64,7 @@ IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveHTMLOnly) { ASSERT_TRUE(current_tab->SavePage(full_file_name, dir, SavePackage::SAVE_AS_ONLY_HTML)); - SavePageFinishedObserver observer; - - EXPECT_EQ(url, observer.page_url()); + EXPECT_EQ(url, WaitForSavePackageToFinish()); if (browser()->SupportsWindowFeature(Browser::FEATURE_DOWNLOADSHELF)) EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); @@ -142,9 +119,7 @@ IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveCompleteHTML) { ASSERT_TRUE(current_tab->SavePage(full_file_name, dir, SavePackage::SAVE_AS_COMPLETE_HTML)); - SavePageFinishedObserver observer; - - EXPECT_EQ(url, observer.page_url()); + EXPECT_EQ(url, WaitForSavePackageToFinish()); if (browser()->SupportsWindowFeature(Browser::FEATURE_DOWNLOADSHELF)) EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); @@ -185,9 +160,8 @@ IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, FileNameFromPageTitle) { ASSERT_TRUE(current_tab->SavePage(full_file_name, dir, SavePackage::SAVE_AS_COMPLETE_HTML)); - SavePageFinishedObserver observer; - EXPECT_EQ(url, observer.page_url()); + EXPECT_EQ(url, WaitForSavePackageToFinish()); if (browser()->SupportsWindowFeature(Browser::FEATURE_DOWNLOADSHELF)) EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); diff --git a/chrome/browser/extensions/extension_apitest.cc b/chrome/browser/extensions/extension_apitest.cc index 081a092..cc16957 100644 --- a/chrome/browser/extensions/extension_apitest.cc +++ b/chrome/browser/extensions/extension_apitest.cc @@ -10,10 +10,6 @@ #include "chrome/common/notification_registrar.h" #include "chrome/test/ui_test_utils.h" -namespace { -static const int kTimeoutMs = 60 * 1000; // 1 minute -}; - ExtensionApiTest::ResultCatcher::ResultCatcher() { registrar_.Add(this, NotificationType::EXTENSION_TEST_PASSED, NotificationService::AllSources()); @@ -26,19 +22,18 @@ bool ExtensionApiTest::ResultCatcher::GetNextResult() { // to RunMessageLoop(), so we maintain a queue of results and just pull them // off as the test calls this, going to the run loop only when the queue is // empty. - if (!results_.size()) { - MessageLoop::current()->PostDelayedTask( - FROM_HERE, new MessageLoop::QuitTask, kTimeoutMs); + if (results_.empty()) ui_test_utils::RunMessageLoop(); - } - if (results_.size()) { + + if (!results_.empty()) { bool ret = results_.front(); results_.pop_front(); message_ = messages_.front(); messages_.pop_front(); return ret; } - message_ = "No response from message loop."; + + NOTREACHED(); return false; } diff --git a/chrome/browser/extensions/extension_browsertest.cc b/chrome/browser/extensions/extension_browsertest.cc index 90cca84..a6280a2 100644 --- a/chrome/browser/extensions/extension_browsertest.cc +++ b/chrome/browser/extensions/extension_browsertest.cc @@ -157,8 +157,9 @@ bool ExtensionBrowserTest::InstallOrUpdateExtension(const std::string& id, void ExtensionBrowserTest::ReloadExtension(const std::string& extension_id) { ExtensionsService* service = browser()->profile()->GetExtensionsService(); service->ReloadExtension(extension_id); - ui_test_utils::RegisterAndWait(NotificationType::EXTENSION_PROCESS_CREATED, - this); + ui_test_utils::RegisterAndWait(this, + NotificationType::EXTENSION_PROCESS_CREATED, + NotificationService::AllSources()); } void ExtensionBrowserTest::UnloadExtension(const std::string& extension_id) { @@ -182,30 +183,26 @@ void ExtensionBrowserTest::EnableExtension(const std::string& extension_id) { } bool ExtensionBrowserTest::WaitForPageActionCountChangeTo(int count) { - NotificationRegistrar registrar; - registrar.Add(this, - NotificationType::EXTENSION_PAGE_ACTION_COUNT_CHANGED, - NotificationService::AllSources()); - - target_page_action_count_ = count; LocationBarTesting* location_bar = browser()->window()->GetLocationBar()->GetLocationBarForTesting(); - if (location_bar->PageActionCount() != count) - ui_test_utils::RunMessageLoop(); + if (location_bar->PageActionCount() != count) { + target_page_action_count_ = count; + ui_test_utils::RegisterAndWait(this, + NotificationType::EXTENSION_PAGE_ACTION_COUNT_CHANGED, + NotificationService::AllSources()); + } return location_bar->PageActionCount() == count; } bool ExtensionBrowserTest::WaitForPageActionVisibilityChangeTo(int count) { - NotificationRegistrar registrar; - registrar.Add(this, - NotificationType::EXTENSION_PAGE_ACTION_VISIBILITY_CHANGED, - NotificationService::AllSources()); - - target_visible_page_action_count_ = count; LocationBarTesting* location_bar = browser()->window()->GetLocationBar()->GetLocationBarForTesting(); - if (location_bar->PageActionVisibleCount() != count) - ui_test_utils::RunMessageLoop(); + if (location_bar->PageActionVisibleCount() != count) { + target_visible_page_action_count_ = count; + ui_test_utils::RegisterAndWait(this, + NotificationType::EXTENSION_PAGE_ACTION_VISIBILITY_CHANGED, + NotificationService::AllSources()); + } return location_bar->PageActionVisibleCount() == count; } @@ -237,19 +234,22 @@ bool ExtensionBrowserTest::WaitForExtensionHostsToLoad() { bool ExtensionBrowserTest::WaitForExtensionInstall() { int before = extension_installs_observed_; - ui_test_utils::RegisterAndWait(NotificationType::EXTENSION_INSTALLED, this); + ui_test_utils::RegisterAndWait(this, NotificationType::EXTENSION_INSTALLED, + NotificationService::AllSources()); return extension_installs_observed_ == (before + 1); } bool ExtensionBrowserTest::WaitForExtensionInstallError() { int before = extension_installs_observed_; - ui_test_utils::RegisterAndWait(NotificationType::EXTENSION_INSTALL_ERROR, - this); + ui_test_utils::RegisterAndWait(this, + NotificationType::EXTENSION_INSTALL_ERROR, + NotificationService::AllSources()); return extension_installs_observed_ == before; } void ExtensionBrowserTest::WaitForExtensionLoad() { - ui_test_utils::RegisterAndWait(NotificationType::EXTENSION_LOADED, this); + ui_test_utils::RegisterAndWait(this, NotificationType::EXTENSION_LOADED, + NotificationService::AllSources()); WaitForExtensionHostsToLoad(); } @@ -261,8 +261,9 @@ bool ExtensionBrowserTest::WaitForExtensionCrash( // The extension is already unloaded, presumably due to a crash. return true; } - ui_test_utils::RegisterAndWait(NotificationType::EXTENSION_PROCESS_TERMINATED, - this); + ui_test_utils::RegisterAndWait(this, + NotificationType::EXTENSION_PROCESS_TERMINATED, + NotificationService::AllSources()); return (service->GetExtensionById(extension_id, true) == NULL); } diff --git a/chrome/browser/extensions/extension_devtools_browsertest.h b/chrome/browser/extensions/extension_devtools_browsertest.h index 7fa6435..a29d3e5 100644 --- a/chrome/browser/extensions/extension_devtools_browsertest.h +++ b/chrome/browser/extensions/extension_devtools_browsertest.h @@ -13,10 +13,6 @@ class ExtensionDevToolsBrowserTest : public ExtensionBrowserTest { protected: virtual void SetUpCommandLine(CommandLine* command_line); - - private: - - NotificationRegistrar registrar_; }; #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_DEVTOOLS_BROWSERTEST_H_ diff --git a/chrome/browser/extensions/extension_startup_unittest.cc b/chrome/browser/extensions/extension_startup_unittest.cc index 4dc6efd..1e1bbe3 100644 --- a/chrome/browser/extensions/extension_startup_unittest.cc +++ b/chrome/browser/extensions/extension_startup_unittest.cc @@ -28,8 +28,7 @@ // had many silly bugs where command line flags did not get propagated correctly // into the services, so we didn't start correctly. -class ExtensionStartupTestBase - : public InProcessBrowserTest, public NotificationObserver { +class ExtensionStartupTestBase : public InProcessBrowserTest { public: ExtensionStartupTestBase() : enable_extensions_(false) { } @@ -67,36 +66,18 @@ class ExtensionStartupTestBase } } - // NotificationObserver - virtual void Observe(NotificationType type, - const NotificationSource& source, - const NotificationDetails& details) { - switch (type.value) { - case NotificationType::EXTENSIONS_READY: - case NotificationType::USER_SCRIPTS_UPDATED: - MessageLoopForUI::current()->Quit(); - break; - default: - NOTREACHED(); - } - } - virtual void TearDown() { - file_util::Delete(preferences_file_, false); - file_util::Delete(user_scripts_dir_, true); - file_util::Delete(extensions_dir_, true); + EXPECT_TRUE(file_util::Delete(preferences_file_, false)); + EXPECT_TRUE(file_util::Delete(user_scripts_dir_, true)); + EXPECT_TRUE(file_util::Delete(extensions_dir_, true)); } void WaitForServicesToStart(int num_expected_extensions, bool expect_extensions_enabled) { ExtensionsService* service = browser()->profile()->GetExtensionsService(); - if (!service->is_ready()) { - registrar_.Add(this, NotificationType::EXTENSIONS_READY, - NotificationService::AllSources()); - ui_test_utils::RunMessageLoop(); - registrar_.Remove(this, NotificationType::EXTENSIONS_READY, - NotificationService::AllSources()); - } + if (!service->is_ready()) + ui_test_utils::WaitForNotification(NotificationType::EXTENSIONS_READY); + ASSERT_TRUE(service->is_ready()); ASSERT_EQ(static_cast<uint32>(num_expected_extensions), service->extensions()->size()); @@ -104,12 +85,8 @@ class ExtensionStartupTestBase UserScriptMaster* master = browser()->profile()->GetUserScriptMaster(); if (!master->ScriptsReady()) { - // Wait for UserScriptMaster to finish its scan. - registrar_.Add(this, NotificationType::USER_SCRIPTS_UPDATED, - NotificationService::AllSources()); - ui_test_utils::RunMessageLoop(); - registrar_.Remove(this, NotificationType::USER_SCRIPTS_UPDATED, - NotificationService::AllSources()); + ui_test_utils::WaitForNotification( + NotificationType::USER_SCRIPTS_UPDATED); } ASSERT_TRUE(master->ScriptsReady()); } @@ -145,7 +122,6 @@ class ExtensionStartupTestBase FilePath user_scripts_dir_; bool enable_extensions_; FilePath load_extension_; - NotificationRegistrar registrar_; }; |