summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/autocomplete/autocomplete_browsertest.cc20
-rw-r--r--chrome/browser/browser_browsertest.cc7
-rw-r--r--chrome/browser/browser_init_browsertest.cc5
-rw-r--r--chrome/browser/crash_recovery_browsertest.cc36
-rw-r--r--chrome/browser/download/save_page_browsertest.cc52
-rw-r--r--chrome/browser/extensions/extension_apitest.cc15
-rw-r--r--chrome/browser/extensions/extension_browsertest.cc49
-rw-r--r--chrome/browser/extensions/extension_devtools_browsertest.h4
-rw-r--r--chrome/browser/extensions/extension_startup_unittest.cc42
-rw-r--r--chrome/test/ui_test_utils.cc116
-rw-r--r--chrome/test/ui_test_utils.h40
11 files changed, 134 insertions, 252 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 142ed9a..799c6ac 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());
@@ -113,9 +90,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());
@@ -156,9 +131,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_;
};
diff --git a/chrome/test/ui_test_utils.cc b/chrome/test/ui_test_utils.cc
index b334e05..612d921 100644
--- a/chrome/test/ui_test_utils.cc
+++ b/chrome/test/ui_test_utils.cc
@@ -215,62 +215,6 @@ class DownloadsCompleteObserver : public DownloadManager::Observer,
DISALLOW_COPY_AND_ASSIGN(DownloadsCompleteObserver);
};
-template <class T>
-class SimpleNotificationObserver : public NotificationObserver {
- public:
- SimpleNotificationObserver(NotificationType notification_type,
- T* source) {
- registrar_.Add(this, notification_type, Source<T>(source));
- ui_test_utils::RunMessageLoop();
- }
-
- virtual void Observe(NotificationType type,
- const NotificationSource& source,
- const NotificationDetails& details) {
- MessageLoopForUI::current()->Quit();
- }
-
- private:
- NotificationRegistrar registrar_;
-
- DISALLOW_COPY_AND_ASSIGN(SimpleNotificationObserver);
-};
-
-// SimpleNotificationObserver that waits for a single notification. When the
-// notification is observer the source (of type S) is recorded and the message
-// loop stopped. Use |source()| to access the source after the constructor
-// returns.
-template <class S>
-class SimpleNotificationObserverWithSource : public NotificationObserver {
- public:
- SimpleNotificationObserverWithSource(NotificationType notification_type,
- const NotificationSource& source)
- : source_(NULL) {
- registrar_.Add(this, notification_type, source);
- ui_test_utils::RunMessageLoop();
- }
-
- virtual void Observe(NotificationType type,
- const NotificationSource& source,
- const NotificationDetails& details) {
- source_ = Source<S>(source).ptr();
-
- // Remove observer now, so that if there any other notifications we don't
- // clobber source_.
- registrar_.RemoveAll();
-
- MessageLoopForUI::current()->Quit();
- }
-
- S* source() const { return source_; }
-
- private:
- S* source_;
- NotificationRegistrar registrar_;
-
- DISALLOW_COPY_AND_ASSIGN(SimpleNotificationObserverWithSource);
-};
-
class LanguageDetectionNotificationObserver : public NotificationObserver {
public:
explicit LanguageDetectionNotificationObserver(TabContents* tab) {
@@ -438,26 +382,28 @@ void WaitForNavigations(NavigationController* controller,
}
void WaitForNewTab(Browser* browser) {
- SimpleNotificationObserver<Browser>
- new_tab_observer(NotificationType::TAB_ADDED, browser);
+ TestNotificationObserver observer;
+ RegisterAndWait(&observer, NotificationType::TAB_ADDED,
+ Source<Browser>(browser));
}
void WaitForBrowserActionUpdated(ExtensionAction* browser_action) {
- SimpleNotificationObserver<ExtensionAction>
- observer(NotificationType::EXTENSION_BROWSER_ACTION_UPDATED,
- browser_action);
+ TestNotificationObserver observer;
+ RegisterAndWait(&observer, NotificationType::EXTENSION_BROWSER_ACTION_UPDATED,
+ Source<ExtensionAction>(browser_action));
}
void WaitForLoadStop(NavigationController* controller) {
- SimpleNotificationObserver<NavigationController>
- new_tab_observer(NotificationType::LOAD_STOP, controller);
+ TestNotificationObserver observer;
+ RegisterAndWait(&observer, NotificationType::LOAD_STOP,
+ Source<NavigationController>(controller));
}
Browser* WaitForNewBrowser() {
- SimpleNotificationObserverWithSource<Browser> observer(
- NotificationType::BROWSER_WINDOW_READY,
- NotificationService::AllSources());
- return observer.source();
+ TestNotificationObserver observer;
+ RegisterAndWait(&observer, NotificationType::BROWSER_WINDOW_READY,
+ NotificationService::AllSources());
+ return Source<Browser>(observer.source()).ptr();
}
void OpenURLOffTheRecord(Profile* profile, const GURL& url) {
@@ -571,28 +517,30 @@ void WaitForDownloadCount(DownloadManager* download_manager, size_t count) {
}
AppModalDialog* WaitForAppModalDialog() {
- SimpleNotificationObserverWithSource<AppModalDialog> observer(
- NotificationType::APP_MODAL_DIALOG_SHOWN,
- NotificationService::AllSources());
- return observer.source();
+ TestNotificationObserver observer;
+ RegisterAndWait(&observer, NotificationType::APP_MODAL_DIALOG_SHOWN,
+ NotificationService::AllSources());
+ return Source<AppModalDialog>(observer.source()).ptr();
}
void CrashTab(TabContents* tab) {
RenderProcessHost* rph = tab->render_view_host()->process();
base::KillProcess(rph->GetHandle(), 0, false);
- SimpleNotificationObserver<RenderProcessHost>
- crash_observer(NotificationType::RENDERER_PROCESS_CLOSED, rph);
+ TestNotificationObserver observer;
+ RegisterAndWait(&observer, NotificationType::RENDERER_PROCESS_CLOSED,
+ Source<RenderProcessHost>(rph));
}
void WaitForFocusChange(RenderViewHost* rvh) {
- SimpleNotificationObserver<RenderViewHost>
- focus_observer(NotificationType::FOCUS_CHANGED_IN_PAGE, rvh);
+ TestNotificationObserver observer;
+ RegisterAndWait(&observer, NotificationType::FOCUS_CHANGED_IN_PAGE,
+ Source<RenderViewHost>(rvh));
}
void WaitForFocusInBrowser(Browser* browser) {
- SimpleNotificationObserver<Browser>
- focus_observer(NotificationType::FOCUS_RETURNED_TO_BROWSER,
- browser);
+ TestNotificationObserver observer;
+ RegisterAndWait(&observer, NotificationType::FOCUS_RETURNED_TO_BROWSER,
+ Source<Browser>(browser));
}
std::string WaitForLanguageDetection(TabContents* tab) {
@@ -609,10 +557,16 @@ int FindInPage(TabContents* tab_contents, const string16& search_string,
return observer.number_of_matches();
}
-void RegisterAndWait(NotificationType::Type type,
- NotificationObserver* observer) {
+void WaitForNotification(NotificationType::Type type) {
+ TestNotificationObserver observer;
+ RegisterAndWait(&observer, type, NotificationService::AllSources());
+}
+
+void RegisterAndWait(NotificationObserver* observer,
+ NotificationType::Type type,
+ const NotificationSource& source) {
NotificationRegistrar registrar;
- registrar.Add(observer, type, NotificationService::AllSources());
+ registrar.Add(observer, type, source);
RunMessageLoop();
}
diff --git a/chrome/test/ui_test_utils.h b/chrome/test/ui_test_utils.h
index b247a19..9543f9d 100644
--- a/chrome/test/ui_test_utils.h
+++ b/chrome/test/ui_test_utils.h
@@ -175,10 +175,14 @@ bool IsViewFocused(const Browser* browser, ViewID vid);
// Simulates a mouse click on a View in the browser.
void ClickOnView(const Browser* browser, ViewID vid);
-// Register |observer| for the given |type| and run the message loop until
-// the observer posts a quit task.
-void RegisterAndWait(NotificationType::Type type,
- NotificationObserver* observer);
+// Blocks until a notification for given |type| is received.
+void WaitForNotification(NotificationType::Type type);
+
+// Register |observer| for the given |type| and |source| and run
+// the message loop until the observer posts a quit task.
+void RegisterAndWait(NotificationObserver* observer,
+ NotificationType::Type type,
+ const NotificationSource& source);
// Run a message loop only for the specified amount of time.
class TimedMessageLoopRunner {
@@ -252,6 +256,34 @@ class TestWebSocketServer {
DISALLOW_COPY_AND_ASSIGN(TestWebSocketServer);
};
+// A notification observer which quits the message loop when a notification
+// is received. It also records the source and details of the notification.
+class TestNotificationObserver : public NotificationObserver {
+ public:
+ TestNotificationObserver() : source_(NotificationService::AllSources()) {
+ }
+
+ virtual void Observe(NotificationType type,
+ const NotificationSource& source,
+ const NotificationDetails& details) {
+ source_ = source;
+ details_ = details;
+ MessageLoopForUI::current()->Quit();
+ }
+
+ const NotificationSource& source() const {
+ return source_;
+ }
+
+ const NotificationDetails& details() const {
+ return details_;
+ }
+
+ private:
+ NotificationSource source_;
+ NotificationDetails details_;
+};
+
// A WindowedNotificationObserver allows code to watch for a notification
// over a window of time. Typically testing code will need to do something
// like this: