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

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

Issue 325483003: Remove unused Views Translate InfoBar code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove test-only infobar toggle; no-op tests for incompatible UX. Created 6 years, 6 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/prefs/pref_change_registrar.h" 10 #include "base/prefs/pref_change_registrar.h"
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 removed_infobars_.insert( 240 removed_infobars_.insert(
241 content::Details<infobars::InfoBar::RemovedDetails>( 241 content::Details<infobars::InfoBar::RemovedDetails>(
242 details)->first->delegate()); 242 details)->first->delegate());
243 } 243 }
244 244
245 MOCK_METHOD1(OnPreferenceChanged, void(const std::string&)); 245 MOCK_METHOD1(OnPreferenceChanged, void(const std::string&));
246 246
247 protected: 247 protected:
248 virtual void SetUp() { 248 virtual void SetUp() {
249 TranslateService::InitializeForTesting(); 249 TranslateService::InitializeForTesting();
250 TranslateService::SetUseInfobar(true);
251 250
252 // Clears the translate script so it is fetched everytime and sets the 251 // Clears the translate script so it is fetched everytime and sets the
253 // expiration delay to a large value by default (in case it was zeroed in a 252 // expiration delay to a large value by default (in case it was zeroed in a
254 // previous test). 253 // previous test).
255 TranslateDownloadManager* download_manager = 254 TranslateDownloadManager* download_manager =
256 TranslateDownloadManager::GetInstance(); 255 TranslateDownloadManager::GetInstance();
257 download_manager->ClearTranslateScriptForTesting(); 256 download_manager->ClearTranslateScriptForTesting();
258 download_manager->SetTranslateScriptExpirationDelay(60 * 60 * 1000); 257 download_manager->SetTranslateScriptExpirationDelay(60 * 60 * 1000);
259 258
260 ChromeRenderViewHostTestHarness::SetUp(); 259 ChromeRenderViewHostTestHarness::SetUp();
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 TranslateBubbleModel* model() { return model_.get(); } 394 TranslateBubbleModel* model() { return model_.get(); }
396 395
397 private: 396 private:
398 scoped_ptr<TranslateBubbleModel> model_; 397 scoped_ptr<TranslateBubbleModel> model_;
399 398
400 DISALLOW_COPY_AND_ASSIGN(MockTranslateBubbleFactory); 399 DISALLOW_COPY_AND_ASSIGN(MockTranslateBubbleFactory);
401 }; 400 };
402 401
403 402
404 TEST_F(TranslateManagerRenderViewHostTest, NormalTranslate) { 403 TEST_F(TranslateManagerRenderViewHostTest, NormalTranslate) {
404 // This test only applies to the infobar translate UX, not the new bubble UX.
405 if (TranslateService::IsTranslateBubbleEnabled())
406 return;
407
405 SimulateNavigation(GURL("http://www.google.fr"), "fr", true); 408 SimulateNavigation(GURL("http://www.google.fr"), "fr", true);
406 409
407 // We should have an infobar. 410 // We should have an infobar.
408 TranslateInfoBarDelegate* infobar = GetTranslateInfoBar(); 411 TranslateInfoBarDelegate* infobar = GetTranslateInfoBar();
409 ASSERT_TRUE(infobar != NULL); 412 ASSERT_TRUE(infobar != NULL);
410 EXPECT_EQ(translate::TRANSLATE_STEP_BEFORE_TRANSLATE, 413 EXPECT_EQ(translate::TRANSLATE_STEP_BEFORE_TRANSLATE,
411 infobar->translate_step()); 414 infobar->translate_step());
412 415
413 // Simulate clicking translate. 416 // Simulate clicking translate.
414 process()->sink().ClearMessages(); 417 process()->sink().ClearMessages();
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
475 infobar->UpdateTargetLanguageIndex(1); 478 infobar->UpdateTargetLanguageIndex(1);
476 infobar->ToggleAlwaysTranslate(); 479 infobar->ToggleAlwaysTranslate();
477 ReloadAndWait(true); 480 ReloadAndWait(true);
478 infobar = GetTranslateInfoBar(); 481 infobar = GetTranslateInfoBar();
479 ASSERT_TRUE(infobar != NULL); 482 ASSERT_TRUE(infobar != NULL);
480 EXPECT_EQ(translate::TRANSLATE_STEP_TRANSLATING, infobar->translate_step()); 483 EXPECT_EQ(translate::TRANSLATE_STEP_TRANSLATING, infobar->translate_step());
481 EXPECT_EQ(new_target_lang, infobar->target_language_code()); 484 EXPECT_EQ(new_target_lang, infobar->target_language_code());
482 } 485 }
483 486
484 TEST_F(TranslateManagerRenderViewHostTest, TranslateScriptNotAvailable) { 487 TEST_F(TranslateManagerRenderViewHostTest, TranslateScriptNotAvailable) {
488 // This test only applies to the infobar translate UX, not the new bubble UX.
489 if (TranslateService::IsTranslateBubbleEnabled())
490 return;
491
485 SimulateNavigation(GURL("http://www.google.fr"), "fr", true); 492 SimulateNavigation(GURL("http://www.google.fr"), "fr", true);
486 493
487 // We should have an infobar. 494 // We should have an infobar.
488 TranslateInfoBarDelegate* infobar = GetTranslateInfoBar(); 495 TranslateInfoBarDelegate* infobar = GetTranslateInfoBar();
489 ASSERT_TRUE(infobar != NULL); 496 ASSERT_TRUE(infobar != NULL);
490 EXPECT_EQ(translate::TRANSLATE_STEP_BEFORE_TRANSLATE, 497 EXPECT_EQ(translate::TRANSLATE_STEP_BEFORE_TRANSLATE,
491 infobar->translate_step()); 498 infobar->translate_step());
492 499
493 // Simulate clicking translate. 500 // Simulate clicking translate.
494 process()->sink().ClearMessages(); 501 process()->sink().ClearMessages();
495 infobar->Translate(); 502 infobar->Translate();
496 SimulateTranslateScriptURLFetch(false); 503 SimulateTranslateScriptURLFetch(false);
497 504
498 // We should not have sent any message to translate to the renderer. 505 // We should not have sent any message to translate to the renderer.
499 EXPECT_FALSE(GetTranslateMessage(NULL, NULL, NULL)); 506 EXPECT_FALSE(GetTranslateMessage(NULL, NULL, NULL));
500 507
501 // And we should have an error infobar showing. 508 // And we should have an error infobar showing.
502 infobar = GetTranslateInfoBar(); 509 infobar = GetTranslateInfoBar();
503 ASSERT_TRUE(infobar != NULL); 510 ASSERT_TRUE(infobar != NULL);
504 EXPECT_EQ(translate::TRANSLATE_STEP_TRANSLATE_ERROR, 511 EXPECT_EQ(translate::TRANSLATE_STEP_TRANSLATE_ERROR,
505 infobar->translate_step()); 512 infobar->translate_step());
506 } 513 }
507 514
508 // Ensures we deal correctly with pages for which the browser does not recognize 515 // Ensures we deal correctly with pages for which the browser does not recognize
509 // the language (the translate server may or not detect the language). 516 // the language (the translate server may or not detect the language).
510 TEST_F(TranslateManagerRenderViewHostTest, TranslateUnknownLanguage) { 517 TEST_F(TranslateManagerRenderViewHostTest, TranslateUnknownLanguage) {
518 // This test only applies to the infobar translate UX, not the new bubble UX.
519 if (TranslateService::IsTranslateBubbleEnabled())
520 return;
521
511 // Simulate navigating to a page ("und" is the string returned by the CLD for 522 // Simulate navigating to a page ("und" is the string returned by the CLD for
512 // languages it does not recognize). 523 // languages it does not recognize).
513 SimulateNavigation(GURL("http://www.google.mys"), "und", true); 524 SimulateNavigation(GURL("http://www.google.mys"), "und", true);
514 525
515 // We should not have an infobar as we don't know the language. 526 // We should not have an infobar as we don't know the language.
516 ASSERT_TRUE(GetTranslateInfoBar() == NULL); 527 ASSERT_TRUE(GetTranslateInfoBar() == NULL);
517 528
518 // Translate the page anyway throught the context menu. 529 // Translate the page anyway throught the context menu.
519 scoped_ptr<TestRenderViewContextMenu> menu(CreateContextMenu()); 530 scoped_ptr<TestRenderViewContextMenu> menu(CreateContextMenu());
520 menu->Init(); 531 menu->Init();
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
566 2, std::string(), "en", TranslateErrors::UNKNOWN_LANGUAGE); 577 2, std::string(), "en", TranslateErrors::UNKNOWN_LANGUAGE);
567 infobar = GetTranslateInfoBar(); 578 infobar = GetTranslateInfoBar();
568 ASSERT_TRUE(infobar != NULL); 579 ASSERT_TRUE(infobar != NULL);
569 EXPECT_EQ(translate::TRANSLATE_STEP_TRANSLATE_ERROR, 580 EXPECT_EQ(translate::TRANSLATE_STEP_TRANSLATE_ERROR,
570 infobar->translate_step()); 581 infobar->translate_step());
571 EXPECT_EQ(TranslateErrors::UNKNOWN_LANGUAGE, infobar->error_type()); 582 EXPECT_EQ(TranslateErrors::UNKNOWN_LANGUAGE, infobar->error_type());
572 } 583 }
573 584
574 // Tests that we show/don't show an info-bar for the languages. 585 // Tests that we show/don't show an info-bar for the languages.
575 TEST_F(TranslateManagerRenderViewHostTest, TestLanguages) { 586 TEST_F(TranslateManagerRenderViewHostTest, TestLanguages) {
587 // This test only applies to the infobar translate UX, not the new bubble UX.
588 if (TranslateService::IsTranslateBubbleEnabled())
589 return;
590
576 std::vector<std::string> languages; 591 std::vector<std::string> languages;
577 languages.push_back("en"); 592 languages.push_back("en");
578 languages.push_back("ja"); 593 languages.push_back("ja");
579 languages.push_back("fr"); 594 languages.push_back("fr");
580 languages.push_back("ht"); 595 languages.push_back("ht");
581 languages.push_back("xx"); 596 languages.push_back("xx");
582 languages.push_back("zh"); 597 languages.push_back("zh");
583 languages.push_back("zh-CN"); 598 languages.push_back("zh-CN");
584 languages.push_back("und"); 599 languages.push_back("und");
585 600
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
703 EXPECT_NE(current_supported_languages.end(), 718 EXPECT_NE(current_supported_languages.end(),
704 std::find(current_supported_languages.begin(), 719 std::find(current_supported_languages.begin(),
705 current_supported_languages.end(), 720 current_supported_languages.end(),
706 lang)); 721 lang));
707 EXPECT_FALSE(TranslateDownloadManager::IsAlphaLanguage(lang)); 722 EXPECT_FALSE(TranslateDownloadManager::IsAlphaLanguage(lang));
708 } 723 }
709 } 724 }
710 725
711 // Tests auto-translate on page. 726 // Tests auto-translate on page.
712 TEST_F(TranslateManagerRenderViewHostTest, AutoTranslateOnNavigate) { 727 TEST_F(TranslateManagerRenderViewHostTest, AutoTranslateOnNavigate) {
728 // This test only applies to the infobar translate UX, not the new bubble UX.
729 if (TranslateService::IsTranslateBubbleEnabled())
730 return;
731
713 SimulateNavigation(GURL("http://www.google.fr"), "fr", true); 732 SimulateNavigation(GURL("http://www.google.fr"), "fr", true);
714 733
715 // Simulate the user translating. 734 // Simulate the user translating.
716 TranslateInfoBarDelegate* infobar = GetTranslateInfoBar(); 735 TranslateInfoBarDelegate* infobar = GetTranslateInfoBar();
717 ASSERT_TRUE(infobar != NULL); 736 ASSERT_TRUE(infobar != NULL);
718 infobar->Translate(); 737 infobar->Translate();
719 // Simulate the translate script being retrieved. 738 // Simulate the translate script being retrieved.
720 SimulateTranslateScriptURLFetch(true); 739 SimulateTranslateScriptURLFetch(true);
721 SimulateOnPageTranslated("fr", "en"); 740 SimulateOnPageTranslated("fr", "en");
722 741
(...skipping 12 matching lines...) Expand all
735 // Now navigate to a page in a different language. 754 // Now navigate to a page in a different language.
736 process()->sink().ClearMessages(); 755 process()->sink().ClearMessages();
737 SimulateNavigation(GURL("http://news.google.es"), "es", true); 756 SimulateNavigation(GURL("http://news.google.es"), "es", true);
738 757
739 // This should not have triggered a translate. 758 // This should not have triggered a translate.
740 EXPECT_FALSE(GetTranslateMessage(&page_id, &original_lang, &target_lang)); 759 EXPECT_FALSE(GetTranslateMessage(&page_id, &original_lang, &target_lang));
741 } 760 }
742 761
743 // Tests that multiple OnPageContents do not cause multiple infobars. 762 // Tests that multiple OnPageContents do not cause multiple infobars.
744 TEST_F(TranslateManagerRenderViewHostTest, MultipleOnPageContents) { 763 TEST_F(TranslateManagerRenderViewHostTest, MultipleOnPageContents) {
764 // This test only applies to the infobar translate UX, not the new bubble UX.
765 if (TranslateService::IsTranslateBubbleEnabled())
766 return;
767
745 SimulateNavigation(GURL("http://www.google.fr"), "fr", true); 768 SimulateNavigation(GURL("http://www.google.fr"), "fr", true);
746 769
747 // Simulate clicking 'Nope' (don't translate). 770 // Simulate clicking 'Nope' (don't translate).
748 EXPECT_TRUE(DenyTranslation()); 771 EXPECT_TRUE(DenyTranslation());
749 EXPECT_EQ(0U, infobar_service()->infobar_count()); 772 EXPECT_EQ(0U, infobar_service()->infobar_count());
750 773
751 // Send a new PageContents, we should not show an infobar. 774 // Send a new PageContents, we should not show an infobar.
752 SimulateOnTranslateLanguageDetermined("fr", true); 775 SimulateOnTranslateLanguageDetermined("fr", true);
753 EXPECT_EQ(0U, infobar_service()->infobar_count()); 776 EXPECT_EQ(0U, infobar_service()->infobar_count());
754 777
755 // Do the same steps but simulate closing the infobar this time. 778 // Do the same steps but simulate closing the infobar this time.
756 SimulateNavigation(GURL("http://www.youtube.fr"), "fr", true); 779 SimulateNavigation(GURL("http://www.youtube.fr"), "fr", true);
757 EXPECT_TRUE(CloseTranslateInfoBar()); 780 EXPECT_TRUE(CloseTranslateInfoBar());
758 EXPECT_EQ(0U, infobar_service()->infobar_count()); 781 EXPECT_EQ(0U, infobar_service()->infobar_count());
759 SimulateOnTranslateLanguageDetermined("fr", true); 782 SimulateOnTranslateLanguageDetermined("fr", true);
760 EXPECT_EQ(0U, infobar_service()->infobar_count()); 783 EXPECT_EQ(0U, infobar_service()->infobar_count());
761 } 784 }
762 785
763 // Test that reloading the page brings back the infobar if the 786 // Test that reloading the page brings back the infobar if the
764 // reload succeeded and does not bring it back the reload fails. 787 // reload succeeded and does not bring it back the reload fails.
765 TEST_F(TranslateManagerRenderViewHostTest, Reload) { 788 TEST_F(TranslateManagerRenderViewHostTest, Reload) {
789 // This test only applies to the infobar translate UX, not the new bubble UX.
790 if (TranslateService::IsTranslateBubbleEnabled())
791 return;
792
766 SimulateNavigation(GURL("http://www.google.fr"), "fr", true); 793 SimulateNavigation(GURL("http://www.google.fr"), "fr", true);
767 794
768 EXPECT_TRUE(CloseTranslateInfoBar()); 795 EXPECT_TRUE(CloseTranslateInfoBar());
769 796
770 // Reload should bring back the infobar if the reload succeeds. 797 // Reload should bring back the infobar if the reload succeeds.
771 ReloadAndWait(true); 798 ReloadAndWait(true);
772 EXPECT_TRUE(GetTranslateInfoBar() != NULL); 799 EXPECT_TRUE(GetTranslateInfoBar() != NULL);
773 EXPECT_TRUE(CloseTranslateInfoBar()); 800 EXPECT_TRUE(CloseTranslateInfoBar());
774 801
775 // ...But not show it if the reload fails. 802 // ...But not show it if the reload fails.
776 ReloadAndWait(false); 803 ReloadAndWait(false);
777 EXPECT_TRUE(GetTranslateInfoBar() == NULL); 804 EXPECT_TRUE(GetTranslateInfoBar() == NULL);
778 805
779 // If we set reload attempts to a high value, we will not see the infobar 806 // If we set reload attempts to a high value, we will not see the infobar
780 // immediately. 807 // immediately.
781 ChromeTranslateClient::FromWebContents(web_contents()) 808 ChromeTranslateClient::FromWebContents(web_contents())
782 ->set_translate_max_reload_attempts(100); 809 ->set_translate_max_reload_attempts(100);
783 ReloadAndWait(true); 810 ReloadAndWait(true);
784 EXPECT_TRUE(GetTranslateInfoBar() == NULL); 811 EXPECT_TRUE(GetTranslateInfoBar() == NULL);
785 } 812 }
786 813
787 // Test that reloading the page by way of typing again the URL in the 814 // Test that reloading the page by way of typing again the URL in the
788 // location bar brings back the infobar. 815 // location bar brings back the infobar.
789 TEST_F(TranslateManagerRenderViewHostTest, ReloadFromLocationBar) { 816 TEST_F(TranslateManagerRenderViewHostTest, ReloadFromLocationBar) {
817 // This test only applies to the infobar translate UX, not the new bubble UX.
818 if (TranslateService::IsTranslateBubbleEnabled())
819 return;
820
790 GURL url("http://www.google.fr"); 821 GURL url("http://www.google.fr");
791 SimulateNavigation(url, "fr", true); 822 SimulateNavigation(url, "fr", true);
792 823
793 EXPECT_TRUE(CloseTranslateInfoBar()); 824 EXPECT_TRUE(CloseTranslateInfoBar());
794 825
795 // Create a pending navigation and simulate a page load. That should be the 826 // Create a pending navigation and simulate a page load. That should be the
796 // equivalent of typing the URL again in the location bar. 827 // equivalent of typing the URL again in the location bar.
797 NavEntryCommittedObserver nav_observer(web_contents()); 828 NavEntryCommittedObserver nav_observer(web_contents());
798 web_contents()->GetController().LoadURL( 829 web_contents()->GetController().LoadURL(
799 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); 830 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string());
800 rvh_tester()->SendNavigateWithTransition( 831 rvh_tester()->SendNavigateWithTransition(
801 0, url, content::PAGE_TRANSITION_TYPED); 832 0, url, content::PAGE_TRANSITION_TYPED);
802 833
803 // Test that we are really getting a same page navigation, the test would be 834 // Test that we are really getting a same page navigation, the test would be
804 // useless if it was not the case. 835 // useless if it was not the case.
805 const content::LoadCommittedDetails& nav_details = 836 const content::LoadCommittedDetails& nav_details =
806 nav_observer.load_committed_details(); 837 nav_observer.load_committed_details();
807 EXPECT_TRUE(nav_details.entry != NULL); // There was a navigation. 838 EXPECT_TRUE(nav_details.entry != NULL); // There was a navigation.
808 EXPECT_EQ(content::NAVIGATION_TYPE_SAME_PAGE, nav_details.type); 839 EXPECT_EQ(content::NAVIGATION_TYPE_SAME_PAGE, nav_details.type);
809 840
810 // The TranslateManager class processes the navigation entry committed 841 // The TranslateManager class processes the navigation entry committed
811 // notification in a posted task; process that task. 842 // notification in a posted task; process that task.
812 base::MessageLoop::current()->RunUntilIdle(); 843 base::MessageLoop::current()->RunUntilIdle();
813 EXPECT_TRUE(GetTranslateInfoBar() != NULL); 844 EXPECT_TRUE(GetTranslateInfoBar() != NULL);
814 } 845 }
815 846
816 // Tests that a closed translate infobar does not reappear when navigating 847 // Tests that a closed translate infobar does not reappear when navigating
817 // in-page. 848 // in-page.
818 TEST_F(TranslateManagerRenderViewHostTest, CloseInfoBarInPageNavigation) { 849 TEST_F(TranslateManagerRenderViewHostTest, CloseInfoBarInPageNavigation) {
850 // This test only applies to the infobar translate UX, not the new bubble UX.
851 if (TranslateService::IsTranslateBubbleEnabled())
852 return;
853
819 SimulateNavigation(GURL("http://www.google.fr"), "fr", true); 854 SimulateNavigation(GURL("http://www.google.fr"), "fr", true);
820 855
821 EXPECT_TRUE(CloseTranslateInfoBar()); 856 EXPECT_TRUE(CloseTranslateInfoBar());
822 857
823 // Navigate in page, no infobar should be shown. 858 // Navigate in page, no infobar should be shown.
824 SimulateNavigation(GURL("http://www.google.fr/#ref1"), "fr", true); 859 SimulateNavigation(GURL("http://www.google.fr/#ref1"), "fr", true);
825 EXPECT_TRUE(GetTranslateInfoBar() == NULL); 860 EXPECT_TRUE(GetTranslateInfoBar() == NULL);
826 861
827 // Navigate out of page, a new infobar should show. 862 // Navigate out of page, a new infobar should show.
828 SimulateNavigation(GURL("http://www.google.fr/foot"), "fr", true); 863 SimulateNavigation(GURL("http://www.google.fr/foot"), "fr", true);
829 EXPECT_TRUE(GetTranslateInfoBar() != NULL); 864 EXPECT_TRUE(GetTranslateInfoBar() != NULL);
830 } 865 }
831 866
832 // Tests that a closed translate infobar does not reappear when navigating 867 // Tests that a closed translate infobar does not reappear when navigating
833 // in a subframe. (http://crbug.com/48215) 868 // in a subframe. (http://crbug.com/48215)
834 TEST_F(TranslateManagerRenderViewHostTest, CloseInfoBarInSubframeNavigation) { 869 TEST_F(TranslateManagerRenderViewHostTest, CloseInfoBarInSubframeNavigation) {
870 // This test only applies to the infobar translate UX, not the new bubble UX.
871 if (TranslateService::IsTranslateBubbleEnabled())
872 return;
873
835 SimulateNavigation(GURL("http://www.google.fr"), "fr", true); 874 SimulateNavigation(GURL("http://www.google.fr"), "fr", true);
836 875
837 EXPECT_TRUE(CloseTranslateInfoBar()); 876 EXPECT_TRUE(CloseTranslateInfoBar());
838 877
839 // Simulate a sub-frame auto-navigating. 878 // Simulate a sub-frame auto-navigating.
840 rvh_tester()->SendNavigateWithTransition( 879 rvh_tester()->SendNavigateWithTransition(
841 1, GURL("http://pub.com"), content::PAGE_TRANSITION_AUTO_SUBFRAME); 880 1, GURL("http://pub.com"), content::PAGE_TRANSITION_AUTO_SUBFRAME);
842 EXPECT_TRUE(GetTranslateInfoBar() == NULL); 881 EXPECT_TRUE(GetTranslateInfoBar() == NULL);
843 882
844 // Simulate the user navigating in a sub-frame. 883 // Simulate the user navigating in a sub-frame.
845 rvh_tester()->SendNavigateWithTransition( 884 rvh_tester()->SendNavigateWithTransition(
846 2, GURL("http://pub.com"), content::PAGE_TRANSITION_MANUAL_SUBFRAME); 885 2, GURL("http://pub.com"), content::PAGE_TRANSITION_MANUAL_SUBFRAME);
847 EXPECT_TRUE(GetTranslateInfoBar() == NULL); 886 EXPECT_TRUE(GetTranslateInfoBar() == NULL);
848 887
849 // Navigate out of page, a new infobar should show. 888 // Navigate out of page, a new infobar should show.
850 SimulateNavigation(GURL("http://www.google.fr/foot"), "fr", true); 889 SimulateNavigation(GURL("http://www.google.fr/foot"), "fr", true);
851 EXPECT_TRUE(GetTranslateInfoBar() != NULL); 890 EXPECT_TRUE(GetTranslateInfoBar() != NULL);
852 } 891 }
853 892
854 // Tests that denying translation is sticky when navigating in page. 893 // Tests that denying translation is sticky when navigating in page.
855 TEST_F(TranslateManagerRenderViewHostTest, DenyTranslateInPageNavigation) { 894 TEST_F(TranslateManagerRenderViewHostTest, DenyTranslateInPageNavigation) {
895 // This test only applies to the infobar translate UX, not the new bubble UX.
896 if (TranslateService::IsTranslateBubbleEnabled())
897 return;
898
856 SimulateNavigation(GURL("http://www.google.fr"), "fr", true); 899 SimulateNavigation(GURL("http://www.google.fr"), "fr", true);
857 900
858 // Simulate clicking 'Nope' (don't translate). 901 // Simulate clicking 'Nope' (don't translate).
859 EXPECT_TRUE(DenyTranslation()); 902 EXPECT_TRUE(DenyTranslation());
860 903
861 // Navigate in page, no infobar should be shown. 904 // Navigate in page, no infobar should be shown.
862 SimulateNavigation(GURL("http://www.google.fr/#ref1"), "fr", true); 905 SimulateNavigation(GURL("http://www.google.fr/#ref1"), "fr", true);
863 EXPECT_TRUE(GetTranslateInfoBar() == NULL); 906 EXPECT_TRUE(GetTranslateInfoBar() == NULL);
864 907
865 // Navigate out of page, a new infobar should show. 908 // Navigate out of page, a new infobar should show.
866 SimulateNavigation(GURL("http://www.google.fr/foot"), "fr", true); 909 SimulateNavigation(GURL("http://www.google.fr/foot"), "fr", true);
867 EXPECT_TRUE(GetTranslateInfoBar() != NULL); 910 EXPECT_TRUE(GetTranslateInfoBar() != NULL);
868 } 911 }
869 912
870 // Tests that after translating and closing the infobar, the infobar does not 913 // Tests that after translating and closing the infobar, the infobar does not
871 // return when navigating in page. 914 // return when navigating in page.
872 TEST_F(TranslateManagerRenderViewHostTest, 915 TEST_F(TranslateManagerRenderViewHostTest,
873 TranslateCloseInfoBarInPageNavigation) { 916 TranslateCloseInfoBarInPageNavigation) {
917 // This test only applies to the infobar translate UX, not the new bubble UX.
918 if (TranslateService::IsTranslateBubbleEnabled())
919 return;
920
874 SimulateNavigation(GURL("http://www.google.fr"), "fr", true); 921 SimulateNavigation(GURL("http://www.google.fr"), "fr", true);
875 922
876 // Simulate the user translating. 923 // Simulate the user translating.
877 TranslateInfoBarDelegate* infobar = GetTranslateInfoBar(); 924 TranslateInfoBarDelegate* infobar = GetTranslateInfoBar();
878 ASSERT_TRUE(infobar != NULL); 925 ASSERT_TRUE(infobar != NULL);
879 infobar->Translate(); 926 infobar->Translate();
880 // Simulate the translate script being retrieved. 927 // Simulate the translate script being retrieved.
881 SimulateTranslateScriptURLFetch(true); 928 SimulateTranslateScriptURLFetch(true);
882 SimulateOnPageTranslated("fr", "en"); 929 SimulateOnPageTranslated("fr", "en");
883 930
884 EXPECT_TRUE(CloseTranslateInfoBar()); 931 EXPECT_TRUE(CloseTranslateInfoBar());
885 932
886 // Navigate in page, no infobar should be shown. 933 // Navigate in page, no infobar should be shown.
887 SimulateNavigation(GURL("http://www.google.fr/#ref1"), "fr", true); 934 SimulateNavigation(GURL("http://www.google.fr/#ref1"), "fr", true);
888 EXPECT_TRUE(GetTranslateInfoBar() == NULL); 935 EXPECT_TRUE(GetTranslateInfoBar() == NULL);
889 936
890 // Navigate out of page, a new infobar should show. 937 // Navigate out of page, a new infobar should show.
891 // Note that we navigate to a page in a different language so we don't trigger 938 // Note that we navigate to a page in a different language so we don't trigger
892 // the auto-translate feature (it would translate the page automatically and 939 // the auto-translate feature (it would translate the page automatically and
893 // the before translate inforbar would not be shown). 940 // the before translate inforbar would not be shown).
894 SimulateNavigation(GURL("http://www.google.de"), "de", true); 941 SimulateNavigation(GURL("http://www.google.de"), "de", true);
895 EXPECT_TRUE(GetTranslateInfoBar() != NULL); 942 EXPECT_TRUE(GetTranslateInfoBar() != NULL);
896 } 943 }
897 944
898 // Tests that the after translate the infobar still shows when navigating 945 // Tests that the after translate the infobar still shows when navigating
899 // in-page. 946 // in-page.
900 TEST_F(TranslateManagerRenderViewHostTest, TranslateInPageNavigation) { 947 TEST_F(TranslateManagerRenderViewHostTest, TranslateInPageNavigation) {
948 // This test only applies to the infobar translate UX, not the new bubble UX.
949 if (TranslateService::IsTranslateBubbleEnabled())
950 return;
951
901 SimulateNavigation(GURL("http://www.google.fr"), "fr", true); 952 SimulateNavigation(GURL("http://www.google.fr"), "fr", true);
902 953
903 // Simulate the user translating. 954 // Simulate the user translating.
904 TranslateInfoBarDelegate* infobar = GetTranslateInfoBar(); 955 TranslateInfoBarDelegate* infobar = GetTranslateInfoBar();
905 ASSERT_TRUE(infobar != NULL); 956 ASSERT_TRUE(infobar != NULL);
906 infobar->Translate(); 957 infobar->Translate();
907 SimulateTranslateScriptURLFetch(true); 958 SimulateTranslateScriptURLFetch(true);
908 SimulateOnPageTranslated("fr", "en"); 959 SimulateOnPageTranslated("fr", "en");
909 // The after translate infobar is showing. 960 // The after translate infobar is showing.
910 infobar = GetTranslateInfoBar(); 961 infobar = GetTranslateInfoBar();
911 ASSERT_TRUE(infobar != NULL); 962 ASSERT_TRUE(infobar != NULL);
912 963
913 // Navigate out of page, a new infobar should show. 964 // Navigate out of page, a new infobar should show.
914 // See note in TranslateCloseInfoBarInPageNavigation test on why it is 965 // See note in TranslateCloseInfoBarInPageNavigation test on why it is
915 // important to navigate to a page in a different language for this test. 966 // important to navigate to a page in a different language for this test.
916 SimulateNavigation(GURL("http://www.google.de"), "de", true); 967 SimulateNavigation(GURL("http://www.google.de"), "de", true);
917 // The old infobar is gone. 968 // The old infobar is gone.
918 EXPECT_TRUE(CheckInfoBarRemovedAndReset(infobar)); 969 EXPECT_TRUE(CheckInfoBarRemovedAndReset(infobar));
919 // And there is a new one. 970 // And there is a new one.
920 EXPECT_TRUE(GetTranslateInfoBar() != NULL); 971 EXPECT_TRUE(GetTranslateInfoBar() != NULL);
921 } 972 }
922 973
923 // Tests that no translate infobar is shown when navigating to a page in an 974 // Tests that no translate infobar is shown when navigating to a page in an
924 // unsupported language. 975 // unsupported language.
925 TEST_F(TranslateManagerRenderViewHostTest, CLDReportsUnsupportedPageLanguage) { 976 TEST_F(TranslateManagerRenderViewHostTest, CLDReportsUnsupportedPageLanguage) {
977 // This test only applies to the infobar translate UX, not the new bubble UX.
978 if (TranslateService::IsTranslateBubbleEnabled())
979 return;
980
926 // Simulate navigating to a page and getting an unsupported language. 981 // Simulate navigating to a page and getting an unsupported language.
927 SimulateNavigation(GURL("http://www.google.com"), "qbz", true); 982 SimulateNavigation(GURL("http://www.google.com"), "qbz", true);
928 983
929 // No info-bar should be shown. 984 // No info-bar should be shown.
930 EXPECT_TRUE(GetTranslateInfoBar() == NULL); 985 EXPECT_TRUE(GetTranslateInfoBar() == NULL);
931 } 986 }
932 987
933 // Tests that we deal correctly with unsupported languages returned by the 988 // Tests that we deal correctly with unsupported languages returned by the
934 // server. 989 // server.
935 // The translation server might return a language we don't support. 990 // The translation server might return a language we don't support.
936 TEST_F(TranslateManagerRenderViewHostTest, ServerReportsUnsupportedLanguage) { 991 TEST_F(TranslateManagerRenderViewHostTest, ServerReportsUnsupportedLanguage) {
992 // This test only applies to the infobar translate UX, not the new bubble UX.
993 if (TranslateService::IsTranslateBubbleEnabled())
994 return;
995
937 SimulateNavigation(GURL("http://mail.google.fr"), "fr", true); 996 SimulateNavigation(GURL("http://mail.google.fr"), "fr", true);
938 TranslateInfoBarDelegate* infobar = GetTranslateInfoBar(); 997 TranslateInfoBarDelegate* infobar = GetTranslateInfoBar();
939 ASSERT_TRUE(infobar != NULL); 998 ASSERT_TRUE(infobar != NULL);
940 process()->sink().ClearMessages(); 999 process()->sink().ClearMessages();
941 infobar->Translate(); 1000 infobar->Translate();
942 SimulateTranslateScriptURLFetch(true); 1001 SimulateTranslateScriptURLFetch(true);
943 // Simulate the render notifying the translation has been done, but it 1002 // Simulate the render notifying the translation has been done, but it
944 // reports a language we don't support. 1003 // reports a language we don't support.
945 SimulateOnPageTranslated("qbz", "en"); 1004 SimulateOnPageTranslated("qbz", "en");
946 1005
(...skipping 13 matching lines...) Expand all
960 const IPC::Message* message = process()->sink().GetFirstMessageMatching( 1019 const IPC::Message* message = process()->sink().GetFirstMessageMatching(
961 ChromeViewMsg_RevertTranslation::ID); 1020 ChromeViewMsg_RevertTranslation::ID);
962 EXPECT_TRUE(message != NULL); 1021 EXPECT_TRUE(message != NULL);
963 // And it should have removed the infobar. 1022 // And it should have removed the infobar.
964 EXPECT_TRUE(GetTranslateInfoBar() == NULL); 1023 EXPECT_TRUE(GetTranslateInfoBar() == NULL);
965 } 1024 }
966 1025
967 // Tests that no translate infobar is shown and context menu is disabled, when 1026 // Tests that no translate infobar is shown and context menu is disabled, when
968 // Chrome is in a language that the translate server does not support. 1027 // Chrome is in a language that the translate server does not support.
969 TEST_F(TranslateManagerRenderViewHostTest, UnsupportedUILanguage) { 1028 TEST_F(TranslateManagerRenderViewHostTest, UnsupportedUILanguage) {
1029 // This test only applies to the infobar translate UX, not the new bubble UX.
1030 if (TranslateService::IsTranslateBubbleEnabled())
1031 return;
1032
970 std::string original_lang = g_browser_process->GetApplicationLocale(); 1033 std::string original_lang = g_browser_process->GetApplicationLocale();
971 SetApplicationLocale("qbz"); 1034 SetApplicationLocale("qbz");
972 1035
973 // Make sure that the accept language list only contains unsupported languages 1036 // Make sure that the accept language list only contains unsupported languages
974 Profile* profile = 1037 Profile* profile =
975 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); 1038 Profile::FromBrowserContext(web_contents()->GetBrowserContext());
976 PrefService* prefs = profile->GetPrefs(); 1039 PrefService* prefs = profile->GetPrefs();
977 prefs->SetString(prefs::kAcceptLanguages, "qbz"); 1040 prefs->SetString(prefs::kAcceptLanguages, "qbz");
978 1041
979 // Simulate navigating to a page in a language supported by the translate 1042 // Simulate navigating to a page in a language supported by the translate
980 // server. 1043 // server.
981 SimulateNavigation(GURL("http://www.google.com"), "en", true); 1044 SimulateNavigation(GURL("http://www.google.com"), "en", true);
982 1045
983 // No info-bar should be shown. 1046 // No info-bar should be shown.
984 EXPECT_TRUE(GetTranslateInfoBar() == NULL); 1047 EXPECT_TRUE(GetTranslateInfoBar() == NULL);
985 1048
986 // And the context menu option should be disabled too. 1049 // And the context menu option should be disabled too.
987 scoped_ptr<TestRenderViewContextMenu> menu(CreateContextMenu()); 1050 scoped_ptr<TestRenderViewContextMenu> menu(CreateContextMenu());
988 menu->Init(); 1051 menu->Init();
989 EXPECT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_TRANSLATE)); 1052 EXPECT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_TRANSLATE));
990 EXPECT_FALSE(menu->IsCommandIdEnabled(IDC_CONTENT_CONTEXT_TRANSLATE)); 1053 EXPECT_FALSE(menu->IsCommandIdEnabled(IDC_CONTENT_CONTEXT_TRANSLATE));
991 1054
992 SetApplicationLocale(original_lang); 1055 SetApplicationLocale(original_lang);
993 } 1056 }
994 1057
995 // Tests that the first supported accept language is selected 1058 // Tests that the first supported accept language is selected
996 TEST_F(TranslateManagerRenderViewHostTest, TranslateAcceptLanguage) { 1059 TEST_F(TranslateManagerRenderViewHostTest, TranslateAcceptLanguage) {
1060 // This test only applies to the infobar translate UX, not the new bubble UX.
1061 if (TranslateService::IsTranslateBubbleEnabled())
1062 return;
1063
997 // Set locate to non-existant language 1064 // Set locate to non-existant language
998 std::string original_lang = g_browser_process->GetApplicationLocale(); 1065 std::string original_lang = g_browser_process->GetApplicationLocale();
999 SetApplicationLocale("qbz"); 1066 SetApplicationLocale("qbz");
1000 1067
1001 // Set Qbz and French as the only accepted languages 1068 // Set Qbz and French as the only accepted languages
1002 Profile* profile = 1069 Profile* profile =
1003 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); 1070 Profile::FromBrowserContext(web_contents()->GetBrowserContext());
1004 PrefService* prefs = profile->GetPrefs(); 1071 PrefService* prefs = profile->GetPrefs();
1005 prefs->SetString(prefs::kAcceptLanguages, "qbz,fr"); 1072 prefs->SetString(prefs::kAcceptLanguages, "qbz,fr");
1006 1073
(...skipping 10 matching lines...) Expand all
1017 1084
1018 // Go to a German page 1085 // Go to a German page
1019 SimulateNavigation(GURL("http://google.de"), "de", true); 1086 SimulateNavigation(GURL("http://google.de"), "de", true);
1020 1087
1021 // Expect the infobar to pop up 1088 // Expect the infobar to pop up
1022 EXPECT_TRUE(GetTranslateInfoBar() != NULL); 1089 EXPECT_TRUE(GetTranslateInfoBar() != NULL);
1023 } 1090 }
1024 1091
1025 // Tests that the translate enabled preference is honored. 1092 // Tests that the translate enabled preference is honored.
1026 TEST_F(TranslateManagerRenderViewHostTest, TranslateEnabledPref) { 1093 TEST_F(TranslateManagerRenderViewHostTest, TranslateEnabledPref) {
1094 // This test only applies to the infobar translate UX, not the new bubble UX.
1095 if (TranslateService::IsTranslateBubbleEnabled())
1096 return;
1097
1027 // Make sure the pref allows translate. 1098 // Make sure the pref allows translate.
1028 Profile* profile = 1099 Profile* profile =
1029 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); 1100 Profile::FromBrowserContext(web_contents()->GetBrowserContext());
1030 PrefService* prefs = profile->GetPrefs(); 1101 PrefService* prefs = profile->GetPrefs();
1031 prefs->SetBoolean(prefs::kEnableTranslate, true); 1102 prefs->SetBoolean(prefs::kEnableTranslate, true);
1032 1103
1033 SimulateNavigation(GURL("http://www.google.fr"), "fr", true); 1104 SimulateNavigation(GURL("http://www.google.fr"), "fr", true);
1034 1105
1035 // An infobar should be shown. 1106 // An infobar should be shown.
1036 TranslateInfoBarDelegate* infobar = GetTranslateInfoBar(); 1107 TranslateInfoBarDelegate* infobar = GetTranslateInfoBar();
(...skipping 10 matching lines...) Expand all
1047 1118
1048 // Simulate getting the page contents and language, that should not trigger 1119 // Simulate getting the page contents and language, that should not trigger
1049 // a translate infobar. 1120 // a translate infobar.
1050 SimulateOnTranslateLanguageDetermined("fr", true); 1121 SimulateOnTranslateLanguageDetermined("fr", true);
1051 infobar = GetTranslateInfoBar(); 1122 infobar = GetTranslateInfoBar();
1052 EXPECT_TRUE(infobar == NULL); 1123 EXPECT_TRUE(infobar == NULL);
1053 } 1124 }
1054 1125
1055 // Tests the "Never translate <language>" pref. 1126 // Tests the "Never translate <language>" pref.
1056 TEST_F(TranslateManagerRenderViewHostTest, NeverTranslateLanguagePref) { 1127 TEST_F(TranslateManagerRenderViewHostTest, NeverTranslateLanguagePref) {
1128 // This test only applies to the infobar translate UX, not the new bubble UX.
1129 if (TranslateService::IsTranslateBubbleEnabled())
1130 return;
1131
1057 GURL url("http://www.google.fr"); 1132 GURL url("http://www.google.fr");
1058 SimulateNavigation(url, "fr", true); 1133 SimulateNavigation(url, "fr", true);
1059 1134
1060 // An infobar should be shown. 1135 // An infobar should be shown.
1061 EXPECT_TRUE(GetTranslateInfoBar() != NULL); 1136 EXPECT_TRUE(GetTranslateInfoBar() != NULL);
1062 1137
1063 // Select never translate this language. 1138 // Select never translate this language.
1064 Profile* profile = 1139 Profile* profile =
1065 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); 1140 Profile::FromBrowserContext(web_contents()->GetBrowserContext());
1066 PrefService* prefs = profile->GetPrefs(); 1141 PrefService* prefs = profile->GetPrefs();
(...skipping 29 matching lines...) Expand all
1096 1171
1097 // Navigate to a page in French. 1172 // Navigate to a page in French.
1098 SimulateNavigation(url, "fr", true); 1173 SimulateNavigation(url, "fr", true);
1099 1174
1100 // There should be a translate infobar. 1175 // There should be a translate infobar.
1101 EXPECT_TRUE(GetTranslateInfoBar() != NULL); 1176 EXPECT_TRUE(GetTranslateInfoBar() != NULL);
1102 } 1177 }
1103 1178
1104 // Tests the "Never translate this site" pref. 1179 // Tests the "Never translate this site" pref.
1105 TEST_F(TranslateManagerRenderViewHostTest, NeverTranslateSitePref) { 1180 TEST_F(TranslateManagerRenderViewHostTest, NeverTranslateSitePref) {
1181 // This test only applies to the infobar translate UX, not the new bubble UX.
1182 if (TranslateService::IsTranslateBubbleEnabled())
1183 return;
1184
1106 GURL url("http://www.google.fr"); 1185 GURL url("http://www.google.fr");
1107 std::string host(url.host()); 1186 std::string host(url.host());
1108 SimulateNavigation(url, "fr", true); 1187 SimulateNavigation(url, "fr", true);
1109 1188
1110 // An infobar should be shown. 1189 // An infobar should be shown.
1111 EXPECT_TRUE(GetTranslateInfoBar() != NULL); 1190 EXPECT_TRUE(GetTranslateInfoBar() != NULL);
1112 1191
1113 // Select never translate this site. 1192 // Select never translate this site.
1114 Profile* profile = 1193 Profile* profile =
1115 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); 1194 Profile::FromBrowserContext(web_contents()->GetBrowserContext());
(...skipping 28 matching lines...) Expand all
1144 1223
1145 // Navigate to a page in French. 1224 // Navigate to a page in French.
1146 SimulateNavigation(url, "fr", true); 1225 SimulateNavigation(url, "fr", true);
1147 1226
1148 // There should be a translate infobar. 1227 // There should be a translate infobar.
1149 EXPECT_TRUE(GetTranslateInfoBar() != NULL); 1228 EXPECT_TRUE(GetTranslateInfoBar() != NULL);
1150 } 1229 }
1151 1230
1152 // Tests the "Always translate this language" pref. 1231 // Tests the "Always translate this language" pref.
1153 TEST_F(TranslateManagerRenderViewHostTest, AlwaysTranslateLanguagePref) { 1232 TEST_F(TranslateManagerRenderViewHostTest, AlwaysTranslateLanguagePref) {
1233 // This test only applies to the infobar translate UX, not the new bubble UX.
1234 if (TranslateService::IsTranslateBubbleEnabled())
1235 return;
1236
1154 // Select always translate French to English. 1237 // Select always translate French to English.
1155 Profile* profile = 1238 Profile* profile =
1156 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); 1239 Profile::FromBrowserContext(web_contents()->GetBrowserContext());
1157 PrefService* prefs = profile->GetPrefs(); 1240 PrefService* prefs = profile->GetPrefs();
1158 PrefChangeRegistrar registrar; 1241 PrefChangeRegistrar registrar;
1159 registrar.Init(prefs); 1242 registrar.Init(prefs);
1160 registrar.Add(TranslatePrefs::kPrefTranslateWhitelists, pref_callback_); 1243 registrar.Add(TranslatePrefs::kPrefTranslateWhitelists, pref_callback_);
1161 scoped_ptr<TranslatePrefs> translate_prefs( 1244 scoped_ptr<TranslatePrefs> translate_prefs(
1162 ChromeTranslateClient::CreateTranslatePrefs(prefs)); 1245 ChromeTranslateClient::CreateTranslatePrefs(prefs));
1163 SetPrefObserverExpectation(TranslatePrefs::kPrefTranslateWhitelists); 1246 SetPrefObserverExpectation(TranslatePrefs::kPrefTranslateWhitelists);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1204 SimulateNavigation(GURL("http://www.google.fr"), "fr", true); 1287 SimulateNavigation(GURL("http://www.google.fr"), "fr", true);
1205 EXPECT_FALSE(GetTranslateMessage(&page_id, &original_lang, &target_lang)); 1288 EXPECT_FALSE(GetTranslateMessage(&page_id, &original_lang, &target_lang));
1206 infobar = GetTranslateInfoBar(); 1289 infobar = GetTranslateInfoBar();
1207 ASSERT_TRUE(infobar != NULL); 1290 ASSERT_TRUE(infobar != NULL);
1208 EXPECT_EQ(translate::TRANSLATE_STEP_BEFORE_TRANSLATE, 1291 EXPECT_EQ(translate::TRANSLATE_STEP_BEFORE_TRANSLATE,
1209 infobar->translate_step()); 1292 infobar->translate_step());
1210 } 1293 }
1211 1294
1212 // Context menu. 1295 // Context menu.
1213 TEST_F(TranslateManagerRenderViewHostTest, ContextMenu) { 1296 TEST_F(TranslateManagerRenderViewHostTest, ContextMenu) {
1297 // This test only applies to the infobar translate UX, not the new bubble UX.
1298 if (TranslateService::IsTranslateBubbleEnabled())
1299 return;
1300
1214 // Blacklist www.google.fr and French for translation. 1301 // Blacklist www.google.fr and French for translation.
1215 GURL url("http://www.google.fr"); 1302 GURL url("http://www.google.fr");
1216 Profile* profile = 1303 Profile* profile =
1217 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); 1304 Profile::FromBrowserContext(web_contents()->GetBrowserContext());
1218 scoped_ptr<TranslatePrefs> translate_prefs( 1305 scoped_ptr<TranslatePrefs> translate_prefs(
1219 ChromeTranslateClient::CreateTranslatePrefs(profile->GetPrefs())); 1306 ChromeTranslateClient::CreateTranslatePrefs(profile->GetPrefs()));
1220 translate_prefs->BlockLanguage("fr"); 1307 translate_prefs->BlockLanguage("fr");
1221 translate_prefs->BlacklistSite(url.host()); 1308 translate_prefs->BlacklistSite(url.host());
1222 EXPECT_TRUE(translate_prefs->IsBlockedLanguage("fr")); 1309 EXPECT_TRUE(translate_prefs->IsBlockedLanguage("fr"));
1223 EXPECT_TRUE(translate_prefs->IsSiteBlacklisted(url.host())); 1310 EXPECT_TRUE(translate_prefs->IsSiteBlacklisted(url.host()));
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
1312 menu.reset(CreateContextMenu()); 1399 menu.reset(CreateContextMenu());
1313 menu->Init(); 1400 menu->Init();
1314 EXPECT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_TRANSLATE)); 1401 EXPECT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_TRANSLATE));
1315 EXPECT_TRUE(menu->IsCommandIdEnabled(IDC_CONTENT_CONTEXT_TRANSLATE)); 1402 EXPECT_TRUE(menu->IsCommandIdEnabled(IDC_CONTENT_CONTEXT_TRANSLATE));
1316 } 1403 }
1317 1404
1318 // Tests that an extra always/never translate button is shown on the "before 1405 // Tests that an extra always/never translate button is shown on the "before
1319 // translate" infobar when the translation is accepted/declined 3 times, 1406 // translate" infobar when the translation is accepted/declined 3 times,
1320 // only when not in incognito mode. 1407 // only when not in incognito mode.
1321 TEST_F(TranslateManagerRenderViewHostTest, BeforeTranslateExtraButtons) { 1408 TEST_F(TranslateManagerRenderViewHostTest, BeforeTranslateExtraButtons) {
1409 // This test only applies to the infobar translate UX, not the new bubble UX.
1410 if (TranslateService::IsTranslateBubbleEnabled())
1411 return;
1412
1322 Profile* profile = 1413 Profile* profile =
1323 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); 1414 Profile::FromBrowserContext(web_contents()->GetBrowserContext());
1324 scoped_ptr<TranslatePrefs> translate_prefs( 1415 scoped_ptr<TranslatePrefs> translate_prefs(
1325 ChromeTranslateClient::CreateTranslatePrefs(profile->GetPrefs())); 1416 ChromeTranslateClient::CreateTranslatePrefs(profile->GetPrefs()));
1326 translate_prefs->ResetTranslationAcceptedCount("fr"); 1417 translate_prefs->ResetTranslationAcceptedCount("fr");
1327 translate_prefs->ResetTranslationDeniedCount("fr"); 1418 translate_prefs->ResetTranslationDeniedCount("fr");
1328 translate_prefs->ResetTranslationAcceptedCount("de"); 1419 translate_prefs->ResetTranslationAcceptedCount("de");
1329 translate_prefs->ResetTranslationDeniedCount("de"); 1420 translate_prefs->ResetTranslationDeniedCount("de");
1330 1421
1331 // We'll do 4 times in incognito mode first to make sure the button is not 1422 // We'll do 4 times in incognito mode first to make sure the button is not
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
1391 EXPECT_TRUE(translate_prefs->IsBlockedLanguage("de")); 1482 EXPECT_TRUE(translate_prefs->IsBlockedLanguage("de"));
1392 // No translation should have occured and the infobar should be gone. 1483 // No translation should have occured and the infobar should be gone.
1393 EXPECT_FALSE(GetTranslateMessage(&page_id, &original_lang, &target_lang)); 1484 EXPECT_FALSE(GetTranslateMessage(&page_id, &original_lang, &target_lang));
1394 process()->sink().ClearMessages(); 1485 process()->sink().ClearMessages();
1395 ASSERT_TRUE(GetTranslateInfoBar() == NULL); 1486 ASSERT_TRUE(GetTranslateInfoBar() == NULL);
1396 } 1487 }
1397 1488
1398 // Tests that we don't show a translate infobar when a page instructs that it 1489 // Tests that we don't show a translate infobar when a page instructs that it
1399 // should not be translated. 1490 // should not be translated.
1400 TEST_F(TranslateManagerRenderViewHostTest, NonTranslatablePage) { 1491 TEST_F(TranslateManagerRenderViewHostTest, NonTranslatablePage) {
1492 // This test only applies to the infobar translate UX, not the new bubble UX.
1493 if (TranslateService::IsTranslateBubbleEnabled())
1494 return;
1495
1401 SimulateNavigation(GURL("http://mail.google.fr"), "fr", false); 1496 SimulateNavigation(GURL("http://mail.google.fr"), "fr", false);
1402 1497
1403 // We should not have an infobar. 1498 // We should not have an infobar.
1404 EXPECT_TRUE(GetTranslateInfoBar() == NULL); 1499 EXPECT_TRUE(GetTranslateInfoBar() == NULL);
1405 1500
1406 // The context menu is enabled to allow users to force translation. 1501 // The context menu is enabled to allow users to force translation.
1407 scoped_ptr<TestRenderViewContextMenu> menu(CreateContextMenu()); 1502 scoped_ptr<TestRenderViewContextMenu> menu(CreateContextMenu());
1408 menu->Init(); 1503 menu->Init();
1409 EXPECT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_TRANSLATE)); 1504 EXPECT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_TRANSLATE));
1410 EXPECT_TRUE(menu->IsCommandIdEnabled(IDC_CONTENT_CONTEXT_TRANSLATE)); 1505 EXPECT_TRUE(menu->IsCommandIdEnabled(IDC_CONTENT_CONTEXT_TRANSLATE));
1411 } 1506 }
1412 1507
1413 // Tests that the script is expired and refetched as expected. 1508 // Tests that the script is expired and refetched as expected.
1414 TEST_F(TranslateManagerRenderViewHostTest, ScriptExpires) { 1509 TEST_F(TranslateManagerRenderViewHostTest, ScriptExpires) {
1510 // This test only applies to the infobar translate UX, not the new bubble UX.
1511 if (TranslateService::IsTranslateBubbleEnabled())
1512 return;
1513
1415 ExpireTranslateScriptImmediately(); 1514 ExpireTranslateScriptImmediately();
1416 1515
1417 SimulateNavigation(GURL("http://www.google.fr"), "fr", true); 1516 SimulateNavigation(GURL("http://www.google.fr"), "fr", true);
1418 TranslateInfoBarDelegate* infobar = GetTranslateInfoBar(); 1517 TranslateInfoBarDelegate* infobar = GetTranslateInfoBar();
1419 ASSERT_TRUE(infobar != NULL); 1518 ASSERT_TRUE(infobar != NULL);
1420 process()->sink().ClearMessages(); 1519 process()->sink().ClearMessages();
1421 infobar->Translate(); 1520 infobar->Translate();
1422 SimulateTranslateScriptURLFetch(true); 1521 SimulateTranslateScriptURLFetch(true);
1423 SimulateOnPageTranslated("fr", "en"); 1522 SimulateOnPageTranslated("fr", "en");
1424 1523
(...skipping 20 matching lines...) Expand all
1445 EXPECT_EQ("en", target_lang); 1544 EXPECT_EQ("en", target_lang);
1446 } 1545 }
1447 1546
1448 TEST_F(TranslateManagerRenderViewHostTest, DownloadsAndHistoryNotTranslated) { 1547 TEST_F(TranslateManagerRenderViewHostTest, DownloadsAndHistoryNotTranslated) {
1449 ASSERT_FALSE( 1548 ASSERT_FALSE(
1450 TranslateService::IsTranslatableURL(GURL(chrome::kChromeUIDownloadsURL))); 1549 TranslateService::IsTranslatableURL(GURL(chrome::kChromeUIDownloadsURL)));
1451 ASSERT_FALSE( 1550 ASSERT_FALSE(
1452 TranslateService::IsTranslatableURL(GURL(chrome::kChromeUIHistoryURL))); 1551 TranslateService::IsTranslatableURL(GURL(chrome::kChromeUIHistoryURL)));
1453 } 1552 }
1454 1553
1455 #if defined(USE_AURA) 1554 TEST_F(TranslateManagerRenderViewHostTest, BubbleNormalTranslate) {
1555 // This test only applies to the bubble transle UX, not the old infobar UX.
1556 if (!TranslateService::IsTranslateBubbleEnabled())
1557 return;
1456 1558
1457 TEST_F(TranslateManagerRenderViewHostTest, BubbleNormalTranslate) {
1458 // Prepare for the bubble
1459 TranslateService::SetUseInfobar(false);
1460 MockTranslateBubbleFactory* factory = new MockTranslateBubbleFactory; 1559 MockTranslateBubbleFactory* factory = new MockTranslateBubbleFactory;
1461 scoped_ptr<TranslateBubbleFactory> factory_ptr(factory); 1560 scoped_ptr<TranslateBubbleFactory> factory_ptr(factory);
1462 TranslateBubbleFactory::SetFactory(factory); 1561 TranslateBubbleFactory::SetFactory(factory);
1463 1562
1464 SimulateNavigation(GURL("http://www.google.fr"), "fr", true); 1563 SimulateNavigation(GURL("http://www.google.fr"), "fr", true);
1465 1564
1466 // Check the bubble exists instead of the infobar. 1565 // Check the bubble exists instead of the infobar.
1467 TranslateInfoBarDelegate* infobar = GetTranslateInfoBar(); 1566 TranslateInfoBarDelegate* infobar = GetTranslateInfoBar();
1468 ASSERT_TRUE(infobar == NULL); 1567 ASSERT_TRUE(infobar == NULL);
1469 TranslateBubbleModel* bubble = factory->model(); 1568 TranslateBubbleModel* bubble = factory->model();
(...skipping 19 matching lines...) Expand all
1489 SimulateOnPageTranslated("fr", "en"); 1588 SimulateOnPageTranslated("fr", "en");
1490 1589
1491 // Check the bubble shows "Translated." 1590 // Check the bubble shows "Translated."
1492 bubble = factory->model(); 1591 bubble = factory->model();
1493 ASSERT_TRUE(bubble != NULL); 1592 ASSERT_TRUE(bubble != NULL);
1494 EXPECT_EQ(TranslateBubbleModel::VIEW_STATE_AFTER_TRANSLATE, 1593 EXPECT_EQ(TranslateBubbleModel::VIEW_STATE_AFTER_TRANSLATE,
1495 bubble->GetViewState()); 1594 bubble->GetViewState());
1496 } 1595 }
1497 1596
1498 TEST_F(TranslateManagerRenderViewHostTest, BubbleTranslateScriptNotAvailable) { 1597 TEST_F(TranslateManagerRenderViewHostTest, BubbleTranslateScriptNotAvailable) {
1499 // Prepare for the bubble 1598 // This test only applies to the bubble transle UX, not the old infobar UX.
1500 TranslateService::SetUseInfobar(false); 1599 if (!TranslateService::IsTranslateBubbleEnabled())
1600 return;
1601
1501 MockTranslateBubbleFactory* factory = new MockTranslateBubbleFactory; 1602 MockTranslateBubbleFactory* factory = new MockTranslateBubbleFactory;
1502 scoped_ptr<TranslateBubbleFactory> factory_ptr(factory); 1603 scoped_ptr<TranslateBubbleFactory> factory_ptr(factory);
1503 TranslateBubbleFactory::SetFactory(factory); 1604 TranslateBubbleFactory::SetFactory(factory);
1504 1605
1505 SimulateNavigation(GURL("http://www.google.fr"), "fr", true); 1606 SimulateNavigation(GURL("http://www.google.fr"), "fr", true);
1506 1607
1507 // Check the bubble exists instead of the infobar. 1608 // Check the bubble exists instead of the infobar.
1508 TranslateInfoBarDelegate* infobar = GetTranslateInfoBar(); 1609 TranslateInfoBarDelegate* infobar = GetTranslateInfoBar();
1509 ASSERT_TRUE(infobar == NULL); 1610 ASSERT_TRUE(infobar == NULL);
1510 TranslateBubbleModel* bubble = factory->model(); 1611 TranslateBubbleModel* bubble = factory->model();
1511 ASSERT_TRUE(bubble != NULL); 1612 ASSERT_TRUE(bubble != NULL);
1512 EXPECT_EQ(TranslateBubbleModel::VIEW_STATE_BEFORE_TRANSLATE, 1613 EXPECT_EQ(TranslateBubbleModel::VIEW_STATE_BEFORE_TRANSLATE,
1513 bubble->GetViewState()); 1614 bubble->GetViewState());
1514 1615
1515 // Simulate clicking translate. 1616 // Simulate clicking translate.
1516 process()->sink().ClearMessages(); 1617 process()->sink().ClearMessages();
1517 bubble->Translate(); 1618 bubble->Translate();
1518 SimulateTranslateScriptURLFetch(false); 1619 SimulateTranslateScriptURLFetch(false);
1519 1620
1520 // We should not have sent any message to translate to the renderer. 1621 // We should not have sent any message to translate to the renderer.
1521 EXPECT_FALSE(GetTranslateMessage(NULL, NULL, NULL)); 1622 EXPECT_FALSE(GetTranslateMessage(NULL, NULL, NULL));
1522 1623
1523 // And we should have an error infobar showing. 1624 // And we should have an error infobar showing.
1524 bubble = factory->model(); 1625 bubble = factory->model();
1525 ASSERT_TRUE(bubble != NULL); 1626 ASSERT_TRUE(bubble != NULL);
1526 EXPECT_EQ(TranslateBubbleModel::VIEW_STATE_ERROR, bubble->GetViewState()); 1627 EXPECT_EQ(TranslateBubbleModel::VIEW_STATE_ERROR, bubble->GetViewState());
1527 } 1628 }
1528 1629
1529 TEST_F(TranslateManagerRenderViewHostTest, BubbleUnknownLanguage) { 1630 TEST_F(TranslateManagerRenderViewHostTest, BubbleUnknownLanguage) {
1530 // Prepare for the bubble 1631 // This test only applies to the bubble transle UX, not the old infobar UX.
1531 TranslateService::SetUseInfobar(false); 1632 if (!TranslateService::IsTranslateBubbleEnabled())
1633 return;
1634
1532 MockTranslateBubbleFactory* factory = new MockTranslateBubbleFactory; 1635 MockTranslateBubbleFactory* factory = new MockTranslateBubbleFactory;
1533 scoped_ptr<TranslateBubbleFactory> factory_ptr(factory); 1636 scoped_ptr<TranslateBubbleFactory> factory_ptr(factory);
1534 TranslateBubbleFactory::SetFactory(factory); 1637 TranslateBubbleFactory::SetFactory(factory);
1535 1638
1536 // Simulate navigating to a page ("und" is the string returned by the CLD for 1639 // Simulate navigating to a page ("und" is the string returned by the CLD for
1537 // languages it does not recognize). 1640 // languages it does not recognize).
1538 SimulateNavigation(GURL("http://www.google.mys"), "und", true); 1641 SimulateNavigation(GURL("http://www.google.mys"), "und", true);
1539 1642
1540 // We should not have a bubble as we don't know the language. 1643 // We should not have a bubble as we don't know the language.
1541 ASSERT_TRUE(factory->model() == NULL); 1644 ASSERT_TRUE(factory->model() == NULL);
1542 1645
1543 // Translate the page anyway throught the context menu. 1646 // Translate the page anyway throught the context menu.
1544 scoped_ptr<TestRenderViewContextMenu> menu(CreateContextMenu()); 1647 scoped_ptr<TestRenderViewContextMenu> menu(CreateContextMenu());
1545 menu->Init(); 1648 menu->Init();
1546 menu->ExecuteCommand(IDC_CONTENT_CONTEXT_TRANSLATE, 0); 1649 menu->ExecuteCommand(IDC_CONTENT_CONTEXT_TRANSLATE, 0);
1547 1650
1548 // Check the bubble exists instead of the infobar. 1651 // Check the bubble exists instead of the infobar.
1549 TranslateInfoBarDelegate* infobar = GetTranslateInfoBar(); 1652 TranslateInfoBarDelegate* infobar = GetTranslateInfoBar();
1550 ASSERT_TRUE(infobar == NULL); 1653 ASSERT_TRUE(infobar == NULL);
1551 TranslateBubbleModel* bubble = factory->model(); 1654 TranslateBubbleModel* bubble = factory->model();
1552 ASSERT_TRUE(bubble != NULL); 1655 ASSERT_TRUE(bubble != NULL);
1553 EXPECT_EQ(TranslateBubbleModel::VIEW_STATE_TRANSLATING, 1656 EXPECT_EQ(TranslateBubbleModel::VIEW_STATE_TRANSLATING,
1554 bubble->GetViewState()); 1657 bubble->GetViewState());
1555 } 1658 }
1556
1557 #endif // defined(USE_AURA)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698