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

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

Issue 2714012: Convert page contents grabbing from wide to UTF16. The current code is a bit... (Closed) Base URL: svn://chrome-svn/chrome/trunk/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
Index: chrome/browser/translate/translate_manager_unittest.cc
===================================================================
--- chrome/browser/translate/translate_manager_unittest.cc (revision 49439)
+++ chrome/browser/translate/translate_manager_unittest.cc (working copy)
@@ -4,6 +4,7 @@
#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"
@@ -41,17 +42,18 @@
// 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::wstring& contents,
+ const std::string& contents,
const std::string& lang) {
NavigateAndCommit(url);
SimulateOnPageContents(url, page_id, contents, lang);
}
void SimulateOnPageContents(const GURL& url, int page_id,
- const std::wstring& contents,
+ const std::string& contents,
const std::string& lang) {
rvh()->TestOnMessageReceived(ViewHostMsg_PageContents(0, url, page_id,
- contents, lang));
+ UTF8ToUTF16(contents),
+ lang));
}
bool GetTranslateMessage(int* page_id,
@@ -259,7 +261,7 @@
TEST_F(TranslateManagerTest, NormalTranslate) {
// Simulate navigating to a page.
- SimulateNavigation(GURL("http://www.google.fr"), 0, L"Le Google", "fr");
+ SimulateNavigation(GURL("http://www.google.fr"), 0, "Le Google", "fr");
// We should have an info-bar.
TranslateInfoBarDelegate* infobar = GetTranslateInfoBar();
@@ -320,7 +322,7 @@
TEST_F(TranslateManagerTest, TranslateScriptNotAvailable) {
// Simulate navigating to a page.
- SimulateNavigation(GURL("http://www.google.fr"), 0, L"Le Google", "fr");
+ SimulateNavigation(GURL("http://www.google.fr"), 0, "Le Google", "fr");
// We should have an info-bar.
TranslateInfoBarDelegate* infobar = GetTranslateInfoBar();
@@ -401,7 +403,7 @@
// Simulate navigating to a page.
NavigateAndCommit(url);
- SimulateOnPageContents(url, i, L"", lang);
+ SimulateOnPageContents(url, i, "", lang);
// Verify we have/don't have an info-bar as expected.
infobar = GetTranslateInfoBar();
@@ -416,7 +418,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, L"Le Google", "fr");
+ SimulateNavigation(GURL("http://www.google.fr"), 0, "Le Google", "fr");
// Simulate the user translating.
TranslateInfoBarDelegate* infobar = GetTranslateInfoBar();
@@ -429,7 +431,7 @@
// Now navigate to a new page in the same language.
process()->sink().ClearMessages();
- SimulateNavigation(GURL("http://news.google.fr"), 1, L"Les news", "fr");
+ SimulateNavigation(GURL("http://news.google.fr"), 1, "Les news", "fr");
// This should have automatically triggered a translation.
int page_id = 0;
@@ -441,7 +443,7 @@
// Now navigate to a page in a different language.
process()->sink().ClearMessages();
- SimulateNavigation(GURL("http://news.google.es"), 1, L"Las news", "es");
+ SimulateNavigation(GURL("http://news.google.es"), 1, "Las news", "es");
// This should not have triggered a translate.
EXPECT_FALSE(GetTranslateMessage(&page_id, &original_lang, &target_lang));
@@ -450,28 +452,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, L"Le Google", "fr");
+ SimulateNavigation(GURL("http://www.google.fr"), 0, "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, L"Le Google", "fr");
+ SimulateOnPageContents(GURL("http://www.google.fr"), 0, "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, L"Le YouTube", "fr");
+ SimulateNavigation(GURL("http://www.youtube.fr"), 1, "Le YouTube", "fr");
EXPECT_TRUE(CloseTranslateInfoBar());
EXPECT_EQ(0, contents()->infobar_delegate_count());
- SimulateOnPageContents(GURL("http://www.youtube.fr"), 1, L"Le YouTube", "fr");
+ SimulateOnPageContents(GURL("http://www.youtube.fr"), 1, "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, L"Le Google", "fr");
+ SimulateNavigation(GURL("http://www.google.fr"), 0, "Le Google", "fr");
// Close the infobar.
EXPECT_TRUE(CloseTranslateInfoBar());
@@ -498,7 +500,7 @@
GURL url("http://www.google.fr");
// Simulate navigating to a page and getting its language.
- SimulateNavigation(url, 0, L"Le Google", "fr");
+ SimulateNavigation(url, 0, "Le Google", "fr");
// Close the infobar.
EXPECT_TRUE(CloseTranslateInfoBar());
@@ -526,34 +528,34 @@
// in-page.
TEST_F(TranslateManagerTest, CloseInfoBarInPageNavigation) {
// Simulate navigating to a page and getting its language.
- SimulateNavigation(GURL("http://www.google.fr"), 0, L"Le Google", "fr");
+ SimulateNavigation(GURL("http://www.google.fr"), 0, "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, L"Le Google", "fr");
+ SimulateNavigation(GURL("http://www.google.fr/#ref1"), 0, "Le Google", "fr");
EXPECT_TRUE(GetTranslateInfoBar() == NULL);
// Navigate out of page, a new infobar should show.
- SimulateNavigation(GURL("http://www.google.fr/foot"), 0, L"Le Google", "fr");
+ SimulateNavigation(GURL("http://www.google.fr/foot"), 0, "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, L"Le Google", "fr");
+ SimulateNavigation(GURL("http://www.google.fr"), 0, "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, L"Le Google", "fr");
+ SimulateNavigation(GURL("http://www.google.fr/#ref1"), 0, "Le Google", "fr");
EXPECT_TRUE(GetTranslateInfoBar() == NULL);
// Navigate out of page, a new infobar should show.
- SimulateNavigation(GURL("http://www.google.fr/foot"), 0, L"Le Google", "fr");
+ SimulateNavigation(GURL("http://www.google.fr/foot"), 0, "Le Google", "fr");
EXPECT_TRUE(GetTranslateInfoBar() != NULL);
}
@@ -561,7 +563,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, L"Le Google", "fr");
+ SimulateNavigation(GURL("http://www.google.fr"), 0, "Le Google", "fr");
// Simulate the user translating.
TranslateInfoBarDelegate* infobar = GetTranslateInfoBar();
@@ -575,14 +577,14 @@
EXPECT_TRUE(CloseTranslateInfoBar());
// Navigate in page, no infobar should be shown.
- SimulateNavigation(GURL("http://www.google.fr/#ref1"), 0, L"Le Google", "fr");
+ SimulateNavigation(GURL("http://www.google.fr/#ref1"), 0, "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, L"Das Google", "de");
+ SimulateNavigation(GURL("http://www.google.de"), 0, "Das Google", "de");
EXPECT_TRUE(GetTranslateInfoBar() != NULL);
}
@@ -590,7 +592,7 @@
// in-page.
TEST_F(TranslateManagerTest, TranslateInPageNavigation) {
// Simulate navigating to a page and getting its language.
- SimulateNavigation(GURL("http://www.google.fr"), 0, L"Le Google", "fr");
+ SimulateNavigation(GURL("http://www.google.fr"), 0, "Le Google", "fr");
// Simulate the user translating.
TranslateInfoBarDelegate* infobar = GetTranslateInfoBar();
@@ -601,14 +603,14 @@
TranslateErrors::NONE));
// Navigate in page, the same infobar should still be shown.
- SimulateNavigation(GURL("http://www.google.fr/#ref1"), 0, L"Le Google", "fr");
+ SimulateNavigation(GURL("http://www.google.fr/#ref1"), 0, "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, L"Das Google", "de");
+ SimulateNavigation(GURL("http://www.google.de"), 0, "Das Google", "de");
// The old infobar is gone.
EXPECT_TRUE(CheckInfoBarRemovedAndReset(infobar));
// And there is a new one.
@@ -619,7 +621,7 @@
// unsupported language.
TEST_F(TranslateManagerTest, UnsupportedPageLanguage) {
// Simulate navigating to a page and getting an unsupported language.
- SimulateNavigation(GURL("http://www.google.com"), 0, L"Google", "qbz");
+ SimulateNavigation(GURL("http://www.google.com"), 0, "Google", "qbz");
// No info-bar should be shown.
EXPECT_TRUE(GetTranslateInfoBar() == NULL);
@@ -635,7 +637,7 @@
// Simulate navigating to a page in a language supported by the translate
// server.
- SimulateNavigation(GURL("http://www.google.com"), 0, L"Google", "en");
+ SimulateNavigation(GURL("http://www.google.com"), 0, "Google", "en");
// No info-bar should be shown.
EXPECT_TRUE(GetTranslateInfoBar() == NULL);
@@ -650,7 +652,7 @@
prefs->SetBoolean(prefs::kEnableTranslate, true);
// Simulate navigating to a page and getting its language.
- SimulateNavigation(GURL("http://www.google.fr"), 0, L"Le Google", "fr");
+ SimulateNavigation(GURL("http://www.google.fr"), 0, "Le Google", "fr");
// An infobar should be shown.
TranslateInfoBarDelegate* infobar = GetTranslateInfoBar();
@@ -667,7 +669,7 @@
// Simulate getting the page contents and language, that should not trigger
// a translate infobar.
- SimulateOnPageContents(url, 1, L"Le YouTube", "fr");
+ SimulateOnPageContents(url, 1, "Le YouTube", "fr");
infobar = GetTranslateInfoBar();
EXPECT_TRUE(infobar == NULL);
}
@@ -676,7 +678,7 @@
TEST_F(TranslateManagerTest, NeverTranslateLanguagePref) {
// Simulate navigating to a page and getting its language.
GURL url("http://www.google.fr");
- SimulateNavigation(url, 0, L"Le Google", "fr");
+ SimulateNavigation(url, 0, "Le Google", "fr");
// An infobar should be shown.
EXPECT_TRUE(GetTranslateInfoBar() != NULL);
@@ -697,7 +699,7 @@
EXPECT_TRUE(CloseTranslateInfoBar());
// Navigate to a new page also in French.
- SimulateNavigation(GURL("http://wwww.youtube.fr"), 1, L"Le YouTube", "fr");
+ SimulateNavigation(GURL("http://wwww.youtube.fr"), 1, "Le YouTube", "fr");
// There should not be a translate infobar.
EXPECT_TRUE(GetTranslateInfoBar() == NULL);
@@ -709,7 +711,7 @@
EXPECT_TRUE(translate_prefs.CanTranslate(prefs, "fr", url));
// Navigate to a page in French.
- SimulateNavigation(url, 2, L"Le Google", "fr");
+ SimulateNavigation(url, 2, "Le Google", "fr");
// There should be a translate infobar.
EXPECT_TRUE(GetTranslateInfoBar() != NULL);
@@ -722,7 +724,7 @@
// Simulate navigating to a page and getting its language.
GURL url("http://www.google.fr");
std::string host(url.host());
- SimulateNavigation(url, 0, L"Le Google", "fr");
+ SimulateNavigation(url, 0, "Le Google", "fr");
// An infobar should be shown.
EXPECT_TRUE(GetTranslateInfoBar() != NULL);
@@ -743,7 +745,7 @@
EXPECT_TRUE(CloseTranslateInfoBar());
// Navigate to a new page also on the same site.
- SimulateNavigation(GURL("http://www.google.fr/hello"), 1, L"Bonjour", "fr");
+ SimulateNavigation(GURL("http://www.google.fr/hello"), 1, "Bonjour", "fr");
// There should not be a translate infobar.
EXPECT_TRUE(GetTranslateInfoBar() == NULL);
@@ -755,7 +757,7 @@
EXPECT_TRUE(translate_prefs.CanTranslate(prefs, "fr", url));
// Navigate to a page in French.
- SimulateNavigation(url, 0, L"Le Google", "fr");
+ SimulateNavigation(url, 0, "Le Google", "fr");
// There should be a translate infobar.
EXPECT_TRUE(GetTranslateInfoBar() != NULL);
@@ -774,7 +776,7 @@
translate_prefs.WhitelistLanguagePair("fr", "en");
// Load a page in French.
- SimulateNavigation(GURL("http://www.google.fr"), 0, L"Le Google", "fr");
+ SimulateNavigation(GURL("http://www.google.fr"), 0, "Le Google", "fr");
// It should have triggered an automatic translation to English.
SimulateURLFetch(true); // Simulate the translate script being retrieved.
@@ -790,7 +792,7 @@
EXPECT_TRUE(GetTranslateInfoBar() == NULL);
// Try another language, it should not be autotranslated.
- SimulateNavigation(GURL("http://www.google.es"), 1, L"El Google", "es");
+ SimulateNavigation(GURL("http://www.google.es"), 1, "El Google", "es");
EXPECT_FALSE(GetTranslateMessage(&page_id, &original_lang, &target_lang));
EXPECT_TRUE(GetTranslateInfoBar() != NULL);
EXPECT_TRUE(CloseTranslateInfoBar());
@@ -800,7 +802,7 @@
TestingProfile* test_profile =
static_cast<TestingProfile*>(contents()->profile());
test_profile->set_off_the_record(true);
- SimulateNavigation(GURL("http://www.youtube.fr"), 2, L"Le YouTube", "fr");
+ SimulateNavigation(GURL("http://www.youtube.fr"), 2, "Le YouTube", "fr");
EXPECT_FALSE(GetTranslateMessage(&page_id, &original_lang, &target_lang));
EXPECT_TRUE(GetTranslateInfoBar() != NULL);
EXPECT_TRUE(CloseTranslateInfoBar());
@@ -810,7 +812,7 @@
// behavior, which is show an infobar.
SetPrefObserverExpectation(TranslatePrefs::kPrefTranslateWhitelists);
translate_prefs.RemoveLanguagePairFromWhitelist("fr", "en");
- SimulateNavigation(GURL("http://www.google.fr"), 3, L"Le Google", "fr");
+ SimulateNavigation(GURL("http://www.google.fr"), 3, "Le Google", "fr");
EXPECT_FALSE(GetTranslateMessage(&page_id, &original_lang, &target_lang));
EXPECT_TRUE(GetTranslateInfoBar() != NULL);
prefs->RemovePrefObserver(TranslatePrefs::kPrefTranslateWhitelists,
@@ -828,7 +830,7 @@
EXPECT_TRUE(translate_prefs.IsSiteBlacklisted(url.host()));
// Simulate navigating to a page in French. The translate menu should show.
- SimulateNavigation(url, 0, L"Le Google", "fr");
+ SimulateNavigation(url, 0, "Le Google", "fr");
scoped_ptr<TestRenderViewContextMenu> menu(
TestRenderViewContextMenu::CreateContextMenu(contents()));
menu->Init();
@@ -865,7 +867,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, L"El Google", "es");
+ SimulateNavigation(GURL("http://www.google.es"), 1, "El Google", "es");
TranslateInfoBarDelegate* infobar = GetTranslateInfoBar();
ASSERT_TRUE(infobar != NULL);
infobar->Translate();
@@ -881,7 +883,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, L"Das Google", "de");
+ SimulateNavigation(GURL("http://www.google.de"), 2, "Das Google", "de");
infobar = GetTranslateInfoBar();
ASSERT_TRUE(infobar != NULL);
infobar->Translate();
@@ -899,7 +901,7 @@
// Test that the translate context menu is disabled when the page is in the
// same language as the UI.
- SimulateNavigation(url, 0, L"Google", "en");
+ SimulateNavigation(url, 0, "Google", "en");
menu.reset(TestRenderViewContextMenu::CreateContextMenu(contents()));
menu->Init();
EXPECT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_TRANSLATE));

Powered by Google App Engine
This is Rietveld 408576698