Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(21)

Side by Side Diff: chrome/browser/translate/translate_manager_browsertest.cc

Issue 23068005: Convert UserPolicySigninService to use OAuth2TokenService (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge with ToT Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #include <algorithm> 5 #include <algorithm>
6 #include <set> 6 #include <set>
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/prefs/pref_change_registrar.h" 10 #include "base/prefs/pref_change_registrar.h"
(...skipping 1128 matching lines...) Expand 10 before | Expand all | Expand 10 after
1139 // Try another language, it should not be autotranslated. 1139 // Try another language, it should not be autotranslated.
1140 SimulateNavigation(GURL("http://www.google.es"), "es", true); 1140 SimulateNavigation(GURL("http://www.google.es"), "es", true);
1141 EXPECT_FALSE(GetTranslateMessage(&page_id, &original_lang, &target_lang)); 1141 EXPECT_FALSE(GetTranslateMessage(&page_id, &original_lang, &target_lang));
1142 EXPECT_TRUE(GetTranslateInfoBar() != NULL); 1142 EXPECT_TRUE(GetTranslateInfoBar() != NULL);
1143 EXPECT_TRUE(CloseTranslateInfoBar()); 1143 EXPECT_TRUE(CloseTranslateInfoBar());
1144 1144
1145 // Let's switch to incognito mode, it should not be autotranslated in that 1145 // Let's switch to incognito mode, it should not be autotranslated in that
1146 // case either. 1146 // case either.
1147 TestingProfile* test_profile = 1147 TestingProfile* test_profile =
1148 static_cast<TestingProfile*>(web_contents()->GetBrowserContext()); 1148 static_cast<TestingProfile*>(web_contents()->GetBrowserContext());
1149 test_profile->set_incognito(true); 1149 test_profile->ForceIncognito(true);
1150 SimulateNavigation(GURL("http://www.youtube.fr"), "fr", true); 1150 SimulateNavigation(GURL("http://www.youtube.fr"), "fr", true);
1151 EXPECT_FALSE(GetTranslateMessage(&page_id, &original_lang, &target_lang)); 1151 EXPECT_FALSE(GetTranslateMessage(&page_id, &original_lang, &target_lang));
1152 EXPECT_TRUE(GetTranslateInfoBar() != NULL); 1152 EXPECT_TRUE(GetTranslateInfoBar() != NULL);
1153 EXPECT_TRUE(CloseTranslateInfoBar()); 1153 EXPECT_TRUE(CloseTranslateInfoBar());
1154 test_profile->set_incognito(false); // Get back to non incognito. 1154 test_profile->ForceIncognito(false); // Get back to non incognito.
1155 1155
1156 // Now revert the always translate pref and make sure we go back to expected 1156 // Now revert the always translate pref and make sure we go back to expected
1157 // behavior, which is show a "before translate" infobar. 1157 // behavior, which is show a "before translate" infobar.
1158 SetPrefObserverExpectation(TranslatePrefs::kPrefTranslateWhitelists); 1158 SetPrefObserverExpectation(TranslatePrefs::kPrefTranslateWhitelists);
1159 translate_prefs.RemoveLanguagePairFromWhitelist("fr", "en"); 1159 translate_prefs.RemoveLanguagePairFromWhitelist("fr", "en");
1160 SimulateNavigation(GURL("http://www.google.fr"), "fr", true); 1160 SimulateNavigation(GURL("http://www.google.fr"), "fr", true);
1161 EXPECT_FALSE(GetTranslateMessage(&page_id, &original_lang, &target_lang)); 1161 EXPECT_FALSE(GetTranslateMessage(&page_id, &original_lang, &target_lang));
1162 infobar = GetTranslateInfoBar(); 1162 infobar = GetTranslateInfoBar();
1163 ASSERT_TRUE(infobar != NULL); 1163 ASSERT_TRUE(infobar != NULL);
1164 EXPECT_EQ(TranslateInfoBarDelegate::BEFORE_TRANSLATE, 1164 EXPECT_EQ(TranslateInfoBarDelegate::BEFORE_TRANSLATE,
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
1284 translate_prefs.ResetTranslationDeniedCount("de"); 1284 translate_prefs.ResetTranslationDeniedCount("de");
1285 1285
1286 // We'll do 4 times in incognito mode first to make sure the button is not 1286 // We'll do 4 times in incognito mode first to make sure the button is not
1287 // shown in that case, then 4 times in normal mode. 1287 // shown in that case, then 4 times in normal mode.
1288 TranslateInfoBarDelegate* infobar; 1288 TranslateInfoBarDelegate* infobar;
1289 TestingProfile* test_profile = 1289 TestingProfile* test_profile =
1290 static_cast<TestingProfile*>(web_contents()->GetBrowserContext()); 1290 static_cast<TestingProfile*>(web_contents()->GetBrowserContext());
1291 static_cast<extensions::TestExtensionSystem*>( 1291 static_cast<extensions::TestExtensionSystem*>(
1292 extensions::ExtensionSystem::Get(test_profile))-> 1292 extensions::ExtensionSystem::Get(test_profile))->
1293 CreateExtensionProcessManager(); 1293 CreateExtensionProcessManager();
1294 test_profile->set_incognito(true); 1294 test_profile->ForceIncognito(true);
1295 for (int i = 0; i < 8; ++i) { 1295 for (int i = 0; i < 8; ++i) {
1296 SCOPED_TRACE(::testing::Message() << "Iteration " << i << 1296 SCOPED_TRACE(::testing::Message() << "Iteration " << i <<
1297 " incognito mode=" << test_profile->IsOffTheRecord()); 1297 " incognito mode=" << test_profile->IsOffTheRecord());
1298 SimulateNavigation(GURL("http://www.google.fr"), "fr", true); 1298 SimulateNavigation(GURL("http://www.google.fr"), "fr", true);
1299 infobar = GetTranslateInfoBar(); 1299 infobar = GetTranslateInfoBar();
1300 ASSERT_TRUE(infobar != NULL); 1300 ASSERT_TRUE(infobar != NULL);
1301 EXPECT_EQ(TranslateInfoBarDelegate::BEFORE_TRANSLATE, 1301 EXPECT_EQ(TranslateInfoBarDelegate::BEFORE_TRANSLATE,
1302 infobar->infobar_type()); 1302 infobar->infobar_type());
1303 if (i < 7) { 1303 if (i < 7) {
1304 EXPECT_FALSE(infobar->ShouldShowAlwaysTranslateShortcut()); 1304 EXPECT_FALSE(infobar->ShouldShowAlwaysTranslateShortcut());
1305 infobar->Translate(); 1305 infobar->Translate();
1306 process()->sink().ClearMessages(); 1306 process()->sink().ClearMessages();
1307 } else { 1307 } else {
1308 EXPECT_TRUE(infobar->ShouldShowAlwaysTranslateShortcut()); 1308 EXPECT_TRUE(infobar->ShouldShowAlwaysTranslateShortcut());
1309 } 1309 }
1310 if (i == 3) 1310 if (i == 3)
1311 test_profile->set_incognito(false); 1311 test_profile->ForceIncognito(false);
1312 } 1312 }
1313 // Simulate the user pressing "Always translate French". 1313 // Simulate the user pressing "Always translate French".
1314 infobar->AlwaysTranslatePageLanguage(); 1314 infobar->AlwaysTranslatePageLanguage();
1315 EXPECT_TRUE(translate_prefs.IsLanguagePairWhitelisted("fr", "en")); 1315 EXPECT_TRUE(translate_prefs.IsLanguagePairWhitelisted("fr", "en"));
1316 // Simulate the translate script being retrieved (it only needs to be done 1316 // Simulate the translate script being retrieved (it only needs to be done
1317 // once in the test as it is cached). 1317 // once in the test as it is cached).
1318 SimulateTranslateScriptURLFetch(true); 1318 SimulateTranslateScriptURLFetch(true);
1319 // That should have triggered a page translate. 1319 // That should have triggered a page translate.
1320 int page_id = 0; 1320 int page_id = 0;
1321 std::string original_lang, target_lang; 1321 std::string original_lang, target_lang;
1322 EXPECT_TRUE(GetTranslateMessage(&page_id, &original_lang, &target_lang)); 1322 EXPECT_TRUE(GetTranslateMessage(&page_id, &original_lang, &target_lang));
1323 process()->sink().ClearMessages(); 1323 process()->sink().ClearMessages();
1324 1324
1325 // Now test that declining the translation causes a "never translate" button 1325 // Now test that declining the translation causes a "never translate" button
1326 // to be shown (in non incognito mode only). 1326 // to be shown (in non incognito mode only).
1327 test_profile->set_incognito(true); 1327 test_profile->ForceIncognito(true);
1328 for (int i = 0; i < 8; ++i) { 1328 for (int i = 0; i < 8; ++i) {
1329 SCOPED_TRACE(::testing::Message() << "Iteration " << i << 1329 SCOPED_TRACE(::testing::Message() << "Iteration " << i <<
1330 " incognito mode=" << test_profile->IsOffTheRecord()); 1330 " incognito mode=" << test_profile->IsOffTheRecord());
1331 SimulateNavigation(GURL("http://www.google.de"), "de", true); 1331 SimulateNavigation(GURL("http://www.google.de"), "de", true);
1332 infobar = GetTranslateInfoBar(); 1332 infobar = GetTranslateInfoBar();
1333 ASSERT_TRUE(infobar != NULL); 1333 ASSERT_TRUE(infobar != NULL);
1334 EXPECT_EQ(TranslateInfoBarDelegate::BEFORE_TRANSLATE, 1334 EXPECT_EQ(TranslateInfoBarDelegate::BEFORE_TRANSLATE,
1335 infobar->infobar_type()); 1335 infobar->infobar_type());
1336 if (i < 7) { 1336 if (i < 7) {
1337 EXPECT_FALSE(infobar->ShouldShowNeverTranslateShortcut()); 1337 EXPECT_FALSE(infobar->ShouldShowNeverTranslateShortcut());
1338 infobar->TranslationDeclined(); 1338 infobar->TranslationDeclined();
1339 } else { 1339 } else {
1340 EXPECT_TRUE(infobar->ShouldShowNeverTranslateShortcut()); 1340 EXPECT_TRUE(infobar->ShouldShowNeverTranslateShortcut());
1341 } 1341 }
1342 if (i == 3) 1342 if (i == 3)
1343 test_profile->set_incognito(false); 1343 test_profile->ForceIncognito(false);
1344 } 1344 }
1345 // Simulate the user pressing "Never translate French". 1345 // Simulate the user pressing "Never translate French".
1346 infobar->NeverTranslatePageLanguage(); 1346 infobar->NeverTranslatePageLanguage();
1347 EXPECT_TRUE(translate_prefs.IsBlockedLanguage("de")); 1347 EXPECT_TRUE(translate_prefs.IsBlockedLanguage("de"));
1348 // No translation should have occured and the infobar should be gone. 1348 // No translation should have occured and the infobar should be gone.
1349 EXPECT_FALSE(GetTranslateMessage(&page_id, &original_lang, &target_lang)); 1349 EXPECT_FALSE(GetTranslateMessage(&page_id, &original_lang, &target_lang));
1350 process()->sink().ClearMessages(); 1350 process()->sink().ClearMessages();
1351 ASSERT_TRUE(GetTranslateInfoBar() == NULL); 1351 ASSERT_TRUE(GetTranslateInfoBar() == NULL);
1352 } 1352 }
1353 1353
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
1454 content::WebContents* current_web_contents = 1454 content::WebContents* current_web_contents =
1455 browser()->tab_strip_model()->GetActiveWebContents(); 1455 browser()->tab_strip_model()->GetActiveWebContents();
1456 content::Source<content::WebContents> source(current_web_contents); 1456 content::Source<content::WebContents> source(current_web_contents);
1457 1457
1458 ui_test_utils::WindowedNotificationObserverWithDetails< 1458 ui_test_utils::WindowedNotificationObserverWithDetails<
1459 LanguageDetectionDetails> 1459 LanguageDetectionDetails>
1460 fr_language_detected_signal(chrome::NOTIFICATION_TAB_LANGUAGE_DETERMINED, 1460 fr_language_detected_signal(chrome::NOTIFICATION_TAB_LANGUAGE_DETERMINED,
1461 source); 1461 source);
1462 fr_language_detected_signal.Wait(); 1462 fr_language_detected_signal.Wait();
1463 } 1463 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698