OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/omnibox/browser/autocomplete_result.h" | 5 #include "components/omnibox/browser/autocomplete_result.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 const TestData* expected, size_t expected_size) { | 201 const TestData* expected, size_t expected_size) { |
202 AutocompleteInput input(base::ASCIIToUTF16("a"), base::string16::npos, | 202 AutocompleteInput input(base::ASCIIToUTF16("a"), base::string16::npos, |
203 std::string(), GURL(), | 203 std::string(), GURL(), |
204 OmniboxEventProto::INVALID_SPEC, false, false, false, | 204 OmniboxEventProto::INVALID_SPEC, false, false, false, |
205 true, false, TestSchemeClassifier()); | 205 true, false, TestSchemeClassifier()); |
206 | 206 |
207 ACMatches last_matches; | 207 ACMatches last_matches; |
208 PopulateAutocompleteMatches(last, last_size, &last_matches); | 208 PopulateAutocompleteMatches(last, last_size, &last_matches); |
209 AutocompleteResult last_result; | 209 AutocompleteResult last_result; |
210 last_result.AppendMatches(input, last_matches); | 210 last_result.AppendMatches(input, last_matches); |
211 last_result.SortAndCull(input, std::string(), template_url_service_.get()); | 211 last_result.SortAndCull(input, template_url_service_.get()); |
212 | 212 |
213 ACMatches current_matches; | 213 ACMatches current_matches; |
214 PopulateAutocompleteMatches(current, current_size, ¤t_matches); | 214 PopulateAutocompleteMatches(current, current_size, ¤t_matches); |
215 AutocompleteResult current_result; | 215 AutocompleteResult current_result; |
216 current_result.AppendMatches(input, current_matches); | 216 current_result.AppendMatches(input, current_matches); |
217 current_result.SortAndCull(input, std::string(), template_url_service_.get()); | 217 current_result.SortAndCull(input, template_url_service_.get()); |
218 current_result.CopyOldMatches( | 218 current_result.CopyOldMatches( |
219 input, std::string(), last_result, template_url_service_.get()); | 219 input, last_result, template_url_service_.get()); |
220 | 220 |
221 AssertResultMatches(current_result, expected, expected_size); | 221 AssertResultMatches(current_result, expected, expected_size); |
222 } | 222 } |
223 | 223 |
224 // Assertion testing for AutocompleteResult::Swap. | 224 // Assertion testing for AutocompleteResult::Swap. |
225 TEST_F(AutocompleteResultTest, Swap) { | 225 TEST_F(AutocompleteResultTest, Swap) { |
226 AutocompleteResult r1; | 226 AutocompleteResult r1; |
227 AutocompleteResult r2; | 227 AutocompleteResult r2; |
228 | 228 |
229 // Swap with empty shouldn't do anything interesting. | 229 // Swap with empty shouldn't do anything interesting. |
230 r1.Swap(&r2); | 230 r1.Swap(&r2); |
231 EXPECT_EQ(r1.end(), r1.default_match()); | 231 EXPECT_EQ(r1.end(), r1.default_match()); |
232 EXPECT_EQ(r2.end(), r2.default_match()); | 232 EXPECT_EQ(r2.end(), r2.default_match()); |
233 | 233 |
234 // Swap with a single match. | 234 // Swap with a single match. |
235 ACMatches matches; | 235 ACMatches matches; |
236 AutocompleteMatch match; | 236 AutocompleteMatch match; |
237 match.relevance = 1; | 237 match.relevance = 1; |
238 match.allowed_to_be_default_match = true; | 238 match.allowed_to_be_default_match = true; |
239 AutocompleteInput input(base::ASCIIToUTF16("a"), base::string16::npos, | 239 AutocompleteInput input(base::ASCIIToUTF16("a"), base::string16::npos, |
240 std::string(), GURL(), | 240 std::string(), GURL(), |
241 OmniboxEventProto::INVALID_SPEC, false, false, false, | 241 OmniboxEventProto::INVALID_SPEC, false, false, false, |
242 true, false, TestSchemeClassifier()); | 242 true, false, TestSchemeClassifier()); |
243 matches.push_back(match); | 243 matches.push_back(match); |
244 r1.AppendMatches(input, matches); | 244 r1.AppendMatches(input, matches); |
245 r1.SortAndCull(input, std::string(), template_url_service_.get()); | 245 r1.SortAndCull(input, template_url_service_.get()); |
246 EXPECT_EQ(r1.begin(), r1.default_match()); | 246 EXPECT_EQ(r1.begin(), r1.default_match()); |
247 EXPECT_EQ("http://a/", r1.alternate_nav_url().spec()); | 247 EXPECT_EQ("http://a/", r1.alternate_nav_url().spec()); |
248 r1.Swap(&r2); | 248 r1.Swap(&r2); |
249 EXPECT_TRUE(r1.empty()); | 249 EXPECT_TRUE(r1.empty()); |
250 EXPECT_EQ(r1.end(), r1.default_match()); | 250 EXPECT_EQ(r1.end(), r1.default_match()); |
251 EXPECT_TRUE(r1.alternate_nav_url().is_empty()); | 251 EXPECT_TRUE(r1.alternate_nav_url().is_empty()); |
252 ASSERT_FALSE(r2.empty()); | 252 ASSERT_FALSE(r2.empty()); |
253 EXPECT_EQ(r2.begin(), r2.default_match()); | 253 EXPECT_EQ(r2.begin(), r2.default_match()); |
254 EXPECT_EQ("http://a/", r2.alternate_nav_url().spec()); | 254 EXPECT_EQ("http://a/", r2.alternate_nav_url().spec()); |
255 } | 255 } |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
372 PopulateAutocompleteMatches(data, arraysize(data), &matches); | 372 PopulateAutocompleteMatches(data, arraysize(data), &matches); |
373 matches[1].destination_url = GURL(); | 373 matches[1].destination_url = GURL(); |
374 matches[3].destination_url = GURL(); | 374 matches[3].destination_url = GURL(); |
375 matches[4].destination_url = GURL(); | 375 matches[4].destination_url = GURL(); |
376 | 376 |
377 AutocompleteInput input(base::string16(), base::string16::npos, std::string(), | 377 AutocompleteInput input(base::string16(), base::string16::npos, std::string(), |
378 GURL(), OmniboxEventProto::INVALID_SPEC, false, false, | 378 GURL(), OmniboxEventProto::INVALID_SPEC, false, false, |
379 false, true, false, TestSchemeClassifier()); | 379 false, true, false, TestSchemeClassifier()); |
380 AutocompleteResult result; | 380 AutocompleteResult result; |
381 result.AppendMatches(input, matches); | 381 result.AppendMatches(input, matches); |
382 result.SortAndCull(input, std::string(), template_url_service_.get()); | 382 result.SortAndCull(input, template_url_service_.get()); |
383 | 383 |
384 // Of the two results with the same non-empty destination URL, the | 384 // Of the two results with the same non-empty destination URL, the |
385 // lower-relevance one should be dropped. All of the results with empty URLs | 385 // lower-relevance one should be dropped. All of the results with empty URLs |
386 // should be kept. | 386 // should be kept. |
387 ASSERT_EQ(4U, result.size()); | 387 ASSERT_EQ(4U, result.size()); |
388 EXPECT_TRUE(result.match_at(0)->destination_url.is_empty()); | 388 EXPECT_TRUE(result.match_at(0)->destination_url.is_empty()); |
389 EXPECT_EQ(1300, result.match_at(0)->relevance); | 389 EXPECT_EQ(1300, result.match_at(0)->relevance); |
390 EXPECT_TRUE(result.match_at(1)->destination_url.is_empty()); | 390 EXPECT_TRUE(result.match_at(1)->destination_url.is_empty()); |
391 EXPECT_EQ(1200, result.match_at(1)->relevance); | 391 EXPECT_EQ(1200, result.match_at(1)->relevance); |
392 EXPECT_TRUE(result.match_at(2)->destination_url.is_empty()); | 392 EXPECT_TRUE(result.match_at(2)->destination_url.is_empty()); |
(...skipping 24 matching lines...) Expand all Loading... |
417 matches[1].destination_url = GURL("http://www.foo.com/s?q=foo2"); | 417 matches[1].destination_url = GURL("http://www.foo.com/s?q=foo2"); |
418 matches[2].destination_url = GURL("http://www.foo.com/s?q=foo&oq=f"); | 418 matches[2].destination_url = GURL("http://www.foo.com/s?q=foo&oq=f"); |
419 matches[3].destination_url = GURL("http://www.foo.com/s?q=foo&aqs=0"); | 419 matches[3].destination_url = GURL("http://www.foo.com/s?q=foo&aqs=0"); |
420 matches[4].destination_url = GURL("http://www.foo.com/"); | 420 matches[4].destination_url = GURL("http://www.foo.com/"); |
421 | 421 |
422 AutocompleteInput input(base::string16(), base::string16::npos, std::string(), | 422 AutocompleteInput input(base::string16(), base::string16::npos, std::string(), |
423 GURL(), OmniboxEventProto::INVALID_SPEC, false, false, | 423 GURL(), OmniboxEventProto::INVALID_SPEC, false, false, |
424 false, true, false, TestSchemeClassifier()); | 424 false, true, false, TestSchemeClassifier()); |
425 AutocompleteResult result; | 425 AutocompleteResult result; |
426 result.AppendMatches(input, matches); | 426 result.AppendMatches(input, matches); |
427 result.SortAndCull(input, std::string(), template_url_service_.get()); | 427 result.SortAndCull(input, template_url_service_.get()); |
428 | 428 |
429 // We expect the 3rd and 4th results to be removed. | 429 // We expect the 3rd and 4th results to be removed. |
430 ASSERT_EQ(3U, result.size()); | 430 ASSERT_EQ(3U, result.size()); |
431 EXPECT_EQ("http://www.foo.com/s?q=foo", | 431 EXPECT_EQ("http://www.foo.com/s?q=foo", |
432 result.match_at(0)->destination_url.spec()); | 432 result.match_at(0)->destination_url.spec()); |
433 EXPECT_EQ(1300, result.match_at(0)->relevance); | 433 EXPECT_EQ(1300, result.match_at(0)->relevance); |
434 EXPECT_EQ("http://www.foo.com/s?q=foo2", | 434 EXPECT_EQ("http://www.foo.com/s?q=foo2", |
435 result.match_at(1)->destination_url.spec()); | 435 result.match_at(1)->destination_url.spec()); |
436 EXPECT_EQ(1200, result.match_at(1)->relevance); | 436 EXPECT_EQ(1200, result.match_at(1)->relevance); |
437 EXPECT_EQ("http://www.foo.com/", | 437 EXPECT_EQ("http://www.foo.com/", |
(...skipping 30 matching lines...) Expand all Loading... |
468 matches[2].destination_url = GURL("http://www.foo.com/s?q=foo&oq=f"); | 468 matches[2].destination_url = GURL("http://www.foo.com/s?q=foo&oq=f"); |
469 matches[3].destination_url = GURL("http://www.foo.com/s?q=foo&aqs=0"); | 469 matches[3].destination_url = GURL("http://www.foo.com/s?q=foo&aqs=0"); |
470 matches[4].destination_url = GURL("http://www.foo.com/"); | 470 matches[4].destination_url = GURL("http://www.foo.com/"); |
471 matches[5].destination_url = GURL("http://www.foo.com/s?q=foo2&oq=f"); | 471 matches[5].destination_url = GURL("http://www.foo.com/s?q=foo2&oq=f"); |
472 | 472 |
473 AutocompleteInput input(base::string16(), base::string16::npos, std::string(), | 473 AutocompleteInput input(base::string16(), base::string16::npos, std::string(), |
474 GURL(), OmniboxEventProto::INVALID_SPEC, false, false, | 474 GURL(), OmniboxEventProto::INVALID_SPEC, false, false, |
475 false, true, false, TestSchemeClassifier()); | 475 false, true, false, TestSchemeClassifier()); |
476 AutocompleteResult result; | 476 AutocompleteResult result; |
477 result.AppendMatches(input, matches); | 477 result.AppendMatches(input, matches); |
478 result.SortAndCull(input, std::string(), template_url_service_.get()); | 478 result.SortAndCull(input, template_url_service_.get()); |
479 | 479 |
480 // Expect 3 unique results after SortAndCull(). | 480 // Expect 3 unique results after SortAndCull(). |
481 ASSERT_EQ(3U, result.size()); | 481 ASSERT_EQ(3U, result.size()); |
482 | 482 |
483 // Check that 3rd and 4th result got added to the first result as dups | 483 // Check that 3rd and 4th result got added to the first result as dups |
484 // and also duplicates of the 4th match got copied. | 484 // and also duplicates of the 4th match got copied. |
485 ASSERT_EQ(4U, result.match_at(0)->duplicate_matches.size()); | 485 ASSERT_EQ(4U, result.match_at(0)->duplicate_matches.size()); |
486 const AutocompleteMatch* first_match = result.match_at(0); | 486 const AutocompleteMatch* first_match = result.match_at(0); |
487 EXPECT_EQ(matches[2].destination_url, | 487 EXPECT_EQ(matches[2].destination_url, |
488 first_match->duplicate_matches.at(1).destination_url); | 488 first_match->duplicate_matches.at(1).destination_url); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
521 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "A", params)); | 521 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "A", params)); |
522 } | 522 } |
523 base::FieldTrialList::CreateFieldTrial( | 523 base::FieldTrialList::CreateFieldTrial( |
524 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "A"); | 524 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "A"); |
525 | 525 |
526 AutocompleteInput input(base::string16(), base::string16::npos, std::string(), | 526 AutocompleteInput input(base::string16(), base::string16::npos, std::string(), |
527 GURL(), OmniboxEventProto::HOME_PAGE, false, false, | 527 GURL(), OmniboxEventProto::HOME_PAGE, false, false, |
528 false, true, false, TestSchemeClassifier()); | 528 false, true, false, TestSchemeClassifier()); |
529 AutocompleteResult result; | 529 AutocompleteResult result; |
530 result.AppendMatches(input, matches); | 530 result.AppendMatches(input, matches); |
531 result.SortAndCull(input, std::string(), template_url_service_.get()); | 531 result.SortAndCull(input, template_url_service_.get()); |
532 | 532 |
533 // Check the new ordering. The history-title results should be omitted. | 533 // Check the new ordering. The history-title results should be omitted. |
534 // We cannot check relevance scores because the matches are sorted by | 534 // We cannot check relevance scores because the matches are sorted by |
535 // demoted relevance but the actual relevance scores are not modified. | 535 // demoted relevance but the actual relevance scores are not modified. |
536 ASSERT_EQ(3u, result.size()); | 536 ASSERT_EQ(3u, result.size()); |
537 EXPECT_EQ("http://search-what-you-typed/", | 537 EXPECT_EQ("http://search-what-you-typed/", |
538 result.match_at(0)->destination_url.spec()); | 538 result.match_at(0)->destination_url.spec()); |
539 EXPECT_EQ("http://history-url/", | 539 EXPECT_EQ("http://history-url/", |
540 result.match_at(1)->destination_url.spec()); | 540 result.match_at(1)->destination_url.spec()); |
541 EXPECT_EQ("http://search-history/", | 541 EXPECT_EQ("http://search-history/", |
(...skipping 24 matching lines...) Expand all Loading... |
566 base::FieldTrialList::CreateFieldTrial( | 566 base::FieldTrialList::CreateFieldTrial( |
567 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "C"); | 567 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "C"); |
568 | 568 |
569 { | 569 { |
570 AutocompleteInput input( | 570 AutocompleteInput input( |
571 base::string16(), base::string16::npos, std::string(), GURL(), | 571 base::string16(), base::string16::npos, std::string(), GURL(), |
572 OmniboxEventProto::INSTANT_NTP_WITH_FAKEBOX_AS_STARTING_FOCUS, false, | 572 OmniboxEventProto::INSTANT_NTP_WITH_FAKEBOX_AS_STARTING_FOCUS, false, |
573 false, false, true, false, TestSchemeClassifier()); | 573 false, false, true, false, TestSchemeClassifier()); |
574 AutocompleteResult result; | 574 AutocompleteResult result; |
575 result.AppendMatches(input, matches); | 575 result.AppendMatches(input, matches); |
576 result.SortAndCull(input, std::string(), template_url_service_.get()); | 576 result.SortAndCull(input, template_url_service_.get()); |
577 | 577 |
578 // The NAVSUGGEST dup-url stay above search-url since the navsuggest | 578 // The NAVSUGGEST dup-url stay above search-url since the navsuggest |
579 // variant should not be demoted. | 579 // variant should not be demoted. |
580 ASSERT_EQ(4u, result.size()); | 580 ASSERT_EQ(4u, result.size()); |
581 EXPECT_EQ("http://search-what-you-typed/", | 581 EXPECT_EQ("http://search-what-you-typed/", |
582 result.match_at(0)->destination_url.spec()); | 582 result.match_at(0)->destination_url.spec()); |
583 EXPECT_EQ("http://dup-url/", | 583 EXPECT_EQ("http://dup-url/", |
584 result.match_at(1)->destination_url.spec()); | 584 result.match_at(1)->destination_url.spec()); |
585 EXPECT_EQ(AutocompleteMatchType::NAVSUGGEST, | 585 EXPECT_EQ(AutocompleteMatchType::NAVSUGGEST, |
586 result.match_at(1)->type); | 586 result.match_at(1)->type); |
(...skipping 17 matching lines...) Expand all Loading... |
604 // is already a legal default match (which is the default from | 604 // is already a legal default match (which is the default from |
605 // PopulateAutocompleteMatches()). | 605 // PopulateAutocompleteMatches()). |
606 ACMatches matches; | 606 ACMatches matches; |
607 PopulateAutocompleteMatches(data, arraysize(data), &matches); | 607 PopulateAutocompleteMatches(data, arraysize(data), &matches); |
608 AutocompleteInput input(base::string16(), base::string16::npos, | 608 AutocompleteInput input(base::string16(), base::string16::npos, |
609 std::string(), GURL(), OmniboxEventProto::HOME_PAGE, | 609 std::string(), GURL(), OmniboxEventProto::HOME_PAGE, |
610 false, false, false, true, false, | 610 false, false, false, true, false, |
611 TestSchemeClassifier()); | 611 TestSchemeClassifier()); |
612 AutocompleteResult result; | 612 AutocompleteResult result; |
613 result.AppendMatches(input, matches); | 613 result.AppendMatches(input, matches); |
614 result.SortAndCull(input, std::string(), template_url_service_.get()); | 614 result.SortAndCull(input, template_url_service_.get()); |
615 AssertResultMatches(result, data, 4); | 615 AssertResultMatches(result, data, 4); |
616 } | 616 } |
617 | 617 |
618 { | 618 { |
619 // Check that reorder swaps up a result appropriately. | 619 // Check that reorder swaps up a result appropriately. |
620 ACMatches matches; | 620 ACMatches matches; |
621 PopulateAutocompleteMatches(data, arraysize(data), &matches); | 621 PopulateAutocompleteMatches(data, arraysize(data), &matches); |
622 matches[0].allowed_to_be_default_match = false; | 622 matches[0].allowed_to_be_default_match = false; |
623 matches[1].allowed_to_be_default_match = false; | 623 matches[1].allowed_to_be_default_match = false; |
624 AutocompleteInput input(base::string16(), base::string16::npos, | 624 AutocompleteInput input(base::string16(), base::string16::npos, |
625 std::string(), GURL(), OmniboxEventProto::HOME_PAGE, | 625 std::string(), GURL(), OmniboxEventProto::HOME_PAGE, |
626 false, false, false, true, false, | 626 false, false, false, true, false, |
627 TestSchemeClassifier()); | 627 TestSchemeClassifier()); |
628 AutocompleteResult result; | 628 AutocompleteResult result; |
629 result.AppendMatches(input, matches); | 629 result.AppendMatches(input, matches); |
630 result.SortAndCull(input, std::string(), template_url_service_.get()); | 630 result.SortAndCull(input, template_url_service_.get()); |
631 ASSERT_EQ(4U, result.size()); | 631 ASSERT_EQ(4U, result.size()); |
632 EXPECT_EQ("http://c/", result.match_at(0)->destination_url.spec()); | 632 EXPECT_EQ("http://c/", result.match_at(0)->destination_url.spec()); |
633 EXPECT_EQ("http://a/", result.match_at(1)->destination_url.spec()); | 633 EXPECT_EQ("http://a/", result.match_at(1)->destination_url.spec()); |
634 EXPECT_EQ("http://b/", result.match_at(2)->destination_url.spec()); | 634 EXPECT_EQ("http://b/", result.match_at(2)->destination_url.spec()); |
635 EXPECT_EQ("http://d/", result.match_at(3)->destination_url.spec()); | 635 EXPECT_EQ("http://d/", result.match_at(3)->destination_url.spec()); |
636 } | 636 } |
637 } | 637 } |
638 | 638 |
639 TEST_F(AutocompleteResultTest, TopMatchIsStandaloneVerbatimMatch) { | 639 TEST_F(AutocompleteResultTest, TopMatchIsStandaloneVerbatimMatch) { |
640 ACMatches matches; | 640 ACMatches matches; |
(...skipping 18 matching lines...) Expand all Loading... |
659 matches.clear(); | 659 matches.clear(); |
660 | 660 |
661 // Case 4: Standalone verbatim match found in AutocompleteResult. | 661 // Case 4: Standalone verbatim match found in AutocompleteResult. |
662 PopulateAutocompleteMatchesFromTestData(kVerbatimMatches, 1, &matches); | 662 PopulateAutocompleteMatchesFromTestData(kVerbatimMatches, 1, &matches); |
663 PopulateAutocompleteMatchesFromTestData(kNonVerbatimMatches, 1, &matches); | 663 PopulateAutocompleteMatchesFromTestData(kNonVerbatimMatches, 1, &matches); |
664 result.AppendMatches(AutocompleteInput(), matches); | 664 result.AppendMatches(AutocompleteInput(), matches); |
665 EXPECT_TRUE(result.TopMatchIsStandaloneVerbatimMatch()); | 665 EXPECT_TRUE(result.TopMatchIsStandaloneVerbatimMatch()); |
666 result.Reset(); | 666 result.Reset(); |
667 matches.clear(); | 667 matches.clear(); |
668 } | 668 } |
OLD | NEW |