| 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 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 EXPECT_EQ(expected_match.destination_url.spec(), | 194 EXPECT_EQ(expected_match.destination_url.spec(), |
| 195 match.destination_url.spec()) << i; | 195 match.destination_url.spec()) << i; |
| 196 } | 196 } |
| 197 } | 197 } |
| 198 | 198 |
| 199 void AutocompleteResultTest::RunCopyOldMatchesTest( | 199 void AutocompleteResultTest::RunCopyOldMatchesTest( |
| 200 const TestData* last, size_t last_size, | 200 const TestData* last, size_t last_size, |
| 201 const TestData* current, size_t current_size, | 201 const TestData* current, size_t current_size, |
| 202 const TestData* expected, size_t expected_size) { | 202 const TestData* expected, size_t expected_size) { |
| 203 AutocompleteInput input(base::ASCIIToUTF16("a"), base::string16::npos, | 203 AutocompleteInput input(base::ASCIIToUTF16("a"), base::string16::npos, |
| 204 std::string(), GURL(), | 204 std::string(), GURL(), base::string16(), |
| 205 OmniboxEventProto::INVALID_SPEC, false, false, false, | 205 OmniboxEventProto::INVALID_SPEC, false, false, false, |
| 206 true, false, TestSchemeClassifier()); | 206 true, false, TestSchemeClassifier()); |
| 207 | 207 |
| 208 ACMatches last_matches; | 208 ACMatches last_matches; |
| 209 PopulateAutocompleteMatches(last, last_size, &last_matches); | 209 PopulateAutocompleteMatches(last, last_size, &last_matches); |
| 210 AutocompleteResult last_result; | 210 AutocompleteResult last_result; |
| 211 last_result.AppendMatches(input, last_matches); | 211 last_result.AppendMatches(input, last_matches); |
| 212 last_result.SortAndCull(input, template_url_service_.get()); | 212 last_result.SortAndCull(input, template_url_service_.get()); |
| 213 | 213 |
| 214 ACMatches current_matches; | 214 ACMatches current_matches; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 231 r1.Swap(&r2); | 231 r1.Swap(&r2); |
| 232 EXPECT_EQ(r1.end(), r1.default_match()); | 232 EXPECT_EQ(r1.end(), r1.default_match()); |
| 233 EXPECT_EQ(r2.end(), r2.default_match()); | 233 EXPECT_EQ(r2.end(), r2.default_match()); |
| 234 | 234 |
| 235 // Swap with a single match. | 235 // Swap with a single match. |
| 236 ACMatches matches; | 236 ACMatches matches; |
| 237 AutocompleteMatch match; | 237 AutocompleteMatch match; |
| 238 match.relevance = 1; | 238 match.relevance = 1; |
| 239 match.allowed_to_be_default_match = true; | 239 match.allowed_to_be_default_match = true; |
| 240 AutocompleteInput input(base::ASCIIToUTF16("a"), base::string16::npos, | 240 AutocompleteInput input(base::ASCIIToUTF16("a"), base::string16::npos, |
| 241 std::string(), GURL(), | 241 std::string(), GURL(), base::string16(), |
| 242 OmniboxEventProto::INVALID_SPEC, false, false, false, | 242 OmniboxEventProto::INVALID_SPEC, false, false, false, |
| 243 true, false, TestSchemeClassifier()); | 243 true, false, TestSchemeClassifier()); |
| 244 matches.push_back(match); | 244 matches.push_back(match); |
| 245 r1.AppendMatches(input, matches); | 245 r1.AppendMatches(input, matches); |
| 246 r1.SortAndCull(input, template_url_service_.get()); | 246 r1.SortAndCull(input, template_url_service_.get()); |
| 247 EXPECT_EQ(r1.begin(), r1.default_match()); | 247 EXPECT_EQ(r1.begin(), r1.default_match()); |
| 248 EXPECT_EQ("http://a/", r1.alternate_nav_url().spec()); | 248 EXPECT_EQ("http://a/", r1.alternate_nav_url().spec()); |
| 249 r1.Swap(&r2); | 249 r1.Swap(&r2); |
| 250 EXPECT_TRUE(r1.empty()); | 250 EXPECT_TRUE(r1.empty()); |
| 251 EXPECT_EQ(r1.end(), r1.default_match()); | 251 EXPECT_EQ(r1.end(), r1.default_match()); |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 369 { 0, 1, 1200, true }, | 369 { 0, 1, 1200, true }, |
| 370 }; | 370 }; |
| 371 | 371 |
| 372 ACMatches matches; | 372 ACMatches matches; |
| 373 PopulateAutocompleteMatches(data, arraysize(data), &matches); | 373 PopulateAutocompleteMatches(data, arraysize(data), &matches); |
| 374 matches[1].destination_url = GURL(); | 374 matches[1].destination_url = GURL(); |
| 375 matches[3].destination_url = GURL(); | 375 matches[3].destination_url = GURL(); |
| 376 matches[4].destination_url = GURL(); | 376 matches[4].destination_url = GURL(); |
| 377 | 377 |
| 378 AutocompleteInput input(base::ASCIIToUTF16("a"), base::string16::npos, | 378 AutocompleteInput input(base::ASCIIToUTF16("a"), base::string16::npos, |
| 379 std::string(), GURL(), | 379 std::string(), GURL(), base::string16(), |
| 380 OmniboxEventProto::INVALID_SPEC, false, false, false, | 380 OmniboxEventProto::INVALID_SPEC, false, false, false, |
| 381 true, false, TestSchemeClassifier()); | 381 true, false, TestSchemeClassifier()); |
| 382 AutocompleteResult result; | 382 AutocompleteResult result; |
| 383 result.AppendMatches(input, matches); | 383 result.AppendMatches(input, matches); |
| 384 result.SortAndCull(input, template_url_service_.get()); | 384 result.SortAndCull(input, template_url_service_.get()); |
| 385 | 385 |
| 386 // Of the two results with the same non-empty destination URL, the | 386 // Of the two results with the same non-empty destination URL, the |
| 387 // lower-relevance one should be dropped. All of the results with empty URLs | 387 // lower-relevance one should be dropped. All of the results with empty URLs |
| 388 // should be kept. | 388 // should be kept. |
| 389 ASSERT_EQ(4U, result.size()); | 389 ASSERT_EQ(4U, result.size()); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 415 | 415 |
| 416 ACMatches matches; | 416 ACMatches matches; |
| 417 PopulateAutocompleteMatches(data, arraysize(data), &matches); | 417 PopulateAutocompleteMatches(data, arraysize(data), &matches); |
| 418 matches[0].destination_url = GURL("http://www.foo.com/s?q=foo"); | 418 matches[0].destination_url = GURL("http://www.foo.com/s?q=foo"); |
| 419 matches[1].destination_url = GURL("http://www.foo.com/s?q=foo2"); | 419 matches[1].destination_url = GURL("http://www.foo.com/s?q=foo2"); |
| 420 matches[2].destination_url = GURL("http://www.foo.com/s?q=foo&oq=f"); | 420 matches[2].destination_url = GURL("http://www.foo.com/s?q=foo&oq=f"); |
| 421 matches[3].destination_url = GURL("http://www.foo.com/s?q=foo&aqs=0"); | 421 matches[3].destination_url = GURL("http://www.foo.com/s?q=foo&aqs=0"); |
| 422 matches[4].destination_url = GURL("http://www.foo.com/"); | 422 matches[4].destination_url = GURL("http://www.foo.com/"); |
| 423 | 423 |
| 424 AutocompleteInput input(base::ASCIIToUTF16("a"), base::string16::npos, | 424 AutocompleteInput input(base::ASCIIToUTF16("a"), base::string16::npos, |
| 425 std::string(), GURL(), | 425 std::string(), GURL(), base::string16(), |
| 426 OmniboxEventProto::INVALID_SPEC, false, false, false, | 426 OmniboxEventProto::INVALID_SPEC, false, false, false, |
| 427 true, false, TestSchemeClassifier()); | 427 true, false, TestSchemeClassifier()); |
| 428 AutocompleteResult result; | 428 AutocompleteResult result; |
| 429 result.AppendMatches(input, matches); | 429 result.AppendMatches(input, matches); |
| 430 result.SortAndCull(input, template_url_service_.get()); | 430 result.SortAndCull(input, template_url_service_.get()); |
| 431 | 431 |
| 432 // We expect the 3rd and 4th results to be removed. | 432 // We expect the 3rd and 4th results to be removed. |
| 433 ASSERT_EQ(3U, result.size()); | 433 ASSERT_EQ(3U, result.size()); |
| 434 EXPECT_EQ("http://www.foo.com/s?q=foo", | 434 EXPECT_EQ("http://www.foo.com/s?q=foo", |
| 435 result.match_at(0)->destination_url.spec()); | 435 result.match_at(0)->destination_url.spec()); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 467 ACMatches matches; | 467 ACMatches matches; |
| 468 PopulateAutocompleteMatches(data, arraysize(data), &matches); | 468 PopulateAutocompleteMatches(data, arraysize(data), &matches); |
| 469 matches[0].destination_url = GURL("http://www.foo.com/s?q=foo"); | 469 matches[0].destination_url = GURL("http://www.foo.com/s?q=foo"); |
| 470 matches[1].destination_url = GURL("http://www.foo.com/s?q=foo2"); | 470 matches[1].destination_url = GURL("http://www.foo.com/s?q=foo2"); |
| 471 matches[2].destination_url = GURL("http://www.foo.com/s?q=foo&oq=f"); | 471 matches[2].destination_url = GURL("http://www.foo.com/s?q=foo&oq=f"); |
| 472 matches[3].destination_url = GURL("http://www.foo.com/s?q=foo&aqs=0"); | 472 matches[3].destination_url = GURL("http://www.foo.com/s?q=foo&aqs=0"); |
| 473 matches[4].destination_url = GURL("http://www.foo.com/"); | 473 matches[4].destination_url = GURL("http://www.foo.com/"); |
| 474 matches[5].destination_url = GURL("http://www.foo.com/s?q=foo2&oq=f"); | 474 matches[5].destination_url = GURL("http://www.foo.com/s?q=foo2&oq=f"); |
| 475 | 475 |
| 476 AutocompleteInput input(base::ASCIIToUTF16("a"), base::string16::npos, | 476 AutocompleteInput input(base::ASCIIToUTF16("a"), base::string16::npos, |
| 477 std::string(), GURL(), | 477 std::string(), GURL(), base::string16(), |
| 478 OmniboxEventProto::INVALID_SPEC, false, false, false, | 478 OmniboxEventProto::INVALID_SPEC, false, false, false, |
| 479 true, false, TestSchemeClassifier()); | 479 true, false, TestSchemeClassifier()); |
| 480 AutocompleteResult result; | 480 AutocompleteResult result; |
| 481 result.AppendMatches(input, matches); | 481 result.AppendMatches(input, matches); |
| 482 result.SortAndCull(input, template_url_service_.get()); | 482 result.SortAndCull(input, template_url_service_.get()); |
| 483 | 483 |
| 484 // Expect 3 unique results after SortAndCull(). | 484 // Expect 3 unique results after SortAndCull(). |
| 485 ASSERT_EQ(3U, result.size()); | 485 ASSERT_EQ(3U, result.size()); |
| 486 | 486 |
| 487 // Check that 3rd and 4th result got added to the first result as dups | 487 // Check that 3rd and 4th result got added to the first result as dups |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 521 std::map<std::string, std::string> params; | 521 std::map<std::string, std::string> params; |
| 522 params[std::string(OmniboxFieldTrial::kDemoteByTypeRule) + ":3:*"] = | 522 params[std::string(OmniboxFieldTrial::kDemoteByTypeRule) + ":3:*"] = |
| 523 "1:50,7:100,2:0"; // 3 == HOME_PAGE | 523 "1:50,7:100,2:0"; // 3 == HOME_PAGE |
| 524 ASSERT_TRUE(variations::AssociateVariationParams( | 524 ASSERT_TRUE(variations::AssociateVariationParams( |
| 525 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "A", params)); | 525 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "A", params)); |
| 526 } | 526 } |
| 527 base::FieldTrialList::CreateFieldTrial( | 527 base::FieldTrialList::CreateFieldTrial( |
| 528 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "A"); | 528 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "A"); |
| 529 | 529 |
| 530 AutocompleteInput input(base::ASCIIToUTF16("a"), base::string16::npos, | 530 AutocompleteInput input(base::ASCIIToUTF16("a"), base::string16::npos, |
| 531 std::string(), GURL(), OmniboxEventProto::HOME_PAGE, | 531 std::string(), GURL(), base::string16(), |
| 532 false, false, false, true, false, | 532 OmniboxEventProto::HOME_PAGE, false, false, false, |
| 533 TestSchemeClassifier()); | 533 true, false, TestSchemeClassifier()); |
| 534 AutocompleteResult result; | 534 AutocompleteResult result; |
| 535 result.AppendMatches(input, matches); | 535 result.AppendMatches(input, matches); |
| 536 result.SortAndCull(input, template_url_service_.get()); | 536 result.SortAndCull(input, template_url_service_.get()); |
| 537 | 537 |
| 538 // Check the new ordering. The history-title results should be omitted. | 538 // Check the new ordering. The history-title results should be omitted. |
| 539 // We cannot check relevance scores because the matches are sorted by | 539 // We cannot check relevance scores because the matches are sorted by |
| 540 // demoted relevance but the actual relevance scores are not modified. | 540 // demoted relevance but the actual relevance scores are not modified. |
| 541 ASSERT_EQ(3u, result.size()); | 541 ASSERT_EQ(3u, result.size()); |
| 542 EXPECT_EQ("http://search-what-you-typed/", | 542 EXPECT_EQ("http://search-what-you-typed/", |
| 543 result.match_at(0)->destination_url.spec()); | 543 result.match_at(0)->destination_url.spec()); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 567 "1:50"; // 8 == INSTANT_NTP_WITH_FAKEBOX_AS_STARTING_FOCUS | 567 "1:50"; // 8 == INSTANT_NTP_WITH_FAKEBOX_AS_STARTING_FOCUS |
| 568 ASSERT_TRUE(variations::AssociateVariationParams( | 568 ASSERT_TRUE(variations::AssociateVariationParams( |
| 569 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "C", params)); | 569 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "C", params)); |
| 570 } | 570 } |
| 571 base::FieldTrialList::CreateFieldTrial( | 571 base::FieldTrialList::CreateFieldTrial( |
| 572 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "C"); | 572 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "C"); |
| 573 | 573 |
| 574 { | 574 { |
| 575 AutocompleteInput input( | 575 AutocompleteInput input( |
| 576 base::ASCIIToUTF16("a"), base::string16::npos, std::string(), GURL(), | 576 base::ASCIIToUTF16("a"), base::string16::npos, std::string(), GURL(), |
| 577 base::string16(), |
| 577 OmniboxEventProto::INSTANT_NTP_WITH_FAKEBOX_AS_STARTING_FOCUS, false, | 578 OmniboxEventProto::INSTANT_NTP_WITH_FAKEBOX_AS_STARTING_FOCUS, false, |
| 578 false, false, true, false, TestSchemeClassifier()); | 579 false, false, true, false, TestSchemeClassifier()); |
| 579 AutocompleteResult result; | 580 AutocompleteResult result; |
| 580 result.AppendMatches(input, matches); | 581 result.AppendMatches(input, matches); |
| 581 result.SortAndCull(input, template_url_service_.get()); | 582 result.SortAndCull(input, template_url_service_.get()); |
| 582 | 583 |
| 583 // The NAVSUGGEST dup-url stay above search-url since the navsuggest | 584 // The NAVSUGGEST dup-url stay above search-url since the navsuggest |
| 584 // variant should not be demoted. | 585 // variant should not be demoted. |
| 585 ASSERT_EQ(4u, result.size()); | 586 ASSERT_EQ(4u, result.size()); |
| 586 EXPECT_EQ("http://search-what-you-typed/", | 587 EXPECT_EQ("http://search-what-you-typed/", |
| (...skipping 18 matching lines...) Expand all Loading... |
| 605 }; | 606 }; |
| 606 TestSchemeClassifier test_scheme_classifier; | 607 TestSchemeClassifier test_scheme_classifier; |
| 607 | 608 |
| 608 { | 609 { |
| 609 // Check that reorder doesn't do anything if the top result | 610 // Check that reorder doesn't do anything if the top result |
| 610 // is already a legal default match (which is the default from | 611 // is already a legal default match (which is the default from |
| 611 // PopulateAutocompleteMatches()). | 612 // PopulateAutocompleteMatches()). |
| 612 ACMatches matches; | 613 ACMatches matches; |
| 613 PopulateAutocompleteMatches(data, arraysize(data), &matches); | 614 PopulateAutocompleteMatches(data, arraysize(data), &matches); |
| 614 AutocompleteInput input(base::ASCIIToUTF16("a"), base::string16::npos, | 615 AutocompleteInput input(base::ASCIIToUTF16("a"), base::string16::npos, |
| 615 std::string(), GURL(), OmniboxEventProto::HOME_PAGE, | 616 std::string(), GURL(), base::string16(), |
| 616 false, false, false, true, false, | 617 OmniboxEventProto::HOME_PAGE, false, false, false, |
| 617 test_scheme_classifier); | 618 true, false, test_scheme_classifier); |
| 618 AutocompleteResult result; | 619 AutocompleteResult result; |
| 619 result.AppendMatches(input, matches); | 620 result.AppendMatches(input, matches); |
| 620 result.SortAndCull(input, template_url_service_.get()); | 621 result.SortAndCull(input, template_url_service_.get()); |
| 621 AssertResultMatches(result, data, 4); | 622 AssertResultMatches(result, data, 4); |
| 622 } | 623 } |
| 623 | 624 |
| 624 { | 625 { |
| 625 // Check that reorder swaps up a result appropriately. | 626 // Check that reorder swaps up a result appropriately. |
| 626 ACMatches matches; | 627 ACMatches matches; |
| 627 PopulateAutocompleteMatches(data, arraysize(data), &matches); | 628 PopulateAutocompleteMatches(data, arraysize(data), &matches); |
| 628 matches[0].allowed_to_be_default_match = false; | 629 matches[0].allowed_to_be_default_match = false; |
| 629 matches[1].allowed_to_be_default_match = false; | 630 matches[1].allowed_to_be_default_match = false; |
| 630 AutocompleteInput input(base::ASCIIToUTF16("a"), base::string16::npos, | 631 AutocompleteInput input(base::ASCIIToUTF16("a"), base::string16::npos, |
| 631 std::string(), GURL(), OmniboxEventProto::HOME_PAGE, | 632 std::string(), GURL(), base::string16(), |
| 632 false, false, false, true, false, | 633 OmniboxEventProto::HOME_PAGE, false, false, false, |
| 633 test_scheme_classifier); | 634 true, false, test_scheme_classifier); |
| 634 AutocompleteResult result; | 635 AutocompleteResult result; |
| 635 result.AppendMatches(input, matches); | 636 result.AppendMatches(input, matches); |
| 636 result.SortAndCull(input, template_url_service_.get()); | 637 result.SortAndCull(input, template_url_service_.get()); |
| 637 ASSERT_EQ(4U, result.size()); | 638 ASSERT_EQ(4U, result.size()); |
| 638 EXPECT_EQ("http://c/", result.match_at(0)->destination_url.spec()); | 639 EXPECT_EQ("http://c/", result.match_at(0)->destination_url.spec()); |
| 639 EXPECT_EQ("http://a/", result.match_at(1)->destination_url.spec()); | 640 EXPECT_EQ("http://a/", result.match_at(1)->destination_url.spec()); |
| 640 EXPECT_EQ("http://b/", result.match_at(2)->destination_url.spec()); | 641 EXPECT_EQ("http://b/", result.match_at(2)->destination_url.spec()); |
| 641 EXPECT_EQ("http://d/", result.match_at(3)->destination_url.spec()); | 642 EXPECT_EQ("http://d/", result.match_at(3)->destination_url.spec()); |
| 642 } | 643 } |
| 643 } | 644 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 665 matches.clear(); | 666 matches.clear(); |
| 666 | 667 |
| 667 // Case 4: Standalone verbatim match found in AutocompleteResult. | 668 // Case 4: Standalone verbatim match found in AutocompleteResult. |
| 668 PopulateAutocompleteMatchesFromTestData(kVerbatimMatches, 1, &matches); | 669 PopulateAutocompleteMatchesFromTestData(kVerbatimMatches, 1, &matches); |
| 669 PopulateAutocompleteMatchesFromTestData(kNonVerbatimMatches, 1, &matches); | 670 PopulateAutocompleteMatchesFromTestData(kNonVerbatimMatches, 1, &matches); |
| 670 result.AppendMatches(AutocompleteInput(), matches); | 671 result.AppendMatches(AutocompleteInput(), matches); |
| 671 EXPECT_TRUE(result.TopMatchIsStandaloneVerbatimMatch()); | 672 EXPECT_TRUE(result.TopMatchIsStandaloneVerbatimMatch()); |
| 672 result.Reset(); | 673 result.Reset(); |
| 673 matches.clear(); | 674 matches.clear(); |
| 674 } | 675 } |
| OLD | NEW |