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

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

Issue 13770003: Translate: URL check should be done at once (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase for dcommit Created 7 years, 8 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 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"
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 return details_; 84 return details_;
85 } 85 }
86 86
87 private: 87 private:
88 content::LoadCommittedDetails details_; 88 content::LoadCommittedDetails details_;
89 content::NotificationRegistrar registrar_; 89 content::NotificationRegistrar registrar_;
90 90
91 DISALLOW_COPY_AND_ASSIGN(NavEntryCommittedObserver); 91 DISALLOW_COPY_AND_ASSIGN(NavEntryCommittedObserver);
92 }; 92 };
93 93
94 class TranslateManagerTest : public ChromeRenderViewHostTestHarness, 94 class TranslateManagerBrowserTest : public ChromeRenderViewHostTestHarness,
95 public content::NotificationObserver { 95 public content::NotificationObserver {
96 public: 96 public:
97 TranslateManagerTest() 97 TranslateManagerBrowserTest()
98 : pref_callback_(base::Bind(&TranslateManagerTest::OnPreferenceChanged, 98 : pref_callback_(
99 base::Unretained(this))), 99 base::Bind(&TranslateManagerBrowserTest::OnPreferenceChanged,
100 base::Unretained(this))),
100 ui_thread_(BrowserThread::UI, &message_loop_) { 101 ui_thread_(BrowserThread::UI, &message_loop_) {
101 } 102 }
102 103
103 // Simulates navigating to a page and getting the page contents and language 104 // Simulates navigating to a page and getting the page contents and language
104 // for that navigation. 105 // for that navigation.
105 void SimulateNavigation(const GURL& url, 106 void SimulateNavigation(const GURL& url,
106 const std::string& lang, 107 const std::string& lang,
107 bool page_translatable) { 108 bool page_translatable) {
108 NavigateAndCommit(url); 109 NavigateAndCommit(url);
109 SimulateOnTranslateLanguageDetermined(lang, page_translatable); 110 SimulateOnTranslateLanguageDetermined(lang, page_translatable);
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 content::NotificationRegistrar notification_registrar_; 308 content::NotificationRegistrar notification_registrar_;
308 net::TestURLFetcherFactory url_fetcher_factory_; 309 net::TestURLFetcherFactory url_fetcher_factory_;
309 content::TestBrowserThread ui_thread_; 310 content::TestBrowserThread ui_thread_;
310 content::RenderViewTest::RendererWebKitPlatformSupportImplNoSandbox 311 content::RenderViewTest::RendererWebKitPlatformSupportImplNoSandbox
311 webkit_platform_support_; 312 webkit_platform_support_;
312 313
313 // The infobars that have been removed. 314 // The infobars that have been removed.
314 // WARNING: the pointers point to deleted objects, use only for comparison. 315 // WARNING: the pointers point to deleted objects, use only for comparison.
315 std::set<InfoBarDelegate*> removed_infobars_; 316 std::set<InfoBarDelegate*> removed_infobars_;
316 317
317 DISALLOW_COPY_AND_ASSIGN(TranslateManagerTest); 318 DISALLOW_COPY_AND_ASSIGN(TranslateManagerBrowserTest);
318 }; 319 };
319 320
320 namespace { 321 namespace {
321 322
322 class TestRenderViewContextMenu : public RenderViewContextMenu { 323 class TestRenderViewContextMenu : public RenderViewContextMenu {
323 public: 324 public:
324 static TestRenderViewContextMenu* CreateContextMenu( 325 static TestRenderViewContextMenu* CreateContextMenu(
325 WebContents* web_contents) { 326 WebContents* web_contents) {
326 content::ContextMenuParams params; 327 content::ContextMenuParams params;
327 params.media_type = WebKit::WebContextMenuData::MediaTypeNone; 328 params.media_type = WebKit::WebContextMenuData::MediaTypeNone;
(...skipping 27 matching lines...) Expand all
355 TestRenderViewContextMenu(WebContents* web_contents, 356 TestRenderViewContextMenu(WebContents* web_contents,
356 const content::ContextMenuParams& params) 357 const content::ContextMenuParams& params)
357 : RenderViewContextMenu(web_contents, params) { 358 : RenderViewContextMenu(web_contents, params) {
358 } 359 }
359 360
360 DISALLOW_COPY_AND_ASSIGN(TestRenderViewContextMenu); 361 DISALLOW_COPY_AND_ASSIGN(TestRenderViewContextMenu);
361 }; 362 };
362 363
363 } // namespace 364 } // namespace
364 365
365 TEST_F(TranslateManagerTest, NormalTranslate) { 366 TEST_F(TranslateManagerBrowserTest, NormalTranslate) {
366 // Simulate navigating to a page. 367 // Simulate navigating to a page.
367 SimulateNavigation(GURL("http://www.google.fr"), "fr", true); 368 SimulateNavigation(GURL("http://www.google.fr"), "fr", true);
368 369
369 // We should have an infobar. 370 // We should have an infobar.
370 TranslateInfoBarDelegate* infobar = GetTranslateInfoBar(); 371 TranslateInfoBarDelegate* infobar = GetTranslateInfoBar();
371 ASSERT_TRUE(infobar != NULL); 372 ASSERT_TRUE(infobar != NULL);
372 EXPECT_EQ(TranslateInfoBarDelegate::BEFORE_TRANSLATE, 373 EXPECT_EQ(TranslateInfoBarDelegate::BEFORE_TRANSLATE,
373 infobar->infobar_type()); 374 infobar->infobar_type());
374 375
375 // Simulate clicking translate. 376 // Simulate clicking translate.
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
438 new_infobar = GetTranslateInfoBar(); 439 new_infobar = GetTranslateInfoBar();
439 ASSERT_TRUE(new_infobar != NULL); 440 ASSERT_TRUE(new_infobar != NULL);
440 441
441 // Verify reload keeps the same settings. 442 // Verify reload keeps the same settings.
442 ReloadAndWait(true); 443 ReloadAndWait(true);
443 new_infobar = GetTranslateInfoBar(); 444 new_infobar = GetTranslateInfoBar();
444 ASSERT_TRUE(new_infobar != NULL); 445 ASSERT_TRUE(new_infobar != NULL);
445 ASSERT_EQ(new_target_lang, infobar->target_language_code()); 446 ASSERT_EQ(new_target_lang, infobar->target_language_code());
446 } 447 }
447 448
448 TEST_F(TranslateManagerTest, TranslateScriptNotAvailable) { 449 TEST_F(TranslateManagerBrowserTest, TranslateScriptNotAvailable) {
449 // Simulate navigating to a page. 450 // Simulate navigating to a page.
450 SimulateNavigation(GURL("http://www.google.fr"), "fr", true); 451 SimulateNavigation(GURL("http://www.google.fr"), "fr", true);
451 452
452 // We should have an infobar. 453 // We should have an infobar.
453 TranslateInfoBarDelegate* infobar = GetTranslateInfoBar(); 454 TranslateInfoBarDelegate* infobar = GetTranslateInfoBar();
454 ASSERT_TRUE(infobar != NULL); 455 ASSERT_TRUE(infobar != NULL);
455 EXPECT_EQ(TranslateInfoBarDelegate::BEFORE_TRANSLATE, 456 EXPECT_EQ(TranslateInfoBarDelegate::BEFORE_TRANSLATE,
456 infobar->infobar_type()); 457 infobar->infobar_type());
457 458
458 // Simulate clicking translate. 459 // Simulate clicking translate.
459 process()->sink().ClearMessages(); 460 process()->sink().ClearMessages();
460 infobar->Translate(); 461 infobar->Translate();
461 // Simulate a failure retrieving the translate script. 462 // Simulate a failure retrieving the translate script.
462 SimulateTranslateScriptURLFetch(false); 463 SimulateTranslateScriptURLFetch(false);
463 464
464 // We should not have sent any message to translate to the renderer. 465 // We should not have sent any message to translate to the renderer.
465 EXPECT_FALSE(GetTranslateMessage(NULL, NULL, NULL)); 466 EXPECT_FALSE(GetTranslateMessage(NULL, NULL, NULL));
466 467
467 // And we should have an error infobar showing. 468 // And we should have an error infobar showing.
468 infobar = GetTranslateInfoBar(); 469 infobar = GetTranslateInfoBar();
469 ASSERT_TRUE(infobar != NULL); 470 ASSERT_TRUE(infobar != NULL);
470 EXPECT_EQ(TranslateInfoBarDelegate::TRANSLATION_ERROR, 471 EXPECT_EQ(TranslateInfoBarDelegate::TRANSLATION_ERROR,
471 infobar->infobar_type()); 472 infobar->infobar_type());
472 } 473 }
473 474
474 // Ensures we deal correctly with pages for which the browser does not recognize 475 // Ensures we deal correctly with pages for which the browser does not recognize
475 // the language (the translate server may or not detect the language). 476 // the language (the translate server may or not detect the language).
476 TEST_F(TranslateManagerTest, TranslateUnknownLanguage) { 477 TEST_F(TranslateManagerBrowserTest, TranslateUnknownLanguage) {
477 // Simulate navigating to a page ("und" is the string returned by the CLD for 478 // Simulate navigating to a page ("und" is the string returned by the CLD for
478 // languages it does not recognize). 479 // languages it does not recognize).
479 SimulateNavigation(GURL("http://www.google.mys"), "und", true); 480 SimulateNavigation(GURL("http://www.google.mys"), "und", true);
480 481
481 // We should not have an infobar as we don't know the language. 482 // We should not have an infobar as we don't know the language.
482 ASSERT_TRUE(GetTranslateInfoBar() == NULL); 483 ASSERT_TRUE(GetTranslateInfoBar() == NULL);
483 484
484 // Translate the page anyway throught the context menu. 485 // Translate the page anyway throught the context menu.
485 scoped_ptr<TestRenderViewContextMenu> menu( 486 scoped_ptr<TestRenderViewContextMenu> menu(
486 TestRenderViewContextMenu::CreateContextMenu(web_contents())); 487 TestRenderViewContextMenu::CreateContextMenu(web_contents()));
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
540 2, 0, "", "en", TranslateErrors::UNKNOWN_LANGUAGE)); 541 2, 0, "", "en", TranslateErrors::UNKNOWN_LANGUAGE));
541 infobar = GetTranslateInfoBar(); 542 infobar = GetTranslateInfoBar();
542 ASSERT_TRUE(infobar != NULL); 543 ASSERT_TRUE(infobar != NULL);
543 EXPECT_EQ(TranslateInfoBarDelegate::TRANSLATION_ERROR, 544 EXPECT_EQ(TranslateInfoBarDelegate::TRANSLATION_ERROR,
544 infobar->infobar_type()); 545 infobar->infobar_type());
545 EXPECT_EQ(TranslateErrors::UNKNOWN_LANGUAGE, infobar->error_type()); 546 EXPECT_EQ(TranslateErrors::UNKNOWN_LANGUAGE, infobar->error_type());
546 } 547 }
547 548
548 // Tests that we show/don't show an info-bar for all languages the CLD can 549 // Tests that we show/don't show an info-bar for all languages the CLD can
549 // report. 550 // report.
550 TEST_F(TranslateManagerTest, TestAllLanguages) { 551 TEST_F(TranslateManagerBrowserTest, TestAllLanguages) {
551 // The index in kExpectation are the Language enum (see languages.pb.h). 552 // The index in kExpectation are the Language enum (see languages.pb.h).
552 // true if we expect a translate infobar for that language. 553 // true if we expect a translate infobar for that language.
553 // Note the supported languages are in translation_manager.cc, see 554 // Note the supported languages are in translation_manager.cc, see
554 // kSupportedLanguages. 555 // kSupportedLanguages.
555 bool kExpectations[] = { 556 bool kExpectations[] = {
556 // 0-9 557 // 0-9
557 false, true, true, true, true, true, false, true, true, true, 558 false, true, true, true, true, true, false, true, true, true,
558 // 10-19 559 // 10-19
559 false, true, true, true, true, true, true, true, true, true, 560 false, true, true, true, true, true, true, true, true, true,
560 // 20-29 561 // 20-29
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
609 infobar = GetTranslateInfoBar(); 610 infobar = GetTranslateInfoBar();
610 EXPECT_EQ(kExpectations[i], infobar != NULL); 611 EXPECT_EQ(kExpectations[i], infobar != NULL);
611 612
612 // Close the info-bar if applicable. 613 // Close the info-bar if applicable.
613 if (infobar != NULL) 614 if (infobar != NULL)
614 EXPECT_TRUE(CloseTranslateInfoBar()); 615 EXPECT_TRUE(CloseTranslateInfoBar());
615 } 616 }
616 } 617 }
617 618
618 // Test the fetching of languages from the translate server 619 // Test the fetching of languages from the translate server
619 TEST_F(TranslateManagerTest, FetchLanguagesFromTranslateServer) { 620 TEST_F(TranslateManagerBrowserTest, FetchLanguagesFromTranslateServer) {
620 std::vector<std::string> server_languages; 621 std::vector<std::string> server_languages;
621 // A list of languages to fake being returned by the translate server. 622 // A list of languages to fake being returned by the translate server.
622 server_languages.push_back("aa"); 623 server_languages.push_back("aa");
623 server_languages.push_back("bb"); 624 server_languages.push_back("bb");
624 server_languages.push_back("ab"); 625 server_languages.push_back("ab");
625 server_languages.push_back("en-CA"); 626 server_languages.push_back("en-CA");
626 server_languages.push_back("zz"); 627 server_languages.push_back("zz");
627 server_languages.push_back("yy"); 628 server_languages.push_back("yy");
628 server_languages.push_back("fr-FR"); 629 server_languages.push_back("fr-FR");
629 630
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
683 language_list_dict.Set("tl", target_languages_dict.release()); 684 language_list_dict.Set("tl", target_languages_dict.release());
684 std::string language_list_json_str; 685 std::string language_list_json_str;
685 base::JSONWriter::Write(&language_list_dict, &language_list_json_str); 686 base::JSONWriter::Write(&language_list_dict, &language_list_json_str);
686 std::string language_list_str("sl("); 687 std::string language_list_str("sl(");
687 language_list_str += language_list_json_str; 688 language_list_str += language_list_json_str;
688 language_list_str += ")"; 689 language_list_str += ")";
689 return language_list_str; 690 return language_list_str;
690 } 691 }
691 692
692 // Tests auto-translate on page. 693 // Tests auto-translate on page.
693 TEST_F(TranslateManagerTest, AutoTranslateOnNavigate) { 694 TEST_F(TranslateManagerBrowserTest, AutoTranslateOnNavigate) {
694 // Simulate navigating to a page and getting its language. 695 // Simulate navigating to a page and getting its language.
695 SimulateNavigation(GURL("http://www.google.fr"), "fr", true); 696 SimulateNavigation(GURL("http://www.google.fr"), "fr", true);
696 697
697 // Simulate the user translating. 698 // Simulate the user translating.
698 TranslateInfoBarDelegate* infobar = GetTranslateInfoBar(); 699 TranslateInfoBarDelegate* infobar = GetTranslateInfoBar();
699 ASSERT_TRUE(infobar != NULL); 700 ASSERT_TRUE(infobar != NULL);
700 infobar->Translate(); 701 infobar->Translate();
701 // Simulate the translate script being retrieved. 702 // Simulate the translate script being retrieved.
702 SimulateTranslateScriptURLFetch(true); 703 SimulateTranslateScriptURLFetch(true);
703 704
(...skipping 16 matching lines...) Expand all
720 721
721 // Now navigate to a page in a different language. 722 // Now navigate to a page in a different language.
722 process()->sink().ClearMessages(); 723 process()->sink().ClearMessages();
723 SimulateNavigation(GURL("http://news.google.es"), "es", true); 724 SimulateNavigation(GURL("http://news.google.es"), "es", true);
724 725
725 // This should not have triggered a translate. 726 // This should not have triggered a translate.
726 EXPECT_FALSE(GetTranslateMessage(&page_id, &original_lang, &target_lang)); 727 EXPECT_FALSE(GetTranslateMessage(&page_id, &original_lang, &target_lang));
727 } 728 }
728 729
729 // Tests that multiple OnPageContents do not cause multiple infobars. 730 // Tests that multiple OnPageContents do not cause multiple infobars.
730 TEST_F(TranslateManagerTest, MultipleOnPageContents) { 731 TEST_F(TranslateManagerBrowserTest, MultipleOnPageContents) {
731 // Simulate navigating to a page and getting its language. 732 // Simulate navigating to a page and getting its language.
732 SimulateNavigation(GURL("http://www.google.fr"), "fr", true); 733 SimulateNavigation(GURL("http://www.google.fr"), "fr", true);
733 734
734 // Simulate clicking 'Nope' (don't translate). 735 // Simulate clicking 'Nope' (don't translate).
735 EXPECT_TRUE(DenyTranslation()); 736 EXPECT_TRUE(DenyTranslation());
736 EXPECT_EQ(0U, infobar_service()->GetInfoBarCount()); 737 EXPECT_EQ(0U, infobar_service()->GetInfoBarCount());
737 738
738 // Send a new PageContents, we should not show an infobar. 739 // Send a new PageContents, we should not show an infobar.
739 SimulateOnTranslateLanguageDetermined("fr", true); 740 SimulateOnTranslateLanguageDetermined("fr", true);
740 EXPECT_EQ(0U, infobar_service()->GetInfoBarCount()); 741 EXPECT_EQ(0U, infobar_service()->GetInfoBarCount());
741 742
742 // Do the same steps but simulate closing the infobar this time. 743 // Do the same steps but simulate closing the infobar this time.
743 SimulateNavigation(GURL("http://www.youtube.fr"), "fr", true); 744 SimulateNavigation(GURL("http://www.youtube.fr"), "fr", true);
744 EXPECT_TRUE(CloseTranslateInfoBar()); 745 EXPECT_TRUE(CloseTranslateInfoBar());
745 EXPECT_EQ(0U, infobar_service()->GetInfoBarCount()); 746 EXPECT_EQ(0U, infobar_service()->GetInfoBarCount());
746 SimulateOnTranslateLanguageDetermined("fr", true); 747 SimulateOnTranslateLanguageDetermined("fr", true);
747 EXPECT_EQ(0U, infobar_service()->GetInfoBarCount()); 748 EXPECT_EQ(0U, infobar_service()->GetInfoBarCount());
748 } 749 }
749 750
750 // Test that reloading the page brings back the infobar if the 751 // Test that reloading the page brings back the infobar if the
751 // reload succeeded and does not bring it back the reload fails. 752 // reload succeeded and does not bring it back the reload fails.
752 TEST_F(TranslateManagerTest, Reload) { 753 TEST_F(TranslateManagerBrowserTest, Reload) {
753 // Simulate navigating to a page and getting its language. 754 // Simulate navigating to a page and getting its language.
754 SimulateNavigation(GURL("http://www.google.fr"), "fr", true); 755 SimulateNavigation(GURL("http://www.google.fr"), "fr", true);
755 756
756 // Close the infobar. 757 // Close the infobar.
757 EXPECT_TRUE(CloseTranslateInfoBar()); 758 EXPECT_TRUE(CloseTranslateInfoBar());
758 759
759 // Reload should bring back the infobar if the page succeds 760 // Reload should bring back the infobar if the page succeds
760 ReloadAndWait(true); 761 ReloadAndWait(true);
761 EXPECT_TRUE(GetTranslateInfoBar() != NULL); 762 EXPECT_TRUE(GetTranslateInfoBar() != NULL);
762 763
763 // Close the infobar. 764 // Close the infobar.
764 EXPECT_TRUE(CloseTranslateInfoBar()); 765 EXPECT_TRUE(CloseTranslateInfoBar());
765 766
766 // And not show it if the reload fails 767 // And not show it if the reload fails
767 ReloadAndWait(false); 768 ReloadAndWait(false);
768 EXPECT_EQ(NULL, GetTranslateInfoBar()); 769 EXPECT_EQ(NULL, GetTranslateInfoBar());
769 } 770 }
770 771
771 // Test that reloading the page by way of typing again the URL in the 772 // Test that reloading the page by way of typing again the URL in the
772 // location bar brings back the infobar. 773 // location bar brings back the infobar.
773 TEST_F(TranslateManagerTest, ReloadFromLocationBar) { 774 TEST_F(TranslateManagerBrowserTest, ReloadFromLocationBar) {
774 GURL url("http://www.google.fr"); 775 GURL url("http://www.google.fr");
775 776
776 // Simulate navigating to a page and getting its language. 777 // Simulate navigating to a page and getting its language.
777 SimulateNavigation(url, "fr", true); 778 SimulateNavigation(url, "fr", true);
778 779
779 // Close the infobar. 780 // Close the infobar.
780 EXPECT_TRUE(CloseTranslateInfoBar()); 781 EXPECT_TRUE(CloseTranslateInfoBar());
781 782
782 // Create a pending navigation and simulate a page load. That should be the 783 // Create a pending navigation and simulate a page load. That should be the
783 // equivalent of typing the URL again in the location bar. 784 // equivalent of typing the URL again in the location bar.
(...skipping 11 matching lines...) Expand all
795 EXPECT_EQ(content::NAVIGATION_TYPE_SAME_PAGE, nav_details.type); 796 EXPECT_EQ(content::NAVIGATION_TYPE_SAME_PAGE, nav_details.type);
796 797
797 // The TranslateManager class processes the navigation entry committed 798 // The TranslateManager class processes the navigation entry committed
798 // notification in a posted task; process that task. 799 // notification in a posted task; process that task.
799 MessageLoop::current()->RunUntilIdle(); 800 MessageLoop::current()->RunUntilIdle();
800 EXPECT_TRUE(GetTranslateInfoBar() != NULL); 801 EXPECT_TRUE(GetTranslateInfoBar() != NULL);
801 } 802 }
802 803
803 // Tests that a closed translate infobar does not reappear when navigating 804 // Tests that a closed translate infobar does not reappear when navigating
804 // in-page. 805 // in-page.
805 TEST_F(TranslateManagerTest, CloseInfoBarInPageNavigation) { 806 TEST_F(TranslateManagerBrowserTest, CloseInfoBarInPageNavigation) {
806 // Simulate navigating to a page and getting its language. 807 // Simulate navigating to a page and getting its language.
807 SimulateNavigation(GURL("http://www.google.fr"), "fr", true); 808 SimulateNavigation(GURL("http://www.google.fr"), "fr", true);
808 809
809 // Close the infobar. 810 // Close the infobar.
810 EXPECT_TRUE(CloseTranslateInfoBar()); 811 EXPECT_TRUE(CloseTranslateInfoBar());
811 812
812 // Navigate in page, no infobar should be shown. 813 // Navigate in page, no infobar should be shown.
813 SimulateNavigation(GURL("http://www.google.fr/#ref1"), "fr", 814 SimulateNavigation(GURL("http://www.google.fr/#ref1"), "fr",
814 true); 815 true);
815 EXPECT_TRUE(GetTranslateInfoBar() == NULL); 816 EXPECT_TRUE(GetTranslateInfoBar() == NULL);
816 817
817 // Navigate out of page, a new infobar should show. 818 // Navigate out of page, a new infobar should show.
818 SimulateNavigation(GURL("http://www.google.fr/foot"), "fr", true); 819 SimulateNavigation(GURL("http://www.google.fr/foot"), "fr", true);
819 EXPECT_TRUE(GetTranslateInfoBar() != NULL); 820 EXPECT_TRUE(GetTranslateInfoBar() != NULL);
820 } 821 }
821 822
822 // Tests that a closed translate infobar does not reappear when navigating 823 // Tests that a closed translate infobar does not reappear when navigating
823 // in a subframe. (http://crbug.com/48215) 824 // in a subframe. (http://crbug.com/48215)
824 TEST_F(TranslateManagerTest, CloseInfoBarInSubframeNavigation) { 825 TEST_F(TranslateManagerBrowserTest, CloseInfoBarInSubframeNavigation) {
825 // Simulate navigating to a page and getting its language. 826 // Simulate navigating to a page and getting its language.
826 SimulateNavigation(GURL("http://www.google.fr"), "fr", true); 827 SimulateNavigation(GURL("http://www.google.fr"), "fr", true);
827 828
828 // Close the infobar. 829 // Close the infobar.
829 EXPECT_TRUE(CloseTranslateInfoBar()); 830 EXPECT_TRUE(CloseTranslateInfoBar());
830 831
831 // Simulate a sub-frame auto-navigating. 832 // Simulate a sub-frame auto-navigating.
832 rvh_tester()->SendNavigateWithTransition( 833 rvh_tester()->SendNavigateWithTransition(
833 1, GURL("http://pub.com"), content::PAGE_TRANSITION_AUTO_SUBFRAME); 834 1, GURL("http://pub.com"), content::PAGE_TRANSITION_AUTO_SUBFRAME);
834 EXPECT_TRUE(GetTranslateInfoBar() == NULL); 835 EXPECT_TRUE(GetTranslateInfoBar() == NULL);
835 836
836 // Simulate the user navigating in a sub-frame. 837 // Simulate the user navigating in a sub-frame.
837 rvh_tester()->SendNavigateWithTransition( 838 rvh_tester()->SendNavigateWithTransition(
838 2, GURL("http://pub.com"), content::PAGE_TRANSITION_MANUAL_SUBFRAME); 839 2, GURL("http://pub.com"), content::PAGE_TRANSITION_MANUAL_SUBFRAME);
839 EXPECT_TRUE(GetTranslateInfoBar() == NULL); 840 EXPECT_TRUE(GetTranslateInfoBar() == NULL);
840 841
841 // Navigate out of page, a new infobar should show. 842 // Navigate out of page, a new infobar should show.
842 SimulateNavigation(GURL("http://www.google.fr/foot"), "fr", true); 843 SimulateNavigation(GURL("http://www.google.fr/foot"), "fr", true);
843 EXPECT_TRUE(GetTranslateInfoBar() != NULL); 844 EXPECT_TRUE(GetTranslateInfoBar() != NULL);
844 } 845 }
845 846
846 // Tests that denying translation is sticky when navigating in page. 847 // Tests that denying translation is sticky when navigating in page.
847 TEST_F(TranslateManagerTest, DenyTranslateInPageNavigation) { 848 TEST_F(TranslateManagerBrowserTest, DenyTranslateInPageNavigation) {
848 // Simulate navigating to a page and getting its language. 849 // Simulate navigating to a page and getting its language.
849 SimulateNavigation(GURL("http://www.google.fr"), "fr", true); 850 SimulateNavigation(GURL("http://www.google.fr"), "fr", true);
850 851
851 // Simulate clicking 'Nope' (don't translate). 852 // Simulate clicking 'Nope' (don't translate).
852 EXPECT_TRUE(DenyTranslation()); 853 EXPECT_TRUE(DenyTranslation());
853 854
854 // Navigate in page, no infobar should be shown. 855 // Navigate in page, no infobar should be shown.
855 SimulateNavigation(GURL("http://www.google.fr/#ref1"), "fr", true); 856 SimulateNavigation(GURL("http://www.google.fr/#ref1"), "fr", true);
856 EXPECT_TRUE(GetTranslateInfoBar() == NULL); 857 EXPECT_TRUE(GetTranslateInfoBar() == NULL);
857 858
858 // Navigate out of page, a new infobar should show. 859 // Navigate out of page, a new infobar should show.
859 SimulateNavigation(GURL("http://www.google.fr/foot"), "fr", true); 860 SimulateNavigation(GURL("http://www.google.fr/foot"), "fr", true);
860 EXPECT_TRUE(GetTranslateInfoBar() != NULL); 861 EXPECT_TRUE(GetTranslateInfoBar() != NULL);
861 } 862 }
862 863
863 // Tests that after translating and closing the infobar, the infobar does not 864 // Tests that after translating and closing the infobar, the infobar does not
864 // return when navigating in page. 865 // return when navigating in page.
865 TEST_F(TranslateManagerTest, TranslateCloseInfoBarInPageNavigation) { 866 TEST_F(TranslateManagerBrowserTest, TranslateCloseInfoBarInPageNavigation) {
866 // Simulate navigating to a page and getting its language. 867 // Simulate navigating to a page and getting its language.
867 SimulateNavigation(GURL("http://www.google.fr"), "fr", true); 868 SimulateNavigation(GURL("http://www.google.fr"), "fr", true);
868 869
869 // Simulate the user translating. 870 // Simulate the user translating.
870 TranslateInfoBarDelegate* infobar = GetTranslateInfoBar(); 871 TranslateInfoBarDelegate* infobar = GetTranslateInfoBar();
871 ASSERT_TRUE(infobar != NULL); 872 ASSERT_TRUE(infobar != NULL);
872 infobar->Translate(); 873 infobar->Translate();
873 // Simulate the translate script being retrieved. 874 // Simulate the translate script being retrieved.
874 SimulateTranslateScriptURLFetch(true); 875 SimulateTranslateScriptURLFetch(true);
875 RenderViewHostTester::TestOnMessageReceived( 876 RenderViewHostTester::TestOnMessageReceived(
(...skipping 11 matching lines...) Expand all
887 // Navigate out of page, a new infobar should show. 888 // Navigate out of page, a new infobar should show.
888 // Note that we navigate to a page in a different language so we don't trigger 889 // Note that we navigate to a page in a different language so we don't trigger
889 // the auto-translate feature (it would translate the page automatically and 890 // the auto-translate feature (it would translate the page automatically and
890 // the before translate inforbar would not be shown). 891 // the before translate inforbar would not be shown).
891 SimulateNavigation(GURL("http://www.google.de"), "de", true); 892 SimulateNavigation(GURL("http://www.google.de"), "de", true);
892 EXPECT_TRUE(GetTranslateInfoBar() != NULL); 893 EXPECT_TRUE(GetTranslateInfoBar() != NULL);
893 } 894 }
894 895
895 // Tests that the after translate the infobar still shows when navigating 896 // Tests that the after translate the infobar still shows when navigating
896 // in-page. 897 // in-page.
897 TEST_F(TranslateManagerTest, TranslateInPageNavigation) { 898 TEST_F(TranslateManagerBrowserTest, TranslateInPageNavigation) {
898 // Simulate navigating to a page and getting its language. 899 // Simulate navigating to a page and getting its language.
899 SimulateNavigation(GURL("http://www.google.fr"), "fr", true); 900 SimulateNavigation(GURL("http://www.google.fr"), "fr", true);
900 901
901 // Simulate the user translating. 902 // Simulate the user translating.
902 TranslateInfoBarDelegate* infobar = GetTranslateInfoBar(); 903 TranslateInfoBarDelegate* infobar = GetTranslateInfoBar();
903 ASSERT_TRUE(infobar != NULL); 904 ASSERT_TRUE(infobar != NULL);
904 infobar->Translate(); 905 infobar->Translate();
905 // Simulate the translate script being retrieved. 906 // Simulate the translate script being retrieved.
906 SimulateTranslateScriptURLFetch(true); 907 SimulateTranslateScriptURLFetch(true);
907 RenderViewHostTester::TestOnMessageReceived( 908 RenderViewHostTester::TestOnMessageReceived(
908 rvh(), 909 rvh(),
909 ChromeViewHostMsg_PageTranslated( 910 ChromeViewHostMsg_PageTranslated(
910 0, 0, "fr", "en", TranslateErrors::NONE)); 911 0, 0, "fr", "en", TranslateErrors::NONE));
911 // The after translate infobar is showing. 912 // The after translate infobar is showing.
912 infobar = GetTranslateInfoBar(); 913 infobar = GetTranslateInfoBar();
913 ASSERT_TRUE(infobar != NULL); 914 ASSERT_TRUE(infobar != NULL);
914 915
915 // Navigate out of page, a new infobar should show. 916 // Navigate out of page, a new infobar should show.
916 // See note in TranslateCloseInfoBarInPageNavigation test on why it is 917 // See note in TranslateCloseInfoBarInPageNavigation test on why it is
917 // important to navigate to a page in a different language for this test. 918 // important to navigate to a page in a different language for this test.
918 SimulateNavigation(GURL("http://www.google.de"), "de", true); 919 SimulateNavigation(GURL("http://www.google.de"), "de", true);
919 // The old infobar is gone. 920 // The old infobar is gone.
920 EXPECT_TRUE(CheckInfoBarRemovedAndReset(infobar)); 921 EXPECT_TRUE(CheckInfoBarRemovedAndReset(infobar));
921 // And there is a new one. 922 // And there is a new one.
922 EXPECT_TRUE(GetTranslateInfoBar() != NULL); 923 EXPECT_TRUE(GetTranslateInfoBar() != NULL);
923 } 924 }
924 925
925 // Tests that no translate infobar is shown when navigating to a page in an 926 // Tests that no translate infobar is shown when navigating to a page in an
926 // unsupported language. 927 // unsupported language.
927 TEST_F(TranslateManagerTest, CLDReportsUnsupportedPageLanguage) { 928 TEST_F(TranslateManagerBrowserTest, CLDReportsUnsupportedPageLanguage) {
928 // Simulate navigating to a page and getting an unsupported language. 929 // Simulate navigating to a page and getting an unsupported language.
929 SimulateNavigation(GURL("http://www.google.com"), "qbz", true); 930 SimulateNavigation(GURL("http://www.google.com"), "qbz", true);
930 931
931 // No info-bar should be shown. 932 // No info-bar should be shown.
932 EXPECT_TRUE(GetTranslateInfoBar() == NULL); 933 EXPECT_TRUE(GetTranslateInfoBar() == NULL);
933 } 934 }
934 935
935 // Tests that we deal correctly with unsupported languages returned by the 936 // Tests that we deal correctly with unsupported languages returned by the
936 // server. 937 // server.
937 // The translation server might return a language we don't support. 938 // The translation server might return a language we don't support.
938 TEST_F(TranslateManagerTest, ServerReportsUnsupportedLanguage) { 939 TEST_F(TranslateManagerBrowserTest, ServerReportsUnsupportedLanguage) {
939 // Simulate navigating to a page and translating it. 940 // Simulate navigating to a page and translating it.
940 SimulateNavigation(GURL("http://mail.google.fr"), "fr", true); 941 SimulateNavigation(GURL("http://mail.google.fr"), "fr", true);
941 TranslateInfoBarDelegate* infobar = GetTranslateInfoBar(); 942 TranslateInfoBarDelegate* infobar = GetTranslateInfoBar();
942 ASSERT_TRUE(infobar != NULL); 943 ASSERT_TRUE(infobar != NULL);
943 process()->sink().ClearMessages(); 944 process()->sink().ClearMessages();
944 infobar->Translate(); 945 infobar->Translate();
945 SimulateTranslateScriptURLFetch(true); 946 SimulateTranslateScriptURLFetch(true);
946 // Simulate the render notifying the translation has been done, but it 947 // Simulate the render notifying the translation has been done, but it
947 // reports a language we don't support. 948 // reports a language we don't support.
948 RenderViewHostTester::TestOnMessageReceived( 949 RenderViewHostTester::TestOnMessageReceived(
(...skipping 17 matching lines...) Expand all
966 const IPC::Message* message = 967 const IPC::Message* message =
967 process()->sink().GetFirstMessageMatching( 968 process()->sink().GetFirstMessageMatching(
968 ChromeViewMsg_RevertTranslation::ID); 969 ChromeViewMsg_RevertTranslation::ID);
969 EXPECT_TRUE(message != NULL); 970 EXPECT_TRUE(message != NULL);
970 // And it should have removed the infobar. 971 // And it should have removed the infobar.
971 EXPECT_TRUE(GetTranslateInfoBar() == NULL); 972 EXPECT_TRUE(GetTranslateInfoBar() == NULL);
972 } 973 }
973 974
974 // Tests that no translate infobar is shown and context menu is disabled, when 975 // Tests that no translate infobar is shown and context menu is disabled, when
975 // Chrome is in a language that the translate server does not support. 976 // Chrome is in a language that the translate server does not support.
976 TEST_F(TranslateManagerTest, UnsupportedUILanguage) { 977 TEST_F(TranslateManagerBrowserTest, UnsupportedUILanguage) {
977 std::string original_lang = g_browser_process->GetApplicationLocale(); 978 std::string original_lang = g_browser_process->GetApplicationLocale();
978 g_browser_process->SetApplicationLocale("qbz"); 979 g_browser_process->SetApplicationLocale("qbz");
979 980
980 // Make sure that the accept language list only contains unsupported languages 981 // Make sure that the accept language list only contains unsupported languages
981 Profile* profile = 982 Profile* profile =
982 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); 983 Profile::FromBrowserContext(web_contents()->GetBrowserContext());
983 PrefService* prefs = profile->GetPrefs(); 984 PrefService* prefs = profile->GetPrefs();
984 prefs->SetString(prefs::kAcceptLanguages, "qbz"); 985 prefs->SetString(prefs::kAcceptLanguages, "qbz");
985 986
986 // Simulate navigating to a page in a language supported by the translate 987 // Simulate navigating to a page in a language supported by the translate
987 // server. 988 // server.
988 SimulateNavigation(GURL("http://www.google.com"), "en", true); 989 SimulateNavigation(GURL("http://www.google.com"), "en", true);
989 990
990 // No info-bar should be shown. 991 // No info-bar should be shown.
991 EXPECT_TRUE(GetTranslateInfoBar() == NULL); 992 EXPECT_TRUE(GetTranslateInfoBar() == NULL);
992 993
993 // And the context menu option should be disabled too. 994 // And the context menu option should be disabled too.
994 scoped_ptr<TestRenderViewContextMenu> menu( 995 scoped_ptr<TestRenderViewContextMenu> menu(
995 TestRenderViewContextMenu::CreateContextMenu(web_contents())); 996 TestRenderViewContextMenu::CreateContextMenu(web_contents()));
996 menu->Init(); 997 menu->Init();
997 EXPECT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_TRANSLATE)); 998 EXPECT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_TRANSLATE));
998 EXPECT_FALSE(menu->IsCommandIdEnabled(IDC_CONTENT_CONTEXT_TRANSLATE)); 999 EXPECT_FALSE(menu->IsCommandIdEnabled(IDC_CONTENT_CONTEXT_TRANSLATE));
999 1000
1000 g_browser_process->SetApplicationLocale(original_lang); 1001 g_browser_process->SetApplicationLocale(original_lang);
1001 } 1002 }
1002 1003
1003 // Tests that the first supported accept language is selected 1004 // Tests that the first supported accept language is selected
1004 TEST_F(TranslateManagerTest, TranslateAcceptLanguage) { 1005 TEST_F(TranslateManagerBrowserTest, TranslateAcceptLanguage) {
1005 // Set locate to non-existant language 1006 // Set locate to non-existant language
1006 std::string original_lang = g_browser_process->GetApplicationLocale(); 1007 std::string original_lang = g_browser_process->GetApplicationLocale();
1007 g_browser_process->SetApplicationLocale("qbz"); 1008 g_browser_process->SetApplicationLocale("qbz");
1008 1009
1009 // Set Qbz and French as the only accepted languages 1010 // Set Qbz and French as the only accepted languages
1010 Profile* profile = 1011 Profile* profile =
1011 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); 1012 Profile::FromBrowserContext(web_contents()->GetBrowserContext());
1012 PrefService* prefs = profile->GetPrefs(); 1013 PrefService* prefs = profile->GetPrefs();
1013 prefs->SetString(prefs::kAcceptLanguages, "qbz,fr"); 1014 prefs->SetString(prefs::kAcceptLanguages, "qbz,fr");
1014 1015
1015 // Go to a German page 1016 // Go to a German page
1016 SimulateNavigation(GURL("http://google.de"), "de", true); 1017 SimulateNavigation(GURL("http://google.de"), "de", true);
1017 1018
1018 // Expect the infobar to pop up 1019 // Expect the infobar to pop up
1019 EXPECT_TRUE(GetTranslateInfoBar() != NULL); 1020 EXPECT_TRUE(GetTranslateInfoBar() != NULL);
1020 1021
1021 // Set Qbz and English-US as the only accepted languages to test the country 1022 // Set Qbz and English-US as the only accepted languages to test the country
1022 // code removal code which was causing a crash as filed in Issue 90106, 1023 // code removal code which was causing a crash as filed in Issue 90106,
1023 // a crash caused by a language with a country code that wasn't recognized. 1024 // a crash caused by a language with a country code that wasn't recognized.
1024 prefs->SetString(prefs::kAcceptLanguages, "qbz,en-us"); 1025 prefs->SetString(prefs::kAcceptLanguages, "qbz,en-us");
1025 1026
1026 // Go to a German page 1027 // Go to a German page
1027 SimulateNavigation(GURL("http://google.de"), "de", true); 1028 SimulateNavigation(GURL("http://google.de"), "de", true);
1028 1029
1029 // Expect the infobar to pop up 1030 // Expect the infobar to pop up
1030 EXPECT_TRUE(GetTranslateInfoBar() != NULL); 1031 EXPECT_TRUE(GetTranslateInfoBar() != NULL);
1031 } 1032 }
1032 1033
1033 // Tests that the translate enabled preference is honored. 1034 // Tests that the translate enabled preference is honored.
1034 TEST_F(TranslateManagerTest, TranslateEnabledPref) { 1035 TEST_F(TranslateManagerBrowserTest, TranslateEnabledPref) {
1035 // Make sure the pref allows translate. 1036 // Make sure the pref allows translate.
1036 Profile* profile = 1037 Profile* profile =
1037 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); 1038 Profile::FromBrowserContext(web_contents()->GetBrowserContext());
1038 PrefService* prefs = profile->GetPrefs(); 1039 PrefService* prefs = profile->GetPrefs();
1039 prefs->SetBoolean(prefs::kEnableTranslate, true); 1040 prefs->SetBoolean(prefs::kEnableTranslate, true);
1040 1041
1041 // Simulate navigating to a page and getting its language. 1042 // Simulate navigating to a page and getting its language.
1042 SimulateNavigation(GURL("http://www.google.fr"), "fr", true); 1043 SimulateNavigation(GURL("http://www.google.fr"), "fr", true);
1043 1044
1044 // An infobar should be shown. 1045 // An infobar should be shown.
(...skipping 10 matching lines...) Expand all
1055 EXPECT_TRUE(infobar == NULL); 1056 EXPECT_TRUE(infobar == NULL);
1056 1057
1057 // Simulate getting the page contents and language, that should not trigger 1058 // Simulate getting the page contents and language, that should not trigger
1058 // a translate infobar. 1059 // a translate infobar.
1059 SimulateOnTranslateLanguageDetermined("fr", true); 1060 SimulateOnTranslateLanguageDetermined("fr", true);
1060 infobar = GetTranslateInfoBar(); 1061 infobar = GetTranslateInfoBar();
1061 EXPECT_TRUE(infobar == NULL); 1062 EXPECT_TRUE(infobar == NULL);
1062 } 1063 }
1063 1064
1064 // Tests the "Never translate <language>" pref. 1065 // Tests the "Never translate <language>" pref.
1065 TEST_F(TranslateManagerTest, NeverTranslateLanguagePref) { 1066 TEST_F(TranslateManagerBrowserTest, NeverTranslateLanguagePref) {
1066 // Simulate navigating to a page and getting its language. 1067 // Simulate navigating to a page and getting its language.
1067 GURL url("http://www.google.fr"); 1068 GURL url("http://www.google.fr");
1068 SimulateNavigation(url, "fr", true); 1069 SimulateNavigation(url, "fr", true);
1069 1070
1070 // An infobar should be shown. 1071 // An infobar should be shown.
1071 EXPECT_TRUE(GetTranslateInfoBar() != NULL); 1072 EXPECT_TRUE(GetTranslateInfoBar() != NULL);
1072 1073
1073 // Select never translate this language. 1074 // Select never translate this language.
1074 Profile* profile = 1075 Profile* profile =
1075 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); 1076 Profile::FromBrowserContext(web_contents()->GetBrowserContext());
(...skipping 26 matching lines...) Expand all
1102 EXPECT_TRUE(translate_prefs.CanTranslate(prefs, "fr", url)); 1103 EXPECT_TRUE(translate_prefs.CanTranslate(prefs, "fr", url));
1103 1104
1104 // Navigate to a page in French. 1105 // Navigate to a page in French.
1105 SimulateNavigation(url, "fr", true); 1106 SimulateNavigation(url, "fr", true);
1106 1107
1107 // There should be a translate infobar. 1108 // There should be a translate infobar.
1108 EXPECT_TRUE(GetTranslateInfoBar() != NULL); 1109 EXPECT_TRUE(GetTranslateInfoBar() != NULL);
1109 } 1110 }
1110 1111
1111 // Tests the "Never translate this site" pref. 1112 // Tests the "Never translate this site" pref.
1112 TEST_F(TranslateManagerTest, NeverTranslateSitePref) { 1113 TEST_F(TranslateManagerBrowserTest, NeverTranslateSitePref) {
1113 // Simulate navigating to a page and getting its language. 1114 // Simulate navigating to a page and getting its language.
1114 GURL url("http://www.google.fr"); 1115 GURL url("http://www.google.fr");
1115 std::string host(url.host()); 1116 std::string host(url.host());
1116 SimulateNavigation(url, "fr", true); 1117 SimulateNavigation(url, "fr", true);
1117 1118
1118 // An infobar should be shown. 1119 // An infobar should be shown.
1119 EXPECT_TRUE(GetTranslateInfoBar() != NULL); 1120 EXPECT_TRUE(GetTranslateInfoBar() != NULL);
1120 1121
1121 // Select never translate this site. 1122 // Select never translate this site.
1122 Profile* profile = 1123 Profile* profile =
(...skipping 26 matching lines...) Expand all
1149 EXPECT_TRUE(translate_prefs.CanTranslate(prefs, "fr", url)); 1150 EXPECT_TRUE(translate_prefs.CanTranslate(prefs, "fr", url));
1150 1151
1151 // Navigate to a page in French. 1152 // Navigate to a page in French.
1152 SimulateNavigation(url, "fr", true); 1153 SimulateNavigation(url, "fr", true);
1153 1154
1154 // There should be a translate infobar. 1155 // There should be a translate infobar.
1155 EXPECT_TRUE(GetTranslateInfoBar() != NULL); 1156 EXPECT_TRUE(GetTranslateInfoBar() != NULL);
1156 } 1157 }
1157 1158
1158 // Tests the "Always translate this language" pref. 1159 // Tests the "Always translate this language" pref.
1159 TEST_F(TranslateManagerTest, AlwaysTranslateLanguagePref) { 1160 TEST_F(TranslateManagerBrowserTest, AlwaysTranslateLanguagePref) {
1160 // Select always translate French to English. 1161 // Select always translate French to English.
1161 Profile* profile = 1162 Profile* profile =
1162 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); 1163 Profile::FromBrowserContext(web_contents()->GetBrowserContext());
1163 PrefService* prefs = profile->GetPrefs(); 1164 PrefService* prefs = profile->GetPrefs();
1164 PrefChangeRegistrar registrar; 1165 PrefChangeRegistrar registrar;
1165 registrar.Init(prefs); 1166 registrar.Init(prefs);
1166 registrar.Add(TranslatePrefs::kPrefTranslateWhitelists, pref_callback_); 1167 registrar.Add(TranslatePrefs::kPrefTranslateWhitelists, pref_callback_);
1167 TranslatePrefs translate_prefs(prefs); 1168 TranslatePrefs translate_prefs(prefs);
1168 SetPrefObserverExpectation(TranslatePrefs::kPrefTranslateWhitelists); 1169 SetPrefObserverExpectation(TranslatePrefs::kPrefTranslateWhitelists);
1169 translate_prefs.WhitelistLanguagePair("fr", "en"); 1170 translate_prefs.WhitelistLanguagePair("fr", "en");
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1209 translate_prefs.RemoveLanguagePairFromWhitelist("fr", "en"); 1210 translate_prefs.RemoveLanguagePairFromWhitelist("fr", "en");
1210 SimulateNavigation(GURL("http://www.google.fr"), "fr", true); 1211 SimulateNavigation(GURL("http://www.google.fr"), "fr", true);
1211 EXPECT_FALSE(GetTranslateMessage(&page_id, &original_lang, &target_lang)); 1212 EXPECT_FALSE(GetTranslateMessage(&page_id, &original_lang, &target_lang));
1212 infobar = GetTranslateInfoBar(); 1213 infobar = GetTranslateInfoBar();
1213 ASSERT_TRUE(infobar != NULL); 1214 ASSERT_TRUE(infobar != NULL);
1214 EXPECT_EQ(TranslateInfoBarDelegate::BEFORE_TRANSLATE, 1215 EXPECT_EQ(TranslateInfoBarDelegate::BEFORE_TRANSLATE,
1215 infobar->infobar_type()); 1216 infobar->infobar_type());
1216 } 1217 }
1217 1218
1218 // Context menu. 1219 // Context menu.
1219 TEST_F(TranslateManagerTest, ContextMenu) { 1220 TEST_F(TranslateManagerBrowserTest, ContextMenu) {
1220 // Blacklist www.google.fr and French for translation. 1221 // Blacklist www.google.fr and French for translation.
1221 GURL url("http://www.google.fr"); 1222 GURL url("http://www.google.fr");
1222 Profile* profile = 1223 Profile* profile =
1223 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); 1224 Profile::FromBrowserContext(web_contents()->GetBrowserContext());
1224 TranslatePrefs translate_prefs(profile->GetPrefs()); 1225 TranslatePrefs translate_prefs(profile->GetPrefs());
1225 translate_prefs.BlacklistLanguage("fr"); 1226 translate_prefs.BlacklistLanguage("fr");
1226 translate_prefs.BlacklistSite(url.host()); 1227 translate_prefs.BlacklistSite(url.host());
1227 EXPECT_TRUE(translate_prefs.IsLanguageBlacklisted("fr")); 1228 EXPECT_TRUE(translate_prefs.IsLanguageBlacklisted("fr"));
1228 EXPECT_TRUE(translate_prefs.IsSiteBlacklisted(url.host())); 1229 EXPECT_TRUE(translate_prefs.IsSiteBlacklisted(url.host()));
1229 1230
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
1324 SimulateNavigation(url, "qbz", true); 1325 SimulateNavigation(url, "qbz", true);
1325 menu.reset(TestRenderViewContextMenu::CreateContextMenu(web_contents())); 1326 menu.reset(TestRenderViewContextMenu::CreateContextMenu(web_contents()));
1326 menu->Init(); 1327 menu->Init();
1327 EXPECT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_TRANSLATE)); 1328 EXPECT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_TRANSLATE));
1328 EXPECT_FALSE(menu->IsCommandIdEnabled(IDC_CONTENT_CONTEXT_TRANSLATE)); 1329 EXPECT_FALSE(menu->IsCommandIdEnabled(IDC_CONTENT_CONTEXT_TRANSLATE));
1329 } 1330 }
1330 1331
1331 // Tests that an extra always/never translate button is shown on the "before 1332 // Tests that an extra always/never translate button is shown on the "before
1332 // translate" infobar when the translation is accepted/declined 3 times, 1333 // translate" infobar when the translation is accepted/declined 3 times,
1333 // only when not in incognito mode. 1334 // only when not in incognito mode.
1334 TEST_F(TranslateManagerTest, BeforeTranslateExtraButtons) { 1335 TEST_F(TranslateManagerBrowserTest, BeforeTranslateExtraButtons) {
1335 Profile* profile = 1336 Profile* profile =
1336 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); 1337 Profile::FromBrowserContext(web_contents()->GetBrowserContext());
1337 TranslatePrefs translate_prefs(profile->GetPrefs()); 1338 TranslatePrefs translate_prefs(profile->GetPrefs());
1338 translate_prefs.ResetTranslationAcceptedCount("fr"); 1339 translate_prefs.ResetTranslationAcceptedCount("fr");
1339 translate_prefs.ResetTranslationDeniedCount("fr"); 1340 translate_prefs.ResetTranslationDeniedCount("fr");
1340 translate_prefs.ResetTranslationAcceptedCount("de"); 1341 translate_prefs.ResetTranslationAcceptedCount("de");
1341 translate_prefs.ResetTranslationDeniedCount("de"); 1342 translate_prefs.ResetTranslationDeniedCount("de");
1342 1343
1343 // We'll do 4 times in incognito mode first to make sure the button is not 1344 // We'll do 4 times in incognito mode first to make sure the button is not
1344 // shown in that case, then 4 times in normal mode. 1345 // shown in that case, then 4 times in normal mode.
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
1403 infobar->NeverTranslatePageLanguage(); 1404 infobar->NeverTranslatePageLanguage();
1404 EXPECT_TRUE(translate_prefs.IsLanguageBlacklisted("de")); 1405 EXPECT_TRUE(translate_prefs.IsLanguageBlacklisted("de"));
1405 // No translation should have occured and the infobar should be gone. 1406 // No translation should have occured and the infobar should be gone.
1406 EXPECT_FALSE(GetTranslateMessage(&page_id, &original_lang, &target_lang)); 1407 EXPECT_FALSE(GetTranslateMessage(&page_id, &original_lang, &target_lang));
1407 process()->sink().ClearMessages(); 1408 process()->sink().ClearMessages();
1408 ASSERT_TRUE(GetTranslateInfoBar() == NULL); 1409 ASSERT_TRUE(GetTranslateInfoBar() == NULL);
1409 } 1410 }
1410 1411
1411 // Tests that we don't show a translate infobar when a page instructs that it 1412 // Tests that we don't show a translate infobar when a page instructs that it
1412 // should not be translated. 1413 // should not be translated.
1413 TEST_F(TranslateManagerTest, NonTranslatablePage) { 1414 TEST_F(TranslateManagerBrowserTest, NonTranslatablePage) {
1414 // Simulate navigating to a page. 1415 // Simulate navigating to a page.
1415 SimulateNavigation(GURL("http://mail.google.fr"), "fr", false); 1416 SimulateNavigation(GURL("http://mail.google.fr"), "fr", false);
1416 1417
1417 // We should not have an infobar. 1418 // We should not have an infobar.
1418 EXPECT_TRUE(GetTranslateInfoBar() == NULL); 1419 EXPECT_TRUE(GetTranslateInfoBar() == NULL);
1419 1420
1420 // The context menu should be disabled. 1421 // The context menu should be disabled.
1421 scoped_ptr<TestRenderViewContextMenu> menu( 1422 scoped_ptr<TestRenderViewContextMenu> menu(
1422 TestRenderViewContextMenu::CreateContextMenu(web_contents())); 1423 TestRenderViewContextMenu::CreateContextMenu(web_contents()));
1423 menu->Init(); 1424 menu->Init();
1424 EXPECT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_TRANSLATE)); 1425 EXPECT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_TRANSLATE));
1425 EXPECT_FALSE(menu->IsCommandIdEnabled(IDC_CONTENT_CONTEXT_TRANSLATE)); 1426 EXPECT_FALSE(menu->IsCommandIdEnabled(IDC_CONTENT_CONTEXT_TRANSLATE));
1426 } 1427 }
1427 1428
1428 // Tests that the script is expired and refetched as expected. 1429 // Tests that the script is expired and refetched as expected.
1429 TEST_F(TranslateManagerTest, ScriptExpires) { 1430 TEST_F(TranslateManagerBrowserTest, ScriptExpires) {
1430 ExpireTranslateScriptImmediately(); 1431 ExpireTranslateScriptImmediately();
1431 1432
1432 // Simulate navigating to a page and translating it. 1433 // Simulate navigating to a page and translating it.
1433 SimulateNavigation(GURL("http://www.google.fr"), "fr", true); 1434 SimulateNavigation(GURL("http://www.google.fr"), "fr", true);
1434 TranslateInfoBarDelegate* infobar = GetTranslateInfoBar(); 1435 TranslateInfoBarDelegate* infobar = GetTranslateInfoBar();
1435 ASSERT_TRUE(infobar != NULL); 1436 ASSERT_TRUE(infobar != NULL);
1436 process()->sink().ClearMessages(); 1437 process()->sink().ClearMessages();
1437 infobar->Translate(); 1438 infobar->Translate();
1438 SimulateTranslateScriptURLFetch(true); 1439 SimulateTranslateScriptURLFetch(true);
1439 RenderViewHostTester::TestOnMessageReceived( 1440 RenderViewHostTester::TestOnMessageReceived(
(...skipping 19 matching lines...) Expand all
1459 // Now simulate the URL fetch. 1460 // Now simulate the URL fetch.
1460 SimulateTranslateScriptURLFetch(true); 1461 SimulateTranslateScriptURLFetch(true);
1461 // Now the message should have been sent. 1462 // Now the message should have been sent.
1462 int page_id = 0; 1463 int page_id = 0;
1463 std::string original_lang, target_lang; 1464 std::string original_lang, target_lang;
1464 EXPECT_TRUE(GetTranslateMessage(&page_id, &original_lang, &target_lang)); 1465 EXPECT_TRUE(GetTranslateMessage(&page_id, &original_lang, &target_lang));
1465 EXPECT_EQ("es", original_lang); 1466 EXPECT_EQ("es", original_lang);
1466 EXPECT_EQ("en", target_lang); 1467 EXPECT_EQ("en", target_lang);
1467 } 1468 }
1468 1469
1469 TEST_F(TranslateManagerTest, DownloadsAndHistoryNotTranslated) { 1470 TEST_F(TranslateManagerBrowserTest, DownloadsAndHistoryNotTranslated) {
1470 ASSERT_FALSE(TranslateManager::IsTranslatableURL( 1471 ASSERT_FALSE(TranslateManager::IsTranslatableURL(
1471 GURL(chrome::kChromeUIDownloadsURL))); 1472 GURL(chrome::kChromeUIDownloadsURL)));
1472 ASSERT_FALSE(TranslateManager::IsTranslatableURL( 1473 ASSERT_FALSE(TranslateManager::IsTranslatableURL(
1473 GURL(chrome::kChromeUIHistoryURL))); 1474 GURL(chrome::kChromeUIHistoryURL)));
1474 } 1475 }
1475 1476
1476 // Test is flaky on Win http://crbug.com/166334 1477 // Test is flaky on Win http://crbug.com/166334
1477 #if defined(OS_WIN) 1478 #if defined(OS_WIN)
1478 #define MAYBE_PRE_TranslateSessionRestore DISABLED_PRE_TranslateSessionRestore 1479 #define MAYBE_PRE_TranslateSessionRestore DISABLED_PRE_TranslateSessionRestore
1479 #else 1480 #else
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1515 IN_PROC_BROWSER_TEST_F(InProcessBrowserTest, MAYBE_TranslateSessionRestore) { 1516 IN_PROC_BROWSER_TEST_F(InProcessBrowserTest, MAYBE_TranslateSessionRestore) {
1516 WebContents* current_web_contents = 1517 WebContents* current_web_contents =
1517 browser()->tab_strip_model()->GetActiveWebContents(); 1518 browser()->tab_strip_model()->GetActiveWebContents();
1518 content::Source<WebContents> source(current_web_contents); 1519 content::Source<WebContents> source(current_web_contents);
1519 1520
1520 ui_test_utils::WindowedNotificationObserverWithDetails<std::string> 1521 ui_test_utils::WindowedNotificationObserverWithDetails<std::string>
1521 fr_language_detected_signal(chrome::NOTIFICATION_TAB_LANGUAGE_DETERMINED, 1522 fr_language_detected_signal(chrome::NOTIFICATION_TAB_LANGUAGE_DETERMINED,
1522 source); 1523 source);
1523 fr_language_detected_signal.Wait(); 1524 fr_language_detected_signal.Wait();
1524 } 1525 }
OLDNEW
« no previous file with comments | « chrome/browser/translate/translate_manager.cc ('k') | chrome/browser/translate/translate_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698