| 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 "components/omnibox/autocomplete_provider.h" | 5 #include "components/omnibox/autocomplete_provider.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/strings/string16.h" | 10 #include "base/strings/string16.h" |
| (...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 399 for (size_t i = 0; i < size; ++i) { | 399 for (size_t i = 0; i < size; ++i) { |
| 400 AutocompleteMatch match; | 400 AutocompleteMatch match; |
| 401 match.relevance = 1000; // Arbitrary non-zero value. | 401 match.relevance = 1000; // Arbitrary non-zero value. |
| 402 match.allowed_to_be_default_match = true; | 402 match.allowed_to_be_default_match = true; |
| 403 match.fill_into_edit = match_data[i].fill_into_edit; | 403 match.fill_into_edit = match_data[i].fill_into_edit; |
| 404 match.transition = ui::PAGE_TRANSITION_KEYWORD; | 404 match.transition = ui::PAGE_TRANSITION_KEYWORD; |
| 405 match.keyword = match_data[i].keyword; | 405 match.keyword = match_data[i].keyword; |
| 406 matches.push_back(match); | 406 matches.push_back(match); |
| 407 } | 407 } |
| 408 | 408 |
| 409 AutocompleteResult result; | |
| 410 result.AppendMatches(matches); | |
| 411 controller_->input_ = AutocompleteInput( | 409 controller_->input_ = AutocompleteInput( |
| 412 input, base::string16::npos, std::string(), GURL(), | 410 input, base::string16::npos, std::string(), GURL(), |
| 413 metrics::OmniboxEventProto::INSTANT_NTP_WITH_OMNIBOX_AS_STARTING_FOCUS, | 411 metrics::OmniboxEventProto::INSTANT_NTP_WITH_OMNIBOX_AS_STARTING_FOCUS, |
| 414 false, true, true, true, ChromeAutocompleteSchemeClassifier(&profile_)); | 412 false, true, true, true, ChromeAutocompleteSchemeClassifier(&profile_)); |
| 413 AutocompleteResult result; |
| 414 result.AppendMatches(controller_->input_, matches); |
| 415 controller_->UpdateAssociatedKeywords(&result); | 415 controller_->UpdateAssociatedKeywords(&result); |
| 416 | 416 |
| 417 for (size_t j = 0; j < result.size(); ++j) { | 417 for (size_t j = 0; j < result.size(); ++j) { |
| 418 EXPECT_EQ(match_data[j].expected_associated_keyword, | 418 EXPECT_EQ(match_data[j].expected_associated_keyword, |
| 419 result.match_at(j)->associated_keyword.get() ? | 419 result.match_at(j)->associated_keyword.get() ? |
| 420 result.match_at(j)->associated_keyword->keyword : | 420 result.match_at(j)->associated_keyword->keyword : |
| 421 base::string16()); | 421 base::string16()); |
| 422 } | 422 } |
| 423 } | 423 } |
| 424 | 424 |
| 425 void AutocompleteProviderTest::RunAssistedQueryStatsTest( | 425 void AutocompleteProviderTest::RunAssistedQueryStatsTest( |
| 426 const AssistedQueryStatsTestData* aqs_test_data, | 426 const AssistedQueryStatsTestData* aqs_test_data, |
| 427 size_t size) { | 427 size_t size) { |
| 428 // Prepare input. | 428 // Prepare input. |
| 429 const size_t kMaxRelevance = 1000; | 429 const size_t kMaxRelevance = 1000; |
| 430 ACMatches matches; | 430 ACMatches matches; |
| 431 for (size_t i = 0; i < size; ++i) { | 431 for (size_t i = 0; i < size; ++i) { |
| 432 AutocompleteMatch match(NULL, kMaxRelevance - i, false, | 432 AutocompleteMatch match(NULL, kMaxRelevance - i, false, |
| 433 aqs_test_data[i].match_type); | 433 aqs_test_data[i].match_type); |
| 434 match.allowed_to_be_default_match = true; | 434 match.allowed_to_be_default_match = true; |
| 435 match.keyword = base::ASCIIToUTF16(kTestTemplateURLKeyword); | 435 match.keyword = base::ASCIIToUTF16(kTestTemplateURLKeyword); |
| 436 match.search_terms_args.reset( | 436 match.search_terms_args.reset( |
| 437 new TemplateURLRef::SearchTermsArgs(base::string16())); | 437 new TemplateURLRef::SearchTermsArgs(base::string16())); |
| 438 matches.push_back(match); | 438 matches.push_back(match); |
| 439 } | 439 } |
| 440 result_.Reset(); | 440 result_.Reset(); |
| 441 result_.AppendMatches(matches); | 441 result_.AppendMatches(AutocompleteInput(), matches); |
| 442 | 442 |
| 443 // Update AQS. | 443 // Update AQS. |
| 444 controller_->UpdateAssistedQueryStats(&result_); | 444 controller_->UpdateAssistedQueryStats(&result_); |
| 445 | 445 |
| 446 // Verify data. | 446 // Verify data. |
| 447 for (size_t i = 0; i < size; ++i) { | 447 for (size_t i = 0; i < size; ++i) { |
| 448 EXPECT_EQ(aqs_test_data[i].expected_aqs, | 448 EXPECT_EQ(aqs_test_data[i].expected_aqs, |
| 449 result_.match_at(i)->search_terms_args->assisted_query_stats); | 449 result_.match_at(i)->search_terms_args->assisted_query_stats); |
| 450 } | 450 } |
| 451 } | 451 } |
| (...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 743 EXPECT_FALSE(search_provider_field_trial_triggered_in_session()); | 743 EXPECT_FALSE(search_provider_field_trial_triggered_in_session()); |
| 744 url = GetDestinationURL(match, base::TimeDelta::FromMilliseconds(2456)); | 744 url = GetDestinationURL(match, base::TimeDelta::FromMilliseconds(2456)); |
| 745 EXPECT_EQ("//aqs=chrome.0.69i57j69i58j5l2j0l3j69i59.2456j0j4&", url.path()); | 745 EXPECT_EQ("//aqs=chrome.0.69i57j69i58j5l2j0l3j69i59.2456j0j4&", url.path()); |
| 746 | 746 |
| 747 // Test page classification and field trial triggered set. | 747 // Test page classification and field trial triggered set. |
| 748 set_search_provider_field_trial_triggered_in_session(true); | 748 set_search_provider_field_trial_triggered_in_session(true); |
| 749 EXPECT_TRUE(search_provider_field_trial_triggered_in_session()); | 749 EXPECT_TRUE(search_provider_field_trial_triggered_in_session()); |
| 750 url = GetDestinationURL(match, base::TimeDelta::FromMilliseconds(2456)); | 750 url = GetDestinationURL(match, base::TimeDelta::FromMilliseconds(2456)); |
| 751 EXPECT_EQ("//aqs=chrome.0.69i57j69i58j5l2j0l3j69i59.2456j1j4&", url.path()); | 751 EXPECT_EQ("//aqs=chrome.0.69i57j69i58j5l2j0l3j69i59.2456j1j4&", url.path()); |
| 752 } | 752 } |
| OLD | NEW |