| 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 "chrome/browser/ui/app_list/search/app_search_provider.h" | 5 #include "chrome/browser/ui/app_list/search/app_search_provider.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 |
| 9 #include <memory> |
| 8 #include <string> | 10 #include <string> |
| 9 #include <utility> | 11 #include <utility> |
| 10 | 12 |
| 11 #include "base/macros.h" | 13 #include "base/macros.h" |
| 12 #include "base/memory/scoped_ptr.h" | |
| 13 #include "base/run_loop.h" | 14 #include "base/run_loop.h" |
| 14 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
| 15 #include "base/test/simple_test_clock.h" | 16 #include "base/test/simple_test_clock.h" |
| 16 #include "chrome/browser/extensions/extension_service.h" | 17 #include "chrome/browser/extensions/extension_service.h" |
| 17 #include "chrome/browser/ui/app_list/app_list_test_util.h" | 18 #include "chrome/browser/ui/app_list/app_list_test_util.h" |
| 18 #include "chrome/browser/ui/app_list/extension_app_model_builder.h" | 19 #include "chrome/browser/ui/app_list/extension_app_model_builder.h" |
| 19 #include "chrome/browser/ui/app_list/test/test_app_list_controller_delegate.h" | 20 #include "chrome/browser/ui/app_list/test/test_app_list_controller_delegate.h" |
| 20 #include "chrome/common/chrome_constants.h" | 21 #include "chrome/common/chrome_constants.h" |
| 21 #include "chrome/test/base/testing_profile.h" | 22 #include "chrome/test/base/testing_profile.h" |
| 22 #include "extensions/browser/extension_prefs.h" | 23 #include "extensions/browser/extension_prefs.h" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 void SetUp() override { | 55 void SetUp() override { |
| 55 AppListTestBase::SetUp(); | 56 AppListTestBase::SetUp(); |
| 56 | 57 |
| 57 model_.reset(new app_list::AppListModel); | 58 model_.reset(new app_list::AppListModel); |
| 58 controller_.reset(new ::test::TestAppListControllerDelegate); | 59 controller_.reset(new ::test::TestAppListControllerDelegate); |
| 59 builder_.reset(new ExtensionAppModelBuilder(controller_.get())); | 60 builder_.reset(new ExtensionAppModelBuilder(controller_.get())); |
| 60 builder_->InitializeWithProfile(profile_.get(), model_.get()); | 61 builder_->InitializeWithProfile(profile_.get(), model_.get()); |
| 61 } | 62 } |
| 62 | 63 |
| 63 void CreateSearch() { | 64 void CreateSearch() { |
| 64 scoped_ptr<base::SimpleTestClock> clock(new base::SimpleTestClock()); | 65 std::unique_ptr<base::SimpleTestClock> clock(new base::SimpleTestClock()); |
| 65 clock->SetNow(kTestCurrentTime); | 66 clock->SetNow(kTestCurrentTime); |
| 66 app_search_.reset(new AppSearchProvider(profile_.get(), nullptr, | 67 app_search_.reset(new AppSearchProvider(profile_.get(), nullptr, |
| 67 std::move(clock), | 68 std::move(clock), |
| 68 model_->top_level_item_list())); | 69 model_->top_level_item_list())); |
| 69 } | 70 } |
| 70 | 71 |
| 71 std::string RunQuery(const std::string& query) { | 72 std::string RunQuery(const std::string& query) { |
| 72 app_search_->Start(false, base::UTF8ToUTF16(query)); | 73 app_search_->Start(false, base::UTF8ToUTF16(query)); |
| 73 | 74 |
| 74 // Sort results by relevance. | 75 // Sort results by relevance. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 85 | 86 |
| 86 result_str += base::UTF16ToUTF8(sorted_results[i]->title()); | 87 result_str += base::UTF16ToUTF8(sorted_results[i]->title()); |
| 87 } | 88 } |
| 88 return result_str; | 89 return result_str; |
| 89 } | 90 } |
| 90 | 91 |
| 91 AppListModel* model() { return model_.get(); } | 92 AppListModel* model() { return model_.get(); } |
| 92 const SearchProvider::Results& results() { return app_search_->results(); } | 93 const SearchProvider::Results& results() { return app_search_->results(); } |
| 93 | 94 |
| 94 private: | 95 private: |
| 95 scoped_ptr<app_list::AppListModel> model_; | 96 std::unique_ptr<app_list::AppListModel> model_; |
| 96 scoped_ptr<AppSearchProvider> app_search_; | 97 std::unique_ptr<AppSearchProvider> app_search_; |
| 97 scoped_ptr<ExtensionAppModelBuilder> builder_; | 98 std::unique_ptr<ExtensionAppModelBuilder> builder_; |
| 98 scoped_ptr<::test::TestAppListControllerDelegate> controller_; | 99 std::unique_ptr<::test::TestAppListControllerDelegate> controller_; |
| 99 | 100 |
| 100 DISALLOW_COPY_AND_ASSIGN(AppSearchProviderTest); | 101 DISALLOW_COPY_AND_ASSIGN(AppSearchProviderTest); |
| 101 }; | 102 }; |
| 102 | 103 |
| 103 TEST_F(AppSearchProviderTest, Basic) { | 104 TEST_F(AppSearchProviderTest, Basic) { |
| 104 #if defined(OS_CHROMEOS) | 105 #if defined(OS_CHROMEOS) |
| 105 ArcAppTest arc_test; | 106 ArcAppTest arc_test; |
| 106 arc_test.SetUp(profile()); | 107 arc_test.SetUp(profile()); |
| 107 arc_test.bridge_service()->SetReady(); | 108 arc_test.bridge_service()->SetReady(); |
| 108 arc_test.app_instance()->RefreshAppList(); | 109 arc_test.app_instance()->RefreshAppList(); |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 prefs->SetLastLaunchTime(kPackagedApp2Id, base::Time::FromInternalValue(0)); | 254 prefs->SetLastLaunchTime(kPackagedApp2Id, base::Time::FromInternalValue(0)); |
| 254 EXPECT_EQ("Hosted App,Packaged App 1,Packaged App 2", RunQuery("")); | 255 EXPECT_EQ("Hosted App,Packaged App 1,Packaged App 2", RunQuery("")); |
| 255 | 256 |
| 256 // Switching the app list order should change the query result. | 257 // Switching the app list order should change the query result. |
| 257 model()->SetItemPosition( | 258 model()->SetItemPosition( |
| 258 model()->FindItem(kPackagedApp2Id), | 259 model()->FindItem(kPackagedApp2Id), |
| 259 model()->FindItem(kPackagedApp1Id)->position().CreateBefore()); | 260 model()->FindItem(kPackagedApp1Id)->position().CreateBefore()); |
| 260 EXPECT_EQ("Hosted App,Packaged App 2,Packaged App 1", RunQuery("")); | 261 EXPECT_EQ("Hosted App,Packaged App 2,Packaged App 1", RunQuery("")); |
| 261 | 262 |
| 262 // Moving an app into a folder deprioritizes it. | 263 // Moving an app into a folder deprioritizes it. |
| 263 model()->AddItem(scoped_ptr<AppListFolderItem>( | 264 model()->AddItem(std::unique_ptr<AppListFolderItem>( |
| 264 new AppListFolderItem(kFolderId, AppListFolderItem::FOLDER_TYPE_NORMAL))); | 265 new AppListFolderItem(kFolderId, AppListFolderItem::FOLDER_TYPE_NORMAL))); |
| 265 model()->MoveItemToFolder(model()->FindItem(kPackagedApp2Id), kFolderId); | 266 model()->MoveItemToFolder(model()->FindItem(kPackagedApp2Id), kFolderId); |
| 266 EXPECT_EQ("Hosted App,Packaged App 1,Packaged App 2", RunQuery("")); | 267 EXPECT_EQ("Hosted App,Packaged App 1,Packaged App 2", RunQuery("")); |
| 267 | 268 |
| 268 // The position of the folder shouldn't matter. | 269 // The position of the folder shouldn't matter. |
| 269 model()->SetItemPosition( | 270 model()->SetItemPosition( |
| 270 model()->FindItem(kFolderId), | 271 model()->FindItem(kFolderId), |
| 271 model()->FindItem(kPackagedApp1Id)->position().CreateBefore()); | 272 model()->FindItem(kPackagedApp1Id)->position().CreateBefore()); |
| 272 EXPECT_EQ("Hosted App,Packaged App 1,Packaged App 2", RunQuery("")); | 273 EXPECT_EQ("Hosted App,Packaged App 1,Packaged App 2", RunQuery("")); |
| 273 } | 274 } |
| 274 | 275 |
| 275 } // namespace test | 276 } // namespace test |
| 276 } // namespace app_list | 277 } // namespace app_list |
| OLD | NEW |