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 | 5 |
6 #include <algorithm> | 6 #include <algorithm> |
7 #include <set> | 7 #include <set> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/stringprintf.h" | 12 #include "base/stringprintf.h" |
13 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
14 #include "base/values.h" | 14 #include "base/values.h" |
15 #include "chrome/app/chrome_command_ids.h" | 15 #include "chrome/app/chrome_command_ids.h" |
16 #include "chrome/browser/extensions/extension_system_factory.h" | |
17 #include "chrome/browser/extensions/test_extension_system.h" | |
18 #include "chrome/browser/infobars/infobar.h" | 16 #include "chrome/browser/infobars/infobar.h" |
19 #include "chrome/browser/infobars/infobar_tab_helper.h" | 17 #include "chrome/browser/infobars/infobar_tab_helper.h" |
20 #include "chrome/browser/prefs/pref_change_registrar.h" | 18 #include "chrome/browser/prefs/pref_change_registrar.h" |
21 #include "chrome/browser/prefs/pref_service.h" | 19 #include "chrome/browser/prefs/pref_service.h" |
22 #include "chrome/browser/tab_contents/render_view_context_menu.h" | 20 #include "chrome/browser/tab_contents/render_view_context_menu.h" |
23 #include "chrome/browser/translate/translate_infobar_delegate.h" | 21 #include "chrome/browser/translate/translate_infobar_delegate.h" |
24 #include "chrome/browser/translate/translate_manager.h" | 22 #include "chrome/browser/translate/translate_manager.h" |
25 #include "chrome/browser/translate/translate_prefs.h" | 23 #include "chrome/browser/translate/translate_prefs.h" |
26 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 24 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
27 #include "chrome/browser/ui/tab_contents/test_tab_contents_wrapper.h" | 25 #include "chrome/browser/ui/tab_contents/test_tab_contents_wrapper.h" |
(...skipping 1272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1300 menu.reset(TestRenderViewContextMenu::CreateContextMenu(contents())); | 1298 menu.reset(TestRenderViewContextMenu::CreateContextMenu(contents())); |
1301 menu->Init(); | 1299 menu->Init(); |
1302 EXPECT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_TRANSLATE)); | 1300 EXPECT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_TRANSLATE)); |
1303 EXPECT_FALSE(menu->IsCommandIdEnabled(IDC_CONTENT_CONTEXT_TRANSLATE)); | 1301 EXPECT_FALSE(menu->IsCommandIdEnabled(IDC_CONTENT_CONTEXT_TRANSLATE)); |
1304 } | 1302 } |
1305 | 1303 |
1306 // Tests that an extra always/never translate button is shown on the "before | 1304 // Tests that an extra always/never translate button is shown on the "before |
1307 // translate" infobar when the translation is accepted/declined 3 times, | 1305 // translate" infobar when the translation is accepted/declined 3 times, |
1308 // only when not in incognito mode. | 1306 // only when not in incognito mode. |
1309 TEST_F(TranslateManagerTest, BeforeTranslateExtraButtons) { | 1307 TEST_F(TranslateManagerTest, BeforeTranslateExtraButtons) { |
1310 Profile* profile = | 1308 Profile* profile = |
1311 Profile::FromBrowserContext(contents()->GetBrowserContext()); | 1309 Profile::FromBrowserContext(contents()->GetBrowserContext()); |
1312 TranslatePrefs translate_prefs(profile->GetPrefs()); | 1310 TranslatePrefs translate_prefs(profile->GetPrefs()); |
1313 translate_prefs.ResetTranslationAcceptedCount("fr"); | 1311 translate_prefs.ResetTranslationAcceptedCount("fr"); |
1314 translate_prefs.ResetTranslationDeniedCount("fr"); | 1312 translate_prefs.ResetTranslationDeniedCount("fr"); |
1315 translate_prefs.ResetTranslationAcceptedCount("de"); | 1313 translate_prefs.ResetTranslationAcceptedCount("de"); |
1316 translate_prefs.ResetTranslationDeniedCount("de"); | 1314 translate_prefs.ResetTranslationDeniedCount("de"); |
1317 | 1315 |
1318 // We'll do 4 times in incognito mode first to make sure the button is not | 1316 // We'll do 4 times in incognito mode first to make sure the button is not |
1319 // shown in that case, then 4 times in normal mode. | 1317 // shown in that case, then 4 times in normal mode. |
1320 TranslateInfoBarDelegate* infobar; | 1318 TranslateInfoBarDelegate* infobar; |
1321 TestingProfile* test_profile = | 1319 TestingProfile* test_profile = |
1322 static_cast<TestingProfile*>(contents()->GetBrowserContext()); | 1320 static_cast<TestingProfile*>(contents()->GetBrowserContext()); |
1323 static_cast<TestExtensionSystem*>( | 1321 test_profile->CreateExtensionProcessManager(); |
1324 ExtensionSystemFactory::GetForProfile(test_profile))-> | |
1325 CreateExtensionProcessManager(); | |
1326 test_profile->set_incognito(true); | 1322 test_profile->set_incognito(true); |
1327 for (int i = 0; i < 8; ++i) { | 1323 for (int i = 0; i < 8; ++i) { |
1328 SCOPED_TRACE(::testing::Message() << "Iteration " << i << | 1324 SCOPED_TRACE(::testing::Message() << "Iteration " << i << |
1329 " incognito mode=" << test_profile->IsOffTheRecord()); | 1325 " incognito mode=" << test_profile->IsOffTheRecord()); |
1330 SimulateNavigation(GURL("http://www.google.fr"), "fr", true); | 1326 SimulateNavigation(GURL("http://www.google.fr"), "fr", true); |
1331 infobar = GetTranslateInfoBar(); | 1327 infobar = GetTranslateInfoBar(); |
1332 ASSERT_TRUE(infobar != NULL); | 1328 ASSERT_TRUE(infobar != NULL); |
1333 EXPECT_EQ(TranslateInfoBarDelegate::BEFORE_TRANSLATE, infobar->type()); | 1329 EXPECT_EQ(TranslateInfoBarDelegate::BEFORE_TRANSLATE, infobar->type()); |
1334 if (i < 7) { | 1330 if (i < 7) { |
1335 EXPECT_FALSE(infobar->ShouldShowAlwaysTranslateButton()); | 1331 EXPECT_FALSE(infobar->ShouldShowAlwaysTranslateButton()); |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1429 NULL); | 1425 NULL); |
1430 // Now simulate the URL fetch. | 1426 // Now simulate the URL fetch. |
1431 SimulateTranslateScriptURLFetch(true); | 1427 SimulateTranslateScriptURLFetch(true); |
1432 // Now the message should have been sent. | 1428 // Now the message should have been sent. |
1433 int page_id = 0; | 1429 int page_id = 0; |
1434 std::string original_lang, target_lang; | 1430 std::string original_lang, target_lang; |
1435 EXPECT_TRUE(GetTranslateMessage(&page_id, &original_lang, &target_lang)); | 1431 EXPECT_TRUE(GetTranslateMessage(&page_id, &original_lang, &target_lang)); |
1436 EXPECT_EQ("es", original_lang); | 1432 EXPECT_EQ("es", original_lang); |
1437 EXPECT_EQ("en", target_lang); | 1433 EXPECT_EQ("en", target_lang); |
1438 } | 1434 } |
OLD | NEW |