| 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/common/chrome_constants.h" | 5 #include "chrome/common/chrome_constants.h" |
| 6 #include "chrome/common/render_messages.h" | 6 #include "chrome/common/render_messages.h" |
| 7 #include "chrome/renderer/translate_helper.h" | 7 #include "chrome/renderer/translate_helper.h" |
| 8 #include "chrome/test/base/render_view_test.h" | 8 #include "chrome/test/base/render_view_test.h" |
| 9 #include "testing/gmock/include/gmock/gmock.h" | 9 #include "testing/gmock/include/gmock/gmock.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 virtual void SetUp() { | 46 virtual void SetUp() { |
| 47 RenderViewTest::SetUp(); | 47 RenderViewTest::SetUp(); |
| 48 translate_helper_ = new TestTranslateHelper(view_); | 48 translate_helper_ = new TestTranslateHelper(view_); |
| 49 } | 49 } |
| 50 | 50 |
| 51 bool GetPageTranslatedMessage(int* page_id, | 51 bool GetPageTranslatedMessage(int* page_id, |
| 52 std::string* original_lang, | 52 std::string* original_lang, |
| 53 std::string* target_lang, | 53 std::string* target_lang, |
| 54 TranslateErrors::Type* error) { | 54 TranslateErrors::Type* error) { |
| 55 const IPC::Message* message = render_thread_.sink(). | 55 const IPC::Message* message = render_thread_.sink(). |
| 56 GetUniqueMessageMatching(ViewHostMsg_PageTranslated::ID); | 56 GetUniqueMessageMatching(ChromeViewHostMsg_PageTranslated::ID); |
| 57 if (!message) | 57 if (!message) |
| 58 return false; | 58 return false; |
| 59 Tuple4<int, std::string, std::string, TranslateErrors::Type> | 59 Tuple4<int, std::string, std::string, TranslateErrors::Type> |
| 60 translate_param; | 60 translate_param; |
| 61 ViewHostMsg_PageTranslated::Read(message, &translate_param); | 61 ChromeViewHostMsg_PageTranslated::Read(message, &translate_param); |
| 62 if (page_id) | 62 if (page_id) |
| 63 *page_id = translate_param.a; | 63 *page_id = translate_param.a; |
| 64 if (original_lang) | 64 if (original_lang) |
| 65 *original_lang = translate_param.b; | 65 *original_lang = translate_param.b; |
| 66 if (target_lang) | 66 if (target_lang) |
| 67 *target_lang = translate_param.c; | 67 *target_lang = translate_param.c; |
| 68 if (error) | 68 if (error) |
| 69 *error = translate_param.d; | 69 *error = translate_param.d; |
| 70 return true; | 70 return true; |
| 71 } | 71 } |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 // Tests that we send the right translatable for a page and that we respect the | 297 // Tests that we send the right translatable for a page and that we respect the |
| 298 // "no translate" meta-tag. | 298 // "no translate" meta-tag. |
| 299 TEST_F(RenderViewTest, TranslatablePage) { | 299 TEST_F(RenderViewTest, TranslatablePage) { |
| 300 // Suppress the normal delay that occurs when the page is loaded before which | 300 // Suppress the normal delay that occurs when the page is loaded before which |
| 301 // the renderer sends the page contents to the browser. | 301 // the renderer sends the page contents to the browser. |
| 302 view_->set_send_content_state_immediately(true); | 302 view_->set_send_content_state_immediately(true); |
| 303 | 303 |
| 304 LoadHTML("<html><body>A random page with random content.</body></html>"); | 304 LoadHTML("<html><body>A random page with random content.</body></html>"); |
| 305 ProcessPendingMessages(); | 305 ProcessPendingMessages(); |
| 306 const IPC::Message* message = render_thread_.sink().GetUniqueMessageMatching( | 306 const IPC::Message* message = render_thread_.sink().GetUniqueMessageMatching( |
| 307 ViewHostMsg_TranslateLanguageDetermined::ID); | 307 ChromeViewHostMsg_TranslateLanguageDetermined::ID); |
| 308 ASSERT_NE(static_cast<IPC::Message*>(NULL), message); | 308 ASSERT_NE(static_cast<IPC::Message*>(NULL), message); |
| 309 ViewHostMsg_TranslateLanguageDetermined::Param params; | 309 ChromeViewHostMsg_TranslateLanguageDetermined::Param params; |
| 310 ViewHostMsg_TranslateLanguageDetermined::Read(message, ¶ms); | 310 ChromeViewHostMsg_TranslateLanguageDetermined::Read(message, ¶ms); |
| 311 EXPECT_TRUE(params.b); // Translatable should be true. | 311 EXPECT_TRUE(params.b); // Translatable should be true. |
| 312 render_thread_.sink().ClearMessages(); | 312 render_thread_.sink().ClearMessages(); |
| 313 | 313 |
| 314 // Now the page specifies the META tag to prevent translation. | 314 // Now the page specifies the META tag to prevent translation. |
| 315 LoadHTML("<html><head><meta name=\"google\" value=\"notranslate\"></head>" | 315 LoadHTML("<html><head><meta name=\"google\" value=\"notranslate\"></head>" |
| 316 "<body>A random page with random content.</body></html>"); | 316 "<body>A random page with random content.</body></html>"); |
| 317 ProcessPendingMessages(); | 317 ProcessPendingMessages(); |
| 318 message = render_thread_.sink().GetUniqueMessageMatching( | 318 message = render_thread_.sink().GetUniqueMessageMatching( |
| 319 ViewHostMsg_TranslateLanguageDetermined::ID); | 319 ChromeViewHostMsg_TranslateLanguageDetermined::ID); |
| 320 ASSERT_NE(static_cast<IPC::Message*>(NULL), message); | 320 ASSERT_NE(static_cast<IPC::Message*>(NULL), message); |
| 321 ViewHostMsg_TranslateLanguageDetermined::Read(message, ¶ms); | 321 ChromeViewHostMsg_TranslateLanguageDetermined::Read(message, ¶ms); |
| 322 EXPECT_FALSE(params.b); // Translatable should be false. | 322 EXPECT_FALSE(params.b); // Translatable should be false. |
| 323 render_thread_.sink().ClearMessages(); | 323 render_thread_.sink().ClearMessages(); |
| 324 | 324 |
| 325 // Try the alternate version of the META tag (content instead of value). | 325 // Try the alternate version of the META tag (content instead of value). |
| 326 LoadHTML("<html><head><meta name=\"google\" content=\"notranslate\"></head>" | 326 LoadHTML("<html><head><meta name=\"google\" content=\"notranslate\"></head>" |
| 327 "<body>A random page with random content.</body></html>"); | 327 "<body>A random page with random content.</body></html>"); |
| 328 ProcessPendingMessages(); | 328 ProcessPendingMessages(); |
| 329 message = render_thread_.sink().GetUniqueMessageMatching( | 329 message = render_thread_.sink().GetUniqueMessageMatching( |
| 330 ViewHostMsg_TranslateLanguageDetermined::ID); | 330 ChromeViewHostMsg_TranslateLanguageDetermined::ID); |
| 331 ASSERT_NE(static_cast<IPC::Message*>(NULL), message); | 331 ASSERT_NE(static_cast<IPC::Message*>(NULL), message); |
| 332 ViewHostMsg_TranslateLanguageDetermined::Read(message, ¶ms); | 332 ChromeViewHostMsg_TranslateLanguageDetermined::Read(message, ¶ms); |
| 333 EXPECT_FALSE(params.b); // Translatable should be false. | 333 EXPECT_FALSE(params.b); // Translatable should be false. |
| 334 } | 334 } |
| 335 | 335 |
| 336 // Tests that the language meta tag takes precedence over the CLD when reporting | 336 // Tests that the language meta tag takes precedence over the CLD when reporting |
| 337 // the page's language. | 337 // the page's language. |
| 338 TEST_F(RenderViewTest, LanguageMetaTag) { | 338 TEST_F(RenderViewTest, LanguageMetaTag) { |
| 339 // Suppress the normal delay that occurs when the page is loaded before which | 339 // Suppress the normal delay that occurs when the page is loaded before which |
| 340 // the renderer sends the page contents to the browser. | 340 // the renderer sends the page contents to the browser. |
| 341 view_->set_send_content_state_immediately(true); | 341 view_->set_send_content_state_immediately(true); |
| 342 | 342 |
| 343 LoadHTML("<html><head><meta http-equiv=\"content-language\" content=\"es\">" | 343 LoadHTML("<html><head><meta http-equiv=\"content-language\" content=\"es\">" |
| 344 "</head><body>A random page with random content.</body></html>"); | 344 "</head><body>A random page with random content.</body></html>"); |
| 345 ProcessPendingMessages(); | 345 ProcessPendingMessages(); |
| 346 const IPC::Message* message = render_thread_.sink().GetUniqueMessageMatching( | 346 const IPC::Message* message = render_thread_.sink().GetUniqueMessageMatching( |
| 347 ViewHostMsg_TranslateLanguageDetermined::ID); | 347 ChromeViewHostMsg_TranslateLanguageDetermined::ID); |
| 348 ASSERT_NE(static_cast<IPC::Message*>(NULL), message); | 348 ASSERT_NE(static_cast<IPC::Message*>(NULL), message); |
| 349 ViewHostMsg_TranslateLanguageDetermined::Param params; | 349 ChromeViewHostMsg_TranslateLanguageDetermined::Param params; |
| 350 ViewHostMsg_TranslateLanguageDetermined::Read(message, ¶ms); | 350 ChromeViewHostMsg_TranslateLanguageDetermined::Read(message, ¶ms); |
| 351 EXPECT_EQ("es", params.a); | 351 EXPECT_EQ("es", params.a); |
| 352 render_thread_.sink().ClearMessages(); | 352 render_thread_.sink().ClearMessages(); |
| 353 | 353 |
| 354 // Makes sure we support multiple languages specified. | 354 // Makes sure we support multiple languages specified. |
| 355 LoadHTML("<html><head><meta http-equiv=\"content-language\" " | 355 LoadHTML("<html><head><meta http-equiv=\"content-language\" " |
| 356 "content=\" fr , es,en \">" | 356 "content=\" fr , es,en \">" |
| 357 "</head><body>A random page with random content.</body></html>"); | 357 "</head><body>A random page with random content.</body></html>"); |
| 358 ProcessPendingMessages(); | 358 ProcessPendingMessages(); |
| 359 message = render_thread_.sink().GetUniqueMessageMatching( | 359 message = render_thread_.sink().GetUniqueMessageMatching( |
| 360 ViewHostMsg_TranslateLanguageDetermined::ID); | 360 ChromeViewHostMsg_TranslateLanguageDetermined::ID); |
| 361 ASSERT_NE(static_cast<IPC::Message*>(NULL), message); | 361 ASSERT_NE(static_cast<IPC::Message*>(NULL), message); |
| 362 ViewHostMsg_TranslateLanguageDetermined::Read(message, ¶ms); | 362 ChromeViewHostMsg_TranslateLanguageDetermined::Read(message, ¶ms); |
| 363 EXPECT_EQ("fr", params.a); | 363 EXPECT_EQ("fr", params.a); |
| 364 } | 364 } |
| OLD | NEW |