Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(55)

Side by Side Diff: chrome/browser/ui/app_list/search/mixer_unittest.cc

Issue 621823004: Simplifies the structure of app_list search a bit. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 overrides:
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 }
38 virtual ChromeSearchResultType GetType() override {
39 return SEARCH_RESULT_TYPE_BOUNDARY;
40 } 36 }
41 37
42 // For reference equality testing. (Addresses cannot be used to test reference 38 // 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 39 // equality because it is possible that an object will be allocated at the
44 // same address as a previously deleted one.) 40 // same address as a previously deleted one.)
45 static int GetInstanceId(SearchResult* result) { 41 static int GetInstanceId(SearchResult* result) {
46 return static_cast<const TestSearchResult*>(result)->instance_id_; 42 return static_cast<const TestSearchResult*>(result)->instance_id_;
47 } 43 }
48 44
49 private: 45 private:
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 webstore_provider()->set_prefix(dup); 185 webstore_provider()->set_prefix(dup);
190 webstore_provider()->set_count(1); 186 webstore_provider()->set_count(1);
191 187
192 RunQuery(); 188 RunQuery();
193 189
194 // Only three results with unique id are kept. 190 // Only three results with unique id are kept.
195 EXPECT_EQ("dup0,dup1,dup2", GetResults()); 191 EXPECT_EQ("dup0,dup1,dup2", GetResults());
196 } 192 }
197 193
198 TEST_F(MixerTest, Publish) { 194 TEST_F(MixerTest, Publish) {
199 scoped_ptr<ChromeSearchResult> result1(new TestSearchResult("app1", 0)); 195 scoped_ptr<SearchResult> result1(new TestSearchResult("app1", 0));
200 scoped_ptr<ChromeSearchResult> result2(new TestSearchResult("app2", 0)); 196 scoped_ptr<SearchResult> result2(new TestSearchResult("app2", 0));
201 scoped_ptr<ChromeSearchResult> result3(new TestSearchResult("app3", 0)); 197 scoped_ptr<SearchResult> result3(new TestSearchResult("app3", 0));
202 scoped_ptr<ChromeSearchResult> result3_copy = result3->Duplicate(); 198 scoped_ptr<SearchResult> result3_copy = result3->Duplicate();
203 scoped_ptr<ChromeSearchResult> result4(new TestSearchResult("app4", 0)); 199 scoped_ptr<SearchResult> result4(new TestSearchResult("app4", 0));
204 scoped_ptr<ChromeSearchResult> result5(new TestSearchResult("app5", 0)); 200 scoped_ptr<SearchResult> result5(new TestSearchResult("app5", 0));
205 201
206 AppListModel::SearchResults ui_results; 202 AppListModel::SearchResults ui_results;
207 203
208 // Publish the first three results to |ui_results|. 204 // Publish the first three results to |ui_results|.
209 Mixer::SortedResults new_results; 205 Mixer::SortedResults new_results;
210 new_results.push_back(Mixer::SortData(result1.get(), 1.0f)); 206 new_results.push_back(Mixer::SortData(result1.get(), 1.0f));
211 new_results.push_back(Mixer::SortData(result2.get(), 1.0f)); 207 new_results.push_back(Mixer::SortData(result2.get(), 1.0f));
212 new_results.push_back(Mixer::SortData(result3.get(), 1.0f)); 208 new_results.push_back(Mixer::SortData(result3.get(), 1.0f));
213 209
214 Mixer::Publish(new_results, &ui_results); 210 Mixer::Publish(new_results, &ui_results);
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 EXPECT_EQ(old_ui_result_ids[0], 274 EXPECT_EQ(old_ui_result_ids[0],
279 TestSearchResult::GetInstanceId(ui_results.GetItemAt(3))); 275 TestSearchResult::GetInstanceId(ui_results.GetItemAt(3)));
280 EXPECT_EQ(old_ui_result_ids[1], 276 EXPECT_EQ(old_ui_result_ids[1],
281 TestSearchResult::GetInstanceId(ui_results.GetItemAt(0))); 277 TestSearchResult::GetInstanceId(ui_results.GetItemAt(0)));
282 EXPECT_EQ(old_ui_result_ids[2], 278 EXPECT_EQ(old_ui_result_ids[2],
283 TestSearchResult::GetInstanceId(ui_results.GetItemAt(2))); 279 TestSearchResult::GetInstanceId(ui_results.GetItemAt(2)));
284 } 280 }
285 281
286 } // namespace test 282 } // namespace test
287 } // namespace app_list 283 } // namespace app_list
OLDNEW
« no previous file with comments | « chrome/browser/ui/app_list/search/mixer.cc ('k') | chrome/browser/ui/app_list/search/omnibox_provider.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698