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