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

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

Issue 14419: Porting in browser/webdata and template_url. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 12 years 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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 <windows.h>
6
7 #include "base/file_util.h" 5 #include "base/file_util.h"
8 #include "base/logging.h" 6 #include "base/logging.h"
9 #include "base/path_service.h" 7 #include "base/path_service.h"
10 #include "base/scoped_ptr.h" 8 #include "base/scoped_ptr.h"
11 #include "chrome/browser/template_url.h" 9 #include "chrome/browser/template_url.h"
12 #include "chrome/browser/template_url_parser.h" 10 #include "chrome/browser/template_url_parser.h"
13 #include "chrome/common/chrome_paths.h" 11 #include "chrome/common/chrome_paths.h"
14 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
15 13
16 class TemplateURLParserTest : public testing::Test { 14 class TemplateURLParserTest : public testing::Test {
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 EXPECT_TRUE(template_url_.GetFavIconURL() == 118 EXPECT_TRUE(template_url_.GetFavIconURL() ==
121 GURL("http://en.wikipedia.org/favicon.ico")); 119 GURL("http://en.wikipedia.org/favicon.ico"));
122 EXPECT_TRUE(template_url_.url() != NULL); 120 EXPECT_TRUE(template_url_.url() != NULL);
123 EXPECT_TRUE(template_url_.url()->SupportsReplacement()); 121 EXPECT_TRUE(template_url_.url()->SupportsReplacement());
124 EXPECT_EQ(template_url_.url()->url(), 122 EXPECT_EQ(template_url_.url()->url(),
125 L"http://en.wikipedia.org/w/index.php?title=Special:Search&search={searchT erms}"); 123 L"http://en.wikipedia.org/w/index.php?title=Special:Search&search={searchT erms}");
126 EXPECT_TRUE(template_url_.suggestions_url() != NULL); 124 EXPECT_TRUE(template_url_.suggestions_url() != NULL);
127 EXPECT_TRUE(template_url_.suggestions_url()->SupportsReplacement()); 125 EXPECT_TRUE(template_url_.suggestions_url()->SupportsReplacement());
128 EXPECT_EQ(template_url_.suggestions_url()->url(), 126 EXPECT_EQ(template_url_.suggestions_url()->url(),
129 L"http://en.wikipedia.org/w/api.php?action=opensearch&search={searchTerms} "); 127 L"http://en.wikipedia.org/w/api.php?action=opensearch&search={searchTerms} ");
130 ASSERT_EQ(2, template_url_.input_encodings().size()); 128 ASSERT_EQ(2U, template_url_.input_encodings().size());
131 EXPECT_EQ("UTF-8", template_url_.input_encodings()[0]); 129 EXPECT_EQ("UTF-8", template_url_.input_encodings()[0]);
132 EXPECT_EQ("Shift_JIS", template_url_.input_encodings()[1]); 130 EXPECT_EQ("Shift_JIS", template_url_.input_encodings()[1]);
133 } 131 }
134 132
135 TEST_F(TemplateURLParserTest, NoCrashOnEmptyAttributes) { 133 TEST_F(TemplateURLParserTest, NoCrashOnEmptyAttributes) {
136 if (IsDisabled()) 134 if (IsDisabled())
137 return; 135 return;
138 ParseFile(L"url_with_no_attributes.xml", NULL); 136 ParseFile(L"url_with_no_attributes.xml", NULL);
139 } 137 }
140 138
141 // Filters any param which as an occurrence of name_str_ in its name or an 139 // Filters any param which as an occurrence of name_str_ in its name or an
142 // occurrence of value_str_ in its value. 140 // occurrence of value_str_ in its value.
143 class ParamFilterImpl : public TemplateURLParser::ParameterFilter { 141 class ParamFilterImpl : public TemplateURLParser::ParameterFilter {
144 public: 142 public:
145 ParamFilterImpl(std::string name_str, std::string value_str) 143 ParamFilterImpl(std::string name_str, std::string value_str)
146 : name_str_(name_str), 144 : name_str_(name_str),
147 value_str_(value_str) { 145 value_str_(value_str) {
148 } 146 }
149 147
150 bool KeepParameter(const std::string& key, const std::string& value) { 148 bool KeepParameter(const std::string& key, const std::string& value) {
151 return (name_str_.empty() || key.find(name_str_) == -1) && 149 return (name_str_.empty() || key.find(name_str_) == std::string::npos) &&
152 (value_str_.empty() || value.find(value_str_) == -1); 150 (value_str_.empty() || value.find(value_str_) == std::string::npos);
153 } 151 }
154 152
155 private: 153 private:
156 std::string name_str_; 154 std::string name_str_;
157 std::string value_str_; 155 std::string value_str_;
158 156
159 DISALLOW_EVIL_CONSTRUCTORS(ParamFilterImpl); 157 DISALLOW_EVIL_CONSTRUCTORS(ParamFilterImpl);
160 }; 158 };
161 159
162 TEST_F(TemplateURLParserTest, TestFirefoxEbay) { 160 TEST_F(TemplateURLParserTest, TestFirefoxEbay) {
163 if (IsDisabled()) 161 if (IsDisabled())
164 return; 162 return;
165 // This file uses the Parameter extension 163 // This file uses the Parameter extension
166 // (see http://www.opensearch.org/Specifications/OpenSearch/Extensions/Paramet er/1.0) 164 // (see http://www.opensearch.org/Specifications/OpenSearch/Extensions/Paramet er/1.0)
167 ParamFilterImpl filter("ebay", "ebay"); 165 ParamFilterImpl filter("ebay", "ebay");
168 ParseFile(L"firefox_ebay.xml", &filter); 166 ParseFile(L"firefox_ebay.xml", &filter);
169 ASSERT_TRUE(parse_result_); 167 ASSERT_TRUE(parse_result_);
170 EXPECT_EQ(L"eBay", template_url_.short_name()); 168 EXPECT_EQ(L"eBay", template_url_.short_name());
171 EXPECT_TRUE(template_url_.url() != NULL); 169 EXPECT_TRUE(template_url_.url() != NULL);
172 EXPECT_TRUE(template_url_.url()->SupportsReplacement()); 170 EXPECT_TRUE(template_url_.url()->SupportsReplacement());
173 std::wstring exp_url = 171 std::wstring exp_url =
174 L"http://search.ebay.com/search/search.dll?query={searchTerms}&" 172 L"http://search.ebay.com/search/search.dll?query={searchTerms}&"
175 L"MfcISAPICommand=GetResult&ht=1&srchdesc=n&maxRecordsReturned=300&" 173 L"MfcISAPICommand=GetResult&ht=1&srchdesc=n&maxRecordsReturned=300&"
176 L"maxRecordsPerPage=50&SortProperty=MetaEndSort"; 174 L"maxRecordsPerPage=50&SortProperty=MetaEndSort";
177 EXPECT_EQ(exp_url, template_url_.url()->url()); 175 EXPECT_EQ(exp_url, template_url_.url()->url());
178 ASSERT_EQ(1, template_url_.input_encodings().size()); 176 ASSERT_EQ(1U, template_url_.input_encodings().size());
179 EXPECT_EQ("ISO-8859-1", template_url_.input_encodings()[0]); 177 EXPECT_EQ("ISO-8859-1", template_url_.input_encodings()[0]);
180 EXPECT_EQ(GURL("http://search.ebay.com/favicon.ico"), 178 EXPECT_EQ(GURL("http://search.ebay.com/favicon.ico"),
181 template_url_.GetFavIconURL()); 179 template_url_.GetFavIconURL());
182 } 180 }
183 181
184 TEST_F(TemplateURLParserTest, TestFirefoxWebster) { 182 TEST_F(TemplateURLParserTest, TestFirefoxWebster) {
185 if (IsDisabled()) 183 if (IsDisabled())
186 return; 184 return;
187 // This XML file uses a namespace. 185 // This XML file uses a namespace.
188 ParamFilterImpl filter("", "Mozilla"); 186 ParamFilterImpl filter("", "Mozilla");
189 ParseFile(L"firefox_webster.xml", &filter); 187 ParseFile(L"firefox_webster.xml", &filter);
190 ASSERT_TRUE(parse_result_); 188 ASSERT_TRUE(parse_result_);
191 EXPECT_EQ(L"Webster", template_url_.short_name()); 189 EXPECT_EQ(L"Webster", template_url_.short_name());
192 EXPECT_TRUE(template_url_.url() != NULL); 190 EXPECT_TRUE(template_url_.url() != NULL);
193 EXPECT_TRUE(template_url_.url()->SupportsReplacement()); 191 EXPECT_TRUE(template_url_.url()->SupportsReplacement());
194 EXPECT_EQ(L"http://www.webster.com/cgi-bin/dictionary?va={searchTerms}", 192 EXPECT_EQ(L"http://www.webster.com/cgi-bin/dictionary?va={searchTerms}",
195 template_url_.url()->url()); 193 template_url_.url()->url());
196 ASSERT_EQ(1, template_url_.input_encodings().size()); 194 ASSERT_EQ(1U, template_url_.input_encodings().size());
197 EXPECT_EQ("ISO-8859-1", template_url_.input_encodings()[0]); 195 EXPECT_EQ("ISO-8859-1", template_url_.input_encodings()[0]);
198 EXPECT_EQ(GURL("http://www.webster.com/favicon.ico"), 196 EXPECT_EQ(GURL("http://www.webster.com/favicon.ico"),
199 template_url_.GetFavIconURL()); 197 template_url_.GetFavIconURL());
200 } 198 }
201 199
202 TEST_F(TemplateURLParserTest, TestFirefoxYahoo) { 200 TEST_F(TemplateURLParserTest, TestFirefoxYahoo) {
203 if (IsDisabled()) 201 if (IsDisabled())
204 return; 202 return;
205 // This XML file uses a namespace. 203 // This XML file uses a namespace.
206 ParamFilterImpl filter("", "Mozilla"); 204 ParamFilterImpl filter("", "Mozilla");
207 ParseFile(L"firefox_yahoo.xml", &filter); 205 ParseFile(L"firefox_yahoo.xml", &filter);
208 ASSERT_TRUE(parse_result_); 206 ASSERT_TRUE(parse_result_);
209 EXPECT_EQ(L"Yahoo", template_url_.short_name()); 207 EXPECT_EQ(L"Yahoo", template_url_.short_name());
210 EXPECT_TRUE(template_url_.url() != NULL); 208 EXPECT_TRUE(template_url_.url() != NULL);
211 EXPECT_TRUE(template_url_.url()->SupportsReplacement()); 209 EXPECT_TRUE(template_url_.url()->SupportsReplacement());
212 EXPECT_EQ(L"http://ff.search.yahoo.com/gossip?" 210 EXPECT_EQ(L"http://ff.search.yahoo.com/gossip?"
213 L"output=fxjson&command={searchTerms}", 211 L"output=fxjson&command={searchTerms}",
214 template_url_.suggestions_url()->url()); 212 template_url_.suggestions_url()->url());
215 EXPECT_EQ(L"http://search.yahoo.com/search?p={searchTerms}&ei=UTF-8", 213 EXPECT_EQ(L"http://search.yahoo.com/search?p={searchTerms}&ei=UTF-8",
216 template_url_.url()->url()); 214 template_url_.url()->url());
217 ASSERT_EQ(1, template_url_.input_encodings().size()); 215 ASSERT_EQ(1U, template_url_.input_encodings().size());
218 EXPECT_EQ("UTF-8", template_url_.input_encodings()[0]); 216 EXPECT_EQ("UTF-8", template_url_.input_encodings()[0]);
219 EXPECT_EQ(GURL("http://search.yahoo.com/favicon.ico"), 217 EXPECT_EQ(GURL("http://search.yahoo.com/favicon.ico"),
220 template_url_.GetFavIconURL()); 218 template_url_.GetFavIconURL());
221 } 219 }
222 220
223 // Make sure we ignore POST suggestions (this is the same XML file as 221 // Make sure we ignore POST suggestions (this is the same XML file as
224 // firefox_yahoo.xml, the suggestion method was just changed to POST). 222 // firefox_yahoo.xml, the suggestion method was just changed to POST).
225 TEST_F(TemplateURLParserTest, TestPostSuggestion) { 223 TEST_F(TemplateURLParserTest, TestPostSuggestion) {
226 if (IsDisabled()) 224 if (IsDisabled())
227 return; 225 return;
228 // This XML file uses a namespace. 226 // This XML file uses a namespace.
229 ParamFilterImpl filter("", "Mozilla"); 227 ParamFilterImpl filter("", "Mozilla");
230 ParseFile(L"post_suggestion.xml", &filter); 228 ParseFile(L"post_suggestion.xml", &filter);
231 ASSERT_TRUE(parse_result_); 229 ASSERT_TRUE(parse_result_);
232 EXPECT_EQ(L"Yahoo", template_url_.short_name()); 230 EXPECT_EQ(L"Yahoo", template_url_.short_name());
233 EXPECT_TRUE(template_url_.url() != NULL); 231 EXPECT_TRUE(template_url_.url() != NULL);
234 EXPECT_TRUE(template_url_.url()->SupportsReplacement()); 232 EXPECT_TRUE(template_url_.url()->SupportsReplacement());
235 EXPECT_TRUE(template_url_.suggestions_url() == NULL); 233 EXPECT_TRUE(template_url_.suggestions_url() == NULL);
236 EXPECT_EQ(L"http://search.yahoo.com/search?p={searchTerms}&ei=UTF-8", 234 EXPECT_EQ(L"http://search.yahoo.com/search?p={searchTerms}&ei=UTF-8",
237 template_url_.url()->url()); 235 template_url_.url()->url());
238 ASSERT_EQ(1, template_url_.input_encodings().size()); 236 ASSERT_EQ(1U, template_url_.input_encodings().size());
239 EXPECT_EQ("UTF-8", template_url_.input_encodings()[0]); 237 EXPECT_EQ("UTF-8", template_url_.input_encodings()[0]);
240 EXPECT_EQ(GURL("http://search.yahoo.com/favicon.ico"), 238 EXPECT_EQ(GURL("http://search.yahoo.com/favicon.ico"),
241 template_url_.GetFavIconURL()); 239 template_url_.GetFavIconURL());
242 } 240 }
OLDNEW
« no previous file with comments | « chrome/browser/template_url_model_unittest.cc ('k') | chrome/browser/webdata/web_data_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698