OLD | NEW |
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/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "base/prefs/pref_change_registrar.h" | 11 #include "base/prefs/pref_change_registrar.h" |
12 #include "base/prefs/pref_service.h" | 12 #include "base/prefs/pref_service.h" |
13 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
14 #include "chrome/app/chrome_command_ids.h" | 14 #include "chrome/app/chrome_command_ids.h" |
15 #include "chrome/browser/chrome_notification_types.h" | 15 #include "chrome/browser/chrome_notification_types.h" |
16 #include "chrome/browser/extensions/test_extension_system.h" | 16 #include "chrome/browser/extensions/test_extension_system.h" |
17 #include "chrome/browser/infobars/infobar.h" | 17 #include "chrome/browser/infobars/infobar.h" |
18 #include "chrome/browser/infobars/infobar_service.h" | 18 #include "chrome/browser/infobars/infobar_service.h" |
19 #include "chrome/browser/prefs/session_startup_pref.h" | 19 #include "chrome/browser/prefs/session_startup_pref.h" |
20 #include "chrome/browser/tab_contents/render_view_context_menu.h" | 20 #include "chrome/browser/tab_contents/render_view_context_menu.h" |
21 #include "chrome/browser/translate/translate_infobar_delegate.h" | 21 #include "chrome/browser/translate/translate_infobar_delegate.h" |
22 #include "chrome/browser/translate/translate_manager.h" | 22 #include "chrome/browser/translate/translate_manager.h" |
23 #include "chrome/browser/translate/translate_prefs.h" | |
24 #include "chrome/browser/translate/translate_service.h" | 23 #include "chrome/browser/translate/translate_service.h" |
25 #include "chrome/browser/translate/translate_tab_helper.h" | 24 #include "chrome/browser/translate/translate_tab_helper.h" |
26 #include "chrome/browser/ui/browser.h" | 25 #include "chrome/browser/ui/browser.h" |
27 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 26 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
28 #include "chrome/browser/ui/translate/translate_bubble_factory.h" | 27 #include "chrome/browser/ui/translate/translate_bubble_factory.h" |
29 #include "chrome/browser/ui/translate/translate_bubble_model.h" | 28 #include "chrome/browser/ui/translate/translate_bubble_model.h" |
30 #include "chrome/browser/ui/translate/translate_bubble_model_impl.h" | 29 #include "chrome/browser/ui/translate/translate_bubble_model_impl.h" |
31 #include "chrome/common/chrome_switches.h" | 30 #include "chrome/common/chrome_switches.h" |
32 #include "chrome/common/pref_names.h" | 31 #include "chrome/common/pref_names.h" |
33 #include "chrome/common/render_messages.h" | 32 #include "chrome/common/render_messages.h" |
34 #include "chrome/common/url_constants.h" | 33 #include "chrome/common/url_constants.h" |
35 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 34 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
36 #include "chrome/test/base/in_process_browser_test.h" | 35 #include "chrome/test/base/in_process_browser_test.h" |
37 #include "chrome/test/base/testing_browser_process.h" | 36 #include "chrome/test/base/testing_browser_process.h" |
38 #include "chrome/test/base/testing_profile.h" | 37 #include "chrome/test/base/testing_profile.h" |
39 #include "chrome/test/base/ui_test_utils.h" | 38 #include "chrome/test/base/ui_test_utils.h" |
| 39 #include "components/translate/core/browser/translate_accept_languages.h" |
40 #include "components/translate/core/browser/translate_download_manager.h" | 40 #include "components/translate/core/browser/translate_download_manager.h" |
41 #include "components/translate/core/browser/translate_language_list.h" | 41 #include "components/translate/core/browser/translate_language_list.h" |
| 42 #include "components/translate/core/browser/translate_prefs.h" |
42 #include "components/translate/core/browser/translate_script.h" | 43 #include "components/translate/core/browser/translate_script.h" |
43 #include "components/translate/core/common/language_detection_details.h" | 44 #include "components/translate/core/common/language_detection_details.h" |
44 #include "components/translate/core/common/translate_pref_names.h" | 45 #include "components/translate/core/common/translate_pref_names.h" |
45 #include "content/public/browser/navigation_details.h" | 46 #include "content/public/browser/navigation_details.h" |
46 #include "content/public/browser/navigation_entry.h" | 47 #include "content/public/browser/navigation_entry.h" |
47 #include "content/public/browser/notification_details.h" | 48 #include "content/public/browser/notification_details.h" |
48 #include "content/public/browser/notification_registrar.h" | 49 #include "content/public/browser/notification_registrar.h" |
49 #include "content/public/browser/web_contents.h" | 50 #include "content/public/browser/web_contents.h" |
50 #include "content/public/test/mock_render_process_host.h" | 51 #include "content/public/test/mock_render_process_host.h" |
51 #include "content/public/test/test_renderer_host.h" | 52 #include "content/public/test/test_renderer_host.h" |
(...skipping 1037 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1089 EXPECT_TRUE(GetTranslateInfoBar() != NULL); | 1090 EXPECT_TRUE(GetTranslateInfoBar() != NULL); |
1090 | 1091 |
1091 // Select never translate this language. | 1092 // Select never translate this language. |
1092 Profile* profile = | 1093 Profile* profile = |
1093 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); | 1094 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); |
1094 PrefService* prefs = profile->GetPrefs(); | 1095 PrefService* prefs = profile->GetPrefs(); |
1095 PrefChangeRegistrar registrar; | 1096 PrefChangeRegistrar registrar; |
1096 registrar.Init(prefs); | 1097 registrar.Init(prefs); |
1097 registrar.Add(TranslatePrefs::kPrefTranslateBlockedLanguages, | 1098 registrar.Add(TranslatePrefs::kPrefTranslateBlockedLanguages, |
1098 pref_callback_); | 1099 pref_callback_); |
1099 TranslatePrefs translate_prefs(prefs); | 1100 scoped_ptr<TranslatePrefs> translate_prefs( |
1100 EXPECT_FALSE(translate_prefs.IsBlockedLanguage("fr")); | 1101 TranslateTabHelper::CreateTranslatePrefs(prefs)); |
1101 EXPECT_TRUE(translate_prefs.CanTranslateLanguage(profile, "fr")); | 1102 EXPECT_FALSE(translate_prefs->IsBlockedLanguage("fr")); |
| 1103 TranslateAcceptLanguages* accept_languages = |
| 1104 TranslateTabHelper::GetTranslateAcceptLanguages(profile); |
| 1105 EXPECT_TRUE(translate_prefs->CanTranslateLanguage(accept_languages, "fr")); |
1102 SetPrefObserverExpectation(TranslatePrefs::kPrefTranslateBlockedLanguages); | 1106 SetPrefObserverExpectation(TranslatePrefs::kPrefTranslateBlockedLanguages); |
1103 translate_prefs.BlockLanguage("fr"); | 1107 translate_prefs->BlockLanguage("fr"); |
1104 EXPECT_TRUE(translate_prefs.IsBlockedLanguage("fr")); | 1108 EXPECT_TRUE(translate_prefs->IsBlockedLanguage("fr")); |
1105 EXPECT_FALSE(translate_prefs.IsSiteBlacklisted(url.host())); | 1109 EXPECT_FALSE(translate_prefs->IsSiteBlacklisted(url.host())); |
1106 EXPECT_FALSE(translate_prefs.CanTranslateLanguage(profile, "fr")); | 1110 EXPECT_FALSE(translate_prefs->CanTranslateLanguage(accept_languages, "fr")); |
1107 | 1111 |
1108 EXPECT_TRUE(CloseTranslateInfoBar()); | 1112 EXPECT_TRUE(CloseTranslateInfoBar()); |
1109 | 1113 |
1110 // Navigate to a new page also in French. | 1114 // Navigate to a new page also in French. |
1111 SimulateNavigation(GURL("http://wwww.youtube.fr"), "fr", true); | 1115 SimulateNavigation(GURL("http://wwww.youtube.fr"), "fr", true); |
1112 | 1116 |
1113 // There should not be a translate infobar. | 1117 // There should not be a translate infobar. |
1114 EXPECT_TRUE(GetTranslateInfoBar() == NULL); | 1118 EXPECT_TRUE(GetTranslateInfoBar() == NULL); |
1115 | 1119 |
1116 // Remove the language from the blacklist. | 1120 // Remove the language from the blacklist. |
1117 SetPrefObserverExpectation(TranslatePrefs::kPrefTranslateBlockedLanguages); | 1121 SetPrefObserverExpectation(TranslatePrefs::kPrefTranslateBlockedLanguages); |
1118 translate_prefs.UnblockLanguage("fr"); | 1122 translate_prefs->UnblockLanguage("fr"); |
1119 EXPECT_FALSE(translate_prefs.IsBlockedLanguage("fr")); | 1123 EXPECT_FALSE(translate_prefs->IsBlockedLanguage("fr")); |
1120 EXPECT_FALSE(translate_prefs.IsSiteBlacklisted(url.host())); | 1124 EXPECT_FALSE(translate_prefs->IsSiteBlacklisted(url.host())); |
1121 EXPECT_TRUE(translate_prefs.CanTranslateLanguage(profile, "fr")); | 1125 EXPECT_TRUE(translate_prefs->CanTranslateLanguage(accept_languages, "fr")); |
1122 | 1126 |
1123 // Navigate to a page in French. | 1127 // Navigate to a page in French. |
1124 SimulateNavigation(url, "fr", true); | 1128 SimulateNavigation(url, "fr", true); |
1125 | 1129 |
1126 // There should be a translate infobar. | 1130 // There should be a translate infobar. |
1127 EXPECT_TRUE(GetTranslateInfoBar() != NULL); | 1131 EXPECT_TRUE(GetTranslateInfoBar() != NULL); |
1128 } | 1132 } |
1129 | 1133 |
1130 // Tests the "Never translate this site" pref. | 1134 // Tests the "Never translate this site" pref. |
1131 TEST_F(TranslateManagerBrowserTest, NeverTranslateSitePref) { | 1135 TEST_F(TranslateManagerBrowserTest, NeverTranslateSitePref) { |
1132 GURL url("http://www.google.fr"); | 1136 GURL url("http://www.google.fr"); |
1133 std::string host(url.host()); | 1137 std::string host(url.host()); |
1134 SimulateNavigation(url, "fr", true); | 1138 SimulateNavigation(url, "fr", true); |
1135 | 1139 |
1136 // An infobar should be shown. | 1140 // An infobar should be shown. |
1137 EXPECT_TRUE(GetTranslateInfoBar() != NULL); | 1141 EXPECT_TRUE(GetTranslateInfoBar() != NULL); |
1138 | 1142 |
1139 // Select never translate this site. | 1143 // Select never translate this site. |
1140 Profile* profile = | 1144 Profile* profile = |
1141 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); | 1145 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); |
1142 PrefService* prefs = profile->GetPrefs(); | 1146 PrefService* prefs = profile->GetPrefs(); |
1143 PrefChangeRegistrar registrar; | 1147 PrefChangeRegistrar registrar; |
1144 registrar.Init(prefs); | 1148 registrar.Init(prefs); |
1145 registrar.Add(TranslatePrefs::kPrefTranslateSiteBlacklist, pref_callback_); | 1149 registrar.Add(TranslatePrefs::kPrefTranslateSiteBlacklist, pref_callback_); |
1146 TranslatePrefs translate_prefs(prefs); | 1150 scoped_ptr<TranslatePrefs> translate_prefs( |
1147 EXPECT_FALSE(translate_prefs.IsSiteBlacklisted(host)); | 1151 TranslateTabHelper::CreateTranslatePrefs(prefs)); |
1148 EXPECT_TRUE(translate_prefs.CanTranslateLanguage(profile, "fr")); | 1152 EXPECT_FALSE(translate_prefs->IsSiteBlacklisted(host)); |
| 1153 TranslateAcceptLanguages* accept_languages = |
| 1154 TranslateTabHelper::GetTranslateAcceptLanguages(profile); |
| 1155 EXPECT_TRUE(translate_prefs->CanTranslateLanguage(accept_languages, "fr")); |
1149 SetPrefObserverExpectation(TranslatePrefs::kPrefTranslateSiteBlacklist); | 1156 SetPrefObserverExpectation(TranslatePrefs::kPrefTranslateSiteBlacklist); |
1150 translate_prefs.BlacklistSite(host); | 1157 translate_prefs->BlacklistSite(host); |
1151 EXPECT_TRUE(translate_prefs.IsSiteBlacklisted(host)); | 1158 EXPECT_TRUE(translate_prefs->IsSiteBlacklisted(host)); |
1152 EXPECT_TRUE(translate_prefs.CanTranslateLanguage(profile, "fr")); | 1159 EXPECT_TRUE(translate_prefs->CanTranslateLanguage(accept_languages, "fr")); |
1153 | 1160 |
1154 EXPECT_TRUE(CloseTranslateInfoBar()); | 1161 EXPECT_TRUE(CloseTranslateInfoBar()); |
1155 | 1162 |
1156 // Navigate to a new page also on the same site. | 1163 // Navigate to a new page also on the same site. |
1157 SimulateNavigation(GURL("http://www.google.fr/hello"), "fr", true); | 1164 SimulateNavigation(GURL("http://www.google.fr/hello"), "fr", true); |
1158 | 1165 |
1159 // There should not be a translate infobar. | 1166 // There should not be a translate infobar. |
1160 EXPECT_TRUE(GetTranslateInfoBar() == NULL); | 1167 EXPECT_TRUE(GetTranslateInfoBar() == NULL); |
1161 | 1168 |
1162 // Remove the site from the blacklist. | 1169 // Remove the site from the blacklist. |
1163 SetPrefObserverExpectation(TranslatePrefs::kPrefTranslateSiteBlacklist); | 1170 SetPrefObserverExpectation(TranslatePrefs::kPrefTranslateSiteBlacklist); |
1164 translate_prefs.RemoveSiteFromBlacklist(host); | 1171 translate_prefs->RemoveSiteFromBlacklist(host); |
1165 EXPECT_FALSE(translate_prefs.IsSiteBlacklisted(host)); | 1172 EXPECT_FALSE(translate_prefs->IsSiteBlacklisted(host)); |
1166 EXPECT_TRUE(translate_prefs.CanTranslateLanguage(profile, "fr")); | 1173 EXPECT_TRUE(translate_prefs->CanTranslateLanguage(accept_languages, "fr")); |
1167 | 1174 |
1168 // Navigate to a page in French. | 1175 // Navigate to a page in French. |
1169 SimulateNavigation(url, "fr", true); | 1176 SimulateNavigation(url, "fr", true); |
1170 | 1177 |
1171 // There should be a translate infobar. | 1178 // There should be a translate infobar. |
1172 EXPECT_TRUE(GetTranslateInfoBar() != NULL); | 1179 EXPECT_TRUE(GetTranslateInfoBar() != NULL); |
1173 } | 1180 } |
1174 | 1181 |
1175 // Tests the "Always translate this language" pref. | 1182 // Tests the "Always translate this language" pref. |
1176 TEST_F(TranslateManagerBrowserTest, AlwaysTranslateLanguagePref) { | 1183 TEST_F(TranslateManagerBrowserTest, AlwaysTranslateLanguagePref) { |
1177 // Select always translate French to English. | 1184 // Select always translate French to English. |
1178 Profile* profile = | 1185 Profile* profile = |
1179 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); | 1186 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); |
1180 PrefService* prefs = profile->GetPrefs(); | 1187 PrefService* prefs = profile->GetPrefs(); |
1181 PrefChangeRegistrar registrar; | 1188 PrefChangeRegistrar registrar; |
1182 registrar.Init(prefs); | 1189 registrar.Init(prefs); |
1183 registrar.Add(TranslatePrefs::kPrefTranslateWhitelists, pref_callback_); | 1190 registrar.Add(TranslatePrefs::kPrefTranslateWhitelists, pref_callback_); |
1184 TranslatePrefs translate_prefs(prefs); | 1191 scoped_ptr<TranslatePrefs> translate_prefs( |
| 1192 TranslateTabHelper::CreateTranslatePrefs(prefs)); |
1185 SetPrefObserverExpectation(TranslatePrefs::kPrefTranslateWhitelists); | 1193 SetPrefObserverExpectation(TranslatePrefs::kPrefTranslateWhitelists); |
1186 translate_prefs.WhitelistLanguagePair("fr", "en"); | 1194 translate_prefs->WhitelistLanguagePair("fr", "en"); |
1187 | 1195 |
1188 // Load a page in French. | 1196 // Load a page in French. |
1189 SimulateNavigation(GURL("http://www.google.fr"), "fr", true); | 1197 SimulateNavigation(GURL("http://www.google.fr"), "fr", true); |
1190 | 1198 |
1191 // It should have triggered an automatic translation to English. | 1199 // It should have triggered an automatic translation to English. |
1192 | 1200 |
1193 // The translating infobar should be showing. | 1201 // The translating infobar should be showing. |
1194 TranslateInfoBarDelegate* infobar = GetTranslateInfoBar(); | 1202 TranslateInfoBarDelegate* infobar = GetTranslateInfoBar(); |
1195 ASSERT_TRUE(infobar != NULL); | 1203 ASSERT_TRUE(infobar != NULL); |
1196 EXPECT_EQ(TranslateInfoBarDelegate::TRANSLATING, infobar->infobar_type()); | 1204 EXPECT_EQ(TranslateInfoBarDelegate::TRANSLATING, infobar->infobar_type()); |
(...skipping 18 matching lines...) Expand all Loading... |
1215 test_profile->ForceIncognito(true); | 1223 test_profile->ForceIncognito(true); |
1216 SimulateNavigation(GURL("http://www.youtube.fr"), "fr", true); | 1224 SimulateNavigation(GURL("http://www.youtube.fr"), "fr", true); |
1217 EXPECT_FALSE(GetTranslateMessage(&page_id, &original_lang, &target_lang)); | 1225 EXPECT_FALSE(GetTranslateMessage(&page_id, &original_lang, &target_lang)); |
1218 EXPECT_TRUE(GetTranslateInfoBar() != NULL); | 1226 EXPECT_TRUE(GetTranslateInfoBar() != NULL); |
1219 EXPECT_TRUE(CloseTranslateInfoBar()); | 1227 EXPECT_TRUE(CloseTranslateInfoBar()); |
1220 test_profile->ForceIncognito(false); // Get back to non incognito. | 1228 test_profile->ForceIncognito(false); // Get back to non incognito. |
1221 | 1229 |
1222 // Now revert the always translate pref and make sure we go back to expected | 1230 // Now revert the always translate pref and make sure we go back to expected |
1223 // behavior, which is show a "before translate" infobar. | 1231 // behavior, which is show a "before translate" infobar. |
1224 SetPrefObserverExpectation(TranslatePrefs::kPrefTranslateWhitelists); | 1232 SetPrefObserverExpectation(TranslatePrefs::kPrefTranslateWhitelists); |
1225 translate_prefs.RemoveLanguagePairFromWhitelist("fr", "en"); | 1233 translate_prefs->RemoveLanguagePairFromWhitelist("fr", "en"); |
1226 SimulateNavigation(GURL("http://www.google.fr"), "fr", true); | 1234 SimulateNavigation(GURL("http://www.google.fr"), "fr", true); |
1227 EXPECT_FALSE(GetTranslateMessage(&page_id, &original_lang, &target_lang)); | 1235 EXPECT_FALSE(GetTranslateMessage(&page_id, &original_lang, &target_lang)); |
1228 infobar = GetTranslateInfoBar(); | 1236 infobar = GetTranslateInfoBar(); |
1229 ASSERT_TRUE(infobar != NULL); | 1237 ASSERT_TRUE(infobar != NULL); |
1230 EXPECT_EQ(TranslateInfoBarDelegate::BEFORE_TRANSLATE, | 1238 EXPECT_EQ(TranslateInfoBarDelegate::BEFORE_TRANSLATE, |
1231 infobar->infobar_type()); | 1239 infobar->infobar_type()); |
1232 } | 1240 } |
1233 | 1241 |
1234 // Context menu. | 1242 // Context menu. |
1235 TEST_F(TranslateManagerBrowserTest, ContextMenu) { | 1243 TEST_F(TranslateManagerBrowserTest, ContextMenu) { |
1236 // Blacklist www.google.fr and French for translation. | 1244 // Blacklist www.google.fr and French for translation. |
1237 GURL url("http://www.google.fr"); | 1245 GURL url("http://www.google.fr"); |
1238 Profile* profile = | 1246 Profile* profile = |
1239 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); | 1247 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); |
1240 TranslatePrefs translate_prefs(profile->GetPrefs()); | 1248 scoped_ptr<TranslatePrefs> translate_prefs( |
1241 translate_prefs.BlockLanguage("fr"); | 1249 TranslateTabHelper::CreateTranslatePrefs(profile->GetPrefs())); |
1242 translate_prefs.BlacklistSite(url.host()); | 1250 translate_prefs->BlockLanguage("fr"); |
1243 EXPECT_TRUE(translate_prefs.IsBlockedLanguage("fr")); | 1251 translate_prefs->BlacklistSite(url.host()); |
1244 EXPECT_TRUE(translate_prefs.IsSiteBlacklisted(url.host())); | 1252 EXPECT_TRUE(translate_prefs->IsBlockedLanguage("fr")); |
| 1253 EXPECT_TRUE(translate_prefs->IsSiteBlacklisted(url.host())); |
1245 | 1254 |
1246 // Simulate navigating to a page in French. The translate menu should show but | 1255 // Simulate navigating to a page in French. The translate menu should show but |
1247 // should only be enabled when the page language has been received. | 1256 // should only be enabled when the page language has been received. |
1248 NavigateAndCommit(url); | 1257 NavigateAndCommit(url); |
1249 scoped_ptr<TestRenderViewContextMenu> menu( | 1258 scoped_ptr<TestRenderViewContextMenu> menu( |
1250 TestRenderViewContextMenu::CreateContextMenu(web_contents())); | 1259 TestRenderViewContextMenu::CreateContextMenu(web_contents())); |
1251 menu->Init(); | 1260 menu->Init(); |
1252 EXPECT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_TRANSLATE)); | 1261 EXPECT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_TRANSLATE)); |
1253 EXPECT_FALSE(menu->IsCommandIdEnabled(IDC_CONTENT_CONTEXT_TRANSLATE)); | 1262 EXPECT_FALSE(menu->IsCommandIdEnabled(IDC_CONTENT_CONTEXT_TRANSLATE)); |
1254 | 1263 |
(...skipping 14 matching lines...) Expand all Loading... |
1269 EXPECT_EQ(TranslateInfoBarDelegate::TRANSLATING, infobar->infobar_type()); | 1278 EXPECT_EQ(TranslateInfoBarDelegate::TRANSLATING, infobar->infobar_type()); |
1270 SimulateTranslateScriptURLFetch(true); | 1279 SimulateTranslateScriptURLFetch(true); |
1271 int page_id = 0; | 1280 int page_id = 0; |
1272 std::string original_lang, target_lang; | 1281 std::string original_lang, target_lang; |
1273 EXPECT_TRUE(GetTranslateMessage(&page_id, &original_lang, &target_lang)); | 1282 EXPECT_TRUE(GetTranslateMessage(&page_id, &original_lang, &target_lang)); |
1274 EXPECT_EQ("fr", original_lang); | 1283 EXPECT_EQ("fr", original_lang); |
1275 EXPECT_EQ("en", target_lang); | 1284 EXPECT_EQ("en", target_lang); |
1276 process()->sink().ClearMessages(); | 1285 process()->sink().ClearMessages(); |
1277 | 1286 |
1278 // This should also have reverted the blacklisting of this site and language. | 1287 // This should also have reverted the blacklisting of this site and language. |
1279 EXPECT_FALSE(translate_prefs.IsBlockedLanguage("fr")); | 1288 EXPECT_FALSE(translate_prefs->IsBlockedLanguage("fr")); |
1280 EXPECT_FALSE(translate_prefs.IsSiteBlacklisted(url.host())); | 1289 EXPECT_FALSE(translate_prefs->IsSiteBlacklisted(url.host())); |
1281 | 1290 |
1282 // Let's simulate the page being translated. | 1291 // Let's simulate the page being translated. |
1283 SimulateOnPageTranslated("fr", "en"); | 1292 SimulateOnPageTranslated("fr", "en"); |
1284 | 1293 |
1285 // The translate menu should now be disabled. | 1294 // The translate menu should now be disabled. |
1286 menu.reset(TestRenderViewContextMenu::CreateContextMenu(web_contents())); | 1295 menu.reset(TestRenderViewContextMenu::CreateContextMenu(web_contents())); |
1287 menu->Init(); | 1296 menu->Init(); |
1288 EXPECT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_TRANSLATE)); | 1297 EXPECT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_TRANSLATE)); |
1289 EXPECT_FALSE(menu->IsCommandIdEnabled(IDC_CONTENT_CONTEXT_TRANSLATE)); | 1298 EXPECT_FALSE(menu->IsCommandIdEnabled(IDC_CONTENT_CONTEXT_TRANSLATE)); |
1290 | 1299 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1336 EXPECT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_TRANSLATE)); | 1345 EXPECT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_TRANSLATE)); |
1337 EXPECT_TRUE(menu->IsCommandIdEnabled(IDC_CONTENT_CONTEXT_TRANSLATE)); | 1346 EXPECT_TRUE(menu->IsCommandIdEnabled(IDC_CONTENT_CONTEXT_TRANSLATE)); |
1338 } | 1347 } |
1339 | 1348 |
1340 // Tests that an extra always/never translate button is shown on the "before | 1349 // Tests that an extra always/never translate button is shown on the "before |
1341 // translate" infobar when the translation is accepted/declined 3 times, | 1350 // translate" infobar when the translation is accepted/declined 3 times, |
1342 // only when not in incognito mode. | 1351 // only when not in incognito mode. |
1343 TEST_F(TranslateManagerBrowserTest, BeforeTranslateExtraButtons) { | 1352 TEST_F(TranslateManagerBrowserTest, BeforeTranslateExtraButtons) { |
1344 Profile* profile = | 1353 Profile* profile = |
1345 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); | 1354 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); |
1346 TranslatePrefs translate_prefs(profile->GetPrefs()); | 1355 scoped_ptr<TranslatePrefs> translate_prefs( |
1347 translate_prefs.ResetTranslationAcceptedCount("fr"); | 1356 TranslateTabHelper::CreateTranslatePrefs(profile->GetPrefs())); |
1348 translate_prefs.ResetTranslationDeniedCount("fr"); | 1357 translate_prefs->ResetTranslationAcceptedCount("fr"); |
1349 translate_prefs.ResetTranslationAcceptedCount("de"); | 1358 translate_prefs->ResetTranslationDeniedCount("fr"); |
1350 translate_prefs.ResetTranslationDeniedCount("de"); | 1359 translate_prefs->ResetTranslationAcceptedCount("de"); |
| 1360 translate_prefs->ResetTranslationDeniedCount("de"); |
1351 | 1361 |
1352 // We'll do 4 times in incognito mode first to make sure the button is not | 1362 // We'll do 4 times in incognito mode first to make sure the button is not |
1353 // shown in that case, then 4 times in normal mode. | 1363 // shown in that case, then 4 times in normal mode. |
1354 TranslateInfoBarDelegate* infobar; | 1364 TranslateInfoBarDelegate* infobar; |
1355 TestingProfile* test_profile = | 1365 TestingProfile* test_profile = |
1356 static_cast<TestingProfile*>(web_contents()->GetBrowserContext()); | 1366 static_cast<TestingProfile*>(web_contents()->GetBrowserContext()); |
1357 static_cast<extensions::TestExtensionSystem*>( | 1367 static_cast<extensions::TestExtensionSystem*>( |
1358 extensions::ExtensionSystem::Get(test_profile))-> | 1368 extensions::ExtensionSystem::Get(test_profile))-> |
1359 CreateProcessManager(); | 1369 CreateProcessManager(); |
1360 test_profile->ForceIncognito(true); | 1370 test_profile->ForceIncognito(true); |
(...skipping 10 matching lines...) Expand all Loading... |
1371 infobar->Translate(); | 1381 infobar->Translate(); |
1372 process()->sink().ClearMessages(); | 1382 process()->sink().ClearMessages(); |
1373 } else { | 1383 } else { |
1374 EXPECT_TRUE(infobar->ShouldShowAlwaysTranslateShortcut()); | 1384 EXPECT_TRUE(infobar->ShouldShowAlwaysTranslateShortcut()); |
1375 } | 1385 } |
1376 if (i == 3) | 1386 if (i == 3) |
1377 test_profile->ForceIncognito(false); | 1387 test_profile->ForceIncognito(false); |
1378 } | 1388 } |
1379 // Simulate the user pressing "Always translate French". | 1389 // Simulate the user pressing "Always translate French". |
1380 infobar->AlwaysTranslatePageLanguage(); | 1390 infobar->AlwaysTranslatePageLanguage(); |
1381 EXPECT_TRUE(translate_prefs.IsLanguagePairWhitelisted("fr", "en")); | 1391 EXPECT_TRUE(translate_prefs->IsLanguagePairWhitelisted("fr", "en")); |
1382 // Simulate the translate script being retrieved (it only needs to be done | 1392 // Simulate the translate script being retrieved (it only needs to be done |
1383 // once in the test as it is cached). | 1393 // once in the test as it is cached). |
1384 SimulateTranslateScriptURLFetch(true); | 1394 SimulateTranslateScriptURLFetch(true); |
1385 // That should have triggered a page translate. | 1395 // That should have triggered a page translate. |
1386 int page_id = 0; | 1396 int page_id = 0; |
1387 std::string original_lang, target_lang; | 1397 std::string original_lang, target_lang; |
1388 EXPECT_TRUE(GetTranslateMessage(&page_id, &original_lang, &target_lang)); | 1398 EXPECT_TRUE(GetTranslateMessage(&page_id, &original_lang, &target_lang)); |
1389 process()->sink().ClearMessages(); | 1399 process()->sink().ClearMessages(); |
1390 | 1400 |
1391 // Now test that declining the translation causes a "never translate" button | 1401 // Now test that declining the translation causes a "never translate" button |
(...skipping 11 matching lines...) Expand all Loading... |
1403 EXPECT_FALSE(infobar->ShouldShowNeverTranslateShortcut()); | 1413 EXPECT_FALSE(infobar->ShouldShowNeverTranslateShortcut()); |
1404 infobar->TranslationDeclined(); | 1414 infobar->TranslationDeclined(); |
1405 } else { | 1415 } else { |
1406 EXPECT_TRUE(infobar->ShouldShowNeverTranslateShortcut()); | 1416 EXPECT_TRUE(infobar->ShouldShowNeverTranslateShortcut()); |
1407 } | 1417 } |
1408 if (i == 3) | 1418 if (i == 3) |
1409 test_profile->ForceIncognito(false); | 1419 test_profile->ForceIncognito(false); |
1410 } | 1420 } |
1411 // Simulate the user pressing "Never translate French". | 1421 // Simulate the user pressing "Never translate French". |
1412 infobar->NeverTranslatePageLanguage(); | 1422 infobar->NeverTranslatePageLanguage(); |
1413 EXPECT_TRUE(translate_prefs.IsBlockedLanguage("de")); | 1423 EXPECT_TRUE(translate_prefs->IsBlockedLanguage("de")); |
1414 // No translation should have occured and the infobar should be gone. | 1424 // No translation should have occured and the infobar should be gone. |
1415 EXPECT_FALSE(GetTranslateMessage(&page_id, &original_lang, &target_lang)); | 1425 EXPECT_FALSE(GetTranslateMessage(&page_id, &original_lang, &target_lang)); |
1416 process()->sink().ClearMessages(); | 1426 process()->sink().ClearMessages(); |
1417 ASSERT_TRUE(GetTranslateInfoBar() == NULL); | 1427 ASSERT_TRUE(GetTranslateInfoBar() == NULL); |
1418 } | 1428 } |
1419 | 1429 |
1420 // Tests that we don't show a translate infobar when a page instructs that it | 1430 // Tests that we don't show a translate infobar when a page instructs that it |
1421 // should not be translated. | 1431 // should not be translated. |
1422 TEST_F(TranslateManagerBrowserTest, NonTranslatablePage) { | 1432 TEST_F(TranslateManagerBrowserTest, NonTranslatablePage) { |
1423 SimulateNavigation(GURL("http://mail.google.fr"), "fr", false); | 1433 SimulateNavigation(GURL("http://mail.google.fr"), "fr", false); |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1626 content::WebContents* current_web_contents = | 1636 content::WebContents* current_web_contents = |
1627 browser()->tab_strip_model()->GetActiveWebContents(); | 1637 browser()->tab_strip_model()->GetActiveWebContents(); |
1628 content::Source<content::WebContents> source(current_web_contents); | 1638 content::Source<content::WebContents> source(current_web_contents); |
1629 | 1639 |
1630 ui_test_utils::WindowedNotificationObserverWithDetails< | 1640 ui_test_utils::WindowedNotificationObserverWithDetails< |
1631 LanguageDetectionDetails> | 1641 LanguageDetectionDetails> |
1632 fr_language_detected_signal(chrome::NOTIFICATION_TAB_LANGUAGE_DETERMINED, | 1642 fr_language_detected_signal(chrome::NOTIFICATION_TAB_LANGUAGE_DETERMINED, |
1633 source); | 1643 source); |
1634 fr_language_detected_signal.Wait(); | 1644 fr_language_detected_signal.Wait(); |
1635 } | 1645 } |
OLD | NEW |