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

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

Issue 363893002: Revert of Reduces dependency from AutocompleteMatch to Profile. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 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"
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 base::string16(), GURL(), 182 base::string16(), GURL(),
183 OmniboxEventProto::INVALID_SPEC, false, false, false, 183 OmniboxEventProto::INVALID_SPEC, false, false, false,
184 true, 184 true,
185 ChromeAutocompleteSchemeClassifier( 185 ChromeAutocompleteSchemeClassifier(
186 test_util_.profile())); 186 test_util_.profile()));
187 187
188 ACMatches last_matches; 188 ACMatches last_matches;
189 PopulateAutocompleteMatches(last, last_size, &last_matches); 189 PopulateAutocompleteMatches(last, last_size, &last_matches);
190 AutocompleteResult last_result; 190 AutocompleteResult last_result;
191 last_result.AppendMatches(last_matches); 191 last_result.AppendMatches(last_matches);
192 last_result.SortAndCull(input, test_util_.model()); 192 last_result.SortAndCull(input, test_util_.profile());
193 193
194 ACMatches current_matches; 194 ACMatches current_matches;
195 PopulateAutocompleteMatches(current, current_size, &current_matches); 195 PopulateAutocompleteMatches(current, current_size, &current_matches);
196 AutocompleteResult current_result; 196 AutocompleteResult current_result;
197 current_result.AppendMatches(current_matches); 197 current_result.AppendMatches(current_matches);
198 current_result.SortAndCull(input, test_util_.model()); 198 current_result.SortAndCull(input, test_util_.profile());
199 current_result.CopyOldMatches(input, last_result, test_util_.model()); 199 current_result.CopyOldMatches(input, last_result, test_util_.profile());
200 200
201 AssertResultMatches(current_result, expected, expected_size); 201 AssertResultMatches(current_result, expected, expected_size);
202 } 202 }
203 203
204 // Assertion testing for AutocompleteResult::Swap. 204 // Assertion testing for AutocompleteResult::Swap.
205 TEST_F(AutocompleteResultTest, Swap) { 205 TEST_F(AutocompleteResultTest, Swap) {
206 AutocompleteResult r1; 206 AutocompleteResult r1;
207 AutocompleteResult r2; 207 AutocompleteResult r2;
208 208
209 // Swap with empty shouldn't do anything interesting. 209 // Swap with empty shouldn't do anything interesting.
210 r1.Swap(&r2); 210 r1.Swap(&r2);
211 EXPECT_EQ(r1.end(), r1.default_match()); 211 EXPECT_EQ(r1.end(), r1.default_match());
212 EXPECT_EQ(r2.end(), r2.default_match()); 212 EXPECT_EQ(r2.end(), r2.default_match());
213 213
214 // Swap with a single match. 214 // Swap with a single match.
215 ACMatches matches; 215 ACMatches matches;
216 AutocompleteMatch match; 216 AutocompleteMatch match;
217 match.relevance = 1; 217 match.relevance = 1;
218 match.allowed_to_be_default_match = true; 218 match.allowed_to_be_default_match = true;
219 AutocompleteInput input(base::ASCIIToUTF16("a"), base::string16::npos, 219 AutocompleteInput input(base::ASCIIToUTF16("a"), base::string16::npos,
220 base::string16(), GURL(), 220 base::string16(), GURL(),
221 OmniboxEventProto::INVALID_SPEC, false, false, false, 221 OmniboxEventProto::INVALID_SPEC, false, false, false,
222 true, ChromeAutocompleteSchemeClassifier( 222 true, ChromeAutocompleteSchemeClassifier(
223 test_util_.profile())); 223 test_util_.profile()));
224 matches.push_back(match); 224 matches.push_back(match);
225 r1.AppendMatches(matches); 225 r1.AppendMatches(matches);
226 r1.SortAndCull(input, test_util_.model()); 226 r1.SortAndCull(input, test_util_.profile());
227 EXPECT_EQ(r1.begin(), r1.default_match()); 227 EXPECT_EQ(r1.begin(), r1.default_match());
228 EXPECT_EQ("http://a/", r1.alternate_nav_url().spec()); 228 EXPECT_EQ("http://a/", r1.alternate_nav_url().spec());
229 r1.Swap(&r2); 229 r1.Swap(&r2);
230 EXPECT_TRUE(r1.empty()); 230 EXPECT_TRUE(r1.empty());
231 EXPECT_EQ(r1.end(), r1.default_match()); 231 EXPECT_EQ(r1.end(), r1.default_match());
232 EXPECT_TRUE(r1.alternate_nav_url().is_empty()); 232 EXPECT_TRUE(r1.alternate_nav_url().is_empty());
233 ASSERT_FALSE(r2.empty()); 233 ASSERT_FALSE(r2.empty());
234 EXPECT_EQ(r2.begin(), r2.default_match()); 234 EXPECT_EQ(r2.begin(), r2.default_match());
235 EXPECT_EQ("http://a/", r2.alternate_nav_url().spec()); 235 EXPECT_EQ("http://a/", r2.alternate_nav_url().spec());
236 } 236 }
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 matches[4].destination_url = GURL(); 299 matches[4].destination_url = GURL();
300 300
301 AutocompleteResult result; 301 AutocompleteResult result;
302 result.AppendMatches(matches); 302 result.AppendMatches(matches);
303 AutocompleteInput input(base::string16(), base::string16::npos, 303 AutocompleteInput input(base::string16(), base::string16::npos,
304 base::string16(), GURL(), 304 base::string16(), GURL(),
305 OmniboxEventProto::INVALID_SPEC, false, false, false, 305 OmniboxEventProto::INVALID_SPEC, false, false, false,
306 true, 306 true,
307 ChromeAutocompleteSchemeClassifier( 307 ChromeAutocompleteSchemeClassifier(
308 test_util_.profile())); 308 test_util_.profile()));
309 result.SortAndCull(input, test_util_.model()); 309 result.SortAndCull(input, test_util_.profile());
310 310
311 // Of the two results with the same non-empty destination URL, the 311 // Of the two results with the same non-empty destination URL, the
312 // lower-relevance one should be dropped. All of the results with empty URLs 312 // lower-relevance one should be dropped. All of the results with empty URLs
313 // should be kept. 313 // should be kept.
314 ASSERT_EQ(4U, result.size()); 314 ASSERT_EQ(4U, result.size());
315 EXPECT_TRUE(result.match_at(0)->destination_url.is_empty()); 315 EXPECT_TRUE(result.match_at(0)->destination_url.is_empty());
316 EXPECT_EQ(1300, result.match_at(0)->relevance); 316 EXPECT_EQ(1300, result.match_at(0)->relevance);
317 EXPECT_TRUE(result.match_at(1)->destination_url.is_empty()); 317 EXPECT_TRUE(result.match_at(1)->destination_url.is_empty());
318 EXPECT_EQ(1200, result.match_at(1)->relevance); 318 EXPECT_EQ(1200, result.match_at(1)->relevance);
319 EXPECT_TRUE(result.match_at(2)->destination_url.is_empty()); 319 EXPECT_TRUE(result.match_at(2)->destination_url.is_empty());
(...skipping 27 matching lines...) Expand all
347 matches[4].destination_url = GURL("http://www.foo.com/"); 347 matches[4].destination_url = GURL("http://www.foo.com/");
348 348
349 AutocompleteResult result; 349 AutocompleteResult result;
350 result.AppendMatches(matches); 350 result.AppendMatches(matches);
351 AutocompleteInput input(base::string16(), base::string16::npos, 351 AutocompleteInput input(base::string16(), base::string16::npos,
352 base::string16(), GURL(), 352 base::string16(), GURL(),
353 OmniboxEventProto::INVALID_SPEC, false, false, false, 353 OmniboxEventProto::INVALID_SPEC, false, false, false,
354 true, 354 true,
355 ChromeAutocompleteSchemeClassifier( 355 ChromeAutocompleteSchemeClassifier(
356 test_util_.profile())); 356 test_util_.profile()));
357 result.SortAndCull(input, test_util_.model()); 357 result.SortAndCull(input, test_util_.profile());
358 358
359 // We expect the 3rd and 4th results to be removed. 359 // We expect the 3rd and 4th results to be removed.
360 ASSERT_EQ(3U, result.size()); 360 ASSERT_EQ(3U, result.size());
361 EXPECT_EQ("http://www.foo.com/s?q=foo", 361 EXPECT_EQ("http://www.foo.com/s?q=foo",
362 result.match_at(0)->destination_url.spec()); 362 result.match_at(0)->destination_url.spec());
363 EXPECT_EQ(1300, result.match_at(0)->relevance); 363 EXPECT_EQ(1300, result.match_at(0)->relevance);
364 EXPECT_EQ("http://www.foo.com/s?q=foo2", 364 EXPECT_EQ("http://www.foo.com/s?q=foo2",
365 result.match_at(1)->destination_url.spec()); 365 result.match_at(1)->destination_url.spec());
366 EXPECT_EQ(1200, result.match_at(1)->relevance); 366 EXPECT_EQ(1200, result.match_at(1)->relevance);
367 EXPECT_EQ("http://www.foo.com/", 367 EXPECT_EQ("http://www.foo.com/",
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 matches[5].destination_url = GURL("http://www.foo.com/s?q=foo2&oq=f"); 401 matches[5].destination_url = GURL("http://www.foo.com/s?q=foo2&oq=f");
402 402
403 AutocompleteResult result; 403 AutocompleteResult result;
404 result.AppendMatches(matches); 404 result.AppendMatches(matches);
405 AutocompleteInput input(base::string16(), base::string16::npos, 405 AutocompleteInput input(base::string16(), base::string16::npos,
406 base::string16(), GURL(), 406 base::string16(), GURL(),
407 OmniboxEventProto::INVALID_SPEC, false, false, false, 407 OmniboxEventProto::INVALID_SPEC, false, false, false,
408 true, 408 true,
409 ChromeAutocompleteSchemeClassifier( 409 ChromeAutocompleteSchemeClassifier(
410 test_util_.profile())); 410 test_util_.profile()));
411 result.SortAndCull(input, test_util_.model()); 411 result.SortAndCull(input, test_util_.profile());
412 412
413 // Expect 3 unique results after SortAndCull(). 413 // Expect 3 unique results after SortAndCull().
414 ASSERT_EQ(3U, result.size()); 414 ASSERT_EQ(3U, result.size());
415 415
416 // Check that 3rd and 4th result got added to the first result as dups 416 // Check that 3rd and 4th result got added to the first result as dups
417 // and also duplicates of the 4th match got copied. 417 // and also duplicates of the 4th match got copied.
418 ASSERT_EQ(4U, result.match_at(0)->duplicate_matches.size()); 418 ASSERT_EQ(4U, result.match_at(0)->duplicate_matches.size());
419 const AutocompleteMatch* first_match = result.match_at(0); 419 const AutocompleteMatch* first_match = result.match_at(0);
420 EXPECT_EQ(matches[2].destination_url, 420 EXPECT_EQ(matches[2].destination_url,
421 first_match->duplicate_matches.at(1).destination_url); 421 first_match->duplicate_matches.at(1).destination_url);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
457 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "A"); 457 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "A");
458 458
459 AutocompleteResult result; 459 AutocompleteResult result;
460 result.AppendMatches(matches); 460 result.AppendMatches(matches);
461 AutocompleteInput input(base::string16(), base::string16::npos, 461 AutocompleteInput input(base::string16(), base::string16::npos,
462 base::string16(), GURL(), 462 base::string16(), GURL(),
463 OmniboxEventProto::HOME_PAGE, false, false, false, 463 OmniboxEventProto::HOME_PAGE, false, false, false,
464 true, 464 true,
465 ChromeAutocompleteSchemeClassifier( 465 ChromeAutocompleteSchemeClassifier(
466 test_util_.profile())); 466 test_util_.profile()));
467 result.SortAndCull(input, test_util_.model()); 467 result.SortAndCull(input, test_util_.profile());
468 468
469 // Check the new ordering. The history-title results should be omitted. 469 // Check the new ordering. The history-title results should be omitted.
470 // We cannot check relevance scores because the matches are sorted by 470 // We cannot check relevance scores because the matches are sorted by
471 // demoted relevance but the actual relevance scores are not modified. 471 // demoted relevance but the actual relevance scores are not modified.
472 ASSERT_EQ(3u, result.size()); 472 ASSERT_EQ(3u, result.size());
473 EXPECT_EQ("http://search-what-you-typed/", 473 EXPECT_EQ("http://search-what-you-typed/",
474 result.match_at(0)->destination_url.spec()); 474 result.match_at(0)->destination_url.spec());
475 EXPECT_EQ("http://history-url/", 475 EXPECT_EQ("http://history-url/",
476 result.match_at(1)->destination_url.spec()); 476 result.match_at(1)->destination_url.spec());
477 EXPECT_EQ("http://search-history/", 477 EXPECT_EQ("http://search-history/",
(...skipping 25 matching lines...) Expand all
503 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "C"); 503 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "C");
504 504
505 { 505 {
506 AutocompleteResult result; 506 AutocompleteResult result;
507 result.AppendMatches(matches); 507 result.AppendMatches(matches);
508 AutocompleteInput input( 508 AutocompleteInput input(
509 base::string16(), base::string16::npos, base::string16(), GURL(), 509 base::string16(), base::string16::npos, base::string16(), GURL(),
510 OmniboxEventProto::INSTANT_NTP_WITH_FAKEBOX_AS_STARTING_FOCUS, false, 510 OmniboxEventProto::INSTANT_NTP_WITH_FAKEBOX_AS_STARTING_FOCUS, false,
511 false, false, true, 511 false, false, true,
512 ChromeAutocompleteSchemeClassifier(test_util_.profile())); 512 ChromeAutocompleteSchemeClassifier(test_util_.profile()));
513 result.SortAndCull(input, test_util_.model()); 513 result.SortAndCull(input, test_util_.profile());
514 514
515 // The NAVSUGGEST dup-url stay above search-url since the navsuggest 515 // The NAVSUGGEST dup-url stay above search-url since the navsuggest
516 // variant should not be demoted. 516 // variant should not be demoted.
517 ASSERT_EQ(4u, result.size()); 517 ASSERT_EQ(4u, result.size());
518 EXPECT_EQ("http://search-what-you-typed/", 518 EXPECT_EQ("http://search-what-you-typed/",
519 result.match_at(0)->destination_url.spec()); 519 result.match_at(0)->destination_url.spec());
520 EXPECT_EQ("http://dup-url/", 520 EXPECT_EQ("http://dup-url/",
521 result.match_at(1)->destination_url.spec()); 521 result.match_at(1)->destination_url.spec());
522 EXPECT_EQ(AutocompleteMatchType::NAVSUGGEST, 522 EXPECT_EQ(AutocompleteMatchType::NAVSUGGEST,
523 result.match_at(1)->type); 523 result.match_at(1)->type);
(...skipping 19 matching lines...) Expand all
543 ACMatches matches; 543 ACMatches matches;
544 PopulateAutocompleteMatches(data, arraysize(data), &matches); 544 PopulateAutocompleteMatches(data, arraysize(data), &matches);
545 AutocompleteResult result; 545 AutocompleteResult result;
546 result.AppendMatches(matches); 546 result.AppendMatches(matches);
547 AutocompleteInput input(base::string16(), base::string16::npos, 547 AutocompleteInput input(base::string16(), base::string16::npos,
548 base::string16(), GURL(), 548 base::string16(), GURL(),
549 OmniboxEventProto::HOME_PAGE, false, false, false, 549 OmniboxEventProto::HOME_PAGE, false, false, false,
550 true, 550 true,
551 ChromeAutocompleteSchemeClassifier( 551 ChromeAutocompleteSchemeClassifier(
552 test_util_.profile())); 552 test_util_.profile()));
553 result.SortAndCull(input, test_util_.model()); 553 result.SortAndCull(input, test_util_.profile());
554 AssertResultMatches(result, data, 4); 554 AssertResultMatches(result, data, 4);
555 } 555 }
556 556
557 { 557 {
558 // Check that reorder swaps up a result appropriately. 558 // Check that reorder swaps up a result appropriately.
559 ACMatches matches; 559 ACMatches matches;
560 PopulateAutocompleteMatches(data, arraysize(data), &matches); 560 PopulateAutocompleteMatches(data, arraysize(data), &matches);
561 matches[0].allowed_to_be_default_match = false; 561 matches[0].allowed_to_be_default_match = false;
562 matches[1].allowed_to_be_default_match = false; 562 matches[1].allowed_to_be_default_match = false;
563 AutocompleteResult result; 563 AutocompleteResult result;
564 result.AppendMatches(matches); 564 result.AppendMatches(matches);
565 AutocompleteInput input(base::string16(), base::string16::npos, 565 AutocompleteInput input(base::string16(), base::string16::npos,
566 base::string16(), GURL(), 566 base::string16(), GURL(),
567 OmniboxEventProto::HOME_PAGE, false, false, false, 567 OmniboxEventProto::HOME_PAGE, false, false, false,
568 true, 568 true,
569 ChromeAutocompleteSchemeClassifier( 569 ChromeAutocompleteSchemeClassifier(
570 test_util_.profile())); 570 test_util_.profile()));
571 result.SortAndCull(input, test_util_.model()); 571 result.SortAndCull(input, test_util_.profile());
572 ASSERT_EQ(4U, result.size()); 572 ASSERT_EQ(4U, result.size());
573 EXPECT_EQ("http://c/", result.match_at(0)->destination_url.spec()); 573 EXPECT_EQ("http://c/", result.match_at(0)->destination_url.spec());
574 EXPECT_EQ("http://a/", result.match_at(1)->destination_url.spec()); 574 EXPECT_EQ("http://a/", result.match_at(1)->destination_url.spec());
575 EXPECT_EQ("http://b/", result.match_at(2)->destination_url.spec()); 575 EXPECT_EQ("http://b/", result.match_at(2)->destination_url.spec());
576 EXPECT_EQ("http://d/", result.match_at(3)->destination_url.spec()); 576 EXPECT_EQ("http://d/", result.match_at(3)->destination_url.spec());
577 } 577 }
578 } 578 }
579 579
580 580
581 581
(...skipping 12 matching lines...) Expand all
594 PopulateAutocompleteMatches(data, arraysize(data), &matches); 594 PopulateAutocompleteMatches(data, arraysize(data), &matches);
595 matches[0].inline_autocompletion = base::ASCIIToUTF16("completion"); 595 matches[0].inline_autocompletion = base::ASCIIToUTF16("completion");
596 AutocompleteResult result; 596 AutocompleteResult result;
597 result.AppendMatches(matches); 597 result.AppendMatches(matches);
598 AutocompleteInput input(base::string16(), base::string16::npos, 598 AutocompleteInput input(base::string16(), base::string16::npos,
599 base::string16(), GURL(), 599 base::string16(), GURL(),
600 OmniboxEventProto::HOME_PAGE, false, false, false, 600 OmniboxEventProto::HOME_PAGE, false, false, false,
601 true, 601 true,
602 ChromeAutocompleteSchemeClassifier( 602 ChromeAutocompleteSchemeClassifier(
603 test_util_.profile())); 603 test_util_.profile()));
604 result.SortAndCull(input, test_util_.model()); 604 result.SortAndCull(input, test_util_.profile());
605 AssertResultMatches(result, data, 4); 605 AssertResultMatches(result, data, 4);
606 } 606 }
607 607
608 // Enable the field trial to disable inlining. 608 // Enable the field trial to disable inlining.
609 { 609 {
610 std::map<std::string, std::string> params; 610 std::map<std::string, std::string> params;
611 params[OmniboxFieldTrial::kDisableInliningRule] = "true"; 611 params[OmniboxFieldTrial::kDisableInliningRule] = "true";
612 ASSERT_TRUE(chrome_variations::AssociateVariationParams( 612 ASSERT_TRUE(chrome_variations::AssociateVariationParams(
613 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "D", params)); 613 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "D", params));
614 } 614 }
615 base::FieldTrialList::CreateFieldTrial( 615 base::FieldTrialList::CreateFieldTrial(
616 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "D"); 616 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "D");
617 617
618 { 618 {
619 // Now the first match should be demoted past the second. 619 // Now the first match should be demoted past the second.
620 ACMatches matches; 620 ACMatches matches;
621 PopulateAutocompleteMatches(data, arraysize(data), &matches); 621 PopulateAutocompleteMatches(data, arraysize(data), &matches);
622 matches[0].inline_autocompletion = base::ASCIIToUTF16("completion"); 622 matches[0].inline_autocompletion = base::ASCIIToUTF16("completion");
623 AutocompleteResult result; 623 AutocompleteResult result;
624 result.AppendMatches(matches); 624 result.AppendMatches(matches);
625 AutocompleteInput input(base::string16(), base::string16::npos, 625 AutocompleteInput input(base::string16(), base::string16::npos,
626 base::string16(), GURL(), 626 base::string16(), GURL(),
627 OmniboxEventProto::HOME_PAGE, false, false, false, 627 OmniboxEventProto::HOME_PAGE, false, false, false,
628 true, 628 true,
629 ChromeAutocompleteSchemeClassifier( 629 ChromeAutocompleteSchemeClassifier(
630 test_util_.profile())); 630 test_util_.profile()));
631 result.SortAndCull(input, test_util_.model()); 631 result.SortAndCull(input, test_util_.profile());
632 ASSERT_EQ(4U, result.size()); 632 ASSERT_EQ(4U, result.size());
633 EXPECT_EQ("http://b/", result.match_at(0)->destination_url.spec()); 633 EXPECT_EQ("http://b/", result.match_at(0)->destination_url.spec());
634 EXPECT_EQ("http://a/", result.match_at(1)->destination_url.spec()); 634 EXPECT_EQ("http://a/", result.match_at(1)->destination_url.spec());
635 EXPECT_EQ("http://c/", result.match_at(2)->destination_url.spec()); 635 EXPECT_EQ("http://c/", result.match_at(2)->destination_url.spec());
636 EXPECT_EQ("http://d/", result.match_at(3)->destination_url.spec()); 636 EXPECT_EQ("http://d/", result.match_at(3)->destination_url.spec());
637 } 637 }
638 638
639 { 639 {
640 // But if there was no inline autocompletion on the first match, then 640 // But if there was no inline autocompletion on the first match, then
641 // the order should stay the same. This is true even if there are 641 // the order should stay the same. This is true even if there are
642 // inline autocompletions elsewhere. 642 // inline autocompletions elsewhere.
643 ACMatches matches; 643 ACMatches matches;
644 PopulateAutocompleteMatches(data, arraysize(data), &matches); 644 PopulateAutocompleteMatches(data, arraysize(data), &matches);
645 matches[2].inline_autocompletion = base::ASCIIToUTF16("completion"); 645 matches[2].inline_autocompletion = base::ASCIIToUTF16("completion");
646 AutocompleteResult result; 646 AutocompleteResult result;
647 result.AppendMatches(matches); 647 result.AppendMatches(matches);
648 AutocompleteInput input(base::string16(), base::string16::npos, 648 AutocompleteInput input(base::string16(), base::string16::npos,
649 base::string16(), GURL(), 649 base::string16(), GURL(),
650 OmniboxEventProto::HOME_PAGE, false, false, false, 650 OmniboxEventProto::HOME_PAGE, false, false, false,
651 true, 651 true,
652 ChromeAutocompleteSchemeClassifier( 652 ChromeAutocompleteSchemeClassifier(
653 test_util_.profile())); 653 test_util_.profile()));
654 result.SortAndCull(input, test_util_.model()); 654 result.SortAndCull(input, test_util_.profile());
655 AssertResultMatches(result, data, 4); 655 AssertResultMatches(result, data, 4);
656 } 656 }
657 657
658 { 658 {
659 // Try a more complicated situation. 659 // Try a more complicated situation.
660 ACMatches matches; 660 ACMatches matches;
661 PopulateAutocompleteMatches(data, arraysize(data), &matches); 661 PopulateAutocompleteMatches(data, arraysize(data), &matches);
662 matches[0].allowed_to_be_default_match = false; 662 matches[0].allowed_to_be_default_match = false;
663 matches[1].inline_autocompletion = base::ASCIIToUTF16("completion"); 663 matches[1].inline_autocompletion = base::ASCIIToUTF16("completion");
664 AutocompleteResult result; 664 AutocompleteResult result;
665 result.AppendMatches(matches); 665 result.AppendMatches(matches);
666 AutocompleteInput input(base::string16(), base::string16::npos, 666 AutocompleteInput input(base::string16(), base::string16::npos,
667 base::string16(), GURL(), 667 base::string16(), GURL(),
668 OmniboxEventProto::HOME_PAGE, false, false, false, 668 OmniboxEventProto::HOME_PAGE, false, false, false,
669 true, 669 true,
670 ChromeAutocompleteSchemeClassifier( 670 ChromeAutocompleteSchemeClassifier(
671 test_util_.profile())); 671 test_util_.profile()));
672 result.SortAndCull(input, test_util_.model()); 672 result.SortAndCull(input, test_util_.profile());
673 ASSERT_EQ(4U, result.size()); 673 ASSERT_EQ(4U, result.size());
674 EXPECT_EQ("http://c/", result.match_at(0)->destination_url.spec()); 674 EXPECT_EQ("http://c/", result.match_at(0)->destination_url.spec());
675 EXPECT_EQ("http://a/", result.match_at(1)->destination_url.spec()); 675 EXPECT_EQ("http://a/", result.match_at(1)->destination_url.spec());
676 EXPECT_EQ("http://b/", result.match_at(2)->destination_url.spec()); 676 EXPECT_EQ("http://b/", result.match_at(2)->destination_url.spec());
677 EXPECT_EQ("http://d/", result.match_at(3)->destination_url.spec()); 677 EXPECT_EQ("http://d/", result.match_at(3)->destination_url.spec());
678 } 678 }
679 679
680 { 680 {
681 // Try another complicated situation. 681 // Try another complicated situation.
682 ACMatches matches; 682 ACMatches matches;
683 PopulateAutocompleteMatches(data, arraysize(data), &matches); 683 PopulateAutocompleteMatches(data, arraysize(data), &matches);
684 matches[0].inline_autocompletion = base::ASCIIToUTF16("completion"); 684 matches[0].inline_autocompletion = base::ASCIIToUTF16("completion");
685 matches[1].allowed_to_be_default_match = false; 685 matches[1].allowed_to_be_default_match = false;
686 AutocompleteResult result; 686 AutocompleteResult result;
687 result.AppendMatches(matches); 687 result.AppendMatches(matches);
688 AutocompleteInput input(base::string16(), base::string16::npos, 688 AutocompleteInput input(base::string16(), base::string16::npos,
689 base::string16(), GURL(), 689 base::string16(), GURL(),
690 OmniboxEventProto::HOME_PAGE, false, false, false, 690 OmniboxEventProto::HOME_PAGE, false, false, false,
691 true, 691 true,
692 ChromeAutocompleteSchemeClassifier( 692 ChromeAutocompleteSchemeClassifier(
693 test_util_.profile())); 693 test_util_.profile()));
694 result.SortAndCull(input, test_util_.model()); 694 result.SortAndCull(input, test_util_.profile());
695 ASSERT_EQ(4U, result.size()); 695 ASSERT_EQ(4U, result.size());
696 EXPECT_EQ("http://c/", result.match_at(0)->destination_url.spec()); 696 EXPECT_EQ("http://c/", result.match_at(0)->destination_url.spec());
697 EXPECT_EQ("http://a/", result.match_at(1)->destination_url.spec()); 697 EXPECT_EQ("http://a/", result.match_at(1)->destination_url.spec());
698 EXPECT_EQ("http://b/", result.match_at(2)->destination_url.spec()); 698 EXPECT_EQ("http://b/", result.match_at(2)->destination_url.spec());
699 EXPECT_EQ("http://d/", result.match_at(3)->destination_url.spec()); 699 EXPECT_EQ("http://d/", result.match_at(3)->destination_url.spec());
700 } 700 }
701 701
702 { 702 {
703 // Check that disaster doesn't strike if we can't demote the top inline 703 // Check that disaster doesn't strike if we can't demote the top inline
704 // autocompletion because every match either has a completion or isn't 704 // autocompletion because every match either has a completion or isn't
705 // allowed to be the default match. In this case, we should leave 705 // allowed to be the default match. In this case, we should leave
706 // everything untouched. 706 // everything untouched.
707 ACMatches matches; 707 ACMatches matches;
708 PopulateAutocompleteMatches(data, arraysize(data), &matches); 708 PopulateAutocompleteMatches(data, arraysize(data), &matches);
709 matches[0].inline_autocompletion = base::ASCIIToUTF16("completion"); 709 matches[0].inline_autocompletion = base::ASCIIToUTF16("completion");
710 matches[1].allowed_to_be_default_match = false; 710 matches[1].allowed_to_be_default_match = false;
711 matches[2].allowed_to_be_default_match = false; 711 matches[2].allowed_to_be_default_match = false;
712 matches[3].inline_autocompletion = base::ASCIIToUTF16("completion"); 712 matches[3].inline_autocompletion = base::ASCIIToUTF16("completion");
713 AutocompleteResult result; 713 AutocompleteResult result;
714 result.AppendMatches(matches); 714 result.AppendMatches(matches);
715 AutocompleteInput input(base::string16(), base::string16::npos, 715 AutocompleteInput input(base::string16(), base::string16::npos,
716 base::string16(), GURL(), 716 base::string16(), GURL(),
717 OmniboxEventProto::HOME_PAGE, false, false, false, 717 OmniboxEventProto::HOME_PAGE, false, false, false,
718 true, 718 true,
719 ChromeAutocompleteSchemeClassifier( 719 ChromeAutocompleteSchemeClassifier(
720 test_util_.profile())); 720 test_util_.profile()));
721 result.SortAndCull(input, test_util_.model()); 721 result.SortAndCull(input, test_util_.profile());
722 AssertResultMatches(result, data, 4); 722 AssertResultMatches(result, data, 4);
723 } 723 }
724 724
725 { 725 {
726 // Check a similar situation, except in this case the top match is not 726 // Check a similar situation, except in this case the top match is not
727 // allowed to the default match, so it still needs to be demoted so we 727 // allowed to the default match, so it still needs to be demoted so we
728 // get a legal default match first. That match will have an inline 728 // get a legal default match first. That match will have an inline
729 // autocompletion because we don't have any better options. 729 // autocompletion because we don't have any better options.
730 ACMatches matches; 730 ACMatches matches;
731 PopulateAutocompleteMatches(data, arraysize(data), &matches); 731 PopulateAutocompleteMatches(data, arraysize(data), &matches);
732 matches[0].allowed_to_be_default_match = false; 732 matches[0].allowed_to_be_default_match = false;
733 matches[1].inline_autocompletion = base::ASCIIToUTF16("completion"); 733 matches[1].inline_autocompletion = base::ASCIIToUTF16("completion");
734 matches[2].allowed_to_be_default_match = false; 734 matches[2].allowed_to_be_default_match = false;
735 matches[3].inline_autocompletion = base::ASCIIToUTF16("completion"); 735 matches[3].inline_autocompletion = base::ASCIIToUTF16("completion");
736 AutocompleteResult result; 736 AutocompleteResult result;
737 result.AppendMatches(matches); 737 result.AppendMatches(matches);
738 AutocompleteInput input(base::string16(), base::string16::npos, 738 AutocompleteInput input(base::string16(), base::string16::npos,
739 base::string16(), GURL(), 739 base::string16(), GURL(),
740 OmniboxEventProto::HOME_PAGE, false, false, false, 740 OmniboxEventProto::HOME_PAGE, false, false, false,
741 true, 741 true,
742 ChromeAutocompleteSchemeClassifier( 742 ChromeAutocompleteSchemeClassifier(
743 test_util_.profile())); 743 test_util_.profile()));
744 result.SortAndCull(input, test_util_.model()); 744 result.SortAndCull(input, test_util_.profile());
745 ASSERT_EQ(4U, result.size()); 745 ASSERT_EQ(4U, result.size());
746 EXPECT_EQ("http://b/", result.match_at(0)->destination_url.spec()); 746 EXPECT_EQ("http://b/", result.match_at(0)->destination_url.spec());
747 EXPECT_EQ("http://a/", result.match_at(1)->destination_url.spec()); 747 EXPECT_EQ("http://a/", result.match_at(1)->destination_url.spec());
748 EXPECT_EQ("http://c/", result.match_at(2)->destination_url.spec()); 748 EXPECT_EQ("http://c/", result.match_at(2)->destination_url.spec());
749 EXPECT_EQ("http://d/", result.match_at(3)->destination_url.spec()); 749 EXPECT_EQ("http://d/", result.match_at(3)->destination_url.spec());
750 } 750 }
751 } 751 }
752 752
753 TEST_F(AutocompleteResultTest, ShouldHideTopMatch) { 753 TEST_F(AutocompleteResultTest, ShouldHideTopMatch) {
754 base::FieldTrialList::CreateFieldTrial("InstantExtended", 754 base::FieldTrialList::CreateFieldTrial("InstantExtended",
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
854 result.Reset(); 854 result.Reset();
855 matches.clear(); 855 matches.clear();
856 856
857 // Case 5: Multiple verbatim matches found in AutocompleteResult. 857 // Case 5: Multiple verbatim matches found in AutocompleteResult.
858 PopulateAutocompleteMatchesFromTestData(kVerbatimMatches, 858 PopulateAutocompleteMatchesFromTestData(kVerbatimMatches,
859 arraysize(kVerbatimMatches), 859 arraysize(kVerbatimMatches),
860 &matches); 860 &matches);
861 result.AppendMatches(matches); 861 result.AppendMatches(matches);
862 EXPECT_FALSE(result.ShouldHideTopMatch()); 862 EXPECT_FALSE(result.ShouldHideTopMatch());
863 } 863 }
OLDNEW
« no previous file with comments | « chrome/browser/autocomplete/autocomplete_result.cc ('k') | chrome/browser/autocomplete/base_search_provider.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698