summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorjcivelli@chromium.org <jcivelli@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-19 05:29:14 +0000
committerjcivelli@chromium.org <jcivelli@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-19 05:29:14 +0000
commiteb3895186d79897fc17310cae771ce2d8df32066 (patch)
treec6423387ba3366c7503db22c4450e280e0d0375a /chrome
parentd6abb667e3ef8fcdf3a01e287e01bb3729b77f18 (diff)
downloadchromium_src-eb3895186d79897fc17310cae771ce2d8df32066.zip
chromium_src-eb3895186d79897fc17310cae771ce2d8df32066.tar.gz
chromium_src-eb3895186d79897fc17310cae771ce2d8df32066.tar.bz2
Attempt at fixing flakyness of the browser test:
BrowserTest.PageLanguageDetection. BUG=40962 TEST=The test should not be flaky anymore. Review URL: http://codereview.chromium.org/1642002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@44903 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/browser_browsertest.cc19
-rw-r--r--chrome/test/ui_test_utils.cc31
-rw-r--r--chrome/test/ui_test_utils.h39
3 files changed, 50 insertions, 39 deletions
diff --git a/chrome/browser/browser_browsertest.cc b/chrome/browser/browser_browsertest.cc
index cc6883c..4a60ef4 100644
--- a/chrome/browser/browser_browsertest.cc
+++ b/chrome/browser/browser_browsertest.cc
@@ -455,8 +455,7 @@ IN_PROC_BROWSER_TEST_F(BrowserTest, AppTabRemovedWhenExtensionUninstalled) {
#endif // !defined(OS_MACOSX)
// Tests that the CLD (Compact Language Detection) works properly.
-// Crashy, http://crbug.com/40962.
-IN_PROC_BROWSER_TEST_F(BrowserTest, DISABLED_PageLanguageDetection) {
+IN_PROC_BROWSER_TEST_F(BrowserTest, PageLanguageDetection) {
static const wchar_t kDocRoot[] = L"chrome/test/data";
scoped_refptr<HTTPTestServer> server(
HTTPTestServer::CreateServer(kDocRoot, NULL));
@@ -465,18 +464,30 @@ IN_PROC_BROWSER_TEST_F(BrowserTest, DISABLED_PageLanguageDetection) {
TabContents* current_tab = browser()->GetSelectedTabContents();
// Navigate to a page in English.
+ ui_test_utils::WindowedNotificationObserverWithDetails<TabContents,
+ std::string>
+ en_language_detected_signal(NotificationType::TAB_LANGUAGE_DETERMINED,
+ current_tab);
ui_test_utils::NavigateToURL(
browser(), GURL(server->TestServerPage("files/english_page.html")));
EXPECT_TRUE(current_tab->language_state().original_language().empty());
- std::string lang = ui_test_utils::WaitForLanguageDetection(current_tab);
+ en_language_detected_signal.Wait();
+ std::string lang;
+ EXPECT_TRUE(en_language_detected_signal.GetDetailsFor(current_tab, &lang));
EXPECT_EQ("en", lang);
EXPECT_EQ("en", current_tab->language_state().original_language());
// Now navigate to a page in French.
+ ui_test_utils::WindowedNotificationObserverWithDetails<TabContents,
+ std::string>
+ fr_language_detected_signal(NotificationType::TAB_LANGUAGE_DETERMINED,
+ current_tab);
ui_test_utils::NavigateToURL(
browser(), GURL(server->TestServerPage("files/french_page.html")));
EXPECT_TRUE(current_tab->language_state().original_language().empty());
- lang = ui_test_utils::WaitForLanguageDetection(current_tab);
+ fr_language_detected_signal.Wait();
+ lang.clear();
+ EXPECT_TRUE(fr_language_detected_signal.GetDetailsFor(current_tab, &lang));
EXPECT_EQ("fr", lang);
EXPECT_EQ("fr", current_tab->language_state().original_language());
}
diff --git a/chrome/test/ui_test_utils.cc b/chrome/test/ui_test_utils.cc
index 8b86ff8..dec305b 100644
--- a/chrome/test/ui_test_utils.cc
+++ b/chrome/test/ui_test_utils.cc
@@ -215,32 +215,6 @@ class DownloadsCompleteObserver : public DownloadManager::Observer,
DISALLOW_COPY_AND_ASSIGN(DownloadsCompleteObserver);
};
-class LanguageDetectionNotificationObserver : public NotificationObserver {
- public:
- explicit LanguageDetectionNotificationObserver(TabContents* tab) {
- registrar_.Add(this, NotificationType::TAB_LANGUAGE_DETERMINED,
- Source<TabContents>(tab));
- ui_test_utils::RunMessageLoop();
- }
-
- virtual void Observe(NotificationType type,
- const NotificationSource& source,
- const NotificationDetails& details) {
- language_ = *(Details<std::string>(details).ptr());
- MessageLoopForUI::current()->Quit();
- }
-
- std::string language() const {
- return language_;
- }
-
- private:
- NotificationRegistrar registrar_;
- std::string language_;
-
- DISALLOW_COPY_AND_ASSIGN(LanguageDetectionNotificationObserver);
-};
-
class FindInPageNotificationObserver : public NotificationObserver {
public:
explicit FindInPageNotificationObserver(TabContents* parent_tab)
@@ -543,11 +517,6 @@ void WaitForFocusInBrowser(Browser* browser) {
Source<Browser>(browser));
}
-std::string WaitForLanguageDetection(TabContents* tab) {
- LanguageDetectionNotificationObserver observer(tab);
- return observer.language();
-}
-
int FindInPage(TabContents* tab_contents, const string16& search_string,
bool forward, bool match_case, int* ordinal) {
tab_contents->StartFinding(search_string, forward, match_case);
diff --git a/chrome/test/ui_test_utils.h b/chrome/test/ui_test_utils.h
index 72c34c2..e125e61 100644
--- a/chrome/test/ui_test_utils.h
+++ b/chrome/test/ui_test_utils.h
@@ -5,6 +5,7 @@
#ifndef CHROME_TEST_UI_TEST_UTILS_H_
#define CHROME_TEST_UI_TEST_UTILS_H_
+#include <map>
#include <string>
#include <set>
@@ -156,10 +157,6 @@ void WaitForFocusChange(RenderViewHost* rvh);
// traversal).
void WaitForFocusInBrowser(Browser* browser);
-// Waits for the language of the page to have been detected and returns it.
-// This should be called right after a navigation notification was received.
-std::string WaitForLanguageDetection(TabContents* tab_contents);
-
// Performs a find in the page of the specified tab. Returns the number of
// matches found. |ordinal| is an optional parameter which is set to the index
// of the current match.
@@ -380,6 +377,40 @@ class WindowedNotificationObserver : public NotificationObserver {
DISALLOW_COPY_AND_ASSIGN(WindowedNotificationObserver);
};
+// Similar to WindowedNotificationObserver but also provides a way of retrieving
+// 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>
+class WindowedNotificationObserverWithDetails
+ : public WindowedNotificationObserver<T> {
+ public:
+ WindowedNotificationObserverWithDetails(NotificationType notification_type,
+ T* source)
+ : WindowedNotificationObserver<T>(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);
+ if (iter == details_.end())
+ return false;
+ *details = iter->second;
+ return true;
+ }
+
+ virtual void Observe(NotificationType type,
+ const NotificationSource& source,
+ const NotificationDetails& details) {
+ details_[Source<T>(source).ptr()] = *Details<U>(details).ptr();
+ WindowedNotificationObserver<T>::Observe(type, source, details);
+ }
+
+ private:
+ std::map<T*, U> details_;
+
+ DISALLOW_COPY_AND_ASSIGN(WindowedNotificationObserverWithDetails);
+};
+
} // namespace ui_test_utils
#endif // CHROME_TEST_UI_TEST_UTILS_H_