| 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 "ui/app_list/search/mixer.h" |
| 6 |
| 5 #include <stddef.h> | 7 #include <stddef.h> |
| 6 | 8 |
| 7 #include <set> | 9 #include <set> |
| 8 #include <string> | 10 #include <string> |
| 9 | 11 |
| 10 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/memory/ptr_util.h" |
| 11 #include "base/memory/scoped_vector.h" | 14 #include "base/memory/scoped_vector.h" |
| 12 #include "base/metrics/field_trial.h" | 15 #include "base/metrics/field_trial.h" |
| 13 #include "base/strings/string16.h" | 16 #include "base/strings/string16.h" |
| 14 #include "base/strings/stringprintf.h" | 17 #include "base/strings/stringprintf.h" |
| 15 #include "base/strings/utf_string_conversions.h" | 18 #include "base/strings/utf_string_conversions.h" |
| 16 #include "base/test/mock_entropy_provider.h" | 19 #include "base/test/mock_entropy_provider.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
| 18 #include "ui/app_list/app_list_model.h" | 21 #include "ui/app_list/app_list_model.h" |
| 19 #include "ui/app_list/search/history_types.h" | 22 #include "ui/app_list/search/history_types.h" |
| 20 #include "ui/app_list/search/mixer.h" | |
| 21 #include "ui/app_list/search_provider.h" | 23 #include "ui/app_list/search_provider.h" |
| 22 #include "ui/app_list/search_result.h" | 24 #include "ui/app_list/search_result.h" |
| 23 | 25 |
| 24 namespace app_list { | 26 namespace app_list { |
| 25 namespace test { | 27 namespace test { |
| 26 | 28 |
| 27 // Maximum number of results to show in each mixer group. | 29 // Maximum number of results to show in each mixer group. |
| 28 const size_t kMaxAppsGroupResults = 4; | 30 const size_t kMaxAppsGroupResults = 4; |
| 29 // Ignored unless AppListMixer field trial is "Blended". | 31 // Ignored unless AppListMixer field trial is "Blended". |
| 30 const size_t kMaxOmniboxResults = 4; | 32 const size_t kMaxOmniboxResults = 4; |
| 31 const size_t kMaxWebstoreResults = 2; | 33 const size_t kMaxWebstoreResults = 2; |
| 32 const size_t kMaxPeopleResults = 2; | 34 const size_t kMaxPeopleResults = 2; |
| 33 | 35 |
| 34 class TestSearchResult : public SearchResult { | 36 class TestSearchResult : public SearchResult { |
| 35 public: | 37 public: |
| 36 TestSearchResult(const std::string& id, double relevance) | 38 TestSearchResult(const std::string& id, double relevance) |
| 37 : instance_id_(instantiation_count++) { | 39 : instance_id_(instantiation_count++) { |
| 38 set_id(id); | 40 set_id(id); |
| 39 set_title(base::UTF8ToUTF16(id)); | 41 set_title(base::UTF8ToUTF16(id)); |
| 40 set_relevance(relevance); | 42 set_relevance(relevance); |
| 41 } | 43 } |
| 42 ~TestSearchResult() override {} | 44 ~TestSearchResult() override {} |
| 43 | 45 |
| 44 using SearchResult::set_voice_result; | 46 using SearchResult::set_voice_result; |
| 45 | 47 |
| 46 // SearchResult overrides: | 48 // SearchResult overrides: |
| 47 void Open(int event_flags) override {} | 49 void Open(int event_flags) override {} |
| 48 void InvokeAction(int action_index, int event_flags) override {} | 50 void InvokeAction(int action_index, int event_flags) override {} |
| 49 scoped_ptr<SearchResult> Duplicate() const override { | 51 std::unique_ptr<SearchResult> Duplicate() const override { |
| 50 return make_scoped_ptr(new TestSearchResult(id(), relevance())); | 52 return base::WrapUnique(new TestSearchResult(id(), relevance())); |
| 51 } | 53 } |
| 52 | 54 |
| 53 // For reference equality testing. (Addresses cannot be used to test reference | 55 // For reference equality testing. (Addresses cannot be used to test reference |
| 54 // equality because it is possible that an object will be allocated at the | 56 // equality because it is possible that an object will be allocated at the |
| 55 // same address as a previously deleted one.) | 57 // same address as a previously deleted one.) |
| 56 static int GetInstanceId(SearchResult* result) { | 58 static int GetInstanceId(SearchResult* result) { |
| 57 return static_cast<const TestSearchResult*>(result)->instance_id_; | 59 return static_cast<const TestSearchResult*>(result)->instance_id_; |
| 58 } | 60 } |
| 59 | 61 |
| 60 private: | 62 private: |
| (...skipping 22 matching lines...) Expand all Loading... |
| 83 base::StringPrintf("%s%d", prefix_.c_str(), static_cast<int>(i)); | 85 base::StringPrintf("%s%d", prefix_.c_str(), static_cast<int>(i)); |
| 84 double relevance = 1.0 - i / 10.0; | 86 double relevance = 1.0 - i / 10.0; |
| 85 // If bad_relevance_range_, change the relevances to give results outside | 87 // If bad_relevance_range_, change the relevances to give results outside |
| 86 // of the canonical [0.0, 1.0] range. | 88 // of the canonical [0.0, 1.0] range. |
| 87 if (bad_relevance_range_) | 89 if (bad_relevance_range_) |
| 88 relevance = 10.0 - i * 10; | 90 relevance = 10.0 - i * 10; |
| 89 TestSearchResult* result = new TestSearchResult(id, relevance); | 91 TestSearchResult* result = new TestSearchResult(id, relevance); |
| 90 result->set_display_type(display_type_); | 92 result->set_display_type(display_type_); |
| 91 if (voice_result_indices.find(i) != voice_result_indices.end()) | 93 if (voice_result_indices.find(i) != voice_result_indices.end()) |
| 92 result->set_voice_result(true); | 94 result->set_voice_result(true); |
| 93 Add(scoped_ptr<SearchResult>(result)); | 95 Add(std::unique_ptr<SearchResult>(result)); |
| 94 } | 96 } |
| 95 } | 97 } |
| 96 void Stop() override {} | 98 void Stop() override {} |
| 97 | 99 |
| 98 void set_prefix(const std::string& prefix) { prefix_ = prefix; } | 100 void set_prefix(const std::string& prefix) { prefix_ = prefix; } |
| 99 void set_display_type(SearchResult::DisplayType display_type) { | 101 void set_display_type(SearchResult::DisplayType display_type) { |
| 100 display_type_ = display_type; | 102 display_type_ = display_type; |
| 101 } | 103 } |
| 102 void set_count(size_t count) { count_ = count; } | 104 void set_count(size_t count) { count_ = count; } |
| 103 void set_as_voice_result(size_t index) { voice_result_indices.insert(index); } | 105 void set_as_voice_result(size_t index) { voice_result_indices.insert(index); } |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 // Sets whether test runs should be treated as a voice query. | 186 // Sets whether test runs should be treated as a voice query. |
| 185 void set_is_voice_query(bool is_voice_query) { | 187 void set_is_voice_query(bool is_voice_query) { |
| 186 is_voice_query_ = is_voice_query; | 188 is_voice_query_ = is_voice_query; |
| 187 } | 189 } |
| 188 | 190 |
| 189 void AddKnownResult(const std::string& id, KnownResultType type) { | 191 void AddKnownResult(const std::string& id, KnownResultType type) { |
| 190 known_results_[id] = type; | 192 known_results_[id] = type; |
| 191 } | 193 } |
| 192 | 194 |
| 193 private: | 195 private: |
| 194 scoped_ptr<Mixer> mixer_; | 196 std::unique_ptr<Mixer> mixer_; |
| 195 scoped_ptr<AppListModel::SearchResults> results_; | 197 std::unique_ptr<AppListModel::SearchResults> results_; |
| 196 KnownResults known_results_; | 198 KnownResults known_results_; |
| 197 | 199 |
| 198 bool is_voice_query_; | 200 bool is_voice_query_; |
| 199 | 201 |
| 200 ScopedVector<TestSearchProvider> providers_; | 202 ScopedVector<TestSearchProvider> providers_; |
| 201 | 203 |
| 202 base::FieldTrialList field_trial_list_; | 204 base::FieldTrialList field_trial_list_; |
| 203 | 205 |
| 204 DISALLOW_COPY_AND_ASSIGN(MixerTest); | 206 DISALLOW_COPY_AND_ASSIGN(MixerTest); |
| 205 }; | 207 }; |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 439 | 441 |
| 440 RunQuery(); | 442 RunQuery(); |
| 441 | 443 |
| 442 // If the results are correctly clamped to the range [0.0, 1.0], the boost to | 444 // If the results are correctly clamped to the range [0.0, 1.0], the boost to |
| 443 // "people1" will push it over the first result. If not, the massive base | 445 // "people1" will push it over the first result. If not, the massive base |
| 444 // score of "people0" will erroneously keep it on top. | 446 // score of "people0" will erroneously keep it on top. |
| 445 EXPECT_EQ("people1,people0", GetResults()); | 447 EXPECT_EQ("people1,people0", GetResults()); |
| 446 } | 448 } |
| 447 | 449 |
| 448 TEST_P(MixerTest, Publish) { | 450 TEST_P(MixerTest, Publish) { |
| 449 scoped_ptr<SearchResult> result1(new TestSearchResult("app1", 0)); | 451 std::unique_ptr<SearchResult> result1(new TestSearchResult("app1", 0)); |
| 450 scoped_ptr<SearchResult> result2(new TestSearchResult("app2", 0)); | 452 std::unique_ptr<SearchResult> result2(new TestSearchResult("app2", 0)); |
| 451 scoped_ptr<SearchResult> result3(new TestSearchResult("app3", 0)); | 453 std::unique_ptr<SearchResult> result3(new TestSearchResult("app3", 0)); |
| 452 scoped_ptr<SearchResult> result3_copy = result3->Duplicate(); | 454 std::unique_ptr<SearchResult> result3_copy = result3->Duplicate(); |
| 453 scoped_ptr<SearchResult> result4(new TestSearchResult("app4", 0)); | 455 std::unique_ptr<SearchResult> result4(new TestSearchResult("app4", 0)); |
| 454 scoped_ptr<SearchResult> result5(new TestSearchResult("app5", 0)); | 456 std::unique_ptr<SearchResult> result5(new TestSearchResult("app5", 0)); |
| 455 | 457 |
| 456 AppListModel::SearchResults ui_results; | 458 AppListModel::SearchResults ui_results; |
| 457 | 459 |
| 458 // Publish the first three results to |ui_results|. | 460 // Publish the first three results to |ui_results|. |
| 459 Mixer::SortedResults new_results; | 461 Mixer::SortedResults new_results; |
| 460 new_results.push_back(Mixer::SortData(result1.get(), 1.0f)); | 462 new_results.push_back(Mixer::SortData(result1.get(), 1.0f)); |
| 461 new_results.push_back(Mixer::SortData(result2.get(), 1.0f)); | 463 new_results.push_back(Mixer::SortData(result2.get(), 1.0f)); |
| 462 new_results.push_back(Mixer::SortData(result3.get(), 1.0f)); | 464 new_results.push_back(Mixer::SortData(result3.get(), 1.0f)); |
| 463 | 465 |
| 464 Mixer::Publish(new_results, &ui_results); | 466 Mixer::Publish(new_results, &ui_results); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 530 EXPECT_EQ(old_ui_result_ids[1], | 532 EXPECT_EQ(old_ui_result_ids[1], |
| 531 TestSearchResult::GetInstanceId(ui_results.GetItemAt(0))); | 533 TestSearchResult::GetInstanceId(ui_results.GetItemAt(0))); |
| 532 EXPECT_EQ(old_ui_result_ids[2], | 534 EXPECT_EQ(old_ui_result_ids[2], |
| 533 TestSearchResult::GetInstanceId(ui_results.GetItemAt(2))); | 535 TestSearchResult::GetInstanceId(ui_results.GetItemAt(2))); |
| 534 } | 536 } |
| 535 | 537 |
| 536 INSTANTIATE_TEST_CASE_P(MixerTestInstance, MixerTest, testing::Bool()); | 538 INSTANTIATE_TEST_CASE_P(MixerTestInstance, MixerTest, testing::Bool()); |
| 537 | 539 |
| 538 } // namespace test | 540 } // namespace test |
| 539 } // namespace app_list | 541 } // namespace app_list |
| OLD | NEW |