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

Side by Side Diff: chrome/browser/autocomplete/history_url_provider_unittest.cc

Issue 18878007: Omnibox: Make the Controller Reorder Matches for Inlining (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Lacks -> has Created 7 years, 4 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) 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 "chrome/browser/autocomplete/history_url_provider.h" 5 #include "chrome/browser/autocomplete/history_url_provider.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 {"http://typedhost/untypedpath", "Intranet untyped", 1, 0}, 125 {"http://typedhost/untypedpath", "Intranet untyped", 1, 0},
126 126
127 {"http://x.com/one", "Internet", 2, 2}, 127 {"http://x.com/one", "Internet", 2, 2},
128 {"http://x.com/two", "Internet two", 1, 1}, 128 {"http://x.com/two", "Internet two", 1, 1},
129 {"http://x.com/three", "Internet three", 2, 2}, 129 {"http://x.com/three", "Internet three", 2, 2},
130 }; 130 };
131 131
132 class HistoryURLProviderTest : public testing::Test, 132 class HistoryURLProviderTest : public testing::Test,
133 public AutocompleteProviderListener { 133 public AutocompleteProviderListener {
134 public: 134 public:
135 // A pair of a URL and whether that URL is allowed to be the default match.
136 typedef std::pair<std::string, bool> ExpectedUrlAndLegalDefaultMatch;
137
135 HistoryURLProviderTest() 138 HistoryURLProviderTest()
136 : sort_matches_(false) { 139 : sort_matches_(false) {
137 HistoryQuickProvider::set_disabled(true); 140 HistoryQuickProvider::set_disabled(true);
138 } 141 }
139 142
140 virtual ~HistoryURLProviderTest() { 143 virtual ~HistoryURLProviderTest() {
141 HistoryQuickProvider::set_disabled(false); 144 HistoryQuickProvider::set_disabled(false);
142 } 145 }
143 146
144 // AutocompleteProviderListener: 147 // AutocompleteProviderListener:
(...skipping 16 matching lines...) Expand all
161 164
162 // Fills test data into the history system. 165 // Fills test data into the history system.
163 void FillData(); 166 void FillData();
164 167
165 // Runs an autocomplete query on |text| and checks to see that the returned 168 // Runs an autocomplete query on |text| and checks to see that the returned
166 // results' destination URLs match those provided. Also allows checking 169 // results' destination URLs match those provided. Also allows checking
167 // that the input type was identified correctly. 170 // that the input type was identified correctly.
168 void RunTest(const string16 text, 171 void RunTest(const string16 text,
169 const string16& desired_tld, 172 const string16& desired_tld,
170 bool prevent_inline_autocomplete, 173 bool prevent_inline_autocomplete,
171 const std::string* expected_urls, 174 const ExpectedUrlAndLegalDefaultMatch* expected_urls,
172 size_t num_results, 175 size_t num_results,
173 AutocompleteInput::Type* identified_input_type); 176 AutocompleteInput::Type* identified_input_type);
174 177
175 // A version of the above without the final |type| output parameter. 178 // A version of the above without the final |type| output parameter.
176 void RunTest(const string16 text, 179 void RunTest(const string16 text,
177 const string16& desired_tld, 180 const string16& desired_tld,
178 bool prevent_inline_autocomplete, 181 bool prevent_inline_autocomplete,
179 const std::string* expected_urls, 182 const ExpectedUrlAndLegalDefaultMatch* expected_urls,
180 size_t num_results) { 183 size_t num_results) {
181 AutocompleteInput::Type type; 184 AutocompleteInput::Type type;
182 return RunTest(text, desired_tld, prevent_inline_autocomplete, 185 return RunTest(text, desired_tld, prevent_inline_autocomplete,
183 expected_urls, num_results, &type); 186 expected_urls, num_results, &type);
184 } 187 }
185 188
186 content::TestBrowserThreadBundle thread_bundle_; 189 content::TestBrowserThreadBundle thread_bundle_;
187 ACMatches matches_; 190 ACMatches matches_;
188 scoped_ptr<TestingProfile> profile_; 191 scoped_ptr<TestingProfile> profile_;
189 HistoryService* history_service_; 192 HistoryService* history_service_;
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 GURL("http://p/"), UTF8ToUTF16("p"), 0, 0, 253 GURL("http://p/"), UTF8ToUTF16("p"), 0, 0,
251 Time::Now() - 254 Time::Now() -
252 TimeDelta::FromDays(history::kLowQualityMatchAgeLimitInDays - 1), 255 TimeDelta::FromDays(history::kLowQualityMatchAgeLimitInDays - 1),
253 false, history::SOURCE_BROWSED); 256 false, history::SOURCE_BROWSED);
254 } 257 }
255 258
256 void HistoryURLProviderTest::RunTest( 259 void HistoryURLProviderTest::RunTest(
257 const string16 text, 260 const string16 text,
258 const string16& desired_tld, 261 const string16& desired_tld,
259 bool prevent_inline_autocomplete, 262 bool prevent_inline_autocomplete,
260 const std::string* expected_urls, 263 const ExpectedUrlAndLegalDefaultMatch* expected_urls,
261 size_t num_results, 264 size_t num_results,
262 AutocompleteInput::Type* identified_input_type) { 265 AutocompleteInput::Type* identified_input_type) {
263 AutocompleteInput input(text, string16::npos, desired_tld, GURL(), 266 AutocompleteInput input(text, string16::npos, desired_tld, GURL(),
264 AutocompleteInput::INVALID_SPEC, 267 AutocompleteInput::INVALID_SPEC,
265 prevent_inline_autocomplete, false, true, 268 prevent_inline_autocomplete, false, true,
266 AutocompleteInput::ALL_MATCHES); 269 AutocompleteInput::ALL_MATCHES);
267 *identified_input_type = input.type(); 270 *identified_input_type = input.type();
268 autocomplete_->Start(input, false); 271 autocomplete_->Start(input, false);
269 if (!autocomplete_->done()) 272 if (!autocomplete_->done())
270 base::MessageLoop::current()->Run(); 273 base::MessageLoop::current()->Run();
271 274
272 matches_ = autocomplete_->matches(); 275 matches_ = autocomplete_->matches();
273 if (sort_matches_) { 276 if (sort_matches_) {
274 for (ACMatches::iterator i = matches_.begin(); i != matches_.end(); ++i) 277 for (ACMatches::iterator i = matches_.begin(); i != matches_.end(); ++i)
275 i->ComputeStrippedDestinationURL(profile_.get()); 278 i->ComputeStrippedDestinationURL(profile_.get());
276 std::sort(matches_.begin(), matches_.end(), 279 std::sort(matches_.begin(), matches_.end(),
277 &AutocompleteMatch::DestinationSortFunc); 280 &AutocompleteMatch::DestinationSortFunc);
278 matches_.erase(std::unique(matches_.begin(), matches_.end(), 281 matches_.erase(std::unique(matches_.begin(), matches_.end(),
279 &AutocompleteMatch::DestinationsEqual), 282 &AutocompleteMatch::DestinationsEqual),
280 matches_.end()); 283 matches_.end());
281 std::sort(matches_.begin(), matches_.end(), 284 std::sort(matches_.begin(), matches_.end(),
282 &AutocompleteMatch::MoreRelevant); 285 &AutocompleteMatch::MoreRelevant);
283 } 286 }
284 ASSERT_EQ(num_results, matches_.size()) << "Input text: " << text 287 ASSERT_EQ(num_results, matches_.size()) << "Input text: " << text
285 << "\nTLD: \"" << desired_tld << "\""; 288 << "\nTLD: \"" << desired_tld << "\"";
286 for (size_t i = 0; i < num_results; ++i) 289 for (size_t i = 0; i < num_results; ++i) {
287 EXPECT_EQ(expected_urls[i], matches_[i].destination_url.spec()); 290 EXPECT_EQ(expected_urls[i].first, matches_[i].destination_url.spec());
291 EXPECT_EQ(expected_urls[i].second, matches_[i].allowed_to_be_default_match);
292 }
288 } 293 }
289 294
290 TEST_F(HistoryURLProviderTest, PromoteShorterURLs) { 295 TEST_F(HistoryURLProviderTest, PromoteShorterURLs) {
291 // Test that hosts get synthesized below popular pages. 296 // Test that hosts get synthesized below popular pages.
292 const std::string expected_nonsynth[] = { 297 const ExpectedUrlAndLegalDefaultMatch expected_nonsynth[] = {
293 "http://slashdot.org/favorite_page.html", 298 ExpectedUrlAndLegalDefaultMatch(
294 "http://slashdot.org/", 299 "http://slashdot.org/favorite_page.html", false),
msw 2013/08/07 20:09:21 I have no clue why these aren't legal defaults. Su
Mark P 2013/08/07 22:13:05 This whole function uses RunTest() calls that have
300 ExpectedUrlAndLegalDefaultMatch("http://slashdot.org/", false)
295 }; 301 };
296 RunTest(ASCIIToUTF16("slash"), string16(), true, expected_nonsynth, 302 RunTest(ASCIIToUTF16("slash"), string16(), true, expected_nonsynth,
297 arraysize(expected_nonsynth)); 303 arraysize(expected_nonsynth));
298 304
299 // Test that hosts get synthesized above less popular pages. 305 // Test that hosts get synthesized above less popular pages.
300 const std::string expected_synth[] = { 306 const ExpectedUrlAndLegalDefaultMatch expected_synth[] = {
301 "http://kerneltrap.org/", 307 ExpectedUrlAndLegalDefaultMatch("http://kerneltrap.org/", false),
302 "http://kerneltrap.org/not_very_popular.html", 308 ExpectedUrlAndLegalDefaultMatch(
309 "http://kerneltrap.org/not_very_popular.html", false)
303 }; 310 };
304 RunTest(ASCIIToUTF16("kernel"), string16(), true, expected_synth, 311 RunTest(ASCIIToUTF16("kernel"), string16(), true, expected_synth,
305 arraysize(expected_synth)); 312 arraysize(expected_synth));
306 313
307 // Test that unpopular pages are ignored completely. 314 // Test that unpopular pages are ignored completely.
308 RunTest(ASCIIToUTF16("fresh"), string16(), true, NULL, 0); 315 RunTest(ASCIIToUTF16("fresh"), string16(), true, NULL, 0);
309 316
310 // Test that if we create or promote shorter suggestions that would not 317 // Test that if we create or promote shorter suggestions that would not
311 // normally be inline autocompletable, we make them inline autocompletable if 318 // normally be inline autocompletable, we make them inline autocompletable if
312 // the original suggestion (that we replaced as "top") was inline 319 // the original suggestion (that we replaced as "top") was inline
313 // autocompletable. 320 // autocompletable.
314 const std::string expected_synthesisa[] = { 321 const ExpectedUrlAndLegalDefaultMatch expected_synthesisa[] = {
315 "http://synthesisatest.com/", 322 ExpectedUrlAndLegalDefaultMatch("http://synthesisatest.com/", true),
316 "http://synthesisatest.com/foo/", 323 ExpectedUrlAndLegalDefaultMatch("http://synthesisatest.com/foo/", true)
317 }; 324 };
318 RunTest(ASCIIToUTF16("synthesisa"), string16(), false, expected_synthesisa, 325 RunTest(ASCIIToUTF16("synthesisa"), string16(), false, expected_synthesisa,
319 arraysize(expected_synthesisa)); 326 arraysize(expected_synthesisa));
320 EXPECT_LT(matches_.front().relevance, 1200); 327 EXPECT_LT(matches_.front().relevance, 1200);
321 const std::string expected_synthesisb[] = { 328 const ExpectedUrlAndLegalDefaultMatch expected_synthesisb[] = {
322 "http://synthesisbtest.com/foo/", 329 ExpectedUrlAndLegalDefaultMatch("http://synthesisbtest.com/foo/", true),
323 "http://synthesisbtest.com/foo/bar.html", 330 ExpectedUrlAndLegalDefaultMatch(
331 "http://synthesisbtest.com/foo/bar.html", true)
324 }; 332 };
325 RunTest(ASCIIToUTF16("synthesisb"), string16(), false, expected_synthesisb, 333 RunTest(ASCIIToUTF16("synthesisb"), string16(), false, expected_synthesisb,
326 arraysize(expected_synthesisb)); 334 arraysize(expected_synthesisb));
327 EXPECT_GE(matches_.front().relevance, 1410); 335 EXPECT_GE(matches_.front().relevance, 1410);
328 336
329 // Test that if we have a synthesized host that matches a suggestion, they 337 // Test that if we have a synthesized host that matches a suggestion, they
330 // get combined into one. 338 // get combined into one.
331 const std::string expected_combine[] = { 339 const ExpectedUrlAndLegalDefaultMatch expected_combine[] = {
332 "http://news.google.com/", 340 ExpectedUrlAndLegalDefaultMatch("http://news.google.com/", false),
333 "http://news.google.com/?ned=us&topic=n", 341 ExpectedUrlAndLegalDefaultMatch(
342 "http://news.google.com/?ned=us&topic=n", false),
334 }; 343 };
335 ASSERT_NO_FATAL_FAILURE(RunTest(ASCIIToUTF16("news"), string16(), true, 344 ASSERT_NO_FATAL_FAILURE(RunTest(ASCIIToUTF16("news"), string16(), true,
336 expected_combine, arraysize(expected_combine))); 345 expected_combine, arraysize(expected_combine)));
337 // The title should also have gotten set properly on the host for the 346 // The title should also have gotten set properly on the host for the
338 // synthesized one, since it was also in the results. 347 // synthesized one, since it was also in the results.
339 EXPECT_EQ(ASCIIToUTF16("Google News"), matches_.front().description); 348 EXPECT_EQ(ASCIIToUTF16("Google News"), matches_.front().description);
340 349
341 // Test that short URL matching works correctly as the user types more 350 // Test that short URL matching works correctly as the user types more
342 // (several tests): 351 // (several tests):
343 // The entry for foo.com is the best of all five foo.com* entries. 352 // The entry for foo.com is the best of all five foo.com* entries.
344 const std::string short_1[] = { 353 const ExpectedUrlAndLegalDefaultMatch short_1[] = {
345 "http://foo.com/", 354 ExpectedUrlAndLegalDefaultMatch("http://foo.com/", false),
346 "http://foo.com/dir/another/again/myfile.html", 355 ExpectedUrlAndLegalDefaultMatch(
347 "http://foo.com/dir/", 356 "http://foo.com/dir/another/again/myfile.html", false),
357 ExpectedUrlAndLegalDefaultMatch("http://foo.com/dir/", false)
348 }; 358 };
349 RunTest(ASCIIToUTF16("foo"), string16(), true, short_1, arraysize(short_1)); 359 RunTest(ASCIIToUTF16("foo"), string16(), true, short_1, arraysize(short_1));
350 360
351 // When the user types the whole host, make sure we don't get two results for 361 // When the user types the whole host, make sure we don't get two results for
352 // it. 362 // it.
353 const std::string short_2[] = { 363 const ExpectedUrlAndLegalDefaultMatch short_2[] = {
354 "http://foo.com/", 364 ExpectedUrlAndLegalDefaultMatch("http://foo.com/", true),
355 "http://foo.com/dir/another/again/myfile.html", 365 ExpectedUrlAndLegalDefaultMatch(
356 "http://foo.com/dir/", 366 "http://foo.com/dir/another/again/myfile.html", false),
357 "http://foo.com/dir/another/", 367 ExpectedUrlAndLegalDefaultMatch("http://foo.com/dir/", false),
368 ExpectedUrlAndLegalDefaultMatch("http://foo.com/dir/another/", false)
358 }; 369 };
359 RunTest(ASCIIToUTF16("foo.com"), string16(), true, short_2, 370 RunTest(ASCIIToUTF16("foo.com"), string16(), true, short_2,
360 arraysize(short_2)); 371 arraysize(short_2));
361 RunTest(ASCIIToUTF16("foo.com/"), string16(), true, short_2, 372 RunTest(ASCIIToUTF16("foo.com/"), string16(), true, short_2,
362 arraysize(short_2)); 373 arraysize(short_2));
363 374
364 // The filename is the second best of the foo.com* entries, but there is a 375 // The filename is the second best of the foo.com* entries, but there is a
365 // shorter URL that's "good enough". The host doesn't match the user input 376 // shorter URL that's "good enough". The host doesn't match the user input
366 // and so should not appear. 377 // and so should not appear.
367 const std::string short_3[] = { 378 const ExpectedUrlAndLegalDefaultMatch short_3[] = {
368 "http://foo.com/d", 379 ExpectedUrlAndLegalDefaultMatch("http://foo.com/d", true),
369 "http://foo.com/dir/another/", 380 ExpectedUrlAndLegalDefaultMatch("http://foo.com/dir/another/", false),
370 "http://foo.com/dir/another/again/myfile.html", 381 ExpectedUrlAndLegalDefaultMatch(
371 "http://foo.com/dir/", 382 "http://foo.com/dir/another/again/myfile.html", false),
383 ExpectedUrlAndLegalDefaultMatch("http://foo.com/dir/", false)
372 }; 384 };
373 RunTest(ASCIIToUTF16("foo.com/d"), string16(), true, short_3, 385 RunTest(ASCIIToUTF16("foo.com/d"), string16(), true, short_3,
374 arraysize(short_3)); 386 arraysize(short_3));
375 387
376 // We shouldn't promote shorter URLs than the best if they're not good 388 // We shouldn't promote shorter URLs than the best if they're not good
377 // enough. 389 // enough.
378 const std::string short_4[] = { 390 const ExpectedUrlAndLegalDefaultMatch short_4[] = {
379 "http://foo.com/dir/another/a", 391 ExpectedUrlAndLegalDefaultMatch("http://foo.com/dir/another/a", true),
380 "http://foo.com/dir/another/again/myfile.html", 392 ExpectedUrlAndLegalDefaultMatch(
381 "http://foo.com/dir/another/again/", 393 "http://foo.com/dir/another/again/myfile.html", false),
394 ExpectedUrlAndLegalDefaultMatch("http://foo.com/dir/another/again/", false)
382 }; 395 };
383 RunTest(ASCIIToUTF16("foo.com/dir/another/a"), string16(), true, short_4, 396 RunTest(ASCIIToUTF16("foo.com/dir/another/a"), string16(), true, short_4,
384 arraysize(short_4)); 397 arraysize(short_4));
385 398
386 // Exact matches should always be best no matter how much more another match 399 // Exact matches should always be best no matter how much more another match
387 // has been typed. 400 // has been typed.
388 const std::string short_5a[] = { 401 const ExpectedUrlAndLegalDefaultMatch short_5a[] = {
389 "http://gooey/", 402 ExpectedUrlAndLegalDefaultMatch("http://gooey/", true),
390 "http://www.google.com/", 403 ExpectedUrlAndLegalDefaultMatch("http://www.google.com/", true),
391 "http://go/", 404 ExpectedUrlAndLegalDefaultMatch("http://go/", true)
392 }; 405 };
393 const std::string short_5b[] = { 406 const ExpectedUrlAndLegalDefaultMatch short_5b[] = {
394 "http://go/", 407 ExpectedUrlAndLegalDefaultMatch("http://go/", true),
395 "http://gooey/", 408 ExpectedUrlAndLegalDefaultMatch("http://gooey/", true),
396 "http://www.google.com/", 409 ExpectedUrlAndLegalDefaultMatch("http://www.google.com/", true)
397 }; 410 };
398 RunTest(ASCIIToUTF16("g"), string16(), false, short_5a, arraysize(short_5a)); 411 RunTest(ASCIIToUTF16("g"), string16(), false, short_5a, arraysize(short_5a));
399 RunTest(ASCIIToUTF16("go"), string16(), false, short_5b, arraysize(short_5b)); 412 RunTest(ASCIIToUTF16("go"), string16(), false, short_5b, arraysize(short_5b));
400 } 413 }
401 414
402 TEST_F(HistoryURLProviderTest, CullRedirects) { 415 TEST_F(HistoryURLProviderTest, CullRedirects) {
403 // URLs we will be using, plus the visit counts they will initially get 416 // URLs we will be using, plus the visit counts they will initially get
404 // (the redirect set below will also increment the visit counts). We want 417 // (the redirect set below will also increment the visit counts). We want
405 // the results to be in A,B,C order. Note also that our visit counts are 418 // the results to be in A,B,C order. Note also that our visit counts are
406 // all high enough so that domain synthesizing won't get triggered. 419 // all high enough so that domain synthesizing won't get triggered.
(...skipping 20 matching lines...) Expand all
427 redirects_to_a.push_back(GURL(test_cases[2].url)); 440 redirects_to_a.push_back(GURL(test_cases[2].url));
428 redirects_to_a.push_back(GURL(test_cases[0].url)); 441 redirects_to_a.push_back(GURL(test_cases[0].url));
429 history_service_->AddPage(GURL(test_cases[0].url), base::Time::Now(), 442 history_service_->AddPage(GURL(test_cases[0].url), base::Time::Now(),
430 NULL, 0, GURL(), redirects_to_a, content::PAGE_TRANSITION_TYPED, 443 NULL, 0, GURL(), redirects_to_a, content::PAGE_TRANSITION_TYPED,
431 history::SOURCE_BROWSED, true); 444 history::SOURCE_BROWSED, true);
432 445
433 // Because all the results are part of a redirect chain with other results, 446 // Because all the results are part of a redirect chain with other results,
434 // all but the first one (A) should be culled. We should get the default 447 // all but the first one (A) should be culled. We should get the default
435 // "what you typed" result, plus this one. 448 // "what you typed" result, plus this one.
436 const string16 typing(ASCIIToUTF16("http://redirects/")); 449 const string16 typing(ASCIIToUTF16("http://redirects/"));
437 const std::string expected_results[] = { 450 const ExpectedUrlAndLegalDefaultMatch expected_results[] = {
438 UTF16ToUTF8(typing), 451 ExpectedUrlAndLegalDefaultMatch(UTF16ToUTF8(typing), true),
439 test_cases[0].url, 452 ExpectedUrlAndLegalDefaultMatch(test_cases[0].url, false)
440 }; 453 };
441 RunTest(typing, string16(), true, expected_results, 454 RunTest(typing, string16(), true, expected_results,
442 arraysize(expected_results)); 455 arraysize(expected_results));
443 } 456 }
444 457
445 TEST_F(HistoryURLProviderTest, WhatYouTyped) { 458 TEST_F(HistoryURLProviderTest, WhatYouTyped) {
446 // Make sure we suggest a What You Typed match at the right times. 459 // Make sure we suggest a What You Typed match at the right times.
447 RunTest(ASCIIToUTF16("wytmatch"), string16(), false, NULL, 0); 460 RunTest(ASCIIToUTF16("wytmatch"), string16(), false, NULL, 0);
448 RunTest(ASCIIToUTF16("wytmatch foo bar"), string16(), false, NULL, 0); 461 RunTest(ASCIIToUTF16("wytmatch foo bar"), string16(), false, NULL, 0);
449 RunTest(ASCIIToUTF16("wytmatch+foo+bar"), string16(), false, NULL, 0); 462 RunTest(ASCIIToUTF16("wytmatch+foo+bar"), string16(), false, NULL, 0);
450 RunTest(ASCIIToUTF16("wytmatch+foo+bar.com"), string16(), false, NULL, 0); 463 RunTest(ASCIIToUTF16("wytmatch+foo+bar.com"), string16(), false, NULL, 0);
451 464
452 const std::string results_1[] = {"http://www.wytmatch.com/"}; 465 const ExpectedUrlAndLegalDefaultMatch results_1[] = {
466 ExpectedUrlAndLegalDefaultMatch("http://www.wytmatch.com/", true)
467 };
453 RunTest(ASCIIToUTF16("wytmatch"), ASCIIToUTF16("com"), false, results_1, 468 RunTest(ASCIIToUTF16("wytmatch"), ASCIIToUTF16("com"), false, results_1,
454 arraysize(results_1)); 469 arraysize(results_1));
455 470
456 const std::string results_2[] = {"http://wytmatch%20foo%20bar/"}; 471 const ExpectedUrlAndLegalDefaultMatch results_2[] = {
472 ExpectedUrlAndLegalDefaultMatch("http://wytmatch%20foo%20bar/", true)
473 };
457 RunTest(ASCIIToUTF16("http://wytmatch foo bar"), string16(), false, results_2, 474 RunTest(ASCIIToUTF16("http://wytmatch foo bar"), string16(), false, results_2,
458 arraysize(results_2)); 475 arraysize(results_2));
459 476
460 const std::string results_3[] = {"https://wytmatch%20foo%20bar/"}; 477 const ExpectedUrlAndLegalDefaultMatch results_3[] = {
478 ExpectedUrlAndLegalDefaultMatch("https://wytmatch%20foo%20bar/", true)
479 };
461 RunTest(ASCIIToUTF16("https://wytmatch foo bar"), string16(), false, 480 RunTest(ASCIIToUTF16("https://wytmatch foo bar"), string16(), false,
462 results_3, arraysize(results_3)); 481 results_3, arraysize(results_3));
463 } 482 }
464 483
465 TEST_F(HistoryURLProviderTest, Fixup) { 484 TEST_F(HistoryURLProviderTest, Fixup) {
466 // Test for various past crashes we've had. 485 // Test for various past crashes we've had.
467 RunTest(ASCIIToUTF16("\\"), string16(), false, NULL, 0); 486 RunTest(ASCIIToUTF16("\\"), string16(), false, NULL, 0);
468 RunTest(ASCIIToUTF16("#"), string16(), false, NULL, 0); 487 RunTest(ASCIIToUTF16("#"), string16(), false, NULL, 0);
469 RunTest(ASCIIToUTF16("%20"), string16(), false, NULL, 0); 488 RunTest(ASCIIToUTF16("%20"), string16(), false, NULL, 0);
470 const std::string fixup_crash[] = {"http://%EF%BD%A5@s/"}; 489 const ExpectedUrlAndLegalDefaultMatch fixup_crash[] = {
490 ExpectedUrlAndLegalDefaultMatch("http://%EF%BD%A5@s/", true)
491 };
471 RunTest(WideToUTF16(L"\uff65@s"), string16(), false, fixup_crash, 492 RunTest(WideToUTF16(L"\uff65@s"), string16(), false, fixup_crash,
472 arraysize(fixup_crash)); 493 arraysize(fixup_crash));
473 RunTest(WideToUTF16(L"\u2015\u2015@ \uff7c"), string16(), false, NULL, 0); 494 RunTest(WideToUTF16(L"\u2015\u2015@ \uff7c"), string16(), false, NULL, 0);
474 495
475 // Fixing up "file:" should result in an inline autocomplete offset of just 496 // Fixing up "file:" should result in an inline autocomplete offset of just
476 // after "file:", not just after "file://". 497 // after "file:", not just after "file://".
477 const string16 input_1(ASCIIToUTF16("file:")); 498 const string16 input_1(ASCIIToUTF16("file:"));
478 const std::string fixup_1[] = {"file:///C:/foo.txt"}; 499 const ExpectedUrlAndLegalDefaultMatch fixup_1[] = {
500 ExpectedUrlAndLegalDefaultMatch("file:///C:/foo.txt", true)
501 };
479 ASSERT_NO_FATAL_FAILURE(RunTest(input_1, string16(), false, fixup_1, 502 ASSERT_NO_FATAL_FAILURE(RunTest(input_1, string16(), false, fixup_1,
480 arraysize(fixup_1))); 503 arraysize(fixup_1)));
481 EXPECT_EQ(ASCIIToUTF16("///C:/foo.txt"), 504 EXPECT_EQ(ASCIIToUTF16("///C:/foo.txt"),
482 matches_.front().inline_autocompletion); 505 matches_.front().inline_autocompletion);
483 506
484 // Fixing up "http:/" should result in an inline autocomplete offset of just 507 // Fixing up "http:/" should result in an inline autocomplete offset of just
485 // after "http:/", not just after "http:". 508 // after "http:/", not just after "http:".
486 const string16 input_2(ASCIIToUTF16("http:/")); 509 const string16 input_2(ASCIIToUTF16("http:/"));
487 const std::string fixup_2[] = { 510 const ExpectedUrlAndLegalDefaultMatch fixup_2[] = {
488 "http://bogussite.com/a", 511 ExpectedUrlAndLegalDefaultMatch("http://bogussite.com/a", true),
489 "http://bogussite.com/b", 512 ExpectedUrlAndLegalDefaultMatch("http://bogussite.com/b", true),
490 "http://bogussite.com/c", 513 ExpectedUrlAndLegalDefaultMatch("http://bogussite.com/c", true)
491 }; 514 };
492 ASSERT_NO_FATAL_FAILURE(RunTest(input_2, string16(), false, fixup_2, 515 ASSERT_NO_FATAL_FAILURE(RunTest(input_2, string16(), false, fixup_2,
493 arraysize(fixup_2))); 516 arraysize(fixup_2)));
494 EXPECT_EQ(ASCIIToUTF16("/bogussite.com/a"), 517 EXPECT_EQ(ASCIIToUTF16("/bogussite.com/a"),
495 matches_.front().inline_autocompletion); 518 matches_.front().inline_autocompletion);
496 519
497 // Adding a TLD to a small number like "56" should result in "www.56.com" 520 // Adding a TLD to a small number like "56" should result in "www.56.com"
498 // rather than "0.0.0.56.com". 521 // rather than "0.0.0.56.com".
499 const std::string fixup_3[] = {"http://www.56.com/"}; 522 const ExpectedUrlAndLegalDefaultMatch fixup_3[] = {
523 ExpectedUrlAndLegalDefaultMatch("http://www.56.com/", true)
524 };
500 RunTest(ASCIIToUTF16("56"), ASCIIToUTF16("com"), true, fixup_3, 525 RunTest(ASCIIToUTF16("56"), ASCIIToUTF16("com"), true, fixup_3,
501 arraysize(fixup_3)); 526 arraysize(fixup_3));
502 527
503 // An input looks like a IP address like "127.0.0.1" should result in 528 // An input looks like a IP address like "127.0.0.1" should result in
504 // "http://127.0.0.1/". 529 // "http://127.0.0.1/".
505 const std::string fixup_4[] = {"http://127.0.0.1/"}; 530 const ExpectedUrlAndLegalDefaultMatch fixup_4[] = {
531 ExpectedUrlAndLegalDefaultMatch("http://127.0.0.1/", true)
532 };
506 RunTest(ASCIIToUTF16("127.0.0.1"), string16(), false, fixup_4, 533 RunTest(ASCIIToUTF16("127.0.0.1"), string16(), false, fixup_4,
507 arraysize(fixup_4)); 534 arraysize(fixup_4));
508 535
509 // An number "17173" should result in "http://www.17173.com/" in db. 536 // An number "17173" should result in "http://www.17173.com/" in db.
510 const std::string fixup_5[] = {"http://www.17173.com/"}; 537 const ExpectedUrlAndLegalDefaultMatch fixup_5[] = {
538 ExpectedUrlAndLegalDefaultMatch("http://www.17173.com/", true)
539 };
511 RunTest(ASCIIToUTF16("17173"), string16(), false, fixup_5, 540 RunTest(ASCIIToUTF16("17173"), string16(), false, fixup_5,
512 arraysize(fixup_5)); 541 arraysize(fixup_5));
513 } 542 }
514 543
515 // Make sure the results for the input 'p' don't change between the first and 544 // Make sure the results for the input 'p' don't change between the first and
516 // second passes. 545 // second passes.
517 TEST_F(HistoryURLProviderTest, EmptyVisits) { 546 TEST_F(HistoryURLProviderTest, EmptyVisits) {
518 // Wait for history to create the in memory DB. 547 // Wait for history to create the in memory DB.
519 profile_->BlockUntilHistoryProcessesPendingRequests(); 548 profile_->BlockUntilHistoryProcessesPendingRequests();
520 549
(...skipping 15 matching lines...) Expand all
536 EXPECT_TRUE(autocomplete_->done()); 565 EXPECT_TRUE(autocomplete_->done());
537 matches_ = autocomplete_->matches(); 566 matches_ = autocomplete_->matches();
538 ASSERT_GT(matches_.size(), 0u); 567 ASSERT_GT(matches_.size(), 0u);
539 EXPECT_EQ(GURL("http://pandora.com/"), matches_[0].destination_url); 568 EXPECT_EQ(GURL("http://pandora.com/"), matches_[0].destination_url);
540 EXPECT_EQ(pandora_relevance, matches_[0].relevance); 569 EXPECT_EQ(pandora_relevance, matches_[0].relevance);
541 } 570 }
542 571
543 TEST_F(HistoryURLProviderTestNoDB, NavigateWithoutDB) { 572 TEST_F(HistoryURLProviderTestNoDB, NavigateWithoutDB) {
544 // Ensure that we will still produce matches for navigation when there is no 573 // Ensure that we will still produce matches for navigation when there is no
545 // database. 574 // database.
546 std::string navigation_1[] = {"http://test.com/"}; 575 ExpectedUrlAndLegalDefaultMatch navigation_1[] = {
576 ExpectedUrlAndLegalDefaultMatch("http://test.com/", true)
577 };
547 RunTest(ASCIIToUTF16("test.com"), string16(), false, navigation_1, 578 RunTest(ASCIIToUTF16("test.com"), string16(), false, navigation_1,
548 arraysize(navigation_1)); 579 arraysize(navigation_1));
549 580
550 std::string navigation_2[] = {"http://slash/"}; 581 ExpectedUrlAndLegalDefaultMatch navigation_2[] = {
582 ExpectedUrlAndLegalDefaultMatch("http://slash/", true)
583 };
551 RunTest(ASCIIToUTF16("slash"), string16(), false, navigation_2, 584 RunTest(ASCIIToUTF16("slash"), string16(), false, navigation_2,
552 arraysize(navigation_2)); 585 arraysize(navigation_2));
553 586
554 RunTest(ASCIIToUTF16("this is a query"), string16(), false, NULL, 0); 587 RunTest(ASCIIToUTF16("this is a query"), string16(), false, NULL, 0);
555 } 588 }
556 589
557 TEST_F(HistoryURLProviderTest, DontAutocompleteOnTrailingWhitespace) { 590 TEST_F(HistoryURLProviderTest, DontAutocompleteOnTrailingWhitespace) {
558 AutocompleteInput input(ASCIIToUTF16("slash "), string16::npos, string16(), 591 AutocompleteInput input(ASCIIToUTF16("slash "), string16::npos, string16(),
559 GURL(), AutocompleteInput::INVALID_SPEC, false, false, 592 GURL(), AutocompleteInput::INVALID_SPEC, false, false,
560 true, AutocompleteInput::ALL_MATCHES); 593 true, AutocompleteInput::ALL_MATCHES);
561 autocomplete_->Start(input, false); 594 autocomplete_->Start(input, false);
562 if (!autocomplete_->done()) 595 if (!autocomplete_->done())
563 base::MessageLoop::current()->Run(); 596 base::MessageLoop::current()->Run();
564 597
565 // None of the matches should attempt to autocomplete. 598 // None of the matches should attempt to autocomplete.
566 matches_ = autocomplete_->matches(); 599 matches_ = autocomplete_->matches();
567 for (size_t i = 0; i < matches_.size(); ++i) 600 for (size_t i = 0; i < matches_.size(); ++i) {
568 EXPECT_TRUE(matches_[i].inline_autocompletion.empty()); 601 EXPECT_TRUE(matches_[i].inline_autocompletion.empty());
602 EXPECT_FALSE(matches_[i].allowed_to_be_default_match);
603 }
569 } 604 }
570 605
571 TEST_F(HistoryURLProviderTest, TreatEmailsAsSearches) { 606 TEST_F(HistoryURLProviderTest, TreatEmailsAsSearches) {
572 // Visiting foo.com should not make this string be treated as a navigation. 607 // Visiting foo.com should not make this string be treated as a navigation.
573 // That means the result should be scored around 1200 ("what you typed") 608 // That means the result should be scored around 1200 ("what you typed")
574 // and not 1400+. 609 // and not 1400+.
575 const std::string expected[] = {"http://user@foo.com/"}; 610 const ExpectedUrlAndLegalDefaultMatch expected[] = {
611 ExpectedUrlAndLegalDefaultMatch("http://user@foo.com/", true)
612 };
576 ASSERT_NO_FATAL_FAILURE(RunTest(ASCIIToUTF16("user@foo.com"), string16(), 613 ASSERT_NO_FATAL_FAILURE(RunTest(ASCIIToUTF16("user@foo.com"), string16(),
577 false, expected, arraysize(expected))); 614 false, expected, arraysize(expected)));
578 EXPECT_LE(1200, matches_[0].relevance); 615 EXPECT_LE(1200, matches_[0].relevance);
579 EXPECT_LT(matches_[0].relevance, 1210); 616 EXPECT_LT(matches_[0].relevance, 1210);
580 } 617 }
581 618
582 TEST_F(HistoryURLProviderTest, IntranetURLsWithPaths) { 619 TEST_F(HistoryURLProviderTest, IntranetURLsWithPaths) {
583 struct TestCase { 620 struct TestCase {
584 const char* input; 621 const char* input;
585 int relevance; 622 int relevance;
586 } test_cases[] = { 623 } test_cases[] = {
587 { "fooey", 0 }, 624 { "fooey", 0 },
588 { "fooey/", 1200 }, // 1200 for URL would still navigate by default. 625 { "fooey/", 1200 }, // 1200 for URL would still navigate by default.
589 { "fooey/a", 1200 }, // 1200 for UNKNOWN would not. 626 { "fooey/a", 1200 }, // 1200 for UNKNOWN would not.
590 { "fooey/a b", 1200 }, // Also UNKNOWN. 627 { "fooey/a b", 1200 }, // Also UNKNOWN.
591 { "gooey", 1410 }, 628 { "gooey", 1410 },
592 { "gooey/", 1410 }, 629 { "gooey/", 1410 },
593 { "gooey/a", 1400 }, 630 { "gooey/a", 1400 },
594 { "gooey/a b", 1400 }, 631 { "gooey/a b", 1400 },
595 }; 632 };
596 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); ++i) { 633 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); ++i) {
597 SCOPED_TRACE(test_cases[i].input); 634 SCOPED_TRACE(test_cases[i].input);
598 if (test_cases[i].relevance == 0) { 635 if (test_cases[i].relevance == 0) {
599 RunTest(ASCIIToUTF16(test_cases[i].input), string16(), false, NULL, 0); 636 RunTest(ASCIIToUTF16(test_cases[i].input), string16(), false, NULL, 0);
600 } else { 637 } else {
601 const std::string output[] = { 638 const ExpectedUrlAndLegalDefaultMatch output[] = {
602 URLFixerUpper::FixupURL(test_cases[i].input, std::string()).spec() 639 ExpectedUrlAndLegalDefaultMatch(
640 URLFixerUpper::FixupURL(test_cases[i].input, std::string()).spec(),
641 true)
603 }; 642 };
604 ASSERT_NO_FATAL_FAILURE(RunTest(ASCIIToUTF16(test_cases[i].input), 643 ASSERT_NO_FATAL_FAILURE(RunTest(ASCIIToUTF16(test_cases[i].input),
605 string16(), false, output, arraysize(output))); 644 string16(), false, output, arraysize(output)));
606 // Actual relevance should be at least what test_cases expects and 645 // Actual relevance should be at least what test_cases expects and
607 // and no more than 10 more. 646 // and no more than 10 more.
608 EXPECT_LE(test_cases[i].relevance, matches_[0].relevance); 647 EXPECT_LE(test_cases[i].relevance, matches_[0].relevance);
609 EXPECT_LT(matches_[0].relevance, test_cases[i].relevance + 10); 648 EXPECT_LT(matches_[0].relevance, test_cases[i].relevance + 10);
610 } 649 }
611 } 650 }
612 } 651 }
613 652
614 TEST_F(HistoryURLProviderTest, IntranetURLsWithRefs) { 653 TEST_F(HistoryURLProviderTest, IntranetURLsWithRefs) {
615 struct TestCase { 654 struct TestCase {
616 const char* input; 655 const char* input;
617 int relevance; 656 int relevance;
618 AutocompleteInput::Type type; 657 AutocompleteInput::Type type;
619 } test_cases[] = { 658 } test_cases[] = {
620 { "gooey", 1410, AutocompleteInput::UNKNOWN }, 659 { "gooey", 1410, AutocompleteInput::UNKNOWN },
621 { "gooey/", 1410, AutocompleteInput::URL }, 660 { "gooey/", 1410, AutocompleteInput::URL },
622 { "gooey#", 1200, AutocompleteInput::UNKNOWN }, 661 { "gooey#", 1200, AutocompleteInput::UNKNOWN },
623 { "gooey/#", 1200, AutocompleteInput::URL }, 662 { "gooey/#", 1200, AutocompleteInput::URL },
624 { "gooey#foo", 1200, AutocompleteInput::UNKNOWN }, 663 { "gooey#foo", 1200, AutocompleteInput::UNKNOWN },
625 { "gooey/#foo", 1200, AutocompleteInput::URL }, 664 { "gooey/#foo", 1200, AutocompleteInput::URL },
626 { "gooey# foo", 1200, AutocompleteInput::UNKNOWN }, 665 { "gooey# foo", 1200, AutocompleteInput::UNKNOWN },
627 { "gooey/# foo", 1200, AutocompleteInput::URL }, 666 { "gooey/# foo", 1200, AutocompleteInput::URL },
628 }; 667 };
629 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); ++i) { 668 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); ++i) {
630 SCOPED_TRACE(test_cases[i].input); 669 SCOPED_TRACE(test_cases[i].input);
631 const std::string output[] = { 670 const ExpectedUrlAndLegalDefaultMatch output[] = {
632 URLFixerUpper::FixupURL(test_cases[i].input, std::string()).spec() 671 ExpectedUrlAndLegalDefaultMatch(
672 URLFixerUpper::FixupURL(test_cases[i].input, std::string()).spec(),
673 true)
633 }; 674 };
634 AutocompleteInput::Type type; 675 AutocompleteInput::Type type;
635 ASSERT_NO_FATAL_FAILURE( 676 ASSERT_NO_FATAL_FAILURE(
636 RunTest(ASCIIToUTF16(test_cases[i].input), 677 RunTest(ASCIIToUTF16(test_cases[i].input),
637 string16(), false, output, arraysize(output), &type)); 678 string16(), false, output, arraysize(output), &type));
638 // Actual relevance should be at least what test_cases expects and 679 // Actual relevance should be at least what test_cases expects and
639 // and no more than 10 more. 680 // and no more than 10 more.
640 EXPECT_LE(test_cases[i].relevance, matches_[0].relevance); 681 EXPECT_LE(test_cases[i].relevance, matches_[0].relevance);
641 EXPECT_LT(matches_[0].relevance, test_cases[i].relevance + 10); 682 EXPECT_LT(matches_[0].relevance, test_cases[i].relevance + 10);
642 // Input type should be what we expect. This is important because 683 // Input type should be what we expect. This is important because
643 // this provider counts on SearchProvider to give queries a relevance 684 // this provider counts on SearchProvider to give queries a relevance
644 // score >1200 for UNKNOWN inputs and <1200 for URL inputs. (That's 685 // score >1200 for UNKNOWN inputs and <1200 for URL inputs. (That's
645 // already tested in search_provider_unittest.cc.) For this test 686 // already tested in search_provider_unittest.cc.) For this test
646 // here to test that the user sees the correct behavior, it needs 687 // here to test that the user sees the correct behavior, it needs
647 // to check that the input type was identified correctly. 688 // to check that the input type was identified correctly.
648 EXPECT_EQ(test_cases[i].type, type); 689 EXPECT_EQ(test_cases[i].type, type);
649 } 690 }
650 } 691 }
651 692
652 // Makes sure autocompletion happens for intranet sites that have been 693 // Makes sure autocompletion happens for intranet sites that have been
653 // previoulsy visited. 694 // previoulsy visited.
654 TEST_F(HistoryURLProviderTest, IntranetURLCompletion) { 695 TEST_F(HistoryURLProviderTest, IntranetURLCompletion) {
655 sort_matches_ = true; 696 sort_matches_ = true;
656 697
657 const std::string expected1[] = { 698 const ExpectedUrlAndLegalDefaultMatch expected1[] = {
658 "http://intra/three", 699 ExpectedUrlAndLegalDefaultMatch("http://intra/three", true),
659 "http://intra/two", 700 ExpectedUrlAndLegalDefaultMatch("http://intra/two", true)
660 }; 701 };
661 ASSERT_NO_FATAL_FAILURE(RunTest(ASCIIToUTF16("intra/t"), string16(), false, 702 ASSERT_NO_FATAL_FAILURE(RunTest(ASCIIToUTF16("intra/t"), string16(), false,
662 expected1, arraysize(expected1))); 703 expected1, arraysize(expected1)));
663 EXPECT_LE(1410, matches_[0].relevance); 704 EXPECT_LE(1410, matches_[0].relevance);
664 EXPECT_LT(matches_[0].relevance, 1420); 705 EXPECT_LT(matches_[0].relevance, 1420);
665 EXPECT_EQ(matches_[0].relevance - 1, matches_[1].relevance); 706 EXPECT_EQ(matches_[0].relevance - 1, matches_[1].relevance);
666 707
667 const std::string expected2[] = { 708 const ExpectedUrlAndLegalDefaultMatch expected2[] = {
668 "http://moo/b", 709 ExpectedUrlAndLegalDefaultMatch("http://moo/b", true),
669 "http://moo/bar", 710 ExpectedUrlAndLegalDefaultMatch("http://moo/bar", true)
670 }; 711 };
671 ASSERT_NO_FATAL_FAILURE(RunTest(ASCIIToUTF16("moo/b"), string16(), false, 712 ASSERT_NO_FATAL_FAILURE(RunTest(ASCIIToUTF16("moo/b"), string16(), false,
672 expected2, arraysize(expected2))); 713 expected2, arraysize(expected2)));
673 // The url what you typed match should be around 1400, otherwise the 714 // The url what you typed match should be around 1400, otherwise the
674 // search what you typed match is going to be first. 715 // search what you typed match is going to be first.
675 EXPECT_LE(1400, matches_[0].relevance); 716 EXPECT_LE(1400, matches_[0].relevance);
676 EXPECT_LT(matches_[0].relevance, 1410); 717 EXPECT_LT(matches_[0].relevance, 1410);
677 718
678 const std::string expected3[] = { 719 const ExpectedUrlAndLegalDefaultMatch expected3[] = {
679 "http://intra/one", 720 ExpectedUrlAndLegalDefaultMatch("http://intra/one", true),
680 "http://intra/three", 721 ExpectedUrlAndLegalDefaultMatch("http://intra/three", true),
681 "http://intra/two", 722 ExpectedUrlAndLegalDefaultMatch("http://intra/two", true)
682 }; 723 };
683 RunTest(ASCIIToUTF16("intra"), string16(), false, expected3, 724 RunTest(ASCIIToUTF16("intra"), string16(), false, expected3,
684 arraysize(expected3)); 725 arraysize(expected3));
685 726
686 const std::string expected4[] = { 727 const ExpectedUrlAndLegalDefaultMatch expected4[] = {
687 "http://intra/one", 728 ExpectedUrlAndLegalDefaultMatch("http://intra/one", true),
688 "http://intra/three", 729 ExpectedUrlAndLegalDefaultMatch("http://intra/three", true),
689 "http://intra/two", 730 ExpectedUrlAndLegalDefaultMatch("http://intra/two", true)
690 }; 731 };
691 RunTest(ASCIIToUTF16("intra/"), string16(), false, expected4, 732 RunTest(ASCIIToUTF16("intra/"), string16(), false, expected4,
692 arraysize(expected4)); 733 arraysize(expected4));
693 734
694 const std::string expected5[] = { 735 const ExpectedUrlAndLegalDefaultMatch expected5[] = {
695 "http://intra/one", 736 ExpectedUrlAndLegalDefaultMatch("http://intra/one", true)
696 }; 737 };
697 ASSERT_NO_FATAL_FAILURE(RunTest(ASCIIToUTF16("intra/o"), string16(), false, 738 ASSERT_NO_FATAL_FAILURE(RunTest(ASCIIToUTF16("intra/o"), string16(), false,
698 expected5, arraysize(expected5))); 739 expected5, arraysize(expected5)));
699 EXPECT_LE(1410, matches_[0].relevance); 740 EXPECT_LE(1410, matches_[0].relevance);
700 EXPECT_LT(matches_[0].relevance, 1420); 741 EXPECT_LT(matches_[0].relevance, 1420);
701 742
702 const std::string expected6[] = { 743 const ExpectedUrlAndLegalDefaultMatch expected6[] = {
703 "http://intra/x", 744 ExpectedUrlAndLegalDefaultMatch("http://intra/x", true)
704 }; 745 };
705 ASSERT_NO_FATAL_FAILURE(RunTest(ASCIIToUTF16("intra/x"), string16(), false, 746 ASSERT_NO_FATAL_FAILURE(RunTest(ASCIIToUTF16("intra/x"), string16(), false,
706 expected6, arraysize(expected6))); 747 expected6, arraysize(expected6)));
707 EXPECT_LE(1400, matches_[0].relevance); 748 EXPECT_LE(1400, matches_[0].relevance);
708 EXPECT_LT(matches_[0].relevance, 1410); 749 EXPECT_LT(matches_[0].relevance, 1410);
709 750
710 const std::string expected7[] = { 751 const ExpectedUrlAndLegalDefaultMatch expected7[] = {
711 "http://typedhost/untypedpath", 752 ExpectedUrlAndLegalDefaultMatch("http://typedhost/untypedpath", true)
712 }; 753 };
713 ASSERT_NO_FATAL_FAILURE(RunTest(ASCIIToUTF16("typedhost/untypedpath"), 754 ASSERT_NO_FATAL_FAILURE(RunTest(ASCIIToUTF16("typedhost/untypedpath"),
714 string16(), false, expected7, arraysize(expected7))); 755 string16(), false, expected7, arraysize(expected7)));
715 EXPECT_LE(1400, matches_[0].relevance); 756 EXPECT_LE(1400, matches_[0].relevance);
716 EXPECT_LT(matches_[0].relevance, 1410); 757 EXPECT_LT(matches_[0].relevance, 1410);
717 } 758 }
718 759
719 TEST_F(HistoryURLProviderTest, CrashDueToFixup) { 760 TEST_F(HistoryURLProviderTest, CrashDueToFixup) {
720 // This test passes if we don't crash. The results don't matter. 761 // This test passes if we don't crash. The results don't matter.
721 const char* const test_cases[] = { 762 const char* const test_cases[] = {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
756 {"https://testsearch.com/?q=foobar", 20}, 797 {"https://testsearch.com/?q=foobar", 20},
757 {"http://foobar.com/", 10} 798 {"http://foobar.com/", 10}
758 }; 799 };
759 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); ++i) { 800 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); ++i) {
760 history_service_->AddPageWithDetails(GURL(test_cases[i].url), 801 history_service_->AddPageWithDetails(GURL(test_cases[i].url),
761 UTF8ToUTF16("Title"), test_cases[i].count, test_cases[i].count, 802 UTF8ToUTF16("Title"), test_cases[i].count, test_cases[i].count,
762 Time::Now(), false, history::SOURCE_BROWSED); 803 Time::Now(), false, history::SOURCE_BROWSED);
763 } 804 }
764 805
765 // We should not see search URLs when typing a previously used query. 806 // We should not see search URLs when typing a previously used query.
766 const std::string expected_when_searching_query[] = { 807 const ExpectedUrlAndLegalDefaultMatch expected_when_searching_query[] = {
767 test_cases[2].url 808 ExpectedUrlAndLegalDefaultMatch(test_cases[2].url, false)
768 }; 809 };
769 RunTest(ASCIIToUTF16("foobar"), string16(), true, 810 RunTest(ASCIIToUTF16("foobar"), string16(), true,
770 expected_when_searching_query, arraysize(expected_when_searching_query)); 811 expected_when_searching_query, arraysize(expected_when_searching_query));
771 812
772 // We should not see search URLs when typing the search engine name. 813 // We should not see search URLs when typing the search engine name.
773 const std::string expected_when_searching_site[] = { 814 const ExpectedUrlAndLegalDefaultMatch expected_when_searching_site[] = {
774 test_cases[0].url 815 ExpectedUrlAndLegalDefaultMatch(test_cases[0].url, false)
775 }; 816 };
776 RunTest(ASCIIToUTF16("testsearch"), string16(), true, 817 RunTest(ASCIIToUTF16("testsearch"), string16(), true,
777 expected_when_searching_site, arraysize(expected_when_searching_site)); 818 expected_when_searching_site, arraysize(expected_when_searching_site));
778 } 819 }
779 820
780 TEST_F(HistoryURLProviderTest, SuggestExactInput) { 821 TEST_F(HistoryURLProviderTest, SuggestExactInput) {
781 const size_t npos = std::string::npos; 822 const size_t npos = std::string::npos;
782 struct TestCase { 823 struct TestCase {
783 // Inputs: 824 // Inputs:
784 const char* input; 825 const char* input;
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
849 EXPECT_EQ(test_cases[i].offsets[match_index], 890 EXPECT_EQ(test_cases[i].offsets[match_index],
850 match.contents_class[match_index].offset); 891 match.contents_class[match_index].offset);
851 EXPECT_EQ(ACMatchClassification::URL | 892 EXPECT_EQ(ACMatchClassification::URL |
852 (match_index == test_cases[i].match_classification_index ? 893 (match_index == test_cases[i].match_classification_index ?
853 ACMatchClassification::MATCH : 0), 894 ACMatchClassification::MATCH : 0),
854 match.contents_class[match_index].style); 895 match.contents_class[match_index].style);
855 } 896 }
856 EXPECT_EQ(npos, test_cases[i].offsets[match.contents_class.size()]); 897 EXPECT_EQ(npos, test_cases[i].offsets[match.contents_class.size()]);
857 } 898 }
858 } 899 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698