Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(52)

Side by Side Diff: chrome/browser/autocomplete/autocomplete_result_unittest.cc

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

Powered by Google App Engine
This is Rietveld 408576698