summaryrefslogtreecommitdiffstats
path: root/chrome/test
diff options
context:
space:
mode:
authorjcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-12-16 18:35:52 +0000
committerjcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-12-16 18:35:52 +0000
commit47c5103a4c932bd88ed0a623d30cd6ff5cab0b44 (patch)
treeb1cc5329401dfb157f977dc68a7b0844836cabef /chrome/test
parente6dd571eecc5b3bbcf1151a805ff2fadcf02f979 (diff)
downloadchromium_src-47c5103a4c932bd88ed0a623d30cd6ff5cab0b44.zip
chromium_src-47c5103a4c932bd88ed0a623d30cd6ff5cab0b44.tar.gz
chromium_src-47c5103a4c932bd88ed0a623d30cd6ff5cab0b44.tar.bz2
Makes the language detection happen with every page load
as we do with the page indexing. (The language detection was previously done on demand when the extension related API was querying it.) Once detected the language is stored on the navigation entry. It'll be used for the upcoming translation feature. Also I moved the existing language detection from the UI to the file thread. The change required few changes for the chrome.tabs.detectLanguage extension API to still work. BUG=None TEST=Run the browser tests and unit-tests. Review URL: http://codereview.chromium.org/492024 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@34728 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test')
-rw-r--r--chrome/test/data/english_page.html6
-rw-r--r--chrome/test/data/french_page.html6
-rw-r--r--chrome/test/ui_test_utils.cc32
-rw-r--r--chrome/test/ui_test_utils.h4
4 files changed, 48 insertions, 0 deletions
diff --git a/chrome/test/data/english_page.html b/chrome/test/data/english_page.html
new file mode 100644
index 0000000..539920d
--- /dev/null
+++ b/chrome/test/data/english_page.html
@@ -0,0 +1,6 @@
+<html>
+<head><title>This page is in English</title></head>
+<body>
+No joke! This is a page written in English. Awesome don't you think?
+</body>
+</html>
diff --git a/chrome/test/data/french_page.html b/chrome/test/data/french_page.html
new file mode 100644
index 0000000..7fcf684
--- /dev/null
+++ b/chrome/test/data/french_page.html
@@ -0,0 +1,6 @@
+<html>
+<head><title>Cette page est en Français</title></head>
+<body>
+Cette page a été rédigée en français. Saviez-vous que le Français est la langue officielle des jeux olympiques? Ça vous en bouche un coin, pas vrai?
+</body>
+</html>
diff --git a/chrome/test/ui_test_utils.cc b/chrome/test/ui_test_utils.cc
index 6723084..e4b5818 100644
--- a/chrome/test/ui_test_utils.cc
+++ b/chrome/test/ui_test_utils.cc
@@ -254,6 +254,33 @@ class SimpleNotificationObserver : public NotificationObserver {
DISALLOW_COPY_AND_ASSIGN(SimpleNotificationObserver);
};
+class LanguageDetectionNotificationObserver : public NotificationObserver {
+ public:
+ explicit LanguageDetectionNotificationObserver(
+ RenderViewHost* render_view_host) {
+ registrar_.Add(this, NotificationType::TAB_LANGUAGE_DETERMINED,
+ Source<RenderViewHost>(render_view_host));
+ 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)
@@ -484,6 +511,11 @@ void WaitForFocusInBrowser(Browser* browser) {
browser);
}
+std::string WaitForLanguageDetection(TabContents* tab) {
+ LanguageDetectionNotificationObserver observer(tab->render_view_host());
+ 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 89dc8fc..2c4cd95 100644
--- a/chrome/test/ui_test_utils.h
+++ b/chrome/test/ui_test_utils.h
@@ -115,6 +115,10 @@ 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.