| 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/renderer_host/mock_render_process_host.h" | 9 #include "chrome/browser/renderer_host/mock_render_process_host.h" |
| 10 #include "chrome/browser/tab_contents/render_view_context_menu.h" | 10 #include "chrome/browser/tab_contents/render_view_context_menu.h" |
| (...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 296 | 296 |
| 297 // Simulate the render notifying the translation has been done. | 297 // Simulate the render notifying the translation has been done. |
| 298 rvh()->TestOnMessageReceived(ViewHostMsg_PageTranslated(0, 0, "fr", "en", | 298 rvh()->TestOnMessageReceived(ViewHostMsg_PageTranslated(0, 0, "fr", "en", |
| 299 TranslateErrors::NONE)); | 299 TranslateErrors::NONE)); |
| 300 | 300 |
| 301 // The after translate infobar should be showing. | 301 // The after translate infobar should be showing. |
| 302 infobar = GetTranslateInfoBar(); | 302 infobar = GetTranslateInfoBar(); |
| 303 ASSERT_TRUE(infobar != NULL); | 303 ASSERT_TRUE(infobar != NULL); |
| 304 EXPECT_EQ(TranslateInfoBarDelegate2::AFTER_TRANSLATE, infobar->type()); | 304 EXPECT_EQ(TranslateInfoBarDelegate2::AFTER_TRANSLATE, infobar->type()); |
| 305 | 305 |
| 306 // Simulate changing the original language, this should trigger a translation. | 306 // Simulate translating again from there but with 2 different languages. |
| 307 infobar->SetOriginalLanguage(0); |
| 308 infobar->SetTargetLanguage(1); |
| 309 std::string new_original_lang = infobar->GetOriginalLanguageCode(); |
| 310 std::string new_target_lang = infobar->GetTargetLanguageCode(); |
| 307 process()->sink().ClearMessages(); | 311 process()->sink().ClearMessages(); |
| 308 std::string new_original_lang = infobar->GetLanguageCodeAt(0); | 312 infobar->Translate(); |
| 309 infobar->SetOriginalLanguage(0); | |
| 310 EXPECT_TRUE(GetTranslateMessage(&page_id, &original_lang, &target_lang)); | |
| 311 EXPECT_EQ(0, page_id); | |
| 312 EXPECT_EQ(new_original_lang, original_lang); | |
| 313 EXPECT_EQ("en", target_lang); | |
| 314 // Simulate the render notifying the translation has been done. | |
| 315 rvh()->TestOnMessageReceived(ViewHostMsg_PageTranslated(0, 0, | |
| 316 new_original_lang, "en", TranslateErrors::NONE)); | |
| 317 // infobar is now invalid. | |
| 318 TranslateInfoBarDelegate2* new_infobar = GetTranslateInfoBar(); | |
| 319 ASSERT_TRUE(new_infobar != NULL); | |
| 320 EXPECT_NE(infobar, new_infobar); | |
| 321 infobar = new_infobar; | |
| 322 | 313 |
| 323 // Simulate changing the target language, this should trigger a translation. | 314 // Test that we sent the right message to the renderer. |
| 324 process()->sink().ClearMessages(); | |
| 325 std::string new_target_lang = infobar->GetLanguageCodeAt(1); | |
| 326 infobar->SetTargetLanguage(1); | |
| 327 EXPECT_TRUE(GetTranslateMessage(&page_id, &original_lang, &target_lang)); | 315 EXPECT_TRUE(GetTranslateMessage(&page_id, &original_lang, &target_lang)); |
| 328 EXPECT_EQ(0, page_id); | 316 EXPECT_EQ(0, page_id); |
| 329 EXPECT_EQ(new_original_lang, original_lang); | 317 EXPECT_EQ(new_original_lang, original_lang); |
| 330 EXPECT_EQ(new_target_lang, target_lang); | 318 EXPECT_EQ(new_target_lang, target_lang); |
| 331 // Simulate the render notifying the translation has been done. | |
| 332 rvh()->TestOnMessageReceived(ViewHostMsg_PageTranslated(0, 0, | |
| 333 new_original_lang, new_target_lang, TranslateErrors::NONE)); | |
| 334 // infobar is now invalid. | |
| 335 new_infobar = GetTranslateInfoBar(); | |
| 336 ASSERT_TRUE(new_infobar != NULL); | |
| 337 EXPECT_NE(infobar, new_infobar); | |
| 338 } | 319 } |
| 339 | 320 |
| 340 TEST_F(TranslateManager2Test, TranslateScriptNotAvailable) { | 321 TEST_F(TranslateManager2Test, TranslateScriptNotAvailable) { |
| 341 // Simulate navigating to a page. | 322 // Simulate navigating to a page. |
| 342 SimulateNavigation(GURL("http://www.google.fr"), 0, "Le Google", "fr"); | 323 SimulateNavigation(GURL("http://www.google.fr"), 0, "Le Google", "fr"); |
| 343 | 324 |
| 344 // We should have an infobar. | 325 // We should have an infobar. |
| 345 TranslateInfoBarDelegate2* infobar = GetTranslateInfoBar(); | 326 TranslateInfoBarDelegate2* infobar = GetTranslateInfoBar(); |
| 346 ASSERT_TRUE(infobar != NULL); | 327 ASSERT_TRUE(infobar != NULL); |
| 347 EXPECT_EQ(TranslateInfoBarDelegate2::BEFORE_TRANSLATE, infobar->type()); | 328 EXPECT_EQ(TranslateInfoBarDelegate2::BEFORE_TRANSLATE, infobar->type()); |
| (...skipping 572 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 920 EXPECT_FALSE(GetTranslateMessage(&page_id, &original_lang, &target_lang)); | 901 EXPECT_FALSE(GetTranslateMessage(&page_id, &original_lang, &target_lang)); |
| 921 | 902 |
| 922 // Test that the translate context menu is disabled when the page is in the | 903 // Test that the translate context menu is disabled when the page is in the |
| 923 // same language as the UI. | 904 // same language as the UI. |
| 924 SimulateNavigation(url, 0, "Google", "en"); | 905 SimulateNavigation(url, 0, "Google", "en"); |
| 925 menu.reset(TestRenderViewContextMenu::CreateContextMenu(contents())); | 906 menu.reset(TestRenderViewContextMenu::CreateContextMenu(contents())); |
| 926 menu->Init(); | 907 menu->Init(); |
| 927 EXPECT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_TRANSLATE)); | 908 EXPECT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_TRANSLATE)); |
| 928 EXPECT_FALSE(menu->IsCommandIdEnabled(IDC_CONTENT_CONTEXT_TRANSLATE)); | 909 EXPECT_FALSE(menu->IsCommandIdEnabled(IDC_CONTENT_CONTEXT_TRANSLATE)); |
| 929 } | 910 } |
| OLD | NEW |