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_provider.h" | 5 #include "chrome/browser/autocomplete/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/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
11 #include "base/strings/string16.h" | 11 #include "base/strings/string16.h" |
12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
15 #include "chrome/browser/autocomplete/autocomplete_controller.h" | 15 #include "chrome/browser/autocomplete/autocomplete_controller.h" |
16 #include "chrome/browser/autocomplete/autocomplete_input.h" | 16 #include "chrome/browser/autocomplete/autocomplete_input.h" |
17 #include "chrome/browser/autocomplete/autocomplete_match.h" | 17 #include "chrome/browser/autocomplete/autocomplete_match.h" |
18 #include "chrome/browser/autocomplete/autocomplete_provider_listener.h" | 18 #include "chrome/browser/autocomplete/autocomplete_provider_listener.h" |
19 #include "chrome/browser/autocomplete/keyword_provider.h" | 19 #include "chrome/browser/autocomplete/keyword_provider.h" |
20 #include "chrome/browser/autocomplete/search_provider.h" | 20 #include "chrome/browser/autocomplete/search_provider.h" |
21 #include "chrome/browser/chrome_notification_types.h" | 21 #include "chrome/browser/chrome_notification_types.h" |
22 #include "chrome/browser/search_engines/template_url.h" | 22 #include "chrome/browser/search_engines/template_url.h" |
23 #include "chrome/browser/search_engines/template_url_service.h" | 23 #include "chrome/browser/search_engines/template_url_service.h" |
24 #include "chrome/browser/search_engines/template_url_service_factory.h" | 24 #include "chrome/browser/search_engines/template_url_service_factory.h" |
25 #include "chrome/common/chrome_switches.h" | 25 #include "chrome/common/chrome_switches.h" |
26 #include "chrome/test/base/testing_browser_process.h" | 26 #include "chrome/test/base/testing_browser_process.h" |
27 #include "chrome/test/base/testing_profile.h" | 27 #include "chrome/test/base/testing_profile.h" |
| 28 #include "components/metrics/proto/omnibox_event.pb.h" |
28 #include "content/public/browser/notification_observer.h" | 29 #include "content/public/browser/notification_observer.h" |
29 #include "content/public/browser/notification_registrar.h" | 30 #include "content/public/browser/notification_registrar.h" |
30 #include "content/public/browser/notification_source.h" | 31 #include "content/public/browser/notification_source.h" |
31 #include "testing/gtest/include/gtest/gtest.h" | 32 #include "testing/gtest/include/gtest/gtest.h" |
32 | 33 |
33 static std::ostream& operator<<(std::ostream& os, | 34 static std::ostream& operator<<(std::ostream& os, |
34 const AutocompleteResult::const_iterator& it) { | 35 const AutocompleteResult::const_iterator& it) { |
35 return os << static_cast<const AutocompleteMatch*>(&(*it)); | 36 return os << static_cast<const AutocompleteMatch*>(&(*it)); |
36 } | 37 } |
37 | 38 |
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
397 for (size_t i = 0; i < size; ++i) { | 398 for (size_t i = 0; i < size; ++i) { |
398 EXPECT_EQ(aqs_test_data[i].expected_aqs, | 399 EXPECT_EQ(aqs_test_data[i].expected_aqs, |
399 result_.match_at(i)->search_terms_args->assisted_query_stats); | 400 result_.match_at(i)->search_terms_args->assisted_query_stats); |
400 } | 401 } |
401 } | 402 } |
402 | 403 |
403 void AutocompleteProviderTest::RunQuery(const base::string16 query) { | 404 void AutocompleteProviderTest::RunQuery(const base::string16 query) { |
404 result_.Reset(); | 405 result_.Reset(); |
405 controller_->Start(AutocompleteInput( | 406 controller_->Start(AutocompleteInput( |
406 query, base::string16::npos, base::string16(), GURL(), | 407 query, base::string16::npos, base::string16(), GURL(), |
407 AutocompleteInput::INVALID_SPEC, true, false, true, true)); | 408 metrics::OmniboxEventProto::INVALID_SPEC, true, false, true, true)); |
408 | 409 |
409 if (!controller_->done()) | 410 if (!controller_->done()) |
410 // The message loop will terminate when all autocomplete input has been | 411 // The message loop will terminate when all autocomplete input has been |
411 // collected. | 412 // collected. |
412 base::MessageLoop::current()->Run(); | 413 base::MessageLoop::current()->Run(); |
413 } | 414 } |
414 | 415 |
415 void AutocompleteProviderTest::RunExactKeymatchTest( | 416 void AutocompleteProviderTest::RunExactKeymatchTest( |
416 bool allow_exact_keyword_match) { | 417 bool allow_exact_keyword_match) { |
417 // Send the controller input which exactly matches the keyword provider we | 418 // Send the controller input which exactly matches the keyword provider we |
418 // created in ResetControllerWithKeywordAndSearchProviders(). The default | 419 // created in ResetControllerWithKeywordAndSearchProviders(). The default |
419 // match should thus be a search-other-engine match iff | 420 // match should thus be a search-other-engine match iff |
420 // |allow_exact_keyword_match| is true. Regardless, the match should | 421 // |allow_exact_keyword_match| is true. Regardless, the match should |
421 // be from SearchProvider. (It provides all verbatim search matches, | 422 // be from SearchProvider. (It provides all verbatim search matches, |
422 // keyword or not.) | 423 // keyword or not.) |
423 controller_->Start(AutocompleteInput( | 424 controller_->Start(AutocompleteInput( |
424 base::ASCIIToUTF16("k test"), base::string16::npos, base::string16(), | 425 base::ASCIIToUTF16("k test"), base::string16::npos, base::string16(), |
425 GURL(), AutocompleteInput::INVALID_SPEC, true, false, | 426 GURL(), metrics::OmniboxEventProto::INVALID_SPEC, true, false, |
426 allow_exact_keyword_match, false)); | 427 allow_exact_keyword_match, false)); |
427 EXPECT_TRUE(controller_->done()); | 428 EXPECT_TRUE(controller_->done()); |
428 EXPECT_EQ(AutocompleteProvider::TYPE_SEARCH, | 429 EXPECT_EQ(AutocompleteProvider::TYPE_SEARCH, |
429 controller_->result().default_match()->provider->type()); | 430 controller_->result().default_match()->provider->type()); |
430 EXPECT_EQ(allow_exact_keyword_match ? | 431 EXPECT_EQ(allow_exact_keyword_match ? |
431 AutocompleteMatchType::SEARCH_OTHER_ENGINE : | 432 AutocompleteMatchType::SEARCH_OTHER_ENGINE : |
432 AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, | 433 AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, |
433 controller_->result().default_match()->type); | 434 controller_->result().default_match()->type); |
434 } | 435 } |
435 | 436 |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
641 EXPECT_EQ("//aqs=chrome.0.69i57j69i58j5l2j0l3j69i59.2456j0j0&", url.path()); | 642 EXPECT_EQ("//aqs=chrome.0.69i57j69i58j5l2j0l3j69i59.2456j0j0&", url.path()); |
642 | 643 |
643 // Test field trial triggered bit set. | 644 // Test field trial triggered bit set. |
644 controller_->search_provider_->field_trial_triggered_in_session_ = true; | 645 controller_->search_provider_->field_trial_triggered_in_session_ = true; |
645 EXPECT_TRUE( | 646 EXPECT_TRUE( |
646 controller_->search_provider_->field_trial_triggered_in_session()); | 647 controller_->search_provider_->field_trial_triggered_in_session()); |
647 url = GetDestinationURL(match, base::TimeDelta::FromMilliseconds(2456)); | 648 url = GetDestinationURL(match, base::TimeDelta::FromMilliseconds(2456)); |
648 EXPECT_EQ("//aqs=chrome.0.69i57j69i58j5l2j0l3j69i59.2456j1j0&", url.path()); | 649 EXPECT_EQ("//aqs=chrome.0.69i57j69i58j5l2j0l3j69i59.2456j1j0&", url.path()); |
649 | 650 |
650 // Test page classification set. | 651 // Test page classification set. |
651 controller_->input_.current_page_classification_ = AutocompleteInput::OTHER; | 652 controller_->input_.current_page_classification_ = |
| 653 metrics::OmniboxEventProto::OTHER; |
652 controller_->search_provider_->field_trial_triggered_in_session_ = false; | 654 controller_->search_provider_->field_trial_triggered_in_session_ = false; |
653 EXPECT_FALSE( | 655 EXPECT_FALSE( |
654 controller_->search_provider_->field_trial_triggered_in_session()); | 656 controller_->search_provider_->field_trial_triggered_in_session()); |
655 url = GetDestinationURL(match, base::TimeDelta::FromMilliseconds(2456)); | 657 url = GetDestinationURL(match, base::TimeDelta::FromMilliseconds(2456)); |
656 EXPECT_EQ("//aqs=chrome.0.69i57j69i58j5l2j0l3j69i59.2456j0j4&", url.path()); | 658 EXPECT_EQ("//aqs=chrome.0.69i57j69i58j5l2j0l3j69i59.2456j0j4&", url.path()); |
657 | 659 |
658 // Test page classification and field trial triggered set. | 660 // Test page classification and field trial triggered set. |
659 controller_->search_provider_->field_trial_triggered_in_session_ = true; | 661 controller_->search_provider_->field_trial_triggered_in_session_ = true; |
660 EXPECT_TRUE( | 662 EXPECT_TRUE( |
661 controller_->search_provider_->field_trial_triggered_in_session()); | 663 controller_->search_provider_->field_trial_triggered_in_session()); |
662 url = GetDestinationURL(match, base::TimeDelta::FromMilliseconds(2456)); | 664 url = GetDestinationURL(match, base::TimeDelta::FromMilliseconds(2456)); |
663 EXPECT_EQ("//aqs=chrome.0.69i57j69i58j5l2j0l3j69i59.2456j1j4&", url.path()); | 665 EXPECT_EQ("//aqs=chrome.0.69i57j69i58j5l2j0l3j69i59.2456j1j4&", url.path()); |
664 } | 666 } |
OLD | NEW |