Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2846)

Unified Diff: chrome/browser/translate/translate_manager_unittest.cc

Issue 2802010: Revert 49594 - Convert page contents grabbing from wide to UTF16. The current... (Closed) Base URL: svn://svn.chromium.org/chrome/branches/437/src/
Patch Set: Created 10 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/tab_contents/tab_contents.cc ('k') | chrome/common/render_messages_internal.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/translate/translate_manager_unittest.cc
===================================================================
--- chrome/browser/translate/translate_manager_unittest.cc (revision 50158)
+++ chrome/browser/translate/translate_manager_unittest.cc (working copy)
@@ -4,7 +4,6 @@
#include "chrome/browser/renderer_host/test/test_render_view_host.h"
-#include "base/utf_string_conversions.h"
#include "chrome/app/chrome_dll_resource.h"
#include "chrome/browser/renderer_host/mock_render_process_host.h"
#include "chrome/browser/tab_contents/render_view_context_menu.h"
@@ -42,18 +41,17 @@
// Simluates navigating to a page and getting the page contents and language
// for that navigation.
void SimulateNavigation(const GURL& url, int page_id,
- const std::string& contents,
+ const std::wstring& contents,
const std::string& lang) {
NavigateAndCommit(url);
SimulateOnPageContents(url, page_id, contents, lang);
}
void SimulateOnPageContents(const GURL& url, int page_id,
- const std::string& contents,
+ const std::wstring& contents,
const std::string& lang) {
rvh()->TestOnMessageReceived(ViewHostMsg_PageContents(0, url, page_id,
- UTF8ToUTF16(contents),
- lang));
+ contents, lang));
}
bool GetTranslateMessage(int* page_id,
@@ -261,7 +259,7 @@
TEST_F(TranslateManagerTest, NormalTranslate) {
// Simulate navigating to a page.
- SimulateNavigation(GURL("http://www.google.fr"), 0, "Le Google", "fr");
+ SimulateNavigation(GURL("http://www.google.fr"), 0, L"Le Google", "fr");
// We should have an info-bar.
TranslateInfoBarDelegate* infobar = GetTranslateInfoBar();
@@ -322,7 +320,7 @@
TEST_F(TranslateManagerTest, TranslateScriptNotAvailable) {
// Simulate navigating to a page.
- SimulateNavigation(GURL("http://www.google.fr"), 0, "Le Google", "fr");
+ SimulateNavigation(GURL("http://www.google.fr"), 0, L"Le Google", "fr");
// We should have an info-bar.
TranslateInfoBarDelegate* infobar = GetTranslateInfoBar();
@@ -403,7 +401,7 @@
// Simulate navigating to a page.
NavigateAndCommit(url);
- SimulateOnPageContents(url, i, "", lang);
+ SimulateOnPageContents(url, i, L"", lang);
// Verify we have/don't have an info-bar as expected.
infobar = GetTranslateInfoBar();
@@ -418,7 +416,7 @@
// Tests auto-translate on page.
TEST_F(TranslateManagerTest, AutoTranslateOnNavigate) {
// Simulate navigating to a page and getting its language.
- SimulateNavigation(GURL("http://www.google.fr"), 0, "Le Google", "fr");
+ SimulateNavigation(GURL("http://www.google.fr"), 0, L"Le Google", "fr");
// Simulate the user translating.
TranslateInfoBarDelegate* infobar = GetTranslateInfoBar();
@@ -431,7 +429,7 @@
// Now navigate to a new page in the same language.
process()->sink().ClearMessages();
- SimulateNavigation(GURL("http://news.google.fr"), 1, "Les news", "fr");
+ SimulateNavigation(GURL("http://news.google.fr"), 1, L"Les news", "fr");
// This should have automatically triggered a translation.
int page_id = 0;
@@ -443,7 +441,7 @@
// Now navigate to a page in a different language.
process()->sink().ClearMessages();
- SimulateNavigation(GURL("http://news.google.es"), 1, "Las news", "es");
+ SimulateNavigation(GURL("http://news.google.es"), 1, L"Las news", "es");
// This should not have triggered a translate.
EXPECT_FALSE(GetTranslateMessage(&page_id, &original_lang, &target_lang));
@@ -452,28 +450,28 @@
// Tests that multiple OnPageContents do not cause multiple infobars.
TEST_F(TranslateManagerTest, MultipleOnPageContents) {
// Simulate navigating to a page and getting its language.
- SimulateNavigation(GURL("http://www.google.fr"), 0, "Le Google", "fr");
+ SimulateNavigation(GURL("http://www.google.fr"), 0, L"Le Google", "fr");
// Simulate clicking 'Nope' (don't translate).
EXPECT_TRUE(DenyTranslation());
EXPECT_EQ(0, contents()->infobar_delegate_count());
// Send a new PageContents, we should not show an infobar.
- SimulateOnPageContents(GURL("http://www.google.fr"), 0, "Le Google", "fr");
+ SimulateOnPageContents(GURL("http://www.google.fr"), 0, L"Le Google", "fr");
EXPECT_EQ(0, contents()->infobar_delegate_count());
// Do the same steps but simulate closing the infobar this time.
- SimulateNavigation(GURL("http://www.youtube.fr"), 1, "Le YouTube", "fr");
+ SimulateNavigation(GURL("http://www.youtube.fr"), 1, L"Le YouTube", "fr");
EXPECT_TRUE(CloseTranslateInfoBar());
EXPECT_EQ(0, contents()->infobar_delegate_count());
- SimulateOnPageContents(GURL("http://www.youtube.fr"), 1, "Le YouTube", "fr");
+ SimulateOnPageContents(GURL("http://www.youtube.fr"), 1, L"Le YouTube", "fr");
EXPECT_EQ(0, contents()->infobar_delegate_count());
}
// Test that reloading the page brings back the infobar.
TEST_F(TranslateManagerTest, Reload) {
// Simulate navigating to a page and getting its language.
- SimulateNavigation(GURL("http://www.google.fr"), 0, "Le Google", "fr");
+ SimulateNavigation(GURL("http://www.google.fr"), 0, L"Le Google", "fr");
// Close the infobar.
EXPECT_TRUE(CloseTranslateInfoBar());
@@ -500,7 +498,7 @@
GURL url("http://www.google.fr");
// Simulate navigating to a page and getting its language.
- SimulateNavigation(url, 0, "Le Google", "fr");
+ SimulateNavigation(url, 0, L"Le Google", "fr");
// Close the infobar.
EXPECT_TRUE(CloseTranslateInfoBar());
@@ -528,34 +526,34 @@
// in-page.
TEST_F(TranslateManagerTest, CloseInfoBarInPageNavigation) {
// Simulate navigating to a page and getting its language.
- SimulateNavigation(GURL("http://www.google.fr"), 0, "Le Google", "fr");
+ SimulateNavigation(GURL("http://www.google.fr"), 0, L"Le Google", "fr");
// Close the infobar.
EXPECT_TRUE(CloseTranslateInfoBar());
// Navigate in page, no infobar should be shown.
- SimulateNavigation(GURL("http://www.google.fr/#ref1"), 0, "Le Google", "fr");
+ SimulateNavigation(GURL("http://www.google.fr/#ref1"), 0, L"Le Google", "fr");
EXPECT_TRUE(GetTranslateInfoBar() == NULL);
// Navigate out of page, a new infobar should show.
- SimulateNavigation(GURL("http://www.google.fr/foot"), 0, "Le Google", "fr");
+ SimulateNavigation(GURL("http://www.google.fr/foot"), 0, L"Le Google", "fr");
EXPECT_TRUE(GetTranslateInfoBar() != NULL);
}
// Tests that denying translation is sticky when navigating in page.
TEST_F(TranslateManagerTest, DenyTranslateInPageNavigation) {
// Simulate navigating to a page and getting its language.
- SimulateNavigation(GURL("http://www.google.fr"), 0, "Le Google", "fr");
+ SimulateNavigation(GURL("http://www.google.fr"), 0, L"Le Google", "fr");
// Simulate clicking 'Nope' (don't translate).
EXPECT_TRUE(DenyTranslation());
// Navigate in page, no infobar should be shown.
- SimulateNavigation(GURL("http://www.google.fr/#ref1"), 0, "Le Google", "fr");
+ SimulateNavigation(GURL("http://www.google.fr/#ref1"), 0, L"Le Google", "fr");
EXPECT_TRUE(GetTranslateInfoBar() == NULL);
// Navigate out of page, a new infobar should show.
- SimulateNavigation(GURL("http://www.google.fr/foot"), 0, "Le Google", "fr");
+ SimulateNavigation(GURL("http://www.google.fr/foot"), 0, L"Le Google", "fr");
EXPECT_TRUE(GetTranslateInfoBar() != NULL);
}
@@ -563,7 +561,7 @@
// return when navigating in page.
TEST_F(TranslateManagerTest, TranslateCloseInfoBarInPageNavigation) {
// Simulate navigating to a page and getting its language.
- SimulateNavigation(GURL("http://www.google.fr"), 0, "Le Google", "fr");
+ SimulateNavigation(GURL("http://www.google.fr"), 0, L"Le Google", "fr");
// Simulate the user translating.
TranslateInfoBarDelegate* infobar = GetTranslateInfoBar();
@@ -577,14 +575,14 @@
EXPECT_TRUE(CloseTranslateInfoBar());
// Navigate in page, no infobar should be shown.
- SimulateNavigation(GURL("http://www.google.fr/#ref1"), 0, "Le Google", "fr");
+ SimulateNavigation(GURL("http://www.google.fr/#ref1"), 0, L"Le Google", "fr");
EXPECT_TRUE(GetTranslateInfoBar() == NULL);
// Navigate out of page, a new infobar should show.
// Note that we navigate to a page in a different language so we don't trigger
// the auto-translate feature (it would translate the page automatically and
// the before translate inforbar would not be shown).
- SimulateNavigation(GURL("http://www.google.de"), 0, "Das Google", "de");
+ SimulateNavigation(GURL("http://www.google.de"), 0, L"Das Google", "de");
EXPECT_TRUE(GetTranslateInfoBar() != NULL);
}
@@ -592,7 +590,7 @@
// in-page.
TEST_F(TranslateManagerTest, TranslateInPageNavigation) {
// Simulate navigating to a page and getting its language.
- SimulateNavigation(GURL("http://www.google.fr"), 0, "Le Google", "fr");
+ SimulateNavigation(GURL("http://www.google.fr"), 0, L"Le Google", "fr");
// Simulate the user translating.
TranslateInfoBarDelegate* infobar = GetTranslateInfoBar();
@@ -603,14 +601,14 @@
TranslateErrors::NONE));
// Navigate in page, the same infobar should still be shown.
- SimulateNavigation(GURL("http://www.google.fr/#ref1"), 0, "Le Google", "fr");
+ SimulateNavigation(GURL("http://www.google.fr/#ref1"), 0, L"Le Google", "fr");
EXPECT_FALSE(InfoBarRemoved());
EXPECT_EQ(infobar, GetTranslateInfoBar());
// Navigate out of page, a new infobar should show.
// See note in TranslateCloseInfoBarInPageNavigation test on why it is
// important to navigate to a page in a different language for this test.
- SimulateNavigation(GURL("http://www.google.de"), 0, "Das Google", "de");
+ SimulateNavigation(GURL("http://www.google.de"), 0, L"Das Google", "de");
// The old infobar is gone.
EXPECT_TRUE(CheckInfoBarRemovedAndReset(infobar));
// And there is a new one.
@@ -621,7 +619,7 @@
// unsupported language.
TEST_F(TranslateManagerTest, UnsupportedPageLanguage) {
// Simulate navigating to a page and getting an unsupported language.
- SimulateNavigation(GURL("http://www.google.com"), 0, "Google", "qbz");
+ SimulateNavigation(GURL("http://www.google.com"), 0, L"Google", "qbz");
// No info-bar should be shown.
EXPECT_TRUE(GetTranslateInfoBar() == NULL);
@@ -637,7 +635,7 @@
// Simulate navigating to a page in a language supported by the translate
// server.
- SimulateNavigation(GURL("http://www.google.com"), 0, "Google", "en");
+ SimulateNavigation(GURL("http://www.google.com"), 0, L"Google", "en");
// No info-bar should be shown.
EXPECT_TRUE(GetTranslateInfoBar() == NULL);
@@ -652,7 +650,7 @@
prefs->SetBoolean(prefs::kEnableTranslate, true);
// Simulate navigating to a page and getting its language.
- SimulateNavigation(GURL("http://www.google.fr"), 0, "Le Google", "fr");
+ SimulateNavigation(GURL("http://www.google.fr"), 0, L"Le Google", "fr");
// An infobar should be shown.
TranslateInfoBarDelegate* infobar = GetTranslateInfoBar();
@@ -669,7 +667,7 @@
// Simulate getting the page contents and language, that should not trigger
// a translate infobar.
- SimulateOnPageContents(url, 1, "Le YouTube", "fr");
+ SimulateOnPageContents(url, 1, L"Le YouTube", "fr");
infobar = GetTranslateInfoBar();
EXPECT_TRUE(infobar == NULL);
}
@@ -678,7 +676,7 @@
TEST_F(TranslateManagerTest, NeverTranslateLanguagePref) {
// Simulate navigating to a page and getting its language.
GURL url("http://www.google.fr");
- SimulateNavigation(url, 0, "Le Google", "fr");
+ SimulateNavigation(url, 0, L"Le Google", "fr");
// An infobar should be shown.
EXPECT_TRUE(GetTranslateInfoBar() != NULL);
@@ -699,7 +697,7 @@
EXPECT_TRUE(CloseTranslateInfoBar());
// Navigate to a new page also in French.
- SimulateNavigation(GURL("http://wwww.youtube.fr"), 1, "Le YouTube", "fr");
+ SimulateNavigation(GURL("http://wwww.youtube.fr"), 1, L"Le YouTube", "fr");
// There should not be a translate infobar.
EXPECT_TRUE(GetTranslateInfoBar() == NULL);
@@ -711,7 +709,7 @@
EXPECT_TRUE(translate_prefs.CanTranslate(prefs, "fr", url));
// Navigate to a page in French.
- SimulateNavigation(url, 2, "Le Google", "fr");
+ SimulateNavigation(url, 2, L"Le Google", "fr");
// There should be a translate infobar.
EXPECT_TRUE(GetTranslateInfoBar() != NULL);
@@ -724,7 +722,7 @@
// Simulate navigating to a page and getting its language.
GURL url("http://www.google.fr");
std::string host(url.host());
- SimulateNavigation(url, 0, "Le Google", "fr");
+ SimulateNavigation(url, 0, L"Le Google", "fr");
// An infobar should be shown.
EXPECT_TRUE(GetTranslateInfoBar() != NULL);
@@ -745,7 +743,7 @@
EXPECT_TRUE(CloseTranslateInfoBar());
// Navigate to a new page also on the same site.
- SimulateNavigation(GURL("http://www.google.fr/hello"), 1, "Bonjour", "fr");
+ SimulateNavigation(GURL("http://www.google.fr/hello"), 1, L"Bonjour", "fr");
// There should not be a translate infobar.
EXPECT_TRUE(GetTranslateInfoBar() == NULL);
@@ -757,7 +755,7 @@
EXPECT_TRUE(translate_prefs.CanTranslate(prefs, "fr", url));
// Navigate to a page in French.
- SimulateNavigation(url, 0, "Le Google", "fr");
+ SimulateNavigation(url, 0, L"Le Google", "fr");
// There should be a translate infobar.
EXPECT_TRUE(GetTranslateInfoBar() != NULL);
@@ -776,7 +774,7 @@
translate_prefs.WhitelistLanguagePair("fr", "en");
// Load a page in French.
- SimulateNavigation(GURL("http://www.google.fr"), 0, "Le Google", "fr");
+ SimulateNavigation(GURL("http://www.google.fr"), 0, L"Le Google", "fr");
// It should have triggered an automatic translation to English.
SimulateURLFetch(true); // Simulate the translate script being retrieved.
@@ -792,7 +790,7 @@
EXPECT_TRUE(GetTranslateInfoBar() == NULL);
// Try another language, it should not be autotranslated.
- SimulateNavigation(GURL("http://www.google.es"), 1, "El Google", "es");
+ SimulateNavigation(GURL("http://www.google.es"), 1, L"El Google", "es");
EXPECT_FALSE(GetTranslateMessage(&page_id, &original_lang, &target_lang));
EXPECT_TRUE(GetTranslateInfoBar() != NULL);
EXPECT_TRUE(CloseTranslateInfoBar());
@@ -802,7 +800,7 @@
TestingProfile* test_profile =
static_cast<TestingProfile*>(contents()->profile());
test_profile->set_off_the_record(true);
- SimulateNavigation(GURL("http://www.youtube.fr"), 2, "Le YouTube", "fr");
+ SimulateNavigation(GURL("http://www.youtube.fr"), 2, L"Le YouTube", "fr");
EXPECT_FALSE(GetTranslateMessage(&page_id, &original_lang, &target_lang));
EXPECT_TRUE(GetTranslateInfoBar() != NULL);
EXPECT_TRUE(CloseTranslateInfoBar());
@@ -812,7 +810,7 @@
// behavior, which is show an infobar.
SetPrefObserverExpectation(TranslatePrefs::kPrefTranslateWhitelists);
translate_prefs.RemoveLanguagePairFromWhitelist("fr", "en");
- SimulateNavigation(GURL("http://www.google.fr"), 3, "Le Google", "fr");
+ SimulateNavigation(GURL("http://www.google.fr"), 3, L"Le Google", "fr");
EXPECT_FALSE(GetTranslateMessage(&page_id, &original_lang, &target_lang));
EXPECT_TRUE(GetTranslateInfoBar() != NULL);
prefs->RemovePrefObserver(TranslatePrefs::kPrefTranslateWhitelists,
@@ -830,7 +828,7 @@
EXPECT_TRUE(translate_prefs.IsSiteBlacklisted(url.host()));
// Simulate navigating to a page in French. The translate menu should show.
- SimulateNavigation(url, 0, "Le Google", "fr");
+ SimulateNavigation(url, 0, L"Le Google", "fr");
scoped_ptr<TestRenderViewContextMenu> menu(
TestRenderViewContextMenu::CreateContextMenu(contents()));
menu->Init();
@@ -867,7 +865,7 @@
// Test that selecting translate in the context menu WHILE the page is being
// translated does nothing (this could happen if autotranslate kicks-in and
// the user selects the menu while the translation is being performed).
- SimulateNavigation(GURL("http://www.google.es"), 1, "El Google", "es");
+ SimulateNavigation(GURL("http://www.google.es"), 1, L"El Google", "es");
TranslateInfoBarDelegate* infobar = GetTranslateInfoBar();
ASSERT_TRUE(infobar != NULL);
infobar->Translate();
@@ -883,7 +881,7 @@
// Now test that selecting translate in the context menu AFTER the page has
// been translated does nothing.
- SimulateNavigation(GURL("http://www.google.de"), 2, "Das Google", "de");
+ SimulateNavigation(GURL("http://www.google.de"), 2, L"Das Google", "de");
infobar = GetTranslateInfoBar();
ASSERT_TRUE(infobar != NULL);
infobar->Translate();
@@ -901,7 +899,7 @@
// Test that the translate context menu is disabled when the page is in the
// same language as the UI.
- SimulateNavigation(url, 0, "Google", "en");
+ SimulateNavigation(url, 0, L"Google", "en");
menu.reset(TestRenderViewContextMenu::CreateContextMenu(contents()));
menu->Init();
EXPECT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_TRANSLATE));
« no previous file with comments | « chrome/browser/tab_contents/tab_contents.cc ('k') | chrome/common/render_messages_internal.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698