OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/utf_string_conversions.h" |
9 #include "chrome/browser/search_engines/template_url.h" | 9 #include "chrome/browser/search_engines/template_url.h" |
10 #include "chrome/browser/search_engines/template_url_parser.h" | 10 #include "chrome/browser/search_engines/template_url_parser.h" |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 } | 128 } |
129 | 129 |
130 TEST_F(TemplateURLParserTest, TestDictionary) { | 130 TEST_F(TemplateURLParserTest, TestDictionary) { |
131 if (is_disabled()) | 131 if (is_disabled()) |
132 return; | 132 return; |
133 ASSERT_NO_FATAL_FAILURE(ParseFile("dictionary.xml", NULL)); | 133 ASSERT_NO_FATAL_FAILURE(ParseFile("dictionary.xml", NULL)); |
134 ASSERT_TRUE(template_url_.get()); | 134 ASSERT_TRUE(template_url_.get()); |
135 EXPECT_EQ(ASCIIToUTF16("Dictionary.com"), template_url_->short_name()); | 135 EXPECT_EQ(ASCIIToUTF16("Dictionary.com"), template_url_->short_name()); |
136 EXPECT_EQ(GURL("http://cache.lexico.com/g/d/favicon.ico"), | 136 EXPECT_EQ(GURL("http://cache.lexico.com/g/d/favicon.ico"), |
137 template_url_->favicon_url()); | 137 template_url_->favicon_url()); |
138 EXPECT_TRUE(template_url_->url_ref().SupportsReplacement()); | 138 ASSERT_FALSE(template_url_->url() == NULL); |
| 139 EXPECT_TRUE(template_url_->url()->SupportsReplacement()); |
139 EXPECT_EQ("http://dictionary.reference.com/browse/{searchTerms}?r=75", | 140 EXPECT_EQ("http://dictionary.reference.com/browse/{searchTerms}?r=75", |
140 template_url_->url()); | 141 template_url_->url()->url()); |
141 } | 142 } |
142 | 143 |
143 TEST_F(TemplateURLParserTest, TestMSDN) { | 144 TEST_F(TemplateURLParserTest, TestMSDN) { |
144 if (is_disabled()) | 145 if (is_disabled()) |
145 return; | 146 return; |
146 ASSERT_NO_FATAL_FAILURE(ParseFile("msdn.xml", NULL)); | 147 ASSERT_NO_FATAL_FAILURE(ParseFile("msdn.xml", NULL)); |
147 ASSERT_TRUE(template_url_.get()); | 148 ASSERT_TRUE(template_url_.get()); |
148 EXPECT_EQ(ASCIIToUTF16("Search \" MSDN"), template_url_->short_name()); | 149 EXPECT_EQ(ASCIIToUTF16("Search \" MSDN"), template_url_->short_name()); |
149 EXPECT_EQ(GURL("http://search.msdn.microsoft.com/search/favicon.ico"), | 150 EXPECT_EQ(GURL("http://search.msdn.microsoft.com/search/favicon.ico"), |
150 template_url_->favicon_url()); | 151 template_url_->favicon_url()); |
151 EXPECT_TRUE(template_url_->url_ref().SupportsReplacement()); | 152 ASSERT_FALSE(template_url_->url() == NULL); |
| 153 EXPECT_TRUE(template_url_->url()->SupportsReplacement()); |
152 EXPECT_EQ("http://search.msdn.microsoft.com/search/default.aspx?" | 154 EXPECT_EQ("http://search.msdn.microsoft.com/search/default.aspx?" |
153 "Query={searchTerms}&brand=msdn&locale=en-US", | 155 "Query={searchTerms}&brand=msdn&locale=en-US", |
154 template_url_->url()); | 156 template_url_->url()->url()); |
155 } | 157 } |
156 | 158 |
157 TEST_F(TemplateURLParserTest, TestWikipedia) { | 159 TEST_F(TemplateURLParserTest, TestWikipedia) { |
158 if (is_disabled()) | 160 if (is_disabled()) |
159 return; | 161 return; |
160 ASSERT_NO_FATAL_FAILURE(ParseFile("wikipedia.xml", NULL)); | 162 ASSERT_NO_FATAL_FAILURE(ParseFile("wikipedia.xml", NULL)); |
161 ASSERT_TRUE(template_url_.get()); | 163 ASSERT_TRUE(template_url_.get()); |
162 EXPECT_EQ(ASCIIToUTF16("Wikipedia (English)"), template_url_->short_name()); | 164 EXPECT_EQ(ASCIIToUTF16("Wikipedia (English)"), template_url_->short_name()); |
163 EXPECT_EQ(GURL("http://en.wikipedia.org/favicon.ico"), | 165 EXPECT_EQ(GURL("http://en.wikipedia.org/favicon.ico"), |
164 template_url_->favicon_url()); | 166 template_url_->favicon_url()); |
165 EXPECT_TRUE(template_url_->url_ref().SupportsReplacement()); | 167 ASSERT_FALSE(template_url_->url() == NULL); |
| 168 EXPECT_TRUE(template_url_->url()->SupportsReplacement()); |
166 EXPECT_EQ("http://en.wikipedia.org/w/index.php?" | 169 EXPECT_EQ("http://en.wikipedia.org/w/index.php?" |
167 "title=Special:Search&search={searchTerms}", | 170 "title=Special:Search&search={searchTerms}", |
168 template_url_->url()); | 171 template_url_->url()->url()); |
169 EXPECT_TRUE(template_url_->suggestions_url_ref().SupportsReplacement()); | 172 ASSERT_FALSE(template_url_->suggestions_url() == NULL); |
| 173 EXPECT_TRUE(template_url_->suggestions_url()->SupportsReplacement()); |
170 EXPECT_EQ("http://en.wikipedia.org/w/api.php?" | 174 EXPECT_EQ("http://en.wikipedia.org/w/api.php?" |
171 "action=opensearch&search={searchTerms}", | 175 "action=opensearch&search={searchTerms}", |
172 template_url_->suggestions_url()); | 176 template_url_->suggestions_url()->url()); |
173 ASSERT_EQ(2U, template_url_->input_encodings().size()); | 177 ASSERT_EQ(2U, template_url_->input_encodings().size()); |
174 EXPECT_EQ("UTF-8", template_url_->input_encodings()[0]); | 178 EXPECT_EQ("UTF-8", template_url_->input_encodings()[0]); |
175 EXPECT_EQ("Shift_JIS", template_url_->input_encodings()[1]); | 179 EXPECT_EQ("Shift_JIS", template_url_->input_encodings()[1]); |
176 } | 180 } |
177 | 181 |
178 TEST_F(TemplateURLParserTest, NoCrashOnEmptyAttributes) { | 182 TEST_F(TemplateURLParserTest, NoCrashOnEmptyAttributes) { |
179 if (is_disabled()) | 183 if (is_disabled()) |
180 return; | 184 return; |
181 ASSERT_NO_FATAL_FAILURE(ParseFile("url_with_no_attributes.xml", NULL)); | 185 ASSERT_NO_FATAL_FAILURE(ParseFile("url_with_no_attributes.xml", NULL)); |
182 } | 186 } |
183 | 187 |
184 TEST_F(TemplateURLParserTest, TestFirefoxEbay) { | 188 TEST_F(TemplateURLParserTest, TestFirefoxEbay) { |
185 if (is_disabled()) | 189 if (is_disabled()) |
186 return; | 190 return; |
187 // This file uses the Parameter extension | 191 // This file uses the Parameter extension |
188 // (see http://www.opensearch.org/Specifications/OpenSearch/Extensions/Paramet
er/1.0) | 192 // (see http://www.opensearch.org/Specifications/OpenSearch/Extensions/Paramet
er/1.0) |
189 ParamFilterImpl filter("ebay", "ebay"); | 193 ParamFilterImpl filter("ebay", "ebay"); |
190 ASSERT_NO_FATAL_FAILURE(ParseFile("firefox_ebay.xml", &filter)); | 194 ASSERT_NO_FATAL_FAILURE(ParseFile("firefox_ebay.xml", &filter)); |
191 ASSERT_TRUE(template_url_.get()); | 195 ASSERT_TRUE(template_url_.get()); |
192 EXPECT_EQ(ASCIIToUTF16("eBay"), template_url_->short_name()); | 196 EXPECT_EQ(ASCIIToUTF16("eBay"), template_url_->short_name()); |
193 EXPECT_TRUE(template_url_->url_ref().SupportsReplacement()); | 197 ASSERT_FALSE(template_url_->url() == NULL); |
| 198 EXPECT_TRUE(template_url_->url()->SupportsReplacement()); |
194 EXPECT_EQ("http://search.ebay.com/search/search.dll?query={searchTerms}&" | 199 EXPECT_EQ("http://search.ebay.com/search/search.dll?query={searchTerms}&" |
195 "MfcISAPICommand=GetResult&ht=1&srchdesc=n&maxRecordsReturned=300&" | 200 "MfcISAPICommand=GetResult&ht=1&srchdesc=n&maxRecordsReturned=300&" |
196 "maxRecordsPerPage=50&SortProperty=MetaEndSort", | 201 "maxRecordsPerPage=50&SortProperty=MetaEndSort", |
197 template_url_->url()); | 202 template_url_->url()->url()); |
198 ASSERT_EQ(1U, template_url_->input_encodings().size()); | 203 ASSERT_EQ(1U, template_url_->input_encodings().size()); |
199 EXPECT_EQ("ISO-8859-1", template_url_->input_encodings()[0]); | 204 EXPECT_EQ("ISO-8859-1", template_url_->input_encodings()[0]); |
200 EXPECT_EQ(GURL("http://search.ebay.com/favicon.ico"), | 205 EXPECT_EQ(GURL("http://search.ebay.com/favicon.ico"), |
201 template_url_->favicon_url()); | 206 template_url_->favicon_url()); |
202 } | 207 } |
203 | 208 |
204 TEST_F(TemplateURLParserTest, TestFirefoxWebster) { | 209 TEST_F(TemplateURLParserTest, TestFirefoxWebster) { |
205 if (is_disabled()) | 210 if (is_disabled()) |
206 return; | 211 return; |
207 // This XML file uses a namespace. | 212 // This XML file uses a namespace. |
208 ParamFilterImpl filter(std::string(), "Mozilla"); | 213 ParamFilterImpl filter(std::string(), "Mozilla"); |
209 ASSERT_NO_FATAL_FAILURE(ParseFile("firefox_webster.xml", &filter)); | 214 ASSERT_NO_FATAL_FAILURE(ParseFile("firefox_webster.xml", &filter)); |
210 ASSERT_TRUE(template_url_.get()); | 215 ASSERT_TRUE(template_url_.get()); |
211 EXPECT_EQ(ASCIIToUTF16("Webster"), template_url_->short_name()); | 216 EXPECT_EQ(ASCIIToUTF16("Webster"), template_url_->short_name()); |
212 EXPECT_TRUE(template_url_->url_ref().SupportsReplacement()); | 217 ASSERT_FALSE(template_url_->url() == NULL); |
| 218 EXPECT_TRUE(template_url_->url()->SupportsReplacement()); |
213 EXPECT_EQ("http://www.webster.com/cgi-bin/dictionary?va={searchTerms}", | 219 EXPECT_EQ("http://www.webster.com/cgi-bin/dictionary?va={searchTerms}", |
214 template_url_->url()); | 220 template_url_->url()->url()); |
215 ASSERT_EQ(1U, template_url_->input_encodings().size()); | 221 ASSERT_EQ(1U, template_url_->input_encodings().size()); |
216 EXPECT_EQ("ISO-8859-1", template_url_->input_encodings()[0]); | 222 EXPECT_EQ("ISO-8859-1", template_url_->input_encodings()[0]); |
217 EXPECT_EQ(GURL("http://www.webster.com/favicon.ico"), | 223 EXPECT_EQ(GURL("http://www.webster.com/favicon.ico"), |
218 template_url_->favicon_url()); | 224 template_url_->favicon_url()); |
219 } | 225 } |
220 | 226 |
221 TEST_F(TemplateURLParserTest, TestFirefoxYahoo) { | 227 TEST_F(TemplateURLParserTest, TestFirefoxYahoo) { |
222 if (is_disabled()) | 228 if (is_disabled()) |
223 return; | 229 return; |
224 // This XML file uses a namespace. | 230 // This XML file uses a namespace. |
225 ParamFilterImpl filter(std::string(), "Mozilla"); | 231 ParamFilterImpl filter(std::string(), "Mozilla"); |
226 ASSERT_NO_FATAL_FAILURE(ParseFile("firefox_yahoo.xml", &filter)); | 232 ASSERT_NO_FATAL_FAILURE(ParseFile("firefox_yahoo.xml", &filter)); |
227 ASSERT_TRUE(template_url_.get()); | 233 ASSERT_TRUE(template_url_.get()); |
228 EXPECT_EQ(ASCIIToUTF16("Yahoo"), template_url_->short_name()); | 234 EXPECT_EQ(ASCIIToUTF16("Yahoo"), template_url_->short_name()); |
229 EXPECT_TRUE(template_url_->url_ref().SupportsReplacement()); | 235 ASSERT_FALSE(template_url_->url() == NULL); |
| 236 EXPECT_TRUE(template_url_->url()->SupportsReplacement()); |
230 EXPECT_EQ("http://ff.search.yahoo.com/gossip?" | 237 EXPECT_EQ("http://ff.search.yahoo.com/gossip?" |
231 "output=fxjson&command={searchTerms}", | 238 "output=fxjson&command={searchTerms}", |
232 template_url_->suggestions_url()); | 239 template_url_->suggestions_url()->url()); |
233 EXPECT_EQ("http://search.yahoo.com/search?p={searchTerms}&ei=UTF-8", | 240 EXPECT_EQ("http://search.yahoo.com/search?p={searchTerms}&ei=UTF-8", |
234 template_url_->url()); | 241 template_url_->url()->url()); |
235 ASSERT_EQ(1U, template_url_->input_encodings().size()); | 242 ASSERT_EQ(1U, template_url_->input_encodings().size()); |
236 EXPECT_EQ("UTF-8", template_url_->input_encodings()[0]); | 243 EXPECT_EQ("UTF-8", template_url_->input_encodings()[0]); |
237 EXPECT_EQ(GURL("http://search.yahoo.com/favicon.ico"), | 244 EXPECT_EQ(GURL("http://search.yahoo.com/favicon.ico"), |
238 template_url_->favicon_url()); | 245 template_url_->favicon_url()); |
239 } | 246 } |
240 | 247 |
241 // Make sure we ignore POST suggestions (this is the same XML file as | 248 // Make sure we ignore POST suggestions (this is the same XML file as |
242 // firefox_yahoo.xml, the suggestion method was just changed to POST). | 249 // firefox_yahoo.xml, the suggestion method was just changed to POST). |
243 TEST_F(TemplateURLParserTest, TestPostSuggestion) { | 250 TEST_F(TemplateURLParserTest, TestPostSuggestion) { |
244 if (is_disabled()) | 251 if (is_disabled()) |
245 return; | 252 return; |
246 // This XML file uses a namespace. | 253 // This XML file uses a namespace. |
247 ParamFilterImpl filter(std::string(), "Mozilla"); | 254 ParamFilterImpl filter(std::string(), "Mozilla"); |
248 ASSERT_NO_FATAL_FAILURE(ParseFile("post_suggestion.xml", &filter)); | 255 ASSERT_NO_FATAL_FAILURE(ParseFile("post_suggestion.xml", &filter)); |
249 ASSERT_TRUE(template_url_.get()); | 256 ASSERT_TRUE(template_url_.get()); |
250 EXPECT_EQ(ASCIIToUTF16("Yahoo"), template_url_->short_name()); | 257 EXPECT_EQ(ASCIIToUTF16("Yahoo"), template_url_->short_name()); |
251 EXPECT_TRUE(template_url_->url_ref().SupportsReplacement()); | 258 ASSERT_FALSE(template_url_->url() == NULL); |
252 EXPECT_TRUE(template_url_->suggestions_url().empty()); | 259 EXPECT_TRUE(template_url_->url()->SupportsReplacement()); |
| 260 EXPECT_TRUE(template_url_->suggestions_url() == NULL); |
253 EXPECT_EQ("http://search.yahoo.com/search?p={searchTerms}&ei=UTF-8", | 261 EXPECT_EQ("http://search.yahoo.com/search?p={searchTerms}&ei=UTF-8", |
254 template_url_->url()); | 262 template_url_->url()->url()); |
255 ASSERT_EQ(1U, template_url_->input_encodings().size()); | 263 ASSERT_EQ(1U, template_url_->input_encodings().size()); |
256 EXPECT_EQ("UTF-8", template_url_->input_encodings()[0]); | 264 EXPECT_EQ("UTF-8", template_url_->input_encodings()[0]); |
257 EXPECT_EQ(GURL("http://search.yahoo.com/favicon.ico"), | 265 EXPECT_EQ(GURL("http://search.yahoo.com/favicon.ico"), |
258 template_url_->favicon_url()); | 266 template_url_->favicon_url()); |
259 } | 267 } |
OLD | NEW |