| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "chrome/browser/renderer_host/test/test_render_view_host.h" | 5 #include "chrome/browser/renderer_host/test/test_render_view_host.h" |
| 6 | 6 |
| 7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
| 8 #include "chrome/app/chrome_dll_resource.h" | 8 #include "chrome/app/chrome_dll_resource.h" |
| 9 #include "chrome/browser/prefs/pref_service.h" | 9 #include "chrome/browser/prefs/pref_service.h" |
| 10 #include "chrome/browser/renderer_host/mock_render_process_host.h" | 10 #include "chrome/browser/renderer_host/mock_render_process_host.h" |
| 11 #include "chrome/browser/tab_contents/navigation_controller.h" |
| 11 #include "chrome/browser/tab_contents/render_view_context_menu.h" | 12 #include "chrome/browser/tab_contents/render_view_context_menu.h" |
| 12 #include "chrome/browser/tab_contents/test_tab_contents.h" | 13 #include "chrome/browser/tab_contents/test_tab_contents.h" |
| 13 #include "chrome/browser/translate/translate_infobar_delegate.h" | 14 #include "chrome/browser/translate/translate_infobar_delegate.h" |
| 14 #include "chrome/browser/translate/translate_manager.h" | 15 #include "chrome/browser/translate/translate_manager.h" |
| 15 #include "chrome/browser/translate/translate_prefs.h" | 16 #include "chrome/browser/translate/translate_prefs.h" |
| 16 #include "chrome/common/ipc_test_sink.h" | 17 #include "chrome/common/ipc_test_sink.h" |
| 17 #include "chrome/common/notification_details.h" | 18 #include "chrome/common/notification_details.h" |
| 18 #include "chrome/common/notification_observer_mock.h" | 19 #include "chrome/common/notification_observer_mock.h" |
| 19 #include "chrome/common/notification_registrar.h" | 20 #include "chrome/common/notification_registrar.h" |
| 20 #include "chrome/common/notification_service.h" | 21 #include "chrome/common/notification_service.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 34 using testing::Property; | 35 using testing::Property; |
| 35 using WebKit::WebContextMenuData; | 36 using WebKit::WebContextMenuData; |
| 36 | 37 |
| 37 class TranslateManagerTest : public RenderViewHostTestHarness, | 38 class TranslateManagerTest : public RenderViewHostTestHarness, |
| 38 public NotificationObserver { | 39 public NotificationObserver { |
| 39 public: | 40 public: |
| 40 TranslateManagerTest() {} | 41 TranslateManagerTest() {} |
| 41 | 42 |
| 42 // Simluates navigating to a page and getting the page contents and language | 43 // Simluates navigating to a page and getting the page contents and language |
| 43 // for that navigation. | 44 // for that navigation. |
| 44 void SimulateNavigation(const GURL& url, int page_id, | 45 void SimulateNavigation(const GURL& url, |
| 45 const std::string& contents, | 46 const std::string& contents, |
| 46 const std::string& lang, | 47 const std::string& lang, |
| 47 bool page_translatable) { | 48 bool page_translatable) { |
| 48 NavigateAndCommit(url); | 49 NavigateAndCommit(url); |
| 50 int page_id = RenderViewHostTestHarness::contents()->controller(). |
| 51 GetLastCommittedEntry()->page_id(); |
| 49 SimulateOnPageContents(url, page_id, contents, lang, page_translatable); | 52 SimulateOnPageContents(url, page_id, contents, lang, page_translatable); |
| 50 } | 53 } |
| 51 | 54 |
| 52 void SimulateOnPageContents(const GURL& url, int page_id, | 55 void SimulateOnPageContents(const GURL& url, int page_id, |
| 53 const std::string& contents, | 56 const std::string& contents, |
| 54 const std::string& lang, | 57 const std::string& lang, |
| 55 bool page_translatable) { | 58 bool page_translatable) { |
| 56 rvh()->TestOnMessageReceived(ViewHostMsg_PageContents(0, url, page_id, | 59 rvh()->TestOnMessageReceived(ViewHostMsg_PageContents(0, url, page_id, |
| 57 UTF8ToUTF16(contents), | 60 UTF8ToUTF16(contents), |
| 58 lang, | 61 lang, |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 TestRenderViewContextMenu(TabContents* tab_contents, | 275 TestRenderViewContextMenu(TabContents* tab_contents, |
| 273 const ContextMenuParams& params) | 276 const ContextMenuParams& params) |
| 274 : RenderViewContextMenu(tab_contents, params) { | 277 : RenderViewContextMenu(tab_contents, params) { |
| 275 } | 278 } |
| 276 | 279 |
| 277 DISALLOW_COPY_AND_ASSIGN(TestRenderViewContextMenu); | 280 DISALLOW_COPY_AND_ASSIGN(TestRenderViewContextMenu); |
| 278 }; | 281 }; |
| 279 | 282 |
| 280 TEST_F(TranslateManagerTest, NormalTranslate) { | 283 TEST_F(TranslateManagerTest, NormalTranslate) { |
| 281 // Simulate navigating to a page. | 284 // Simulate navigating to a page. |
| 282 SimulateNavigation(GURL("http://www.google.fr"), 0, "Le Google", "fr", true); | 285 SimulateNavigation(GURL("http://www.google.fr"), "Le Google", "fr", true); |
| 283 | 286 |
| 284 // We should have an infobar. | 287 // We should have an infobar. |
| 285 TranslateInfoBarDelegate* infobar = GetTranslateInfoBar(); | 288 TranslateInfoBarDelegate* infobar = GetTranslateInfoBar(); |
| 286 ASSERT_TRUE(infobar != NULL); | 289 ASSERT_TRUE(infobar != NULL); |
| 287 EXPECT_EQ(TranslateInfoBarDelegate::BEFORE_TRANSLATE, infobar->type()); | 290 EXPECT_EQ(TranslateInfoBarDelegate::BEFORE_TRANSLATE, infobar->type()); |
| 288 | 291 |
| 289 // Simulate clicking translate. | 292 // Simulate clicking translate. |
| 290 process()->sink().ClearMessages(); | 293 process()->sink().ClearMessages(); |
| 291 infobar->Translate(); | 294 infobar->Translate(); |
| 292 | 295 |
| 293 // The "Translating..." infobar should be showing. | 296 // The "Translating..." infobar should be showing. |
| 294 infobar = GetTranslateInfoBar(); | 297 infobar = GetTranslateInfoBar(); |
| 295 ASSERT_TRUE(infobar != NULL); | 298 ASSERT_TRUE(infobar != NULL); |
| 296 EXPECT_EQ(TranslateInfoBarDelegate::TRANSLATING, infobar->type()); | 299 EXPECT_EQ(TranslateInfoBarDelegate::TRANSLATING, infobar->type()); |
| 297 | 300 |
| 298 // Simulate the translate script being retrieved (it only needs to be done | 301 // Simulate the translate script being retrieved (it only needs to be done |
| 299 // once in the test as it is cached). | 302 // once in the test as it is cached). |
| 300 SimulateURLFetch(true); | 303 SimulateURLFetch(true); |
| 301 | 304 |
| 302 // Test that we sent the right message to the renderer. | 305 // Test that we sent the right message to the renderer. |
| 303 int page_id = 0; | 306 int page_id = 0; |
| 304 std::string original_lang, target_lang; | 307 std::string original_lang, target_lang; |
| 305 EXPECT_TRUE(GetTranslateMessage(&page_id, &original_lang, &target_lang)); | 308 EXPECT_TRUE(GetTranslateMessage(&page_id, &original_lang, &target_lang)); |
| 306 EXPECT_EQ(0, page_id); | |
| 307 EXPECT_EQ("fr", original_lang); | 309 EXPECT_EQ("fr", original_lang); |
| 308 EXPECT_EQ("en", target_lang); | 310 EXPECT_EQ("en", target_lang); |
| 309 | 311 |
| 310 // Simulate the render notifying the translation has been done. | 312 // Simulate the render notifying the translation has been done. |
| 311 rvh()->TestOnMessageReceived(ViewHostMsg_PageTranslated(0, 0, "fr", "en", | 313 rvh()->TestOnMessageReceived(ViewHostMsg_PageTranslated(0, 0, "fr", "en", |
| 312 TranslateErrors::NONE)); | 314 TranslateErrors::NONE)); |
| 313 | 315 |
| 314 // The after translate infobar should be showing. | 316 // The after translate infobar should be showing. |
| 315 infobar = GetTranslateInfoBar(); | 317 infobar = GetTranslateInfoBar(); |
| 316 ASSERT_TRUE(infobar != NULL); | 318 ASSERT_TRUE(infobar != NULL); |
| 317 EXPECT_EQ(TranslateInfoBarDelegate::AFTER_TRANSLATE, infobar->type()); | 319 EXPECT_EQ(TranslateInfoBarDelegate::AFTER_TRANSLATE, infobar->type()); |
| 318 | 320 |
| 319 // Simulate changing the original language, this should trigger a translation. | 321 // Simulate changing the original language, this should trigger a translation. |
| 320 process()->sink().ClearMessages(); | 322 process()->sink().ClearMessages(); |
| 321 std::string new_original_lang = infobar->GetLanguageCodeAt(0); | 323 std::string new_original_lang = infobar->GetLanguageCodeAt(0); |
| 322 infobar->SetOriginalLanguage(0); | 324 infobar->SetOriginalLanguage(0); |
| 323 EXPECT_TRUE(GetTranslateMessage(&page_id, &original_lang, &target_lang)); | 325 EXPECT_TRUE(GetTranslateMessage(&page_id, &original_lang, &target_lang)); |
| 324 EXPECT_EQ(0, page_id); | |
| 325 EXPECT_EQ(new_original_lang, original_lang); | 326 EXPECT_EQ(new_original_lang, original_lang); |
| 326 EXPECT_EQ("en", target_lang); | 327 EXPECT_EQ("en", target_lang); |
| 327 // Simulate the render notifying the translation has been done. | 328 // Simulate the render notifying the translation has been done. |
| 328 rvh()->TestOnMessageReceived(ViewHostMsg_PageTranslated(0, 0, | 329 rvh()->TestOnMessageReceived(ViewHostMsg_PageTranslated(0, 0, |
| 329 new_original_lang, "en", TranslateErrors::NONE)); | 330 new_original_lang, "en", TranslateErrors::NONE)); |
| 330 // infobar is now invalid. | 331 // infobar is now invalid. |
| 331 TranslateInfoBarDelegate* new_infobar = GetTranslateInfoBar(); | 332 TranslateInfoBarDelegate* new_infobar = GetTranslateInfoBar(); |
| 332 ASSERT_TRUE(new_infobar != NULL); | 333 ASSERT_TRUE(new_infobar != NULL); |
| 333 infobar = new_infobar; | 334 infobar = new_infobar; |
| 334 | 335 |
| 335 // Simulate changing the target language, this should trigger a translation. | 336 // Simulate changing the target language, this should trigger a translation. |
| 336 process()->sink().ClearMessages(); | 337 process()->sink().ClearMessages(); |
| 337 std::string new_target_lang = infobar->GetLanguageCodeAt(1); | 338 std::string new_target_lang = infobar->GetLanguageCodeAt(1); |
| 338 infobar->SetTargetLanguage(1); | 339 infobar->SetTargetLanguage(1); |
| 339 EXPECT_TRUE(GetTranslateMessage(&page_id, &original_lang, &target_lang)); | 340 EXPECT_TRUE(GetTranslateMessage(&page_id, &original_lang, &target_lang)); |
| 340 EXPECT_EQ(0, page_id); | |
| 341 EXPECT_EQ(new_original_lang, original_lang); | 341 EXPECT_EQ(new_original_lang, original_lang); |
| 342 EXPECT_EQ(new_target_lang, target_lang); | 342 EXPECT_EQ(new_target_lang, target_lang); |
| 343 // Simulate the render notifying the translation has been done. | 343 // Simulate the render notifying the translation has been done. |
| 344 rvh()->TestOnMessageReceived(ViewHostMsg_PageTranslated(0, 0, | 344 rvh()->TestOnMessageReceived(ViewHostMsg_PageTranslated(0, 0, |
| 345 new_original_lang, new_target_lang, TranslateErrors::NONE)); | 345 new_original_lang, new_target_lang, TranslateErrors::NONE)); |
| 346 // infobar is now invalid. | 346 // infobar is now invalid. |
| 347 new_infobar = GetTranslateInfoBar(); | 347 new_infobar = GetTranslateInfoBar(); |
| 348 ASSERT_TRUE(new_infobar != NULL); | 348 ASSERT_TRUE(new_infobar != NULL); |
| 349 } | 349 } |
| 350 | 350 |
| 351 TEST_F(TranslateManagerTest, TranslateScriptNotAvailable) { | 351 TEST_F(TranslateManagerTest, TranslateScriptNotAvailable) { |
| 352 // Simulate navigating to a page. | 352 // Simulate navigating to a page. |
| 353 SimulateNavigation(GURL("http://www.google.fr"), 0, "Le Google", "fr", true); | 353 SimulateNavigation(GURL("http://www.google.fr"), "Le Google", "fr", true); |
| 354 | 354 |
| 355 // We should have an infobar. | 355 // We should have an infobar. |
| 356 TranslateInfoBarDelegate* infobar = GetTranslateInfoBar(); | 356 TranslateInfoBarDelegate* infobar = GetTranslateInfoBar(); |
| 357 ASSERT_TRUE(infobar != NULL); | 357 ASSERT_TRUE(infobar != NULL); |
| 358 EXPECT_EQ(TranslateInfoBarDelegate::BEFORE_TRANSLATE, infobar->type()); | 358 EXPECT_EQ(TranslateInfoBarDelegate::BEFORE_TRANSLATE, infobar->type()); |
| 359 | 359 |
| 360 // Simulate clicking translate. | 360 // Simulate clicking translate. |
| 361 process()->sink().ClearMessages(); | 361 process()->sink().ClearMessages(); |
| 362 infobar->Translate(); | 362 infobar->Translate(); |
| 363 // Simulate a failure retrieving the translate script. | 363 // Simulate a failure retrieving the translate script. |
| 364 SimulateURLFetch(false); | 364 SimulateURLFetch(false); |
| 365 | 365 |
| 366 // We should not have sent any message to translate to the renderer. | 366 // We should not have sent any message to translate to the renderer. |
| 367 EXPECT_FALSE(GetTranslateMessage(NULL, NULL, NULL)); | 367 EXPECT_FALSE(GetTranslateMessage(NULL, NULL, NULL)); |
| 368 | 368 |
| 369 // And we should have an error infobar showing. | 369 // And we should have an error infobar showing. |
| 370 infobar = GetTranslateInfoBar(); | 370 infobar = GetTranslateInfoBar(); |
| 371 ASSERT_TRUE(infobar != NULL); | 371 ASSERT_TRUE(infobar != NULL); |
| 372 EXPECT_EQ(TranslateInfoBarDelegate::TRANSLATION_ERROR, infobar->type()); | 372 EXPECT_EQ(TranslateInfoBarDelegate::TRANSLATION_ERROR, infobar->type()); |
| 373 } | 373 } |
| 374 | 374 |
| 375 // Ensures we deal correctly with pages for which the browser does not recognize | 375 // Ensures we deal correctly with pages for which the browser does not recognize |
| 376 // the language (the translate server may or not detect the language). | 376 // the language (the translate server may or not detect the language). |
| 377 TEST_F(TranslateManagerTest, TranslateUnknownLanguage) { | 377 TEST_F(TranslateManagerTest, TranslateUnknownLanguage) { |
| 378 // Simulate navigating to a page ("und" is the string returned by the CLD for | 378 // Simulate navigating to a page ("und" is the string returned by the CLD for |
| 379 // languages it does not recognize). | 379 // languages it does not recognize). |
| 380 SimulateNavigation(GURL("http://www.google.mys"), 0, "G00g1e", "und", true); | 380 SimulateNavigation(GURL("http://www.google.mys"), "G00g1e", "und", true); |
| 381 | 381 |
| 382 // We should not have an infobar as we don't know the language. | 382 // We should not have an infobar as we don't know the language. |
| 383 ASSERT_TRUE(GetTranslateInfoBar() == NULL); | 383 ASSERT_TRUE(GetTranslateInfoBar() == NULL); |
| 384 | 384 |
| 385 // Translate the page anyway throught the context menu. | 385 // Translate the page anyway throught the context menu. |
| 386 scoped_ptr<TestRenderViewContextMenu> menu( | 386 scoped_ptr<TestRenderViewContextMenu> menu( |
| 387 TestRenderViewContextMenu::CreateContextMenu(contents())); | 387 TestRenderViewContextMenu::CreateContextMenu(contents())); |
| 388 menu->Init(); | 388 menu->Init(); |
| 389 menu->ExecuteCommand(IDC_CONTENT_CONTEXT_TRANSLATE); | 389 menu->ExecuteCommand(IDC_CONTENT_CONTEXT_TRANSLATE); |
| 390 | 390 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 404 | 404 |
| 405 // The after translate infobar should be showing. | 405 // The after translate infobar should be showing. |
| 406 infobar = GetTranslateInfoBar(); | 406 infobar = GetTranslateInfoBar(); |
| 407 ASSERT_TRUE(infobar != NULL); | 407 ASSERT_TRUE(infobar != NULL); |
| 408 EXPECT_EQ(TranslateInfoBarDelegate::AFTER_TRANSLATE, infobar->type()); | 408 EXPECT_EQ(TranslateInfoBarDelegate::AFTER_TRANSLATE, infobar->type()); |
| 409 EXPECT_EQ("fr", infobar->GetOriginalLanguageCode()); | 409 EXPECT_EQ("fr", infobar->GetOriginalLanguageCode()); |
| 410 EXPECT_EQ("en", infobar->GetTargetLanguageCode()); | 410 EXPECT_EQ("en", infobar->GetTargetLanguageCode()); |
| 411 | 411 |
| 412 // Let's run the same steps but this time the server detects the page is | 412 // Let's run the same steps but this time the server detects the page is |
| 413 // already in English. | 413 // already in English. |
| 414 SimulateNavigation(GURL("http://www.google.com"), 1, "The Google", "und", | 414 SimulateNavigation(GURL("http://www.google.com"), "The Google", "und", true); |
| 415 true); | |
| 416 menu.reset(TestRenderViewContextMenu::CreateContextMenu(contents())); | 415 menu.reset(TestRenderViewContextMenu::CreateContextMenu(contents())); |
| 417 menu->Init(); | 416 menu->Init(); |
| 418 menu->ExecuteCommand(IDC_CONTENT_CONTEXT_TRANSLATE); | 417 menu->ExecuteCommand(IDC_CONTENT_CONTEXT_TRANSLATE); |
| 419 rvh()->TestOnMessageReceived(ViewHostMsg_PageTranslated(1, 0, "en", "en", | 418 rvh()->TestOnMessageReceived(ViewHostMsg_PageTranslated(1, 0, "en", "en", |
| 420 TranslateErrors::IDENTICAL_LANGUAGES)); | 419 TranslateErrors::IDENTICAL_LANGUAGES)); |
| 421 infobar = GetTranslateInfoBar(); | 420 infobar = GetTranslateInfoBar(); |
| 422 ASSERT_TRUE(infobar != NULL); | 421 ASSERT_TRUE(infobar != NULL); |
| 423 EXPECT_EQ(TranslateInfoBarDelegate::TRANSLATION_ERROR, infobar->type()); | 422 EXPECT_EQ(TranslateInfoBarDelegate::TRANSLATION_ERROR, infobar->type()); |
| 424 EXPECT_EQ(TranslateErrors::IDENTICAL_LANGUAGES, infobar->error()); | 423 EXPECT_EQ(TranslateErrors::IDENTICAL_LANGUAGES, infobar->error()); |
| 425 | 424 |
| 426 // Let's run the same steps again but this time the server fails to detect the | 425 // Let's run the same steps again but this time the server fails to detect the |
| 427 // page's language (it returns an empty string). | 426 // page's language (it returns an empty string). |
| 428 SimulateNavigation(GURL("http://www.google.com"), 2, "The Google", "und", | 427 SimulateNavigation(GURL("http://www.google.com"), "The Google", "und", true); |
| 429 true); | |
| 430 menu.reset(TestRenderViewContextMenu::CreateContextMenu(contents())); | 428 menu.reset(TestRenderViewContextMenu::CreateContextMenu(contents())); |
| 431 menu->Init(); | 429 menu->Init(); |
| 432 menu->ExecuteCommand(IDC_CONTENT_CONTEXT_TRANSLATE); | 430 menu->ExecuteCommand(IDC_CONTENT_CONTEXT_TRANSLATE); |
| 433 rvh()->TestOnMessageReceived(ViewHostMsg_PageTranslated(2, 0, "", "en", | 431 rvh()->TestOnMessageReceived(ViewHostMsg_PageTranslated(2, 0, "", "en", |
| 434 TranslateErrors::UNKNOWN_LANGUAGE)); | 432 TranslateErrors::UNKNOWN_LANGUAGE)); |
| 435 infobar = GetTranslateInfoBar(); | 433 infobar = GetTranslateInfoBar(); |
| 436 ASSERT_TRUE(infobar != NULL); | 434 ASSERT_TRUE(infobar != NULL); |
| 437 EXPECT_EQ(TranslateInfoBarDelegate::TRANSLATION_ERROR, infobar->type()); | 435 EXPECT_EQ(TranslateInfoBarDelegate::TRANSLATION_ERROR, infobar->type()); |
| 438 EXPECT_EQ(TranslateErrors::UNKNOWN_LANGUAGE, infobar->error()); | 436 EXPECT_EQ(TranslateErrors::UNKNOWN_LANGUAGE, infobar->error()); |
| 439 } | 437 } |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 504 | 502 |
| 505 // Close the info-bar if applicable. | 503 // Close the info-bar if applicable. |
| 506 if (infobar != NULL) | 504 if (infobar != NULL) |
| 507 EXPECT_TRUE(CloseTranslateInfoBar()); | 505 EXPECT_TRUE(CloseTranslateInfoBar()); |
| 508 } | 506 } |
| 509 } | 507 } |
| 510 | 508 |
| 511 // Tests auto-translate on page. | 509 // Tests auto-translate on page. |
| 512 TEST_F(TranslateManagerTest, AutoTranslateOnNavigate) { | 510 TEST_F(TranslateManagerTest, AutoTranslateOnNavigate) { |
| 513 // Simulate navigating to a page and getting its language. | 511 // Simulate navigating to a page and getting its language. |
| 514 SimulateNavigation(GURL("http://www.google.fr"), 0, "Le Google", "fr", true); | 512 SimulateNavigation(GURL("http://www.google.fr"), "Le Google", "fr", true); |
| 515 | 513 |
| 516 // Simulate the user translating. | 514 // Simulate the user translating. |
| 517 TranslateInfoBarDelegate* infobar = GetTranslateInfoBar(); | 515 TranslateInfoBarDelegate* infobar = GetTranslateInfoBar(); |
| 518 ASSERT_TRUE(infobar != NULL); | 516 ASSERT_TRUE(infobar != NULL); |
| 519 infobar->Translate(); | 517 infobar->Translate(); |
| 520 SimulateURLFetch(true); // Simulate the translate script being retrieved. | 518 SimulateURLFetch(true); // Simulate the translate script being retrieved. |
| 521 | 519 |
| 522 rvh()->TestOnMessageReceived(ViewHostMsg_PageTranslated(0, 0, "fr", "en", | 520 rvh()->TestOnMessageReceived(ViewHostMsg_PageTranslated(0, 0, "fr", "en", |
| 523 TranslateErrors::NONE)); | 521 TranslateErrors::NONE)); |
| 524 | 522 |
| 525 // Now navigate to a new page in the same language. | 523 // Now navigate to a new page in the same language. |
| 526 process()->sink().ClearMessages(); | 524 process()->sink().ClearMessages(); |
| 527 SimulateNavigation(GURL("http://news.google.fr"), 1, "Les news", "fr", true); | 525 SimulateNavigation(GURL("http://news.google.fr"), "Les news", "fr", true); |
| 528 | 526 |
| 529 // This should have automatically triggered a translation. | 527 // This should have automatically triggered a translation. |
| 530 int page_id = 0; | 528 int page_id = 0; |
| 531 std::string original_lang, target_lang; | 529 std::string original_lang, target_lang; |
| 532 EXPECT_TRUE(GetTranslateMessage(&page_id, &original_lang, &target_lang)); | 530 EXPECT_TRUE(GetTranslateMessage(&page_id, &original_lang, &target_lang)); |
| 533 EXPECT_EQ(1, page_id); | 531 EXPECT_EQ(1, page_id); |
| 534 EXPECT_EQ("fr", original_lang); | 532 EXPECT_EQ("fr", original_lang); |
| 535 EXPECT_EQ("en", target_lang); | 533 EXPECT_EQ("en", target_lang); |
| 536 | 534 |
| 537 // Now navigate to a page in a different language. | 535 // Now navigate to a page in a different language. |
| 538 process()->sink().ClearMessages(); | 536 process()->sink().ClearMessages(); |
| 539 SimulateNavigation(GURL("http://news.google.es"), 1, "Las news", "es", true); | 537 SimulateNavigation(GURL("http://news.google.es"), "Las news", "es", true); |
| 540 | 538 |
| 541 // This should not have triggered a translate. | 539 // This should not have triggered a translate. |
| 542 EXPECT_FALSE(GetTranslateMessage(&page_id, &original_lang, &target_lang)); | 540 EXPECT_FALSE(GetTranslateMessage(&page_id, &original_lang, &target_lang)); |
| 543 } | 541 } |
| 544 | 542 |
| 545 // Tests that multiple OnPageContents do not cause multiple infobars. | 543 // Tests that multiple OnPageContents do not cause multiple infobars. |
| 546 TEST_F(TranslateManagerTest, MultipleOnPageContents) { | 544 TEST_F(TranslateManagerTest, MultipleOnPageContents) { |
| 547 // Simulate navigating to a page and getting its language. | 545 // Simulate navigating to a page and getting its language. |
| 548 SimulateNavigation(GURL("http://www.google.fr"), 0, "Le Google", "fr", true); | 546 SimulateNavigation(GURL("http://www.google.fr"), "Le Google", "fr", true); |
| 549 | 547 |
| 550 // Simulate clicking 'Nope' (don't translate). | 548 // Simulate clicking 'Nope' (don't translate). |
| 551 EXPECT_TRUE(DenyTranslation()); | 549 EXPECT_TRUE(DenyTranslation()); |
| 552 EXPECT_EQ(0, contents()->infobar_delegate_count()); | 550 EXPECT_EQ(0, contents()->infobar_delegate_count()); |
| 553 | 551 |
| 554 // Send a new PageContents, we should not show an infobar. | 552 // Send a new PageContents, we should not show an infobar. |
| 555 SimulateOnPageContents(GURL("http://www.google.fr"), 0, "Le Google", "fr", | 553 SimulateOnPageContents(GURL("http://www.google.fr"), 0, "Le Google", "fr", |
| 556 true); | 554 true); |
| 557 EXPECT_EQ(0, contents()->infobar_delegate_count()); | 555 EXPECT_EQ(0, contents()->infobar_delegate_count()); |
| 558 | 556 |
| 559 // Do the same steps but simulate closing the infobar this time. | 557 // Do the same steps but simulate closing the infobar this time. |
| 560 SimulateNavigation(GURL("http://www.youtube.fr"), 1, "Le YouTube", "fr", | 558 SimulateNavigation(GURL("http://www.youtube.fr"), "Le YouTube", "fr", |
| 561 true); | 559 true); |
| 562 EXPECT_TRUE(CloseTranslateInfoBar()); | 560 EXPECT_TRUE(CloseTranslateInfoBar()); |
| 563 EXPECT_EQ(0, contents()->infobar_delegate_count()); | 561 EXPECT_EQ(0, contents()->infobar_delegate_count()); |
| 564 SimulateOnPageContents(GURL("http://www.youtube.fr"), 1, "Le YouTube", "fr", | 562 SimulateOnPageContents(GURL("http://www.youtube.fr"), 1, "Le YouTube", "fr", |
| 565 true); | 563 true); |
| 566 EXPECT_EQ(0, contents()->infobar_delegate_count()); | 564 EXPECT_EQ(0, contents()->infobar_delegate_count()); |
| 567 } | 565 } |
| 568 | 566 |
| 569 // Test that reloading the page brings back the infobar. | 567 // Test that reloading the page brings back the infobar. |
| 570 TEST_F(TranslateManagerTest, Reload) { | 568 TEST_F(TranslateManagerTest, Reload) { |
| 571 // Simulate navigating to a page and getting its language. | 569 // Simulate navigating to a page and getting its language. |
| 572 SimulateNavigation(GURL("http://www.google.fr"), 0, "Le Google", "fr", true); | 570 SimulateNavigation(GURL("http://www.google.fr"), "Le Google", "fr", true); |
| 573 | 571 |
| 574 // Close the infobar. | 572 // Close the infobar. |
| 575 EXPECT_TRUE(CloseTranslateInfoBar()); | 573 EXPECT_TRUE(CloseTranslateInfoBar()); |
| 576 | 574 |
| 577 // Reload should bring back the infobar. | 575 // Reload should bring back the infobar. |
| 578 NavEntryCommittedObserver nav_observer(contents()); | 576 NavEntryCommittedObserver nav_observer(contents()); |
| 579 Reload(); | 577 Reload(); |
| 580 | 578 |
| 581 // Ensures it is really handled a reload. | 579 // Ensures it is really handled a reload. |
| 582 const NavigationController::LoadCommittedDetails& nav_details = | 580 const NavigationController::LoadCommittedDetails& nav_details = |
| 583 nav_observer.get_load_commited_details(); | 581 nav_observer.get_load_commited_details(); |
| 584 EXPECT_TRUE(nav_details.entry != NULL); // There was a navigation. | 582 EXPECT_TRUE(nav_details.entry != NULL); // There was a navigation. |
| 585 EXPECT_EQ(NavigationType::EXISTING_PAGE, nav_details.type); | 583 EXPECT_EQ(NavigationType::EXISTING_PAGE, nav_details.type); |
| 586 | 584 |
| 587 // The TranslateManager class processes the navigation entry committed | 585 // The TranslateManager class processes the navigation entry committed |
| 588 // notification in a posted task; process that task. | 586 // notification in a posted task; process that task. |
| 589 MessageLoop::current()->RunAllPending(); | 587 MessageLoop::current()->RunAllPending(); |
| 590 EXPECT_TRUE(GetTranslateInfoBar() != NULL); | 588 EXPECT_TRUE(GetTranslateInfoBar() != NULL); |
| 591 } | 589 } |
| 592 | 590 |
| 593 // Test that reloading the page by way of typing again the URL in the | 591 // Test that reloading the page by way of typing again the URL in the |
| 594 // location bar brings back the infobar. | 592 // location bar brings back the infobar. |
| 595 TEST_F(TranslateManagerTest, ReloadFromLocationBar) { | 593 TEST_F(TranslateManagerTest, ReloadFromLocationBar) { |
| 596 GURL url("http://www.google.fr"); | 594 GURL url("http://www.google.fr"); |
| 597 | 595 |
| 598 // Simulate navigating to a page and getting its language. | 596 // Simulate navigating to a page and getting its language. |
| 599 SimulateNavigation(url, 0, "Le Google", "fr", true); | 597 SimulateNavigation(url, "Le Google", "fr", true); |
| 600 | 598 |
| 601 // Close the infobar. | 599 // Close the infobar. |
| 602 EXPECT_TRUE(CloseTranslateInfoBar()); | 600 EXPECT_TRUE(CloseTranslateInfoBar()); |
| 603 | 601 |
| 604 // Create a pending navigation and simulate a page load. That should be the | 602 // Create a pending navigation and simulate a page load. That should be the |
| 605 // equivalent of typing the URL again in the location bar. | 603 // equivalent of typing the URL again in the location bar. |
| 606 NavEntryCommittedObserver nav_observer(contents()); | 604 NavEntryCommittedObserver nav_observer(contents()); |
| 607 contents()->controller().LoadURL(url, GURL(), PageTransition::TYPED); | 605 contents()->controller().LoadURL(url, GURL(), PageTransition::TYPED); |
| 608 rvh()->SendNavigate(0, url); | 606 rvh()->SendNavigate(0, url); |
| 609 | 607 |
| 610 // Test that we are really getting a same page navigation, the test would be | 608 // Test that we are really getting a same page navigation, the test would be |
| 611 // useless if it was not the case. | 609 // useless if it was not the case. |
| 612 const NavigationController::LoadCommittedDetails& nav_details = | 610 const NavigationController::LoadCommittedDetails& nav_details = |
| 613 nav_observer.get_load_commited_details(); | 611 nav_observer.get_load_commited_details(); |
| 614 EXPECT_TRUE(nav_details.entry != NULL); // There was a navigation. | 612 EXPECT_TRUE(nav_details.entry != NULL); // There was a navigation. |
| 615 EXPECT_EQ(NavigationType::SAME_PAGE, nav_details.type); | 613 EXPECT_EQ(NavigationType::SAME_PAGE, nav_details.type); |
| 616 | 614 |
| 617 // The TranslateManager class processes the navigation entry committed | 615 // The TranslateManager class processes the navigation entry committed |
| 618 // notification in a posted task; process that task. | 616 // notification in a posted task; process that task. |
| 619 MessageLoop::current()->RunAllPending(); | 617 MessageLoop::current()->RunAllPending(); |
| 620 EXPECT_TRUE(GetTranslateInfoBar() != NULL); | 618 EXPECT_TRUE(GetTranslateInfoBar() != NULL); |
| 621 } | 619 } |
| 622 | 620 |
| 623 // Tests that a closed translate infobar does not reappear when navigating | 621 // Tests that a closed translate infobar does not reappear when navigating |
| 624 // in-page. | 622 // in-page. |
| 625 TEST_F(TranslateManagerTest, CloseInfoBarInPageNavigation) { | 623 TEST_F(TranslateManagerTest, CloseInfoBarInPageNavigation) { |
| 626 // Simulate navigating to a page and getting its language. | 624 // Simulate navigating to a page and getting its language. |
| 627 SimulateNavigation(GURL("http://www.google.fr"), 0, "Le Google", "fr", true); | 625 SimulateNavigation(GURL("http://www.google.fr"), "Le Google", "fr", true); |
| 628 | 626 |
| 629 // Close the infobar. | 627 // Close the infobar. |
| 630 EXPECT_TRUE(CloseTranslateInfoBar()); | 628 EXPECT_TRUE(CloseTranslateInfoBar()); |
| 631 | 629 |
| 632 // Navigate in page, no infobar should be shown. | 630 // Navigate in page, no infobar should be shown. |
| 633 SimulateNavigation(GURL("http://www.google.fr/#ref1"), 0, "Le Google", "fr", | 631 SimulateNavigation(GURL("http://www.google.fr/#ref1"), "Le Google", "fr", |
| 634 true); | 632 true); |
| 635 EXPECT_TRUE(GetTranslateInfoBar() == NULL); | 633 EXPECT_TRUE(GetTranslateInfoBar() == NULL); |
| 636 | 634 |
| 637 // Navigate out of page, a new infobar should show. | 635 // Navigate out of page, a new infobar should show. |
| 638 SimulateNavigation(GURL("http://www.google.fr/foot"), 0, "Le Google", "fr", | 636 SimulateNavigation(GURL("http://www.google.fr/foot"), "Le Google", "fr", |
| 639 true); | 637 true); |
| 640 EXPECT_TRUE(GetTranslateInfoBar() != NULL); | 638 EXPECT_TRUE(GetTranslateInfoBar() != NULL); |
| 641 } | 639 } |
| 642 | 640 |
| 643 // Tests that a closed translate infobar does not reappear when navigating | 641 // Tests that a closed translate infobar does not reappear when navigating |
| 644 // in a subframe. (http://crbug.com/48215) | 642 // in a subframe. (http://crbug.com/48215) |
| 645 TEST_F(TranslateManagerTest, CloseInfoBarInSubframeNavigation) { | 643 TEST_F(TranslateManagerTest, CloseInfoBarInSubframeNavigation) { |
| 646 // Simulate navigating to a page and getting its language. | 644 // Simulate navigating to a page and getting its language. |
| 647 SimulateNavigation(GURL("http://www.google.fr"), 0, "Le Google", "fr", true); | 645 SimulateNavigation(GURL("http://www.google.fr"), "Le Google", "fr", true); |
| 648 | 646 |
| 649 // Close the infobar. | 647 // Close the infobar. |
| 650 EXPECT_TRUE(CloseTranslateInfoBar()); | 648 EXPECT_TRUE(CloseTranslateInfoBar()); |
| 651 | 649 |
| 652 // Simulate a sub-frame auto-navigating. | 650 // Simulate a sub-frame auto-navigating. |
| 653 rvh()->SendNavigateWithTransition(1, GURL("http://pub.com"), | 651 rvh()->SendNavigateWithTransition(1, GURL("http://pub.com"), |
| 654 PageTransition::AUTO_SUBFRAME); | 652 PageTransition::AUTO_SUBFRAME); |
| 655 EXPECT_TRUE(GetTranslateInfoBar() == NULL); | 653 EXPECT_TRUE(GetTranslateInfoBar() == NULL); |
| 656 | 654 |
| 657 // Simulate the user navigating in a sub-frame. | 655 // Simulate the user navigating in a sub-frame. |
| 658 rvh()->SendNavigateWithTransition(2, GURL("http://pub.com"), | 656 rvh()->SendNavigateWithTransition(2, GURL("http://pub.com"), |
| 659 PageTransition::MANUAL_SUBFRAME); | 657 PageTransition::MANUAL_SUBFRAME); |
| 660 EXPECT_TRUE(GetTranslateInfoBar() == NULL); | 658 EXPECT_TRUE(GetTranslateInfoBar() == NULL); |
| 661 | 659 |
| 662 // Navigate out of page, a new infobar should show. | 660 // Navigate out of page, a new infobar should show. |
| 663 SimulateNavigation(GURL("http://www.google.fr/foot"), 3, "Le Google", "fr", | 661 SimulateNavigation(GURL("http://www.google.fr/foot"), "Le Google", "fr", |
| 664 true); | 662 true); |
| 665 EXPECT_TRUE(GetTranslateInfoBar() != NULL); | 663 EXPECT_TRUE(GetTranslateInfoBar() != NULL); |
| 666 } | 664 } |
| 667 | 665 |
| 668 | 666 |
| 669 | 667 |
| 670 // Tests that denying translation is sticky when navigating in page. | 668 // Tests that denying translation is sticky when navigating in page. |
| 671 TEST_F(TranslateManagerTest, DenyTranslateInPageNavigation) { | 669 TEST_F(TranslateManagerTest, DenyTranslateInPageNavigation) { |
| 672 // Simulate navigating to a page and getting its language. | 670 // Simulate navigating to a page and getting its language. |
| 673 SimulateNavigation(GURL("http://www.google.fr"), 0, "Le Google", "fr", true); | 671 SimulateNavigation(GURL("http://www.google.fr"), "Le Google", "fr", true); |
| 674 | 672 |
| 675 // Simulate clicking 'Nope' (don't translate). | 673 // Simulate clicking 'Nope' (don't translate). |
| 676 EXPECT_TRUE(DenyTranslation()); | 674 EXPECT_TRUE(DenyTranslation()); |
| 677 | 675 |
| 678 // Navigate in page, no infobar should be shown. | 676 // Navigate in page, no infobar should be shown. |
| 679 SimulateNavigation(GURL("http://www.google.fr/#ref1"), 0, "Le Google", "fr", | 677 SimulateNavigation(GURL("http://www.google.fr/#ref1"), "Le Google", "fr", |
| 680 true); | 678 true); |
| 681 EXPECT_TRUE(GetTranslateInfoBar() == NULL); | 679 EXPECT_TRUE(GetTranslateInfoBar() == NULL); |
| 682 | 680 |
| 683 // Navigate out of page, a new infobar should show. | 681 // Navigate out of page, a new infobar should show. |
| 684 SimulateNavigation(GURL("http://www.google.fr/foot"), 0, "Le Google", "fr", | 682 SimulateNavigation(GURL("http://www.google.fr/foot"), "Le Google", "fr", |
| 685 true); | 683 true); |
| 686 EXPECT_TRUE(GetTranslateInfoBar() != NULL); | 684 EXPECT_TRUE(GetTranslateInfoBar() != NULL); |
| 687 } | 685 } |
| 688 | 686 |
| 689 // Tests that after translating and closing the infobar, the infobar does not | 687 // Tests that after translating and closing the infobar, the infobar does not |
| 690 // return when navigating in page. | 688 // return when navigating in page. |
| 691 TEST_F(TranslateManagerTest, TranslateCloseInfoBarInPageNavigation) { | 689 TEST_F(TranslateManagerTest, TranslateCloseInfoBarInPageNavigation) { |
| 692 // Simulate navigating to a page and getting its language. | 690 // Simulate navigating to a page and getting its language. |
| 693 SimulateNavigation(GURL("http://www.google.fr"), 0, "Le Google", "fr", true); | 691 SimulateNavigation(GURL("http://www.google.fr"), "Le Google", "fr", true); |
| 694 | 692 |
| 695 // Simulate the user translating. | 693 // Simulate the user translating. |
| 696 TranslateInfoBarDelegate* infobar = GetTranslateInfoBar(); | 694 TranslateInfoBarDelegate* infobar = GetTranslateInfoBar(); |
| 697 ASSERT_TRUE(infobar != NULL); | 695 ASSERT_TRUE(infobar != NULL); |
| 698 infobar->Translate(); | 696 infobar->Translate(); |
| 699 SimulateURLFetch(true); // Simulate the translate script being retrieved. | 697 SimulateURLFetch(true); // Simulate the translate script being retrieved. |
| 700 rvh()->TestOnMessageReceived(ViewHostMsg_PageTranslated(0, 0, "fr", "en", | 698 rvh()->TestOnMessageReceived(ViewHostMsg_PageTranslated(0, 0, "fr", "en", |
| 701 TranslateErrors::NONE)); | 699 TranslateErrors::NONE)); |
| 702 | 700 |
| 703 // Close the infobar. | 701 // Close the infobar. |
| 704 EXPECT_TRUE(CloseTranslateInfoBar()); | 702 EXPECT_TRUE(CloseTranslateInfoBar()); |
| 705 | 703 |
| 706 // Navigate in page, no infobar should be shown. | 704 // Navigate in page, no infobar should be shown. |
| 707 SimulateNavigation(GURL("http://www.google.fr/#ref1"), 0, "Le Google", "fr", | 705 SimulateNavigation(GURL("http://www.google.fr/#ref1"), "Le Google", "fr", |
| 708 true); | 706 true); |
| 709 EXPECT_TRUE(GetTranslateInfoBar() == NULL); | 707 EXPECT_TRUE(GetTranslateInfoBar() == NULL); |
| 710 | 708 |
| 711 // Navigate out of page, a new infobar should show. | 709 // Navigate out of page, a new infobar should show. |
| 712 // Note that we navigate to a page in a different language so we don't trigger | 710 // Note that we navigate to a page in a different language so we don't trigger |
| 713 // the auto-translate feature (it would translate the page automatically and | 711 // the auto-translate feature (it would translate the page automatically and |
| 714 // the before translate inforbar would not be shown). | 712 // the before translate inforbar would not be shown). |
| 715 SimulateNavigation(GURL("http://www.google.de"), 0, "Das Google", "de", true); | 713 SimulateNavigation(GURL("http://www.google.de"), "Das Google", "de", true); |
| 716 EXPECT_TRUE(GetTranslateInfoBar() != NULL); | 714 EXPECT_TRUE(GetTranslateInfoBar() != NULL); |
| 717 } | 715 } |
| 718 | 716 |
| 719 // Tests that the after translate the infobar still shows when navigating | 717 // Tests that the after translate the infobar still shows when navigating |
| 720 // in-page. | 718 // in-page. |
| 721 TEST_F(TranslateManagerTest, TranslateInPageNavigation) { | 719 TEST_F(TranslateManagerTest, TranslateInPageNavigation) { |
| 722 // Simulate navigating to a page and getting its language. | 720 // Simulate navigating to a page and getting its language. |
| 723 SimulateNavigation(GURL("http://www.google.fr"), 0, "Le Google", "fr", true); | 721 SimulateNavigation(GURL("http://www.google.fr"), "Le Google", "fr", true); |
| 724 | 722 |
| 725 // Simulate the user translating. | 723 // Simulate the user translating. |
| 726 TranslateInfoBarDelegate* infobar = GetTranslateInfoBar(); | 724 TranslateInfoBarDelegate* infobar = GetTranslateInfoBar(); |
| 727 ASSERT_TRUE(infobar != NULL); | 725 ASSERT_TRUE(infobar != NULL); |
| 728 infobar->Translate(); | 726 infobar->Translate(); |
| 729 SimulateURLFetch(true); // Simulate the translate script being retrieved. | 727 SimulateURLFetch(true); // Simulate the translate script being retrieved. |
| 730 rvh()->TestOnMessageReceived(ViewHostMsg_PageTranslated(0, 0, "fr", "en", | 728 rvh()->TestOnMessageReceived(ViewHostMsg_PageTranslated(0, 0, "fr", "en", |
| 731 TranslateErrors::NONE)); | 729 TranslateErrors::NONE)); |
| 732 // The after translate infobar is showing. | 730 // The after translate infobar is showing. |
| 733 infobar = GetTranslateInfoBar(); | 731 infobar = GetTranslateInfoBar(); |
| 734 ASSERT_TRUE(infobar != NULL); | 732 ASSERT_TRUE(infobar != NULL); |
| 735 | 733 |
| 736 // Navigate in page, the same infobar should still be shown. | 734 // Navigate in page, the same infobar should still be shown. |
| 737 ClearRemovedInfoBars(); | 735 ClearRemovedInfoBars(); |
| 738 SimulateNavigation(GURL("http://www.google.fr/#ref1"), 0, "Le Google", "fr", | 736 SimulateNavigation(GURL("http://www.google.fr/#ref1"), "Le Google", "fr", |
| 739 true); | 737 true); |
| 740 EXPECT_FALSE(InfoBarRemoved()); | 738 EXPECT_FALSE(InfoBarRemoved()); |
| 741 EXPECT_EQ(infobar, GetTranslateInfoBar()); | 739 EXPECT_EQ(infobar, GetTranslateInfoBar()); |
| 742 | 740 |
| 743 // Navigate out of page, a new infobar should show. | 741 // Navigate out of page, a new infobar should show. |
| 744 // See note in TranslateCloseInfoBarInPageNavigation test on why it is | 742 // See note in TranslateCloseInfoBarInPageNavigation test on why it is |
| 745 // important to navigate to a page in a different language for this test. | 743 // important to navigate to a page in a different language for this test. |
| 746 SimulateNavigation(GURL("http://www.google.de"), 0, "Das Google", "de", true); | 744 SimulateNavigation(GURL("http://www.google.de"), "Das Google", "de", true); |
| 747 // The old infobar is gone. | 745 // The old infobar is gone. |
| 748 EXPECT_TRUE(CheckInfoBarRemovedAndReset(infobar)); | 746 EXPECT_TRUE(CheckInfoBarRemovedAndReset(infobar)); |
| 749 // And there is a new one. | 747 // And there is a new one. |
| 750 EXPECT_TRUE(GetTranslateInfoBar() != NULL); | 748 EXPECT_TRUE(GetTranslateInfoBar() != NULL); |
| 751 } | 749 } |
| 752 | 750 |
| 753 // Tests that no translate infobar is shown when navigating to a page in an | 751 // Tests that no translate infobar is shown when navigating to a page in an |
| 754 // unsupported language. | 752 // unsupported language. |
| 755 TEST_F(TranslateManagerTest, CLDReportsUnsupportedPageLanguage) { | 753 TEST_F(TranslateManagerTest, CLDReportsUnsupportedPageLanguage) { |
| 756 // Simulate navigating to a page and getting an unsupported language. | 754 // Simulate navigating to a page and getting an unsupported language. |
| 757 SimulateNavigation(GURL("http://www.google.com"), 0, "Google", "qbz", true); | 755 SimulateNavigation(GURL("http://www.google.com"), "Google", "qbz", true); |
| 758 | 756 |
| 759 // No info-bar should be shown. | 757 // No info-bar should be shown. |
| 760 EXPECT_TRUE(GetTranslateInfoBar() == NULL); | 758 EXPECT_TRUE(GetTranslateInfoBar() == NULL); |
| 761 } | 759 } |
| 762 | 760 |
| 763 // Tests that we deal correctly with unsupported languages returned by the | 761 // Tests that we deal correctly with unsupported languages returned by the |
| 764 // server. | 762 // server. |
| 765 // The translation server might return a language we don't support. | 763 // The translation server might return a language we don't support. |
| 766 TEST_F(TranslateManagerTest, ServerReportsUnsupportedLanguage) { | 764 TEST_F(TranslateManagerTest, ServerReportsUnsupportedLanguage) { |
| 767 // Simulate navigating to a page and translating it. | 765 // Simulate navigating to a page and translating it. |
| 768 SimulateNavigation(GURL("http://mail.google.fr"), 0, "Le Google", "fr", | 766 SimulateNavigation(GURL("http://mail.google.fr"), "Le Google", "fr", true); |
| 769 true); | |
| 770 TranslateInfoBarDelegate* infobar = GetTranslateInfoBar(); | 767 TranslateInfoBarDelegate* infobar = GetTranslateInfoBar(); |
| 771 ASSERT_TRUE(infobar != NULL); | 768 ASSERT_TRUE(infobar != NULL); |
| 772 process()->sink().ClearMessages(); | 769 process()->sink().ClearMessages(); |
| 773 infobar->Translate(); | 770 infobar->Translate(); |
| 774 SimulateURLFetch(true); | 771 SimulateURLFetch(true); |
| 775 // Simulate the render notifying the translation has been done, but it | 772 // Simulate the render notifying the translation has been done, but it |
| 776 // reports a language we don't support. | 773 // reports a language we don't support. |
| 777 rvh()->TestOnMessageReceived(ViewHostMsg_PageTranslated(0, 0, "qbz", "en", | 774 rvh()->TestOnMessageReceived(ViewHostMsg_PageTranslated(0, 0, "qbz", "en", |
| 778 TranslateErrors::NONE)); | 775 TranslateErrors::NONE)); |
| 779 | 776 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 799 // Tests that no translate infobar is shown when Chrome is in a language that | 796 // Tests that no translate infobar is shown when Chrome is in a language that |
| 800 // the translate server does not support. | 797 // the translate server does not support. |
| 801 TEST_F(TranslateManagerTest, UnsupportedUILanguage) { | 798 TEST_F(TranslateManagerTest, UnsupportedUILanguage) { |
| 802 TestingBrowserProcess* browser_process = | 799 TestingBrowserProcess* browser_process = |
| 803 static_cast<TestingBrowserProcess*>(g_browser_process); | 800 static_cast<TestingBrowserProcess*>(g_browser_process); |
| 804 std::string original_lang = browser_process->GetApplicationLocale(); | 801 std::string original_lang = browser_process->GetApplicationLocale(); |
| 805 browser_process->SetApplicationLocale("qbz"); | 802 browser_process->SetApplicationLocale("qbz"); |
| 806 | 803 |
| 807 // Simulate navigating to a page in a language supported by the translate | 804 // Simulate navigating to a page in a language supported by the translate |
| 808 // server. | 805 // server. |
| 809 SimulateNavigation(GURL("http://www.google.com"), 0, "Google", "en", true); | 806 SimulateNavigation(GURL("http://www.google.com"), "Google", "en", true); |
| 810 | 807 |
| 811 // No info-bar should be shown. | 808 // No info-bar should be shown. |
| 812 EXPECT_TRUE(GetTranslateInfoBar() == NULL); | 809 EXPECT_TRUE(GetTranslateInfoBar() == NULL); |
| 813 | 810 |
| 814 browser_process->SetApplicationLocale(original_lang); | 811 browser_process->SetApplicationLocale(original_lang); |
| 815 } | 812 } |
| 816 | 813 |
| 817 // Tests that the translate enabled preference is honored. | 814 // Tests that the translate enabled preference is honored. |
| 818 TEST_F(TranslateManagerTest, TranslateEnabledPref) { | 815 TEST_F(TranslateManagerTest, TranslateEnabledPref) { |
| 819 // Make sure the pref allows translate. | 816 // Make sure the pref allows translate. |
| 820 PrefService* prefs = contents()->profile()->GetPrefs(); | 817 PrefService* prefs = contents()->profile()->GetPrefs(); |
| 821 prefs->SetBoolean(prefs::kEnableTranslate, true); | 818 prefs->SetBoolean(prefs::kEnableTranslate, true); |
| 822 | 819 |
| 823 // Simulate navigating to a page and getting its language. | 820 // Simulate navigating to a page and getting its language. |
| 824 SimulateNavigation(GURL("http://www.google.fr"), 0, "Le Google", "fr", true); | 821 SimulateNavigation(GURL("http://www.google.fr"), "Le Google", "fr", true); |
| 825 | 822 |
| 826 // An infobar should be shown. | 823 // An infobar should be shown. |
| 827 TranslateInfoBarDelegate* infobar = GetTranslateInfoBar(); | 824 TranslateInfoBarDelegate* infobar = GetTranslateInfoBar(); |
| 828 EXPECT_TRUE(infobar != NULL); | 825 EXPECT_TRUE(infobar != NULL); |
| 829 | 826 |
| 830 // Disable translate. | 827 // Disable translate. |
| 831 prefs->SetBoolean(prefs::kEnableTranslate, false); | 828 prefs->SetBoolean(prefs::kEnableTranslate, false); |
| 832 | 829 |
| 833 // Navigate to a new page, that should close the previous infobar. | 830 // Navigate to a new page, that should close the previous infobar. |
| 834 GURL url("http://www.youtube.fr"); | 831 GURL url("http://www.youtube.fr"); |
| 835 NavigateAndCommit(url); | 832 NavigateAndCommit(url); |
| 836 infobar = GetTranslateInfoBar(); | 833 infobar = GetTranslateInfoBar(); |
| 837 EXPECT_TRUE(infobar == NULL); | 834 EXPECT_TRUE(infobar == NULL); |
| 838 | 835 |
| 839 // Simulate getting the page contents and language, that should not trigger | 836 // Simulate getting the page contents and language, that should not trigger |
| 840 // a translate infobar. | 837 // a translate infobar. |
| 841 SimulateOnPageContents(url, 1, "Le YouTube", "fr", true); | 838 SimulateOnPageContents(url, 1, "Le YouTube", "fr", true); |
| 842 infobar = GetTranslateInfoBar(); | 839 infobar = GetTranslateInfoBar(); |
| 843 EXPECT_TRUE(infobar == NULL); | 840 EXPECT_TRUE(infobar == NULL); |
| 844 } | 841 } |
| 845 | 842 |
| 846 // Tests the "Never translate <language>" pref. | 843 // Tests the "Never translate <language>" pref. |
| 847 TEST_F(TranslateManagerTest, NeverTranslateLanguagePref) { | 844 TEST_F(TranslateManagerTest, NeverTranslateLanguagePref) { |
| 848 // Simulate navigating to a page and getting its language. | 845 // Simulate navigating to a page and getting its language. |
| 849 GURL url("http://www.google.fr"); | 846 GURL url("http://www.google.fr"); |
| 850 SimulateNavigation(url, 0, "Le Google", "fr", true); | 847 SimulateNavigation(url, "Le Google", "fr", true); |
| 851 | 848 |
| 852 // An infobar should be shown. | 849 // An infobar should be shown. |
| 853 EXPECT_TRUE(GetTranslateInfoBar() != NULL); | 850 EXPECT_TRUE(GetTranslateInfoBar() != NULL); |
| 854 | 851 |
| 855 // Select never translate this language. | 852 // Select never translate this language. |
| 856 PrefService* prefs = contents()->profile()->GetPrefs(); | 853 PrefService* prefs = contents()->profile()->GetPrefs(); |
| 857 prefs->AddPrefObserver(TranslatePrefs::kPrefTranslateLanguageBlacklist, | 854 prefs->AddPrefObserver(TranslatePrefs::kPrefTranslateLanguageBlacklist, |
| 858 &pref_observer_); | 855 &pref_observer_); |
| 859 TranslatePrefs translate_prefs(prefs); | 856 TranslatePrefs translate_prefs(prefs); |
| 860 EXPECT_FALSE(translate_prefs.IsLanguageBlacklisted("fr")); | 857 EXPECT_FALSE(translate_prefs.IsLanguageBlacklisted("fr")); |
| 861 EXPECT_TRUE(translate_prefs.CanTranslate(prefs, "fr", url)); | 858 EXPECT_TRUE(translate_prefs.CanTranslate(prefs, "fr", url)); |
| 862 SetPrefObserverExpectation(TranslatePrefs::kPrefTranslateLanguageBlacklist); | 859 SetPrefObserverExpectation(TranslatePrefs::kPrefTranslateLanguageBlacklist); |
| 863 translate_prefs.BlacklistLanguage("fr"); | 860 translate_prefs.BlacklistLanguage("fr"); |
| 864 EXPECT_TRUE(translate_prefs.IsLanguageBlacklisted("fr")); | 861 EXPECT_TRUE(translate_prefs.IsLanguageBlacklisted("fr")); |
| 865 EXPECT_FALSE(translate_prefs.CanTranslate(prefs, "fr", url)); | 862 EXPECT_FALSE(translate_prefs.CanTranslate(prefs, "fr", url)); |
| 866 | 863 |
| 867 // Close the infobar. | 864 // Close the infobar. |
| 868 EXPECT_TRUE(CloseTranslateInfoBar()); | 865 EXPECT_TRUE(CloseTranslateInfoBar()); |
| 869 | 866 |
| 870 // Navigate to a new page also in French. | 867 // Navigate to a new page also in French. |
| 871 SimulateNavigation(GURL("http://wwww.youtube.fr"), 1, "Le YouTube", "fr", | 868 SimulateNavigation(GURL("http://wwww.youtube.fr"), "Le YouTube", "fr", true); |
| 872 true); | |
| 873 | 869 |
| 874 // There should not be a translate infobar. | 870 // There should not be a translate infobar. |
| 875 EXPECT_TRUE(GetTranslateInfoBar() == NULL); | 871 EXPECT_TRUE(GetTranslateInfoBar() == NULL); |
| 876 | 872 |
| 877 // Remove the language from the blacklist. | 873 // Remove the language from the blacklist. |
| 878 SetPrefObserverExpectation(TranslatePrefs::kPrefTranslateLanguageBlacklist); | 874 SetPrefObserverExpectation(TranslatePrefs::kPrefTranslateLanguageBlacklist); |
| 879 translate_prefs.RemoveLanguageFromBlacklist("fr"); | 875 translate_prefs.RemoveLanguageFromBlacklist("fr"); |
| 880 EXPECT_FALSE(translate_prefs.IsLanguageBlacklisted("fr")); | 876 EXPECT_FALSE(translate_prefs.IsLanguageBlacklisted("fr")); |
| 881 EXPECT_TRUE(translate_prefs.CanTranslate(prefs, "fr", url)); | 877 EXPECT_TRUE(translate_prefs.CanTranslate(prefs, "fr", url)); |
| 882 | 878 |
| 883 // Navigate to a page in French. | 879 // Navigate to a page in French. |
| 884 SimulateNavigation(url, 2, "Le Google", "fr", true); | 880 SimulateNavigation(url, "Le Google", "fr", true); |
| 885 | 881 |
| 886 // There should be a translate infobar. | 882 // There should be a translate infobar. |
| 887 EXPECT_TRUE(GetTranslateInfoBar() != NULL); | 883 EXPECT_TRUE(GetTranslateInfoBar() != NULL); |
| 888 prefs->RemovePrefObserver(TranslatePrefs::kPrefTranslateLanguageBlacklist, | 884 prefs->RemovePrefObserver(TranslatePrefs::kPrefTranslateLanguageBlacklist, |
| 889 &pref_observer_); | 885 &pref_observer_); |
| 890 } | 886 } |
| 891 | 887 |
| 892 // Tests the "Never translate this site" pref. | 888 // Tests the "Never translate this site" pref. |
| 893 TEST_F(TranslateManagerTest, NeverTranslateSitePref) { | 889 TEST_F(TranslateManagerTest, NeverTranslateSitePref) { |
| 894 // Simulate navigating to a page and getting its language. | 890 // Simulate navigating to a page and getting its language. |
| 895 GURL url("http://www.google.fr"); | 891 GURL url("http://www.google.fr"); |
| 896 std::string host(url.host()); | 892 std::string host(url.host()); |
| 897 SimulateNavigation(url, 0, "Le Google", "fr", true); | 893 SimulateNavigation(url, "Le Google", "fr", true); |
| 898 | 894 |
| 899 // An infobar should be shown. | 895 // An infobar should be shown. |
| 900 EXPECT_TRUE(GetTranslateInfoBar() != NULL); | 896 EXPECT_TRUE(GetTranslateInfoBar() != NULL); |
| 901 | 897 |
| 902 // Select never translate this site. | 898 // Select never translate this site. |
| 903 PrefService* prefs = contents()->profile()->GetPrefs(); | 899 PrefService* prefs = contents()->profile()->GetPrefs(); |
| 904 prefs->AddPrefObserver(TranslatePrefs::kPrefTranslateSiteBlacklist, | 900 prefs->AddPrefObserver(TranslatePrefs::kPrefTranslateSiteBlacklist, |
| 905 &pref_observer_); | 901 &pref_observer_); |
| 906 TranslatePrefs translate_prefs(prefs); | 902 TranslatePrefs translate_prefs(prefs); |
| 907 EXPECT_FALSE(translate_prefs.IsSiteBlacklisted(host)); | 903 EXPECT_FALSE(translate_prefs.IsSiteBlacklisted(host)); |
| 908 EXPECT_TRUE(translate_prefs.CanTranslate(prefs, "fr", url)); | 904 EXPECT_TRUE(translate_prefs.CanTranslate(prefs, "fr", url)); |
| 909 SetPrefObserverExpectation(TranslatePrefs::kPrefTranslateSiteBlacklist); | 905 SetPrefObserverExpectation(TranslatePrefs::kPrefTranslateSiteBlacklist); |
| 910 translate_prefs.BlacklistSite(host); | 906 translate_prefs.BlacklistSite(host); |
| 911 EXPECT_TRUE(translate_prefs.IsSiteBlacklisted(host)); | 907 EXPECT_TRUE(translate_prefs.IsSiteBlacklisted(host)); |
| 912 EXPECT_FALSE(translate_prefs.CanTranslate(prefs, "fr", url)); | 908 EXPECT_FALSE(translate_prefs.CanTranslate(prefs, "fr", url)); |
| 913 | 909 |
| 914 // Close the infobar. | 910 // Close the infobar. |
| 915 EXPECT_TRUE(CloseTranslateInfoBar()); | 911 EXPECT_TRUE(CloseTranslateInfoBar()); |
| 916 | 912 |
| 917 // Navigate to a new page also on the same site. | 913 // Navigate to a new page also on the same site. |
| 918 SimulateNavigation(GURL("http://www.google.fr/hello"), 1, "Bonjour", "fr", | 914 SimulateNavigation(GURL("http://www.google.fr/hello"), "Bonjour", "fr", true); |
| 919 true); | |
| 920 | 915 |
| 921 // There should not be a translate infobar. | 916 // There should not be a translate infobar. |
| 922 EXPECT_TRUE(GetTranslateInfoBar() == NULL); | 917 EXPECT_TRUE(GetTranslateInfoBar() == NULL); |
| 923 | 918 |
| 924 // Remove the site from the blacklist. | 919 // Remove the site from the blacklist. |
| 925 SetPrefObserverExpectation(TranslatePrefs::kPrefTranslateSiteBlacklist); | 920 SetPrefObserverExpectation(TranslatePrefs::kPrefTranslateSiteBlacklist); |
| 926 translate_prefs.RemoveSiteFromBlacklist(host); | 921 translate_prefs.RemoveSiteFromBlacklist(host); |
| 927 EXPECT_FALSE(translate_prefs.IsSiteBlacklisted(host)); | 922 EXPECT_FALSE(translate_prefs.IsSiteBlacklisted(host)); |
| 928 EXPECT_TRUE(translate_prefs.CanTranslate(prefs, "fr", url)); | 923 EXPECT_TRUE(translate_prefs.CanTranslate(prefs, "fr", url)); |
| 929 | 924 |
| 930 // Navigate to a page in French. | 925 // Navigate to a page in French. |
| 931 SimulateNavigation(url, 0, "Le Google", "fr", true); | 926 SimulateNavigation(url, "Le Google", "fr", true); |
| 932 | 927 |
| 933 // There should be a translate infobar. | 928 // There should be a translate infobar. |
| 934 EXPECT_TRUE(GetTranslateInfoBar() != NULL); | 929 EXPECT_TRUE(GetTranslateInfoBar() != NULL); |
| 935 prefs->RemovePrefObserver(TranslatePrefs::kPrefTranslateSiteBlacklist, | 930 prefs->RemovePrefObserver(TranslatePrefs::kPrefTranslateSiteBlacklist, |
| 936 &pref_observer_); | 931 &pref_observer_); |
| 937 } | 932 } |
| 938 | 933 |
| 939 // Tests the "Always translate this language" pref. | 934 // Tests the "Always translate this language" pref. |
| 940 TEST_F(TranslateManagerTest, AlwaysTranslateLanguagePref) { | 935 TEST_F(TranslateManagerTest, AlwaysTranslateLanguagePref) { |
| 941 // Select always translate French to English. | 936 // Select always translate French to English. |
| 942 PrefService* prefs = contents()->profile()->GetPrefs(); | 937 PrefService* prefs = contents()->profile()->GetPrefs(); |
| 943 prefs->AddPrefObserver(TranslatePrefs::kPrefTranslateWhitelists, | 938 prefs->AddPrefObserver(TranslatePrefs::kPrefTranslateWhitelists, |
| 944 &pref_observer_); | 939 &pref_observer_); |
| 945 TranslatePrefs translate_prefs(prefs); | 940 TranslatePrefs translate_prefs(prefs); |
| 946 SetPrefObserverExpectation(TranslatePrefs::kPrefTranslateWhitelists); | 941 SetPrefObserverExpectation(TranslatePrefs::kPrefTranslateWhitelists); |
| 947 translate_prefs.WhitelistLanguagePair("fr", "en"); | 942 translate_prefs.WhitelistLanguagePair("fr", "en"); |
| 948 | 943 |
| 949 // Load a page in French. | 944 // Load a page in French. |
| 950 SimulateNavigation(GURL("http://www.google.fr"), 0, "Le Google", "fr", true); | 945 SimulateNavigation(GURL("http://www.google.fr"), "Le Google", "fr", true); |
| 951 | 946 |
| 952 // It should have triggered an automatic translation to English. | 947 // It should have triggered an automatic translation to English. |
| 953 | 948 |
| 954 // The translating infobar should be showing. | 949 // The translating infobar should be showing. |
| 955 TranslateInfoBarDelegate* infobar = GetTranslateInfoBar(); | 950 TranslateInfoBarDelegate* infobar = GetTranslateInfoBar(); |
| 956 ASSERT_TRUE(infobar != NULL); | 951 ASSERT_TRUE(infobar != NULL); |
| 957 EXPECT_EQ(TranslateInfoBarDelegate::TRANSLATING, infobar->type()); | 952 EXPECT_EQ(TranslateInfoBarDelegate::TRANSLATING, infobar->type()); |
| 958 | 953 |
| 959 SimulateURLFetch(true); // Simulate the translate script being retrieved. | 954 SimulateURLFetch(true); // Simulate the translate script being retrieved. |
| 960 int page_id = 0; | 955 int page_id = 0; |
| 961 std::string original_lang, target_lang; | 956 std::string original_lang, target_lang; |
| 962 EXPECT_TRUE(GetTranslateMessage(&page_id, &original_lang, &target_lang)); | 957 EXPECT_TRUE(GetTranslateMessage(&page_id, &original_lang, &target_lang)); |
| 963 EXPECT_EQ(0, page_id); | |
| 964 EXPECT_EQ("fr", original_lang); | 958 EXPECT_EQ("fr", original_lang); |
| 965 EXPECT_EQ("en", target_lang); | 959 EXPECT_EQ("en", target_lang); |
| 966 process()->sink().ClearMessages(); | 960 process()->sink().ClearMessages(); |
| 967 | 961 |
| 968 // Try another language, it should not be autotranslated. | 962 // Try another language, it should not be autotranslated. |
| 969 SimulateNavigation(GURL("http://www.google.es"), 1, "El Google", "es", true); | 963 SimulateNavigation(GURL("http://www.google.es"), "El Google", "es", true); |
| 970 EXPECT_FALSE(GetTranslateMessage(&page_id, &original_lang, &target_lang)); | 964 EXPECT_FALSE(GetTranslateMessage(&page_id, &original_lang, &target_lang)); |
| 971 EXPECT_TRUE(GetTranslateInfoBar() != NULL); | 965 EXPECT_TRUE(GetTranslateInfoBar() != NULL); |
| 972 EXPECT_TRUE(CloseTranslateInfoBar()); | 966 EXPECT_TRUE(CloseTranslateInfoBar()); |
| 973 | 967 |
| 974 // Let's switch to incognito mode, it should not be autotranslated in that | 968 // Let's switch to incognito mode, it should not be autotranslated in that |
| 975 // case either. | 969 // case either. |
| 976 TestingProfile* test_profile = | 970 TestingProfile* test_profile = |
| 977 static_cast<TestingProfile*>(contents()->profile()); | 971 static_cast<TestingProfile*>(contents()->profile()); |
| 978 test_profile->set_off_the_record(true); | 972 test_profile->set_off_the_record(true); |
| 979 SimulateNavigation(GURL("http://www.youtube.fr"), 2, "Le YouTube", "fr", | 973 SimulateNavigation(GURL("http://www.youtube.fr"), "Le YouTube", "fr", true); |
| 980 true); | |
| 981 EXPECT_FALSE(GetTranslateMessage(&page_id, &original_lang, &target_lang)); | 974 EXPECT_FALSE(GetTranslateMessage(&page_id, &original_lang, &target_lang)); |
| 982 EXPECT_TRUE(GetTranslateInfoBar() != NULL); | 975 EXPECT_TRUE(GetTranslateInfoBar() != NULL); |
| 983 EXPECT_TRUE(CloseTranslateInfoBar()); | 976 EXPECT_TRUE(CloseTranslateInfoBar()); |
| 984 test_profile->set_off_the_record(false); // Get back to non incognito. | 977 test_profile->set_off_the_record(false); // Get back to non incognito. |
| 985 | 978 |
| 986 // Now revert the always translate pref and make sure we go back to expected | 979 // Now revert the always translate pref and make sure we go back to expected |
| 987 // behavior, which is show a "before translate" infobar. | 980 // behavior, which is show a "before translate" infobar. |
| 988 SetPrefObserverExpectation(TranslatePrefs::kPrefTranslateWhitelists); | 981 SetPrefObserverExpectation(TranslatePrefs::kPrefTranslateWhitelists); |
| 989 translate_prefs.RemoveLanguagePairFromWhitelist("fr", "en"); | 982 translate_prefs.RemoveLanguagePairFromWhitelist("fr", "en"); |
| 990 SimulateNavigation(GURL("http://www.google.fr"), 3, "Le Google", "fr", true); | 983 SimulateNavigation(GURL("http://www.google.fr"), "Le Google", "fr", true); |
| 991 EXPECT_FALSE(GetTranslateMessage(&page_id, &original_lang, &target_lang)); | 984 EXPECT_FALSE(GetTranslateMessage(&page_id, &original_lang, &target_lang)); |
| 992 infobar = GetTranslateInfoBar(); | 985 infobar = GetTranslateInfoBar(); |
| 993 ASSERT_TRUE(infobar != NULL); | 986 ASSERT_TRUE(infobar != NULL); |
| 994 EXPECT_EQ(TranslateInfoBarDelegate::BEFORE_TRANSLATE, infobar->type()); | 987 EXPECT_EQ(TranslateInfoBarDelegate::BEFORE_TRANSLATE, infobar->type()); |
| 995 prefs->RemovePrefObserver(TranslatePrefs::kPrefTranslateWhitelists, | 988 prefs->RemovePrefObserver(TranslatePrefs::kPrefTranslateWhitelists, |
| 996 &pref_observer_); | 989 &pref_observer_); |
| 997 } | 990 } |
| 998 | 991 |
| 999 // Context menu. | 992 // Context menu. |
| 1000 TEST_F(TranslateManagerTest, ContextMenu) { | 993 TEST_F(TranslateManagerTest, ContextMenu) { |
| (...skipping 26 matching lines...) Expand all Loading... |
| 1027 | 1020 |
| 1028 // That should have triggered a translation. | 1021 // That should have triggered a translation. |
| 1029 // The "translating..." infobar should be showing. | 1022 // The "translating..." infobar should be showing. |
| 1030 TranslateInfoBarDelegate* infobar = GetTranslateInfoBar(); | 1023 TranslateInfoBarDelegate* infobar = GetTranslateInfoBar(); |
| 1031 ASSERT_TRUE(infobar != NULL); | 1024 ASSERT_TRUE(infobar != NULL); |
| 1032 EXPECT_EQ(TranslateInfoBarDelegate::TRANSLATING, infobar->type()); | 1025 EXPECT_EQ(TranslateInfoBarDelegate::TRANSLATING, infobar->type()); |
| 1033 SimulateURLFetch(true); // Simulate the translate script being retrieved. | 1026 SimulateURLFetch(true); // Simulate the translate script being retrieved. |
| 1034 int page_id = 0; | 1027 int page_id = 0; |
| 1035 std::string original_lang, target_lang; | 1028 std::string original_lang, target_lang; |
| 1036 EXPECT_TRUE(GetTranslateMessage(&page_id, &original_lang, &target_lang)); | 1029 EXPECT_TRUE(GetTranslateMessage(&page_id, &original_lang, &target_lang)); |
| 1037 EXPECT_EQ(0, page_id); | |
| 1038 EXPECT_EQ("fr", original_lang); | 1030 EXPECT_EQ("fr", original_lang); |
| 1039 EXPECT_EQ("en", target_lang); | 1031 EXPECT_EQ("en", target_lang); |
| 1040 process()->sink().ClearMessages(); | 1032 process()->sink().ClearMessages(); |
| 1041 | 1033 |
| 1042 // This should also have reverted the blacklisting of this site and language. | 1034 // This should also have reverted the blacklisting of this site and language. |
| 1043 EXPECT_FALSE(translate_prefs.IsLanguageBlacklisted("fr")); | 1035 EXPECT_FALSE(translate_prefs.IsLanguageBlacklisted("fr")); |
| 1044 EXPECT_FALSE(translate_prefs.IsSiteBlacklisted(url.host())); | 1036 EXPECT_FALSE(translate_prefs.IsSiteBlacklisted(url.host())); |
| 1045 | 1037 |
| 1046 // Let's simulate the page being translated. | 1038 // Let's simulate the page being translated. |
| 1047 rvh()->TestOnMessageReceived(ViewHostMsg_PageTranslated(0, 0, "fr", "en", | 1039 rvh()->TestOnMessageReceived(ViewHostMsg_PageTranslated(0, 0, "fr", "en", |
| 1048 TranslateErrors::NONE)); | 1040 TranslateErrors::NONE)); |
| 1049 | 1041 |
| 1050 // The translate menu should now be disabled. | 1042 // The translate menu should now be disabled. |
| 1051 menu.reset(TestRenderViewContextMenu::CreateContextMenu(contents())); | 1043 menu.reset(TestRenderViewContextMenu::CreateContextMenu(contents())); |
| 1052 menu->Init(); | 1044 menu->Init(); |
| 1053 EXPECT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_TRANSLATE)); | 1045 EXPECT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_TRANSLATE)); |
| 1054 EXPECT_FALSE(menu->IsCommandIdEnabled(IDC_CONTENT_CONTEXT_TRANSLATE)); | 1046 EXPECT_FALSE(menu->IsCommandIdEnabled(IDC_CONTENT_CONTEXT_TRANSLATE)); |
| 1055 | 1047 |
| 1056 // Test that selecting translate in the context menu WHILE the page is being | 1048 // Test that selecting translate in the context menu WHILE the page is being |
| 1057 // translated does nothing (this could happen if autotranslate kicks-in and | 1049 // translated does nothing (this could happen if autotranslate kicks-in and |
| 1058 // the user selects the menu while the translation is being performed). | 1050 // the user selects the menu while the translation is being performed). |
| 1059 SimulateNavigation(GURL("http://www.google.es"), 1, "El Google", "es", true); | 1051 SimulateNavigation(GURL("http://www.google.es"), "El Google", "es", true); |
| 1060 infobar = GetTranslateInfoBar(); | 1052 infobar = GetTranslateInfoBar(); |
| 1061 ASSERT_TRUE(infobar != NULL); | 1053 ASSERT_TRUE(infobar != NULL); |
| 1062 infobar->Translate(); | 1054 infobar->Translate(); |
| 1063 EXPECT_TRUE(GetTranslateMessage(&page_id, &original_lang, &target_lang)); | 1055 EXPECT_TRUE(GetTranslateMessage(&page_id, &original_lang, &target_lang)); |
| 1064 EXPECT_EQ(1, page_id); | |
| 1065 process()->sink().ClearMessages(); | 1056 process()->sink().ClearMessages(); |
| 1066 menu.reset(TestRenderViewContextMenu::CreateContextMenu(contents())); | 1057 menu.reset(TestRenderViewContextMenu::CreateContextMenu(contents())); |
| 1067 menu->Init(); | 1058 menu->Init(); |
| 1068 EXPECT_TRUE(menu->IsCommandIdEnabled(IDC_CONTENT_CONTEXT_TRANSLATE)); | 1059 EXPECT_TRUE(menu->IsCommandIdEnabled(IDC_CONTENT_CONTEXT_TRANSLATE)); |
| 1069 menu->ExecuteCommand(IDC_CONTENT_CONTEXT_TRANSLATE); | 1060 menu->ExecuteCommand(IDC_CONTENT_CONTEXT_TRANSLATE); |
| 1070 // No message expected since the translation should have been ignored. | 1061 // No message expected since the translation should have been ignored. |
| 1071 EXPECT_FALSE(GetTranslateMessage(&page_id, &original_lang, &target_lang)); | 1062 EXPECT_FALSE(GetTranslateMessage(&page_id, &original_lang, &target_lang)); |
| 1072 | 1063 |
| 1073 // Now test that selecting translate in the context menu AFTER the page has | 1064 // Now test that selecting translate in the context menu AFTER the page has |
| 1074 // been translated does nothing. | 1065 // been translated does nothing. |
| 1075 SimulateNavigation(GURL("http://www.google.de"), 2, "Das Google", "de", true); | 1066 SimulateNavigation(GURL("http://www.google.de"), "Das Google", "de", true); |
| 1076 infobar = GetTranslateInfoBar(); | 1067 infobar = GetTranslateInfoBar(); |
| 1077 ASSERT_TRUE(infobar != NULL); | 1068 ASSERT_TRUE(infobar != NULL); |
| 1078 infobar->Translate(); | 1069 infobar->Translate(); |
| 1079 EXPECT_TRUE(GetTranslateMessage(&page_id, &original_lang, &target_lang)); | 1070 EXPECT_TRUE(GetTranslateMessage(&page_id, &original_lang, &target_lang)); |
| 1080 EXPECT_EQ(2, page_id); | |
| 1081 process()->sink().ClearMessages(); | 1071 process()->sink().ClearMessages(); |
| 1082 menu.reset(TestRenderViewContextMenu::CreateContextMenu(contents())); | 1072 menu.reset(TestRenderViewContextMenu::CreateContextMenu(contents())); |
| 1083 menu->Init(); | 1073 menu->Init(); |
| 1084 EXPECT_TRUE(menu->IsCommandIdEnabled(IDC_CONTENT_CONTEXT_TRANSLATE)); | 1074 EXPECT_TRUE(menu->IsCommandIdEnabled(IDC_CONTENT_CONTEXT_TRANSLATE)); |
| 1085 rvh()->TestOnMessageReceived(ViewHostMsg_PageTranslated(0, 0, "de", "en", | 1075 rvh()->TestOnMessageReceived(ViewHostMsg_PageTranslated(0, 0, "de", "en", |
| 1086 TranslateErrors::NONE)); | 1076 TranslateErrors::NONE)); |
| 1087 menu->ExecuteCommand(IDC_CONTENT_CONTEXT_TRANSLATE); | 1077 menu->ExecuteCommand(IDC_CONTENT_CONTEXT_TRANSLATE); |
| 1088 // No message expected since the translation should have been ignored. | 1078 // No message expected since the translation should have been ignored. |
| 1089 EXPECT_FALSE(GetTranslateMessage(&page_id, &original_lang, &target_lang)); | 1079 EXPECT_FALSE(GetTranslateMessage(&page_id, &original_lang, &target_lang)); |
| 1090 | 1080 |
| 1091 // Test that the translate context menu is disabled when the page is in the | 1081 // Test that the translate context menu is disabled when the page is in the |
| 1092 // same language as the UI. | 1082 // same language as the UI. |
| 1093 SimulateNavigation(url, 0, "Google", "en", true); | 1083 SimulateNavigation(url, "Google", "en", true); |
| 1094 menu.reset(TestRenderViewContextMenu::CreateContextMenu(contents())); | 1084 menu.reset(TestRenderViewContextMenu::CreateContextMenu(contents())); |
| 1095 menu->Init(); | 1085 menu->Init(); |
| 1096 EXPECT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_TRANSLATE)); | 1086 EXPECT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_TRANSLATE)); |
| 1097 EXPECT_FALSE(menu->IsCommandIdEnabled(IDC_CONTENT_CONTEXT_TRANSLATE)); | 1087 EXPECT_FALSE(menu->IsCommandIdEnabled(IDC_CONTENT_CONTEXT_TRANSLATE)); |
| 1098 | 1088 |
| 1099 // Test that the translate context menu is enabled when the page is in an | 1089 // Test that the translate context menu is enabled when the page is in an |
| 1100 // unknown language. | 1090 // unknown language. |
| 1101 SimulateNavigation(url, 0, "G00g1e", "und", true); | 1091 SimulateNavigation(url, "G00g1e", "und", true); |
| 1102 menu.reset(TestRenderViewContextMenu::CreateContextMenu(contents())); | 1092 menu.reset(TestRenderViewContextMenu::CreateContextMenu(contents())); |
| 1103 menu->Init(); | 1093 menu->Init(); |
| 1104 EXPECT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_TRANSLATE)); | 1094 EXPECT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_TRANSLATE)); |
| 1105 EXPECT_TRUE(menu->IsCommandIdEnabled(IDC_CONTENT_CONTEXT_TRANSLATE)); | 1095 EXPECT_TRUE(menu->IsCommandIdEnabled(IDC_CONTENT_CONTEXT_TRANSLATE)); |
| 1106 | 1096 |
| 1107 // Test that the translate context menu is disabled when the page is in an | 1097 // Test that the translate context menu is disabled when the page is in an |
| 1108 // unsupported language. | 1098 // unsupported language. |
| 1109 SimulateNavigation(url, 0, "G00g1e", "qbz", true); | 1099 SimulateNavigation(url, "G00g1e", "qbz", true); |
| 1110 menu.reset(TestRenderViewContextMenu::CreateContextMenu(contents())); | 1100 menu.reset(TestRenderViewContextMenu::CreateContextMenu(contents())); |
| 1111 menu->Init(); | 1101 menu->Init(); |
| 1112 EXPECT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_TRANSLATE)); | 1102 EXPECT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_TRANSLATE)); |
| 1113 EXPECT_FALSE(menu->IsCommandIdEnabled(IDC_CONTENT_CONTEXT_TRANSLATE)); | 1103 EXPECT_FALSE(menu->IsCommandIdEnabled(IDC_CONTENT_CONTEXT_TRANSLATE)); |
| 1114 } | 1104 } |
| 1115 | 1105 |
| 1116 // Tests that an extra always/never translate button is shown on the "before | 1106 // Tests that an extra always/never translate button is shown on the "before |
| 1117 // translate" infobar when the translation is accepted/declined 3 times, | 1107 // translate" infobar when the translation is accepted/declined 3 times, |
| 1118 // only when not in incognito mode. | 1108 // only when not in incognito mode. |
| 1119 TEST_F(TranslateManagerTest, BeforeTranslateExtraButtons) { | 1109 TEST_F(TranslateManagerTest, BeforeTranslateExtraButtons) { |
| 1120 TranslatePrefs translate_prefs(contents()->profile()->GetPrefs()); | 1110 TranslatePrefs translate_prefs(contents()->profile()->GetPrefs()); |
| 1121 translate_prefs.ResetTranslationAcceptedCount("fr"); | 1111 translate_prefs.ResetTranslationAcceptedCount("fr"); |
| 1122 translate_prefs.ResetTranslationDeniedCount("fr"); | 1112 translate_prefs.ResetTranslationDeniedCount("fr"); |
| 1123 translate_prefs.ResetTranslationAcceptedCount("de"); | 1113 translate_prefs.ResetTranslationAcceptedCount("de"); |
| 1124 translate_prefs.ResetTranslationDeniedCount("de"); | 1114 translate_prefs.ResetTranslationDeniedCount("de"); |
| 1125 | 1115 |
| 1126 // We'll do 4 times in incognito mode first to make sure the button is not | 1116 // We'll do 4 times in incognito mode first to make sure the button is not |
| 1127 // shown in that case, then 4 times in normal mode. | 1117 // shown in that case, then 4 times in normal mode. |
| 1128 TranslateInfoBarDelegate* infobar; | 1118 TranslateInfoBarDelegate* infobar; |
| 1129 TestingProfile* test_profile = | 1119 TestingProfile* test_profile = |
| 1130 static_cast<TestingProfile*>(contents()->profile()); | 1120 static_cast<TestingProfile*>(contents()->profile()); |
| 1131 test_profile->set_off_the_record(true); | 1121 test_profile->set_off_the_record(true); |
| 1132 for (int i = 0; i < 8; ++i) { | 1122 for (int i = 0; i < 8; ++i) { |
| 1133 SCOPED_TRACE(::testing::Message::Message() << "Iteration " << i << | 1123 SCOPED_TRACE(::testing::Message::Message() << "Iteration " << i << |
| 1134 " incognito mode=" << test_profile->IsOffTheRecord()); | 1124 " incognito mode=" << test_profile->IsOffTheRecord()); |
| 1135 SimulateNavigation(GURL("http://www.google.fr"), 1, "Le Google", "fr", | 1125 SimulateNavigation(GURL("http://www.google.fr"), "Le Google", "fr", true); |
| 1136 true); | |
| 1137 infobar = GetTranslateInfoBar(); | 1126 infobar = GetTranslateInfoBar(); |
| 1138 ASSERT_TRUE(infobar != NULL); | 1127 ASSERT_TRUE(infobar != NULL); |
| 1139 EXPECT_EQ(TranslateInfoBarDelegate::BEFORE_TRANSLATE, infobar->type()); | 1128 EXPECT_EQ(TranslateInfoBarDelegate::BEFORE_TRANSLATE, infobar->type()); |
| 1140 if (i < 7) { | 1129 if (i < 7) { |
| 1141 EXPECT_FALSE(infobar->ShouldShowAlwaysTranslateButton()); | 1130 EXPECT_FALSE(infobar->ShouldShowAlwaysTranslateButton()); |
| 1142 infobar->Translate(); | 1131 infobar->Translate(); |
| 1143 process()->sink().ClearMessages(); | 1132 process()->sink().ClearMessages(); |
| 1144 } else { | 1133 } else { |
| 1145 EXPECT_TRUE(infobar->ShouldShowAlwaysTranslateButton()); | 1134 EXPECT_TRUE(infobar->ShouldShowAlwaysTranslateButton()); |
| 1146 } | 1135 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1158 std::string original_lang, target_lang; | 1147 std::string original_lang, target_lang; |
| 1159 EXPECT_TRUE(GetTranslateMessage(&page_id, &original_lang, &target_lang)); | 1148 EXPECT_TRUE(GetTranslateMessage(&page_id, &original_lang, &target_lang)); |
| 1160 process()->sink().ClearMessages(); | 1149 process()->sink().ClearMessages(); |
| 1161 | 1150 |
| 1162 // Now test that declining the translation causes a "never translate" button | 1151 // Now test that declining the translation causes a "never translate" button |
| 1163 // to be shown (in non incognito mode only). | 1152 // to be shown (in non incognito mode only). |
| 1164 test_profile->set_off_the_record(true); | 1153 test_profile->set_off_the_record(true); |
| 1165 for (int i = 0; i < 8; ++i) { | 1154 for (int i = 0; i < 8; ++i) { |
| 1166 SCOPED_TRACE(::testing::Message::Message() << "Iteration " << i << | 1155 SCOPED_TRACE(::testing::Message::Message() << "Iteration " << i << |
| 1167 " incognito mode=" << test_profile->IsOffTheRecord()); | 1156 " incognito mode=" << test_profile->IsOffTheRecord()); |
| 1168 SimulateNavigation(GURL("http://www.google.de"), 1, "Das Google", "de", | 1157 SimulateNavigation(GURL("http://www.google.de"), "Das Google", "de", true); |
| 1169 true); | |
| 1170 infobar = GetTranslateInfoBar(); | 1158 infobar = GetTranslateInfoBar(); |
| 1171 ASSERT_TRUE(infobar != NULL); | 1159 ASSERT_TRUE(infobar != NULL); |
| 1172 EXPECT_EQ(TranslateInfoBarDelegate::BEFORE_TRANSLATE, infobar->type()); | 1160 EXPECT_EQ(TranslateInfoBarDelegate::BEFORE_TRANSLATE, infobar->type()); |
| 1173 if (i < 7) { | 1161 if (i < 7) { |
| 1174 EXPECT_FALSE(infobar->ShouldShowNeverTranslateButton()); | 1162 EXPECT_FALSE(infobar->ShouldShowNeverTranslateButton()); |
| 1175 infobar->TranslationDeclined(); | 1163 infobar->TranslationDeclined(); |
| 1176 } else { | 1164 } else { |
| 1177 EXPECT_TRUE(infobar->ShouldShowNeverTranslateButton()); | 1165 EXPECT_TRUE(infobar->ShouldShowNeverTranslateButton()); |
| 1178 } | 1166 } |
| 1179 if (i == 3) | 1167 if (i == 3) |
| 1180 test_profile->set_off_the_record(false); | 1168 test_profile->set_off_the_record(false); |
| 1181 } | 1169 } |
| 1182 // Simulate the user pressing "Never translate French". | 1170 // Simulate the user pressing "Never translate French". |
| 1183 infobar->NeverTranslatePageLanguage(); | 1171 infobar->NeverTranslatePageLanguage(); |
| 1184 EXPECT_TRUE(translate_prefs.IsLanguageBlacklisted("de")); | 1172 EXPECT_TRUE(translate_prefs.IsLanguageBlacklisted("de")); |
| 1185 // No translation should have occured and the infobar should be gone. | 1173 // No translation should have occured and the infobar should be gone. |
| 1186 EXPECT_FALSE(GetTranslateMessage(&page_id, &original_lang, &target_lang)); | 1174 EXPECT_FALSE(GetTranslateMessage(&page_id, &original_lang, &target_lang)); |
| 1187 process()->sink().ClearMessages(); | 1175 process()->sink().ClearMessages(); |
| 1188 ASSERT_TRUE(GetTranslateInfoBar() == NULL); | 1176 ASSERT_TRUE(GetTranslateInfoBar() == NULL); |
| 1189 } | 1177 } |
| 1190 | 1178 |
| 1191 // Tests that we don't show a translate infobar when a page instructs that it | 1179 // Tests that we don't show a translate infobar when a page instructs that it |
| 1192 // should not be translated. | 1180 // should not be translated. |
| 1193 TEST_F(TranslateManagerTest, NonTranslatablePage) { | 1181 TEST_F(TranslateManagerTest, NonTranslatablePage) { |
| 1194 // Simulate navigating to a page. | 1182 // Simulate navigating to a page. |
| 1195 SimulateNavigation(GURL("http://mail.google.fr"), 0, "Le Google", "fr", | 1183 SimulateNavigation(GURL("http://mail.google.fr"), "Le Google", "fr", false); |
| 1196 false); | |
| 1197 | 1184 |
| 1198 // We should not have an infobar. | 1185 // We should not have an infobar. |
| 1199 EXPECT_TRUE(GetTranslateInfoBar() == NULL); | 1186 EXPECT_TRUE(GetTranslateInfoBar() == NULL); |
| 1200 | 1187 |
| 1201 // The context menu should be disabled. | 1188 // The context menu should be disabled. |
| 1202 scoped_ptr<TestRenderViewContextMenu> menu( | 1189 scoped_ptr<TestRenderViewContextMenu> menu( |
| 1203 TestRenderViewContextMenu::CreateContextMenu(contents())); | 1190 TestRenderViewContextMenu::CreateContextMenu(contents())); |
| 1204 menu->Init(); | 1191 menu->Init(); |
| 1205 EXPECT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_TRANSLATE)); | 1192 EXPECT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_TRANSLATE)); |
| 1206 EXPECT_FALSE(menu->IsCommandIdEnabled(IDC_CONTENT_CONTEXT_TRANSLATE)); | 1193 EXPECT_FALSE(menu->IsCommandIdEnabled(IDC_CONTENT_CONTEXT_TRANSLATE)); |
| 1207 } | 1194 } |
| 1208 | 1195 |
| 1209 // Tests that the script is expired and refetched as expected. | 1196 // Tests that the script is expired and refetched as expected. |
| 1210 TEST_F(TranslateManagerTest, ScriptExpires) { | 1197 TEST_F(TranslateManagerTest, ScriptExpires) { |
| 1211 ExpireTranslateScriptImmediately(); | 1198 ExpireTranslateScriptImmediately(); |
| 1212 | 1199 |
| 1213 // Simulate navigating to a page and translating it. | 1200 // Simulate navigating to a page and translating it. |
| 1214 SimulateNavigation(GURL("http://www.google.fr"), 0, "Le Google", "fr", true); | 1201 SimulateNavigation(GURL("http://www.google.fr"), "Le Google", "fr", true); |
| 1215 TranslateInfoBarDelegate* infobar = GetTranslateInfoBar(); | 1202 TranslateInfoBarDelegate* infobar = GetTranslateInfoBar(); |
| 1216 ASSERT_TRUE(infobar != NULL); | 1203 ASSERT_TRUE(infobar != NULL); |
| 1217 process()->sink().ClearMessages(); | 1204 process()->sink().ClearMessages(); |
| 1218 infobar->Translate(); | 1205 infobar->Translate(); |
| 1219 SimulateURLFetch(true); | 1206 SimulateURLFetch(true); |
| 1220 rvh()->TestOnMessageReceived(ViewHostMsg_PageTranslated(0, 0, "fr", "en", | 1207 rvh()->TestOnMessageReceived(ViewHostMsg_PageTranslated(0, 0, "fr", "en", |
| 1221 TranslateErrors::NONE)); | 1208 TranslateErrors::NONE)); |
| 1222 | 1209 |
| 1223 // A task should have been posted to clear the script, run it. | 1210 // A task should have been posted to clear the script, run it. |
| 1224 MessageLoop::current()->RunAllPending(); | 1211 MessageLoop::current()->RunAllPending(); |
| 1225 | 1212 |
| 1226 // Do another navigation and translation. | 1213 // Do another navigation and translation. |
| 1227 SimulateNavigation(GURL("http://www.google.es"), 1, "El Google", "es", true); | 1214 SimulateNavigation(GURL("http://www.google.es"), "El Google", "es", true); |
| 1228 infobar = GetTranslateInfoBar(); | 1215 infobar = GetTranslateInfoBar(); |
| 1229 ASSERT_TRUE(infobar != NULL); | 1216 ASSERT_TRUE(infobar != NULL); |
| 1230 process()->sink().ClearMessages(); | 1217 process()->sink().ClearMessages(); |
| 1231 infobar->Translate(); | 1218 infobar->Translate(); |
| 1232 // If we don't simulate the URL fetch, the TranslateManager should be waiting | 1219 // If we don't simulate the URL fetch, the TranslateManager should be waiting |
| 1233 // for the script and no message should have been sent to the renderer. | 1220 // for the script and no message should have been sent to the renderer. |
| 1234 EXPECT_TRUE( | 1221 EXPECT_TRUE( |
| 1235 process()->sink().GetFirstMessageMatching(ViewMsg_TranslatePage::ID) == | 1222 process()->sink().GetFirstMessageMatching(ViewMsg_TranslatePage::ID) == |
| 1236 NULL); | 1223 NULL); |
| 1237 // Now simulate the URL fetch. | 1224 // Now simulate the URL fetch. |
| 1238 SimulateURLFetch(true); | 1225 SimulateURLFetch(true); |
| 1239 // Now the message should have been sent. | 1226 // Now the message should have been sent. |
| 1240 int page_id = 0; | 1227 int page_id = 0; |
| 1241 std::string original_lang, target_lang; | 1228 std::string original_lang, target_lang; |
| 1242 EXPECT_TRUE(GetTranslateMessage(&page_id, &original_lang, &target_lang)); | 1229 EXPECT_TRUE(GetTranslateMessage(&page_id, &original_lang, &target_lang)); |
| 1243 EXPECT_EQ(1, page_id); | |
| 1244 EXPECT_EQ("es", original_lang); | 1230 EXPECT_EQ("es", original_lang); |
| 1245 EXPECT_EQ("en", target_lang); | 1231 EXPECT_EQ("en", target_lang); |
| 1246 } | 1232 } |
| OLD | NEW |