| 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 <memory> | 9 #include <memory> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 { 0, 1, 1300, true }, | 367 { 0, 1, 1300, true }, |
| 368 { 0, 1, 1200, true }, | 368 { 0, 1, 1200, true }, |
| 369 }; | 369 }; |
| 370 | 370 |
| 371 ACMatches matches; | 371 ACMatches matches; |
| 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::ASCIIToUTF16("a"), base::string16::npos, |
| 378 GURL(), OmniboxEventProto::INVALID_SPEC, false, false, | 378 std::string(), GURL(), |
| 379 false, true, false, TestSchemeClassifier()); | 379 OmniboxEventProto::INVALID_SPEC, false, false, false, |
| 380 true, false, TestSchemeClassifier()); |
| 380 AutocompleteResult result; | 381 AutocompleteResult result; |
| 381 result.AppendMatches(input, matches); | 382 result.AppendMatches(input, matches); |
| 382 result.SortAndCull(input, template_url_service_.get()); | 383 result.SortAndCull(input, template_url_service_.get()); |
| 383 | 384 |
| 384 // Of the two results with the same non-empty destination URL, the | 385 // 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 | 386 // lower-relevance one should be dropped. All of the results with empty URLs |
| 386 // should be kept. | 387 // should be kept. |
| 387 ASSERT_EQ(4U, result.size()); | 388 ASSERT_EQ(4U, result.size()); |
| 388 EXPECT_TRUE(result.match_at(0)->destination_url.is_empty()); | 389 EXPECT_TRUE(result.match_at(0)->destination_url.is_empty()); |
| 389 EXPECT_EQ(1300, result.match_at(0)->relevance); | 390 EXPECT_EQ(1300, result.match_at(0)->relevance); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 412 }; | 413 }; |
| 413 | 414 |
| 414 ACMatches matches; | 415 ACMatches matches; |
| 415 PopulateAutocompleteMatches(data, arraysize(data), &matches); | 416 PopulateAutocompleteMatches(data, arraysize(data), &matches); |
| 416 matches[0].destination_url = GURL("http://www.foo.com/s?q=foo"); | 417 matches[0].destination_url = GURL("http://www.foo.com/s?q=foo"); |
| 417 matches[1].destination_url = GURL("http://www.foo.com/s?q=foo2"); | 418 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"); | 419 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"); | 420 matches[3].destination_url = GURL("http://www.foo.com/s?q=foo&aqs=0"); |
| 420 matches[4].destination_url = GURL("http://www.foo.com/"); | 421 matches[4].destination_url = GURL("http://www.foo.com/"); |
| 421 | 422 |
| 422 AutocompleteInput input(base::string16(), base::string16::npos, std::string(), | 423 AutocompleteInput input(base::ASCIIToUTF16("a"), base::string16::npos, |
| 423 GURL(), OmniboxEventProto::INVALID_SPEC, false, false, | 424 std::string(), GURL(), |
| 424 false, true, false, TestSchemeClassifier()); | 425 OmniboxEventProto::INVALID_SPEC, false, false, false, |
| 426 true, false, TestSchemeClassifier()); |
| 425 AutocompleteResult result; | 427 AutocompleteResult result; |
| 426 result.AppendMatches(input, matches); | 428 result.AppendMatches(input, matches); |
| 427 result.SortAndCull(input, template_url_service_.get()); | 429 result.SortAndCull(input, template_url_service_.get()); |
| 428 | 430 |
| 429 // We expect the 3rd and 4th results to be removed. | 431 // We expect the 3rd and 4th results to be removed. |
| 430 ASSERT_EQ(3U, result.size()); | 432 ASSERT_EQ(3U, result.size()); |
| 431 EXPECT_EQ("http://www.foo.com/s?q=foo", | 433 EXPECT_EQ("http://www.foo.com/s?q=foo", |
| 432 result.match_at(0)->destination_url.spec()); | 434 result.match_at(0)->destination_url.spec()); |
| 433 EXPECT_EQ(1300, result.match_at(0)->relevance); | 435 EXPECT_EQ(1300, result.match_at(0)->relevance); |
| 434 EXPECT_EQ("http://www.foo.com/s?q=foo2", | 436 EXPECT_EQ("http://www.foo.com/s?q=foo2", |
| (...skipping 28 matching lines...) Expand all Loading... |
| 463 | 465 |
| 464 ACMatches matches; | 466 ACMatches matches; |
| 465 PopulateAutocompleteMatches(data, arraysize(data), &matches); | 467 PopulateAutocompleteMatches(data, arraysize(data), &matches); |
| 466 matches[0].destination_url = GURL("http://www.foo.com/s?q=foo"); | 468 matches[0].destination_url = GURL("http://www.foo.com/s?q=foo"); |
| 467 matches[1].destination_url = GURL("http://www.foo.com/s?q=foo2"); | 469 matches[1].destination_url = GURL("http://www.foo.com/s?q=foo2"); |
| 468 matches[2].destination_url = GURL("http://www.foo.com/s?q=foo&oq=f"); | 470 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"); | 471 matches[3].destination_url = GURL("http://www.foo.com/s?q=foo&aqs=0"); |
| 470 matches[4].destination_url = GURL("http://www.foo.com/"); | 472 matches[4].destination_url = GURL("http://www.foo.com/"); |
| 471 matches[5].destination_url = GURL("http://www.foo.com/s?q=foo2&oq=f"); | 473 matches[5].destination_url = GURL("http://www.foo.com/s?q=foo2&oq=f"); |
| 472 | 474 |
| 473 AutocompleteInput input(base::string16(), base::string16::npos, std::string(), | 475 AutocompleteInput input(base::ASCIIToUTF16("a"), base::string16::npos, |
| 474 GURL(), OmniboxEventProto::INVALID_SPEC, false, false, | 476 std::string(), GURL(), |
| 475 false, true, false, TestSchemeClassifier()); | 477 OmniboxEventProto::INVALID_SPEC, false, false, false, |
| 478 true, false, TestSchemeClassifier()); |
| 476 AutocompleteResult result; | 479 AutocompleteResult result; |
| 477 result.AppendMatches(input, matches); | 480 result.AppendMatches(input, matches); |
| 478 result.SortAndCull(input, template_url_service_.get()); | 481 result.SortAndCull(input, template_url_service_.get()); |
| 479 | 482 |
| 480 // Expect 3 unique results after SortAndCull(). | 483 // Expect 3 unique results after SortAndCull(). |
| 481 ASSERT_EQ(3U, result.size()); | 484 ASSERT_EQ(3U, result.size()); |
| 482 | 485 |
| 483 // Check that 3rd and 4th result got added to the first result as dups | 486 // Check that 3rd and 4th result got added to the first result as dups |
| 484 // and also duplicates of the 4th match got copied. | 487 // and also duplicates of the 4th match got copied. |
| 485 ASSERT_EQ(4U, result.match_at(0)->duplicate_matches.size()); | 488 ASSERT_EQ(4U, result.match_at(0)->duplicate_matches.size()); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 516 { | 519 { |
| 517 std::map<std::string, std::string> params; | 520 std::map<std::string, std::string> params; |
| 518 params[std::string(OmniboxFieldTrial::kDemoteByTypeRule) + ":3:*"] = | 521 params[std::string(OmniboxFieldTrial::kDemoteByTypeRule) + ":3:*"] = |
| 519 "1:50,7:100,2:0"; // 3 == HOME_PAGE | 522 "1:50,7:100,2:0"; // 3 == HOME_PAGE |
| 520 ASSERT_TRUE(variations::AssociateVariationParams( | 523 ASSERT_TRUE(variations::AssociateVariationParams( |
| 521 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "A", params)); | 524 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "A", params)); |
| 522 } | 525 } |
| 523 base::FieldTrialList::CreateFieldTrial( | 526 base::FieldTrialList::CreateFieldTrial( |
| 524 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "A"); | 527 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "A"); |
| 525 | 528 |
| 526 AutocompleteInput input(base::string16(), base::string16::npos, std::string(), | 529 AutocompleteInput input(base::ASCIIToUTF16("a"), base::string16::npos, |
| 527 GURL(), OmniboxEventProto::HOME_PAGE, false, false, | 530 std::string(), GURL(), OmniboxEventProto::HOME_PAGE, |
| 528 false, true, false, TestSchemeClassifier()); | 531 false, false, false, true, false, |
| 532 TestSchemeClassifier()); |
| 529 AutocompleteResult result; | 533 AutocompleteResult result; |
| 530 result.AppendMatches(input, matches); | 534 result.AppendMatches(input, matches); |
| 531 result.SortAndCull(input, template_url_service_.get()); | 535 result.SortAndCull(input, template_url_service_.get()); |
| 532 | 536 |
| 533 // Check the new ordering. The history-title results should be omitted. | 537 // Check the new ordering. The history-title results should be omitted. |
| 534 // We cannot check relevance scores because the matches are sorted by | 538 // We cannot check relevance scores because the matches are sorted by |
| 535 // demoted relevance but the actual relevance scores are not modified. | 539 // demoted relevance but the actual relevance scores are not modified. |
| 536 ASSERT_EQ(3u, result.size()); | 540 ASSERT_EQ(3u, result.size()); |
| 537 EXPECT_EQ("http://search-what-you-typed/", | 541 EXPECT_EQ("http://search-what-you-typed/", |
| 538 result.match_at(0)->destination_url.spec()); | 542 result.match_at(0)->destination_url.spec()); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 561 params[std::string(OmniboxFieldTrial::kDemoteByTypeRule) + ":8:*"] = | 565 params[std::string(OmniboxFieldTrial::kDemoteByTypeRule) + ":8:*"] = |
| 562 "1:50"; // 8 == INSTANT_NTP_WITH_FAKEBOX_AS_STARTING_FOCUS | 566 "1:50"; // 8 == INSTANT_NTP_WITH_FAKEBOX_AS_STARTING_FOCUS |
| 563 ASSERT_TRUE(variations::AssociateVariationParams( | 567 ASSERT_TRUE(variations::AssociateVariationParams( |
| 564 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "C", params)); | 568 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "C", params)); |
| 565 } | 569 } |
| 566 base::FieldTrialList::CreateFieldTrial( | 570 base::FieldTrialList::CreateFieldTrial( |
| 567 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "C"); | 571 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "C"); |
| 568 | 572 |
| 569 { | 573 { |
| 570 AutocompleteInput input( | 574 AutocompleteInput input( |
| 571 base::string16(), base::string16::npos, std::string(), GURL(), | 575 base::ASCIIToUTF16("a"), base::string16::npos, std::string(), GURL(), |
| 572 OmniboxEventProto::INSTANT_NTP_WITH_FAKEBOX_AS_STARTING_FOCUS, false, | 576 OmniboxEventProto::INSTANT_NTP_WITH_FAKEBOX_AS_STARTING_FOCUS, false, |
| 573 false, false, true, false, TestSchemeClassifier()); | 577 false, false, true, false, TestSchemeClassifier()); |
| 574 AutocompleteResult result; | 578 AutocompleteResult result; |
| 575 result.AppendMatches(input, matches); | 579 result.AppendMatches(input, matches); |
| 576 result.SortAndCull(input, template_url_service_.get()); | 580 result.SortAndCull(input, template_url_service_.get()); |
| 577 | 581 |
| 578 // The NAVSUGGEST dup-url stay above search-url since the navsuggest | 582 // The NAVSUGGEST dup-url stay above search-url since the navsuggest |
| 579 // variant should not be demoted. | 583 // variant should not be demoted. |
| 580 ASSERT_EQ(4u, result.size()); | 584 ASSERT_EQ(4u, result.size()); |
| 581 EXPECT_EQ("http://search-what-you-typed/", | 585 EXPECT_EQ("http://search-what-you-typed/", |
| 582 result.match_at(0)->destination_url.spec()); | 586 result.match_at(0)->destination_url.spec()); |
| 583 EXPECT_EQ("http://dup-url/", | 587 EXPECT_EQ("http://dup-url/", |
| 584 result.match_at(1)->destination_url.spec()); | 588 result.match_at(1)->destination_url.spec()); |
| 585 EXPECT_EQ(AutocompleteMatchType::NAVSUGGEST, | 589 EXPECT_EQ(AutocompleteMatchType::NAVSUGGEST, |
| 586 result.match_at(1)->type); | 590 result.match_at(1)->type); |
| 587 EXPECT_EQ("http://search-url/", | 591 EXPECT_EQ("http://search-url/", |
| 588 result.match_at(2)->destination_url.spec()); | 592 result.match_at(2)->destination_url.spec()); |
| 589 EXPECT_EQ("http://history-url/", | 593 EXPECT_EQ("http://history-url/", |
| 590 result.match_at(3)->destination_url.spec()); | 594 result.match_at(3)->destination_url.spec()); |
| 591 } | 595 } |
| 592 } | 596 } |
| 593 | 597 |
| 594 TEST_F(AutocompleteResultTest, SortAndCullReorderForDefaultMatch) { | 598 TEST_F(AutocompleteResultTest, SortAndCullReorderForDefaultMatch) { |
| 595 TestData data[] = { | 599 TestData data[] = { |
| 596 { 0, 1, 1300, true }, | 600 { 0, 1, 1300, true }, |
| 597 { 1, 1, 1200, true }, | 601 { 1, 1, 1200, true }, |
| 598 { 2, 1, 1100, true }, | 602 { 2, 1, 1100, true }, |
| 599 { 3, 1, 1000, true } | 603 { 3, 1, 1000, true } |
| 600 }; | 604 }; |
| 605 TestSchemeClassifier test_scheme_classifier; |
| 601 | 606 |
| 602 { | 607 { |
| 603 // Check that reorder doesn't do anything if the top result | 608 // Check that reorder doesn't do anything if the top result |
| 604 // is already a legal default match (which is the default from | 609 // is already a legal default match (which is the default from |
| 605 // PopulateAutocompleteMatches()). | 610 // PopulateAutocompleteMatches()). |
| 606 ACMatches matches; | 611 ACMatches matches; |
| 607 PopulateAutocompleteMatches(data, arraysize(data), &matches); | 612 PopulateAutocompleteMatches(data, arraysize(data), &matches); |
| 608 AutocompleteInput input(base::string16(), base::string16::npos, | 613 AutocompleteInput input(base::ASCIIToUTF16("a"), base::string16::npos, |
| 609 std::string(), GURL(), OmniboxEventProto::HOME_PAGE, | 614 std::string(), GURL(), OmniboxEventProto::HOME_PAGE, |
| 610 false, false, false, true, false, | 615 false, false, false, true, false, |
| 611 TestSchemeClassifier()); | 616 test_scheme_classifier); |
| 612 AutocompleteResult result; | 617 AutocompleteResult result; |
| 613 result.AppendMatches(input, matches); | 618 result.AppendMatches(input, matches); |
| 614 result.SortAndCull(input, template_url_service_.get()); | 619 result.SortAndCull(input, template_url_service_.get()); |
| 615 AssertResultMatches(result, data, 4); | 620 AssertResultMatches(result, data, 4); |
| 616 } | 621 } |
| 617 | 622 |
| 618 { | 623 { |
| 619 // Check that reorder swaps up a result appropriately. | 624 // Check that reorder swaps up a result appropriately. |
| 620 ACMatches matches; | 625 ACMatches matches; |
| 621 PopulateAutocompleteMatches(data, arraysize(data), &matches); | 626 PopulateAutocompleteMatches(data, arraysize(data), &matches); |
| 622 matches[0].allowed_to_be_default_match = false; | 627 matches[0].allowed_to_be_default_match = false; |
| 623 matches[1].allowed_to_be_default_match = false; | 628 matches[1].allowed_to_be_default_match = false; |
| 624 AutocompleteInput input(base::string16(), base::string16::npos, | 629 AutocompleteInput input(base::ASCIIToUTF16("a"), base::string16::npos, |
| 625 std::string(), GURL(), OmniboxEventProto::HOME_PAGE, | 630 std::string(), GURL(), OmniboxEventProto::HOME_PAGE, |
| 626 false, false, false, true, false, | 631 false, false, false, true, false, |
| 627 TestSchemeClassifier()); | 632 test_scheme_classifier); |
| 628 AutocompleteResult result; | 633 AutocompleteResult result; |
| 629 result.AppendMatches(input, matches); | 634 result.AppendMatches(input, matches); |
| 630 result.SortAndCull(input, template_url_service_.get()); | 635 result.SortAndCull(input, template_url_service_.get()); |
| 631 ASSERT_EQ(4U, result.size()); | 636 ASSERT_EQ(4U, result.size()); |
| 632 EXPECT_EQ("http://c/", result.match_at(0)->destination_url.spec()); | 637 EXPECT_EQ("http://c/", result.match_at(0)->destination_url.spec()); |
| 633 EXPECT_EQ("http://a/", result.match_at(1)->destination_url.spec()); | 638 EXPECT_EQ("http://a/", result.match_at(1)->destination_url.spec()); |
| 634 EXPECT_EQ("http://b/", result.match_at(2)->destination_url.spec()); | 639 EXPECT_EQ("http://b/", result.match_at(2)->destination_url.spec()); |
| 635 EXPECT_EQ("http://d/", result.match_at(3)->destination_url.spec()); | 640 EXPECT_EQ("http://d/", result.match_at(3)->destination_url.spec()); |
| 636 } | 641 } |
| 637 } | 642 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 659 matches.clear(); | 664 matches.clear(); |
| 660 | 665 |
| 661 // Case 4: Standalone verbatim match found in AutocompleteResult. | 666 // Case 4: Standalone verbatim match found in AutocompleteResult. |
| 662 PopulateAutocompleteMatchesFromTestData(kVerbatimMatches, 1, &matches); | 667 PopulateAutocompleteMatchesFromTestData(kVerbatimMatches, 1, &matches); |
| 663 PopulateAutocompleteMatchesFromTestData(kNonVerbatimMatches, 1, &matches); | 668 PopulateAutocompleteMatchesFromTestData(kNonVerbatimMatches, 1, &matches); |
| 664 result.AppendMatches(AutocompleteInput(), matches); | 669 result.AppendMatches(AutocompleteInput(), matches); |
| 665 EXPECT_TRUE(result.TopMatchIsStandaloneVerbatimMatch()); | 670 EXPECT_TRUE(result.TopMatchIsStandaloneVerbatimMatch()); |
| 666 result.Reset(); | 671 result.Reset(); |
| 667 matches.clear(); | 672 matches.clear(); |
| 668 } | 673 } |
| OLD | NEW |