diff options
author | bryeung@google.com <bryeung@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-12-03 03:53:54 +0000 |
---|---|---|
committer | bryeung@google.com <bryeung@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-12-03 03:53:54 +0000 |
commit | c0751438662d59e24eb79b4a484df4a3fce7d3cc (patch) | |
tree | d48fc6e2612d3f80a5e4934313d58c23e9b4156c /chrome | |
parent | c7b1d2fde3236b8438a326037af08e933eb68905 (diff) | |
download | chromium_src-c0751438662d59e24eb79b4a484df4a3fce7d3cc.zip chromium_src-c0751438662d59e24eb79b4a484df4a3fce7d3cc.tar.gz chromium_src-c0751438662d59e24eb79b4a484df4a3fce7d3cc.tar.bz2 |
Simplfy WindowedNotificationObserverWithDetails.
This change makes the interface to
WindowedNotificationObserverWithDetails closer to that of
WindowedNotificationObserver, which should make it easier to use more
broadly in testing utility code.
I have a follow-up CL that will be somewhat simplified by this change.
BUG=none
TEST=browser_tests compiles and passes
Review URL: http://codereview.chromium.org/5365008
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@68147 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/browser_browsertest.cc | 14 | ||||
-rw-r--r-- | chrome/test/ui_test_utils.h | 16 |
2 files changed, 16 insertions, 14 deletions
diff --git a/chrome/browser/browser_browsertest.cc b/chrome/browser/browser_browsertest.cc index b3d5e08..43a6bab 100644 --- a/chrome/browser/browser_browsertest.cc +++ b/chrome/browser/browser_browsertest.cc @@ -31,8 +31,9 @@ #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/extensions/extension.h" -#include "chrome/common/url_constants.h" +#include "chrome/common/notification_source.h" #include "chrome/common/page_transition_types.h" +#include "chrome/common/url_constants.h" #include "chrome/test/in_process_browser_test.h" #include "chrome/test/ui_test_utils.h" #include "grit/chromium_strings.h" @@ -452,12 +453,12 @@ IN_PROC_BROWSER_TEST_F(BrowserTest, MAYBE_PageLanguageDetection) { ASSERT_TRUE(test_server()->Start()); TabContents* current_tab = browser()->GetSelectedTabContents(); + Source<TabContents> source(current_tab); // Navigate to a page in English. - ui_test_utils::WindowedNotificationObserverWithDetails<TabContents, - std::string> + ui_test_utils::WindowedNotificationObserverWithDetails<std::string> en_language_detected_signal(NotificationType::TAB_LANGUAGE_DETERMINED, - current_tab); + source); ui_test_utils::NavigateToURL( browser(), GURL(test_server()->GetURL("files/english_page.html"))); EXPECT_TRUE(current_tab->language_state().original_language().empty()); @@ -468,10 +469,9 @@ IN_PROC_BROWSER_TEST_F(BrowserTest, MAYBE_PageLanguageDetection) { EXPECT_EQ("en", current_tab->language_state().original_language()); // Now navigate to a page in French. - ui_test_utils::WindowedNotificationObserverWithDetails<TabContents, - std::string> + ui_test_utils::WindowedNotificationObserverWithDetails<std::string> fr_language_detected_signal(NotificationType::TAB_LANGUAGE_DETERMINED, - current_tab); + source); ui_test_utils::NavigateToURL( browser(), GURL(test_server()->GetURL("files/french_page.html"))); EXPECT_TRUE(current_tab->language_state().original_language().empty()); diff --git a/chrome/test/ui_test_utils.h b/chrome/test/ui_test_utils.h index a1eb5bc..09b96f1 100644 --- a/chrome/test/ui_test_utils.h +++ b/chrome/test/ui_test_utils.h @@ -20,6 +20,7 @@ #include "chrome/common/notification_observer.h" #include "chrome/common/notification_registrar.h" #include "chrome/common/notification_service.h" +#include "chrome/common/notification_source.h" #include "chrome/test/automation/dom_element_proxy.h" #include "gfx/native_widget_types.h" @@ -393,17 +394,18 @@ class WindowedNotificationObserver : public NotificationObserver { // the details associated with the notification. // Note that in order to use that class the details class should be copiable, // which is the case with most notifications. -template <class T, class U> +template <class U> class WindowedNotificationObserverWithDetails : public WindowedNotificationObserver { public: WindowedNotificationObserverWithDetails(NotificationType notification_type, - const T* source) - : WindowedNotificationObserver(notification_type, Source<T>(source)) {} + const NotificationSource& source) + : WindowedNotificationObserver(notification_type, source) {} // Fills |details| with the details of the notification received for |source|. - bool GetDetailsFor(T* source, U* details) { - typename std::map<T*, U>::const_iterator iter = details_.find(source); + bool GetDetailsFor(const void* source, U* details) { + typename std::map<uintptr_t, U>::const_iterator iter = + details_.find(reinterpret_cast<uintptr_t>(source)); if (iter == details_.end()) return false; *details = iter->second; @@ -413,12 +415,12 @@ class WindowedNotificationObserverWithDetails virtual void Observe(NotificationType type, const NotificationSource& source, const NotificationDetails& details) { - details_[Source<T>(source).ptr()] = *Details<U>(details).ptr(); + details_[source.map_key()] = *Details<U>(details).ptr(); WindowedNotificationObserver::Observe(type, source, details); } private: - std::map<T*, U> details_; + std::map<uintptr_t, U> details_; DISALLOW_COPY_AND_ASSIGN(WindowedNotificationObserverWithDetails); }; |