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 "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
12 #include "ui/app_list/app_list_model.h" | 12 #include "ui/app_list/app_list_model.h" |
13 #include "ui/app_list/search/history_types.h" | 13 #include "ui/app_list/search/history_types.h" |
14 #include "ui/app_list/search/mixer.h" | 14 #include "ui/app_list/search/mixer.h" |
15 #include "ui/app_list/search_provider.h" | 15 #include "ui/app_list/search_provider.h" |
16 #include "ui/app_list/search_result.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 SearchResult { | 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 ~TestSearchResult() override {} |
30 | 30 |
31 // SearchResult overrides: | 31 // SearchResult overrides: |
32 virtual void Open(int event_flags) override {} | 32 void Open(int event_flags) override {} |
33 virtual void InvokeAction(int action_index, int event_flags) override {} | 33 void InvokeAction(int action_index, int event_flags) override {} |
34 virtual scoped_ptr<SearchResult> Duplicate() override { | 34 scoped_ptr<SearchResult> Duplicate() override { |
35 return scoped_ptr<SearchResult>(new TestSearchResult(id(), relevance())); | 35 return scoped_ptr<SearchResult>(new TestSearchResult(id(), relevance())); |
36 } | 36 } |
37 | 37 |
38 // For reference equality testing. (Addresses cannot be used to test reference | 38 // For reference equality testing. (Addresses cannot be used to test reference |
39 // 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 |
40 // same address as a previously deleted one.) | 40 // same address as a previously deleted one.) |
41 static int GetInstanceId(SearchResult* result) { | 41 static int GetInstanceId(SearchResult* result) { |
42 return static_cast<const TestSearchResult*>(result)->instance_id_; | 42 return static_cast<const TestSearchResult*>(result)->instance_id_; |
43 } | 43 } |
44 | 44 |
45 private: | 45 private: |
46 static int instantiation_count; | 46 static int instantiation_count; |
47 | 47 |
48 int instance_id_; | 48 int instance_id_; |
49 | 49 |
50 DISALLOW_COPY_AND_ASSIGN(TestSearchResult); | 50 DISALLOW_COPY_AND_ASSIGN(TestSearchResult); |
51 }; | 51 }; |
52 int TestSearchResult::instantiation_count = 0; | 52 int TestSearchResult::instantiation_count = 0; |
53 | 53 |
54 class TestSearchProvider : public SearchProvider { | 54 class TestSearchProvider : public SearchProvider { |
55 public: | 55 public: |
56 explicit TestSearchProvider(const std::string& prefix) | 56 explicit TestSearchProvider(const std::string& prefix) |
57 : prefix_(prefix), count_(0) {} | 57 : prefix_(prefix), count_(0) {} |
58 virtual ~TestSearchProvider() {} | 58 ~TestSearchProvider() override {} |
59 | 59 |
60 // SearchProvider overrides: | 60 // SearchProvider overrides: |
61 virtual void Start(const base::string16& query) override { | 61 void Start(const base::string16& query) override { |
62 ClearResults(); | 62 ClearResults(); |
63 for (size_t i = 0; i < count_; ++i) { | 63 for (size_t i = 0; i < count_; ++i) { |
64 const std::string id = | 64 const std::string id = |
65 base::StringPrintf("%s%d", prefix_.c_str(), static_cast<int>(i)); | 65 base::StringPrintf("%s%d", prefix_.c_str(), static_cast<int>(i)); |
66 const double relevance = 1.0 - i / 10.0; | 66 const double relevance = 1.0 - i / 10.0; |
67 Add(scoped_ptr<SearchResult>(new TestSearchResult(id, relevance)).Pass()); | 67 Add(scoped_ptr<SearchResult>(new TestSearchResult(id, relevance)).Pass()); |
68 } | 68 } |
69 } | 69 } |
70 virtual void Stop() override {} | 70 void Stop() override {} |
71 | 71 |
72 void set_prefix(const std::string& prefix) { prefix_ = prefix; } | 72 void set_prefix(const std::string& prefix) { prefix_ = prefix; } |
73 void set_count(size_t count) { count_ = count; } | 73 void set_count(size_t count) { count_ = count; } |
74 | 74 |
75 private: | 75 private: |
76 std::string prefix_; | 76 std::string prefix_; |
77 size_t count_; | 77 size_t count_; |
78 | 78 |
79 DISALLOW_COPY_AND_ASSIGN(TestSearchProvider); | 79 DISALLOW_COPY_AND_ASSIGN(TestSearchProvider); |
80 }; | 80 }; |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 EXPECT_EQ(old_ui_result_ids[0], | 273 EXPECT_EQ(old_ui_result_ids[0], |
274 TestSearchResult::GetInstanceId(ui_results.GetItemAt(3))); | 274 TestSearchResult::GetInstanceId(ui_results.GetItemAt(3))); |
275 EXPECT_EQ(old_ui_result_ids[1], | 275 EXPECT_EQ(old_ui_result_ids[1], |
276 TestSearchResult::GetInstanceId(ui_results.GetItemAt(0))); | 276 TestSearchResult::GetInstanceId(ui_results.GetItemAt(0))); |
277 EXPECT_EQ(old_ui_result_ids[2], | 277 EXPECT_EQ(old_ui_result_ids[2], |
278 TestSearchResult::GetInstanceId(ui_results.GetItemAt(2))); | 278 TestSearchResult::GetInstanceId(ui_results.GetItemAt(2))); |
279 } | 279 } |
280 | 280 |
281 } // namespace test | 281 } // namespace test |
282 } // namespace app_list | 282 } // namespace app_list |
OLD | NEW |