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 "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "base/metrics/field_trial.h" | 8 #include "base/metrics/field_trial.h" |
9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
370 // demoted relevance but the actual relevance scores are not modified. | 370 // demoted relevance but the actual relevance scores are not modified. |
371 ASSERT_EQ(3u, result.size()); | 371 ASSERT_EQ(3u, result.size()); |
372 EXPECT_EQ("http://search-what-you-typed/", | 372 EXPECT_EQ("http://search-what-you-typed/", |
373 result.match_at(0)->destination_url.spec()); | 373 result.match_at(0)->destination_url.spec()); |
374 EXPECT_EQ("http://history-url/", | 374 EXPECT_EQ("http://history-url/", |
375 result.match_at(1)->destination_url.spec()); | 375 result.match_at(1)->destination_url.spec()); |
376 EXPECT_EQ("http://search-history/", | 376 EXPECT_EQ("http://search-history/", |
377 result.match_at(2)->destination_url.spec()); | 377 result.match_at(2)->destination_url.spec()); |
378 } | 378 } |
379 | 379 |
| 380 TEST_F(AutocompleteResultTest, SortAndCullWithUndemotableTypes) { |
| 381 // Add some matches. |
| 382 ACMatches matches; |
| 383 { |
| 384 AutocompleteMatch match; |
| 385 match.destination_url = GURL("http://history-url/"); |
| 386 match.relevance = 1400; |
| 387 match.allowed_to_be_default_match = true; |
| 388 match.type = AutocompleteMatchType::HISTORY_URL; |
| 389 matches.push_back(match); |
| 390 } |
| 391 { |
| 392 AutocompleteMatch match; |
| 393 match.destination_url = GURL("http://history-url2/"); |
| 394 match.relevance = 1300; |
| 395 match.allowed_to_be_default_match = true; |
| 396 match.type = AutocompleteMatchType::HISTORY_URL; |
| 397 matches.push_back(match); |
| 398 } |
| 399 { |
| 400 AutocompleteMatch match; |
| 401 match.destination_url = GURL("http://search-what-you-typed/"); |
| 402 match.relevance = 1200; |
| 403 match.allowed_to_be_default_match = true; |
| 404 match.type = AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED; |
| 405 matches.push_back(match); |
| 406 } |
| 407 |
| 408 // Add a rule demoting history-url, but don't demote the top match. |
| 409 { |
| 410 std::map<std::string, std::string> params; |
| 411 params[std::string(OmniboxFieldTrial::kDemoteByTypeRule) + ":3:*"] = |
| 412 "1:50"; // 3 == HOME_PAGE |
| 413 params[std::string(OmniboxFieldTrial::kUndemotableTopTypeRule) + ":3:*"] = |
| 414 "1,5"; // 3 == HOME_PAGE |
| 415 ASSERT_TRUE(chrome_variations::AssociateVariationParams( |
| 416 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "B", params)); |
| 417 } |
| 418 base::FieldTrialList::CreateFieldTrial( |
| 419 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "B"); |
| 420 |
| 421 AutocompleteResult result; |
| 422 result.AppendMatches(matches); |
| 423 AutocompleteInput input(string16(), string16::npos, string16(), GURL(), |
| 424 AutocompleteInput::HOME_PAGE, false, false, false, |
| 425 AutocompleteInput::ALL_MATCHES); |
| 426 result.SortAndCull(input, test_util_.profile()); |
| 427 |
| 428 // Check the new ordering. The first history-url result should not be |
| 429 // demoted, but the second result should be. |
| 430 // We cannot check relevance scores because the matches are sorted by |
| 431 // demoted relevance but the actual relevance scores are not modified. |
| 432 ASSERT_EQ(3u, result.size()); |
| 433 EXPECT_EQ("http://history-url/", |
| 434 result.match_at(0)->destination_url.spec()); |
| 435 EXPECT_EQ("http://search-what-you-typed/", |
| 436 result.match_at(1)->destination_url.spec()); |
| 437 EXPECT_EQ("http://history-url2/", |
| 438 result.match_at(2)->destination_url.spec()); |
| 439 } |
| 440 |
380 TEST_F(AutocompleteResultTest, SortAndCullReorderForDefaultMatch) { | 441 TEST_F(AutocompleteResultTest, SortAndCullReorderForDefaultMatch) { |
381 TestData data[] = { | 442 TestData data[] = { |
382 { 0, 0, 1300 }, | 443 { 0, 0, 1300 }, |
383 { 1, 0, 1200 }, | 444 { 1, 0, 1200 }, |
384 { 2, 0, 1100 }, | 445 { 2, 0, 1100 }, |
385 { 3, 0, 1000 } | 446 { 3, 0, 1000 } |
386 }; | 447 }; |
387 | 448 |
388 std::map<std::string, std::string> params; | 449 std::map<std::string, std::string> params; |
389 // Enable reorder for omnibox inputs on the user's home page. | 450 // Enable reorder for omnibox inputs on the user's home page. |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
421 AutocompleteInput::HOME_PAGE, false, false, false, | 482 AutocompleteInput::HOME_PAGE, false, false, false, |
422 AutocompleteInput::ALL_MATCHES); | 483 AutocompleteInput::ALL_MATCHES); |
423 result.SortAndCull(input, test_util_.profile()); | 484 result.SortAndCull(input, test_util_.profile()); |
424 ASSERT_EQ(4U, result.size()); | 485 ASSERT_EQ(4U, result.size()); |
425 EXPECT_EQ("http://c/", result.match_at(0)->destination_url.spec()); | 486 EXPECT_EQ("http://c/", result.match_at(0)->destination_url.spec()); |
426 EXPECT_EQ("http://a/", result.match_at(1)->destination_url.spec()); | 487 EXPECT_EQ("http://a/", result.match_at(1)->destination_url.spec()); |
427 EXPECT_EQ("http://b/", result.match_at(2)->destination_url.spec()); | 488 EXPECT_EQ("http://b/", result.match_at(2)->destination_url.spec()); |
428 EXPECT_EQ("http://d/", result.match_at(3)->destination_url.spec()); | 489 EXPECT_EQ("http://d/", result.match_at(3)->destination_url.spec()); |
429 } | 490 } |
430 } | 491 } |
OLD | NEW |