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

Side by Side Diff: ash/mus/test/wm_test_base.cc

Issue 2322613002: Adds support for multiple displays to WmTestBase (Closed)
Patch Set: moar Created 4 years, 3 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 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/root_window_controller.h" 10 #include "ash/mus/root_window_controller.h"
11 #include "ash/mus/test/wm_test_helper.h" 11 #include "ash/mus/test/wm_test_helper.h"
12 #include "ash/mus/test/wm_test_screen.h" 12 #include "ash/mus/test/wm_test_screen.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 "base/strings/string_number_conversions.h"
16 #include "base/strings/string_split.h"
17 #include "services/ui/public/cpp/property_type_converters.h" 15 #include "services/ui/public/cpp/property_type_converters.h"
18 #include "services/ui/public/cpp/window_tree_client.h" 16 #include "services/ui/public/cpp/window_tree_client.h"
19 #include "ui/display/display.h" 17 #include "ui/display/display.h"
20 18
21 namespace ash { 19 namespace ash {
22 namespace mus { 20 namespace mus {
23 namespace { 21 namespace {
24 22
25 ui::mojom::WindowType MusWindowTypeFromWmWindowType( 23 ui::mojom::WindowType MusWindowTypeFromWmWindowType(
26 ui::wm::WindowType wm_window_type) { 24 ui::wm::WindowType wm_window_type) {
(...skipping 17 matching lines...) Expand all
44 return ui::mojom::WindowType::MENU; 42 return ui::mojom::WindowType::MENU;
45 43
46 case ui::wm::WINDOW_TYPE_TOOLTIP: 44 case ui::wm::WINDOW_TYPE_TOOLTIP:
47 return ui::mojom::WindowType::TOOLTIP; 45 return ui::mojom::WindowType::TOOLTIP;
48 } 46 }
49 47
50 NOTREACHED(); 48 NOTREACHED();
51 return ui::mojom::WindowType::CONTROL; 49 return ui::mojom::WindowType::CONTROL;
52 } 50 }
53 51
54 bool CompareByDisplayId(const RootWindowController* root1,
55 const RootWindowController* root2) {
56 return root1->display().id() < root2->display().id();
57 }
58
59 // TODO(sky): at some point this needs to support everything in DisplayInfo,
60 // for now just the bare minimum, which is [x+y-]wxh.
61 gfx::Rect ParseDisplayBounds(const std::string& spec) {
62 gfx::Rect bounds;
63 const std::vector<std::string> parts =
64 base::SplitString(spec, "-", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
65 std::string size_spec;
66 if (parts.size() == 2u) {
67 size_spec = parts[1];
68 const std::vector<std::string> origin_parts = base::SplitString(
69 parts[0], "+", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
70 CHECK_EQ(2u, origin_parts.size());
71 int x, y;
72 CHECK(base::StringToInt(origin_parts[0], &x));
73 CHECK(base::StringToInt(origin_parts[1], &y));
74 bounds.set_origin(gfx::Point(x, y));
75 } else {
76 CHECK_EQ(1u, parts.size());
77 size_spec = spec;
78 }
79 const std::vector<std::string> size_parts = base::SplitString(
80 size_spec, "x", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
81 CHECK_EQ(2u, size_parts.size());
82 int w, h;
83 CHECK(base::StringToInt(size_parts[0], &w));
84 CHECK(base::StringToInt(size_parts[1], &h));
85 bounds.set_size(gfx::Size(w, h));
86 return bounds;
87 }
88
89 } // namespace 52 } // namespace
90 53
91 WmTestBase::WmTestBase() {} 54 WmTestBase::WmTestBase() {}
92 55
93 WmTestBase::~WmTestBase() { 56 WmTestBase::~WmTestBase() {
94 CHECK(setup_called_) 57 CHECK(setup_called_)
95 << "You have overridden SetUp but never called WmTestBase::SetUp"; 58 << "You have overridden SetUp but never called WmTestBase::SetUp";
96 CHECK(teardown_called_) 59 CHECK(teardown_called_)
97 << "You have overridden TearDown but never called WmTestBase::TearDown"; 60 << "You have overridden TearDown but never called WmTestBase::TearDown";
98 } 61 }
99 62
100 bool WmTestBase::SupportsMultipleDisplays() const { 63 bool WmTestBase::SupportsMultipleDisplays() const {
101 return false; 64 return true;
102 } 65 }
103 66
104 void WmTestBase::UpdateDisplay(const std::string& display_spec) { 67 void WmTestBase::UpdateDisplay(const std::string& display_spec) {
105 const std::vector<std::string> parts = base::SplitString( 68 test_helper_->UpdateDisplay(display_spec);
106 display_spec, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
107 // TODO(sky): allow > 1 once http://crbug.com/611563 is fixed.
108 DCHECK_EQ(1u, parts.size());
109 gfx::Rect bounds = ParseDisplayBounds(parts[0]);
110 std::vector<RootWindowController*> roots =
111 WmTestBase::GetRootsOrderedByDisplayId();
112 roots[0]->display_.set_bounds(bounds);
113 gfx::Rect work_area(bounds);
114 // Offset the height slightly to give a different work area. -2 is arbitrary,
115 // it could be anything.
116 work_area.set_height(std::max(0, work_area.height() - 2));
117 roots[0]->display_.set_work_area(work_area);
118 roots[0]->root()->SetBounds(gfx::Rect(bounds.size()));
119 test_helper_->screen()->display_list()->UpdateDisplay(
120 roots[0]->display(), display::DisplayList::Type::PRIMARY);
121 } 69 }
122 70
123 ui::Window* WmTestBase::GetPrimaryRootWindow() { 71 ui::Window* WmTestBase::GetPrimaryRootWindow() {
124 std::vector<RootWindowController*> roots = 72 std::vector<RootWindowController*> roots =
125 WmTestBase::GetRootsOrderedByDisplayId(); 73 test_helper_->GetRootsOrderedByDisplayId();
126 DCHECK(!roots.empty()); 74 DCHECK(!roots.empty());
127 return roots[0]->root(); 75 return roots[0]->root();
128 } 76 }
129 77
130 ui::Window* WmTestBase::GetSecondaryRootWindow() { 78 ui::Window* WmTestBase::GetSecondaryRootWindow() {
131 std::vector<RootWindowController*> roots = 79 std::vector<RootWindowController*> roots =
132 WmTestBase::GetRootsOrderedByDisplayId(); 80 test_helper_->GetRootsOrderedByDisplayId();
133 return roots.size() < 2 ? nullptr : roots[1]->root(); 81 return roots.size() < 2 ? nullptr : roots[1]->root();
134 } 82 }
135 83
136 display::Display WmTestBase::GetPrimaryDisplay() { 84 display::Display WmTestBase::GetPrimaryDisplay() {
137 std::vector<RootWindowController*> roots = 85 std::vector<RootWindowController*> roots =
138 WmTestBase::GetRootsOrderedByDisplayId(); 86 test_helper_->GetRootsOrderedByDisplayId();
139 DCHECK(!roots.empty()); 87 DCHECK(!roots.empty());
140 return roots[0]->display(); 88 return roots[0]->display();
141 } 89 }
142 90
143 display::Display WmTestBase::GetSecondaryDisplay() { 91 display::Display WmTestBase::GetSecondaryDisplay() {
144 std::vector<RootWindowController*> roots = 92 std::vector<RootWindowController*> roots =
145 WmTestBase::GetRootsOrderedByDisplayId(); 93 test_helper_->GetRootsOrderedByDisplayId();
146 return roots.size() < 2 ? display::Display() : roots[1]->display(); 94 return roots.size() < 2 ? display::Display() : roots[1]->display();
147 } 95 }
148 96
149 ui::Window* WmTestBase::CreateTestWindow(const gfx::Rect& bounds) { 97 ui::Window* WmTestBase::CreateTestWindow(const gfx::Rect& bounds) {
150 return CreateTestWindow(bounds, ui::wm::WINDOW_TYPE_NORMAL); 98 return CreateTestWindow(bounds, ui::wm::WINDOW_TYPE_NORMAL);
151 } 99 }
152 100
153 ui::Window* WmTestBase::CreateTestWindow(const gfx::Rect& bounds, 101 ui::Window* WmTestBase::CreateTestWindow(const gfx::Rect& bounds,
154 ui::wm::WindowType window_type) { 102 ui::wm::WindowType window_type) {
155 std::map<std::string, std::vector<uint8_t>> properties; 103 std::map<std::string, std::vector<uint8_t>> properties;
156 properties[ui::mojom::WindowManager::kWindowType_Property] = 104 properties[ui::mojom::WindowManager::kWindowType_Property] =
157 mojo::ConvertTo<std::vector<uint8_t>>( 105 mojo::ConvertTo<std::vector<uint8_t>>(
158 static_cast<int32_t>(MusWindowTypeFromWmWindowType(window_type))); 106 static_cast<int32_t>(MusWindowTypeFromWmWindowType(window_type)));
159 if (!bounds.IsEmpty()) { 107 if (!bounds.IsEmpty()) {
160 properties[ui::mojom::WindowManager::kInitialBounds_Property] = 108 properties[ui::mojom::WindowManager::kInitialBounds_Property] =
161 mojo::ConvertTo<std::vector<uint8_t>>(bounds); 109 mojo::ConvertTo<std::vector<uint8_t>>(bounds);
162 } 110 }
163 properties[ui::mojom::WindowManager::kResizeBehavior_Property] = 111 properties[ui::mojom::WindowManager::kResizeBehavior_Property] =
164 mojo::ConvertTo<std::vector<uint8_t>>( 112 mojo::ConvertTo<std::vector<uint8_t>>(
165 ui::mojom::kResizeBehaviorCanResize | 113 ui::mojom::kResizeBehaviorCanResize |
166 ui::mojom::kResizeBehaviorCanMaximize | 114 ui::mojom::kResizeBehaviorCanMaximize |
167 ui::mojom::kResizeBehaviorCanMinimize); 115 ui::mojom::kResizeBehaviorCanMinimize);
168 116
169 ui::Window* window = 117 ui::Window* window = test_helper_->GetRootsOrderedByDisplayId()[0]
170 GetRootsOrderedByDisplayId()[0]->window_manager()->NewTopLevelWindow( 118 ->window_manager()
171 &properties); 119 ->NewTopLevelWindow(&properties);
172 window->SetVisible(true); 120 window->SetVisible(true);
173 return window; 121 return window;
174 } 122 }
175 123
176 ui::Window* WmTestBase::CreateFullscreenTestWindow() { 124 ui::Window* WmTestBase::CreateFullscreenTestWindow() {
177 std::map<std::string, std::vector<uint8_t>> properties; 125 std::map<std::string, std::vector<uint8_t>> properties;
178 properties[ui::mojom::WindowManager::kShowState_Property] = 126 properties[ui::mojom::WindowManager::kShowState_Property] =
179 mojo::ConvertTo<std::vector<uint8_t>>( 127 mojo::ConvertTo<std::vector<uint8_t>>(
180 static_cast<int32_t>(ui::mojom::ShowState::FULLSCREEN)); 128 static_cast<int32_t>(ui::mojom::ShowState::FULLSCREEN));
181 ui::Window* window = 129 ui::Window* window = test_helper_->GetRootsOrderedByDisplayId()[0]
182 GetRootsOrderedByDisplayId()[0]->window_manager()->NewTopLevelWindow( 130 ->window_manager()
183 &properties); 131 ->NewTopLevelWindow(&properties);
184 window->SetVisible(true); 132 window->SetVisible(true);
185 return window; 133 return window;
186 } 134 }
187 135
188 ui::Window* WmTestBase::CreateChildTestWindow(ui::Window* parent, 136 ui::Window* WmTestBase::CreateChildTestWindow(ui::Window* parent,
189 const gfx::Rect& bounds) { 137 const gfx::Rect& bounds) {
190 std::map<std::string, std::vector<uint8_t>> properties; 138 std::map<std::string, std::vector<uint8_t>> properties;
191 properties[ui::mojom::WindowManager::kWindowType_Property] = 139 properties[ui::mojom::WindowManager::kWindowType_Property] =
192 mojo::ConvertTo<std::vector<uint8_t>>(static_cast<int32_t>( 140 mojo::ConvertTo<std::vector<uint8_t>>(static_cast<int32_t>(
193 MusWindowTypeFromWmWindowType(ui::wm::WINDOW_TYPE_NORMAL))); 141 MusWindowTypeFromWmWindowType(ui::wm::WINDOW_TYPE_NORMAL)));
194 ui::Window* window = 142 ui::Window* window = test_helper_->GetRootsOrderedByDisplayId()[0]
195 GetRootsOrderedByDisplayId()[0]->root()->window_tree()->NewWindow( 143 ->root()
196 &properties); 144 ->window_tree()
145 ->NewWindow(&properties);
197 window->SetBounds(bounds); 146 window->SetBounds(bounds);
198 window->SetVisible(true); 147 window->SetVisible(true);
199 parent->AddChild(window); 148 parent->AddChild(window);
200 return window; 149 return window;
201 } 150 }
202 151
203 void WmTestBase::SetUp() { 152 void WmTestBase::SetUp() {
204 setup_called_ = true; 153 setup_called_ = true;
205 test_helper_.reset(new WmTestHelper); 154 test_helper_.reset(new WmTestHelper);
206 test_helper_->Init(); 155 test_helper_->Init();
207 } 156 }
208 157
209 void WmTestBase::TearDown() { 158 void WmTestBase::TearDown() {
210 teardown_called_ = true; 159 teardown_called_ = true;
211 test_helper_.reset(); 160 test_helper_.reset();
212 } 161 }
213 162
214 std::vector<RootWindowController*> WmTestBase::GetRootsOrderedByDisplayId() {
215 std::set<RootWindowController*> roots = test_helper_->window_manager_app()
216 ->window_manager()
217 ->GetRootWindowControllers();
218 std::vector<RootWindowController*> ordered_roots;
219 ordered_roots.insert(ordered_roots.begin(), roots.begin(), roots.end());
220 std::sort(ordered_roots.begin(), ordered_roots.end(), &CompareByDisplayId);
221 return ordered_roots;
222 }
223
224 } // namespace mus 163 } // namespace mus
225 } // namespace ash 164 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698