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