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