| 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 OmniboxEventProto::INVALID_SPEC, false, false, |
| 379 false, true, false, TestSchemeClassifier()); | 380 false, 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()); |
| (...skipping 23 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(), |
| 425 OmniboxEventProto::INVALID_SPEC, false, false, |
| 424 false, true, false, TestSchemeClassifier()); | 426 false, 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); |
| (...skipping 29 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(), |
| 477 OmniboxEventProto::INVALID_SPEC, false, false, |
| 475 false, true, false, TestSchemeClassifier()); | 478 false, 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. |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after 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(), |
| 531 OmniboxEventProto::INVALID_SPEC, false, false, |
| 528 false, true, false, TestSchemeClassifier()); | 532 false, true, false, 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/", |
| (...skipping 23 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/", |
| (...skipping 16 matching lines...) Expand all Loading... |
| 598 { 2, 1, 1100, true }, | 602 { 2, 1, 1100, true }, |
| 599 { 3, 1, 1000, true } | 603 { 3, 1, 1000, true } |
| 600 }; | 604 }; |
| 601 | 605 |
| 602 { | 606 { |
| 603 // Check that reorder doesn't do anything if the top result | 607 // Check that reorder doesn't do anything if the top result |
| 604 // is already a legal default match (which is the default from | 608 // is already a legal default match (which is the default from |
| 605 // PopulateAutocompleteMatches()). | 609 // PopulateAutocompleteMatches()). |
| 606 ACMatches matches; | 610 ACMatches matches; |
| 607 PopulateAutocompleteMatches(data, arraysize(data), &matches); | 611 PopulateAutocompleteMatches(data, arraysize(data), &matches); |
| 608 AutocompleteInput input(base::string16(), base::string16::npos, | 612 AutocompleteInput input(base::ASCIIToUTF16("a"), base::string16::npos, |
| 609 std::string(), GURL(), OmniboxEventProto::HOME_PAGE, | 613 std::string(), GURL(), OmniboxEventProto::HOME_PAGE, |
| 610 false, false, false, true, false, | 614 false, false, false, true, false, |
| 611 TestSchemeClassifier()); | 615 TestSchemeClassifier()); |
| 612 AutocompleteResult result; | 616 AutocompleteResult result; |
| 613 result.AppendMatches(input, matches); | 617 result.AppendMatches(input, matches); |
| 614 result.SortAndCull(input, template_url_service_.get()); | 618 result.SortAndCull(input, template_url_service_.get()); |
| 615 AssertResultMatches(result, data, 4); | 619 AssertResultMatches(result, data, 4); |
| 616 } | 620 } |
| 617 | 621 |
| 618 { | 622 { |
| 619 // Check that reorder swaps up a result appropriately. | 623 // Check that reorder swaps up a result appropriately. |
| 620 ACMatches matches; | 624 ACMatches matches; |
| 621 PopulateAutocompleteMatches(data, arraysize(data), &matches); | 625 PopulateAutocompleteMatches(data, arraysize(data), &matches); |
| 622 matches[0].allowed_to_be_default_match = false; | 626 matches[0].allowed_to_be_default_match = false; |
| 623 matches[1].allowed_to_be_default_match = false; | 627 matches[1].allowed_to_be_default_match = false; |
| 624 AutocompleteInput input(base::string16(), base::string16::npos, | 628 AutocompleteInput input(base::ASCIIToUTF16("a"), base::string16::npos, |
| 625 std::string(), GURL(), OmniboxEventProto::HOME_PAGE, | 629 std::string(), GURL(), OmniboxEventProto::HOME_PAGE, |
| 626 false, false, false, true, false, | 630 false, false, false, true, false, |
| 627 TestSchemeClassifier()); | 631 TestSchemeClassifier()); |
| 628 AutocompleteResult result; | 632 AutocompleteResult result; |
| 629 result.AppendMatches(input, matches); | 633 result.AppendMatches(input, matches); |
| 630 result.SortAndCull(input, template_url_service_.get()); | 634 result.SortAndCull(input, template_url_service_.get()); |
| 631 ASSERT_EQ(4U, result.size()); | 635 ASSERT_EQ(4U, result.size()); |
| 632 EXPECT_EQ("http://c/", result.match_at(0)->destination_url.spec()); | 636 EXPECT_EQ("http://c/", result.match_at(0)->destination_url.spec()); |
| 633 EXPECT_EQ("http://a/", result.match_at(1)->destination_url.spec()); | 637 EXPECT_EQ("http://a/", result.match_at(1)->destination_url.spec()); |
| 634 EXPECT_EQ("http://b/", result.match_at(2)->destination_url.spec()); | 638 EXPECT_EQ("http://b/", result.match_at(2)->destination_url.spec()); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 659 matches.clear(); | 663 matches.clear(); |
| 660 | 664 |
| 661 // Case 4: Standalone verbatim match found in AutocompleteResult. | 665 // Case 4: Standalone verbatim match found in AutocompleteResult. |
| 662 PopulateAutocompleteMatchesFromTestData(kVerbatimMatches, 1, &matches); | 666 PopulateAutocompleteMatchesFromTestData(kVerbatimMatches, 1, &matches); |
| 663 PopulateAutocompleteMatchesFromTestData(kNonVerbatimMatches, 1, &matches); | 667 PopulateAutocompleteMatchesFromTestData(kNonVerbatimMatches, 1, &matches); |
| 664 result.AppendMatches(AutocompleteInput(), matches); | 668 result.AppendMatches(AutocompleteInput(), matches); |
| 665 EXPECT_TRUE(result.TopMatchIsStandaloneVerbatimMatch()); | 669 EXPECT_TRUE(result.TopMatchIsStandaloneVerbatimMatch()); |
| 666 result.Reset(); | 670 result.Reset(); |
| 667 matches.clear(); | 671 matches.clear(); |
| 668 } | 672 } |
| OLD | NEW |