Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(232)

Side by Side Diff: ash/test/ash_test_base.cc

Issue 2840393002: chromeos: converts TopLevelWindowFactoryTest to AshTestBase (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
29 #include "base/command_line.h" 32 #include "base/command_line.h"
33 #include "services/ui/public/cpp/property_type_converters.h"
34 #include "services/ui/public/interfaces/window_manager.mojom.h"
30 #include "services/ui/public/interfaces/window_manager_constants.mojom.h" 35 #include "services/ui/public/interfaces/window_manager_constants.mojom.h"
31 #include "ui/aura/client/aura_constants.h" 36 #include "ui/aura/client/aura_constants.h"
32 #include "ui/aura/client/screen_position_client.h" 37 #include "ui/aura/client/screen_position_client.h"
33 #include "ui/aura/client/window_parenting_client.h" 38 #include "ui/aura/client/window_parenting_client.h"
34 #include "ui/aura/env.h" 39 #include "ui/aura/env.h"
40 #include "ui/aura/mus/property_converter.h"
35 #include "ui/aura/test/event_generator_delegate_aura.h" 41 #include "ui/aura/test/event_generator_delegate_aura.h"
36 #include "ui/aura/test/test_window_delegate.h" 42 #include "ui/aura/test/test_window_delegate.h"
37 #include "ui/aura/window.h" 43 #include "ui/aura/window.h"
38 #include "ui/aura/window_delegate.h" 44 #include "ui/aura/window_delegate.h"
39 #include "ui/aura/window_tree_host.h" 45 #include "ui/aura/window_tree_host.h"
40 #include "ui/base/ime/input_method_initializer.h" 46 #include "ui/base/ime/input_method_initializer.h"
41 #include "ui/display/display.h" 47 #include "ui/display/display.h"
42 #include "ui/display/display_switches.h" 48 #include "ui/display/display_switches.h"
43 #include "ui/display/screen.h" 49 #include "ui/display/screen.h"
44 #include "ui/display/test/display_manager_test_api.h" 50 #include "ui/display/test/display_manager_test_api.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 void DispatchKeyEventToIME(ui::EventTarget* target, 86 void DispatchKeyEventToIME(ui::EventTarget* target,
81 ui::KeyEvent* event) override { 87 ui::KeyEvent* event) override {
82 // In Ash environment, the key event will be processed by event rewriters 88 // In Ash environment, the key event will be processed by event rewriters
83 // first. 89 // first.
84 } 90 }
85 91
86 private: 92 private:
87 DISALLOW_COPY_AND_ASSIGN(AshEventGeneratorDelegate); 93 DISALLOW_COPY_AND_ASSIGN(AshEventGeneratorDelegate);
88 }; 94 };
89 95
96 ui::mojom::WindowType MusWindowTypeFromWmWindowType(
97 ui::wm::WindowType wm_window_type) {
98 switch (wm_window_type) {
99 case ui::wm::WINDOW_TYPE_UNKNOWN:
100 break;
101
102 case ui::wm::WINDOW_TYPE_NORMAL:
103 return ui::mojom::WindowType::WINDOW;
104
105 case ui::wm::WINDOW_TYPE_POPUP:
106 return ui::mojom::WindowType::POPUP;
107
108 case ui::wm::WINDOW_TYPE_CONTROL:
109 return ui::mojom::WindowType::CONTROL;
110
111 case ui::wm::WINDOW_TYPE_PANEL:
112 return ui::mojom::WindowType::PANEL;
113
114 case ui::wm::WINDOW_TYPE_MENU:
115 return ui::mojom::WindowType::MENU;
116
117 case ui::wm::WINDOW_TYPE_TOOLTIP:
118 return ui::mojom::WindowType::TOOLTIP;
119 }
120
121 NOTREACHED();
122 return ui::mojom::WindowType::CONTROL;
123 }
124
90 } // namespace 125 } // namespace
91 126
92 ///////////////////////////////////////////////////////////////////////////// 127 /////////////////////////////////////////////////////////////////////////////
93 128
94 AshTestBase::AshTestBase() 129 AshTestBase::AshTestBase()
95 : setup_called_(false), teardown_called_(false), start_session_(true) { 130 : setup_called_(false), teardown_called_(false), start_session_(true) {
96 #if defined(USE_X11) 131 #if defined(USE_X11)
97 // This is needed for tests which use this base class but are run in browser 132 // This is needed for tests which use this base class but are run in browser
98 // test binaries so don't get the default initialization in the unit test 133 // test binaries so don't get the default initialization in the unit test
99 // suite. 134 // suite.
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 &params); 265 &params);
231 widget->Init(params); 266 widget->Init(params);
232 widget->Show(); 267 widget->Show();
233 return widget; 268 return widget;
234 } 269 }
235 270
236 std::unique_ptr<aura::Window> AshTestBase::CreateTestWindow( 271 std::unique_ptr<aura::Window> AshTestBase::CreateTestWindow(
237 const gfx::Rect& bounds_in_screen, 272 const gfx::Rect& bounds_in_screen,
238 ui::wm::WindowType type, 273 ui::wm::WindowType type,
239 int shell_window_id) { 274 int shell_window_id) {
240 return base::WrapUnique<aura::Window>( 275 if (AshTestHelper::config() != Config::MASH) {
241 CreateTestWindowInShellWithDelegateAndType(nullptr, type, shell_window_id, 276 return base::WrapUnique<aura::Window>(
242 bounds_in_screen)); 277 CreateTestWindowInShellWithDelegateAndType(
278 nullptr, type, shell_window_id, bounds_in_screen));
279 }
280
281 // For mash route creation through the window manager. This better simulates
282 // what happens when a client creates a top level window.
283 std::map<std::string, std::vector<uint8_t>> properties;
284 if (!bounds_in_screen.IsEmpty()) {
285 properties[ui::mojom::WindowManager::kBounds_InitProperty] =
286 mojo::ConvertTo<std::vector<uint8_t>>(bounds_in_screen);
287 }
288
289 properties[ui::mojom::WindowManager::kResizeBehavior_Property] =
290 mojo::ConvertTo<std::vector<uint8_t>>(
291 static_cast<aura::PropertyConverter::PrimitiveType>(
292 ui::mojom::kResizeBehaviorCanResize |
293 ui::mojom::kResizeBehaviorCanMaximize |
294 ui::mojom::kResizeBehaviorCanMinimize));
295
296 const ui::mojom::WindowType mus_window_type =
297 MusWindowTypeFromWmWindowType(type);
298 mus::WindowManager* window_manager =
299 ash_test_helper_->window_manager_app()->window_manager();
300 aura::Window* window = mus::CreateAndParentTopLevelWindow(
301 window_manager, mus_window_type, &properties);
302 window->Show();
303 return base::WrapUnique<aura::Window>(window);
243 } 304 }
244 305
245 aura::Window* AshTestBase::CreateTestWindowInShellWithId(int id) { 306 aura::Window* AshTestBase::CreateTestWindowInShellWithId(int id) {
246 return CreateTestWindowInShellWithDelegate(NULL, id, gfx::Rect()); 307 return CreateTestWindowInShellWithDelegate(NULL, id, gfx::Rect());
247 } 308 }
248 309
249 aura::Window* AshTestBase::CreateTestWindowInShellWithBounds( 310 aura::Window* AshTestBase::CreateTestWindowInShellWithBounds(
250 const gfx::Rect& bounds) { 311 const gfx::Rect& bounds) {
251 return CreateTestWindowInShellWithDelegate(NULL, 0, bounds); 312 return CreateTestWindowInShellWithDelegate(NULL, 0, bounds);
252 } 313 }
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
417 .id(); 478 .id();
418 } 479 }
419 480
420 void AshTestBase::SwapPrimaryDisplay() { 481 void AshTestBase::SwapPrimaryDisplay() {
421 if (display::Screen::GetScreen()->GetNumDisplays() <= 1) 482 if (display::Screen::GetScreen()->GetNumDisplays() <= 1)
422 return; 483 return;
423 Shell::Get()->window_tree_host_manager()->SetPrimaryDisplayId( 484 Shell::Get()->window_tree_host_manager()->SetPrimaryDisplayId(
424 display_manager()->GetSecondaryDisplay().id()); 485 display_manager()->GetSecondaryDisplay().id());
425 } 486 }
426 487
488 display::Display AshTestBase::GetPrimaryDisplay() {
489 return display::Screen::GetScreen()->GetDisplayNearestWindow(
490 Shell::GetPrimaryRootWindow());
491 }
492
427 display::Display AshTestBase::GetSecondaryDisplay() { 493 display::Display AshTestBase::GetSecondaryDisplay() {
428 return ash_test_helper_->GetSecondaryDisplay(); 494 return ash_test_helper_->GetSecondaryDisplay();
429 } 495 }
430 496
431 } // namespace test 497 } // namespace test
432 } // namespace ash 498 } // namespace ash
OLDNEW
« ash/mus/top_level_window_factory_unittest.cc ('K') | « ash/test/ash_test_base.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698