Home | History | Annotate | Download | only in test
      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 
     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 
     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 #endif
    100 
    101 bool AppListTestViewDelegate::IsSpeechRecognitionEnabled() {
    102   return false;
    103 }
    104 
    105 const AppListViewDelegate::Users& AppListTestViewDelegate::GetUsers() const {
    106   return users_;
    107 }
    108 
    109 bool AppListTestViewDelegate::ShouldCenterWindow() const {
    110   return app_list::switches::IsCenteredAppListEnabled();
    111 }
    112 
    113 void AppListTestViewDelegate::ReplaceTestModel(int item_count) {
    114   model_.reset(new AppListTestModel);
    115   model_->PopulateApps(item_count);
    116 }
    117 
    118 void AppListTestViewDelegate::AddObserver(
    119     AppListViewDelegateObserver* observer) {
    120   observers_.AddObserver(observer);
    121 }
    122 
    123 void AppListTestViewDelegate::RemoveObserver(
    124     AppListViewDelegateObserver* observer) {
    125   observers_.RemoveObserver(observer);
    126 }
    127 
    128 }  // namespace test
    129 }  // namespace app_list
    130