OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "ash/common/test/ash_test.h" | |
6 | |
7 #include "ash/common/shelf/wm_shelf.h" | |
8 #include "ash/common/test/ash_test_impl.h" | |
9 #include "ash/common/test/test_session_state_delegate.h" | |
10 #include "ash/common/test/test_system_tray_delegate.h" | |
11 #include "ash/common/wm_shell.h" | |
12 #include "ash/common/wm_window.h" | |
13 #include "ash/root_window_controller.h" | |
14 #include "ash/system/status_area_widget.h" | |
15 #include "base/memory/ptr_util.h" | |
16 #include "base/run_loop.h" | |
17 #include "ui/compositor/layer_type.h" | |
18 #include "ui/display/display.h" | |
19 | |
20 namespace ash { | |
21 | |
22 WindowOwner::WindowOwner(WmWindow* window) : window_(window) {} | |
23 | |
24 WindowOwner::~WindowOwner() { | |
25 window_->Destroy(); | |
26 } | |
27 | |
28 AshTest::AshTest() : test_impl_(AshTestImpl::Create()) {} | |
29 | |
30 AshTest::~AshTest() {} | |
31 | |
32 // static | |
33 WmShelf* AshTest::GetPrimaryShelf() { | |
34 return WmShell::Get() | |
35 ->GetPrimaryRootWindow() | |
36 ->GetRootWindowController() | |
37 ->GetShelf(); | |
38 } | |
39 | |
40 // static | |
41 SystemTray* AshTest::GetPrimarySystemTray() { | |
42 return GetPrimaryShelf()->GetStatusAreaWidget()->system_tray(); | |
43 } | |
44 | |
45 // static | |
46 test::TestSystemTrayDelegate* AshTest::GetSystemTrayDelegate() { | |
47 return static_cast<test::TestSystemTrayDelegate*>( | |
48 WmShell::Get()->system_tray_delegate()); | |
49 } | |
50 | |
51 void AshTest::UpdateDisplay(const std::string& display_spec) { | |
52 return test_impl_->UpdateDisplay(display_spec); | |
53 } | |
54 | |
55 std::unique_ptr<WindowOwner> AshTest::CreateTestWindow(const gfx::Rect& bounds, | |
56 ui::wm::WindowType type, | |
57 int shell_window_id) { | |
58 return test_impl_->CreateTestWindow(bounds, type, shell_window_id); | |
59 } | |
60 | |
61 std::unique_ptr<WindowOwner> AshTest::CreateToplevelTestWindow( | |
62 const gfx::Rect& bounds_in_screen, | |
63 int shell_window_id) { | |
64 return test_impl_->CreateToplevelTestWindow(bounds_in_screen, | |
65 shell_window_id); | |
66 } | |
67 | |
68 std::unique_ptr<WindowOwner> AshTest::CreateChildWindow(WmWindow* parent, | |
69 const gfx::Rect& bounds, | |
70 int shell_window_id) { | |
71 std::unique_ptr<WindowOwner> window_owner = | |
72 base::MakeUnique<WindowOwner>(WmShell::Get()->NewWindow( | |
73 ui::wm::WINDOW_TYPE_NORMAL, ui::LAYER_NOT_DRAWN)); | |
74 window_owner->window()->SetBounds(bounds); | |
75 window_owner->window()->SetShellWindowId(shell_window_id); | |
76 parent->AddChild(window_owner->window()); | |
77 window_owner->window()->Show(); | |
78 return window_owner; | |
79 } | |
80 | |
81 // static | |
82 std::unique_ptr<views::Widget> AshTest::CreateTestWidget( | |
83 const gfx::Rect& bounds, | |
84 views::WidgetDelegate* delegate, | |
85 int container_id) { | |
86 std::unique_ptr<views::Widget> widget(new views::Widget); | |
87 views::Widget::InitParams params; | |
88 params.delegate = delegate; | |
89 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | |
90 params.bounds = bounds; | |
91 WmShell::Get() | |
92 ->GetPrimaryRootWindow() | |
93 ->GetRootWindowController() | |
94 ->ConfigureWidgetInitParamsForContainer(widget.get(), container_id, | |
95 ¶ms); | |
96 widget->Init(params); | |
97 widget->Show(); | |
98 return widget; | |
99 } | |
100 | |
101 display::Display AshTest::GetSecondaryDisplay() { | |
102 return test_impl_->GetSecondaryDisplay(); | |
103 } | |
104 | |
105 bool AshTest::SetSecondaryDisplayPlacement( | |
106 display::DisplayPlacement::Position position, | |
107 int offset) { | |
108 if (WmShell::Get()->IsRunningInMash()) { | |
109 NOTIMPLEMENTED(); | |
110 return false; | |
111 } | |
112 return test_impl_->SetSecondaryDisplayPlacement(position, offset); | |
113 } | |
114 | |
115 void AshTest::ConfigureWidgetInitParamsForDisplay( | |
116 WmWindow* window, | |
117 views::Widget::InitParams* init_params) { | |
118 test_impl_->ConfigureWidgetInitParamsForDisplay(window, init_params); | |
119 } | |
120 | |
121 void AshTest::ParentWindowInPrimaryRootWindow(WmWindow* window) { | |
122 window->SetParentUsingContext(WmShell::Get()->GetPrimaryRootWindow(), | |
123 gfx::Rect()); | |
124 } | |
125 | |
126 void AshTest::AddTransientChild(WmWindow* parent, WmWindow* window) { | |
127 test_impl_->AddTransientChild(parent, window); | |
128 } | |
129 | |
130 void AshTest::RunAllPendingInMessageLoop() { | |
131 base::RunLoop run_loop; | |
132 run_loop.RunUntilIdle(); | |
133 } | |
134 | |
135 void AshTest::SetUp() { | |
136 test_impl_->SetUp(); | |
137 } | |
138 | |
139 void AshTest::TearDown() { | |
140 test_impl_->TearDown(); | |
141 } | |
142 | |
143 } // namespace ash | |
OLD | NEW |