| 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 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 EXPECT_EQ(expected_match.relevance, match.relevance) << i; | 124 EXPECT_EQ(expected_match.relevance, match.relevance) << i; |
| 125 EXPECT_EQ(expected_match.destination_url.spec(), | 125 EXPECT_EQ(expected_match.destination_url.spec(), |
| 126 match.destination_url.spec()) << i; | 126 match.destination_url.spec()) << i; |
| 127 } | 127 } |
| 128 } | 128 } |
| 129 | 129 |
| 130 void AutocompleteResultTest::RunCopyOldMatchesTest( | 130 void AutocompleteResultTest::RunCopyOldMatchesTest( |
| 131 const TestData* last, size_t last_size, | 131 const TestData* last, size_t last_size, |
| 132 const TestData* current, size_t current_size, | 132 const TestData* current, size_t current_size, |
| 133 const TestData* expected, size_t expected_size) { | 133 const TestData* expected, size_t expected_size) { |
| 134 AutocompleteInput input(ASCIIToUTF16("a"), string16::npos, string16(), GURL(), | 134 AutocompleteInput input(ASCIIToUTF16("a"), base::string16::npos, |
| 135 base::string16(), GURL(), |
| 135 AutocompleteInput::INVALID_SPEC, false, false, false, | 136 AutocompleteInput::INVALID_SPEC, false, false, false, |
| 136 AutocompleteInput::ALL_MATCHES); | 137 AutocompleteInput::ALL_MATCHES); |
| 137 | 138 |
| 138 ACMatches last_matches; | 139 ACMatches last_matches; |
| 139 PopulateAutocompleteMatches(last, last_size, &last_matches); | 140 PopulateAutocompleteMatches(last, last_size, &last_matches); |
| 140 AutocompleteResult last_result; | 141 AutocompleteResult last_result; |
| 141 last_result.AppendMatches(last_matches); | 142 last_result.AppendMatches(last_matches); |
| 142 last_result.SortAndCull(input, test_util_.profile()); | 143 last_result.SortAndCull(input, test_util_.profile()); |
| 143 | 144 |
| 144 ACMatches current_matches; | 145 ACMatches current_matches; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 159 // Swap with empty shouldn't do anything interesting. | 160 // Swap with empty shouldn't do anything interesting. |
| 160 r1.Swap(&r2); | 161 r1.Swap(&r2); |
| 161 EXPECT_EQ(r1.end(), r1.default_match()); | 162 EXPECT_EQ(r1.end(), r1.default_match()); |
| 162 EXPECT_EQ(r2.end(), r2.default_match()); | 163 EXPECT_EQ(r2.end(), r2.default_match()); |
| 163 | 164 |
| 164 // Swap with a single match. | 165 // Swap with a single match. |
| 165 ACMatches matches; | 166 ACMatches matches; |
| 166 AutocompleteMatch match; | 167 AutocompleteMatch match; |
| 167 match.relevance = 1; | 168 match.relevance = 1; |
| 168 match.allowed_to_be_default_match = true; | 169 match.allowed_to_be_default_match = true; |
| 169 AutocompleteInput input(ASCIIToUTF16("a"), string16::npos, string16(), GURL(), | 170 AutocompleteInput input(ASCIIToUTF16("a"), base::string16::npos, |
| 171 base::string16(), GURL(), |
| 170 AutocompleteInput::INVALID_SPEC, false, false, false, | 172 AutocompleteInput::INVALID_SPEC, false, false, false, |
| 171 AutocompleteInput::ALL_MATCHES); | 173 AutocompleteInput::ALL_MATCHES); |
| 172 matches.push_back(match); | 174 matches.push_back(match); |
| 173 r1.AppendMatches(matches); | 175 r1.AppendMatches(matches); |
| 174 r1.SortAndCull(input, test_util_.profile()); | 176 r1.SortAndCull(input, test_util_.profile()); |
| 175 EXPECT_EQ(r1.begin(), r1.default_match()); | 177 EXPECT_EQ(r1.begin(), r1.default_match()); |
| 176 EXPECT_EQ("http://a/", r1.alternate_nav_url().spec()); | 178 EXPECT_EQ("http://a/", r1.alternate_nav_url().spec()); |
| 177 r1.Swap(&r2); | 179 r1.Swap(&r2); |
| 178 EXPECT_TRUE(r1.empty()); | 180 EXPECT_TRUE(r1.empty()); |
| 179 EXPECT_EQ(r1.end(), r1.default_match()); | 181 EXPECT_EQ(r1.end(), r1.default_match()); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 }; | 243 }; |
| 242 | 244 |
| 243 ACMatches matches; | 245 ACMatches matches; |
| 244 PopulateAutocompleteMatches(data, arraysize(data), &matches); | 246 PopulateAutocompleteMatches(data, arraysize(data), &matches); |
| 245 matches[1].destination_url = GURL(); | 247 matches[1].destination_url = GURL(); |
| 246 matches[3].destination_url = GURL(); | 248 matches[3].destination_url = GURL(); |
| 247 matches[4].destination_url = GURL(); | 249 matches[4].destination_url = GURL(); |
| 248 | 250 |
| 249 AutocompleteResult result; | 251 AutocompleteResult result; |
| 250 result.AppendMatches(matches); | 252 result.AppendMatches(matches); |
| 251 AutocompleteInput input(string16(), string16::npos, string16(), GURL(), | 253 AutocompleteInput input(base::string16(), base::string16::npos, |
| 254 base::string16(), GURL(), |
| 252 AutocompleteInput::INVALID_SPEC, false, false, false, | 255 AutocompleteInput::INVALID_SPEC, false, false, false, |
| 253 AutocompleteInput::ALL_MATCHES); | 256 AutocompleteInput::ALL_MATCHES); |
| 254 result.SortAndCull(input, test_util_.profile()); | 257 result.SortAndCull(input, test_util_.profile()); |
| 255 | 258 |
| 256 // Of the two results with the same non-empty destination URL, the | 259 // Of the two results with the same non-empty destination URL, the |
| 257 // lower-relevance one should be dropped. All of the results with empty URLs | 260 // lower-relevance one should be dropped. All of the results with empty URLs |
| 258 // should be kept. | 261 // should be kept. |
| 259 ASSERT_EQ(4U, result.size()); | 262 ASSERT_EQ(4U, result.size()); |
| 260 EXPECT_TRUE(result.match_at(0)->destination_url.is_empty()); | 263 EXPECT_TRUE(result.match_at(0)->destination_url.is_empty()); |
| 261 EXPECT_EQ(1300, result.match_at(0)->relevance); | 264 EXPECT_EQ(1300, result.match_at(0)->relevance); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 286 ACMatches matches; | 289 ACMatches matches; |
| 287 PopulateAutocompleteMatches(data, arraysize(data), &matches); | 290 PopulateAutocompleteMatches(data, arraysize(data), &matches); |
| 288 matches[0].destination_url = GURL("http://www.foo.com/s?q=foo"); | 291 matches[0].destination_url = GURL("http://www.foo.com/s?q=foo"); |
| 289 matches[1].destination_url = GURL("http://www.foo.com/s?q=foo2"); | 292 matches[1].destination_url = GURL("http://www.foo.com/s?q=foo2"); |
| 290 matches[2].destination_url = GURL("http://www.foo.com/s?q=foo&oq=f"); | 293 matches[2].destination_url = GURL("http://www.foo.com/s?q=foo&oq=f"); |
| 291 matches[3].destination_url = GURL("http://www.foo.com/s?q=foo&aqs=0"); | 294 matches[3].destination_url = GURL("http://www.foo.com/s?q=foo&aqs=0"); |
| 292 matches[4].destination_url = GURL("http://www.foo.com/"); | 295 matches[4].destination_url = GURL("http://www.foo.com/"); |
| 293 | 296 |
| 294 AutocompleteResult result; | 297 AutocompleteResult result; |
| 295 result.AppendMatches(matches); | 298 result.AppendMatches(matches); |
| 296 AutocompleteInput input(string16(), string16::npos, string16(), GURL(), | 299 AutocompleteInput input(base::string16(), base::string16::npos, |
| 300 base::string16(), GURL(), |
| 297 AutocompleteInput::INVALID_SPEC, false, false, false, | 301 AutocompleteInput::INVALID_SPEC, false, false, false, |
| 298 AutocompleteInput::ALL_MATCHES); | 302 AutocompleteInput::ALL_MATCHES); |
| 299 result.SortAndCull(input, test_util_.profile()); | 303 result.SortAndCull(input, test_util_.profile()); |
| 300 | 304 |
| 301 // We expect the 3rd and 4th results to be removed. | 305 // We expect the 3rd and 4th results to be removed. |
| 302 ASSERT_EQ(3U, result.size()); | 306 ASSERT_EQ(3U, result.size()); |
| 303 EXPECT_EQ("http://www.foo.com/s?q=foo", | 307 EXPECT_EQ("http://www.foo.com/s?q=foo", |
| 304 result.match_at(0)->destination_url.spec()); | 308 result.match_at(0)->destination_url.spec()); |
| 305 EXPECT_EQ(1300, result.match_at(0)->relevance); | 309 EXPECT_EQ(1300, result.match_at(0)->relevance); |
| 306 EXPECT_EQ("http://www.foo.com/s?q=foo2", | 310 EXPECT_EQ("http://www.foo.com/s?q=foo2", |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 353 params[std::string(OmniboxFieldTrial::kDemoteByTypeRule) + ":3:*"] = | 357 params[std::string(OmniboxFieldTrial::kDemoteByTypeRule) + ":3:*"] = |
| 354 "1:50,7:100,2:0"; // 3 == HOME_PAGE | 358 "1:50,7:100,2:0"; // 3 == HOME_PAGE |
| 355 ASSERT_TRUE(chrome_variations::AssociateVariationParams( | 359 ASSERT_TRUE(chrome_variations::AssociateVariationParams( |
| 356 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "A", params)); | 360 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "A", params)); |
| 357 } | 361 } |
| 358 base::FieldTrialList::CreateFieldTrial( | 362 base::FieldTrialList::CreateFieldTrial( |
| 359 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "A"); | 363 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "A"); |
| 360 | 364 |
| 361 AutocompleteResult result; | 365 AutocompleteResult result; |
| 362 result.AppendMatches(matches); | 366 result.AppendMatches(matches); |
| 363 AutocompleteInput input(string16(), string16::npos, string16(), GURL(), | 367 AutocompleteInput input(base::string16(), base::string16::npos, |
| 368 base::string16(), GURL(), |
| 364 AutocompleteInput::HOME_PAGE, false, false, false, | 369 AutocompleteInput::HOME_PAGE, false, false, false, |
| 365 AutocompleteInput::ALL_MATCHES); | 370 AutocompleteInput::ALL_MATCHES); |
| 366 result.SortAndCull(input, test_util_.profile()); | 371 result.SortAndCull(input, test_util_.profile()); |
| 367 | 372 |
| 368 // Check the new ordering. The history-title results should be omitted. | 373 // Check the new ordering. The history-title results should be omitted. |
| 369 // We cannot check relevance scores because the matches are sorted by | 374 // We cannot check relevance scores because the matches are sorted by |
| 370 // demoted relevance but the actual relevance scores are not modified. | 375 // demoted relevance but the actual relevance scores are not modified. |
| 371 ASSERT_EQ(3u, result.size()); | 376 ASSERT_EQ(3u, result.size()); |
| 372 EXPECT_EQ("http://search-what-you-typed/", | 377 EXPECT_EQ("http://search-what-you-typed/", |
| 373 result.match_at(0)->destination_url.spec()); | 378 result.match_at(0)->destination_url.spec()); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 402 params[std::string(OmniboxFieldTrial::kUndemotableTopTypeRule) + ":3:*"] = | 407 params[std::string(OmniboxFieldTrial::kUndemotableTopTypeRule) + ":3:*"] = |
| 403 "1,5"; | 408 "1,5"; |
| 404 ASSERT_TRUE(chrome_variations::AssociateVariationParams( | 409 ASSERT_TRUE(chrome_variations::AssociateVariationParams( |
| 405 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "B", params)); | 410 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "B", params)); |
| 406 } | 411 } |
| 407 base::FieldTrialList::CreateFieldTrial( | 412 base::FieldTrialList::CreateFieldTrial( |
| 408 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "B"); | 413 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "B"); |
| 409 | 414 |
| 410 AutocompleteResult result; | 415 AutocompleteResult result; |
| 411 result.AppendMatches(matches); | 416 result.AppendMatches(matches); |
| 412 AutocompleteInput input(string16(), string16::npos, string16(), GURL(), | 417 AutocompleteInput input(base::string16(), base::string16::npos, |
| 418 base::string16(), GURL(), |
| 413 AutocompleteInput::HOME_PAGE, false, false, false, | 419 AutocompleteInput::HOME_PAGE, false, false, false, |
| 414 AutocompleteInput::ALL_MATCHES); | 420 AutocompleteInput::ALL_MATCHES); |
| 415 result.SortAndCull(input, test_util_.profile()); | 421 result.SortAndCull(input, test_util_.profile()); |
| 416 | 422 |
| 417 // Check the new ordering. The first history-url result should not be | 423 // Check the new ordering. The first history-url result should not be |
| 418 // demoted, but the second result should be. | 424 // demoted, but the second result should be. |
| 419 // We cannot check relevance scores because the matches are sorted by | 425 // We cannot check relevance scores because the matches are sorted by |
| 420 // demoted relevance but the actual relevance scores are not modified. | 426 // demoted relevance but the actual relevance scores are not modified. |
| 421 ASSERT_EQ(3u, result.size()); | 427 ASSERT_EQ(3u, result.size()); |
| 422 EXPECT_EQ("http://top-history-url/", | 428 EXPECT_EQ("http://top-history-url/", |
| (...skipping 22 matching lines...) Expand all Loading... |
| 445 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "A"); | 451 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "A"); |
| 446 | 452 |
| 447 { | 453 { |
| 448 // Check that reorder doesn't do anything if the top result | 454 // Check that reorder doesn't do anything if the top result |
| 449 // is already a legal default match (which is the default from | 455 // is already a legal default match (which is the default from |
| 450 // PopulateAutocompleteMatches()). | 456 // PopulateAutocompleteMatches()). |
| 451 ACMatches matches; | 457 ACMatches matches; |
| 452 PopulateAutocompleteMatches(data, arraysize(data), &matches); | 458 PopulateAutocompleteMatches(data, arraysize(data), &matches); |
| 453 AutocompleteResult result; | 459 AutocompleteResult result; |
| 454 result.AppendMatches(matches); | 460 result.AppendMatches(matches); |
| 455 AutocompleteInput input(string16(), string16::npos, string16(), GURL(), | 461 AutocompleteInput input(base::string16(), base::string16::npos, |
| 462 base::string16(), GURL(), |
| 456 AutocompleteInput::HOME_PAGE, false, false, false, | 463 AutocompleteInput::HOME_PAGE, false, false, false, |
| 457 AutocompleteInput::ALL_MATCHES); | 464 AutocompleteInput::ALL_MATCHES); |
| 458 result.SortAndCull(input, test_util_.profile()); | 465 result.SortAndCull(input, test_util_.profile()); |
| 459 AssertResultMatches(result, data, 4); | 466 AssertResultMatches(result, data, 4); |
| 460 } | 467 } |
| 461 | 468 |
| 462 { | 469 { |
| 463 // Check that reorder swaps up a result appropriately. | 470 // Check that reorder swaps up a result appropriately. |
| 464 ACMatches matches; | 471 ACMatches matches; |
| 465 PopulateAutocompleteMatches(data, arraysize(data), &matches); | 472 PopulateAutocompleteMatches(data, arraysize(data), &matches); |
| 466 matches[0].allowed_to_be_default_match = false; | 473 matches[0].allowed_to_be_default_match = false; |
| 467 matches[1].allowed_to_be_default_match = false; | 474 matches[1].allowed_to_be_default_match = false; |
| 468 AutocompleteResult result; | 475 AutocompleteResult result; |
| 469 result.AppendMatches(matches); | 476 result.AppendMatches(matches); |
| 470 AutocompleteInput input(string16(), string16::npos, string16(), GURL(), | 477 AutocompleteInput input(base::string16(), base::string16::npos, |
| 478 base::string16(), GURL(), |
| 471 AutocompleteInput::HOME_PAGE, false, false, false, | 479 AutocompleteInput::HOME_PAGE, false, false, false, |
| 472 AutocompleteInput::ALL_MATCHES); | 480 AutocompleteInput::ALL_MATCHES); |
| 473 result.SortAndCull(input, test_util_.profile()); | 481 result.SortAndCull(input, test_util_.profile()); |
| 474 ASSERT_EQ(4U, result.size()); | 482 ASSERT_EQ(4U, result.size()); |
| 475 EXPECT_EQ("http://c/", result.match_at(0)->destination_url.spec()); | 483 EXPECT_EQ("http://c/", result.match_at(0)->destination_url.spec()); |
| 476 EXPECT_EQ("http://a/", result.match_at(1)->destination_url.spec()); | 484 EXPECT_EQ("http://a/", result.match_at(1)->destination_url.spec()); |
| 477 EXPECT_EQ("http://b/", result.match_at(2)->destination_url.spec()); | 485 EXPECT_EQ("http://b/", result.match_at(2)->destination_url.spec()); |
| 478 EXPECT_EQ("http://d/", result.match_at(3)->destination_url.spec()); | 486 EXPECT_EQ("http://d/", result.match_at(3)->destination_url.spec()); |
| 479 } | 487 } |
| 480 } | 488 } |
| OLD | NEW |