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