Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / ui / app_list / test / app_list_test_view_delegate.cc
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_view_delegate_observer.h"
13 #include "ui/app_list/signin_delegate.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
20 class TestSigninDelegate : public SigninDelegate {
21  public:
22   TestSigninDelegate() : signed_in_(true) {}
23
24   void set_signed_in(bool signed_in) { signed_in_ = signed_in; }
25
26   // SigninDelegate overrides:
27   virtual bool NeedSignin() OVERRIDE { return !signed_in_; }
28   virtual void ShowSignin() OVERRIDE {}
29   virtual void OpenLearnMore() OVERRIDE {}
30   virtual void OpenSettings() OVERRIDE {}
31
32   virtual base::string16 GetSigninHeading() OVERRIDE {
33     return base::string16();
34   }
35   virtual base::string16 GetSigninText() OVERRIDE { return base::string16(); }
36   virtual base::string16 GetSigninButtonText() OVERRIDE {
37     return base::string16();
38   }
39   virtual base::string16 GetLearnMoreLinkText() OVERRIDE {
40     return base::string16();
41   }
42   virtual base::string16 GetSettingsLinkText() OVERRIDE {
43     return base::string16();
44   }
45
46  private:
47   bool signed_in_;
48
49   DISALLOW_COPY_AND_ASSIGN(TestSigninDelegate);
50 };
51
52 AppListTestViewDelegate::AppListTestViewDelegate()
53     : dismiss_count_(0),
54       open_search_result_count_(0),
55       test_signin_delegate_(new TestSigninDelegate),
56       model_(new AppListTestModel),
57       speech_ui_(SPEECH_RECOGNITION_OFF) {
58 }
59
60 AppListTestViewDelegate::~AppListTestViewDelegate() {}
61
62 void AppListTestViewDelegate::SetSignedIn(bool signed_in) {
63   test_signin_delegate_->set_signed_in(signed_in);
64   FOR_EACH_OBSERVER(AppListViewDelegateObserver,
65                     observers_,
66                     OnProfilesChanged());
67 }
68
69 bool AppListTestViewDelegate::ForceNativeDesktop() const {
70   return false;
71 }
72
73 AppListModel* AppListTestViewDelegate::GetModel() {
74   return model_.get();
75 }
76
77 SigninDelegate* AppListTestViewDelegate::GetSigninDelegate() {
78   return test_signin_delegate_.get();
79 }
80
81 SpeechUIModel* AppListTestViewDelegate::GetSpeechUI() {
82   return &speech_ui_;
83 }
84
85 void AppListTestViewDelegate::GetShortcutPathForApp(
86     const std::string& app_id,
87     const base::Callback<void(const base::FilePath&)>& callback) {
88   callback.Run(base::FilePath());
89 }
90
91 void AppListTestViewDelegate::OpenSearchResult(SearchResult* result,
92                                                bool auto_launch,
93                                                int event_flags) {
94   const AppListModel::SearchResults* results = model_->results();
95   for (size_t i = 0; i < results->item_count(); ++i) {
96     if (results->GetItemAt(i) == result) {
97       open_search_result_counts_[i]++;
98       break;
99     }
100   }
101   ++open_search_result_count_;
102 }
103
104 base::TimeDelta AppListTestViewDelegate::GetAutoLaunchTimeout() {
105   return auto_launch_timeout_;
106 }
107
108 void AppListTestViewDelegate::AutoLaunchCanceled() {
109   auto_launch_timeout_ = base::TimeDelta();
110 }
111
112 void AppListTestViewDelegate::Dismiss() {
113   ++dismiss_count_;
114 }
115
116 gfx::ImageSkia AppListTestViewDelegate::GetWindowIcon() {
117   return gfx::ImageSkia();
118 }
119
120 content::WebContents* AppListTestViewDelegate::GetStartPageContents() {
121   return NULL;
122 }
123
124 content::WebContents* AppListTestViewDelegate::GetSpeechRecognitionContents() {
125   return NULL;
126 }
127
128 const AppListViewDelegate::Users& AppListTestViewDelegate::GetUsers() const {
129   return users_;
130 }
131
132 bool AppListTestViewDelegate::ShouldCenterWindow() const {
133   return false;
134 }
135
136 void AppListTestViewDelegate::ReplaceTestModel(int item_count) {
137   model_.reset(new AppListTestModel);
138   model_->PopulateApps(item_count);
139 }
140
141 void AppListTestViewDelegate::AddObserver(
142     AppListViewDelegateObserver* observer) {
143   observers_.AddObserver(observer);
144 }
145
146 void AppListTestViewDelegate::RemoveObserver(
147     AppListViewDelegateObserver* observer) {
148   observers_.RemoveObserver(observer);
149 }
150
151 }  // namespace test
152 }  // namespace app_list