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

Side by Side Diff: chrome/browser/search_engines/template_url_parser_unittest.cc

Issue 6291003: Revert 71485 - Remove wstring from TemplateURL and friends.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 11 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 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 "base/file_util.h" 5 #include "base/file_util.h"
6 #include "base/logging.h" 6 #include "base/logging.h"
7 #include "base/path_service.h" 7 #include "base/path_service.h"
8 #include "base/utf_string_conversions.h"
9 #include "chrome/browser/search_engines/template_url.h" 8 #include "chrome/browser/search_engines/template_url.h"
10 #include "chrome/browser/search_engines/template_url_parser.h" 9 #include "chrome/browser/search_engines/template_url_parser.h"
11 #include "chrome/common/chrome_paths.h" 10 #include "chrome/common/chrome_paths.h"
12 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
13 12
14 class TemplateURLParserTest : public testing::Test { 13 class TemplateURLParserTest : public testing::Test {
15 public: 14 public:
16 TemplateURLParserTest() : parse_result_(true) { 15 TemplateURLParserTest() : parse_result_(true) {
17 } 16 }
18 17
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 return; 77 return;
79 ParseFile("post.xml", NULL); 78 ParseFile("post.xml", NULL);
80 EXPECT_FALSE(parse_result_); 79 EXPECT_FALSE(parse_result_);
81 } 80 }
82 81
83 TEST_F(TemplateURLParserTest, TestDictionary) { 82 TEST_F(TemplateURLParserTest, TestDictionary) {
84 if (IsDisabled()) 83 if (IsDisabled())
85 return; 84 return;
86 ParseFile("dictionary.xml", NULL); 85 ParseFile("dictionary.xml", NULL);
87 ASSERT_TRUE(parse_result_); 86 ASSERT_TRUE(parse_result_);
88 EXPECT_EQ(ASCIIToUTF16("Dictionary.com"), template_url_.short_name()); 87 EXPECT_EQ(L"Dictionary.com", template_url_.short_name());
89 EXPECT_TRUE(template_url_.GetFavIconURL() == 88 EXPECT_TRUE(template_url_.GetFavIconURL() ==
90 GURL("http://cache.lexico.com/g/d/favicon.ico")); 89 GURL("http://cache.lexico.com/g/d/favicon.ico"));
91 EXPECT_TRUE(template_url_.url() != NULL); 90 EXPECT_TRUE(template_url_.url() != NULL);
92 EXPECT_TRUE(template_url_.url()->SupportsReplacement()); 91 EXPECT_TRUE(template_url_.url()->SupportsReplacement());
93 EXPECT_EQ(template_url_.url()->url(), 92 EXPECT_EQ(template_url_.url()->url(),
94 "http://dictionary.reference.com/browse/{searchTerms}?r=75"); 93 "http://dictionary.reference.com/browse/{searchTerms}?r=75");
95 } 94 }
96 95
97 TEST_F(TemplateURLParserTest, TestMSDN) { 96 TEST_F(TemplateURLParserTest, TestMSDN) {
98 if (IsDisabled()) 97 if (IsDisabled())
99 return; 98 return;
100 ParseFile("msdn.xml", NULL); 99 ParseFile("msdn.xml", NULL);
101 ASSERT_TRUE(parse_result_); 100 ASSERT_TRUE(parse_result_);
102 EXPECT_EQ(ASCIIToUTF16("Search \" MSDN"), template_url_.short_name()); 101 EXPECT_EQ(L"Search \" MSDN", template_url_.short_name());
103 EXPECT_TRUE(template_url_.GetFavIconURL() == 102 EXPECT_TRUE(template_url_.GetFavIconURL() ==
104 GURL("http://search.msdn.microsoft.com/search/favicon.ico")); 103 GURL("http://search.msdn.microsoft.com/search/favicon.ico"));
105 EXPECT_TRUE(template_url_.url() != NULL); 104 EXPECT_TRUE(template_url_.url() != NULL);
106 EXPECT_TRUE(template_url_.url()->SupportsReplacement()); 105 EXPECT_TRUE(template_url_.url()->SupportsReplacement());
107 EXPECT_EQ(template_url_.url()->url(), 106 EXPECT_EQ(template_url_.url()->url(),
108 "http://search.msdn.microsoft.com/search/default.aspx?Query={searchT erms}&brand=msdn&locale=en-US"); 107 "http://search.msdn.microsoft.com/search/default.aspx?Query={searchT erms}&brand=msdn&locale=en-US");
109 } 108 }
110 109
111 TEST_F(TemplateURLParserTest, TestWikipedia) { 110 TEST_F(TemplateURLParserTest, TestWikipedia) {
112 if (IsDisabled()) 111 if (IsDisabled())
113 return; 112 return;
114 ParseFile("wikipedia.xml", NULL); 113 ParseFile("wikipedia.xml", NULL);
115 ASSERT_TRUE(parse_result_); 114 ASSERT_TRUE(parse_result_);
116 EXPECT_EQ(ASCIIToUTF16("Wikipedia (English)"), template_url_.short_name()); 115 EXPECT_EQ(L"Wikipedia (English)", template_url_.short_name());
117 EXPECT_TRUE(template_url_.GetFavIconURL() == 116 EXPECT_TRUE(template_url_.GetFavIconURL() ==
118 GURL("http://en.wikipedia.org/favicon.ico")); 117 GURL("http://en.wikipedia.org/favicon.ico"));
119 EXPECT_TRUE(template_url_.url() != NULL); 118 EXPECT_TRUE(template_url_.url() != NULL);
120 EXPECT_TRUE(template_url_.url()->SupportsReplacement()); 119 EXPECT_TRUE(template_url_.url()->SupportsReplacement());
121 EXPECT_EQ(template_url_.url()->url(), 120 EXPECT_EQ(template_url_.url()->url(),
122 "http://en.wikipedia.org/w/index.php?title=Special:Search&search={searchTe rms}"); 121 "http://en.wikipedia.org/w/index.php?title=Special:Search&search={searchTe rms}");
123 EXPECT_TRUE(template_url_.suggestions_url() != NULL); 122 EXPECT_TRUE(template_url_.suggestions_url() != NULL);
124 EXPECT_TRUE(template_url_.suggestions_url()->SupportsReplacement()); 123 EXPECT_TRUE(template_url_.suggestions_url()->SupportsReplacement());
125 EXPECT_EQ(template_url_.suggestions_url()->url(), 124 EXPECT_EQ(template_url_.suggestions_url()->url(),
126 "http://en.wikipedia.org/w/api.php?action=opensearch&search={searchTerms}" ); 125 "http://en.wikipedia.org/w/api.php?action=opensearch&search={searchTerms}" );
(...skipping 30 matching lines...) Expand all
157 }; 156 };
158 157
159 TEST_F(TemplateURLParserTest, TestFirefoxEbay) { 158 TEST_F(TemplateURLParserTest, TestFirefoxEbay) {
160 if (IsDisabled()) 159 if (IsDisabled())
161 return; 160 return;
162 // This file uses the Parameter extension 161 // This file uses the Parameter extension
163 // (see http://www.opensearch.org/Specifications/OpenSearch/Extensions/Paramet er/1.0) 162 // (see http://www.opensearch.org/Specifications/OpenSearch/Extensions/Paramet er/1.0)
164 ParamFilterImpl filter("ebay", "ebay"); 163 ParamFilterImpl filter("ebay", "ebay");
165 ParseFile("firefox_ebay.xml", &filter); 164 ParseFile("firefox_ebay.xml", &filter);
166 ASSERT_TRUE(parse_result_); 165 ASSERT_TRUE(parse_result_);
167 EXPECT_EQ(ASCIIToUTF16("eBay"), template_url_.short_name()); 166 EXPECT_EQ(L"eBay", template_url_.short_name());
168 EXPECT_TRUE(template_url_.url() != NULL); 167 EXPECT_TRUE(template_url_.url() != NULL);
169 EXPECT_TRUE(template_url_.url()->SupportsReplacement()); 168 EXPECT_TRUE(template_url_.url()->SupportsReplacement());
170 std::string exp_url = 169 std::string exp_url =
171 "http://search.ebay.com/search/search.dll?query={searchTerms}&" 170 "http://search.ebay.com/search/search.dll?query={searchTerms}&"
172 "MfcISAPICommand=GetResult&ht=1&srchdesc=n&maxRecordsReturned=300&" 171 "MfcISAPICommand=GetResult&ht=1&srchdesc=n&maxRecordsReturned=300&"
173 "maxRecordsPerPage=50&SortProperty=MetaEndSort"; 172 "maxRecordsPerPage=50&SortProperty=MetaEndSort";
174 EXPECT_EQ(exp_url, template_url_.url()->url()); 173 EXPECT_EQ(exp_url, template_url_.url()->url());
175 ASSERT_EQ(1U, template_url_.input_encodings().size()); 174 ASSERT_EQ(1U, template_url_.input_encodings().size());
176 EXPECT_EQ("ISO-8859-1", template_url_.input_encodings()[0]); 175 EXPECT_EQ("ISO-8859-1", template_url_.input_encodings()[0]);
177 EXPECT_EQ(GURL("http://search.ebay.com/favicon.ico"), 176 EXPECT_EQ(GURL("http://search.ebay.com/favicon.ico"),
178 template_url_.GetFavIconURL()); 177 template_url_.GetFavIconURL());
179 } 178 }
180 179
181 TEST_F(TemplateURLParserTest, TestFirefoxWebster) { 180 TEST_F(TemplateURLParserTest, TestFirefoxWebster) {
182 if (IsDisabled()) 181 if (IsDisabled())
183 return; 182 return;
184 // This XML file uses a namespace. 183 // This XML file uses a namespace.
185 ParamFilterImpl filter("", "Mozilla"); 184 ParamFilterImpl filter("", "Mozilla");
186 ParseFile("firefox_webster.xml", &filter); 185 ParseFile("firefox_webster.xml", &filter);
187 ASSERT_TRUE(parse_result_); 186 ASSERT_TRUE(parse_result_);
188 EXPECT_EQ(ASCIIToUTF16("Webster"), template_url_.short_name()); 187 EXPECT_EQ(L"Webster", template_url_.short_name());
189 EXPECT_TRUE(template_url_.url() != NULL); 188 EXPECT_TRUE(template_url_.url() != NULL);
190 EXPECT_TRUE(template_url_.url()->SupportsReplacement()); 189 EXPECT_TRUE(template_url_.url()->SupportsReplacement());
191 EXPECT_EQ("http://www.webster.com/cgi-bin/dictionary?va={searchTerms}", 190 EXPECT_EQ("http://www.webster.com/cgi-bin/dictionary?va={searchTerms}",
192 template_url_.url()->url()); 191 template_url_.url()->url());
193 ASSERT_EQ(1U, template_url_.input_encodings().size()); 192 ASSERT_EQ(1U, template_url_.input_encodings().size());
194 EXPECT_EQ("ISO-8859-1", template_url_.input_encodings()[0]); 193 EXPECT_EQ("ISO-8859-1", template_url_.input_encodings()[0]);
195 EXPECT_EQ(GURL("http://www.webster.com/favicon.ico"), 194 EXPECT_EQ(GURL("http://www.webster.com/favicon.ico"),
196 template_url_.GetFavIconURL()); 195 template_url_.GetFavIconURL());
197 } 196 }
198 197
199 TEST_F(TemplateURLParserTest, TestFirefoxYahoo) { 198 TEST_F(TemplateURLParserTest, TestFirefoxYahoo) {
200 if (IsDisabled()) 199 if (IsDisabled())
201 return; 200 return;
202 // This XML file uses a namespace. 201 // This XML file uses a namespace.
203 ParamFilterImpl filter("", "Mozilla"); 202 ParamFilterImpl filter("", "Mozilla");
204 ParseFile("firefox_yahoo.xml", &filter); 203 ParseFile("firefox_yahoo.xml", &filter);
205 ASSERT_TRUE(parse_result_); 204 ASSERT_TRUE(parse_result_);
206 EXPECT_EQ(ASCIIToUTF16("Yahoo"), template_url_.short_name()); 205 EXPECT_EQ(L"Yahoo", template_url_.short_name());
207 EXPECT_TRUE(template_url_.url() != NULL); 206 EXPECT_TRUE(template_url_.url() != NULL);
208 EXPECT_TRUE(template_url_.url()->SupportsReplacement()); 207 EXPECT_TRUE(template_url_.url()->SupportsReplacement());
209 EXPECT_EQ("http://ff.search.yahoo.com/gossip?" 208 EXPECT_EQ("http://ff.search.yahoo.com/gossip?"
210 "output=fxjson&command={searchTerms}", 209 "output=fxjson&command={searchTerms}",
211 template_url_.suggestions_url()->url()); 210 template_url_.suggestions_url()->url());
212 EXPECT_EQ("http://search.yahoo.com/search?p={searchTerms}&ei=UTF-8", 211 EXPECT_EQ("http://search.yahoo.com/search?p={searchTerms}&ei=UTF-8",
213 template_url_.url()->url()); 212 template_url_.url()->url());
214 ASSERT_EQ(1U, template_url_.input_encodings().size()); 213 ASSERT_EQ(1U, template_url_.input_encodings().size());
215 EXPECT_EQ("UTF-8", template_url_.input_encodings()[0]); 214 EXPECT_EQ("UTF-8", template_url_.input_encodings()[0]);
216 EXPECT_EQ(GURL("http://search.yahoo.com/favicon.ico"), 215 EXPECT_EQ(GURL("http://search.yahoo.com/favicon.ico"),
217 template_url_.GetFavIconURL()); 216 template_url_.GetFavIconURL());
218 } 217 }
219 218
220 // Make sure we ignore POST suggestions (this is the same XML file as 219 // Make sure we ignore POST suggestions (this is the same XML file as
221 // firefox_yahoo.xml, the suggestion method was just changed to POST). 220 // firefox_yahoo.xml, the suggestion method was just changed to POST).
222 TEST_F(TemplateURLParserTest, TestPostSuggestion) { 221 TEST_F(TemplateURLParserTest, TestPostSuggestion) {
223 if (IsDisabled()) 222 if (IsDisabled())
224 return; 223 return;
225 // This XML file uses a namespace. 224 // This XML file uses a namespace.
226 ParamFilterImpl filter("", "Mozilla"); 225 ParamFilterImpl filter("", "Mozilla");
227 ParseFile("post_suggestion.xml", &filter); 226 ParseFile("post_suggestion.xml", &filter);
228 ASSERT_TRUE(parse_result_); 227 ASSERT_TRUE(parse_result_);
229 EXPECT_EQ(ASCIIToUTF16("Yahoo"), template_url_.short_name()); 228 EXPECT_EQ(L"Yahoo", template_url_.short_name());
230 EXPECT_TRUE(template_url_.url() != NULL); 229 EXPECT_TRUE(template_url_.url() != NULL);
231 EXPECT_TRUE(template_url_.url()->SupportsReplacement()); 230 EXPECT_TRUE(template_url_.url()->SupportsReplacement());
232 EXPECT_TRUE(template_url_.suggestions_url() == NULL); 231 EXPECT_TRUE(template_url_.suggestions_url() == NULL);
233 EXPECT_EQ("http://search.yahoo.com/search?p={searchTerms}&ei=UTF-8", 232 EXPECT_EQ("http://search.yahoo.com/search?p={searchTerms}&ei=UTF-8",
234 template_url_.url()->url()); 233 template_url_.url()->url());
235 ASSERT_EQ(1U, template_url_.input_encodings().size()); 234 ASSERT_EQ(1U, template_url_.input_encodings().size());
236 EXPECT_EQ("UTF-8", template_url_.input_encodings()[0]); 235 EXPECT_EQ("UTF-8", template_url_.input_encodings()[0]);
237 EXPECT_EQ(GURL("http://search.yahoo.com/favicon.ico"), 236 EXPECT_EQ(GURL("http://search.yahoo.com/favicon.ico"),
238 template_url_.GetFavIconURL()); 237 template_url_.GetFavIconURL());
239 } 238 }
OLDNEW
« no previous file with comments | « chrome/browser/search_engines/template_url_parser.cc ('k') | chrome/browser/search_engines/template_url_prepopulate_data.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698