OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <set> | 5 #include <set> |
6 #include <string> | 6 #include <string> |
7 | 7 |
8 #include "base/memory/scoped_vector.h" | 8 #include "base/memory/scoped_vector.h" |
9 #include "base/strings/string16.h" | 9 #include "base/strings/string16.h" |
10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 } | 113 } |
114 | 114 |
115 void RunQuery() { | 115 void RunQuery() { |
116 const base::string16 query; | 116 const base::string16 query; |
117 | 117 |
118 for (size_t i = 0; i < providers_.size(); ++i) { | 118 for (size_t i = 0; i < providers_.size(); ++i) { |
119 providers_[i]->Start(is_voice_query_, query); | 119 providers_[i]->Start(is_voice_query_, query); |
120 providers_[i]->Stop(); | 120 providers_[i]->Stop(); |
121 } | 121 } |
122 | 122 |
123 mixer_->MixAndPublish(is_voice_query_, KnownResults()); | 123 mixer_->MixAndPublish(is_voice_query_, known_results_); |
124 } | 124 } |
125 | 125 |
126 std::string GetResults() const { | 126 std::string GetResults() const { |
127 std::string result; | 127 std::string result; |
128 for (size_t i = 0; i < results_->item_count(); ++i) { | 128 for (size_t i = 0; i < results_->item_count(); ++i) { |
129 if (!result.empty()) | 129 if (!result.empty()) |
130 result += ','; | 130 result += ','; |
131 | 131 |
132 result += base::UTF16ToUTF8(results_->GetItemAt(i)->title()); | 132 result += base::UTF16ToUTF8(results_->GetItemAt(i)->title()); |
133 } | 133 } |
134 | 134 |
135 return result; | 135 return result; |
136 } | 136 } |
137 | 137 |
138 Mixer* mixer() { return mixer_.get(); } | 138 Mixer* mixer() { return mixer_.get(); } |
139 TestSearchProvider* app_provider() { return providers_[0]; } | 139 TestSearchProvider* app_provider() { return providers_[0]; } |
140 TestSearchProvider* omnibox_provider() { return providers_[1]; } | 140 TestSearchProvider* omnibox_provider() { return providers_[1]; } |
141 TestSearchProvider* webstore_provider() { return providers_[2]; } | 141 TestSearchProvider* webstore_provider() { return providers_[2]; } |
142 TestSearchProvider* people_provider() { return providers_[3]; } | 142 TestSearchProvider* people_provider() { return providers_[3]; } |
143 | 143 |
144 // Sets whether test runs should be treated as a voice query. | 144 // Sets whether test runs should be treated as a voice query. |
145 void set_is_voice_query(bool is_voice_query) { | 145 void set_is_voice_query(bool is_voice_query) { |
146 is_voice_query_ = is_voice_query; | 146 is_voice_query_ = is_voice_query; |
147 } | 147 } |
148 | 148 |
| 149 void AddKnownResult(const std::string& id, KnownResultType type) { |
| 150 known_results_[id] = type; |
| 151 } |
| 152 |
149 private: | 153 private: |
150 scoped_ptr<Mixer> mixer_; | 154 scoped_ptr<Mixer> mixer_; |
151 scoped_ptr<AppListModel::SearchResults> results_; | 155 scoped_ptr<AppListModel::SearchResults> results_; |
| 156 KnownResults known_results_; |
152 | 157 |
153 bool is_voice_query_; | 158 bool is_voice_query_; |
154 | 159 |
155 ScopedVector<TestSearchProvider> providers_; | 160 ScopedVector<TestSearchProvider> providers_; |
156 | 161 |
157 DISALLOW_COPY_AND_ASSIGN(MixerTest); | 162 DISALLOW_COPY_AND_ASSIGN(MixerTest); |
158 }; | 163 }; |
159 | 164 |
160 TEST_F(MixerTest, Basic) { | 165 TEST_F(MixerTest, Basic) { |
161 struct TestCase { | 166 struct TestCase { |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 // This gives "dup0". | 216 // This gives "dup0". |
212 webstore_provider()->set_prefix(dup); | 217 webstore_provider()->set_prefix(dup); |
213 webstore_provider()->set_count(1); | 218 webstore_provider()->set_count(1); |
214 | 219 |
215 RunQuery(); | 220 RunQuery(); |
216 | 221 |
217 // Only three results with unique id are kept. | 222 // Only three results with unique id are kept. |
218 EXPECT_EQ("dup0,dup1,dup2", GetResults()); | 223 EXPECT_EQ("dup0,dup1,dup2", GetResults()); |
219 } | 224 } |
220 | 225 |
| 226 // Tests that "known results" have priority over others. |
| 227 TEST_F(MixerTest, KnownResultsPriority) { |
| 228 // This gives omnibox 0 -- 5. |
| 229 omnibox_provider()->set_count(6); |
| 230 |
| 231 // omnibox 1 -- 4 are "known results". |
| 232 AddKnownResult("omnibox1", PREFIX_SECONDARY); |
| 233 AddKnownResult("omnibox2", PERFECT_SECONDARY); |
| 234 AddKnownResult("omnibox3", PREFIX_PRIMARY); |
| 235 AddKnownResult("omnibox4", PERFECT_PRIMARY); |
| 236 |
| 237 RunQuery(); |
| 238 |
| 239 // omnibox 1 -- 4 should be prioritised over the others. They should be |
| 240 // ordered 4, 3, 2, 1 (in order of match quality). |
| 241 EXPECT_EQ("omnibox4,omnibox3,omnibox2,omnibox1,omnibox0,omnibox5", |
| 242 GetResults()); |
| 243 } |
| 244 |
221 TEST_F(MixerTest, VoiceQuery) { | 245 TEST_F(MixerTest, VoiceQuery) { |
222 omnibox_provider()->set_count(3); | 246 omnibox_provider()->set_count(3); |
223 RunQuery(); | 247 RunQuery(); |
224 EXPECT_EQ("omnibox0,omnibox1,omnibox2", GetResults()); | 248 EXPECT_EQ("omnibox0,omnibox1,omnibox2", GetResults()); |
225 | 249 |
226 // Set "omnibox1" as a voice result. Do not expect any changes (as this is not | 250 // Set "omnibox1" as a voice result. Do not expect any changes (as this is not |
227 // a voice query). | 251 // a voice query). |
228 omnibox_provider()->set_as_voice_result(1); | 252 omnibox_provider()->set_as_voice_result(1); |
229 RunQuery(); | 253 RunQuery(); |
230 EXPECT_EQ("omnibox0,omnibox1,omnibox2", GetResults()); | 254 EXPECT_EQ("omnibox0,omnibox1,omnibox2", GetResults()); |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
323 EXPECT_EQ(old_ui_result_ids[0], | 347 EXPECT_EQ(old_ui_result_ids[0], |
324 TestSearchResult::GetInstanceId(ui_results.GetItemAt(3))); | 348 TestSearchResult::GetInstanceId(ui_results.GetItemAt(3))); |
325 EXPECT_EQ(old_ui_result_ids[1], | 349 EXPECT_EQ(old_ui_result_ids[1], |
326 TestSearchResult::GetInstanceId(ui_results.GetItemAt(0))); | 350 TestSearchResult::GetInstanceId(ui_results.GetItemAt(0))); |
327 EXPECT_EQ(old_ui_result_ids[2], | 351 EXPECT_EQ(old_ui_result_ids[2], |
328 TestSearchResult::GetInstanceId(ui_results.GetItemAt(2))); | 352 TestSearchResult::GetInstanceId(ui_results.GetItemAt(2))); |
329 } | 353 } |
330 | 354 |
331 } // namespace test | 355 } // namespace test |
332 } // namespace app_list | 356 } // namespace app_list |
OLD | NEW |