OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #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/chrome_render_view_test.h" | 8 #include "chrome/test/base/chrome_render_view_test.h" |
9 #include "content/public/renderer/render_view.h" | 9 #include "content/public/renderer/render_view.h" |
10 #include "testing/gmock/include/gmock/gmock.h" | 10 #include "testing/gmock/include/gmock/gmock.h" |
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
388 LoadHTML("<html><head><meta http-equiv=\"Content-Language\" " | 388 LoadHTML("<html><head><meta http-equiv=\"Content-Language\" " |
389 "content=\" fr , es,en \">" | 389 "content=\" fr , es,en \">" |
390 "</head><body>A random page with random content.</body></html>"); | 390 "</head><body>A random page with random content.</body></html>"); |
391 message = render_thread_->sink().GetUniqueMessageMatching( | 391 message = render_thread_->sink().GetUniqueMessageMatching( |
392 ChromeViewHostMsg_TranslateLanguageDetermined::ID); | 392 ChromeViewHostMsg_TranslateLanguageDetermined::ID); |
393 ASSERT_NE(static_cast<IPC::Message*>(NULL), message); | 393 ASSERT_NE(static_cast<IPC::Message*>(NULL), message); |
394 ChromeViewHostMsg_TranslateLanguageDetermined::Read(message, ¶ms); | 394 ChromeViewHostMsg_TranslateLanguageDetermined::Read(message, ¶ms); |
395 EXPECT_EQ("fr", params.a); | 395 EXPECT_EQ("fr", params.a); |
396 } | 396 } |
397 | 397 |
398 // Tests that the language meta tag is converted to chrome standard of dashes | |
James Hawkins
2012/11/06 18:47:49
re: chrome standard - Is this just Chrome's interp
bcwhite
2012/11/06 18:55:23
As far as I could find, dashes are the official wa
| |
399 // instead of underscores and proper capitalization. | |
400 // http://code.google.com/p/chromium/issues/detail?id=159487 | |
401 TEST_F(ChromeRenderViewTest, LanguageFormatCorrect) { | |
James Hawkins
2012/11/06 18:47:49
nit: Please use a more precise test name.
bcwhite
2012/11/06 18:55:23
Done.
| |
402 // Suppress the normal delay that occurs when the page is loaded before which | |
403 // the renderer sends the page contents to the browser. | |
404 SendContentStateImmediately(); | |
405 | |
406 LoadHTML("<html><head><meta http-equiv='Content-Language' content='EN_us'>" | |
407 "</head><body>A random page with random content.</body></html>"); | |
408 const IPC::Message* message = render_thread_->sink().GetUniqueMessageMatching( | |
409 ChromeViewHostMsg_TranslateLanguageDetermined::ID); | |
410 ASSERT_NE(static_cast<IPC::Message*>(NULL), message); | |
411 ChromeViewHostMsg_TranslateLanguageDetermined::Param params; | |
412 ChromeViewHostMsg_TranslateLanguageDetermined::Read(message, ¶ms); | |
413 EXPECT_EQ("en-US", params.a); | |
414 render_thread_->sink().ClearMessages(); | |
415 } | |
416 | |
398 | 417 |
399 // Tests that a back navigation gets a translate language message. | 418 // Tests that a back navigation gets a translate language message. |
400 TEST_F(ChromeRenderViewTest, BackToTranslatablePage) { | 419 TEST_F(ChromeRenderViewTest, BackToTranslatablePage) { |
401 SendContentStateImmediately(); | 420 SendContentStateImmediately(); |
402 LoadHTML("<html><head><meta http-equiv=\"content-language\" content=\"zh\">" | 421 LoadHTML("<html><head><meta http-equiv=\"content-language\" content=\"zh\">" |
403 "</head><body>This page is in Chinese.</body></html>"); | 422 "</head><body>This page is in Chinese.</body></html>"); |
404 const IPC::Message* message = render_thread_->sink().GetUniqueMessageMatching( | 423 const IPC::Message* message = render_thread_->sink().GetUniqueMessageMatching( |
405 ChromeViewHostMsg_TranslateLanguageDetermined::ID); | 424 ChromeViewHostMsg_TranslateLanguageDetermined::ID); |
406 ASSERT_NE(static_cast<IPC::Message*>(NULL), message); | 425 ASSERT_NE(static_cast<IPC::Message*>(NULL), message); |
407 ChromeViewHostMsg_TranslateLanguageDetermined::Param params; | 426 ChromeViewHostMsg_TranslateLanguageDetermined::Param params; |
(...skipping 13 matching lines...) Expand all Loading... | |
421 GoBack(GetMainFrame()->previousHistoryItem()); | 440 GoBack(GetMainFrame()->previousHistoryItem()); |
422 | 441 |
423 message = render_thread_->sink().GetUniqueMessageMatching( | 442 message = render_thread_->sink().GetUniqueMessageMatching( |
424 ChromeViewHostMsg_TranslateLanguageDetermined::ID); | 443 ChromeViewHostMsg_TranslateLanguageDetermined::ID); |
425 ASSERT_NE(static_cast<IPC::Message*>(NULL), message); | 444 ASSERT_NE(static_cast<IPC::Message*>(NULL), message); |
426 ChromeViewHostMsg_TranslateLanguageDetermined::Read(message, ¶ms); | 445 ChromeViewHostMsg_TranslateLanguageDetermined::Read(message, ¶ms); |
427 EXPECT_EQ("zh", params.a); | 446 EXPECT_EQ("zh", params.a); |
428 render_thread_->sink().ClearMessages(); | 447 render_thread_->sink().ClearMessages(); |
429 } | 448 } |
430 | 449 |
OLD | NEW |