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