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_MODEL_H_
      6 #define UI_APP_LIST_TEST_APP_LIST_TEST_MODEL_H_
      7 
      8 #include <string>
      9 
     10 #include "ui/app_list/app_list_folder_item.h"
     11 #include "ui/app_list/app_list_item.h"
     12 #include "ui/app_list/app_list_model.h"
     13 
     14 namespace app_list {
     15 
     16 namespace test {
     17 
     18 // Extends AppListModel with helper functions for use in tests.
     19 class AppListTestModel : public AppListModel {
     20  public:
     21   class AppListTestItem : public AppListItem {
     22    public:
     23     AppListTestItem(const std::string& id, AppListTestModel* model);
     24     virtual ~AppListTestItem();
     25     virtual void Activate(int event_flags) OVERRIDE;
     26     virtual const char* GetItemType() const OVERRIDE;
     27 
     28     void SetPosition(const syncer::StringOrdinal& new_position);
     29 
     30    private:
     31     AppListTestModel* model_;
     32 
     33     DISALLOW_COPY_AND_ASSIGN(AppListTestItem);
     34   };
     35 
     36   static const char kItemType[];
     37 
     38   AppListTestModel();
     39 
     40   // Raw pointer version convenience versions of AppListModel methods.
     41   AppListItem* AddItem(AppListItem* item);
     42   AppListItem* AddItemToFolder(AppListItem* item, const std::string& folder_id);
     43   void MoveItemToFolder(AppListItem* item, const std::string& folder_id);
     44 
     45   // Generates a name based on |id|.
     46   std::string GetItemName(int id);
     47 
     48   // Populate the model with |n| items titled "Item #".
     49   void PopulateApps(int n);
     50 
     51   // Creates and populate a folder with |n| test apps in it.
     52   AppListFolderItem* CreateAndPopulateFolderWithApps(int n);
     53 
     54   AppListFolderItem* CreateAndAddOemFolder(const std::string& id);
     55 
     56   AppListFolderItem* CreateSingleItemFolder(const std::string& folder_id,
     57                                             const std::string& item_id);
     58 
     59   // Populate the model with an item titled "Item |id|".
     60   void PopulateAppWithId(int id);
     61 
     62   // Get a string of all apps in |model| joined with ','.
     63   std::string GetModelContent();
     64 
     65   // Creates an item with id |id|. Caller owns the result.
     66   AppListTestItem* CreateItem(const std::string& id);
     67 
     68   // Creates and adds an item with id |id| to the model. Returns an unowned
     69   // pointer to the created item.
     70   AppListTestItem* CreateAndAddItem(const std::string& id);
     71 
     72   // Call SetHighlighted on the specified item.
     73   void HighlightItemAt(int index);
     74 
     75   int activate_count() { return activate_count_; }
     76   AppListItem* last_activated() { return last_activated_; }
     77 
     78  private:
     79   void ItemActivated(AppListTestItem* item);
     80 
     81   int activate_count_;
     82   AppListItem* last_activated_;
     83 
     84   DISALLOW_COPY_AND_ASSIGN(AppListTestModel);
     85 };
     86 
     87 }  // namespace test
     88 }  // namespace app_list
     89 
     90 #endif  // UI_APP_LIST_TEST_APP_LIST_TEST_MODEL_H_
     91