diff options
author | jcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-01-07 21:41:50 +0000 |
---|---|---|
committer | jcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-01-07 21:41:50 +0000 |
commit | 807cb1036f557b8e24306c66a6bac9bfb0c804af (patch) | |
tree | b10af2181ae1e2ce1640f868a217a868332ecc3e /chrome/test/ui_test_utils.cc | |
parent | 462474b9444dcda47b5c140f5d31b790610b6176 (diff) | |
download | chromium_src-807cb1036f557b8e24306c66a6bac9bfb0c804af.zip chromium_src-807cb1036f557b8e24306c66a6bac9bfb0c804af.tar.gz chromium_src-807cb1036f557b8e24306c66a6bac9bfb0c804af.tar.bz2 |
Relanding the language detection code.
The code would crash if multiple PageContents notifications
were received rapidly. The CLDHelper now notifies the
TabContents directly and the TabContents ensures only one
language detection can be performed at a time.
Added unit-tests to validate these cases in web_contents_unittest.cc.
Note that patch set 1 is the original patch, patch set 2 contains the new changes.
Original review:
http://codereview.chromium.org/492024/show
BUG=30662
TEST=Run the unit-tests.
Review URL: http://codereview.chromium.org/504051
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@35735 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test/ui_test_utils.cc')
-rw-r--r-- | chrome/test/ui_test_utils.cc | 32 |
1 files changed, 32 insertions, 0 deletions
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); |