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