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 #ifndef UI_APP_LIST_TEST_APP_LIST_TEST_VIEW_DELEGATE_H_
      6 #define UI_APP_LIST_TEST_APP_LIST_TEST_VIEW_DELEGATE_H_
      7 
      8 #include <map>
      9 #include <string>
     10 
     11 #include "base/callback_forward.h"
     12 #include "base/compiler_specific.h"
     13 #include "base/memory/scoped_ptr.h"
     14 #include "base/observer_list.h"
     15 #include "ui/app_list/app_list_view_delegate.h"
     16 #include "ui/app_list/speech_ui_model.h"
     17 
     18 namespace app_list {
     19 namespace test {
     20 
     21 class AppListTestModel;
     22 
     23 // A concrete AppListViewDelegate for unit tests.
     24 class AppListTestViewDelegate : public AppListViewDelegate {
     25  public:
     26   AppListTestViewDelegate();
     27   virtual ~AppListTestViewDelegate();
     28 
     29   int dismiss_count() { return dismiss_count_; }
     30   int open_search_result_count() { return open_search_result_count_; }
     31   void SetUsers(const Users& users) {
     32     users_ = users;
     33   }
     34   std::map<size_t, int> open_search_result_counts() {
     35     return open_search_result_counts_;
     36   }
     37 
     38   // Sets the number of apps that the model will be created with the next time
     39   // SetProfileByPath() is called.
     40   void set_next_profile_app_count(int apps) { next_profile_app_count_ = apps; }
     41 
     42   void set_auto_launch_timeout(const base::TimeDelta& timeout) {
     43     auto_launch_timeout_ = timeout;
     44   }
     45 
     46   // Returns the value of |toggle_speech_recognition_count_| and then
     47   // resets this value to 0.
     48   int GetToggleSpeechRecognitionCountAndReset();
     49 
     50   // AppListViewDelegate overrides:
     51   virtual bool ForceNativeDesktop() const OVERRIDE;
     52   virtual void SetProfileByPath(const base::FilePath& profile_path) OVERRIDE;
     53   virtual AppListModel* GetModel() OVERRIDE;
     54   virtual SpeechUIModel* GetSpeechUI() OVERRIDE;
     55   virtual void GetShortcutPathForApp(
     56       const std::string& app_id,
     57       const base::Callback<void(const base::FilePath&)>& callback) OVERRIDE;
     58   virtual void StartSearch() OVERRIDE {}
     59   virtual void StopSearch() OVERRIDE {}
     60   virtual void OpenSearchResult(SearchResult* result,
     61                                 bool auto_launch,
     62                                 int event_flags) OVERRIDE;
     63   virtual void InvokeSearchResultAction(SearchResult* result,
     64                                         int action_index,
     65                                         int event_flags) OVERRIDE {}
     66   virtual base::TimeDelta GetAutoLaunchTimeout() OVERRIDE;
     67   virtual void AutoLaunchCanceled() OVERRIDE;
     68   virtual void ViewInitialized() OVERRIDE {}
     69   virtual void Dismiss() OVERRIDE;
     70   virtual void ViewClosing() OVERRIDE {}
     71   virtual gfx::ImageSkia GetWindowIcon() OVERRIDE;
     72   virtual void OpenSettings() OVERRIDE {}
     73   virtual void OpenHelp() OVERRIDE {}
     74   virtual void OpenFeedback() OVERRIDE {}
     75   virtual void ToggleSpeechRecognition() OVERRIDE;
     76   virtual void ShowForProfileByPath(
     77       const base::FilePath& profile_path) OVERRIDE {}
     78 #if defined(TOOLKIT_VIEWS)
     79   virtual views::View* CreateStartPageWebView(const gfx::Size& size) OVERRIDE;
     80   virtual std::vector<views::View*> CreateCustomPageWebViews(
     81       const gfx::Size& size) OVERRIDE;
     82 #endif
     83   virtual bool IsSpeechRecognitionEnabled() OVERRIDE;
     84   virtual const Users& GetUsers() const OVERRIDE;
     85   virtual bool ShouldCenterWindow() const OVERRIDE;
     86   virtual void AddObserver(AppListViewDelegateObserver* observer) OVERRIDE;
     87   virtual void RemoveObserver(AppListViewDelegateObserver* observer) OVERRIDE;
     88 
     89   // Do a bulk replacement of the items in the model.
     90   void ReplaceTestModel(int item_count);
     91 
     92   AppListTestModel* ReleaseTestModel() { return model_.release(); }
     93   AppListTestModel* GetTestModel() { return model_.get(); }
     94 
     95  private:
     96   int dismiss_count_;
     97   int toggle_speech_recognition_count_;
     98   int open_search_result_count_;
     99   int next_profile_app_count_;
    100   std::map<size_t, int> open_search_result_counts_;
    101   Users users_;
    102   scoped_ptr<AppListTestModel> model_;
    103   ObserverList<AppListViewDelegateObserver> observers_;
    104   SpeechUIModel speech_ui_;
    105   base::TimeDelta auto_launch_timeout_;
    106 
    107   DISALLOW_COPY_AND_ASSIGN(AppListTestViewDelegate);
    108 };
    109 
    110 }  // namespace test
    111 }  // namespace app_list
    112 
    113 #endif  // UI_APP_LIST_TEST_APP_LIST_TEST_VIEW_DELEGATE_H_
    114