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 3 // found in the LICENSE file. 4 5 #include "ui/app_list/test/app_list_test_view_delegate.h" 6 7 #include <string> 8 #include <vector> 9 10 #include "base/callback.h" 11 #include "base/files/file_path.h" 12 #include "ui/app_list/app_list_model.h" 13 #include "ui/app_list/app_list_switches.h" 14 #include "ui/app_list/app_list_view_delegate_observer.h" 15 #include "ui/app_list/test/app_list_test_model.h" 16 #include "ui/gfx/image/image_skia.h" 17 18 namespace app_list { 19 namespace test { 20 21 AppListTestViewDelegate::AppListTestViewDelegate() 22 : dismiss_count_(0), 23 toggle_speech_recognition_count_(0), 24 open_search_result_count_(0), 25 next_profile_app_count_(0), 26 model_(new AppListTestModel) { 27 model_->SetFoldersEnabled(true); 28 } 29 30 AppListTestViewDelegate::~AppListTestViewDelegate() {} 31 32 int AppListTestViewDelegate::GetToggleSpeechRecognitionCountAndReset() { 33 int count = toggle_speech_recognition_count_; 34 toggle_speech_recognition_count_ = 0; 35 return count; 36 } 37 38 bool AppListTestViewDelegate::ForceNativeDesktop() const { 39 return false; 40 } 41 42 void AppListTestViewDelegate::SetProfileByPath( 43 const base::FilePath& profile_path) { 44 ReplaceTestModel(next_profile_app_count_); 45 } 46 47 AppListModel* AppListTestViewDelegate::GetModel() { 48 return model_.get(); 49 } 50 51 SpeechUIModel* AppListTestViewDelegate::GetSpeechUI() { 52 return &speech_ui_; 53 } 54 55 void AppListTestViewDelegate::GetShortcutPathForApp( 56 const std::string& app_id, 57 const base::Callback<void(const base::FilePath&)>& callback) { 58 callback.Run(base::FilePath()); 59 } 60 61 void AppListTestViewDelegate::OpenSearchResult(SearchResult* result, 62 bool auto_launch, 63 int event_flags) { 64 const AppListModel::SearchResults* results = model_->results(); 65 for (size_t i = 0; i < results->item_count(); ++i) { 66 if (results->GetItemAt(i) == result) { 67 open_search_result_counts_[i]++; 68 break; 69 } 70 } 71 ++open_search_result_count_; 72 } 73 74 base::TimeDelta AppListTestViewDelegate::GetAutoLaunchTimeout() { 75 return auto_launch_timeout_; 76 } 77 78 void AppListTestViewDelegate::AutoLaunchCanceled() { 79 auto_launch_timeout_ = base::TimeDelta(); 80 } 81 82 void AppListTestViewDelegate::Dismiss() { 83 ++dismiss_count_; 84 } 85 86 void AppListTestViewDelegate::ToggleSpeechRecognition() { 87 ++toggle_speech_recognition_count_; 88 } 89 90 gfx::ImageSkia AppListTestViewDelegate::GetWindowIcon() { 91 return gfx::ImageSkia(); 92 } 93 94 #if defined(TOOLKIT_VIEWS) 95 views::View* AppListTestViewDelegate::CreateStartPageWebView( 96 const gfx::Size& size) { 97 return NULL; 98 } 99 std::vector<views::View*> AppListTestViewDelegate::CreateCustomPageWebViews( 100 const gfx::Size& size) { 101 return std::vector<views::View*>(); 102 } 103 #endif 104 105 bool AppListTestViewDelegate::IsSpeechRecognitionEnabled() { 106 return false; 107 } 108 109 const AppListViewDelegate::Users& AppListTestViewDelegate::GetUsers() const { 110 return users_; 111 } 112 113 bool AppListTestViewDelegate::ShouldCenterWindow() const { 114 return app_list::switches::IsCenteredAppListEnabled(); 115 } 116 117 void AppListTestViewDelegate::ReplaceTestModel(int item_count) { 118 model_.reset(new AppListTestModel); 119 model_->PopulateApps(item_count); 120 } 121 122 void AppListTestViewDelegate::AddObserver( 123 AppListViewDelegateObserver* observer) { 124 observers_.AddObserver(observer); 125 } 126 127 void AppListTestViewDelegate::RemoveObserver( 128 AppListViewDelegateObserver* observer) { 129 observers_.RemoveObserver(observer); 130 } 131 132 } // namespace test 133 } // namespace app_list 134