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

Side by Side Diff: chrome/renderer/searchbox/searchbox_unittest.cc

Issue 2873383002: Remove unused instant support for chrome://large-icon and chrome://fallback-icon (Closed)
Patch Set: Created 3 years, 7 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
« no previous file with comments | « chrome/renderer/searchbox/searchbox.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "chrome/renderer/searchbox/searchbox.h" 5 #include "chrome/renderer/searchbox/searchbox.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <map> 9 #include <map>
10 #include <string> 10 #include <string>
11 11
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "chrome/common/search/instant_types.h" 13 #include "chrome/common/search/instant_types.h"
14 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
15 #include "url/gurl.h" 15 #include "url/gurl.h"
16 16
17 namespace { 17 namespace {
18 18
19 const auto FAVICON = SearchBox::FAVICON; 19 const auto FAVICON = SearchBox::FAVICON;
20 const auto LARGE_ICON = SearchBox::LARGE_ICON;
21 const auto FALLBACK_ICON = SearchBox::FALLBACK_ICON;
22 const auto THUMB = SearchBox::THUMB; 20 const auto THUMB = SearchBox::THUMB;
23 21
24 const char* kUrlString1 = "http://www.google.com"; 22 const char* kUrlString1 = "http://www.google.com";
25 const char* kUrlString2 = "http://www.chromium.org/path/q=3#r=4"; 23 const char* kUrlString2 = "http://www.chromium.org/path/q=3#r=4";
26 const char* kUrlString3 = "http://www.youtube.com:8080/hosps"; 24 const char* kUrlString3 = "http://www.youtube.com:8080/hosps";
27 25
28 // Mock helper to test internal::TranslateIconRestrictedUrl(). 26 // Mock helper to test internal::TranslateIconRestrictedUrl().
29 class MockIconURLHelper: public SearchBox::IconURLHelper { 27 class MockIconURLHelper: public SearchBox::IconURLHelper {
30 public: 28 public:
31 MockIconURLHelper(); 29 MockIconURLHelper();
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 struct { 146 struct {
149 SearchBox::ImageSourceType type; 147 SearchBox::ImageSourceType type;
150 const char* transient_url_str; 148 const char* transient_url_str;
151 const char* expected_param_part; 149 const char* expected_param_part;
152 int expected_view_id; 150 int expected_view_id;
153 InstantRestrictedID expected_rid; 151 InstantRestrictedID expected_rid;
154 } test_cases[] = { 152 } test_cases[] = {
155 {FAVICON, "chrome-search://favicon/1/2", "", 1, 2}, 153 {FAVICON, "chrome-search://favicon/1/2", "", 1, 2},
156 {FAVICON, "chrome-search://favicon/size/16@2x/3/4", "size/16@2x/", 3, 4}, 154 {FAVICON, "chrome-search://favicon/size/16@2x/3/4", "size/16@2x/", 3, 4},
157 {FAVICON, "chrome-search://favicon/iconurl/9/10", "iconurl/", 9, 10}, 155 {FAVICON, "chrome-search://favicon/iconurl/9/10", "iconurl/", 9, 10},
158 {LARGE_ICON, "chrome-search://large-icon/96/1/2", "96/", 1, 2},
159 {LARGE_ICON, "chrome-search://large-icon/1/3/4", "1/", 3, 4},
160 // Size restriction is *not* enforced during parsing, but later.
161 {LARGE_ICON, "chrome-search://large-icon/1000000/5/6", "1000000/", 5, 6},
162 {FALLBACK_ICON, "chrome-search://fallback-icon/,,,,/1/2", ",,,,/", 1, 2},
163 {FALLBACK_ICON, "chrome-search://fallback-icon/1,,,,/3/4", "1,,,,/", 3, 4},
164 {FALLBACK_ICON, "chrome-search://fallback-icon/64,fff,black,0.4,0.6/5/6",
165 "64,fff,black,0.4,0.6/", 5, 6},
166 {THUMB, "chrome-search://thumb/1/2", "", 1, 2}, 156 {THUMB, "chrome-search://thumb/1/2", "", 1, 2},
167 }; 157 };
168 for (size_t i = 0; i < arraysize(test_cases); ++i) { 158 for (size_t i = 0; i < arraysize(test_cases); ++i) {
169 std::string param_part = "(unwritten)"; 159 std::string param_part = "(unwritten)";
170 int view_id = -1; 160 int view_id = -1;
171 InstantRestrictedID rid = -1; 161 InstantRestrictedID rid = -1;
172 EXPECT_TRUE(ParseIconRestrictedUrl(GURL(test_cases[i].transient_url_str), 162 EXPECT_TRUE(ParseIconRestrictedUrl(GURL(test_cases[i].transient_url_str),
173 test_cases[i].type, &param_part, &view_id, &rid)) 163 test_cases[i].type, &param_part, &view_id, &rid))
174 << " for test_cases[" << i << "]"; 164 << " for test_cases[" << i << "]";
175 EXPECT_EQ(test_cases[i].expected_param_part, param_part) 165 EXPECT_EQ(test_cases[i].expected_param_part, param_part)
176 << " for test_cases[" << i << "]"; 166 << " for test_cases[" << i << "]";
177 EXPECT_EQ(test_cases[i].expected_view_id, view_id) 167 EXPECT_EQ(test_cases[i].expected_view_id, view_id)
178 << " for test_cases[" << i << "]"; 168 << " for test_cases[" << i << "]";
179 EXPECT_EQ(test_cases[i].expected_rid, rid) 169 EXPECT_EQ(test_cases[i].expected_rid, rid)
180 << " for test_cases[" << i << "]"; 170 << " for test_cases[" << i << "]";
181 } 171 }
182 } 172 }
183 173
184 TEST(SearchBoxUtilTest, ParseIconRestrictedUrlFailure) { 174 TEST(SearchBoxUtilTest, ParseIconRestrictedUrlFailure) {
185 struct { 175 struct {
186 SearchBox::ImageSourceType type; 176 SearchBox::ImageSourceType type;
187 const char* transient_url_str; 177 const char* transient_url_str;
188 } test_cases[] = { 178 } test_cases[] = {
189 {FAVICON, "chrome-search://favicon/"}, 179 {FAVICON, "chrome-search://favicon/"},
190 {FAVICON, "chrome-search://favicon/3/"}, 180 {FAVICON, "chrome-search://favicon/3/"},
191 {FAVICON, "chrome-search://favicon/size/3/4"}, 181 {FAVICON, "chrome-search://favicon/size/3/4"},
192 {FAVICON, "chrome-search://favicon/largest/http://www.google.com"}, 182 {FAVICON, "chrome-search://favicon/largest/http://www.google.com"},
193 {FAVICON, "chrome-search://favicon/size/16@2x/-1/10"}, 183 {FAVICON, "chrome-search://favicon/size/16@2x/-1/10"},
194 {LARGE_ICON, "chrome-search://large-icon/"},
195 {LARGE_ICON, "chrome-search://large-icon/3"},
196 {LARGE_ICON, "chrome-search://large-icon/3/4"},
197 {LARGE_ICON, "chrome-search://large-icon/-1/3/4"},
198 {LARGE_ICON, "chrome-search://large-icon/0/3/4"},
199 {LARGE_ICON, "chrome-search://large-icon/64/http://www.google.com"},
200 {LARGE_ICON, "chrome-search://large-icon/bad-size/3/4"},
201 {FALLBACK_ICON, "chrome-search://fallback-icon/"},
202 {FALLBACK_ICON, "chrome-search://fallback-icon/3"},
203 {FALLBACK_ICON, "chrome-search://fallback-icon/3/4"},
204 {FALLBACK_ICON, "chrome-search://fallback-icon//3/4"},
205 {FALLBACK_ICON, "chrome-search://fallback-icon/,,/3/4"},
206 {FALLBACK_ICON, "chrome-search://fallback-icon/bad-spec/3/4"},
207 {FALLBACK_ICON, "chrome-search://fallback-icon/-1,,,,/3/4"},
208 {FALLBACK_ICON, "chrome-search://fallback-icon/,junk,,,/3/4"},
209 // This case is a bit stringent. Since we always render fallback icons,
210 // search privider can't use this to probe user history. We'll consider
211 // relaxing the check if the need arises.
212 {FALLBACK_ICON, "chrome-search://fallback-icon/,,,,/http://www.google.com"},
213 {THUMB, "chrome-search://thumb"}, 184 {THUMB, "chrome-search://thumb"},
214 {THUMB, "chrome-search://thumb/"}, 185 {THUMB, "chrome-search://thumb/"},
215 {THUMB, "chrome-search://thumb/123"}, 186 {THUMB, "chrome-search://thumb/123"},
216 {THUMB, "chrome-search://thumb/xyz"}, 187 {THUMB, "chrome-search://thumb/xyz"},
217 {THUMB, "chrome-search://thumb/123/"}, 188 {THUMB, "chrome-search://thumb/123/"},
218 {THUMB, "chrome-search://thumb/123/xyz"}, 189 {THUMB, "chrome-search://thumb/123/xyz"},
219 {THUMB, "chrome-search://thumb/http://www.google.com"}, 190 {THUMB, "chrome-search://thumb/http://www.google.com"},
220 }; 191 };
221 for (size_t i = 0; i < arraysize(test_cases); ++i) { 192 for (size_t i = 0; i < arraysize(test_cases); ++i) {
222 std::string param_part = "(unwritten)"; 193 std::string param_part = "(unwritten)";
(...skipping 20 matching lines...) Expand all
243 {FAVICON, "chrome-search://favicon/", "chrome-search://favicon/"}, 214 {FAVICON, "chrome-search://favicon/", "chrome-search://favicon/"},
244 {FAVICON, "chrome-search://favicon/314", "chrome-search://favicon/"}, 215 {FAVICON, "chrome-search://favicon/314", "chrome-search://favicon/"},
245 {FAVICON, "chrome-search://favicon/314/1", "chrome-search://favicon/"}, 216 {FAVICON, "chrome-search://favicon/314/1", "chrome-search://favicon/"},
246 {FAVICON, "chrome-search://favicon/137/255", "chrome-search://favicon/"}, 217 {FAVICON, "chrome-search://favicon/137/255", "chrome-search://favicon/"},
247 {FAVICON, "chrome-search://favicon/-3/-1", "chrome-search://favicon/"}, 218 {FAVICON, "chrome-search://favicon/-3/-1", "chrome-search://favicon/"},
248 {FAVICON, "chrome-search://favicon/invalidstuff", 219 {FAVICON, "chrome-search://favicon/invalidstuff",
249 "chrome-search://favicon/"}, 220 "chrome-search://favicon/"},
250 {FAVICON, "chrome-search://favicon/size/16@2x/http://www.google.com", 221 {FAVICON, "chrome-search://favicon/size/16@2x/http://www.google.com",
251 "chrome-search://favicon/"}, 222 "chrome-search://favicon/"},
252 // Other types of icons. 223 // Other types of icons.
253 {LARGE_ICON, "chrome-search://large-icon/64/137/2",
254 std::string("chrome-search://large-icon/64/") + kUrlString2},
255 {LARGE_ICON, "chrome-search://large-icon/1/137/1",
256 std::string("chrome-search://large-icon/1/") + kUrlString1},
257 {FALLBACK_ICON, "chrome-search://fallback-icon/,,,,/137/3",
258 std::string("chrome-search://fallback-icon/,,,,/") + kUrlString3},
259 {FALLBACK_ICON, "chrome-search://fallback-icon/64,fff,,,1/137/1",
260 std::string("chrome-search://fallback-icon/64,fff,,,1/") + kUrlString1},
261 {THUMB, "chrome-search://thumb/137/3", 224 {THUMB, "chrome-search://thumb/137/3",
262 std::string("chrome-search://thumb/") + kUrlString3}, 225 std::string("chrome-search://thumb/") + kUrlString3},
263 }; 226 };
264 227
265 MockIconURLHelper helper; 228 MockIconURLHelper helper;
266 for (size_t i = 0; i < arraysize(test_cases); ++i) { 229 for (size_t i = 0; i < arraysize(test_cases); ++i) {
267 GURL url; 230 GURL url;
268 GURL transient_url(test_cases[i].transient_url_str); 231 GURL transient_url(test_cases[i].transient_url_str);
269 EXPECT_TRUE(TranslateIconRestrictedUrl(transient_url, test_cases[i].type, 232 EXPECT_TRUE(TranslateIconRestrictedUrl(transient_url, test_cases[i].type,
270 helper, &url)) 233 helper, &url))
271 << " for test_cases[" << i << "]"; 234 << " for test_cases[" << i << "]";
272 EXPECT_EQ(GURL(test_cases[i].expected_url_str), url) 235 EXPECT_EQ(GURL(test_cases[i].expected_url_str), url)
273 << " for test_cases[" << i << "]"; 236 << " for test_cases[" << i << "]";
274 } 237 }
275 } 238 }
276 239
277 // For Non-FAVICON only. 240 // For Non-FAVICON only.
278 TEST(SearchBoxUtilTest, TranslateIconRestrictedUrlFailure) { 241 TEST(SearchBoxUtilTest, TranslateIconRestrictedUrlFailure) {
279 struct { 242 struct {
280 SearchBox::ImageSourceType type; 243 SearchBox::ImageSourceType type;
281 const char* transient_url_str; 244 const char* transient_url_str;
282 } test_cases[] = { 245 } test_cases[] = {
283 // Empty. 246 // Empty.
284 {LARGE_ICON, "chrome-search://large-icon/"},
285 {FALLBACK_ICON, "chrome-search://fallback-icon/"},
286 {THUMB, "chrome-search://thumb/"}, 247 {THUMB, "chrome-search://thumb/"},
287 // Bad view_id. 248 // Bad view_id.
288 {LARGE_ICON, "chrome-search://large-icon/64/314/2"},
289 {LARGE_ICON, "chrome-search://large-icon/1/314/1"},
290 {FALLBACK_ICON, "chrome-search://fallback-icon/,,,,/314/3"},
291 {FALLBACK_ICON, "chrome-search://fallback-icon/64,fff,,,1/314/1"},
292 {THUMB, "chrome-search://thumb/314/1"}, 249 {THUMB, "chrome-search://thumb/314/1"},
293 // Missing rid. 250 // Missing rid.
294 {LARGE_ICON, "chrome-search://large-icon/64/137/"},
295 {LARGE_ICON, "chrome-search://large-icon/64/137/blah"},
296 {FALLBACK_ICON, "chrome-search://fallback-icon/,,,,/137/"},
297 {THUMB, "chrome-search://thumb/314/"}, 251 {THUMB, "chrome-search://thumb/314/"},
298 // Bad params.
299 {LARGE_ICON, "chrome-search://large-icon/137/2"},
300 {LARGE_ICON, "chrome-search://large-icon//137/2"},
301 {LARGE_ICON, "chrome-search://large-icon/96"},
302 {LARGE_ICON, "chrome-search://large-icon/-1/137/2"},
303 {LARGE_ICON, "chrome-search://large-icon/blah/137/2"},
304 {FALLBACK_ICON, "chrome-search://fallback-icon/137/3"},
305 {FALLBACK_ICON, "chrome-search://fallback-icon//137/3"},
306 {FALLBACK_ICON, "chrome-search://fallback-icon/-64,fff,,,1/137/3"},
307 {FALLBACK_ICON, "chrome-search://fallback-icon/springfront/137/3"},
308 // Use Page URL. 252 // Use Page URL.
309 {LARGE_ICON, "chrome-search://large-icon/96/http://www.google.com"},
310 {FALLBACK_ICON, "chrome-search://fallback-icon/,,,,/http://www.google.com"},
311 {THUMB, "chrome-search://thumb/http://www.google.com"}, 253 {THUMB, "chrome-search://thumb/http://www.google.com"},
312 }; 254 };
313 255
314 MockIconURLHelper helper; 256 MockIconURLHelper helper;
315 for (size_t i = 0; i < arraysize(test_cases); ++i) { 257 for (size_t i = 0; i < arraysize(test_cases); ++i) {
316 GURL url; 258 GURL url;
317 GURL transient_url(test_cases[i].transient_url_str); 259 GURL transient_url(test_cases[i].transient_url_str);
318 EXPECT_FALSE(TranslateIconRestrictedUrl(transient_url, test_cases[i].type, 260 EXPECT_FALSE(TranslateIconRestrictedUrl(transient_url, test_cases[i].type,
319 helper, &url)) 261 helper, &url))
320 << " for test_cases[" << i << "]"; 262 << " for test_cases[" << i << "]";
321 EXPECT_TRUE(url.is_empty()) << " for test_cases[" << i << "]"; 263 EXPECT_TRUE(url.is_empty()) << " for test_cases[" << i << "]";
322 } 264 }
323 } 265 }
324 266
325 } // namespace internal 267 } // namespace internal
OLDNEW
« no previous file with comments | « chrome/renderer/searchbox/searchbox.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698