From 47c5103a4c932bd88ed0a623d30cd6ff5cab0b44 Mon Sep 17 00:00:00 2001 From: "jcampan@chromium.org" Date: Wed, 16 Dec 2009 18:35:52 +0000 Subject: 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 --- chrome/test/ui_test_utils.cc | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'chrome/test/ui_test_utils.cc') 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(render_view_host)); + ui_test_utils::RunMessageLoop(); + } + + virtual void Observe(NotificationType type, + const NotificationSource& source, + const NotificationDetails& details) { + language_ = *(Details(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); -- cgit v1.1