OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/autocomplete/autocomplete_result.h" | 5 #include "chrome/browser/autocomplete/autocomplete_result.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/metrics/field_trial.h" | 10 #include "base/metrics/field_trial.h" |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 const TestData* expected, size_t expected_size) { | 179 const TestData* expected, size_t expected_size) { |
180 AutocompleteInput input(base::ASCIIToUTF16("a"), base::string16::npos, | 180 AutocompleteInput input(base::ASCIIToUTF16("a"), base::string16::npos, |
181 base::string16(), GURL(), | 181 base::string16(), GURL(), |
182 OmniboxEventProto::INVALID_SPEC, false, false, false, | 182 OmniboxEventProto::INVALID_SPEC, false, false, false, |
183 true, test_util_.profile()); | 183 true, test_util_.profile()); |
184 | 184 |
185 ACMatches last_matches; | 185 ACMatches last_matches; |
186 PopulateAutocompleteMatches(last, last_size, &last_matches); | 186 PopulateAutocompleteMatches(last, last_size, &last_matches); |
187 AutocompleteResult last_result; | 187 AutocompleteResult last_result; |
188 last_result.AppendMatches(last_matches); | 188 last_result.AppendMatches(last_matches); |
189 last_result.SortAndCull(input, test_util_.profile()); | 189 last_result.SortAndCull(input, test_util_.model()); |
190 | 190 |
191 ACMatches current_matches; | 191 ACMatches current_matches; |
192 PopulateAutocompleteMatches(current, current_size, ¤t_matches); | 192 PopulateAutocompleteMatches(current, current_size, ¤t_matches); |
193 AutocompleteResult current_result; | 193 AutocompleteResult current_result; |
194 current_result.AppendMatches(current_matches); | 194 current_result.AppendMatches(current_matches); |
195 current_result.SortAndCull(input, test_util_.profile()); | 195 current_result.SortAndCull(input, test_util_.model()); |
196 current_result.CopyOldMatches(input, last_result, test_util_.profile()); | 196 current_result.CopyOldMatches(input, last_result, test_util_.model()); |
197 | 197 |
198 AssertResultMatches(current_result, expected, expected_size); | 198 AssertResultMatches(current_result, expected, expected_size); |
199 } | 199 } |
200 | 200 |
201 // Assertion testing for AutocompleteResult::Swap. | 201 // Assertion testing for AutocompleteResult::Swap. |
202 TEST_F(AutocompleteResultTest, Swap) { | 202 TEST_F(AutocompleteResultTest, Swap) { |
203 AutocompleteResult r1; | 203 AutocompleteResult r1; |
204 AutocompleteResult r2; | 204 AutocompleteResult r2; |
205 | 205 |
206 // Swap with empty shouldn't do anything interesting. | 206 // Swap with empty shouldn't do anything interesting. |
207 r1.Swap(&r2); | 207 r1.Swap(&r2); |
208 EXPECT_EQ(r1.end(), r1.default_match()); | 208 EXPECT_EQ(r1.end(), r1.default_match()); |
209 EXPECT_EQ(r2.end(), r2.default_match()); | 209 EXPECT_EQ(r2.end(), r2.default_match()); |
210 | 210 |
211 // Swap with a single match. | 211 // Swap with a single match. |
212 ACMatches matches; | 212 ACMatches matches; |
213 AutocompleteMatch match; | 213 AutocompleteMatch match; |
214 match.relevance = 1; | 214 match.relevance = 1; |
215 match.allowed_to_be_default_match = true; | 215 match.allowed_to_be_default_match = true; |
216 AutocompleteInput input(base::ASCIIToUTF16("a"), base::string16::npos, | 216 AutocompleteInput input(base::ASCIIToUTF16("a"), base::string16::npos, |
217 base::string16(), GURL(), | 217 base::string16(), GURL(), |
218 OmniboxEventProto::INVALID_SPEC, false, false, false, | 218 OmniboxEventProto::INVALID_SPEC, false, false, false, |
219 true, test_util_.profile()); | 219 true, test_util_.profile()); |
220 matches.push_back(match); | 220 matches.push_back(match); |
221 r1.AppendMatches(matches); | 221 r1.AppendMatches(matches); |
222 r1.SortAndCull(input, test_util_.profile()); | 222 r1.SortAndCull(input, test_util_.model()); |
223 EXPECT_EQ(r1.begin(), r1.default_match()); | 223 EXPECT_EQ(r1.begin(), r1.default_match()); |
224 EXPECT_EQ("http://a/", r1.alternate_nav_url().spec()); | 224 EXPECT_EQ("http://a/", r1.alternate_nav_url().spec()); |
225 r1.Swap(&r2); | 225 r1.Swap(&r2); |
226 EXPECT_TRUE(r1.empty()); | 226 EXPECT_TRUE(r1.empty()); |
227 EXPECT_EQ(r1.end(), r1.default_match()); | 227 EXPECT_EQ(r1.end(), r1.default_match()); |
228 EXPECT_TRUE(r1.alternate_nav_url().is_empty()); | 228 EXPECT_TRUE(r1.alternate_nav_url().is_empty()); |
229 ASSERT_FALSE(r2.empty()); | 229 ASSERT_FALSE(r2.empty()); |
230 EXPECT_EQ(r2.begin(), r2.default_match()); | 230 EXPECT_EQ(r2.begin(), r2.default_match()); |
231 EXPECT_EQ("http://a/", r2.alternate_nav_url().spec()); | 231 EXPECT_EQ("http://a/", r2.alternate_nav_url().spec()); |
232 } | 232 } |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 matches[1].destination_url = GURL(); | 293 matches[1].destination_url = GURL(); |
294 matches[3].destination_url = GURL(); | 294 matches[3].destination_url = GURL(); |
295 matches[4].destination_url = GURL(); | 295 matches[4].destination_url = GURL(); |
296 | 296 |
297 AutocompleteResult result; | 297 AutocompleteResult result; |
298 result.AppendMatches(matches); | 298 result.AppendMatches(matches); |
299 AutocompleteInput input(base::string16(), base::string16::npos, | 299 AutocompleteInput input(base::string16(), base::string16::npos, |
300 base::string16(), GURL(), | 300 base::string16(), GURL(), |
301 OmniboxEventProto::INVALID_SPEC, false, false, false, | 301 OmniboxEventProto::INVALID_SPEC, false, false, false, |
302 true, test_util_.profile()); | 302 true, test_util_.profile()); |
303 result.SortAndCull(input, test_util_.profile()); | 303 result.SortAndCull(input, test_util_.model()); |
304 | 304 |
305 // 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 |
306 // 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 |
307 // should be kept. | 307 // should be kept. |
308 ASSERT_EQ(4U, result.size()); | 308 ASSERT_EQ(4U, result.size()); |
309 EXPECT_TRUE(result.match_at(0)->destination_url.is_empty()); | 309 EXPECT_TRUE(result.match_at(0)->destination_url.is_empty()); |
310 EXPECT_EQ(1300, result.match_at(0)->relevance); | 310 EXPECT_EQ(1300, result.match_at(0)->relevance); |
311 EXPECT_TRUE(result.match_at(1)->destination_url.is_empty()); | 311 EXPECT_TRUE(result.match_at(1)->destination_url.is_empty()); |
312 EXPECT_EQ(1200, result.match_at(1)->relevance); | 312 EXPECT_EQ(1200, result.match_at(1)->relevance); |
313 EXPECT_TRUE(result.match_at(2)->destination_url.is_empty()); | 313 EXPECT_TRUE(result.match_at(2)->destination_url.is_empty()); |
(...skipping 25 matching lines...) Expand all Loading... |
339 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"); |
340 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"); |
341 matches[4].destination_url = GURL("http://www.foo.com/"); | 341 matches[4].destination_url = GURL("http://www.foo.com/"); |
342 | 342 |
343 AutocompleteResult result; | 343 AutocompleteResult result; |
344 result.AppendMatches(matches); | 344 result.AppendMatches(matches); |
345 AutocompleteInput input(base::string16(), base::string16::npos, | 345 AutocompleteInput input(base::string16(), base::string16::npos, |
346 base::string16(), GURL(), | 346 base::string16(), GURL(), |
347 OmniboxEventProto::INVALID_SPEC, false, false, false, | 347 OmniboxEventProto::INVALID_SPEC, false, false, false, |
348 true, test_util_.profile()); | 348 true, test_util_.profile()); |
349 result.SortAndCull(input, test_util_.profile()); | 349 result.SortAndCull(input, test_util_.model()); |
350 | 350 |
351 // We expect the 3rd and 4th results to be removed. | 351 // We expect the 3rd and 4th results to be removed. |
352 ASSERT_EQ(3U, result.size()); | 352 ASSERT_EQ(3U, result.size()); |
353 EXPECT_EQ("http://www.foo.com/s?q=foo", | 353 EXPECT_EQ("http://www.foo.com/s?q=foo", |
354 result.match_at(0)->destination_url.spec()); | 354 result.match_at(0)->destination_url.spec()); |
355 EXPECT_EQ(1300, result.match_at(0)->relevance); | 355 EXPECT_EQ(1300, result.match_at(0)->relevance); |
356 EXPECT_EQ("http://www.foo.com/s?q=foo2", | 356 EXPECT_EQ("http://www.foo.com/s?q=foo2", |
357 result.match_at(1)->destination_url.spec()); | 357 result.match_at(1)->destination_url.spec()); |
358 EXPECT_EQ(1200, result.match_at(1)->relevance); | 358 EXPECT_EQ(1200, result.match_at(1)->relevance); |
359 EXPECT_EQ("http://www.foo.com/", | 359 EXPECT_EQ("http://www.foo.com/", |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
391 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"); |
392 matches[4].destination_url = GURL("http://www.foo.com/"); | 392 matches[4].destination_url = GURL("http://www.foo.com/"); |
393 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"); |
394 | 394 |
395 AutocompleteResult result; | 395 AutocompleteResult result; |
396 result.AppendMatches(matches); | 396 result.AppendMatches(matches); |
397 AutocompleteInput input(base::string16(), base::string16::npos, | 397 AutocompleteInput input(base::string16(), base::string16::npos, |
398 base::string16(), GURL(), | 398 base::string16(), GURL(), |
399 OmniboxEventProto::INVALID_SPEC, false, false, false, | 399 OmniboxEventProto::INVALID_SPEC, false, false, false, |
400 true, test_util_.profile()); | 400 true, test_util_.profile()); |
401 result.SortAndCull(input, test_util_.profile()); | 401 result.SortAndCull(input, test_util_.model()); |
402 | 402 |
403 // Expect 3 unique results after SortAndCull(). | 403 // Expect 3 unique results after SortAndCull(). |
404 ASSERT_EQ(3U, result.size()); | 404 ASSERT_EQ(3U, result.size()); |
405 | 405 |
406 // 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 |
407 // and also duplicates of the 4th match got copied. | 407 // and also duplicates of the 4th match got copied. |
408 ASSERT_EQ(4U, result.match_at(0)->duplicate_matches.size()); | 408 ASSERT_EQ(4U, result.match_at(0)->duplicate_matches.size()); |
409 const AutocompleteMatch* first_match = result.match_at(0); | 409 const AutocompleteMatch* first_match = result.match_at(0); |
410 EXPECT_EQ(matches[2].destination_url, | 410 EXPECT_EQ(matches[2].destination_url, |
411 first_match->duplicate_matches.at(1).destination_url); | 411 first_match->duplicate_matches.at(1).destination_url); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
445 } | 445 } |
446 base::FieldTrialList::CreateFieldTrial( | 446 base::FieldTrialList::CreateFieldTrial( |
447 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "A"); | 447 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "A"); |
448 | 448 |
449 AutocompleteResult result; | 449 AutocompleteResult result; |
450 result.AppendMatches(matches); | 450 result.AppendMatches(matches); |
451 AutocompleteInput input(base::string16(), base::string16::npos, | 451 AutocompleteInput input(base::string16(), base::string16::npos, |
452 base::string16(), GURL(), | 452 base::string16(), GURL(), |
453 OmniboxEventProto::HOME_PAGE, false, false, false, | 453 OmniboxEventProto::HOME_PAGE, false, false, false, |
454 true, test_util_.profile()); | 454 true, test_util_.profile()); |
455 result.SortAndCull(input, test_util_.profile()); | 455 result.SortAndCull(input, test_util_.model()); |
456 | 456 |
457 // Check the new ordering. The history-title results should be omitted. | 457 // Check the new ordering. The history-title results should be omitted. |
458 // We cannot check relevance scores because the matches are sorted by | 458 // We cannot check relevance scores because the matches are sorted by |
459 // demoted relevance but the actual relevance scores are not modified. | 459 // demoted relevance but the actual relevance scores are not modified. |
460 ASSERT_EQ(3u, result.size()); | 460 ASSERT_EQ(3u, result.size()); |
461 EXPECT_EQ("http://search-what-you-typed/", | 461 EXPECT_EQ("http://search-what-you-typed/", |
462 result.match_at(0)->destination_url.spec()); | 462 result.match_at(0)->destination_url.spec()); |
463 EXPECT_EQ("http://history-url/", | 463 EXPECT_EQ("http://history-url/", |
464 result.match_at(1)->destination_url.spec()); | 464 result.match_at(1)->destination_url.spec()); |
465 EXPECT_EQ("http://search-history/", | 465 EXPECT_EQ("http://search-history/", |
(...skipping 24 matching lines...) Expand all Loading... |
490 base::FieldTrialList::CreateFieldTrial( | 490 base::FieldTrialList::CreateFieldTrial( |
491 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "C"); | 491 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "C"); |
492 | 492 |
493 { | 493 { |
494 AutocompleteResult result; | 494 AutocompleteResult result; |
495 result.AppendMatches(matches); | 495 result.AppendMatches(matches); |
496 AutocompleteInput input( | 496 AutocompleteInput input( |
497 base::string16(), base::string16::npos, base::string16(), GURL(), | 497 base::string16(), base::string16::npos, base::string16(), GURL(), |
498 OmniboxEventProto::INSTANT_NTP_WITH_FAKEBOX_AS_STARTING_FOCUS, false, | 498 OmniboxEventProto::INSTANT_NTP_WITH_FAKEBOX_AS_STARTING_FOCUS, false, |
499 false, false, true, test_util_.profile()); | 499 false, false, true, test_util_.profile()); |
500 result.SortAndCull(input, test_util_.profile()); | 500 result.SortAndCull(input, test_util_.model()); |
501 | 501 |
502 // The NAVSUGGEST dup-url stay above search-url since the navsuggest | 502 // The NAVSUGGEST dup-url stay above search-url since the navsuggest |
503 // variant should not be demoted. | 503 // variant should not be demoted. |
504 ASSERT_EQ(4u, result.size()); | 504 ASSERT_EQ(4u, result.size()); |
505 EXPECT_EQ("http://search-what-you-typed/", | 505 EXPECT_EQ("http://search-what-you-typed/", |
506 result.match_at(0)->destination_url.spec()); | 506 result.match_at(0)->destination_url.spec()); |
507 EXPECT_EQ("http://dup-url/", | 507 EXPECT_EQ("http://dup-url/", |
508 result.match_at(1)->destination_url.spec()); | 508 result.match_at(1)->destination_url.spec()); |
509 EXPECT_EQ(AutocompleteMatchType::NAVSUGGEST, | 509 EXPECT_EQ(AutocompleteMatchType::NAVSUGGEST, |
510 result.match_at(1)->type); | 510 result.match_at(1)->type); |
(...skipping 17 matching lines...) Expand all Loading... |
528 // is already a legal default match (which is the default from | 528 // is already a legal default match (which is the default from |
529 // PopulateAutocompleteMatches()). | 529 // PopulateAutocompleteMatches()). |
530 ACMatches matches; | 530 ACMatches matches; |
531 PopulateAutocompleteMatches(data, arraysize(data), &matches); | 531 PopulateAutocompleteMatches(data, arraysize(data), &matches); |
532 AutocompleteResult result; | 532 AutocompleteResult result; |
533 result.AppendMatches(matches); | 533 result.AppendMatches(matches); |
534 AutocompleteInput input(base::string16(), base::string16::npos, | 534 AutocompleteInput input(base::string16(), base::string16::npos, |
535 base::string16(), GURL(), | 535 base::string16(), GURL(), |
536 OmniboxEventProto::HOME_PAGE, false, false, false, | 536 OmniboxEventProto::HOME_PAGE, false, false, false, |
537 true, test_util_.profile()); | 537 true, test_util_.profile()); |
538 result.SortAndCull(input, test_util_.profile()); | 538 result.SortAndCull(input, test_util_.model()); |
539 AssertResultMatches(result, data, 4); | 539 AssertResultMatches(result, data, 4); |
540 } | 540 } |
541 | 541 |
542 { | 542 { |
543 // Check that reorder swaps up a result appropriately. | 543 // Check that reorder swaps up a result appropriately. |
544 ACMatches matches; | 544 ACMatches matches; |
545 PopulateAutocompleteMatches(data, arraysize(data), &matches); | 545 PopulateAutocompleteMatches(data, arraysize(data), &matches); |
546 matches[0].allowed_to_be_default_match = false; | 546 matches[0].allowed_to_be_default_match = false; |
547 matches[1].allowed_to_be_default_match = false; | 547 matches[1].allowed_to_be_default_match = false; |
548 AutocompleteResult result; | 548 AutocompleteResult result; |
549 result.AppendMatches(matches); | 549 result.AppendMatches(matches); |
550 AutocompleteInput input(base::string16(), base::string16::npos, | 550 AutocompleteInput input(base::string16(), base::string16::npos, |
551 base::string16(), GURL(), | 551 base::string16(), GURL(), |
552 OmniboxEventProto::HOME_PAGE, false, false, false, | 552 OmniboxEventProto::HOME_PAGE, false, false, false, |
553 true, test_util_.profile()); | 553 true, test_util_.profile()); |
554 result.SortAndCull(input, test_util_.profile()); | 554 result.SortAndCull(input, test_util_.model()); |
555 ASSERT_EQ(4U, result.size()); | 555 ASSERT_EQ(4U, result.size()); |
556 EXPECT_EQ("http://c/", result.match_at(0)->destination_url.spec()); | 556 EXPECT_EQ("http://c/", result.match_at(0)->destination_url.spec()); |
557 EXPECT_EQ("http://a/", result.match_at(1)->destination_url.spec()); | 557 EXPECT_EQ("http://a/", result.match_at(1)->destination_url.spec()); |
558 EXPECT_EQ("http://b/", result.match_at(2)->destination_url.spec()); | 558 EXPECT_EQ("http://b/", result.match_at(2)->destination_url.spec()); |
559 EXPECT_EQ("http://d/", result.match_at(3)->destination_url.spec()); | 559 EXPECT_EQ("http://d/", result.match_at(3)->destination_url.spec()); |
560 } | 560 } |
561 } | 561 } |
562 | 562 |
563 | 563 |
564 | 564 |
(...skipping 10 matching lines...) Expand all Loading... |
575 // first even if it has an inline autocompletion. | 575 // first even if it has an inline autocompletion. |
576 ACMatches matches; | 576 ACMatches matches; |
577 PopulateAutocompleteMatches(data, arraysize(data), &matches); | 577 PopulateAutocompleteMatches(data, arraysize(data), &matches); |
578 matches[0].inline_autocompletion = base::ASCIIToUTF16("completion"); | 578 matches[0].inline_autocompletion = base::ASCIIToUTF16("completion"); |
579 AutocompleteResult result; | 579 AutocompleteResult result; |
580 result.AppendMatches(matches); | 580 result.AppendMatches(matches); |
581 AutocompleteInput input(base::string16(), base::string16::npos, | 581 AutocompleteInput input(base::string16(), base::string16::npos, |
582 base::string16(), GURL(), | 582 base::string16(), GURL(), |
583 OmniboxEventProto::HOME_PAGE, false, false, false, | 583 OmniboxEventProto::HOME_PAGE, false, false, false, |
584 true, test_util_.profile()); | 584 true, test_util_.profile()); |
585 result.SortAndCull(input, test_util_.profile()); | 585 result.SortAndCull(input, test_util_.model()); |
586 AssertResultMatches(result, data, 4); | 586 AssertResultMatches(result, data, 4); |
587 } | 587 } |
588 | 588 |
589 // Enable the field trial to disable inlining. | 589 // Enable the field trial to disable inlining. |
590 { | 590 { |
591 std::map<std::string, std::string> params; | 591 std::map<std::string, std::string> params; |
592 params[OmniboxFieldTrial::kDisableInliningRule] = "true"; | 592 params[OmniboxFieldTrial::kDisableInliningRule] = "true"; |
593 ASSERT_TRUE(chrome_variations::AssociateVariationParams( | 593 ASSERT_TRUE(chrome_variations::AssociateVariationParams( |
594 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "D", params)); | 594 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "D", params)); |
595 } | 595 } |
596 base::FieldTrialList::CreateFieldTrial( | 596 base::FieldTrialList::CreateFieldTrial( |
597 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "D"); | 597 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "D"); |
598 | 598 |
599 { | 599 { |
600 // Now the first match should be demoted past the second. | 600 // Now the first match should be demoted past the second. |
601 ACMatches matches; | 601 ACMatches matches; |
602 PopulateAutocompleteMatches(data, arraysize(data), &matches); | 602 PopulateAutocompleteMatches(data, arraysize(data), &matches); |
603 matches[0].inline_autocompletion = base::ASCIIToUTF16("completion"); | 603 matches[0].inline_autocompletion = base::ASCIIToUTF16("completion"); |
604 AutocompleteResult result; | 604 AutocompleteResult result; |
605 result.AppendMatches(matches); | 605 result.AppendMatches(matches); |
606 AutocompleteInput input(base::string16(), base::string16::npos, | 606 AutocompleteInput input(base::string16(), base::string16::npos, |
607 base::string16(), GURL(), | 607 base::string16(), GURL(), |
608 OmniboxEventProto::HOME_PAGE, false, false, false, | 608 OmniboxEventProto::HOME_PAGE, false, false, false, |
609 true, test_util_.profile()); | 609 true, test_util_.profile()); |
610 result.SortAndCull(input, test_util_.profile()); | 610 result.SortAndCull(input, test_util_.model()); |
611 ASSERT_EQ(4U, result.size()); | 611 ASSERT_EQ(4U, result.size()); |
612 EXPECT_EQ("http://b/", result.match_at(0)->destination_url.spec()); | 612 EXPECT_EQ("http://b/", result.match_at(0)->destination_url.spec()); |
613 EXPECT_EQ("http://a/", result.match_at(1)->destination_url.spec()); | 613 EXPECT_EQ("http://a/", result.match_at(1)->destination_url.spec()); |
614 EXPECT_EQ("http://c/", result.match_at(2)->destination_url.spec()); | 614 EXPECT_EQ("http://c/", result.match_at(2)->destination_url.spec()); |
615 EXPECT_EQ("http://d/", result.match_at(3)->destination_url.spec()); | 615 EXPECT_EQ("http://d/", result.match_at(3)->destination_url.spec()); |
616 } | 616 } |
617 | 617 |
618 { | 618 { |
619 // 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 |
620 // 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 |
621 // inline autocompletions elsewhere. | 621 // inline autocompletions elsewhere. |
622 ACMatches matches; | 622 ACMatches matches; |
623 PopulateAutocompleteMatches(data, arraysize(data), &matches); | 623 PopulateAutocompleteMatches(data, arraysize(data), &matches); |
624 matches[2].inline_autocompletion = base::ASCIIToUTF16("completion"); | 624 matches[2].inline_autocompletion = base::ASCIIToUTF16("completion"); |
625 AutocompleteResult result; | 625 AutocompleteResult result; |
626 result.AppendMatches(matches); | 626 result.AppendMatches(matches); |
627 AutocompleteInput input(base::string16(), base::string16::npos, | 627 AutocompleteInput input(base::string16(), base::string16::npos, |
628 base::string16(), GURL(), | 628 base::string16(), GURL(), |
629 OmniboxEventProto::HOME_PAGE, false, false, false, | 629 OmniboxEventProto::HOME_PAGE, false, false, false, |
630 true, test_util_.profile()); | 630 true, test_util_.profile()); |
631 result.SortAndCull(input, test_util_.profile()); | 631 result.SortAndCull(input, test_util_.model()); |
632 AssertResultMatches(result, data, 4); | 632 AssertResultMatches(result, data, 4); |
633 } | 633 } |
634 | 634 |
635 { | 635 { |
636 // Try a more complicated situation. | 636 // Try a more complicated situation. |
637 ACMatches matches; | 637 ACMatches matches; |
638 PopulateAutocompleteMatches(data, arraysize(data), &matches); | 638 PopulateAutocompleteMatches(data, arraysize(data), &matches); |
639 matches[0].allowed_to_be_default_match = false; | 639 matches[0].allowed_to_be_default_match = false; |
640 matches[1].inline_autocompletion = base::ASCIIToUTF16("completion"); | 640 matches[1].inline_autocompletion = base::ASCIIToUTF16("completion"); |
641 AutocompleteResult result; | 641 AutocompleteResult result; |
642 result.AppendMatches(matches); | 642 result.AppendMatches(matches); |
643 AutocompleteInput input(base::string16(), base::string16::npos, | 643 AutocompleteInput input(base::string16(), base::string16::npos, |
644 base::string16(), GURL(), | 644 base::string16(), GURL(), |
645 OmniboxEventProto::HOME_PAGE, false, false, false, | 645 OmniboxEventProto::HOME_PAGE, false, false, false, |
646 true, test_util_.profile()); | 646 true, test_util_.profile()); |
647 result.SortAndCull(input, test_util_.profile()); | 647 result.SortAndCull(input, test_util_.model()); |
648 ASSERT_EQ(4U, result.size()); | 648 ASSERT_EQ(4U, result.size()); |
649 EXPECT_EQ("http://c/", result.match_at(0)->destination_url.spec()); | 649 EXPECT_EQ("http://c/", result.match_at(0)->destination_url.spec()); |
650 EXPECT_EQ("http://a/", result.match_at(1)->destination_url.spec()); | 650 EXPECT_EQ("http://a/", result.match_at(1)->destination_url.spec()); |
651 EXPECT_EQ("http://b/", result.match_at(2)->destination_url.spec()); | 651 EXPECT_EQ("http://b/", result.match_at(2)->destination_url.spec()); |
652 EXPECT_EQ("http://d/", result.match_at(3)->destination_url.spec()); | 652 EXPECT_EQ("http://d/", result.match_at(3)->destination_url.spec()); |
653 } | 653 } |
654 | 654 |
655 { | 655 { |
656 // Try another complicated situation. | 656 // Try another complicated situation. |
657 ACMatches matches; | 657 ACMatches matches; |
658 PopulateAutocompleteMatches(data, arraysize(data), &matches); | 658 PopulateAutocompleteMatches(data, arraysize(data), &matches); |
659 matches[0].inline_autocompletion = base::ASCIIToUTF16("completion"); | 659 matches[0].inline_autocompletion = base::ASCIIToUTF16("completion"); |
660 matches[1].allowed_to_be_default_match = false; | 660 matches[1].allowed_to_be_default_match = false; |
661 AutocompleteResult result; | 661 AutocompleteResult result; |
662 result.AppendMatches(matches); | 662 result.AppendMatches(matches); |
663 AutocompleteInput input(base::string16(), base::string16::npos, | 663 AutocompleteInput input(base::string16(), base::string16::npos, |
664 base::string16(), GURL(), | 664 base::string16(), GURL(), |
665 OmniboxEventProto::HOME_PAGE, false, false, false, | 665 OmniboxEventProto::HOME_PAGE, false, false, false, |
666 true, test_util_.profile()); | 666 true, test_util_.profile()); |
667 result.SortAndCull(input, test_util_.profile()); | 667 result.SortAndCull(input, test_util_.model()); |
668 ASSERT_EQ(4U, result.size()); | 668 ASSERT_EQ(4U, result.size()); |
669 EXPECT_EQ("http://c/", result.match_at(0)->destination_url.spec()); | 669 EXPECT_EQ("http://c/", result.match_at(0)->destination_url.spec()); |
670 EXPECT_EQ("http://a/", result.match_at(1)->destination_url.spec()); | 670 EXPECT_EQ("http://a/", result.match_at(1)->destination_url.spec()); |
671 EXPECT_EQ("http://b/", result.match_at(2)->destination_url.spec()); | 671 EXPECT_EQ("http://b/", result.match_at(2)->destination_url.spec()); |
672 EXPECT_EQ("http://d/", result.match_at(3)->destination_url.spec()); | 672 EXPECT_EQ("http://d/", result.match_at(3)->destination_url.spec()); |
673 } | 673 } |
674 | 674 |
675 { | 675 { |
676 // 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 |
677 // autocompletion because every match either has a completion or isn't | 677 // autocompletion because every match either has a completion or isn't |
678 // 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 |
679 // everything untouched. | 679 // everything untouched. |
680 ACMatches matches; | 680 ACMatches matches; |
681 PopulateAutocompleteMatches(data, arraysize(data), &matches); | 681 PopulateAutocompleteMatches(data, arraysize(data), &matches); |
682 matches[0].inline_autocompletion = base::ASCIIToUTF16("completion"); | 682 matches[0].inline_autocompletion = base::ASCIIToUTF16("completion"); |
683 matches[1].allowed_to_be_default_match = false; | 683 matches[1].allowed_to_be_default_match = false; |
684 matches[2].allowed_to_be_default_match = false; | 684 matches[2].allowed_to_be_default_match = false; |
685 matches[3].inline_autocompletion = base::ASCIIToUTF16("completion"); | 685 matches[3].inline_autocompletion = base::ASCIIToUTF16("completion"); |
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, test_util_.profile()); | 691 true, test_util_.profile()); |
692 result.SortAndCull(input, test_util_.profile()); | 692 result.SortAndCull(input, test_util_.model()); |
693 AssertResultMatches(result, data, 4); | 693 AssertResultMatches(result, data, 4); |
694 } | 694 } |
695 | 695 |
696 { | 696 { |
697 // 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 |
698 // 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 |
699 // 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 |
700 // autocompletion because we don't have any better options. | 700 // autocompletion because we don't have any better options. |
701 ACMatches matches; | 701 ACMatches matches; |
702 PopulateAutocompleteMatches(data, arraysize(data), &matches); | 702 PopulateAutocompleteMatches(data, arraysize(data), &matches); |
703 matches[0].allowed_to_be_default_match = false; | 703 matches[0].allowed_to_be_default_match = false; |
704 matches[1].inline_autocompletion = base::ASCIIToUTF16("completion"); | 704 matches[1].inline_autocompletion = base::ASCIIToUTF16("completion"); |
705 matches[2].allowed_to_be_default_match = false; | 705 matches[2].allowed_to_be_default_match = false; |
706 matches[3].inline_autocompletion = base::ASCIIToUTF16("completion"); | 706 matches[3].inline_autocompletion = base::ASCIIToUTF16("completion"); |
707 AutocompleteResult result; | 707 AutocompleteResult result; |
708 result.AppendMatches(matches); | 708 result.AppendMatches(matches); |
709 AutocompleteInput input(base::string16(), base::string16::npos, | 709 AutocompleteInput input(base::string16(), base::string16::npos, |
710 base::string16(), GURL(), | 710 base::string16(), GURL(), |
711 OmniboxEventProto::HOME_PAGE, false, false, false, | 711 OmniboxEventProto::HOME_PAGE, false, false, false, |
712 true, test_util_.profile()); | 712 true, test_util_.profile()); |
713 result.SortAndCull(input, test_util_.profile()); | 713 result.SortAndCull(input, test_util_.model()); |
714 ASSERT_EQ(4U, result.size()); | 714 ASSERT_EQ(4U, result.size()); |
715 EXPECT_EQ("http://b/", result.match_at(0)->destination_url.spec()); | 715 EXPECT_EQ("http://b/", result.match_at(0)->destination_url.spec()); |
716 EXPECT_EQ("http://a/", result.match_at(1)->destination_url.spec()); | 716 EXPECT_EQ("http://a/", result.match_at(1)->destination_url.spec()); |
717 EXPECT_EQ("http://c/", result.match_at(2)->destination_url.spec()); | 717 EXPECT_EQ("http://c/", result.match_at(2)->destination_url.spec()); |
718 EXPECT_EQ("http://d/", result.match_at(3)->destination_url.spec()); | 718 EXPECT_EQ("http://d/", result.match_at(3)->destination_url.spec()); |
719 } | 719 } |
720 } | 720 } |
721 | 721 |
722 TEST_F(AutocompleteResultTest, ShouldHideTopMatch) { | 722 TEST_F(AutocompleteResultTest, ShouldHideTopMatch) { |
723 base::FieldTrialList::CreateFieldTrial("InstantExtended", | 723 base::FieldTrialList::CreateFieldTrial("InstantExtended", |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
823 result.Reset(); | 823 result.Reset(); |
824 matches.clear(); | 824 matches.clear(); |
825 | 825 |
826 // Case 5: Multiple verbatim matches found in AutocompleteResult. | 826 // Case 5: Multiple verbatim matches found in AutocompleteResult. |
827 PopulateAutocompleteMatchesFromTestData(kVerbatimMatches, | 827 PopulateAutocompleteMatchesFromTestData(kVerbatimMatches, |
828 arraysize(kVerbatimMatches), | 828 arraysize(kVerbatimMatches), |
829 &matches); | 829 &matches); |
830 result.AppendMatches(matches); | 830 result.AppendMatches(matches); |
831 EXPECT_FALSE(result.ShouldHideTopMatch()); | 831 EXPECT_FALSE(result.ShouldHideTopMatch()); |
832 } | 832 } |
OLD | NEW |