| OLD | NEW |
| 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/autocomplete_result.h" | 5 #include "chrome/browser/autocomplete/autocomplete_result.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/metrics/field_trial.h" | 10 #include "base/metrics/field_trial.h" |
| 11 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
| 12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 14 #include "chrome/browser/autocomplete/autocomplete_input.h" | 14 #include "chrome/browser/autocomplete/autocomplete_input.h" |
| 15 #include "chrome/browser/autocomplete/autocomplete_match.h" | 15 #include "chrome/browser/autocomplete/autocomplete_match.h" |
| 16 #include "chrome/browser/autocomplete/autocomplete_provider.h" | 16 #include "chrome/browser/autocomplete/autocomplete_provider.h" |
| 17 #include "chrome/browser/omnibox/omnibox_field_trial.h" | 17 #include "chrome/browser/omnibox/omnibox_field_trial.h" |
| 18 #include "chrome/browser/search_engines/template_url_prepopulate_data.h" | 18 #include "chrome/browser/search_engines/template_url_prepopulate_data.h" |
| 19 #include "chrome/browser/search_engines/template_url_service.h" | 19 #include "chrome/browser/search_engines/template_url_service.h" |
| 20 #include "chrome/browser/search_engines/template_url_service_test_util.h" | 20 #include "chrome/browser/search_engines/template_url_service_test_util.h" |
| 21 #include "chrome/common/autocomplete_match_type.h" | 21 #include "chrome/common/autocomplete_match_type.h" |
| 22 #include "chrome/test/base/testing_profile.h" | 22 #include "chrome/test/base/testing_profile.h" |
| 23 #include "components/variations/entropy_provider.h" | 23 #include "components/variations/entropy_provider.h" |
| 24 #include "components/variations/variations_associated_data.h" | 24 #include "components/variations/variations_associated_data.h" |
| 25 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
| 26 | 26 |
| 27 using metrics::OmniboxEventProto; |
| 28 |
| 27 namespace { | 29 namespace { |
| 28 | 30 |
| 29 struct AutocompleteMatchTestData { | 31 struct AutocompleteMatchTestData { |
| 30 std::string destination_url; | 32 std::string destination_url; |
| 31 AutocompleteMatch::Type type; | 33 AutocompleteMatch::Type type; |
| 32 }; | 34 }; |
| 33 | 35 |
| 34 const AutocompleteMatchTestData kVerbatimMatches[] = { | 36 const AutocompleteMatchTestData kVerbatimMatches[] = { |
| 35 { "http://search-what-you-typed/", | 37 { "http://search-what-you-typed/", |
| 36 AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED }, | 38 AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED }, |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 match.destination_url.spec()) << i; | 171 match.destination_url.spec()) << i; |
| 170 } | 172 } |
| 171 } | 173 } |
| 172 | 174 |
| 173 void AutocompleteResultTest::RunCopyOldMatchesTest( | 175 void AutocompleteResultTest::RunCopyOldMatchesTest( |
| 174 const TestData* last, size_t last_size, | 176 const TestData* last, size_t last_size, |
| 175 const TestData* current, size_t current_size, | 177 const TestData* current, size_t current_size, |
| 176 const TestData* expected, size_t expected_size) { | 178 const TestData* expected, size_t expected_size) { |
| 177 AutocompleteInput input(base::ASCIIToUTF16("a"), base::string16::npos, | 179 AutocompleteInput input(base::ASCIIToUTF16("a"), base::string16::npos, |
| 178 base::string16(), GURL(), | 180 base::string16(), GURL(), |
| 179 AutocompleteInput::INVALID_SPEC, false, false, false, | 181 OmniboxEventProto::INVALID_SPEC, false, false, false, |
| 180 true); | 182 true); |
| 181 | 183 |
| 182 ACMatches last_matches; | 184 ACMatches last_matches; |
| 183 PopulateAutocompleteMatches(last, last_size, &last_matches); | 185 PopulateAutocompleteMatches(last, last_size, &last_matches); |
| 184 AutocompleteResult last_result; | 186 AutocompleteResult last_result; |
| 185 last_result.AppendMatches(last_matches); | 187 last_result.AppendMatches(last_matches); |
| 186 last_result.SortAndCull(input, test_util_.profile()); | 188 last_result.SortAndCull(input, test_util_.profile()); |
| 187 | 189 |
| 188 ACMatches current_matches; | 190 ACMatches current_matches; |
| 189 PopulateAutocompleteMatches(current, current_size, ¤t_matches); | 191 PopulateAutocompleteMatches(current, current_size, ¤t_matches); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 205 EXPECT_EQ(r1.end(), r1.default_match()); | 207 EXPECT_EQ(r1.end(), r1.default_match()); |
| 206 EXPECT_EQ(r2.end(), r2.default_match()); | 208 EXPECT_EQ(r2.end(), r2.default_match()); |
| 207 | 209 |
| 208 // Swap with a single match. | 210 // Swap with a single match. |
| 209 ACMatches matches; | 211 ACMatches matches; |
| 210 AutocompleteMatch match; | 212 AutocompleteMatch match; |
| 211 match.relevance = 1; | 213 match.relevance = 1; |
| 212 match.allowed_to_be_default_match = true; | 214 match.allowed_to_be_default_match = true; |
| 213 AutocompleteInput input(base::ASCIIToUTF16("a"), base::string16::npos, | 215 AutocompleteInput input(base::ASCIIToUTF16("a"), base::string16::npos, |
| 214 base::string16(), GURL(), | 216 base::string16(), GURL(), |
| 215 AutocompleteInput::INVALID_SPEC, false, false, false, | 217 OmniboxEventProto::INVALID_SPEC, false, false, false, |
| 216 true); | 218 true); |
| 217 matches.push_back(match); | 219 matches.push_back(match); |
| 218 r1.AppendMatches(matches); | 220 r1.AppendMatches(matches); |
| 219 r1.SortAndCull(input, test_util_.profile()); | 221 r1.SortAndCull(input, test_util_.profile()); |
| 220 EXPECT_EQ(r1.begin(), r1.default_match()); | 222 EXPECT_EQ(r1.begin(), r1.default_match()); |
| 221 EXPECT_EQ("http://a/", r1.alternate_nav_url().spec()); | 223 EXPECT_EQ("http://a/", r1.alternate_nav_url().spec()); |
| 222 r1.Swap(&r2); | 224 r1.Swap(&r2); |
| 223 EXPECT_TRUE(r1.empty()); | 225 EXPECT_TRUE(r1.empty()); |
| 224 EXPECT_EQ(r1.end(), r1.default_match()); | 226 EXPECT_EQ(r1.end(), r1.default_match()); |
| 225 EXPECT_TRUE(r1.alternate_nav_url().is_empty()); | 227 EXPECT_TRUE(r1.alternate_nav_url().is_empty()); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 ACMatches matches; | 290 ACMatches matches; |
| 289 PopulateAutocompleteMatches(data, arraysize(data), &matches); | 291 PopulateAutocompleteMatches(data, arraysize(data), &matches); |
| 290 matches[1].destination_url = GURL(); | 292 matches[1].destination_url = GURL(); |
| 291 matches[3].destination_url = GURL(); | 293 matches[3].destination_url = GURL(); |
| 292 matches[4].destination_url = GURL(); | 294 matches[4].destination_url = GURL(); |
| 293 | 295 |
| 294 AutocompleteResult result; | 296 AutocompleteResult result; |
| 295 result.AppendMatches(matches); | 297 result.AppendMatches(matches); |
| 296 AutocompleteInput input(base::string16(), base::string16::npos, | 298 AutocompleteInput input(base::string16(), base::string16::npos, |
| 297 base::string16(), GURL(), | 299 base::string16(), GURL(), |
| 298 AutocompleteInput::INVALID_SPEC, false, false, false, | 300 OmniboxEventProto::INVALID_SPEC, false, false, false, |
| 299 true); | 301 true); |
| 300 result.SortAndCull(input, test_util_.profile()); | 302 result.SortAndCull(input, test_util_.profile()); |
| 301 | 303 |
| 302 // Of the two results with the same non-empty destination URL, the | 304 // Of the two results with the same non-empty destination URL, the |
| 303 // lower-relevance one should be dropped. All of the results with empty URLs | 305 // lower-relevance one should be dropped. All of the results with empty URLs |
| 304 // should be kept. | 306 // should be kept. |
| 305 ASSERT_EQ(4U, result.size()); | 307 ASSERT_EQ(4U, result.size()); |
| 306 EXPECT_TRUE(result.match_at(0)->destination_url.is_empty()); | 308 EXPECT_TRUE(result.match_at(0)->destination_url.is_empty()); |
| 307 EXPECT_EQ(1300, result.match_at(0)->relevance); | 309 EXPECT_EQ(1300, result.match_at(0)->relevance); |
| 308 EXPECT_TRUE(result.match_at(1)->destination_url.is_empty()); | 310 EXPECT_TRUE(result.match_at(1)->destination_url.is_empty()); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 334 matches[0].destination_url = GURL("http://www.foo.com/s?q=foo"); | 336 matches[0].destination_url = GURL("http://www.foo.com/s?q=foo"); |
| 335 matches[1].destination_url = GURL("http://www.foo.com/s?q=foo2"); | 337 matches[1].destination_url = GURL("http://www.foo.com/s?q=foo2"); |
| 336 matches[2].destination_url = GURL("http://www.foo.com/s?q=foo&oq=f"); | 338 matches[2].destination_url = GURL("http://www.foo.com/s?q=foo&oq=f"); |
| 337 matches[3].destination_url = GURL("http://www.foo.com/s?q=foo&aqs=0"); | 339 matches[3].destination_url = GURL("http://www.foo.com/s?q=foo&aqs=0"); |
| 338 matches[4].destination_url = GURL("http://www.foo.com/"); | 340 matches[4].destination_url = GURL("http://www.foo.com/"); |
| 339 | 341 |
| 340 AutocompleteResult result; | 342 AutocompleteResult result; |
| 341 result.AppendMatches(matches); | 343 result.AppendMatches(matches); |
| 342 AutocompleteInput input(base::string16(), base::string16::npos, | 344 AutocompleteInput input(base::string16(), base::string16::npos, |
| 343 base::string16(), GURL(), | 345 base::string16(), GURL(), |
| 344 AutocompleteInput::INVALID_SPEC, false, false, false, | 346 OmniboxEventProto::INVALID_SPEC, false, false, false, |
| 345 true); | 347 true); |
| 346 result.SortAndCull(input, test_util_.profile()); | 348 result.SortAndCull(input, test_util_.profile()); |
| 347 | 349 |
| 348 // We expect the 3rd and 4th results to be removed. | 350 // We expect the 3rd and 4th results to be removed. |
| 349 ASSERT_EQ(3U, result.size()); | 351 ASSERT_EQ(3U, result.size()); |
| 350 EXPECT_EQ("http://www.foo.com/s?q=foo", | 352 EXPECT_EQ("http://www.foo.com/s?q=foo", |
| 351 result.match_at(0)->destination_url.spec()); | 353 result.match_at(0)->destination_url.spec()); |
| 352 EXPECT_EQ(1300, result.match_at(0)->relevance); | 354 EXPECT_EQ(1300, result.match_at(0)->relevance); |
| 353 EXPECT_EQ("http://www.foo.com/s?q=foo2", | 355 EXPECT_EQ("http://www.foo.com/s?q=foo2", |
| 354 result.match_at(1)->destination_url.spec()); | 356 result.match_at(1)->destination_url.spec()); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 386 matches[1].destination_url = GURL("http://www.foo.com/s?q=foo2"); | 388 matches[1].destination_url = GURL("http://www.foo.com/s?q=foo2"); |
| 387 matches[2].destination_url = GURL("http://www.foo.com/s?q=foo&oq=f"); | 389 matches[2].destination_url = GURL("http://www.foo.com/s?q=foo&oq=f"); |
| 388 matches[3].destination_url = GURL("http://www.foo.com/s?q=foo&aqs=0"); | 390 matches[3].destination_url = GURL("http://www.foo.com/s?q=foo&aqs=0"); |
| 389 matches[4].destination_url = GURL("http://www.foo.com/"); | 391 matches[4].destination_url = GURL("http://www.foo.com/"); |
| 390 matches[5].destination_url = GURL("http://www.foo.com/s?q=foo2&oq=f"); | 392 matches[5].destination_url = GURL("http://www.foo.com/s?q=foo2&oq=f"); |
| 391 | 393 |
| 392 AutocompleteResult result; | 394 AutocompleteResult result; |
| 393 result.AppendMatches(matches); | 395 result.AppendMatches(matches); |
| 394 AutocompleteInput input(base::string16(), base::string16::npos, | 396 AutocompleteInput input(base::string16(), base::string16::npos, |
| 395 base::string16(), GURL(), | 397 base::string16(), GURL(), |
| 396 AutocompleteInput::INVALID_SPEC, false, false, false, | 398 OmniboxEventProto::INVALID_SPEC, false, false, false, |
| 397 true); | 399 true); |
| 398 result.SortAndCull(input, test_util_.profile()); | 400 result.SortAndCull(input, test_util_.profile()); |
| 399 | 401 |
| 400 // Expect 3 unique results after SortAndCull(). | 402 // Expect 3 unique results after SortAndCull(). |
| 401 ASSERT_EQ(3U, result.size()); | 403 ASSERT_EQ(3U, result.size()); |
| 402 | 404 |
| 403 // Check that 3rd and 4th result got added to the first result as dups | 405 // Check that 3rd and 4th result got added to the first result as dups |
| 404 // and also duplicates of the 4th match got copied. | 406 // and also duplicates of the 4th match got copied. |
| 405 ASSERT_EQ(4U, result.match_at(0)->duplicate_matches.size()); | 407 ASSERT_EQ(4U, result.match_at(0)->duplicate_matches.size()); |
| 406 const AutocompleteMatch* first_match = result.match_at(0); | 408 const AutocompleteMatch* first_match = result.match_at(0); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 440 ASSERT_TRUE(chrome_variations::AssociateVariationParams( | 442 ASSERT_TRUE(chrome_variations::AssociateVariationParams( |
| 441 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "A", params)); | 443 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "A", params)); |
| 442 } | 444 } |
| 443 base::FieldTrialList::CreateFieldTrial( | 445 base::FieldTrialList::CreateFieldTrial( |
| 444 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "A"); | 446 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "A"); |
| 445 | 447 |
| 446 AutocompleteResult result; | 448 AutocompleteResult result; |
| 447 result.AppendMatches(matches); | 449 result.AppendMatches(matches); |
| 448 AutocompleteInput input(base::string16(), base::string16::npos, | 450 AutocompleteInput input(base::string16(), base::string16::npos, |
| 449 base::string16(), GURL(), | 451 base::string16(), GURL(), |
| 450 AutocompleteInput::HOME_PAGE, false, false, false, | 452 OmniboxEventProto::HOME_PAGE, false, false, false, |
| 451 true); | 453 true); |
| 452 result.SortAndCull(input, test_util_.profile()); | 454 result.SortAndCull(input, test_util_.profile()); |
| 453 | 455 |
| 454 // Check the new ordering. The history-title results should be omitted. | 456 // Check the new ordering. The history-title results should be omitted. |
| 455 // We cannot check relevance scores because the matches are sorted by | 457 // We cannot check relevance scores because the matches are sorted by |
| 456 // demoted relevance but the actual relevance scores are not modified. | 458 // demoted relevance but the actual relevance scores are not modified. |
| 457 ASSERT_EQ(3u, result.size()); | 459 ASSERT_EQ(3u, result.size()); |
| 458 EXPECT_EQ("http://search-what-you-typed/", | 460 EXPECT_EQ("http://search-what-you-typed/", |
| 459 result.match_at(0)->destination_url.spec()); | 461 result.match_at(0)->destination_url.spec()); |
| 460 EXPECT_EQ("http://history-url/", | 462 EXPECT_EQ("http://history-url/", |
| (...skipping 24 matching lines...) Expand all Loading... |
| 485 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "C", params)); | 487 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "C", params)); |
| 486 } | 488 } |
| 487 base::FieldTrialList::CreateFieldTrial( | 489 base::FieldTrialList::CreateFieldTrial( |
| 488 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "C"); | 490 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "C"); |
| 489 | 491 |
| 490 { | 492 { |
| 491 AutocompleteResult result; | 493 AutocompleteResult result; |
| 492 result.AppendMatches(matches); | 494 result.AppendMatches(matches); |
| 493 AutocompleteInput input( | 495 AutocompleteInput input( |
| 494 base::string16(), base::string16::npos, base::string16(), GURL(), | 496 base::string16(), base::string16::npos, base::string16(), GURL(), |
| 495 AutocompleteInput::INSTANT_NTP_WITH_FAKEBOX_AS_STARTING_FOCUS, false, | 497 OmniboxEventProto::INSTANT_NTP_WITH_FAKEBOX_AS_STARTING_FOCUS, false, |
| 496 false, false, true); | 498 false, false, true); |
| 497 result.SortAndCull(input, test_util_.profile()); | 499 result.SortAndCull(input, test_util_.profile()); |
| 498 | 500 |
| 499 // The NAVSUGGEST dup-url stay above search-url since the navsuggest | 501 // The NAVSUGGEST dup-url stay above search-url since the navsuggest |
| 500 // variant should not be demoted. | 502 // variant should not be demoted. |
| 501 ASSERT_EQ(4u, result.size()); | 503 ASSERT_EQ(4u, result.size()); |
| 502 EXPECT_EQ("http://search-what-you-typed/", | 504 EXPECT_EQ("http://search-what-you-typed/", |
| 503 result.match_at(0)->destination_url.spec()); | 505 result.match_at(0)->destination_url.spec()); |
| 504 EXPECT_EQ("http://dup-url/", | 506 EXPECT_EQ("http://dup-url/", |
| 505 result.match_at(1)->destination_url.spec()); | 507 result.match_at(1)->destination_url.spec()); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 523 { | 525 { |
| 524 // Check that reorder doesn't do anything if the top result | 526 // Check that reorder doesn't do anything if the top result |
| 525 // is already a legal default match (which is the default from | 527 // is already a legal default match (which is the default from |
| 526 // PopulateAutocompleteMatches()). | 528 // PopulateAutocompleteMatches()). |
| 527 ACMatches matches; | 529 ACMatches matches; |
| 528 PopulateAutocompleteMatches(data, arraysize(data), &matches); | 530 PopulateAutocompleteMatches(data, arraysize(data), &matches); |
| 529 AutocompleteResult result; | 531 AutocompleteResult result; |
| 530 result.AppendMatches(matches); | 532 result.AppendMatches(matches); |
| 531 AutocompleteInput input(base::string16(), base::string16::npos, | 533 AutocompleteInput input(base::string16(), base::string16::npos, |
| 532 base::string16(), GURL(), | 534 base::string16(), GURL(), |
| 533 AutocompleteInput::HOME_PAGE, false, false, false, | 535 OmniboxEventProto::HOME_PAGE, false, false, false, |
| 534 true); | 536 true); |
| 535 result.SortAndCull(input, test_util_.profile()); | 537 result.SortAndCull(input, test_util_.profile()); |
| 536 AssertResultMatches(result, data, 4); | 538 AssertResultMatches(result, data, 4); |
| 537 } | 539 } |
| 538 | 540 |
| 539 { | 541 { |
| 540 // Check that reorder swaps up a result appropriately. | 542 // Check that reorder swaps up a result appropriately. |
| 541 ACMatches matches; | 543 ACMatches matches; |
| 542 PopulateAutocompleteMatches(data, arraysize(data), &matches); | 544 PopulateAutocompleteMatches(data, arraysize(data), &matches); |
| 543 matches[0].allowed_to_be_default_match = false; | 545 matches[0].allowed_to_be_default_match = false; |
| 544 matches[1].allowed_to_be_default_match = false; | 546 matches[1].allowed_to_be_default_match = false; |
| 545 AutocompleteResult result; | 547 AutocompleteResult result; |
| 546 result.AppendMatches(matches); | 548 result.AppendMatches(matches); |
| 547 AutocompleteInput input(base::string16(), base::string16::npos, | 549 AutocompleteInput input(base::string16(), base::string16::npos, |
| 548 base::string16(), GURL(), | 550 base::string16(), GURL(), |
| 549 AutocompleteInput::HOME_PAGE, false, false, false, | 551 OmniboxEventProto::HOME_PAGE, false, false, false, |
| 550 true); | 552 true); |
| 551 result.SortAndCull(input, test_util_.profile()); | 553 result.SortAndCull(input, test_util_.profile()); |
| 552 ASSERT_EQ(4U, result.size()); | 554 ASSERT_EQ(4U, result.size()); |
| 553 EXPECT_EQ("http://c/", result.match_at(0)->destination_url.spec()); | 555 EXPECT_EQ("http://c/", result.match_at(0)->destination_url.spec()); |
| 554 EXPECT_EQ("http://a/", result.match_at(1)->destination_url.spec()); | 556 EXPECT_EQ("http://a/", result.match_at(1)->destination_url.spec()); |
| 555 EXPECT_EQ("http://b/", result.match_at(2)->destination_url.spec()); | 557 EXPECT_EQ("http://b/", result.match_at(2)->destination_url.spec()); |
| 556 EXPECT_EQ("http://d/", result.match_at(3)->destination_url.spec()); | 558 EXPECT_EQ("http://d/", result.match_at(3)->destination_url.spec()); |
| 557 } | 559 } |
| 558 } | 560 } |
| 559 | 561 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 570 { | 572 { |
| 571 // Check that with the field trial disabled, we keep keep the first match | 573 // Check that with the field trial disabled, we keep keep the first match |
| 572 // first even if it has an inline autocompletion. | 574 // first even if it has an inline autocompletion. |
| 573 ACMatches matches; | 575 ACMatches matches; |
| 574 PopulateAutocompleteMatches(data, arraysize(data), &matches); | 576 PopulateAutocompleteMatches(data, arraysize(data), &matches); |
| 575 matches[0].inline_autocompletion = base::ASCIIToUTF16("completion"); | 577 matches[0].inline_autocompletion = base::ASCIIToUTF16("completion"); |
| 576 AutocompleteResult result; | 578 AutocompleteResult result; |
| 577 result.AppendMatches(matches); | 579 result.AppendMatches(matches); |
| 578 AutocompleteInput input(base::string16(), base::string16::npos, | 580 AutocompleteInput input(base::string16(), base::string16::npos, |
| 579 base::string16(), GURL(), | 581 base::string16(), GURL(), |
| 580 AutocompleteInput::HOME_PAGE, false, false, false, | 582 OmniboxEventProto::HOME_PAGE, false, false, false, |
| 581 true); | 583 true); |
| 582 result.SortAndCull(input, test_util_.profile()); | 584 result.SortAndCull(input, test_util_.profile()); |
| 583 AssertResultMatches(result, data, 4); | 585 AssertResultMatches(result, data, 4); |
| 584 } | 586 } |
| 585 | 587 |
| 586 // Enable the field trial to disable inlining. | 588 // Enable the field trial to disable inlining. |
| 587 { | 589 { |
| 588 std::map<std::string, std::string> params; | 590 std::map<std::string, std::string> params; |
| 589 params[OmniboxFieldTrial::kDisableInliningRule] = "true"; | 591 params[OmniboxFieldTrial::kDisableInliningRule] = "true"; |
| 590 ASSERT_TRUE(chrome_variations::AssociateVariationParams( | 592 ASSERT_TRUE(chrome_variations::AssociateVariationParams( |
| 591 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "D", params)); | 593 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "D", params)); |
| 592 } | 594 } |
| 593 base::FieldTrialList::CreateFieldTrial( | 595 base::FieldTrialList::CreateFieldTrial( |
| 594 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "D"); | 596 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "D"); |
| 595 | 597 |
| 596 { | 598 { |
| 597 // Now the first match should be demoted past the second. | 599 // Now the first match should be demoted past the second. |
| 598 ACMatches matches; | 600 ACMatches matches; |
| 599 PopulateAutocompleteMatches(data, arraysize(data), &matches); | 601 PopulateAutocompleteMatches(data, arraysize(data), &matches); |
| 600 matches[0].inline_autocompletion = base::ASCIIToUTF16("completion"); | 602 matches[0].inline_autocompletion = base::ASCIIToUTF16("completion"); |
| 601 AutocompleteResult result; | 603 AutocompleteResult result; |
| 602 result.AppendMatches(matches); | 604 result.AppendMatches(matches); |
| 603 AutocompleteInput input(base::string16(), base::string16::npos, | 605 AutocompleteInput input(base::string16(), base::string16::npos, |
| 604 base::string16(), GURL(), | 606 base::string16(), GURL(), |
| 605 AutocompleteInput::HOME_PAGE, false, false, false, | 607 OmniboxEventProto::HOME_PAGE, false, false, false, |
| 606 true); | 608 true); |
| 607 result.SortAndCull(input, test_util_.profile()); | 609 result.SortAndCull(input, test_util_.profile()); |
| 608 ASSERT_EQ(4U, result.size()); | 610 ASSERT_EQ(4U, result.size()); |
| 609 EXPECT_EQ("http://b/", result.match_at(0)->destination_url.spec()); | 611 EXPECT_EQ("http://b/", result.match_at(0)->destination_url.spec()); |
| 610 EXPECT_EQ("http://a/", result.match_at(1)->destination_url.spec()); | 612 EXPECT_EQ("http://a/", result.match_at(1)->destination_url.spec()); |
| 611 EXPECT_EQ("http://c/", result.match_at(2)->destination_url.spec()); | 613 EXPECT_EQ("http://c/", result.match_at(2)->destination_url.spec()); |
| 612 EXPECT_EQ("http://d/", result.match_at(3)->destination_url.spec()); | 614 EXPECT_EQ("http://d/", result.match_at(3)->destination_url.spec()); |
| 613 } | 615 } |
| 614 | 616 |
| 615 { | 617 { |
| 616 // But if there was no inline autocompletion on the first match, then | 618 // But if there was no inline autocompletion on the first match, then |
| 617 // the order should stay the same. This is true even if there are | 619 // the order should stay the same. This is true even if there are |
| 618 // inline autocompletions elsewhere. | 620 // inline autocompletions elsewhere. |
| 619 ACMatches matches; | 621 ACMatches matches; |
| 620 PopulateAutocompleteMatches(data, arraysize(data), &matches); | 622 PopulateAutocompleteMatches(data, arraysize(data), &matches); |
| 621 matches[2].inline_autocompletion = base::ASCIIToUTF16("completion"); | 623 matches[2].inline_autocompletion = base::ASCIIToUTF16("completion"); |
| 622 AutocompleteResult result; | 624 AutocompleteResult result; |
| 623 result.AppendMatches(matches); | 625 result.AppendMatches(matches); |
| 624 AutocompleteInput input(base::string16(), base::string16::npos, | 626 AutocompleteInput input(base::string16(), base::string16::npos, |
| 625 base::string16(), GURL(), | 627 base::string16(), GURL(), |
| 626 AutocompleteInput::HOME_PAGE, false, false, false, | 628 OmniboxEventProto::HOME_PAGE, false, false, false, |
| 627 true); | 629 true); |
| 628 result.SortAndCull(input, test_util_.profile()); | 630 result.SortAndCull(input, test_util_.profile()); |
| 629 AssertResultMatches(result, data, 4); | 631 AssertResultMatches(result, data, 4); |
| 630 } | 632 } |
| 631 | 633 |
| 632 { | 634 { |
| 633 // Try a more complicated situation. | 635 // Try a more complicated situation. |
| 634 ACMatches matches; | 636 ACMatches matches; |
| 635 PopulateAutocompleteMatches(data, arraysize(data), &matches); | 637 PopulateAutocompleteMatches(data, arraysize(data), &matches); |
| 636 matches[0].allowed_to_be_default_match = false; | 638 matches[0].allowed_to_be_default_match = false; |
| 637 matches[1].inline_autocompletion = base::ASCIIToUTF16("completion"); | 639 matches[1].inline_autocompletion = base::ASCIIToUTF16("completion"); |
| 638 AutocompleteResult result; | 640 AutocompleteResult result; |
| 639 result.AppendMatches(matches); | 641 result.AppendMatches(matches); |
| 640 AutocompleteInput input(base::string16(), base::string16::npos, | 642 AutocompleteInput input(base::string16(), base::string16::npos, |
| 641 base::string16(), GURL(), | 643 base::string16(), GURL(), |
| 642 AutocompleteInput::HOME_PAGE, false, false, false, | 644 OmniboxEventProto::HOME_PAGE, false, false, false, |
| 643 true); | 645 true); |
| 644 result.SortAndCull(input, test_util_.profile()); | 646 result.SortAndCull(input, test_util_.profile()); |
| 645 ASSERT_EQ(4U, result.size()); | 647 ASSERT_EQ(4U, result.size()); |
| 646 EXPECT_EQ("http://c/", result.match_at(0)->destination_url.spec()); | 648 EXPECT_EQ("http://c/", result.match_at(0)->destination_url.spec()); |
| 647 EXPECT_EQ("http://a/", result.match_at(1)->destination_url.spec()); | 649 EXPECT_EQ("http://a/", result.match_at(1)->destination_url.spec()); |
| 648 EXPECT_EQ("http://b/", result.match_at(2)->destination_url.spec()); | 650 EXPECT_EQ("http://b/", result.match_at(2)->destination_url.spec()); |
| 649 EXPECT_EQ("http://d/", result.match_at(3)->destination_url.spec()); | 651 EXPECT_EQ("http://d/", result.match_at(3)->destination_url.spec()); |
| 650 } | 652 } |
| 651 | 653 |
| 652 { | 654 { |
| 653 // Try another complicated situation. | 655 // Try another complicated situation. |
| 654 ACMatches matches; | 656 ACMatches matches; |
| 655 PopulateAutocompleteMatches(data, arraysize(data), &matches); | 657 PopulateAutocompleteMatches(data, arraysize(data), &matches); |
| 656 matches[0].inline_autocompletion = base::ASCIIToUTF16("completion"); | 658 matches[0].inline_autocompletion = base::ASCIIToUTF16("completion"); |
| 657 matches[1].allowed_to_be_default_match = false; | 659 matches[1].allowed_to_be_default_match = false; |
| 658 AutocompleteResult result; | 660 AutocompleteResult result; |
| 659 result.AppendMatches(matches); | 661 result.AppendMatches(matches); |
| 660 AutocompleteInput input(base::string16(), base::string16::npos, | 662 AutocompleteInput input(base::string16(), base::string16::npos, |
| 661 base::string16(), GURL(), | 663 base::string16(), GURL(), |
| 662 AutocompleteInput::HOME_PAGE, false, false, false, | 664 OmniboxEventProto::HOME_PAGE, false, false, false, |
| 663 true); | 665 true); |
| 664 result.SortAndCull(input, test_util_.profile()); | 666 result.SortAndCull(input, test_util_.profile()); |
| 665 ASSERT_EQ(4U, result.size()); | 667 ASSERT_EQ(4U, result.size()); |
| 666 EXPECT_EQ("http://c/", result.match_at(0)->destination_url.spec()); | 668 EXPECT_EQ("http://c/", result.match_at(0)->destination_url.spec()); |
| 667 EXPECT_EQ("http://a/", result.match_at(1)->destination_url.spec()); | 669 EXPECT_EQ("http://a/", result.match_at(1)->destination_url.spec()); |
| 668 EXPECT_EQ("http://b/", result.match_at(2)->destination_url.spec()); | 670 EXPECT_EQ("http://b/", result.match_at(2)->destination_url.spec()); |
| 669 EXPECT_EQ("http://d/", result.match_at(3)->destination_url.spec()); | 671 EXPECT_EQ("http://d/", result.match_at(3)->destination_url.spec()); |
| 670 } | 672 } |
| 671 | 673 |
| 672 { | 674 { |
| 673 // Check that disaster doesn't strike if we can't demote the top inline | 675 // Check that disaster doesn't strike if we can't demote the top inline |
| 674 // autocompletion because every match either has a completion or isn't | 676 // autocompletion because every match either has a completion or isn't |
| 675 // allowed to be the default match. In this case, we should leave | 677 // allowed to be the default match. In this case, we should leave |
| 676 // everything untouched. | 678 // everything untouched. |
| 677 ACMatches matches; | 679 ACMatches matches; |
| 678 PopulateAutocompleteMatches(data, arraysize(data), &matches); | 680 PopulateAutocompleteMatches(data, arraysize(data), &matches); |
| 679 matches[0].inline_autocompletion = base::ASCIIToUTF16("completion"); | 681 matches[0].inline_autocompletion = base::ASCIIToUTF16("completion"); |
| 680 matches[1].allowed_to_be_default_match = false; | 682 matches[1].allowed_to_be_default_match = false; |
| 681 matches[2].allowed_to_be_default_match = false; | 683 matches[2].allowed_to_be_default_match = false; |
| 682 matches[3].inline_autocompletion = base::ASCIIToUTF16("completion"); | 684 matches[3].inline_autocompletion = base::ASCIIToUTF16("completion"); |
| 683 AutocompleteResult result; | 685 AutocompleteResult result; |
| 684 result.AppendMatches(matches); | 686 result.AppendMatches(matches); |
| 685 AutocompleteInput input(base::string16(), base::string16::npos, | 687 AutocompleteInput input(base::string16(), base::string16::npos, |
| 686 base::string16(), GURL(), | 688 base::string16(), GURL(), |
| 687 AutocompleteInput::HOME_PAGE, false, false, false, | 689 OmniboxEventProto::HOME_PAGE, false, false, false, |
| 688 true); | 690 true); |
| 689 result.SortAndCull(input, test_util_.profile()); | 691 result.SortAndCull(input, test_util_.profile()); |
| 690 AssertResultMatches(result, data, 4); | 692 AssertResultMatches(result, data, 4); |
| 691 } | 693 } |
| 692 | 694 |
| 693 { | 695 { |
| 694 // Check a similar situation, except in this case the top match is not | 696 // Check a similar situation, except in this case the top match is not |
| 695 // allowed to the default match, so it still needs to be demoted so we | 697 // allowed to the default match, so it still needs to be demoted so we |
| 696 // get a legal default match first. That match will have an inline | 698 // get a legal default match first. That match will have an inline |
| 697 // autocompletion because we don't have any better options. | 699 // autocompletion because we don't have any better options. |
| 698 ACMatches matches; | 700 ACMatches matches; |
| 699 PopulateAutocompleteMatches(data, arraysize(data), &matches); | 701 PopulateAutocompleteMatches(data, arraysize(data), &matches); |
| 700 matches[0].allowed_to_be_default_match = false; | 702 matches[0].allowed_to_be_default_match = false; |
| 701 matches[1].inline_autocompletion = base::ASCIIToUTF16("completion"); | 703 matches[1].inline_autocompletion = base::ASCIIToUTF16("completion"); |
| 702 matches[2].allowed_to_be_default_match = false; | 704 matches[2].allowed_to_be_default_match = false; |
| 703 matches[3].inline_autocompletion = base::ASCIIToUTF16("completion"); | 705 matches[3].inline_autocompletion = base::ASCIIToUTF16("completion"); |
| 704 AutocompleteResult result; | 706 AutocompleteResult result; |
| 705 result.AppendMatches(matches); | 707 result.AppendMatches(matches); |
| 706 AutocompleteInput input(base::string16(), base::string16::npos, | 708 AutocompleteInput input(base::string16(), base::string16::npos, |
| 707 base::string16(), GURL(), | 709 base::string16(), GURL(), |
| 708 AutocompleteInput::HOME_PAGE, false, false, false, | 710 OmniboxEventProto::HOME_PAGE, false, false, false, |
| 709 true); | 711 true); |
| 710 result.SortAndCull(input, test_util_.profile()); | 712 result.SortAndCull(input, test_util_.profile()); |
| 711 ASSERT_EQ(4U, result.size()); | 713 ASSERT_EQ(4U, result.size()); |
| 712 EXPECT_EQ("http://b/", result.match_at(0)->destination_url.spec()); | 714 EXPECT_EQ("http://b/", result.match_at(0)->destination_url.spec()); |
| 713 EXPECT_EQ("http://a/", result.match_at(1)->destination_url.spec()); | 715 EXPECT_EQ("http://a/", result.match_at(1)->destination_url.spec()); |
| 714 EXPECT_EQ("http://c/", result.match_at(2)->destination_url.spec()); | 716 EXPECT_EQ("http://c/", result.match_at(2)->destination_url.spec()); |
| 715 EXPECT_EQ("http://d/", result.match_at(3)->destination_url.spec()); | 717 EXPECT_EQ("http://d/", result.match_at(3)->destination_url.spec()); |
| 716 } | 718 } |
| 717 } | 719 } |
| 718 | 720 |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 820 result.Reset(); | 822 result.Reset(); |
| 821 matches.clear(); | 823 matches.clear(); |
| 822 | 824 |
| 823 // Case 5: Multiple verbatim matches found in AutocompleteResult. | 825 // Case 5: Multiple verbatim matches found in AutocompleteResult. |
| 824 PopulateAutocompleteMatchesFromTestData(kVerbatimMatches, | 826 PopulateAutocompleteMatchesFromTestData(kVerbatimMatches, |
| 825 arraysize(kVerbatimMatches), | 827 arraysize(kVerbatimMatches), |
| 826 &matches); | 828 &matches); |
| 827 result.AppendMatches(matches); | 829 result.AppendMatches(matches); |
| 828 EXPECT_FALSE(result.ShouldHideTopMatch()); | 830 EXPECT_FALSE(result.ShouldHideTopMatch()); |
| 829 } | 831 } |
| OLD | NEW |