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

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

Issue 9838009: Clean up a few TODO items. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Respond to review comments. Created 8 years, 9 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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 // for that navigation. 67 // for that navigation.
68 void SimulateNavigation(const GURL& url, 68 void SimulateNavigation(const GURL& url,
69 const std::string& lang, 69 const std::string& lang,
70 bool page_translatable) { 70 bool page_translatable) {
71 NavigateAndCommit(url); 71 NavigateAndCommit(url);
72 SimulateOnTranslateLanguageDetermined(lang, page_translatable); 72 SimulateOnTranslateLanguageDetermined(lang, page_translatable);
73 } 73 }
74 74
75 void SimulateOnTranslateLanguageDetermined(const std::string& lang, 75 void SimulateOnTranslateLanguageDetermined(const std::string& lang,
76 bool page_translatable) { 76 bool page_translatable) {
77 rvh_tester()->TestOnMessageReceived( 77 RenderViewHostTester::TestOnMessageReceived(
78 rvh(),
78 ChromeViewHostMsg_TranslateLanguageDetermined( 79 ChromeViewHostMsg_TranslateLanguageDetermined(
79 0, lang, page_translatable)); 80 0, lang, page_translatable));
80 } 81 }
81 82
82 bool GetTranslateMessage(int* page_id, 83 bool GetTranslateMessage(int* page_id,
83 std::string* original_lang, 84 std::string* original_lang,
84 std::string* target_lang) { 85 std::string* target_lang) {
85 const IPC::Message* message = 86 const IPC::Message* message =
86 process()->sink().GetFirstMessageMatching( 87 process()->sink().GetFirstMessageMatching(
87 ChromeViewMsg_TranslatePage::ID); 88 ChromeViewMsg_TranslatePage::ID);
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 SimulateTranslateScriptURLFetch(true); 360 SimulateTranslateScriptURLFetch(true);
360 361
361 // Test that we sent the right message to the renderer. 362 // Test that we sent the right message to the renderer.
362 int page_id = 0; 363 int page_id = 0;
363 std::string original_lang, target_lang; 364 std::string original_lang, target_lang;
364 EXPECT_TRUE(GetTranslateMessage(&page_id, &original_lang, &target_lang)); 365 EXPECT_TRUE(GetTranslateMessage(&page_id, &original_lang, &target_lang));
365 EXPECT_EQ("fr", original_lang); 366 EXPECT_EQ("fr", original_lang);
366 EXPECT_EQ("en", target_lang); 367 EXPECT_EQ("en", target_lang);
367 368
368 // Simulate the render notifying the translation has been done. 369 // Simulate the render notifying the translation has been done.
369 rvh_tester()->TestOnMessageReceived(ChromeViewHostMsg_PageTranslated( 370 RenderViewHostTester::TestOnMessageReceived(
370 0, 0, "fr", "en", TranslateErrors::NONE)); 371 rvh(),
372 ChromeViewHostMsg_PageTranslated(
373 0, 0, "fr", "en", TranslateErrors::NONE));
371 374
372 // The after translate infobar should be showing. 375 // The after translate infobar should be showing.
373 infobar = GetTranslateInfoBar(); 376 infobar = GetTranslateInfoBar();
374 ASSERT_TRUE(infobar != NULL); 377 ASSERT_TRUE(infobar != NULL);
375 EXPECT_EQ(TranslateInfoBarDelegate::AFTER_TRANSLATE, infobar->type()); 378 EXPECT_EQ(TranslateInfoBarDelegate::AFTER_TRANSLATE, infobar->type());
376 379
377 // Simulate changing the original language, this should trigger a translation. 380 // Simulate changing the original language, this should trigger a translation.
378 process()->sink().ClearMessages(); 381 process()->sink().ClearMessages();
379 std::string new_original_lang = infobar->GetLanguageCodeAt(0); 382 std::string new_original_lang = infobar->GetLanguageCodeAt(0);
380 infobar->SetOriginalLanguage(0); 383 infobar->SetOriginalLanguage(0);
381 EXPECT_TRUE(GetTranslateMessage(&page_id, &original_lang, &target_lang)); 384 EXPECT_TRUE(GetTranslateMessage(&page_id, &original_lang, &target_lang));
382 EXPECT_EQ(new_original_lang, original_lang); 385 EXPECT_EQ(new_original_lang, original_lang);
383 EXPECT_EQ("en", target_lang); 386 EXPECT_EQ("en", target_lang);
384 // Simulate the render notifying the translation has been done. 387 // Simulate the render notifying the translation has been done.
385 rvh_tester()->TestOnMessageReceived(ChromeViewHostMsg_PageTranslated( 388 RenderViewHostTester::TestOnMessageReceived(
386 0, 0, new_original_lang, "en", TranslateErrors::NONE)); 389 rvh(),
390 ChromeViewHostMsg_PageTranslated(
391 0, 0, new_original_lang, "en", TranslateErrors::NONE));
387 // infobar is now invalid. 392 // infobar is now invalid.
388 TranslateInfoBarDelegate* new_infobar = GetTranslateInfoBar(); 393 TranslateInfoBarDelegate* new_infobar = GetTranslateInfoBar();
389 ASSERT_TRUE(new_infobar != NULL); 394 ASSERT_TRUE(new_infobar != NULL);
390 infobar = new_infobar; 395 infobar = new_infobar;
391 396
392 // Simulate changing the target language, this should trigger a translation. 397 // Simulate changing the target language, this should trigger a translation.
393 process()->sink().ClearMessages(); 398 process()->sink().ClearMessages();
394 std::string new_target_lang = infobar->GetLanguageCodeAt(1); 399 std::string new_target_lang = infobar->GetLanguageCodeAt(1);
395 infobar->SetTargetLanguage(1); 400 infobar->SetTargetLanguage(1);
396 EXPECT_TRUE(GetTranslateMessage(&page_id, &original_lang, &target_lang)); 401 EXPECT_TRUE(GetTranslateMessage(&page_id, &original_lang, &target_lang));
397 EXPECT_EQ(new_original_lang, original_lang); 402 EXPECT_EQ(new_original_lang, original_lang);
398 EXPECT_EQ(new_target_lang, target_lang); 403 EXPECT_EQ(new_target_lang, target_lang);
399 // Simulate the render notifying the translation has been done. 404 // Simulate the render notifying the translation has been done.
400 rvh_tester()->TestOnMessageReceived( 405 RenderViewHostTester::TestOnMessageReceived(
406 rvh(),
401 ChromeViewHostMsg_PageTranslated( 407 ChromeViewHostMsg_PageTranslated(
402 0, 0, new_original_lang, new_target_lang, TranslateErrors::NONE)); 408 0, 0, new_original_lang, new_target_lang, TranslateErrors::NONE));
403 // infobar is now invalid. 409 // infobar is now invalid.
404 new_infobar = GetTranslateInfoBar(); 410 new_infobar = GetTranslateInfoBar();
405 ASSERT_TRUE(new_infobar != NULL); 411 ASSERT_TRUE(new_infobar != NULL);
406 } 412 }
407 413
408 TEST_F(TranslateManagerTest, TranslateScriptNotAvailable) { 414 TEST_F(TranslateManagerTest, TranslateScriptNotAvailable) {
409 // Simulate navigating to a page. 415 // Simulate navigating to a page.
410 SimulateNavigation(GURL("http://www.google.fr"), "fr", true); 416 SimulateNavigation(GURL("http://www.google.fr"), "fr", true);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 SimulateTranslateScriptURLFetch(false); 456 SimulateTranslateScriptURLFetch(false);
451 TranslateInfoBarDelegate* infobar = GetTranslateInfoBar(); 457 TranslateInfoBarDelegate* infobar = GetTranslateInfoBar();
452 ASSERT_TRUE(infobar != NULL); 458 ASSERT_TRUE(infobar != NULL);
453 EXPECT_EQ(TranslateInfoBarDelegate::TRANSLATION_ERROR, infobar->type()); 459 EXPECT_EQ(TranslateInfoBarDelegate::TRANSLATION_ERROR, infobar->type());
454 EXPECT_TRUE(infobar->IsError()); 460 EXPECT_TRUE(infobar->IsError());
455 infobar->MessageInfoBarButtonPressed(); 461 infobar->MessageInfoBarButtonPressed();
456 SimulateTranslateScriptURLFetch(true); // This time succeed. 462 SimulateTranslateScriptURLFetch(true); // This time succeed.
457 463
458 // Simulate the render notifying the translation has been done, the server 464 // Simulate the render notifying the translation has been done, the server
459 // having detected the page was in a known and supported language. 465 // having detected the page was in a known and supported language.
460 rvh_tester()->TestOnMessageReceived(ChromeViewHostMsg_PageTranslated( 466 RenderViewHostTester::TestOnMessageReceived(
461 0, 0, "fr", "en", TranslateErrors::NONE)); 467 rvh(),
468 ChromeViewHostMsg_PageTranslated(
469 0, 0, "fr", "en", TranslateErrors::NONE));
462 470
463 // The after translate infobar should be showing. 471 // The after translate infobar should be showing.
464 infobar = GetTranslateInfoBar(); 472 infobar = GetTranslateInfoBar();
465 ASSERT_TRUE(infobar != NULL); 473 ASSERT_TRUE(infobar != NULL);
466 EXPECT_EQ(TranslateInfoBarDelegate::AFTER_TRANSLATE, infobar->type()); 474 EXPECT_EQ(TranslateInfoBarDelegate::AFTER_TRANSLATE, infobar->type());
467 EXPECT_EQ("fr", infobar->GetOriginalLanguageCode()); 475 EXPECT_EQ("fr", infobar->GetOriginalLanguageCode());
468 EXPECT_EQ("en", infobar->GetTargetLanguageCode()); 476 EXPECT_EQ("en", infobar->GetTargetLanguageCode());
469 477
470 // Let's run the same steps but this time the server detects the page is 478 // Let's run the same steps but this time the server detects the page is
471 // already in English. 479 // already in English.
472 SimulateNavigation(GURL("http://www.google.com"), "und", true); 480 SimulateNavigation(GURL("http://www.google.com"), "und", true);
473 menu.reset(TestRenderViewContextMenu::CreateContextMenu(contents())); 481 menu.reset(TestRenderViewContextMenu::CreateContextMenu(contents()));
474 menu->Init(); 482 menu->Init();
475 menu->ExecuteCommand(IDC_CONTENT_CONTEXT_TRANSLATE); 483 menu->ExecuteCommand(IDC_CONTENT_CONTEXT_TRANSLATE);
476 rvh_tester()->TestOnMessageReceived(ChromeViewHostMsg_PageTranslated( 484 RenderViewHostTester::TestOnMessageReceived(
477 1, 0, "en", "en", TranslateErrors::IDENTICAL_LANGUAGES)); 485 rvh(),
486 ChromeViewHostMsg_PageTranslated(
487 1, 0, "en", "en", TranslateErrors::IDENTICAL_LANGUAGES));
478 infobar = GetTranslateInfoBar(); 488 infobar = GetTranslateInfoBar();
479 ASSERT_TRUE(infobar != NULL); 489 ASSERT_TRUE(infobar != NULL);
480 EXPECT_EQ(TranslateInfoBarDelegate::TRANSLATION_ERROR, infobar->type()); 490 EXPECT_EQ(TranslateInfoBarDelegate::TRANSLATION_ERROR, infobar->type());
481 EXPECT_EQ(TranslateErrors::IDENTICAL_LANGUAGES, infobar->error()); 491 EXPECT_EQ(TranslateErrors::IDENTICAL_LANGUAGES, infobar->error());
482 492
483 // Let's run the same steps again but this time the server fails to detect the 493 // Let's run the same steps again but this time the server fails to detect the
484 // page's language (it returns an empty string). 494 // page's language (it returns an empty string).
485 SimulateNavigation(GURL("http://www.google.com"), "und", true); 495 SimulateNavigation(GURL("http://www.google.com"), "und", true);
486 menu.reset(TestRenderViewContextMenu::CreateContextMenu(contents())); 496 menu.reset(TestRenderViewContextMenu::CreateContextMenu(contents()));
487 menu->Init(); 497 menu->Init();
488 menu->ExecuteCommand(IDC_CONTENT_CONTEXT_TRANSLATE); 498 menu->ExecuteCommand(IDC_CONTENT_CONTEXT_TRANSLATE);
489 rvh_tester()->TestOnMessageReceived(ChromeViewHostMsg_PageTranslated( 499 RenderViewHostTester::TestOnMessageReceived(
490 2, 0, "", "en", TranslateErrors::UNKNOWN_LANGUAGE)); 500 rvh(),
501 ChromeViewHostMsg_PageTranslated(
502 2, 0, "", "en", TranslateErrors::UNKNOWN_LANGUAGE));
491 infobar = GetTranslateInfoBar(); 503 infobar = GetTranslateInfoBar();
492 ASSERT_TRUE(infobar != NULL); 504 ASSERT_TRUE(infobar != NULL);
493 EXPECT_EQ(TranslateInfoBarDelegate::TRANSLATION_ERROR, infobar->type()); 505 EXPECT_EQ(TranslateInfoBarDelegate::TRANSLATION_ERROR, infobar->type());
494 EXPECT_EQ(TranslateErrors::UNKNOWN_LANGUAGE, infobar->error()); 506 EXPECT_EQ(TranslateErrors::UNKNOWN_LANGUAGE, infobar->error());
495 } 507 }
496 508
497 // Tests that we show/don't show an info-bar for all languages the CLD can 509 // Tests that we show/don't show an info-bar for all languages the CLD can
498 // report. 510 // report.
499 TEST_F(TranslateManagerTest, TestAllLanguages) { 511 TEST_F(TranslateManagerTest, TestAllLanguages) {
500 // The index in kExpectation are the Language enum (see languages.pb.h). 512 // The index in kExpectation are the Language enum (see languages.pb.h).
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
679 // Simulate navigating to a page and getting its language. 691 // Simulate navigating to a page and getting its language.
680 SimulateNavigation(GURL("http://www.google.fr"), "fr", true); 692 SimulateNavigation(GURL("http://www.google.fr"), "fr", true);
681 693
682 // Simulate the user translating. 694 // Simulate the user translating.
683 TranslateInfoBarDelegate* infobar = GetTranslateInfoBar(); 695 TranslateInfoBarDelegate* infobar = GetTranslateInfoBar();
684 ASSERT_TRUE(infobar != NULL); 696 ASSERT_TRUE(infobar != NULL);
685 infobar->Translate(); 697 infobar->Translate();
686 // Simulate the translate script being retrieved. 698 // Simulate the translate script being retrieved.
687 SimulateTranslateScriptURLFetch(true); 699 SimulateTranslateScriptURLFetch(true);
688 700
689 rvh_tester()->TestOnMessageReceived(ChromeViewHostMsg_PageTranslated( 701 RenderViewHostTester::TestOnMessageReceived(
690 0, 0, "fr", "en", TranslateErrors::NONE)); 702 rvh(),
703 ChromeViewHostMsg_PageTranslated(
704 0, 0, "fr", "en", TranslateErrors::NONE));
691 705
692 // Now navigate to a new page in the same language. 706 // Now navigate to a new page in the same language.
693 process()->sink().ClearMessages(); 707 process()->sink().ClearMessages();
694 SimulateNavigation(GURL("http://news.google.fr"), "fr", true); 708 SimulateNavigation(GURL("http://news.google.fr"), "fr", true);
695 709
696 // This should have automatically triggered a translation. 710 // This should have automatically triggered a translation.
697 int page_id = 0; 711 int page_id = 0;
698 std::string original_lang, target_lang; 712 std::string original_lang, target_lang;
699 EXPECT_TRUE(GetTranslateMessage(&page_id, &original_lang, &target_lang)); 713 EXPECT_TRUE(GetTranslateMessage(&page_id, &original_lang, &target_lang));
700 EXPECT_EQ(1, page_id); 714 EXPECT_EQ(1, page_id);
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
853 TEST_F(TranslateManagerTest, TranslateCloseInfoBarInPageNavigation) { 867 TEST_F(TranslateManagerTest, TranslateCloseInfoBarInPageNavigation) {
854 // Simulate navigating to a page and getting its language. 868 // Simulate navigating to a page and getting its language.
855 SimulateNavigation(GURL("http://www.google.fr"), "fr", true); 869 SimulateNavigation(GURL("http://www.google.fr"), "fr", true);
856 870
857 // Simulate the user translating. 871 // Simulate the user translating.
858 TranslateInfoBarDelegate* infobar = GetTranslateInfoBar(); 872 TranslateInfoBarDelegate* infobar = GetTranslateInfoBar();
859 ASSERT_TRUE(infobar != NULL); 873 ASSERT_TRUE(infobar != NULL);
860 infobar->Translate(); 874 infobar->Translate();
861 // Simulate the translate script being retrieved. 875 // Simulate the translate script being retrieved.
862 SimulateTranslateScriptURLFetch(true); 876 SimulateTranslateScriptURLFetch(true);
863 rvh_tester()->TestOnMessageReceived(ChromeViewHostMsg_PageTranslated( 877 RenderViewHostTester::TestOnMessageReceived(
864 0, 0, "fr", "en", TranslateErrors::NONE)); 878 rvh(),
879 ChromeViewHostMsg_PageTranslated(
880 0, 0, "fr", "en", TranslateErrors::NONE));
865 881
866 // Close the infobar. 882 // Close the infobar.
867 EXPECT_TRUE(CloseTranslateInfoBar()); 883 EXPECT_TRUE(CloseTranslateInfoBar());
868 884
869 // Navigate in page, no infobar should be shown. 885 // Navigate in page, no infobar should be shown.
870 SimulateNavigation(GURL("http://www.google.fr/#ref1"), "fr", true); 886 SimulateNavigation(GURL("http://www.google.fr/#ref1"), "fr", true);
871 EXPECT_TRUE(GetTranslateInfoBar() == NULL); 887 EXPECT_TRUE(GetTranslateInfoBar() == NULL);
872 888
873 // Navigate out of page, a new infobar should show. 889 // Navigate out of page, a new infobar should show.
874 // Note that we navigate to a page in a different language so we don't trigger 890 // Note that we navigate to a page in a different language so we don't trigger
875 // the auto-translate feature (it would translate the page automatically and 891 // the auto-translate feature (it would translate the page automatically and
876 // the before translate inforbar would not be shown). 892 // the before translate inforbar would not be shown).
877 SimulateNavigation(GURL("http://www.google.de"), "de", true); 893 SimulateNavigation(GURL("http://www.google.de"), "de", true);
878 EXPECT_TRUE(GetTranslateInfoBar() != NULL); 894 EXPECT_TRUE(GetTranslateInfoBar() != NULL);
879 } 895 }
880 896
881 // Tests that the after translate the infobar still shows when navigating 897 // Tests that the after translate the infobar still shows when navigating
882 // in-page. 898 // in-page.
883 TEST_F(TranslateManagerTest, TranslateInPageNavigation) { 899 TEST_F(TranslateManagerTest, TranslateInPageNavigation) {
884 // Simulate navigating to a page and getting its language. 900 // Simulate navigating to a page and getting its language.
885 SimulateNavigation(GURL("http://www.google.fr"), "fr", true); 901 SimulateNavigation(GURL("http://www.google.fr"), "fr", true);
886 902
887 // Simulate the user translating. 903 // Simulate the user translating.
888 TranslateInfoBarDelegate* infobar = GetTranslateInfoBar(); 904 TranslateInfoBarDelegate* infobar = GetTranslateInfoBar();
889 ASSERT_TRUE(infobar != NULL); 905 ASSERT_TRUE(infobar != NULL);
890 infobar->Translate(); 906 infobar->Translate();
891 // Simulate the translate script being retrieved. 907 // Simulate the translate script being retrieved.
892 SimulateTranslateScriptURLFetch(true); 908 SimulateTranslateScriptURLFetch(true);
893 rvh_tester()->TestOnMessageReceived(ChromeViewHostMsg_PageTranslated( 909 RenderViewHostTester::TestOnMessageReceived(
894 0, 0, "fr", "en", TranslateErrors::NONE)); 910 rvh(),
911 ChromeViewHostMsg_PageTranslated(
912 0, 0, "fr", "en", TranslateErrors::NONE));
895 // The after translate infobar is showing. 913 // The after translate infobar is showing.
896 infobar = GetTranslateInfoBar(); 914 infobar = GetTranslateInfoBar();
897 ASSERT_TRUE(infobar != NULL); 915 ASSERT_TRUE(infobar != NULL);
898 916
899 // Navigate out of page, a new infobar should show. 917 // Navigate out of page, a new infobar should show.
900 // See note in TranslateCloseInfoBarInPageNavigation test on why it is 918 // See note in TranslateCloseInfoBarInPageNavigation test on why it is
901 // important to navigate to a page in a different language for this test. 919 // important to navigate to a page in a different language for this test.
902 SimulateNavigation(GURL("http://www.google.de"), "de", true); 920 SimulateNavigation(GURL("http://www.google.de"), "de", true);
903 // The old infobar is gone. 921 // The old infobar is gone.
904 EXPECT_TRUE(CheckInfoBarRemovedAndReset(infobar)); 922 EXPECT_TRUE(CheckInfoBarRemovedAndReset(infobar));
(...skipping 17 matching lines...) Expand all
922 TEST_F(TranslateManagerTest, ServerReportsUnsupportedLanguage) { 940 TEST_F(TranslateManagerTest, ServerReportsUnsupportedLanguage) {
923 // Simulate navigating to a page and translating it. 941 // Simulate navigating to a page and translating it.
924 SimulateNavigation(GURL("http://mail.google.fr"), "fr", true); 942 SimulateNavigation(GURL("http://mail.google.fr"), "fr", true);
925 TranslateInfoBarDelegate* infobar = GetTranslateInfoBar(); 943 TranslateInfoBarDelegate* infobar = GetTranslateInfoBar();
926 ASSERT_TRUE(infobar != NULL); 944 ASSERT_TRUE(infobar != NULL);
927 process()->sink().ClearMessages(); 945 process()->sink().ClearMessages();
928 infobar->Translate(); 946 infobar->Translate();
929 SimulateTranslateScriptURLFetch(true); 947 SimulateTranslateScriptURLFetch(true);
930 // Simulate the render notifying the translation has been done, but it 948 // Simulate the render notifying the translation has been done, but it
931 // reports a language we don't support. 949 // reports a language we don't support.
932 rvh_tester()->TestOnMessageReceived(ChromeViewHostMsg_PageTranslated( 950 RenderViewHostTester::TestOnMessageReceived(
933 0, 0, "qbz", "en", TranslateErrors::NONE)); 951 rvh(),
952 ChromeViewHostMsg_PageTranslated(
953 0, 0, "qbz", "en", TranslateErrors::NONE));
934 954
935 // An error infobar should be showing to report that we don't support this 955 // An error infobar should be showing to report that we don't support this
936 // language. 956 // language.
937 infobar = GetTranslateInfoBar(); 957 infobar = GetTranslateInfoBar();
938 ASSERT_TRUE(infobar != NULL); 958 ASSERT_TRUE(infobar != NULL);
939 EXPECT_EQ(TranslateInfoBarDelegate::TRANSLATION_ERROR, infobar->type()); 959 EXPECT_EQ(TranslateInfoBarDelegate::TRANSLATION_ERROR, infobar->type());
940 960
941 // This infobar should have a button (so the string should not be empty). 961 // This infobar should have a button (so the string should not be empty).
942 ASSERT_FALSE(infobar->GetMessageInfoBarButtonText().empty()); 962 ASSERT_FALSE(infobar->GetMessageInfoBarButtonText().empty());
943 963
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
1240 EXPECT_TRUE(GetTranslateMessage(&page_id, &original_lang, &target_lang)); 1260 EXPECT_TRUE(GetTranslateMessage(&page_id, &original_lang, &target_lang));
1241 EXPECT_EQ("fr", original_lang); 1261 EXPECT_EQ("fr", original_lang);
1242 EXPECT_EQ("en", target_lang); 1262 EXPECT_EQ("en", target_lang);
1243 process()->sink().ClearMessages(); 1263 process()->sink().ClearMessages();
1244 1264
1245 // This should also have reverted the blacklisting of this site and language. 1265 // This should also have reverted the blacklisting of this site and language.
1246 EXPECT_FALSE(translate_prefs.IsLanguageBlacklisted("fr")); 1266 EXPECT_FALSE(translate_prefs.IsLanguageBlacklisted("fr"));
1247 EXPECT_FALSE(translate_prefs.IsSiteBlacklisted(url.host())); 1267 EXPECT_FALSE(translate_prefs.IsSiteBlacklisted(url.host()));
1248 1268
1249 // Let's simulate the page being translated. 1269 // Let's simulate the page being translated.
1250 rvh_tester()->TestOnMessageReceived(ChromeViewHostMsg_PageTranslated( 1270 RenderViewHostTester::TestOnMessageReceived(
1251 0, 0, "fr", "en", TranslateErrors::NONE)); 1271 rvh(),
1272 ChromeViewHostMsg_PageTranslated(
1273 0, 0, "fr", "en", TranslateErrors::NONE));
1252 1274
1253 // The translate menu should now be disabled. 1275 // The translate menu should now be disabled.
1254 menu.reset(TestRenderViewContextMenu::CreateContextMenu(contents())); 1276 menu.reset(TestRenderViewContextMenu::CreateContextMenu(contents()));
1255 menu->Init(); 1277 menu->Init();
1256 EXPECT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_TRANSLATE)); 1278 EXPECT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_TRANSLATE));
1257 EXPECT_FALSE(menu->IsCommandIdEnabled(IDC_CONTENT_CONTEXT_TRANSLATE)); 1279 EXPECT_FALSE(menu->IsCommandIdEnabled(IDC_CONTENT_CONTEXT_TRANSLATE));
1258 1280
1259 // Test that selecting translate in the context menu WHILE the page is being 1281 // Test that selecting translate in the context menu WHILE the page is being
1260 // translated does nothing (this could happen if autotranslate kicks-in and 1282 // translated does nothing (this could happen if autotranslate kicks-in and
1261 // the user selects the menu while the translation is being performed). 1283 // the user selects the menu while the translation is being performed).
(...skipping 14 matching lines...) Expand all
1276 // been translated does nothing. 1298 // been translated does nothing.
1277 SimulateNavigation(GURL("http://www.google.de"), "de", true); 1299 SimulateNavigation(GURL("http://www.google.de"), "de", true);
1278 infobar = GetTranslateInfoBar(); 1300 infobar = GetTranslateInfoBar();
1279 ASSERT_TRUE(infobar != NULL); 1301 ASSERT_TRUE(infobar != NULL);
1280 infobar->Translate(); 1302 infobar->Translate();
1281 EXPECT_TRUE(GetTranslateMessage(&page_id, &original_lang, &target_lang)); 1303 EXPECT_TRUE(GetTranslateMessage(&page_id, &original_lang, &target_lang));
1282 process()->sink().ClearMessages(); 1304 process()->sink().ClearMessages();
1283 menu.reset(TestRenderViewContextMenu::CreateContextMenu(contents())); 1305 menu.reset(TestRenderViewContextMenu::CreateContextMenu(contents()));
1284 menu->Init(); 1306 menu->Init();
1285 EXPECT_TRUE(menu->IsCommandIdEnabled(IDC_CONTENT_CONTEXT_TRANSLATE)); 1307 EXPECT_TRUE(menu->IsCommandIdEnabled(IDC_CONTENT_CONTEXT_TRANSLATE));
1286 rvh_tester()->TestOnMessageReceived(ChromeViewHostMsg_PageTranslated( 1308 RenderViewHostTester::TestOnMessageReceived(
1287 0, 0, "de", "en", TranslateErrors::NONE)); 1309 rvh(),
1310 ChromeViewHostMsg_PageTranslated(
1311 0, 0, "de", "en", TranslateErrors::NONE));
1288 menu->ExecuteCommand(IDC_CONTENT_CONTEXT_TRANSLATE); 1312 menu->ExecuteCommand(IDC_CONTENT_CONTEXT_TRANSLATE);
1289 // No message expected since the translation should have been ignored. 1313 // No message expected since the translation should have been ignored.
1290 EXPECT_FALSE(GetTranslateMessage(&page_id, &original_lang, &target_lang)); 1314 EXPECT_FALSE(GetTranslateMessage(&page_id, &original_lang, &target_lang));
1291 1315
1292 // Test that the translate context menu is enabled when the page is in an 1316 // Test that the translate context menu is enabled when the page is in an
1293 // unknown language. 1317 // unknown language.
1294 SimulateNavigation(url, "und", true); 1318 SimulateNavigation(url, "und", true);
1295 menu.reset(TestRenderViewContextMenu::CreateContextMenu(contents())); 1319 menu.reset(TestRenderViewContextMenu::CreateContextMenu(contents()));
1296 menu->Init(); 1320 menu->Init();
1297 EXPECT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_TRANSLATE)); 1321 EXPECT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_TRANSLATE));
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
1403 TEST_F(TranslateManagerTest, ScriptExpires) { 1427 TEST_F(TranslateManagerTest, ScriptExpires) {
1404 ExpireTranslateScriptImmediately(); 1428 ExpireTranslateScriptImmediately();
1405 1429
1406 // Simulate navigating to a page and translating it. 1430 // Simulate navigating to a page and translating it.
1407 SimulateNavigation(GURL("http://www.google.fr"), "fr", true); 1431 SimulateNavigation(GURL("http://www.google.fr"), "fr", true);
1408 TranslateInfoBarDelegate* infobar = GetTranslateInfoBar(); 1432 TranslateInfoBarDelegate* infobar = GetTranslateInfoBar();
1409 ASSERT_TRUE(infobar != NULL); 1433 ASSERT_TRUE(infobar != NULL);
1410 process()->sink().ClearMessages(); 1434 process()->sink().ClearMessages();
1411 infobar->Translate(); 1435 infobar->Translate();
1412 SimulateTranslateScriptURLFetch(true); 1436 SimulateTranslateScriptURLFetch(true);
1413 rvh_tester()->TestOnMessageReceived(ChromeViewHostMsg_PageTranslated( 1437 RenderViewHostTester::TestOnMessageReceived(
1414 0, 0, "fr", "en", TranslateErrors::NONE)); 1438 rvh(),
1439 ChromeViewHostMsg_PageTranslated(
1440 0, 0, "fr", "en", TranslateErrors::NONE));
1415 1441
1416 // A task should have been posted to clear the script, run it. 1442 // A task should have been posted to clear the script, run it.
1417 MessageLoop::current()->RunAllPending(); 1443 MessageLoop::current()->RunAllPending();
1418 1444
1419 // Do another navigation and translation. 1445 // Do another navigation and translation.
1420 SimulateNavigation(GURL("http://www.google.es"), "es", true); 1446 SimulateNavigation(GURL("http://www.google.es"), "es", true);
1421 infobar = GetTranslateInfoBar(); 1447 infobar = GetTranslateInfoBar();
1422 ASSERT_TRUE(infobar != NULL); 1448 ASSERT_TRUE(infobar != NULL);
1423 process()->sink().ClearMessages(); 1449 process()->sink().ClearMessages();
1424 infobar->Translate(); 1450 infobar->Translate();
1425 // If we don't simulate the URL fetch, the TranslateManager should be waiting 1451 // If we don't simulate the URL fetch, the TranslateManager should be waiting
1426 // for the script and no message should have been sent to the renderer. 1452 // for the script and no message should have been sent to the renderer.
1427 EXPECT_TRUE( 1453 EXPECT_TRUE(
1428 process()->sink().GetFirstMessageMatching( 1454 process()->sink().GetFirstMessageMatching(
1429 ChromeViewMsg_TranslatePage::ID) == 1455 ChromeViewMsg_TranslatePage::ID) ==
1430 NULL); 1456 NULL);
1431 // Now simulate the URL fetch. 1457 // Now simulate the URL fetch.
1432 SimulateTranslateScriptURLFetch(true); 1458 SimulateTranslateScriptURLFetch(true);
1433 // Now the message should have been sent. 1459 // Now the message should have been sent.
1434 int page_id = 0; 1460 int page_id = 0;
1435 std::string original_lang, target_lang; 1461 std::string original_lang, target_lang;
1436 EXPECT_TRUE(GetTranslateMessage(&page_id, &original_lang, &target_lang)); 1462 EXPECT_TRUE(GetTranslateMessage(&page_id, &original_lang, &target_lang));
1437 EXPECT_EQ("es", original_lang); 1463 EXPECT_EQ("es", original_lang);
1438 EXPECT_EQ("en", target_lang); 1464 EXPECT_EQ("en", target_lang);
1439 } 1465 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698