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 <string> | 5 #include <string> |
6 | 6 |
7 #include "base/memory/scoped_vector.h" | 7 #include "base/memory/scoped_vector.h" |
8 #include "base/strings/string16.h" | 8 #include "base/strings/string16.h" |
9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
11 #include "chrome/browser/ui/app_list/search/chrome_search_result.h" | |
12 #include "chrome/browser/ui/app_list/search/history_types.h" | 11 #include "chrome/browser/ui/app_list/search/history_types.h" |
13 #include "chrome/browser/ui/app_list/search/mixer.h" | 12 #include "chrome/browser/ui/app_list/search/mixer.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
15 #include "ui/app_list/app_list_model.h" | 14 #include "ui/app_list/app_list_model.h" |
16 #include "ui/app_list/search_provider.h" | 15 #include "ui/app_list/search_provider.h" |
16 #include "ui/app_list/search_result.h" | |
17 | 17 |
18 namespace app_list { | 18 namespace app_list { |
19 namespace test { | 19 namespace test { |
20 | 20 |
21 class TestSearchResult : public ChromeSearchResult { | 21 class TestSearchResult : public SearchResult { |
22 public: | 22 public: |
23 TestSearchResult(const std::string& id, double relevance) | 23 TestSearchResult(const std::string& id, double relevance) |
24 : instance_id_(instantiation_count++) { | 24 : instance_id_(instantiation_count++) { |
25 set_id(id); | 25 set_id(id); |
26 set_title(base::UTF8ToUTF16(id)); | 26 set_title(base::UTF8ToUTF16(id)); |
27 set_relevance(relevance); | 27 set_relevance(relevance); |
28 } | 28 } |
29 virtual ~TestSearchResult() {} | 29 virtual ~TestSearchResult() {} |
30 | 30 |
31 // ChromeSearchResult overides: | 31 // SearchResult overides: |
tapted
2014/10/02 07:19:21
nit: overide -> overrides
Jun Mukai
2014/10/03 01:24:23
Done.
Jun Mukai
2014/10/03 01:24:23
Done.
| |
32 virtual void Open(int event_flags) OVERRIDE {} | 32 virtual void Open(int event_flags) OVERRIDE {} |
33 virtual void InvokeAction(int action_index, int event_flags) OVERRIDE {} | 33 virtual void InvokeAction(int action_index, int event_flags) OVERRIDE {} |
34 virtual scoped_ptr<ChromeSearchResult> Duplicate() OVERRIDE { | 34 virtual scoped_ptr<SearchResult> Duplicate() OVERRIDE { |
35 return scoped_ptr<ChromeSearchResult>( | 35 return scoped_ptr<SearchResult>(new TestSearchResult(id(), relevance())); |
36 new TestSearchResult(id(), relevance())).Pass(); | |
37 } | 36 } |
38 virtual ChromeSearchResultType GetType() OVERRIDE { | 37 virtual SearchResultType GetType() OVERRIDE { |
39 return SEARCH_RESULT_TYPE_BOUNDARY; | 38 return SEARCH_RESULT_TYPE_BOUNDARY; |
40 } | 39 } |
41 | 40 |
42 // For reference equality testing. (Addresses cannot be used to test reference | 41 // For reference equality testing. (Addresses cannot be used to test reference |
43 // equality because it is possible that an object will be allocated at the | 42 // equality because it is possible that an object will be allocated at the |
44 // same address as a previously deleted one.) | 43 // same address as a previously deleted one.) |
45 static int GetInstanceId(SearchResult* result) { | 44 static int GetInstanceId(SearchResult* result) { |
46 return static_cast<const TestSearchResult*>(result)->instance_id_; | 45 return static_cast<const TestSearchResult*>(result)->instance_id_; |
47 } | 46 } |
48 | 47 |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
189 webstore_provider()->set_prefix(dup); | 188 webstore_provider()->set_prefix(dup); |
190 webstore_provider()->set_count(1); | 189 webstore_provider()->set_count(1); |
191 | 190 |
192 RunQuery(); | 191 RunQuery(); |
193 | 192 |
194 // Only three results with unique id are kept. | 193 // Only three results with unique id are kept. |
195 EXPECT_EQ("dup0,dup1,dup2", GetResults()); | 194 EXPECT_EQ("dup0,dup1,dup2", GetResults()); |
196 } | 195 } |
197 | 196 |
198 TEST_F(MixerTest, Publish) { | 197 TEST_F(MixerTest, Publish) { |
199 scoped_ptr<ChromeSearchResult> result1(new TestSearchResult("app1", 0)); | 198 scoped_ptr<SearchResult> result1(new TestSearchResult("app1", 0)); |
200 scoped_ptr<ChromeSearchResult> result2(new TestSearchResult("app2", 0)); | 199 scoped_ptr<SearchResult> result2(new TestSearchResult("app2", 0)); |
201 scoped_ptr<ChromeSearchResult> result3(new TestSearchResult("app3", 0)); | 200 scoped_ptr<SearchResult> result3(new TestSearchResult("app3", 0)); |
202 scoped_ptr<ChromeSearchResult> result3_copy = result3->Duplicate(); | 201 scoped_ptr<SearchResult> result3_copy = result3->Duplicate(); |
203 scoped_ptr<ChromeSearchResult> result4(new TestSearchResult("app4", 0)); | 202 scoped_ptr<SearchResult> result4(new TestSearchResult("app4", 0)); |
204 scoped_ptr<ChromeSearchResult> result5(new TestSearchResult("app5", 0)); | 203 scoped_ptr<SearchResult> result5(new TestSearchResult("app5", 0)); |
205 | 204 |
206 AppListModel::SearchResults ui_results; | 205 AppListModel::SearchResults ui_results; |
207 | 206 |
208 // Publish the first three results to |ui_results|. | 207 // Publish the first three results to |ui_results|. |
209 Mixer::SortedResults new_results; | 208 Mixer::SortedResults new_results; |
210 new_results.push_back(Mixer::SortData(result1.get(), 1.0f)); | 209 new_results.push_back(Mixer::SortData(result1.get(), 1.0f)); |
211 new_results.push_back(Mixer::SortData(result2.get(), 1.0f)); | 210 new_results.push_back(Mixer::SortData(result2.get(), 1.0f)); |
212 new_results.push_back(Mixer::SortData(result3.get(), 1.0f)); | 211 new_results.push_back(Mixer::SortData(result3.get(), 1.0f)); |
213 | 212 |
214 Mixer::Publish(new_results, &ui_results); | 213 Mixer::Publish(new_results, &ui_results); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
278 EXPECT_EQ(old_ui_result_ids[0], | 277 EXPECT_EQ(old_ui_result_ids[0], |
279 TestSearchResult::GetInstanceId(ui_results.GetItemAt(3))); | 278 TestSearchResult::GetInstanceId(ui_results.GetItemAt(3))); |
280 EXPECT_EQ(old_ui_result_ids[1], | 279 EXPECT_EQ(old_ui_result_ids[1], |
281 TestSearchResult::GetInstanceId(ui_results.GetItemAt(0))); | 280 TestSearchResult::GetInstanceId(ui_results.GetItemAt(0))); |
282 EXPECT_EQ(old_ui_result_ids[2], | 281 EXPECT_EQ(old_ui_result_ids[2], |
283 TestSearchResult::GetInstanceId(ui_results.GetItemAt(2))); | 282 TestSearchResult::GetInstanceId(ui_results.GetItemAt(2))); |
284 } | 283 } |
285 | 284 |
286 } // namespace test | 285 } // namespace test |
287 } // namespace app_list | 286 } // namespace app_list |
OLD | NEW |