| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 | 5 |
| 6 #include <algorithm> | 6 #include <algorithm> |
| 7 #include <set> | 7 #include <set> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| (...skipping 851 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 862 process()->sink().GetFirstMessageMatching( | 862 process()->sink().GetFirstMessageMatching( |
| 863 ChromeViewMsg_RevertTranslation::ID); | 863 ChromeViewMsg_RevertTranslation::ID); |
| 864 EXPECT_TRUE(message != NULL); | 864 EXPECT_TRUE(message != NULL); |
| 865 // And it should have removed the infobar. | 865 // And it should have removed the infobar. |
| 866 EXPECT_TRUE(GetTranslateInfoBar() == NULL); | 866 EXPECT_TRUE(GetTranslateInfoBar() == NULL); |
| 867 } | 867 } |
| 868 | 868 |
| 869 // Tests that no translate infobar is shown when Chrome is in a language that | 869 // Tests that no translate infobar is shown when Chrome is in a language that |
| 870 // the translate server does not support. | 870 // the translate server does not support. |
| 871 TEST_F(TranslateManagerTest, UnsupportedUILanguage) { | 871 TEST_F(TranslateManagerTest, UnsupportedUILanguage) { |
| 872 TestingBrowserProcess* browser_process = testing_browser_process_.get(); | 872 std::string original_lang = g_browser_process->GetApplicationLocale(); |
| 873 std::string original_lang = browser_process->GetApplicationLocale(); | 873 g_browser_process->SetApplicationLocale("qbz"); |
| 874 browser_process->SetApplicationLocale("qbz"); | |
| 875 | 874 |
| 876 // Make sure that the accept language list only contains unsupported languages | 875 // Make sure that the accept language list only contains unsupported languages |
| 877 Profile* profile = Profile::FromBrowserContext(contents()->browser_context()); | 876 Profile* profile = Profile::FromBrowserContext(contents()->browser_context()); |
| 878 PrefService* prefs = profile->GetPrefs(); | 877 PrefService* prefs = profile->GetPrefs(); |
| 879 prefs->SetString(prefs::kAcceptLanguages, "qbz"); | 878 prefs->SetString(prefs::kAcceptLanguages, "qbz"); |
| 880 | 879 |
| 881 // Simulate navigating to a page in a language supported by the translate | 880 // Simulate navigating to a page in a language supported by the translate |
| 882 // server. | 881 // server. |
| 883 SimulateNavigation(GURL("http://www.google.com"), "en", true); | 882 SimulateNavigation(GURL("http://www.google.com"), "en", true); |
| 884 | 883 |
| 885 // No info-bar should be shown. | 884 // No info-bar should be shown. |
| 886 EXPECT_TRUE(GetTranslateInfoBar() == NULL); | 885 EXPECT_TRUE(GetTranslateInfoBar() == NULL); |
| 887 | 886 |
| 888 browser_process->SetApplicationLocale(original_lang); | 887 g_browser_process->SetApplicationLocale(original_lang); |
| 889 } | 888 } |
| 890 | 889 |
| 891 // Tests that the first supported accept language is selected | 890 // Tests that the first supported accept language is selected |
| 892 TEST_F(TranslateManagerTest, TranslateAcceptLanguage) { | 891 TEST_F(TranslateManagerTest, TranslateAcceptLanguage) { |
| 893 // Set locate to non-existant language | 892 // Set locate to non-existant language |
| 894 TestingBrowserProcess* browser_process = testing_browser_process_.get(); | 893 std::string original_lang = g_browser_process->GetApplicationLocale(); |
| 895 std::string original_lang = browser_process->GetApplicationLocale(); | 894 g_browser_process->SetApplicationLocale("qbz"); |
| 896 browser_process->SetApplicationLocale("qbz"); | |
| 897 | 895 |
| 898 // Set Qbz and French as the only accepted languages | 896 // Set Qbz and French as the only accepted languages |
| 899 Profile* profile = Profile::FromBrowserContext(contents()->browser_context()); | 897 Profile* profile = Profile::FromBrowserContext(contents()->browser_context()); |
| 900 PrefService* prefs = profile->GetPrefs(); | 898 PrefService* prefs = profile->GetPrefs(); |
| 901 prefs->SetString(prefs::kAcceptLanguages, "qbz,fr"); | 899 prefs->SetString(prefs::kAcceptLanguages, "qbz,fr"); |
| 902 | 900 |
| 903 // Go to a German page | 901 // Go to a German page |
| 904 SimulateNavigation(GURL("http://google.de"), "de", true); | 902 SimulateNavigation(GURL("http://google.de"), "de", true); |
| 905 | 903 |
| 906 // Expect the infobar to pop up | 904 // Expect the infobar to pop up |
| (...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1330 NULL); | 1328 NULL); |
| 1331 // Now simulate the URL fetch. | 1329 // Now simulate the URL fetch. |
| 1332 SimulateTranslateScriptURLFetch(true); | 1330 SimulateTranslateScriptURLFetch(true); |
| 1333 // Now the message should have been sent. | 1331 // Now the message should have been sent. |
| 1334 int page_id = 0; | 1332 int page_id = 0; |
| 1335 std::string original_lang, target_lang; | 1333 std::string original_lang, target_lang; |
| 1336 EXPECT_TRUE(GetTranslateMessage(&page_id, &original_lang, &target_lang)); | 1334 EXPECT_TRUE(GetTranslateMessage(&page_id, &original_lang, &target_lang)); |
| 1337 EXPECT_EQ("es", original_lang); | 1335 EXPECT_EQ("es", original_lang); |
| 1338 EXPECT_EQ("en", target_lang); | 1336 EXPECT_EQ("en", target_lang); |
| 1339 } | 1337 } |
| OLD | NEW |