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