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

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

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