OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/test/ash_test_base.h" | 5 #include "ash/test/ash_test_base.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "ash/display/extended_mouse_warp_controller.h" | 10 #include "ash/display/extended_mouse_warp_controller.h" |
11 #include "ash/display/mouse_cursor_event_filter.h" | 11 #include "ash/display/mouse_cursor_event_filter.h" |
12 #include "ash/display/unified_mouse_warp_controller.h" | 12 #include "ash/display/unified_mouse_warp_controller.h" |
13 #include "ash/display/window_tree_host_manager.h" | 13 #include "ash/display/window_tree_host_manager.h" |
14 #include "ash/ime/input_method_event_handler.h" | 14 #include "ash/ime/input_method_event_handler.h" |
| 15 #include "ash/mus/top_level_window_factory.h" |
| 16 #include "ash/mus/window_manager.h" |
| 17 #include "ash/mus/window_manager_application.h" |
15 #include "ash/public/cpp/config.h" | 18 #include "ash/public/cpp/config.h" |
16 #include "ash/public/cpp/window_properties.h" | 19 #include "ash/public/cpp/window_properties.h" |
17 #include "ash/root_window_controller.h" | 20 #include "ash/root_window_controller.h" |
18 #include "ash/session/session_controller.h" | 21 #include "ash/session/session_controller.h" |
19 #include "ash/shell.h" | 22 #include "ash/shell.h" |
20 #include "ash/shell/toplevel_window.h" | 23 #include "ash/shell/toplevel_window.h" |
21 #include "ash/shell_port.h" | 24 #include "ash/shell_port.h" |
22 #include "ash/test/ash_test_environment.h" | 25 #include "ash/test/ash_test_environment.h" |
23 #include "ash/test/ash_test_helper.h" | 26 #include "ash/test/ash_test_helper.h" |
24 #include "ash/test/test_session_controller_client.h" | 27 #include "ash/test/test_session_controller_client.h" |
25 #include "ash/test/test_shell_delegate.h" | 28 #include "ash/test/test_shell_delegate.h" |
26 #include "ash/test/test_system_tray_delegate.h" | 29 #include "ash/test/test_system_tray_delegate.h" |
27 #include "ash/wm/window_positioner.h" | 30 #include "ash/wm/window_positioner.h" |
28 #include "ash/wm_window.h" | 31 #include "ash/wm_window.h" |
| 32 #include "services/ui/public/cpp/property_type_converters.h" |
| 33 #include "services/ui/public/interfaces/window_manager.mojom.h" |
29 #include "services/ui/public/interfaces/window_manager_constants.mojom.h" | 34 #include "services/ui/public/interfaces/window_manager_constants.mojom.h" |
30 #include "ui/aura/client/aura_constants.h" | 35 #include "ui/aura/client/aura_constants.h" |
31 #include "ui/aura/client/screen_position_client.h" | 36 #include "ui/aura/client/screen_position_client.h" |
32 #include "ui/aura/client/window_parenting_client.h" | 37 #include "ui/aura/client/window_parenting_client.h" |
33 #include "ui/aura/env.h" | 38 #include "ui/aura/env.h" |
| 39 #include "ui/aura/mus/property_converter.h" |
34 #include "ui/aura/test/event_generator_delegate_aura.h" | 40 #include "ui/aura/test/event_generator_delegate_aura.h" |
35 #include "ui/aura/test/test_window_delegate.h" | 41 #include "ui/aura/test/test_window_delegate.h" |
36 #include "ui/aura/window.h" | 42 #include "ui/aura/window.h" |
37 #include "ui/aura/window_delegate.h" | 43 #include "ui/aura/window_delegate.h" |
38 #include "ui/aura/window_tree_host.h" | 44 #include "ui/aura/window_tree_host.h" |
39 #include "ui/base/ime/input_method_initializer.h" | 45 #include "ui/base/ime/input_method_initializer.h" |
40 #include "ui/display/display.h" | 46 #include "ui/display/display.h" |
41 #include "ui/display/screen.h" | 47 #include "ui/display/screen.h" |
42 #include "ui/display/test/display_manager_test_api.h" | 48 #include "ui/display/test/display_manager_test_api.h" |
43 #include "ui/display/types/display_constants.h" | 49 #include "ui/display/types/display_constants.h" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 void DispatchKeyEventToIME(ui::EventTarget* target, | 84 void DispatchKeyEventToIME(ui::EventTarget* target, |
79 ui::KeyEvent* event) override { | 85 ui::KeyEvent* event) override { |
80 // In Ash environment, the key event will be processed by event rewriters | 86 // In Ash environment, the key event will be processed by event rewriters |
81 // first. | 87 // first. |
82 } | 88 } |
83 | 89 |
84 private: | 90 private: |
85 DISALLOW_COPY_AND_ASSIGN(AshEventGeneratorDelegate); | 91 DISALLOW_COPY_AND_ASSIGN(AshEventGeneratorDelegate); |
86 }; | 92 }; |
87 | 93 |
| 94 ui::mojom::WindowType MusWindowTypeFromWmWindowType( |
| 95 ui::wm::WindowType wm_window_type) { |
| 96 switch (wm_window_type) { |
| 97 case ui::wm::WINDOW_TYPE_UNKNOWN: |
| 98 break; |
| 99 |
| 100 case ui::wm::WINDOW_TYPE_NORMAL: |
| 101 return ui::mojom::WindowType::WINDOW; |
| 102 |
| 103 case ui::wm::WINDOW_TYPE_POPUP: |
| 104 return ui::mojom::WindowType::POPUP; |
| 105 |
| 106 case ui::wm::WINDOW_TYPE_CONTROL: |
| 107 return ui::mojom::WindowType::CONTROL; |
| 108 |
| 109 case ui::wm::WINDOW_TYPE_PANEL: |
| 110 return ui::mojom::WindowType::PANEL; |
| 111 |
| 112 case ui::wm::WINDOW_TYPE_MENU: |
| 113 return ui::mojom::WindowType::MENU; |
| 114 |
| 115 case ui::wm::WINDOW_TYPE_TOOLTIP: |
| 116 return ui::mojom::WindowType::TOOLTIP; |
| 117 } |
| 118 |
| 119 NOTREACHED(); |
| 120 return ui::mojom::WindowType::CONTROL; |
| 121 } |
| 122 |
88 } // namespace | 123 } // namespace |
89 | 124 |
90 ///////////////////////////////////////////////////////////////////////////// | 125 ///////////////////////////////////////////////////////////////////////////// |
91 | 126 |
92 AshTestBase::AshTestBase() | 127 AshTestBase::AshTestBase() |
93 : setup_called_(false), teardown_called_(false), start_session_(true) { | 128 : setup_called_(false), teardown_called_(false), start_session_(true) { |
94 #if defined(USE_X11) | 129 #if defined(USE_X11) |
95 // This is needed for tests which use this base class but are run in browser | 130 // This is needed for tests which use this base class but are run in browser |
96 // test binaries so don't get the default initialization in the unit test | 131 // test binaries so don't get the default initialization in the unit test |
97 // suite. | 132 // suite. |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 ¶ms); | 254 ¶ms); |
220 widget->Init(params); | 255 widget->Init(params); |
221 widget->Show(); | 256 widget->Show(); |
222 return widget; | 257 return widget; |
223 } | 258 } |
224 | 259 |
225 std::unique_ptr<aura::Window> AshTestBase::CreateTestWindow( | 260 std::unique_ptr<aura::Window> AshTestBase::CreateTestWindow( |
226 const gfx::Rect& bounds_in_screen, | 261 const gfx::Rect& bounds_in_screen, |
227 ui::wm::WindowType type, | 262 ui::wm::WindowType type, |
228 int shell_window_id) { | 263 int shell_window_id) { |
229 return base::WrapUnique<aura::Window>( | 264 if (AshTestHelper::config() != Config::MASH) { |
230 CreateTestWindowInShellWithDelegateAndType(nullptr, type, shell_window_id, | 265 return base::WrapUnique<aura::Window>( |
231 bounds_in_screen)); | 266 CreateTestWindowInShellWithDelegateAndType( |
| 267 nullptr, type, shell_window_id, bounds_in_screen)); |
| 268 } |
| 269 |
| 270 // For mash route creation through the window manager. This better simulates |
| 271 // what happens when a client creates a top level window. |
| 272 std::map<std::string, std::vector<uint8_t>> properties; |
| 273 if (!bounds_in_screen.IsEmpty()) { |
| 274 properties[ui::mojom::WindowManager::kBounds_InitProperty] = |
| 275 mojo::ConvertTo<std::vector<uint8_t>>(bounds_in_screen); |
| 276 } |
| 277 |
| 278 properties[ui::mojom::WindowManager::kResizeBehavior_Property] = |
| 279 mojo::ConvertTo<std::vector<uint8_t>>( |
| 280 static_cast<aura::PropertyConverter::PrimitiveType>( |
| 281 ui::mojom::kResizeBehaviorCanResize | |
| 282 ui::mojom::kResizeBehaviorCanMaximize | |
| 283 ui::mojom::kResizeBehaviorCanMinimize)); |
| 284 |
| 285 const ui::mojom::WindowType mus_window_type = |
| 286 MusWindowTypeFromWmWindowType(type); |
| 287 mus::WindowManager* window_manager = |
| 288 ash_test_helper_->window_manager_app()->window_manager(); |
| 289 aura::Window* window = mus::CreateAndParentTopLevelWindow( |
| 290 window_manager, mus_window_type, &properties); |
| 291 window->Show(); |
| 292 return base::WrapUnique<aura::Window>(window); |
232 } | 293 } |
233 | 294 |
234 aura::Window* AshTestBase::CreateTestWindowInShellWithId(int id) { | 295 aura::Window* AshTestBase::CreateTestWindowInShellWithId(int id) { |
235 return CreateTestWindowInShellWithDelegate(NULL, id, gfx::Rect()); | 296 return CreateTestWindowInShellWithDelegate(NULL, id, gfx::Rect()); |
236 } | 297 } |
237 | 298 |
238 aura::Window* AshTestBase::CreateTestWindowInShellWithBounds( | 299 aura::Window* AshTestBase::CreateTestWindowInShellWithBounds( |
239 const gfx::Rect& bounds) { | 300 const gfx::Rect& bounds) { |
240 return CreateTestWindowInShellWithDelegate(NULL, 0, bounds); | 301 return CreateTestWindowInShellWithDelegate(NULL, 0, bounds); |
241 } | 302 } |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
406 .id(); | 467 .id(); |
407 } | 468 } |
408 | 469 |
409 void AshTestBase::SwapPrimaryDisplay() { | 470 void AshTestBase::SwapPrimaryDisplay() { |
410 if (display::Screen::GetScreen()->GetNumDisplays() <= 1) | 471 if (display::Screen::GetScreen()->GetNumDisplays() <= 1) |
411 return; | 472 return; |
412 Shell::Get()->window_tree_host_manager()->SetPrimaryDisplayId( | 473 Shell::Get()->window_tree_host_manager()->SetPrimaryDisplayId( |
413 display_manager()->GetSecondaryDisplay().id()); | 474 display_manager()->GetSecondaryDisplay().id()); |
414 } | 475 } |
415 | 476 |
| 477 display::Display AshTestBase::GetPrimaryDisplay() { |
| 478 return display::Screen::GetScreen()->GetDisplayNearestWindow( |
| 479 Shell::GetPrimaryRootWindow()); |
| 480 } |
| 481 |
416 display::Display AshTestBase::GetSecondaryDisplay() { | 482 display::Display AshTestBase::GetSecondaryDisplay() { |
417 return ash_test_helper_->GetSecondaryDisplay(); | 483 return ash_test_helper_->GetSecondaryDisplay(); |
418 } | 484 } |
419 | 485 |
420 } // namespace test | 486 } // namespace test |
421 } // namespace ash | 487 } // namespace ash |
OLD | NEW |