OLD | NEW |
| (Empty) |
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_COMMON_TEST_TEST_SHELF_DELEGATE_H_ | |
6 #define ASH_COMMON_TEST_TEST_SHELF_DELEGATE_H_ | |
7 | |
8 #include <map> | |
9 #include <set> | |
10 #include <string> | |
11 | |
12 #include "ash/common/shelf/shelf_delegate.h" | |
13 #include "base/macros.h" | |
14 #include "ui/aura/window_observer.h" | |
15 | |
16 namespace ash { | |
17 | |
18 class WmWindow; | |
19 | |
20 namespace test { | |
21 | |
22 class ShelfInitializer; | |
23 | |
24 // Test implementation of ShelfDelegate. | |
25 // Tests may create icons for windows by calling AddShelfItem(). | |
26 class TestShelfDelegate : public ShelfDelegate, public aura::WindowObserver { | |
27 public: | |
28 TestShelfDelegate(); | |
29 ~TestShelfDelegate() override; | |
30 | |
31 // Adds a ShelfItem for the given |window|. The ShelfItem's status will be | |
32 // STATUS_CLOSED. | |
33 void AddShelfItem(WmWindow* window); | |
34 | |
35 // Adds a ShelfItem for the given |window| and adds a mapping from the added | |
36 // ShelfItem's ShelfID to the given |app_id|. The ShelfItem's status will be | |
37 // STATUS_CLOSED. | |
38 void AddShelfItem(WmWindow* window, const std::string& app_id); | |
39 | |
40 // Adds a ShelfItem for the given |window| with the specified |status|. | |
41 void AddShelfItem(WmWindow* window, ShelfItemStatus status); | |
42 | |
43 // Removes the ShelfItem for the specified |window| and unpins it if it was | |
44 // pinned. The |window|'s ShelfID to app id mapping will be removed if it | |
45 // exists. | |
46 void RemoveShelfItemForWindow(WmWindow* window); | |
47 | |
48 static TestShelfDelegate* instance() { return instance_; } | |
49 | |
50 // WindowObserver implementation | |
51 void OnWindowDestroying(aura::Window* window) override; | |
52 void OnWindowHierarchyChanging(const HierarchyChangeParams& params) override; | |
53 | |
54 // ShelfDelegate implementation. | |
55 ShelfID GetShelfIDForAppID(const std::string& app_id) override; | |
56 ShelfID GetShelfIDForAppIDAndLaunchID(const std::string& app_id, | |
57 const std::string& launch_id) override; | |
58 bool HasShelfIDToAppIDMapping(ShelfID id) const override; | |
59 const std::string& GetAppIDForShelfID(ShelfID id) override; | |
60 void PinAppWithID(const std::string& app_id) override; | |
61 bool IsAppPinned(const std::string& app_id) override; | |
62 void UnpinAppWithID(const std::string& app_id) override; | |
63 | |
64 private: | |
65 // Adds a mapping from a ShelfID to an app id. | |
66 void AddShelfIDToAppIDMapping(ShelfID shelf_id, const std::string& app_id); | |
67 | |
68 // Removes the mapping from a ShelfID to an app id. | |
69 void RemoveShelfIDToAppIDMapping(ShelfID shelf_id); | |
70 | |
71 static TestShelfDelegate* instance_; | |
72 | |
73 std::unique_ptr<ShelfInitializer> shelf_initializer_; | |
74 | |
75 std::set<std::string> pinned_apps_; | |
76 | |
77 // Tracks the ShelfID to app id mappings. | |
78 std::map<ShelfID, std::string> shelf_id_to_app_id_map_; | |
79 | |
80 DISALLOW_COPY_AND_ASSIGN(TestShelfDelegate); | |
81 }; | |
82 | |
83 } // namespace test | |
84 } // namespace ash | |
85 | |
86 #endif // ASH_COMMON_TEST_TEST_SHELF_DELEGATE_H_ | |
OLD | NEW |