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
9 #include "base/callback.h"
10 #include "base/files/file_path.h"
11 #include "ui/app_list/app_list_model.h"
12 #include "ui/app_list/app_list_switches.h"
13 #include "ui/app_list/app_list_view_delegate_observer.h"
14 #include "ui/app_list/test/app_list_test_model.h"
15 #include "ui/gfx/image/image_skia.h"
16
17 namespace app_list {
18 namespace test {
19
AppListTestViewDelegate()20 AppListTestViewDelegate::AppListTestViewDelegate()
21 : dismiss_count_(0),
22 toggle_speech_recognition_count_(0),
23 open_search_result_count_(0),
24 next_profile_app_count_(0),
25 model_(new AppListTestModel),
26 speech_ui_(SPEECH_RECOGNITION_OFF) {
27 model_->SetFoldersEnabled(true);
28 }
29
~AppListTestViewDelegate()30 AppListTestViewDelegate::~AppListTestViewDelegate() {}
31
GetToggleSpeechRecognitionCountAndReset()32 int AppListTestViewDelegate::GetToggleSpeechRecognitionCountAndReset() {
33 int count = toggle_speech_recognition_count_;
34 toggle_speech_recognition_count_ = 0;
35 return count;
36 }
37
ForceNativeDesktop() const38 bool AppListTestViewDelegate::ForceNativeDesktop() const {
39 return false;
40 }
41
SetProfileByPath(const base::FilePath & profile_path)42 void AppListTestViewDelegate::SetProfileByPath(
43 const base::FilePath& profile_path) {
44 ReplaceTestModel(next_profile_app_count_);
45 }
46
GetModel()47 AppListModel* AppListTestViewDelegate::GetModel() {
48 return model_.get();
49 }
50
GetSpeechUI()51 SpeechUIModel* AppListTestViewDelegate::GetSpeechUI() {
52 return &speech_ui_;
53 }
54
GetShortcutPathForApp(const std::string & app_id,const base::Callback<void (const base::FilePath &)> & callback)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
OpenSearchResult(SearchResult * result,bool auto_launch,int event_flags)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
GetAutoLaunchTimeout()74 base::TimeDelta AppListTestViewDelegate::GetAutoLaunchTimeout() {
75 return auto_launch_timeout_;
76 }
77
AutoLaunchCanceled()78 void AppListTestViewDelegate::AutoLaunchCanceled() {
79 auto_launch_timeout_ = base::TimeDelta();
80 }
81
Dismiss()82 void AppListTestViewDelegate::Dismiss() {
83 ++dismiss_count_;
84 }
85
ToggleSpeechRecognition()86 void AppListTestViewDelegate::ToggleSpeechRecognition() {
87 ++toggle_speech_recognition_count_;
88 }
89
GetWindowIcon()90 gfx::ImageSkia AppListTestViewDelegate::GetWindowIcon() {
91 return gfx::ImageSkia();
92 }
93
94 #if defined(TOOLKIT_VIEWS)
CreateStartPageWebView(const gfx::Size & size)95 views::View* AppListTestViewDelegate::CreateStartPageWebView(
96 const gfx::Size& size) {
97 return NULL;
98 }
99 #endif
100
IsSpeechRecognitionEnabled()101 bool AppListTestViewDelegate::IsSpeechRecognitionEnabled() {
102 return false;
103 }
104
GetUsers() const105 const AppListViewDelegate::Users& AppListTestViewDelegate::GetUsers() const {
106 return users_;
107 }
108
ShouldCenterWindow() const109 bool AppListTestViewDelegate::ShouldCenterWindow() const {
110 return app_list::switches::IsCenteredAppListEnabled();
111 }
112
ReplaceTestModel(int item_count)113 void AppListTestViewDelegate::ReplaceTestModel(int item_count) {
114 model_.reset(new AppListTestModel);
115 model_->PopulateApps(item_count);
116 }
117
AddObserver(AppListViewDelegateObserver * observer)118 void AppListTestViewDelegate::AddObserver(
119 AppListViewDelegateObserver* observer) {
120 observers_.AddObserver(observer);
121 }
122
RemoveObserver(AppListViewDelegateObserver * observer)123 void AppListTestViewDelegate::RemoveObserver(
124 AppListViewDelegateObserver* observer) {
125 observers_.RemoveObserver(observer);
126 }
127
128 } // namespace test
129 } // namespace app_list
130