Index: chrome/browser/search_engines/template_url_unittest.cc |
=================================================================== |
--- chrome/browser/search_engines/template_url_unittest.cc (revision 71499) |
+++ chrome/browser/search_engines/template_url_unittest.cc (working copy) |
@@ -1,4 +1,4 @@ |
-// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
+// Copyright (c) 2006-2010 The Chromium Authors. All rights reserved. |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
@@ -28,8 +28,8 @@ |
#if defined(OS_WIN) && defined(GOOGLE_CHROME_BUILD) |
// Returns the value for the Chrome Omnibox rlz. |
- virtual string16 GetRlzParameterValue() const { |
- return string16(); |
+ virtual std::wstring GetRlzParameterValue() const { |
+ return L""; |
} |
#endif |
@@ -68,16 +68,15 @@ |
TEST_F(TemplateURLTest, URLRefTestSearchTerms) { |
struct SearchTermsCase { |
const char* url; |
- const string16 terms; |
+ const wchar_t* terms; |
const char* output; |
} search_term_cases[] = { |
- { "http://foo{searchTerms}", ASCIIToUTF16("sea rch/bar"), |
- "http://foosea%20rch/bar" }, |
- { "http://foo{searchTerms}?boo=abc", ASCIIToUTF16("sea rch/bar"), |
+ { "http://foo{searchTerms}", L"sea rch/bar", "http://foosea%20rch/bar" }, |
+ { "http://foo{searchTerms}?boo=abc", L"sea rch/bar", |
"http://foosea%20rch/bar?boo=abc" }, |
- { "http://foo/?boo={searchTerms}", ASCIIToUTF16("sea rch/bar"), |
+ { "http://foo/?boo={searchTerms}", L"sea rch/bar", |
"http://foo/?boo=sea+rch%2Fbar" }, |
- { "http://en.wikipedia.org/{searchTerms}", ASCIIToUTF16("wiki/?"), |
+ { "http://en.wikipedia.org/{searchTerms}", L"wiki/?", |
"http://en.wikipedia.org/wiki/%3F" } |
}; |
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(search_term_cases); ++i) { |
@@ -88,7 +87,7 @@ |
ASSERT_TRUE(ref.SupportsReplacement()); |
GURL result = GURL(ref.ReplaceSearchTerms(t_url, value.terms, |
- TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16())); |
+ TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, std::wstring())); |
ASSERT_TRUE(result.is_valid()); |
ASSERT_EQ(value.output, result.spec()); |
} |
@@ -99,8 +98,8 @@ |
TemplateURLRef ref("http://foo{searchTerms}{count?}", 0, 0); |
ASSERT_TRUE(ref.IsValid()); |
ASSERT_TRUE(ref.SupportsReplacement()); |
- GURL result = GURL(ref.ReplaceSearchTerms(t_url, ASCIIToUTF16("X"), |
- TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16())); |
+ GURL result = GURL(ref.ReplaceSearchTerms(t_url, L"X", |
+ TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, std::wstring())); |
ASSERT_TRUE(result.is_valid()); |
ASSERT_EQ("http://foox/", result.spec()); |
} |
@@ -110,8 +109,8 @@ |
TemplateURLRef ref("http://foo{searchTerms}{count}", 0, 0); |
ASSERT_TRUE(ref.IsValid()); |
ASSERT_TRUE(ref.SupportsReplacement()); |
- GURL result = GURL(ref.ReplaceSearchTerms(t_url, ASCIIToUTF16("X"), |
- TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16())); |
+ GURL result = GURL(ref.ReplaceSearchTerms(t_url, L"X", |
+ TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, std::wstring())); |
ASSERT_TRUE(result.is_valid()); |
ASSERT_EQ("http://foox10/", result.spec()); |
} |
@@ -122,8 +121,8 @@ |
1, 2); |
ASSERT_TRUE(ref.IsValid()); |
ASSERT_TRUE(ref.SupportsReplacement()); |
- GURL result = GURL(ref.ReplaceSearchTerms(t_url, ASCIIToUTF16("X"), |
- TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16())); |
+ GURL result = GURL(ref.ReplaceSearchTerms(t_url, L"X", |
+ TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, std::wstring())); |
ASSERT_TRUE(result.is_valid()); |
ASSERT_EQ("http://fooxxy/", result.spec()); |
} |
@@ -133,8 +132,8 @@ |
TemplateURLRef ref("http://foo{searchTerms}x{startIndex}y{startPage}", 1, 2); |
ASSERT_TRUE(ref.IsValid()); |
ASSERT_TRUE(ref.SupportsReplacement()); |
- GURL result = GURL(ref.ReplaceSearchTerms(t_url, ASCIIToUTF16("X"), |
- TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16())); |
+ GURL result = GURL(ref.ReplaceSearchTerms(t_url, L"X", |
+ TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, std::wstring())); |
ASSERT_TRUE(result.is_valid()); |
ASSERT_EQ("http://fooxx1y2/", result.spec()); |
} |
@@ -145,8 +144,8 @@ |
"http://foo{searchTerms}x{inputEncoding?}y{outputEncoding?}a", 1, 2); |
ASSERT_TRUE(ref.IsValid()); |
ASSERT_TRUE(ref.SupportsReplacement()); |
- GURL result = GURL(ref.ReplaceSearchTerms(t_url, ASCIIToUTF16("X"), |
- TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16())); |
+ GURL result = GURL(ref.ReplaceSearchTerms(t_url, L"X", |
+ TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, std::wstring())); |
ASSERT_TRUE(result.is_valid()); |
ASSERT_EQ("http://fooxxutf-8ya/", result.spec()); |
} |
@@ -157,8 +156,8 @@ |
"http://foox{inputEncoding?}a{searchTerms}y{outputEncoding?}b", 1, 2); |
ASSERT_TRUE(ref.IsValid()); |
ASSERT_TRUE(ref.SupportsReplacement()); |
- GURL result = GURL(ref.ReplaceSearchTerms(t_url, ASCIIToUTF16("X"), |
- TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16())); |
+ GURL result = GURL(ref.ReplaceSearchTerms(t_url, L"X", |
+ TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, std::wstring())); |
ASSERT_TRUE(result.is_valid()); |
ASSERT_EQ("http://fooxutf-8axyb/", result.spec()); |
} |
@@ -169,8 +168,8 @@ |
"http://foo{searchTerms}x{inputEncoding}y{outputEncoding}a", 1, 2); |
ASSERT_TRUE(ref.IsValid()); |
ASSERT_TRUE(ref.SupportsReplacement()); |
- GURL result = GURL(ref.ReplaceSearchTerms(t_url, ASCIIToUTF16("X"), |
- TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16())); |
+ GURL result = GURL(ref.ReplaceSearchTerms(t_url, L"X", |
+ TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, std::wstring())); |
ASSERT_TRUE(result.is_valid()); |
ASSERT_EQ("http://fooxxutf-8yutf-8a/", result.spec()); |
} |
@@ -178,12 +177,12 @@ |
TEST_F(TemplateURLTest, URLRefTestSearchTermsUsingTermsData) { |
struct SearchTermsCase { |
const char* url; |
- const string16 terms; |
+ const wchar_t* terms; |
const char* output; |
} search_term_cases[] = { |
- { "{google:baseURL}{language}{searchTerms}", string16(), |
+ { "{google:baseURL}{language}{searchTerms}", L"", |
"http://example.com/e/yy" }, |
- { "{google:baseSuggestURL}{searchTerms}", string16(), |
+ { "{google:baseSuggestURL}{searchTerms}", L"", |
"http://clients1.example.com/complete/" } |
}; |
@@ -197,7 +196,7 @@ |
ASSERT_TRUE(ref.SupportsReplacement()); |
GURL result = GURL(ref.ReplaceSearchTermsUsingTermsData( |
t_url, value.terms, |
- TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16(), |
+ TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, std::wstring(), |
search_terms_data)); |
ASSERT_TRUE(result.is_valid()); |
ASSERT_EQ(value.output, result.spec()); |
@@ -207,21 +206,21 @@ |
TEST_F(TemplateURLTest, URLRefTermToWide) { |
struct ToWideCase { |
const char* encoded_search_term; |
- const string16 expected_decoded_term; |
+ const wchar_t* expected_decoded_term; |
} to_wide_cases[] = { |
- {"hello+world", ASCIIToUTF16("hello world")}, |
+ {"hello+world", L"hello world"}, |
// Test some big-5 input. |
- {"%a7A%A6%6e+to+you", WideToUTF16(L"\x4f60\x597d to you")}, |
+ {"%a7A%A6%6e+to+you", L"\x4f60\x597d to you"}, |
// Test some UTF-8 input. We should fall back to this when the encoding |
// doesn't look like big-5. We have a '5' in the middle, which is an invalid |
// Big-5 trailing byte. |
- {"%e4%bd%a05%e5%a5%bd+to+you", WideToUTF16(L"\x4f60\x35\x597d to you")}, |
+ {"%e4%bd%a05%e5%a5%bd+to+you", L"\x4f60\x35\x597d to you"}, |
// Undecodable input should stay escaped. |
- {"%91%01+abcd", WideToUTF16(L"%91%01 abcd")}, |
+ {"%91%01+abcd", L"%91%01 abcd"}, |
// Make sure we convert %2B to +. |
- {"C%2B%2B", ASCIIToUTF16("C++")}, |
+ {"C%2B%2B", L"C++"}, |
// C%2B is escaped as C%252B, make sure we unescape it properly. |
- {"C%252B", ASCIIToUTF16("C%2B")}, |
+ {"C%252B", L"C%2B"}, |
}; |
TemplateURL t_url; |
@@ -236,10 +235,10 @@ |
ASSERT_TRUE(ref.SupportsReplacement()); |
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(to_wide_cases); i++) { |
- string16 result = ref.SearchTermToString16(t_url, |
+ std::wstring result = ref.SearchTermToWide(t_url, |
to_wide_cases[i].encoded_search_term); |
- EXPECT_EQ(to_wide_cases[i].expected_decoded_term, result); |
+ EXPECT_EQ(std::wstring(to_wide_cases[i].expected_decoded_term), result); |
} |
} |
@@ -259,16 +258,16 @@ |
TEST_F(TemplateURLTest, DisplayURLToURLRef) { |
struct TestData { |
const std::string url; |
- const string16 expected_result; |
+ const std::wstring expected_result; |
} data[] = { |
{ "http://foo{searchTerms}x{inputEncoding}y{outputEncoding}a", |
- ASCIIToUTF16("http://foo%sx{inputEncoding}y{outputEncoding}a") }, |
+ L"http://foo%sx{inputEncoding}y{outputEncoding}a" }, |
{ "http://X", |
- ASCIIToUTF16("http://X") }, |
+ L"http://X" }, |
{ "http://foo{searchTerms", |
- ASCIIToUTF16("http://foo{searchTerms") }, |
+ L"http://foo{searchTerms" }, |
{ "http://foo{searchTerms}{language}", |
- ASCIIToUTF16("http://foo%s{language}") }, |
+ L"http://foo%s{language}" }, |
}; |
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(data); ++i) { |
TemplateURLRef ref(data[i].url, 1, 2); |
@@ -317,8 +316,8 @@ |
std::string expected_result = data[i].expected_result; |
ReplaceSubstringsAfterOffset(&expected_result, 0, "{language}", |
g_browser_process->GetApplicationLocale()); |
- GURL result = GURL(ref.ReplaceSearchTerms(turl, ASCIIToUTF16("X"), |
- TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16())); |
+ GURL result = GURL(ref.ReplaceSearchTerms(turl, L"X", |
+ TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, std::wstring())); |
EXPECT_TRUE(result.is_valid()); |
EXPECT_EQ(expected_result, result.spec()); |
} |
@@ -330,15 +329,13 @@ |
TEST_F(TemplateURLTest, ReplaceArbitrarySearchTerms) { |
struct TestData { |
const std::string encoding; |
- const string16 search_term; |
+ const std::wstring search_term; |
const std::string url; |
const std::string expected_result; |
} data[] = { |
- { "BIG5", WideToUTF16(L"\x60BD"), |
- "http://foo/?{searchTerms}{inputEncoding}", |
+ { "BIG5", L"\x60BD", "http://foo/?{searchTerms}{inputEncoding}", |
"http://foo/?%B1~BIG5" }, |
- { "UTF-8", ASCIIToUTF16("blah"), |
- "http://foo/?{searchTerms}{inputEncoding}", |
+ { "UTF-8", L"blah", "http://foo/?{searchTerms}{inputEncoding}", |
"http://foo/?blahUTF-8" }, |
}; |
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(data); ++i) { |
@@ -347,7 +344,7 @@ |
TemplateURLRef ref(data[i].url, 1, 2); |
GURL result = GURL(ref.ReplaceSearchTerms(turl, |
data[i].search_term, TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, |
- string16())); |
+ std::wstring())); |
EXPECT_TRUE(result.is_valid()); |
EXPECT_EQ(data[i].expected_result, result.spec()); |
} |
@@ -356,19 +353,19 @@ |
TEST_F(TemplateURLTest, Suggestions) { |
struct TestData { |
const int accepted_suggestion; |
- const string16 original_query_for_suggestion; |
+ const std::wstring original_query_for_suggestion; |
const std::string expected_result; |
} data[] = { |
- { TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16(), |
+ { TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, std::wstring(), |
"http://bar/foo?q=foobar" }, |
- { TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, ASCIIToUTF16("foo"), |
+ { TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, L"foo", |
"http://bar/foo?q=foobar" }, |
- { TemplateURLRef::NO_SUGGESTION_CHOSEN, string16(), |
+ { TemplateURLRef::NO_SUGGESTION_CHOSEN, std::wstring(), |
"http://bar/foo?aq=f&q=foobar" }, |
- { TemplateURLRef::NO_SUGGESTION_CHOSEN, ASCIIToUTF16("foo"), |
+ { TemplateURLRef::NO_SUGGESTION_CHOSEN, L"foo", |
"http://bar/foo?aq=f&q=foobar" }, |
- { 0, string16(), "http://bar/foo?aq=0&oq=&q=foobar" }, |
- { 1, ASCIIToUTF16("foo"), "http://bar/foo?aq=1&oq=foo&q=foobar" }, |
+ { 0, std::wstring(), "http://bar/foo?aq=0&oq=&q=foobar" }, |
+ { 1, L"foo", "http://bar/foo?aq=1&oq=foo&q=foobar" }, |
}; |
TemplateURL turl; |
turl.add_input_encoding("UTF-8"); |
@@ -377,7 +374,7 @@ |
ASSERT_TRUE(ref.IsValid()); |
ASSERT_TRUE(ref.SupportsReplacement()); |
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(data); ++i) { |
- GURL result = GURL(ref.ReplaceSearchTerms(turl, ASCIIToUTF16("foobar"), |
+ GURL result = GURL(ref.ReplaceSearchTerms(turl, L"foobar", |
data[i].accepted_suggestion, data[i].original_query_for_suggestion)); |
EXPECT_TRUE(result.is_valid()); |
EXPECT_EQ(data[i].expected_result, result.spec()); |
@@ -386,7 +383,7 @@ |
#if defined(OS_WIN) |
TEST_F(TemplateURLTest, RLZ) { |
- string16 rlz_string; |
+ std::wstring rlz_string; |
#if defined(GOOGLE_CHROME_BUILD) |
RLZTracker::GetAccessPointRlz(rlz_lib::CHROME_OMNIBOX, &rlz_string); |
#endif |
@@ -396,7 +393,7 @@ |
ASSERT_TRUE(ref.IsValid()); |
ASSERT_TRUE(ref.SupportsReplacement()); |
GURL result(ref.ReplaceSearchTerms(t_url, L"x", |
- TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16())); |
+ TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, std::wstring())); |
ASSERT_TRUE(result.is_valid()); |
std::string expected_url = "http://bar/?"; |
if (!rlz_string.empty()) { |
@@ -464,14 +461,14 @@ |
TemplateURL t_url; |
t_url.SetURL("http://www.google.com/search", 0, 0); |
EXPECT_FALSE(t_url.autogenerate_keyword()); |
- t_url.set_keyword(ASCIIToUTF16("foo")); |
- EXPECT_EQ(ASCIIToUTF16("foo"), t_url.keyword()); |
+ t_url.set_keyword(L"foo"); |
+ EXPECT_EQ(L"foo", t_url.keyword()); |
t_url.set_autogenerate_keyword(true); |
EXPECT_TRUE(t_url.autogenerate_keyword()); |
- EXPECT_EQ(ASCIIToUTF16("google.com"), t_url.keyword()); |
- t_url.set_keyword(ASCIIToUTF16("foo")); |
+ EXPECT_EQ(L"google.com", t_url.keyword()); |
+ t_url.set_keyword(L"foo"); |
EXPECT_FALSE(t_url.autogenerate_keyword()); |
- EXPECT_EQ(ASCIIToUTF16("foo"), t_url.keyword()); |
+ EXPECT_EQ(L"foo", t_url.keyword()); |
} |
TEST_F(TemplateURLTest, ParseParameterKnown) { |