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

Side by Side Diff: components/omnibox/autocomplete_result_unittest.cc

Issue 1155673002: Omnibox - Add About Flag to Reverse Title and URLs in the Dropdown (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix mac and add command line flag to histograms.xml Created 5 years, 7 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
« no previous file with comments | « components/omnibox/autocomplete_result.cc ('k') | components/omnibox/omnibox_switches.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/autocomplete_result.h" 5 #include "components/omnibox/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"
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 const TestData* expected, size_t expected_size) { 200 const TestData* expected, size_t expected_size) {
201 AutocompleteInput input(base::ASCIIToUTF16("a"), base::string16::npos, 201 AutocompleteInput input(base::ASCIIToUTF16("a"), base::string16::npos,
202 std::string(), GURL(), 202 std::string(), GURL(),
203 OmniboxEventProto::INVALID_SPEC, false, false, false, 203 OmniboxEventProto::INVALID_SPEC, false, false, false,
204 true, 204 true,
205 TestSchemeClassifier()); 205 TestSchemeClassifier());
206 206
207 ACMatches last_matches; 207 ACMatches last_matches;
208 PopulateAutocompleteMatches(last, last_size, &last_matches); 208 PopulateAutocompleteMatches(last, last_size, &last_matches);
209 AutocompleteResult last_result; 209 AutocompleteResult last_result;
210 last_result.AppendMatches(last_matches); 210 last_result.AppendMatches(input, last_matches);
211 last_result.SortAndCull(input, template_url_service_.get()); 211 last_result.SortAndCull(input, template_url_service_.get());
212 212
213 ACMatches current_matches; 213 ACMatches current_matches;
214 PopulateAutocompleteMatches(current, current_size, &current_matches); 214 PopulateAutocompleteMatches(current, current_size, &current_matches);
215 AutocompleteResult current_result; 215 AutocompleteResult current_result;
216 current_result.AppendMatches(current_matches); 216 current_result.AppendMatches(input, current_matches);
217 current_result.SortAndCull(input, template_url_service_.get()); 217 current_result.SortAndCull(input, template_url_service_.get());
218 current_result.CopyOldMatches( 218 current_result.CopyOldMatches(
219 input, last_result, template_url_service_.get()); 219 input, last_result, template_url_service_.get());
220 220
221 AssertResultMatches(current_result, expected, expected_size); 221 AssertResultMatches(current_result, expected, expected_size);
222 } 222 }
223 223
224 // Assertion testing for AutocompleteResult::Swap. 224 // Assertion testing for AutocompleteResult::Swap.
225 TEST_F(AutocompleteResultTest, Swap) { 225 TEST_F(AutocompleteResultTest, Swap) {
226 AutocompleteResult r1; 226 AutocompleteResult r1;
227 AutocompleteResult r2; 227 AutocompleteResult r2;
228 228
229 // Swap with empty shouldn't do anything interesting. 229 // Swap with empty shouldn't do anything interesting.
230 r1.Swap(&r2); 230 r1.Swap(&r2);
231 EXPECT_EQ(r1.end(), r1.default_match()); 231 EXPECT_EQ(r1.end(), r1.default_match());
232 EXPECT_EQ(r2.end(), r2.default_match()); 232 EXPECT_EQ(r2.end(), r2.default_match());
233 233
234 // Swap with a single match. 234 // Swap with a single match.
235 ACMatches matches; 235 ACMatches matches;
236 AutocompleteMatch match; 236 AutocompleteMatch match;
237 match.relevance = 1; 237 match.relevance = 1;
238 match.allowed_to_be_default_match = true; 238 match.allowed_to_be_default_match = true;
239 AutocompleteInput input(base::ASCIIToUTF16("a"), base::string16::npos, 239 AutocompleteInput input(base::ASCIIToUTF16("a"), base::string16::npos,
240 std::string(), GURL(), 240 std::string(), GURL(),
241 OmniboxEventProto::INVALID_SPEC, false, false, false, 241 OmniboxEventProto::INVALID_SPEC, false, false, false,
242 true, TestSchemeClassifier()); 242 true, TestSchemeClassifier());
243 matches.push_back(match); 243 matches.push_back(match);
244 r1.AppendMatches(matches); 244 r1.AppendMatches(input, matches);
245 r1.SortAndCull(input, template_url_service_.get()); 245 r1.SortAndCull(input, template_url_service_.get());
246 EXPECT_EQ(r1.begin(), r1.default_match()); 246 EXPECT_EQ(r1.begin(), r1.default_match());
247 EXPECT_EQ("http://a/", r1.alternate_nav_url().spec()); 247 EXPECT_EQ("http://a/", r1.alternate_nav_url().spec());
248 r1.Swap(&r2); 248 r1.Swap(&r2);
249 EXPECT_TRUE(r1.empty()); 249 EXPECT_TRUE(r1.empty());
250 EXPECT_EQ(r1.end(), r1.default_match()); 250 EXPECT_EQ(r1.end(), r1.default_match());
251 EXPECT_TRUE(r1.alternate_nav_url().is_empty()); 251 EXPECT_TRUE(r1.alternate_nav_url().is_empty());
252 ASSERT_FALSE(r2.empty()); 252 ASSERT_FALSE(r2.empty());
253 EXPECT_EQ(r2.begin(), r2.default_match()); 253 EXPECT_EQ(r2.begin(), r2.default_match());
254 EXPECT_EQ("http://a/", r2.alternate_nav_url().spec()); 254 EXPECT_EQ("http://a/", r2.alternate_nav_url().spec());
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 AutocompleteResult result;
378 result.AppendMatches(matches);
379 AutocompleteInput input(base::string16(), base::string16::npos, 377 AutocompleteInput input(base::string16(), base::string16::npos,
380 std::string(), GURL(), 378 std::string(), GURL(),
381 OmniboxEventProto::INVALID_SPEC, false, false, false, 379 OmniboxEventProto::INVALID_SPEC, false, false, false,
382 true, 380 true,
383 TestSchemeClassifier()); 381 TestSchemeClassifier());
382 AutocompleteResult result;
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());
390 EXPECT_TRUE(result.match_at(0)->destination_url.is_empty()); 390 EXPECT_TRUE(result.match_at(0)->destination_url.is_empty());
391 EXPECT_EQ(1300, result.match_at(0)->relevance); 391 EXPECT_EQ(1300, result.match_at(0)->relevance);
392 EXPECT_TRUE(result.match_at(1)->destination_url.is_empty()); 392 EXPECT_TRUE(result.match_at(1)->destination_url.is_empty());
393 EXPECT_EQ(1200, result.match_at(1)->relevance); 393 EXPECT_EQ(1200, result.match_at(1)->relevance);
(...skipping 20 matching lines...) Expand all
414 }; 414 };
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 AutocompleteResult result;
425 result.AppendMatches(matches);
426 AutocompleteInput input(base::string16(), base::string16::npos, 424 AutocompleteInput input(base::string16(), base::string16::npos,
427 std::string(), GURL(), 425 std::string(), GURL(),
428 OmniboxEventProto::INVALID_SPEC, false, false, false, 426 OmniboxEventProto::INVALID_SPEC, false, false, false,
429 true, 427 true,
430 TestSchemeClassifier()); 428 TestSchemeClassifier());
429 AutocompleteResult result;
430 result.AppendMatches(input, matches);
431 result.SortAndCull(input, template_url_service_.get()); 431 result.SortAndCull(input, template_url_service_.get());
432 432
433 // We expect the 3rd and 4th results to be removed. 433 // We expect the 3rd and 4th results to be removed.
434 ASSERT_EQ(3U, result.size()); 434 ASSERT_EQ(3U, result.size());
435 EXPECT_EQ("http://www.foo.com/s?q=foo", 435 EXPECT_EQ("http://www.foo.com/s?q=foo",
436 result.match_at(0)->destination_url.spec()); 436 result.match_at(0)->destination_url.spec());
437 EXPECT_EQ(1300, result.match_at(0)->relevance); 437 EXPECT_EQ(1300, result.match_at(0)->relevance);
438 EXPECT_EQ("http://www.foo.com/s?q=foo2", 438 EXPECT_EQ("http://www.foo.com/s?q=foo2",
439 result.match_at(1)->destination_url.spec()); 439 result.match_at(1)->destination_url.spec());
440 EXPECT_EQ(1200, result.match_at(1)->relevance); 440 EXPECT_EQ(1200, result.match_at(1)->relevance);
(...skipping 26 matching lines...) Expand all
467 467
468 ACMatches matches; 468 ACMatches matches;
469 PopulateAutocompleteMatches(data, arraysize(data), &matches); 469 PopulateAutocompleteMatches(data, arraysize(data), &matches);
470 matches[0].destination_url = GURL("http://www.foo.com/s?q=foo"); 470 matches[0].destination_url = GURL("http://www.foo.com/s?q=foo");
471 matches[1].destination_url = GURL("http://www.foo.com/s?q=foo2"); 471 matches[1].destination_url = GURL("http://www.foo.com/s?q=foo2");
472 matches[2].destination_url = GURL("http://www.foo.com/s?q=foo&oq=f"); 472 matches[2].destination_url = GURL("http://www.foo.com/s?q=foo&oq=f");
473 matches[3].destination_url = GURL("http://www.foo.com/s?q=foo&aqs=0"); 473 matches[3].destination_url = GURL("http://www.foo.com/s?q=foo&aqs=0");
474 matches[4].destination_url = GURL("http://www.foo.com/"); 474 matches[4].destination_url = GURL("http://www.foo.com/");
475 matches[5].destination_url = GURL("http://www.foo.com/s?q=foo2&oq=f"); 475 matches[5].destination_url = GURL("http://www.foo.com/s?q=foo2&oq=f");
476 476
477 AutocompleteResult result;
478 result.AppendMatches(matches);
479 AutocompleteInput input(base::string16(), base::string16::npos, 477 AutocompleteInput input(base::string16(), base::string16::npos,
480 std::string(), GURL(), 478 std::string(), GURL(),
481 OmniboxEventProto::INVALID_SPEC, false, false, false, 479 OmniboxEventProto::INVALID_SPEC, false, false, false,
482 true, 480 true,
483 TestSchemeClassifier()); 481 TestSchemeClassifier());
482 AutocompleteResult result;
483 result.AppendMatches(input, matches);
484 result.SortAndCull(input, template_url_service_.get()); 484 result.SortAndCull(input, template_url_service_.get());
485 485
486 // Expect 3 unique results after SortAndCull(). 486 // Expect 3 unique results after SortAndCull().
487 ASSERT_EQ(3U, result.size()); 487 ASSERT_EQ(3U, result.size());
488 488
489 // Check that 3rd and 4th result got added to the first result as dups 489 // Check that 3rd and 4th result got added to the first result as dups
490 // and also duplicates of the 4th match got copied. 490 // and also duplicates of the 4th match got copied.
491 ASSERT_EQ(4U, result.match_at(0)->duplicate_matches.size()); 491 ASSERT_EQ(4U, result.match_at(0)->duplicate_matches.size());
492 const AutocompleteMatch* first_match = result.match_at(0); 492 const AutocompleteMatch* first_match = result.match_at(0);
493 EXPECT_EQ(matches[2].destination_url, 493 EXPECT_EQ(matches[2].destination_url,
(...skipping 28 matching lines...) Expand all
522 { 522 {
523 std::map<std::string, std::string> params; 523 std::map<std::string, std::string> params;
524 params[std::string(OmniboxFieldTrial::kDemoteByTypeRule) + ":3:*"] = 524 params[std::string(OmniboxFieldTrial::kDemoteByTypeRule) + ":3:*"] =
525 "1:50,7:100,2:0"; // 3 == HOME_PAGE 525 "1:50,7:100,2:0"; // 3 == HOME_PAGE
526 ASSERT_TRUE(variations::AssociateVariationParams( 526 ASSERT_TRUE(variations::AssociateVariationParams(
527 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "A", params)); 527 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "A", params));
528 } 528 }
529 base::FieldTrialList::CreateFieldTrial( 529 base::FieldTrialList::CreateFieldTrial(
530 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "A"); 530 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "A");
531 531
532 AutocompleteResult result;
533 result.AppendMatches(matches);
534 AutocompleteInput input(base::string16(), base::string16::npos, 532 AutocompleteInput input(base::string16(), base::string16::npos,
535 std::string(), GURL(), 533 std::string(), GURL(),
536 OmniboxEventProto::HOME_PAGE, false, false, false, 534 OmniboxEventProto::HOME_PAGE, false, false, false,
537 true, 535 true,
538 TestSchemeClassifier()); 536 TestSchemeClassifier());
537 AutocompleteResult result;
538 result.AppendMatches(input, matches);
539 result.SortAndCull(input, template_url_service_.get()); 539 result.SortAndCull(input, template_url_service_.get());
540 540
541 // Check the new ordering. The history-title results should be omitted. 541 // Check the new ordering. The history-title results should be omitted.
542 // We cannot check relevance scores because the matches are sorted by 542 // We cannot check relevance scores because the matches are sorted by
543 // demoted relevance but the actual relevance scores are not modified. 543 // demoted relevance but the actual relevance scores are not modified.
544 ASSERT_EQ(3u, result.size()); 544 ASSERT_EQ(3u, result.size());
545 EXPECT_EQ("http://search-what-you-typed/", 545 EXPECT_EQ("http://search-what-you-typed/",
546 result.match_at(0)->destination_url.spec()); 546 result.match_at(0)->destination_url.spec());
547 EXPECT_EQ("http://history-url/", 547 EXPECT_EQ("http://history-url/",
548 result.match_at(1)->destination_url.spec()); 548 result.match_at(1)->destination_url.spec());
(...skipping 19 matching lines...) Expand all
568 std::map<std::string, std::string> params; 568 std::map<std::string, std::string> params;
569 params[std::string(OmniboxFieldTrial::kDemoteByTypeRule) + ":8:*"] = 569 params[std::string(OmniboxFieldTrial::kDemoteByTypeRule) + ":8:*"] =
570 "1:50"; // 8 == INSTANT_NTP_WITH_FAKEBOX_AS_STARTING_FOCUS 570 "1:50"; // 8 == INSTANT_NTP_WITH_FAKEBOX_AS_STARTING_FOCUS
571 ASSERT_TRUE(variations::AssociateVariationParams( 571 ASSERT_TRUE(variations::AssociateVariationParams(
572 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "C", params)); 572 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "C", params));
573 } 573 }
574 base::FieldTrialList::CreateFieldTrial( 574 base::FieldTrialList::CreateFieldTrial(
575 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "C"); 575 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "C");
576 576
577 { 577 {
578 AutocompleteResult result;
579 result.AppendMatches(matches);
580 AutocompleteInput input( 578 AutocompleteInput input(
581 base::string16(), base::string16::npos, std::string(), GURL(), 579 base::string16(), base::string16::npos, std::string(), GURL(),
582 OmniboxEventProto::INSTANT_NTP_WITH_FAKEBOX_AS_STARTING_FOCUS, false, 580 OmniboxEventProto::INSTANT_NTP_WITH_FAKEBOX_AS_STARTING_FOCUS, false,
583 false, false, true, 581 false, false, true,
584 TestSchemeClassifier()); 582 TestSchemeClassifier());
583 AutocompleteResult result;
584 result.AppendMatches(input, matches);
585 result.SortAndCull(input, template_url_service_.get()); 585 result.SortAndCull(input, template_url_service_.get());
586 586
587 // The NAVSUGGEST dup-url stay above search-url since the navsuggest 587 // The NAVSUGGEST dup-url stay above search-url since the navsuggest
588 // variant should not be demoted. 588 // variant should not be demoted.
589 ASSERT_EQ(4u, result.size()); 589 ASSERT_EQ(4u, result.size());
590 EXPECT_EQ("http://search-what-you-typed/", 590 EXPECT_EQ("http://search-what-you-typed/",
591 result.match_at(0)->destination_url.spec()); 591 result.match_at(0)->destination_url.spec());
592 EXPECT_EQ("http://dup-url/", 592 EXPECT_EQ("http://dup-url/",
593 result.match_at(1)->destination_url.spec()); 593 result.match_at(1)->destination_url.spec());
594 EXPECT_EQ(AutocompleteMatchType::NAVSUGGEST, 594 EXPECT_EQ(AutocompleteMatchType::NAVSUGGEST,
(...skipping 12 matching lines...) Expand all
607 { 2, 1, 1100, true }, 607 { 2, 1, 1100, true },
608 { 3, 1, 1000, true } 608 { 3, 1, 1000, true }
609 }; 609 };
610 610
611 { 611 {
612 // Check that reorder doesn't do anything if the top result 612 // Check that reorder doesn't do anything if the top result
613 // is already a legal default match (which is the default from 613 // is already a legal default match (which is the default from
614 // PopulateAutocompleteMatches()). 614 // PopulateAutocompleteMatches()).
615 ACMatches matches; 615 ACMatches matches;
616 PopulateAutocompleteMatches(data, arraysize(data), &matches); 616 PopulateAutocompleteMatches(data, arraysize(data), &matches);
617 AutocompleteResult result;
618 result.AppendMatches(matches);
619 AutocompleteInput input(base::string16(), base::string16::npos, 617 AutocompleteInput input(base::string16(), base::string16::npos,
620 std::string(), GURL(), 618 std::string(), GURL(),
621 OmniboxEventProto::HOME_PAGE, false, false, false, 619 OmniboxEventProto::HOME_PAGE, false, false, false,
622 true, 620 true,
623 TestSchemeClassifier()); 621 TestSchemeClassifier());
622 AutocompleteResult result;
623 result.AppendMatches(input, matches);
624 result.SortAndCull(input, template_url_service_.get()); 624 result.SortAndCull(input, template_url_service_.get());
625 AssertResultMatches(result, data, 4); 625 AssertResultMatches(result, data, 4);
626 } 626 }
627 627
628 { 628 {
629 // Check that reorder swaps up a result appropriately. 629 // Check that reorder swaps up a result appropriately.
630 ACMatches matches; 630 ACMatches matches;
631 PopulateAutocompleteMatches(data, arraysize(data), &matches); 631 PopulateAutocompleteMatches(data, arraysize(data), &matches);
632 matches[0].allowed_to_be_default_match = false; 632 matches[0].allowed_to_be_default_match = false;
633 matches[1].allowed_to_be_default_match = false; 633 matches[1].allowed_to_be_default_match = false;
634 AutocompleteResult result;
635 result.AppendMatches(matches);
636 AutocompleteInput input(base::string16(), base::string16::npos, 634 AutocompleteInput input(base::string16(), base::string16::npos,
637 std::string(), GURL(), 635 std::string(), GURL(),
638 OmniboxEventProto::HOME_PAGE, false, false, false, 636 OmniboxEventProto::HOME_PAGE, false, false, false,
639 true, 637 true,
640 TestSchemeClassifier()); 638 TestSchemeClassifier());
639 AutocompleteResult result;
640 result.AppendMatches(input, matches);
641 result.SortAndCull(input, template_url_service_.get()); 641 result.SortAndCull(input, template_url_service_.get());
642 ASSERT_EQ(4U, result.size()); 642 ASSERT_EQ(4U, result.size());
643 EXPECT_EQ("http://c/", result.match_at(0)->destination_url.spec()); 643 EXPECT_EQ("http://c/", result.match_at(0)->destination_url.spec());
644 EXPECT_EQ("http://a/", result.match_at(1)->destination_url.spec()); 644 EXPECT_EQ("http://a/", result.match_at(1)->destination_url.spec());
645 EXPECT_EQ("http://b/", result.match_at(2)->destination_url.spec()); 645 EXPECT_EQ("http://b/", result.match_at(2)->destination_url.spec());
646 EXPECT_EQ("http://d/", result.match_at(3)->destination_url.spec()); 646 EXPECT_EQ("http://d/", result.match_at(3)->destination_url.spec());
647 } 647 }
648 } 648 }
649 649
650 TEST_F(AutocompleteResultTest, ShouldHideTopMatch) { 650 TEST_F(AutocompleteResultTest, ShouldHideTopMatch) {
651 base::FieldTrialList::CreateFieldTrial("InstantExtended", 651 base::FieldTrialList::CreateFieldTrial("InstantExtended",
652 "Group1 hide_verbatim:1"); 652 "Group1 hide_verbatim:1");
653 ACMatches matches; 653 ACMatches matches;
654 654
655 // Case 1: Top match is a verbatim match. 655 // Case 1: Top match is a verbatim match.
656 PopulateAutocompleteMatchesFromTestData(kVerbatimMatches, 1, &matches); 656 PopulateAutocompleteMatchesFromTestData(kVerbatimMatches, 1, &matches);
657 AutocompleteResult result; 657 AutocompleteResult result;
658 result.AppendMatches(matches); 658 result.AppendMatches(AutocompleteInput(), matches);
659 EXPECT_TRUE(result.ShouldHideTopMatch()); 659 EXPECT_TRUE(result.ShouldHideTopMatch());
660 matches.clear(); 660 matches.clear();
661 result.Reset(); 661 result.Reset();
662 662
663 // Case 2: If the verbatim first match is followed by another verbatim match, 663 // Case 2: If the verbatim first match is followed by another verbatim match,
664 // don't hide the top verbatim match. 664 // don't hide the top verbatim match.
665 PopulateAutocompleteMatchesFromTestData(kVerbatimMatches, 665 PopulateAutocompleteMatchesFromTestData(kVerbatimMatches,
666 arraysize(kVerbatimMatches), 666 arraysize(kVerbatimMatches),
667 &matches); 667 &matches);
668 result.AppendMatches(matches); 668 result.AppendMatches(AutocompleteInput(), matches);
669 EXPECT_FALSE(result.ShouldHideTopMatch()); 669 EXPECT_FALSE(result.ShouldHideTopMatch());
670 matches.clear(); 670 matches.clear();
671 result.Reset(); 671 result.Reset();
672 672
673 // Case 3: Top match is not a verbatim match. Do not hide the top match. 673 // Case 3: Top match is not a verbatim match. Do not hide the top match.
674 PopulateAutocompleteMatchesFromTestData(kNonVerbatimMatches, 1, &matches); 674 PopulateAutocompleteMatchesFromTestData(kNonVerbatimMatches, 1, &matches);
675 PopulateAutocompleteMatchesFromTestData(kVerbatimMatches, 675 PopulateAutocompleteMatchesFromTestData(kVerbatimMatches,
676 arraysize(kVerbatimMatches), 676 arraysize(kVerbatimMatches),
677 &matches); 677 &matches);
678 result.AppendMatches(matches); 678 result.AppendMatches(AutocompleteInput(), matches);
679 EXPECT_FALSE(result.ShouldHideTopMatch()); 679 EXPECT_FALSE(result.ShouldHideTopMatch());
680 } 680 }
681 681
682 TEST_F(AutocompleteResultTest, ShouldHideTopMatchAfterCopy) { 682 TEST_F(AutocompleteResultTest, ShouldHideTopMatchAfterCopy) {
683 base::FieldTrialList::CreateFieldTrial("InstantExtended", 683 base::FieldTrialList::CreateFieldTrial("InstantExtended",
684 "Group1 hide_verbatim:1"); 684 "Group1 hide_verbatim:1");
685 ACMatches matches; 685 ACMatches matches;
686 686
687 // Case 1: Top match is a verbatim match followed by only copied matches. 687 // Case 1: Top match is a verbatim match followed by only copied matches.
688 PopulateAutocompleteMatchesFromTestData(kVerbatimMatches, 688 PopulateAutocompleteMatchesFromTestData(kVerbatimMatches,
689 arraysize(kVerbatimMatches), 689 arraysize(kVerbatimMatches),
690 &matches); 690 &matches);
691 for (size_t i = 1; i < arraysize(kVerbatimMatches); ++i) 691 for (size_t i = 1; i < arraysize(kVerbatimMatches); ++i)
692 matches[i].from_previous = true; 692 matches[i].from_previous = true;
693 AutocompleteResult result; 693 AutocompleteResult result;
694 result.AppendMatches(matches); 694 result.AppendMatches(AutocompleteInput(), matches);
695 EXPECT_TRUE(result.ShouldHideTopMatch()); 695 EXPECT_TRUE(result.ShouldHideTopMatch());
696 result.Reset(); 696 result.Reset();
697 697
698 // Case 2: The copied matches are then followed by a non-verbatim match. 698 // Case 2: The copied matches are then followed by a non-verbatim match.
699 PopulateAutocompleteMatchesFromTestData(kNonVerbatimMatches, 1, &matches); 699 PopulateAutocompleteMatchesFromTestData(kNonVerbatimMatches, 1, &matches);
700 result.AppendMatches(matches); 700 result.AppendMatches(AutocompleteInput(), matches);
701 EXPECT_TRUE(result.ShouldHideTopMatch()); 701 EXPECT_TRUE(result.ShouldHideTopMatch());
702 result.Reset(); 702 result.Reset();
703 703
704 // Case 3: The copied matches are instead followed by a verbatim match. 704 // Case 3: The copied matches are instead followed by a verbatim match.
705 matches.back().from_previous = true; 705 matches.back().from_previous = true;
706 PopulateAutocompleteMatchesFromTestData(kVerbatimMatches, 1, &matches); 706 PopulateAutocompleteMatchesFromTestData(kVerbatimMatches, 1, &matches);
707 result.AppendMatches(matches); 707 result.AppendMatches(AutocompleteInput(), matches);
708 EXPECT_FALSE(result.ShouldHideTopMatch()); 708 EXPECT_FALSE(result.ShouldHideTopMatch());
709 } 709 }
710 710
711 TEST_F(AutocompleteResultTest, DoNotHideTopMatch_FieldTrialFlagDisabled) { 711 TEST_F(AutocompleteResultTest, DoNotHideTopMatch_FieldTrialFlagDisabled) {
712 // This test config is identical to ShouldHideTopMatch test ("Case 1") except 712 // This test config is identical to ShouldHideTopMatch test ("Case 1") except
713 // that the "hide_verbatim" flag is disabled in the field trials. 713 // that the "hide_verbatim" flag is disabled in the field trials.
714 base::FieldTrialList::CreateFieldTrial("InstantExtended", 714 base::FieldTrialList::CreateFieldTrial("InstantExtended",
715 "Group1 hide_verbatim:0"); 715 "Group1 hide_verbatim:0");
716 ACMatches matches; 716 ACMatches matches;
717 PopulateAutocompleteMatchesFromTestData(kVerbatimMatches, 1, &matches); 717 PopulateAutocompleteMatchesFromTestData(kVerbatimMatches, 1, &matches);
718 AutocompleteResult result; 718 AutocompleteResult result;
719 result.AppendMatches(matches); 719 result.AppendMatches(AutocompleteInput(), matches);
720 // Field trial flag "hide_verbatim" is disabled. Do not hide top match. 720 // Field trial flag "hide_verbatim" is disabled. Do not hide top match.
721 EXPECT_FALSE(result.ShouldHideTopMatch()); 721 EXPECT_FALSE(result.ShouldHideTopMatch());
722 } 722 }
723 723
724 TEST_F(AutocompleteResultTest, TopMatchIsStandaloneVerbatimMatch) { 724 TEST_F(AutocompleteResultTest, TopMatchIsStandaloneVerbatimMatch) {
725 ACMatches matches; 725 ACMatches matches;
726 AutocompleteResult result; 726 AutocompleteResult result;
727 result.AppendMatches(matches); 727 result.AppendMatches(AutocompleteInput(), matches);
728 728
729 // Case 1: Result set is empty. 729 // Case 1: Result set is empty.
730 EXPECT_FALSE(result.TopMatchIsStandaloneVerbatimMatch()); 730 EXPECT_FALSE(result.TopMatchIsStandaloneVerbatimMatch());
731 731
732 // Case 2: Top match is not a verbatim match. 732 // Case 2: Top match is not a verbatim match.
733 PopulateAutocompleteMatchesFromTestData(kNonVerbatimMatches, 1, &matches); 733 PopulateAutocompleteMatchesFromTestData(kNonVerbatimMatches, 1, &matches);
734 result.AppendMatches(matches); 734 result.AppendMatches(AutocompleteInput(), matches);
735 EXPECT_FALSE(result.TopMatchIsStandaloneVerbatimMatch()); 735 EXPECT_FALSE(result.TopMatchIsStandaloneVerbatimMatch());
736 result.Reset(); 736 result.Reset();
737 matches.clear(); 737 matches.clear();
738 738
739 // Case 3: Top match is a verbatim match. 739 // Case 3: Top match is a verbatim match.
740 PopulateAutocompleteMatchesFromTestData(kVerbatimMatches, 1, &matches); 740 PopulateAutocompleteMatchesFromTestData(kVerbatimMatches, 1, &matches);
741 result.AppendMatches(matches); 741 result.AppendMatches(AutocompleteInput(), matches);
742 EXPECT_TRUE(result.TopMatchIsStandaloneVerbatimMatch()); 742 EXPECT_TRUE(result.TopMatchIsStandaloneVerbatimMatch());
743 result.Reset(); 743 result.Reset();
744 matches.clear(); 744 matches.clear();
745 745
746 // Case 4: Standalone verbatim match found in AutocompleteResult. 746 // Case 4: Standalone verbatim match found in AutocompleteResult.
747 PopulateAutocompleteMatchesFromTestData(kVerbatimMatches, 1, &matches); 747 PopulateAutocompleteMatchesFromTestData(kVerbatimMatches, 1, &matches);
748 PopulateAutocompleteMatchesFromTestData(kNonVerbatimMatches, 1, &matches); 748 PopulateAutocompleteMatchesFromTestData(kNonVerbatimMatches, 1, &matches);
749 result.AppendMatches(matches); 749 result.AppendMatches(AutocompleteInput(), matches);
750 EXPECT_TRUE(result.TopMatchIsStandaloneVerbatimMatch()); 750 EXPECT_TRUE(result.TopMatchIsStandaloneVerbatimMatch());
751 result.Reset(); 751 result.Reset();
752 matches.clear(); 752 matches.clear();
753 753
754 // Case 5: Multiple verbatim matches found in AutocompleteResult. 754 // Case 5: Multiple verbatim matches found in AutocompleteResult.
755 PopulateAutocompleteMatchesFromTestData(kVerbatimMatches, 755 PopulateAutocompleteMatchesFromTestData(kVerbatimMatches,
756 arraysize(kVerbatimMatches), 756 arraysize(kVerbatimMatches),
757 &matches); 757 &matches);
758 result.AppendMatches(matches); 758 result.AppendMatches(AutocompleteInput(), matches);
759 EXPECT_FALSE(result.ShouldHideTopMatch()); 759 EXPECT_FALSE(result.ShouldHideTopMatch());
760 } 760 }
OLDNEW
« no previous file with comments | « components/omnibox/autocomplete_result.cc ('k') | components/omnibox/omnibox_switches.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698