diff options
author | jcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-03 23:01:10 +0000 |
---|---|---|
committer | jcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-03 23:01:10 +0000 |
commit | 50501181e41c307f353432ba8aa176a366999611 (patch) | |
tree | 01f7d2ce058cb87b28c50f36c301d6017916b7a2 /chrome/browser/translate/translate_manager_unittest.cc | |
parent | 32e851ac4653283d8602cdf20ac1c689416389c8 (diff) | |
download | chromium_src-50501181e41c307f353432ba8aa176a366999611.zip chromium_src-50501181e41c307f353432ba8aa176a366999611.tar.gz chromium_src-50501181e41c307f353432ba8aa176a366999611.tar.bz2 |
The browser would crash when pressing the translate button in the infobar when the locale is Norvegian,
Filipino or any Chrome languages that the translation server does not support.
The crash would happen in the translate infobar, the source index would be
-1 and would cause us to crash accessing that index in a vector.
This CL fixes that by cleaning up the list of supported languages, so they
match Chrome's locales.
Also it makes sure we don't create an infobar if for any reason one of the
language (source or target) is not supported.
BUG=37218
TEST=For each language Chrome can be run into, select that language and open
www.google.com. Check that the info-bar is shown for languages supported
by the Google translate server (see the list at http://translate.google.com/)
and for the supported language translating works.
Review URL: http://codereview.chromium.org/661434
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@40558 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/translate/translate_manager_unittest.cc')
-rw-r--r-- | chrome/browser/translate/translate_manager_unittest.cc | 47 |
1 files changed, 38 insertions, 9 deletions
diff --git a/chrome/browser/translate/translate_manager_unittest.cc b/chrome/browser/translate/translate_manager_unittest.cc index eb63416..476faa7 100644 --- a/chrome/browser/translate/translate_manager_unittest.cc +++ b/chrome/browser/translate/translate_manager_unittest.cc @@ -12,6 +12,7 @@ #include "chrome/common/notification_service.h" #include "chrome/common/pref_names.h" #include "chrome/common/render_messages.h" +#include "chrome/test/testing_browser_process.h" class TestTranslateManager : public TranslateManager { public: @@ -23,7 +24,7 @@ class TranslateManagerTest : public RenderViewHostTestHarness, public: TranslateManagerTest() {} - // Simluates navigating to a page and getting teh page contents and language + // Simluates navigating to a page and getting the page contents and language // for that navigation. void SimulateNavigation(const GURL& url, int page_id, const std::wstring& contents, @@ -207,7 +208,7 @@ TEST_F(TranslateManagerTest, NormalTranslate) { // Tests auto-translate on page. TEST_F(TranslateManagerTest, AutoTranslateOnNavigate) { - // Simulate navigating to a page and gettings its language. + // Simulate navigating to a page and getting its language. SimulateNavigation(GURL("http://www.google.fr"), 0, L"Le Google", "fr"); // Simulate the user translating. @@ -238,7 +239,7 @@ TEST_F(TranslateManagerTest, AutoTranslateOnNavigate) { // Tests that multiple OnPageContents do not cause multiple infobars. TEST_F(TranslateManagerTest, MultipleOnPageContents) { - // Simulate navigating to a page and gettings its language. + // Simulate navigating to a page and getting its language. SimulateNavigation(GURL("http://www.google.fr"), 0, L"Le Google", "fr"); // Simulate clicking 'Nope' (don't translate). @@ -259,7 +260,7 @@ TEST_F(TranslateManagerTest, MultipleOnPageContents) { // Test that reloading the page brings back the infobar. TEST_F(TranslateManagerTest, Reload) { - // Simulate navigating to a page and gettings its language. + // Simulate navigating to a page and getting its language. SimulateNavigation(GURL("http://www.google.fr"), 0, L"Le Google", "fr"); // Close the infobar. @@ -276,7 +277,7 @@ TEST_F(TranslateManagerTest, Reload) { // Tests that a close translate infobar does not reappear when navigating // in-page. TEST_F(TranslateManagerTest, CloseInfoBarInPageNavigation) { - // Simulate navigating to a page and gettings its language. + // Simulate navigating to a page and getting its language. SimulateNavigation(GURL("http://www.google.fr"), 0, L"Le Google", "fr"); // Close the infobar. @@ -293,7 +294,7 @@ TEST_F(TranslateManagerTest, CloseInfoBarInPageNavigation) { // Tests that denying translation is sticky when navigating in page. TEST_F(TranslateManagerTest, DenyTranslateInPageNavigation) { - // Simulate navigating to a page and gettings its language. + // Simulate navigating to a page and getting its language. SimulateNavigation(GURL("http://www.google.fr"), 0, L"Le Google", "fr"); // Simulate clicking 'Nope' (don't translate). @@ -311,7 +312,7 @@ TEST_F(TranslateManagerTest, DenyTranslateInPageNavigation) { // Tests that after translating and closing the infobar, the infobar does not // return when navigating in page. TEST_F(TranslateManagerTest, TranslateCloseInfoBarInPageNavigation) { - // Simulate navigating to a page and gettings its language. + // Simulate navigating to a page and getting its language. SimulateNavigation(GURL("http://www.google.fr"), 0, L"Le Google", "fr"); // Simulate the user translating. @@ -338,7 +339,7 @@ TEST_F(TranslateManagerTest, TranslateCloseInfoBarInPageNavigation) { // Tests that the after translate the infobar still shows when navigating // in-page. TEST_F(TranslateManagerTest, TranslateInPageNavigation) { - // Simulate navigating to a page and gettings its language. + // Simulate navigating to a page and getting its language. SimulateNavigation(GURL("http://www.google.fr"), 0, L"Le Google", "fr"); // Simulate the user translating. @@ -362,13 +363,41 @@ TEST_F(TranslateManagerTest, TranslateInPageNavigation) { EXPECT_TRUE(GetTranslateInfoBar() != NULL); } +// Tests that no translate infobar is shown when navigating to a page in an +// unsupported language. +TEST_F(TranslateManagerTest, UnsupportedPageLanguage) { + // Simulate navigating to a page and getting an unsupported language. + SimulateNavigation(GURL("http://www.google.com"), 0, L"Google", "qbz"); + + // No info-bar should be shown. + EXPECT_TRUE(GetTranslateInfoBar() == NULL); +} + +// Tests that no translate infobar is shown when Chrome is in a language that +// the translate server does not support. +TEST_F(TranslateManagerTest, UnsupportedUILanguage) { + TestingBrowserProcess* browser_process = + static_cast<TestingBrowserProcess*>(g_browser_process); + std::string original_lang = browser_process->GetApplicationLocale(); + browser_process->set_application_locale("qbz"); + + // Simulate navigating to a page in a language supported by the translate + // server. + SimulateNavigation(GURL("http://www.google.com"), 0, L"Google", "en"); + + // No info-bar should be shown. + EXPECT_TRUE(GetTranslateInfoBar() == NULL); + + browser_process->set_application_locale(original_lang); +} + // Tests that the translate preference is honored. TEST_F(TranslateManagerTest, TranslatePref) { // Make sure the pref allows translate. PrefService* prefs = contents()->profile()->GetPrefs(); prefs->SetBoolean(prefs::kEnableTranslate, true); - // Simulate navigating to a page and gettings its language. + // Simulate navigating to a page and getting its language. SimulateNavigation(GURL("http://www.google.fr"), 0, L"Le Google", "fr"); // An infobar should be shown. |