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/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 Profile* profile, | 50 Profile* profile, |
51 const base::string16 match_keyword) | 51 const base::string16 match_keyword) |
52 : AutocompleteProvider(AutocompleteProvider::TYPE_SEARCH), | 52 : AutocompleteProvider(AutocompleteProvider::TYPE_SEARCH), |
53 listener_(NULL), | 53 listener_(NULL), |
54 profile_(profile), | 54 profile_(profile), |
55 relevance_(relevance), | 55 relevance_(relevance), |
56 prefix_(prefix), | 56 prefix_(prefix), |
57 match_keyword_(match_keyword) { | 57 match_keyword_(match_keyword) { |
58 } | 58 } |
59 | 59 |
60 void Start(const AutocompleteInput& input, bool minimal_changes) override; | 60 void Start(const AutocompleteInput& input, |
| 61 bool minimal_changes, |
| 62 bool called_due_to_focus) override; |
61 | 63 |
62 void set_listener(AutocompleteProviderListener* listener) { | 64 void set_listener(AutocompleteProviderListener* listener) { |
63 listener_ = listener; | 65 listener_ = listener; |
64 } | 66 } |
65 | 67 |
66 private: | 68 private: |
67 ~TestProvider() override {} | 69 ~TestProvider() override {} |
68 | 70 |
69 void Run(); | 71 void Run(); |
70 | 72 |
71 void AddResults(int start_at, int num); | 73 void AddResults(int start_at, int num); |
72 void AddResultsWithSearchTermsArgs( | 74 void AddResultsWithSearchTermsArgs( |
73 int start_at, | 75 int start_at, |
74 int num, | 76 int num, |
75 AutocompleteMatch::Type type, | 77 AutocompleteMatch::Type type, |
76 const TemplateURLRef::SearchTermsArgs& search_terms_args); | 78 const TemplateURLRef::SearchTermsArgs& search_terms_args); |
77 | 79 |
78 AutocompleteProviderListener* listener_; | 80 AutocompleteProviderListener* listener_; |
79 Profile* profile_; | 81 Profile* profile_; |
80 int relevance_; | 82 int relevance_; |
81 const base::string16 prefix_; | 83 const base::string16 prefix_; |
82 const base::string16 match_keyword_; | 84 const base::string16 match_keyword_; |
83 }; | 85 }; |
84 | 86 |
85 void TestProvider::Start(const AutocompleteInput& input, | 87 void TestProvider::Start(const AutocompleteInput& input, |
86 bool minimal_changes) { | 88 bool minimal_changes, |
| 89 bool called_due_to_focus) { |
87 if (minimal_changes) | 90 if (minimal_changes) |
88 return; | 91 return; |
89 | 92 |
90 matches_.clear(); | 93 matches_.clear(); |
91 | 94 |
| 95 if (called_due_to_focus) |
| 96 return; |
| 97 |
92 // Generate 4 results synchronously, the rest later. | 98 // Generate 4 results synchronously, the rest later. |
93 AddResults(0, 1); | 99 AddResults(0, 1); |
94 AddResultsWithSearchTermsArgs( | 100 AddResultsWithSearchTermsArgs( |
95 1, 1, AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, | 101 1, 1, AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, |
96 TemplateURLRef::SearchTermsArgs(base::ASCIIToUTF16("echo"))); | 102 TemplateURLRef::SearchTermsArgs(base::ASCIIToUTF16("echo"))); |
97 AddResultsWithSearchTermsArgs( | 103 AddResultsWithSearchTermsArgs( |
98 2, 1, AutocompleteMatchType::NAVSUGGEST, | 104 2, 1, AutocompleteMatchType::NAVSUGGEST, |
99 TemplateURLRef::SearchTermsArgs(base::ASCIIToUTF16("nav"))); | 105 TemplateURLRef::SearchTermsArgs(base::ASCIIToUTF16("nav"))); |
100 AddResultsWithSearchTermsArgs( | 106 AddResultsWithSearchTermsArgs( |
101 3, 1, AutocompleteMatchType::SEARCH_SUGGEST, | 107 3, 1, AutocompleteMatchType::SEARCH_SUGGEST, |
(...skipping 625 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
727 url = GetDestinationURL(match, base::TimeDelta::FromMilliseconds(2456)); | 733 url = GetDestinationURL(match, base::TimeDelta::FromMilliseconds(2456)); |
728 EXPECT_EQ("//aqs=chrome.0.69i57j69i58j5l2j0l3j69i59.2456j0j4&", url.path()); | 734 EXPECT_EQ("//aqs=chrome.0.69i57j69i58j5l2j0l3j69i59.2456j0j4&", url.path()); |
729 | 735 |
730 // Test page classification and field trial triggered set. | 736 // Test page classification and field trial triggered set. |
731 controller_->search_provider_->field_trial_triggered_in_session_ = true; | 737 controller_->search_provider_->field_trial_triggered_in_session_ = true; |
732 EXPECT_TRUE( | 738 EXPECT_TRUE( |
733 controller_->search_provider_->field_trial_triggered_in_session()); | 739 controller_->search_provider_->field_trial_triggered_in_session()); |
734 url = GetDestinationURL(match, base::TimeDelta::FromMilliseconds(2456)); | 740 url = GetDestinationURL(match, base::TimeDelta::FromMilliseconds(2456)); |
735 EXPECT_EQ("//aqs=chrome.0.69i57j69i58j5l2j0l3j69i59.2456j1j4&", url.path()); | 741 EXPECT_EQ("//aqs=chrome.0.69i57j69i58j5l2j0l3j69i59.2456j1j4&", url.path()); |
736 } | 742 } |
OLD | NEW |