Chromium Code Reviews| 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 #include "ash/common/test/test_shelf_delegate.h" | 5 #include "ash/common/test/test_shelf_delegate.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "ash/common/shelf/shelf_model.h" | 9 #include "ash/common/shelf/shelf_model.h" |
| 10 #include "ash/common/shelf/wm_shelf.h" | |
| 11 #include "ash/common/shell_observer.h" | |
| 10 #include "ash/common/test/test_shelf_item_delegate.h" | 12 #include "ash/common/test/test_shelf_item_delegate.h" |
| 13 #include "ash/common/wm_shell.h" | |
| 11 #include "ash/common/wm_window.h" | 14 #include "ash/common/wm_window.h" |
| 12 #include "ash/common/wm_window_property.h" | 15 #include "ash/common/wm_window_property.h" |
| 16 #include "ash/root_window_controller.h" | |
| 13 #include "base/memory/ptr_util.h" | 17 #include "base/memory/ptr_util.h" |
| 14 | 18 |
| 15 namespace ash { | 19 namespace ash { |
| 16 namespace test { | 20 namespace test { |
| 17 | 21 |
| 18 TestShelfDelegate* TestShelfDelegate::instance_ = nullptr; | 22 TestShelfDelegate* TestShelfDelegate::instance_ = nullptr; |
| 19 | 23 |
| 24 // A ShellObserver that sets the shelf alignment and auto hide behavior when the | |
| 25 // shelf is created, to simulate ChromeLauncherController's behavior. | |
| 26 class ShelfInitializer : public ShellObserver { | |
| 27 public: | |
| 28 ShelfInitializer() { WmShell::Get()->AddShellObserver(this); } | |
| 29 ~ShelfInitializer() override { WmShell::Get()->RemoveShellObserver(this); } | |
| 30 | |
| 31 // ShellObserver: | |
| 32 void OnShelfCreatedForRootWindow(WmWindow* root_window) override { | |
| 33 WmShelf* shelf = root_window->GetRootWindowController()->GetShelf(); | |
| 34 // Do not override the custom initialization performed by some unit tests. | |
| 35 if (shelf->alignment() == SHELF_ALIGNMENT_BOTTOM_LOCKED && | |
| 36 shelf->auto_hide_behavior() == SHELF_AUTO_HIDE_ALWAYS_HIDDEN) { | |
| 37 shelf->SetAlignment(SHELF_ALIGNMENT_BOTTOM); | |
| 38 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER); | |
| 39 shelf->UpdateVisibilityState(); | |
| 40 } | |
| 41 } | |
| 42 | |
| 43 private: | |
| 44 DISALLOW_COPY_AND_ASSIGN(ShelfInitializer); | |
| 45 }; | |
| 46 | |
| 20 TestShelfDelegate::TestShelfDelegate(ShelfModel* model) : model_(model) { | 47 TestShelfDelegate::TestShelfDelegate(ShelfModel* model) : model_(model) { |
| 21 CHECK(!instance_); | 48 CHECK(!instance_); |
| 22 instance_ = this; | 49 instance_ = this; |
| 50 shelf_initializer_ = base::MakeUnique<ShelfInitializer>(); | |
|
James Cook
2017/02/14 01:38:03
Can this go in the initializer list? If not, comme
msw
2017/02/14 05:13:18
Done.
| |
| 23 } | 51 } |
| 24 | 52 |
| 25 TestShelfDelegate::~TestShelfDelegate() { | 53 TestShelfDelegate::~TestShelfDelegate() { |
| 26 instance_ = nullptr; | 54 instance_ = nullptr; |
| 27 } | 55 } |
| 28 | 56 |
| 29 void TestShelfDelegate::AddShelfItem(WmWindow* window) { | 57 void TestShelfDelegate::AddShelfItem(WmWindow* window) { |
| 30 AddShelfItem(window, STATUS_CLOSED); | 58 AddShelfItem(window, STATUS_CLOSED); |
| 31 } | 59 } |
| 32 | 60 |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 122 const std::string& app_id) { | 150 const std::string& app_id) { |
| 123 shelf_id_to_app_id_map_[shelf_id] = app_id; | 151 shelf_id_to_app_id_map_[shelf_id] = app_id; |
| 124 } | 152 } |
| 125 | 153 |
| 126 void TestShelfDelegate::RemoveShelfIDToAppIDMapping(ShelfID shelf_id) { | 154 void TestShelfDelegate::RemoveShelfIDToAppIDMapping(ShelfID shelf_id) { |
| 127 shelf_id_to_app_id_map_.erase(shelf_id); | 155 shelf_id_to_app_id_map_.erase(shelf_id); |
| 128 } | 156 } |
| 129 | 157 |
| 130 } // namespace test | 158 } // namespace test |
| 131 } // namespace ash | 159 } // namespace ash |
| OLD | NEW |