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" |
11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
13 #include "ui/app_list/app_list_model.h" | 13 #include "ui/app_list/app_list_model.h" |
14 #include "ui/app_list/search/history_types.h" | 14 #include "ui/app_list/search/history_types.h" |
15 #include "ui/app_list/search/mixer.h" | 15 #include "ui/app_list/search/mixer.h" |
16 #include "ui/app_list/search_provider.h" | 16 #include "ui/app_list/search_provider.h" |
17 #include "ui/app_list/search_result.h" | 17 #include "ui/app_list/search_result.h" |
18 | 18 |
19 namespace app_list { | 19 namespace app_list { |
20 namespace test { | 20 namespace test { |
21 | 21 |
22 // Maximum number of results to show in each mixer group. | 22 // Maximum number of results to show in each mixer group. |
23 const size_t kMaxAppsGroupResults = 4; | 23 const size_t kMaxAppsGroupResults = 4; |
24 const size_t kMaxOmniboxResults = 0; // Ignored. | 24 // Ignored unless AppListMixer field trial is "Blended". |
| 25 const size_t kMaxOmniboxResults = 4; |
25 const size_t kMaxWebstoreResults = 2; | 26 const size_t kMaxWebstoreResults = 2; |
26 const size_t kMaxPeopleResults = 2; | 27 const size_t kMaxPeopleResults = 2; |
27 | 28 |
28 class TestSearchResult : public SearchResult { | 29 class TestSearchResult : public SearchResult { |
29 public: | 30 public: |
30 TestSearchResult(const std::string& id, double relevance) | 31 TestSearchResult(const std::string& id, double relevance) |
31 : instance_id_(instantiation_count++) { | 32 : instance_id_(instantiation_count++) { |
32 set_id(id); | 33 set_id(id); |
33 set_title(base::UTF8ToUTF16(id)); | 34 set_title(base::UTF8ToUTF16(id)); |
34 set_relevance(relevance); | 35 set_relevance(relevance); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 private: | 94 private: |
94 std::string prefix_; | 95 std::string prefix_; |
95 size_t count_; | 96 size_t count_; |
96 bool bad_relevance_range_; | 97 bool bad_relevance_range_; |
97 // Indices of results that will have the |voice_result| flag set. | 98 // Indices of results that will have the |voice_result| flag set. |
98 std::set<size_t> voice_result_indices; | 99 std::set<size_t> voice_result_indices; |
99 | 100 |
100 DISALLOW_COPY_AND_ASSIGN(TestSearchProvider); | 101 DISALLOW_COPY_AND_ASSIGN(TestSearchProvider); |
101 }; | 102 }; |
102 | 103 |
| 104 // TODO(mgiuca): Parameterize this test so it tests both the default and |
| 105 // "Blended" states for the AppListMixer field trial. |
103 class MixerTest : public testing::Test { | 106 class MixerTest : public testing::Test { |
104 public: | 107 public: |
105 MixerTest() : is_voice_query_(false) {} | 108 MixerTest() : is_voice_query_(false) {} |
106 ~MixerTest() override {} | 109 ~MixerTest() override {} |
107 | 110 |
108 // testing::Test overrides: | 111 // testing::Test overrides: |
109 void SetUp() override { | 112 void SetUp() override { |
110 results_.reset(new AppListModel::SearchResults); | 113 results_.reset(new AppListModel::SearchResults); |
111 | 114 |
112 providers_.push_back(new TestSearchProvider("app")); | 115 providers_.push_back(new TestSearchProvider("app")); |
113 providers_.push_back(new TestSearchProvider("omnibox")); | 116 providers_.push_back(new TestSearchProvider("omnibox")); |
114 providers_.push_back(new TestSearchProvider("webstore")); | 117 providers_.push_back(new TestSearchProvider("webstore")); |
115 providers_.push_back(new TestSearchProvider("people")); | 118 providers_.push_back(new TestSearchProvider("people")); |
116 | 119 |
117 is_voice_query_ = false; | 120 is_voice_query_ = false; |
118 | 121 |
119 mixer_.reset(new Mixer(results_.get())); | 122 mixer_.reset(new Mixer(results_.get())); |
120 | 123 |
121 size_t apps_group_id = mixer_->AddGroup(kMaxAppsGroupResults, 3.0); | 124 size_t apps_group_id = mixer_->AddGroup(kMaxAppsGroupResults, 3.0, 1.0); |
122 size_t omnibox_group_id = mixer_->AddOmniboxGroup(kMaxOmniboxResults, 2.0); | 125 size_t omnibox_group_id = |
123 size_t webstore_group_id = mixer_->AddGroup(kMaxWebstoreResults, 1.0); | 126 mixer_->AddOmniboxGroup(kMaxOmniboxResults, 2.0, 1.0); |
124 size_t people_group_id = mixer_->AddGroup(kMaxPeopleResults, 0.0); | 127 size_t webstore_group_id = mixer_->AddGroup(kMaxWebstoreResults, 1.0, 0.5); |
| 128 size_t people_group_id = mixer_->AddGroup(kMaxPeopleResults, 0.0, 1.0); |
125 | 129 |
126 mixer_->AddProviderToGroup(apps_group_id, providers_[0]); | 130 mixer_->AddProviderToGroup(apps_group_id, providers_[0]); |
127 mixer_->AddProviderToGroup(omnibox_group_id, providers_[1]); | 131 mixer_->AddProviderToGroup(omnibox_group_id, providers_[1]); |
128 mixer_->AddProviderToGroup(webstore_group_id, providers_[2]); | 132 mixer_->AddProviderToGroup(webstore_group_id, providers_[2]); |
129 mixer_->AddProviderToGroup(people_group_id, providers_[3]); | 133 mixer_->AddProviderToGroup(people_group_id, providers_[3]); |
130 } | 134 } |
131 | 135 |
132 void RunQuery() { | 136 void RunQuery() { |
133 const base::string16 query; | 137 const base::string16 query; |
134 | 138 |
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
383 EXPECT_EQ(old_ui_result_ids[0], | 387 EXPECT_EQ(old_ui_result_ids[0], |
384 TestSearchResult::GetInstanceId(ui_results.GetItemAt(3))); | 388 TestSearchResult::GetInstanceId(ui_results.GetItemAt(3))); |
385 EXPECT_EQ(old_ui_result_ids[1], | 389 EXPECT_EQ(old_ui_result_ids[1], |
386 TestSearchResult::GetInstanceId(ui_results.GetItemAt(0))); | 390 TestSearchResult::GetInstanceId(ui_results.GetItemAt(0))); |
387 EXPECT_EQ(old_ui_result_ids[2], | 391 EXPECT_EQ(old_ui_result_ids[2], |
388 TestSearchResult::GetInstanceId(ui_results.GetItemAt(2))); | 392 TestSearchResult::GetInstanceId(ui_results.GetItemAt(2))); |
389 } | 393 } |
390 | 394 |
391 } // namespace test | 395 } // namespace test |
392 } // namespace app_list | 396 } // namespace app_list |
OLD | NEW |