| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/mus/test/wm_test_base.h" | 5 #include "ash/mus/test/wm_test_base.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "ash/mus/bridge/wm_window_mus_test_api.h" | 10 #include "ash/mus/bridge/wm_window_mus_test_api.h" |
| 11 #include "ash/mus/root_window_controller.h" | 11 #include "ash/mus/root_window_controller.h" |
| 12 #include "ash/mus/test/wm_test_helper.h" | 12 #include "ash/mus/test/wm_test_helper.h" |
| 13 #include "ash/mus/window_manager.h" | 13 #include "ash/mus/window_manager.h" |
| 14 #include "ash/mus/window_manager_application.h" | 14 #include "ash/mus/window_manager_application.h" |
| 15 #include "services/ui/public/cpp/property_type_converters.h" | 15 #include "services/ui/public/cpp/property_type_converters.h" |
| 16 #include "services/ui/public/cpp/window_tree_client.h" | 16 #include "ui/aura/mus/property_converter.h" |
| 17 #include "ui/aura/mus/window_tree_client.h" |
| 18 #include "ui/aura/window.h" |
| 19 #include "ui/compositor/scoped_animation_duration_scale_mode.h" |
| 20 #include "ui/display/display.h" |
| 17 | 21 |
| 18 namespace ash { | 22 namespace ash { |
| 19 namespace mus { | 23 namespace mus { |
| 20 namespace { | 24 namespace { |
| 21 | 25 |
| 22 ui::mojom::WindowType MusWindowTypeFromWmWindowType( | 26 ui::mojom::WindowType MusWindowTypeFromWmWindowType( |
| 23 ui::wm::WindowType wm_window_type) { | 27 ui::wm::WindowType wm_window_type) { |
| 24 switch (wm_window_type) { | 28 switch (wm_window_type) { |
| 25 case ui::wm::WINDOW_TYPE_UNKNOWN: | 29 case ui::wm::WINDOW_TYPE_UNKNOWN: |
| 26 break; | 30 break; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 } | 64 } |
| 61 | 65 |
| 62 bool WmTestBase::SupportsMultipleDisplays() const { | 66 bool WmTestBase::SupportsMultipleDisplays() const { |
| 63 return true; | 67 return true; |
| 64 } | 68 } |
| 65 | 69 |
| 66 void WmTestBase::UpdateDisplay(const std::string& display_spec) { | 70 void WmTestBase::UpdateDisplay(const std::string& display_spec) { |
| 67 test_helper_->UpdateDisplay(display_spec); | 71 test_helper_->UpdateDisplay(display_spec); |
| 68 } | 72 } |
| 69 | 73 |
| 70 ui::Window* WmTestBase::GetPrimaryRootWindow() { | 74 aura::Window* WmTestBase::GetPrimaryRootWindow() { |
| 71 std::vector<RootWindowController*> roots = | 75 std::vector<RootWindowController*> roots = |
| 72 test_helper_->GetRootsOrderedByDisplayId(); | 76 test_helper_->GetRootsOrderedByDisplayId(); |
| 73 DCHECK(!roots.empty()); | 77 DCHECK(!roots.empty()); |
| 74 return roots[0]->root(); | 78 return roots[0]->root(); |
| 75 } | 79 } |
| 76 | 80 |
| 77 ui::Window* WmTestBase::GetSecondaryRootWindow() { | 81 aura::Window* WmTestBase::GetSecondaryRootWindow() { |
| 78 std::vector<RootWindowController*> roots = | 82 std::vector<RootWindowController*> roots = |
| 79 test_helper_->GetRootsOrderedByDisplayId(); | 83 test_helper_->GetRootsOrderedByDisplayId(); |
| 80 return roots.size() < 2 ? nullptr : roots[1]->root(); | 84 return roots.size() < 2 ? nullptr : roots[1]->root(); |
| 81 } | 85 } |
| 82 | 86 |
| 83 display::Display WmTestBase::GetPrimaryDisplay() { | 87 display::Display WmTestBase::GetPrimaryDisplay() { |
| 84 std::vector<RootWindowController*> roots = | 88 std::vector<RootWindowController*> roots = |
| 85 test_helper_->GetRootsOrderedByDisplayId(); | 89 test_helper_->GetRootsOrderedByDisplayId(); |
| 86 DCHECK(!roots.empty()); | 90 DCHECK(!roots.empty()); |
| 87 return roots[0]->display(); | 91 return roots[0]->display(); |
| 88 } | 92 } |
| 89 | 93 |
| 90 display::Display WmTestBase::GetSecondaryDisplay() { | 94 display::Display WmTestBase::GetSecondaryDisplay() { |
| 91 std::vector<RootWindowController*> roots = | 95 std::vector<RootWindowController*> roots = |
| 92 test_helper_->GetRootsOrderedByDisplayId(); | 96 test_helper_->GetRootsOrderedByDisplayId(); |
| 93 return roots.size() < 2 ? display::Display() : roots[1]->display(); | 97 return roots.size() < 2 ? display::Display() : roots[1]->display(); |
| 94 } | 98 } |
| 95 | 99 |
| 96 ui::Window* WmTestBase::CreateTestWindow(const gfx::Rect& bounds) { | 100 aura::Window* WmTestBase::CreateTestWindow(const gfx::Rect& bounds) { |
| 97 return CreateTestWindow(bounds, ui::wm::WINDOW_TYPE_NORMAL); | 101 return CreateTestWindow(bounds, ui::wm::WINDOW_TYPE_NORMAL); |
| 98 } | 102 } |
| 99 | 103 |
| 100 ui::Window* WmTestBase::CreateTestWindow(const gfx::Rect& bounds, | 104 aura::Window* WmTestBase::CreateTestWindow(const gfx::Rect& bounds, |
| 101 ui::wm::WindowType window_type) { | 105 ui::wm::WindowType window_type) { |
| 102 std::map<std::string, std::vector<uint8_t>> properties; | 106 std::map<std::string, std::vector<uint8_t>> properties; |
| 103 properties[ui::mojom::WindowManager::kWindowType_Property] = | |
| 104 mojo::ConvertTo<std::vector<uint8_t>>( | |
| 105 static_cast<int32_t>(MusWindowTypeFromWmWindowType(window_type))); | |
| 106 if (!bounds.IsEmpty()) { | 107 if (!bounds.IsEmpty()) { |
| 107 properties[ui::mojom::WindowManager::kInitialBounds_Property] = | 108 properties[ui::mojom::WindowManager::kInitialBounds_Property] = |
| 108 mojo::ConvertTo<std::vector<uint8_t>>(bounds); | 109 mojo::ConvertTo<std::vector<uint8_t>>(bounds); |
| 109 } | 110 } |
| 111 |
| 110 properties[ui::mojom::WindowManager::kResizeBehavior_Property] = | 112 properties[ui::mojom::WindowManager::kResizeBehavior_Property] = |
| 111 mojo::ConvertTo<std::vector<uint8_t>>( | 113 mojo::ConvertTo<std::vector<uint8_t>>( |
| 112 ui::mojom::kResizeBehaviorCanResize | | 114 static_cast<aura::PropertyConverter::PrimitiveType>( |
| 113 ui::mojom::kResizeBehaviorCanMaximize | | 115 ui::mojom::kResizeBehaviorCanResize | |
| 114 ui::mojom::kResizeBehaviorCanMinimize); | 116 ui::mojom::kResizeBehaviorCanMaximize | |
| 117 ui::mojom::kResizeBehaviorCanMinimize)); |
| 115 | 118 |
| 116 ui::Window* window = test_helper_->GetRootsOrderedByDisplayId()[0] | 119 const ui::mojom::WindowType mus_window_type = |
| 117 ->window_manager() | 120 MusWindowTypeFromWmWindowType(window_type); |
| 118 ->NewTopLevelWindow(&properties); | 121 aura::Window* window = test_helper_->GetRootsOrderedByDisplayId()[0] |
| 119 window->SetVisible(true); | 122 ->window_manager() |
| 120 // Most tests expect a minimum size of 0x0. | 123 ->NewTopLevelWindow(mus_window_type, &properties); |
| 121 WmWindowMusTestApi(WmWindowMus::Get(window)).set_use_empty_minimum_size(true); | 124 window->Show(); |
| 122 return window; | 125 return window; |
| 123 } | 126 } |
| 124 | 127 |
| 125 ui::Window* WmTestBase::CreateFullscreenTestWindow(int64_t display_id) { | 128 aura::Window* WmTestBase::CreateFullscreenTestWindow(int64_t display_id) { |
| 126 std::map<std::string, std::vector<uint8_t>> properties; | 129 std::map<std::string, std::vector<uint8_t>> properties; |
| 127 properties[ui::mojom::WindowManager::kShowState_Property] = | 130 properties[ui::mojom::WindowManager::kShowState_Property] = |
| 128 mojo::ConvertTo<std::vector<uint8_t>>( | 131 mojo::ConvertTo<std::vector<uint8_t>>( |
| 129 static_cast<int32_t>(ui::mojom::ShowState::FULLSCREEN)); | 132 static_cast<aura::PropertyConverter::PrimitiveType>( |
| 130 | 133 ui::mojom::ShowState::FULLSCREEN)); |
| 131 if (display_id != display::kInvalidDisplayId) { | 134 if (display_id != display::kInvalidDisplayId) { |
| 132 properties[ui::mojom::WindowManager::kInitialDisplayId_Property] = | 135 properties[ui::mojom::WindowManager::kInitialDisplayId_Property] = |
| 133 mojo::ConvertTo<std::vector<uint8_t>>(display_id); | 136 mojo::ConvertTo<std::vector<uint8_t>>(display_id); |
| 134 } | 137 } |
| 135 | 138 aura::Window* window = |
| 136 ui::Window* window = test_helper_->GetRootsOrderedByDisplayId()[0] | 139 test_helper_->GetRootsOrderedByDisplayId()[0] |
| 137 ->window_manager() | 140 ->window_manager() |
| 138 ->NewTopLevelWindow(&properties); | 141 ->NewTopLevelWindow(ui::mojom::WindowType::WINDOW, &properties); |
| 139 window->SetVisible(true); | 142 window->Show(); |
| 140 return window; | 143 return window; |
| 141 } | 144 } |
| 142 | 145 |
| 143 ui::Window* WmTestBase::CreateChildTestWindow(ui::Window* parent, | 146 aura::Window* WmTestBase::CreateChildTestWindow(aura::Window* parent, |
| 144 const gfx::Rect& bounds) { | 147 const gfx::Rect& bounds) { |
| 145 std::map<std::string, std::vector<uint8_t>> properties; | 148 std::map<std::string, std::vector<uint8_t>> properties; |
| 146 properties[ui::mojom::WindowManager::kWindowType_Property] = | 149 aura::Window* window = new aura::Window(nullptr); |
| 147 mojo::ConvertTo<std::vector<uint8_t>>(static_cast<int32_t>( | 150 window->Init(ui::LAYER_TEXTURED); |
| 148 MusWindowTypeFromWmWindowType(ui::wm::WINDOW_TYPE_NORMAL))); | |
| 149 ui::Window* window = test_helper_->GetRootsOrderedByDisplayId()[0] | |
| 150 ->root() | |
| 151 ->window_tree() | |
| 152 ->NewWindow(&properties); | |
| 153 window->SetBounds(bounds); | 151 window->SetBounds(bounds); |
| 154 window->SetVisible(true); | 152 window->Show(); |
| 155 parent->AddChild(window); | 153 parent->AddChild(window); |
| 156 return window; | 154 return window; |
| 157 } | 155 } |
| 158 | 156 |
| 159 void WmTestBase::SetUp() { | 157 void WmTestBase::SetUp() { |
| 160 setup_called_ = true; | 158 setup_called_ = true; |
| 159 // Disable animations during tests. |
| 160 zero_duration_mode_ = base::MakeUnique<ui::ScopedAnimationDurationScaleMode>( |
| 161 ui::ScopedAnimationDurationScaleMode::ZERO_DURATION); |
| 162 // Most tests expect a minimum size of 0x0. |
| 163 minimum_size_lock_ = |
| 164 base::MakeUnique<WmWindowMusTestApi::GlobalMinimumSizeLock>(); |
| 161 test_helper_.reset(new WmTestHelper); | 165 test_helper_.reset(new WmTestHelper); |
| 162 test_helper_->Init(); | 166 test_helper_->Init(); |
| 163 } | 167 } |
| 164 | 168 |
| 165 void WmTestBase::TearDown() { | 169 void WmTestBase::TearDown() { |
| 166 teardown_called_ = true; | 170 teardown_called_ = true; |
| 167 test_helper_.reset(); | 171 test_helper_.reset(); |
| 172 minimum_size_lock_.reset(); |
| 173 zero_duration_mode_.reset(); |
| 168 } | 174 } |
| 169 | 175 |
| 170 } // namespace mus | 176 } // namespace mus |
| 171 } // namespace ash | 177 } // namespace ash |
| OLD | NEW |