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

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

Issue 2029883002: Moves mash/wm into ash/mus (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@remove_static_assert
Patch Set: move comment Created 4 years, 6 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
« no previous file with comments | « ash/mus/test/wm_test_base.h ('k') | ash/mus/test/wm_test_helper.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "mash/wm/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"
11 #include "ash/mus/test/wm_test_helper.h"
12 #include "ash/mus/test/wm_test_screen.h"
13 #include "ash/mus/window_manager.h"
14 #include "ash/mus/window_manager_application.h"
10 #include "base/strings/string_number_conversions.h" 15 #include "base/strings/string_number_conversions.h"
11 #include "base/strings/string_split.h" 16 #include "base/strings/string_split.h"
12 #include "components/mus/public/cpp/property_type_converters.h" 17 #include "components/mus/public/cpp/property_type_converters.h"
13 #include "components/mus/public/cpp/window_tree_client.h" 18 #include "components/mus/public/cpp/window_tree_client.h"
14 #include "mash/wm/root_window_controller.h"
15 #include "mash/wm/test/wm_test_helper.h"
16 #include "mash/wm/test/wm_test_screen.h"
17 #include "mash/wm/window_manager.h"
18 #include "mash/wm/window_manager_application.h"
19 #include "ui/display/display.h" 19 #include "ui/display/display.h"
20 20
21 namespace mash { 21 namespace ash {
22 namespace wm { 22 namespace mus {
23 namespace { 23 namespace {
24 24
25 mus::mojom::WindowType MusWindowTypeFromWmWindowType( 25 ::mus::mojom::WindowType MusWindowTypeFromWmWindowType(
26 ui::wm::WindowType wm_window_type) { 26 ui::wm::WindowType wm_window_type) {
27 switch (wm_window_type) { 27 switch (wm_window_type) {
28 case ui::wm::WINDOW_TYPE_UNKNOWN: 28 case ui::wm::WINDOW_TYPE_UNKNOWN:
29 break; 29 break;
30 30
31 case ui::wm::WINDOW_TYPE_NORMAL: 31 case ui::wm::WINDOW_TYPE_NORMAL:
32 return mus::mojom::WindowType::WINDOW; 32 return ::mus::mojom::WindowType::WINDOW;
33 33
34 case ui::wm::WINDOW_TYPE_POPUP: 34 case ui::wm::WINDOW_TYPE_POPUP:
35 return mus::mojom::WindowType::POPUP; 35 return ::mus::mojom::WindowType::POPUP;
36 36
37 case ui::wm::WINDOW_TYPE_CONTROL: 37 case ui::wm::WINDOW_TYPE_CONTROL:
38 return mus::mojom::WindowType::CONTROL; 38 return ::mus::mojom::WindowType::CONTROL;
39 39
40 case ui::wm::WINDOW_TYPE_PANEL: 40 case ui::wm::WINDOW_TYPE_PANEL:
41 return mus::mojom::WindowType::PANEL; 41 return ::mus::mojom::WindowType::PANEL;
42 42
43 case ui::wm::WINDOW_TYPE_MENU: 43 case ui::wm::WINDOW_TYPE_MENU:
44 return mus::mojom::WindowType::MENU; 44 return ::mus::mojom::WindowType::MENU;
45 45
46 case ui::wm::WINDOW_TYPE_TOOLTIP: 46 case ui::wm::WINDOW_TYPE_TOOLTIP:
47 return mus::mojom::WindowType::TOOLTIP; 47 return ::mus::mojom::WindowType::TOOLTIP;
48 } 48 }
49 49
50 NOTREACHED(); 50 NOTREACHED();
51 return mus::mojom::WindowType::CONTROL; 51 return ::mus::mojom::WindowType::CONTROL;
52 } 52 }
53 53
54 bool CompareByDisplayId(const RootWindowController* root1, 54 bool CompareByDisplayId(const RootWindowController* root1,
55 const RootWindowController* root2) { 55 const RootWindowController* root2) {
56 return root1->display().id() < root2->display().id(); 56 return root1->display().id() < root2->display().id();
57 } 57 }
58 58
59 // TODO(sky): at some point this needs to support everything in DisplayInfo, 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. 60 // for now just the bare minimum, which is [x+y-]wxh.
61 gfx::Rect ParseDisplayBounds(const std::string& spec) { 61 gfx::Rect ParseDisplayBounds(const std::string& spec) {
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 gfx::Rect work_area(bounds); 113 gfx::Rect work_area(bounds);
114 // Offset the height slightly to give a different work area. -2 is arbitrary, 114 // Offset the height slightly to give a different work area. -2 is arbitrary,
115 // it could be anything. 115 // it could be anything.
116 work_area.set_height(std::max(0, work_area.height() - 2)); 116 work_area.set_height(std::max(0, work_area.height() - 2));
117 roots[0]->display_.set_work_area(work_area); 117 roots[0]->display_.set_work_area(work_area);
118 roots[0]->root()->SetBounds(gfx::Rect(bounds.size())); 118 roots[0]->root()->SetBounds(gfx::Rect(bounds.size()));
119 test_helper_->screen()->display_list()->UpdateDisplay( 119 test_helper_->screen()->display_list()->UpdateDisplay(
120 roots[0]->display(), views::DisplayList::Type::PRIMARY); 120 roots[0]->display(), views::DisplayList::Type::PRIMARY);
121 } 121 }
122 122
123 mus::Window* WmTestBase::GetPrimaryRootWindow() { 123 ::mus::Window* WmTestBase::GetPrimaryRootWindow() {
124 std::vector<RootWindowController*> roots = 124 std::vector<RootWindowController*> roots =
125 WmTestBase::GetRootsOrderedByDisplayId(); 125 WmTestBase::GetRootsOrderedByDisplayId();
126 DCHECK(!roots.empty()); 126 DCHECK(!roots.empty());
127 return roots[0]->root(); 127 return roots[0]->root();
128 } 128 }
129 129
130 mus::Window* WmTestBase::GetSecondaryRootWindow() { 130 ::mus::Window* WmTestBase::GetSecondaryRootWindow() {
131 std::vector<RootWindowController*> roots = 131 std::vector<RootWindowController*> roots =
132 WmTestBase::GetRootsOrderedByDisplayId(); 132 WmTestBase::GetRootsOrderedByDisplayId();
133 return roots.size() < 2 ? nullptr : roots[1]->root(); 133 return roots.size() < 2 ? nullptr : roots[1]->root();
134 } 134 }
135 135
136 display::Display WmTestBase::GetPrimaryDisplay() { 136 display::Display WmTestBase::GetPrimaryDisplay() {
137 std::vector<RootWindowController*> roots = 137 std::vector<RootWindowController*> roots =
138 WmTestBase::GetRootsOrderedByDisplayId(); 138 WmTestBase::GetRootsOrderedByDisplayId();
139 DCHECK(!roots.empty()); 139 DCHECK(!roots.empty());
140 return roots[0]->display(); 140 return roots[0]->display();
141 } 141 }
142 142
143 display::Display WmTestBase::GetSecondaryDisplay() { 143 display::Display WmTestBase::GetSecondaryDisplay() {
144 std::vector<RootWindowController*> roots = 144 std::vector<RootWindowController*> roots =
145 WmTestBase::GetRootsOrderedByDisplayId(); 145 WmTestBase::GetRootsOrderedByDisplayId();
146 return roots.size() < 2 ? display::Display() : roots[1]->display(); 146 return roots.size() < 2 ? display::Display() : roots[1]->display();
147 } 147 }
148 148
149 mus::Window* WmTestBase::CreateTestWindow(const gfx::Rect& bounds) { 149 ::mus::Window* WmTestBase::CreateTestWindow(const gfx::Rect& bounds) {
150 return CreateTestWindow(bounds, ui::wm::WINDOW_TYPE_NORMAL); 150 return CreateTestWindow(bounds, ui::wm::WINDOW_TYPE_NORMAL);
151 } 151 }
152 152
153 mus::Window* WmTestBase::CreateTestWindow(const gfx::Rect& bounds, 153 ::mus::Window* WmTestBase::CreateTestWindow(const gfx::Rect& bounds,
154 ui::wm::WindowType window_type) { 154 ui::wm::WindowType window_type) {
155 std::map<std::string, std::vector<uint8_t>> properties; 155 std::map<std::string, std::vector<uint8_t>> properties;
156 properties[mus::mojom::WindowManager::kWindowType_Property] = 156 properties[::mus::mojom::WindowManager::kWindowType_Property] =
157 mojo::ConvertTo<std::vector<uint8_t>>( 157 mojo::ConvertTo<std::vector<uint8_t>>(
158 static_cast<int32_t>(MusWindowTypeFromWmWindowType(window_type))); 158 static_cast<int32_t>(MusWindowTypeFromWmWindowType(window_type)));
159 if (!bounds.IsEmpty()) { 159 if (!bounds.IsEmpty()) {
160 properties[mus::mojom::WindowManager::kInitialBounds_Property] = 160 properties[::mus::mojom::WindowManager::kInitialBounds_Property] =
161 mojo::ConvertTo<std::vector<uint8_t>>(bounds); 161 mojo::ConvertTo<std::vector<uint8_t>>(bounds);
162 } 162 }
163 properties[mus::mojom::WindowManager::kResizeBehavior_Property] = 163 properties[::mus::mojom::WindowManager::kResizeBehavior_Property] =
164 mojo::ConvertTo<std::vector<uint8_t>>( 164 mojo::ConvertTo<std::vector<uint8_t>>(
165 mus::mojom::kResizeBehaviorCanResize | 165 ::mus::mojom::kResizeBehaviorCanResize |
166 mus::mojom::kResizeBehaviorCanMaximize | 166 ::mus::mojom::kResizeBehaviorCanMaximize |
167 mus::mojom::kResizeBehaviorCanMinimize); 167 ::mus::mojom::kResizeBehaviorCanMinimize);
168 168
169 mus::Window* window = 169 ::mus::Window* window =
170 GetRootsOrderedByDisplayId()[0]->window_manager()->NewTopLevelWindow( 170 GetRootsOrderedByDisplayId()[0]->window_manager()->NewTopLevelWindow(
171 &properties); 171 &properties);
172 window->SetVisible(true); 172 window->SetVisible(true);
173 return window; 173 return window;
174 } 174 }
175 175
176 mus::Window* WmTestBase::CreateChildTestWindow(mus::Window* parent, 176 ::mus::Window* WmTestBase::CreateChildTestWindow(::mus::Window* parent,
177 const gfx::Rect& bounds) { 177 const gfx::Rect& bounds) {
178 std::map<std::string, std::vector<uint8_t>> properties; 178 std::map<std::string, std::vector<uint8_t>> properties;
179 properties[mus::mojom::WindowManager::kWindowType_Property] = 179 properties[::mus::mojom::WindowManager::kWindowType_Property] =
180 mojo::ConvertTo<std::vector<uint8_t>>(static_cast<int32_t>( 180 mojo::ConvertTo<std::vector<uint8_t>>(static_cast<int32_t>(
181 MusWindowTypeFromWmWindowType(ui::wm::WINDOW_TYPE_NORMAL))); 181 MusWindowTypeFromWmWindowType(ui::wm::WINDOW_TYPE_NORMAL)));
182 mus::Window* window = 182 ::mus::Window* window =
183 GetRootsOrderedByDisplayId()[0]->root()->window_tree()->NewWindow( 183 GetRootsOrderedByDisplayId()[0]->root()->window_tree()->NewWindow(
184 &properties); 184 &properties);
185 window->SetBounds(bounds); 185 window->SetBounds(bounds);
186 window->SetVisible(true); 186 window->SetVisible(true);
187 parent->AddChild(window); 187 parent->AddChild(window);
188 return window; 188 return window;
189 } 189 }
190 190
191 void WmTestBase::SetUp() { 191 void WmTestBase::SetUp() {
192 setup_called_ = true; 192 setup_called_ = true;
193 test_helper_.reset(new WmTestHelper); 193 test_helper_.reset(new WmTestHelper);
194 test_helper_->Init(); 194 test_helper_->Init();
195 } 195 }
196 196
197 void WmTestBase::TearDown() { 197 void WmTestBase::TearDown() {
198 teardown_called_ = true; 198 teardown_called_ = true;
199 test_helper_.reset(); 199 test_helper_.reset();
200 } 200 }
201 201
202 std::vector<RootWindowController*> WmTestBase::GetRootsOrderedByDisplayId() { 202 std::vector<RootWindowController*> WmTestBase::GetRootsOrderedByDisplayId() {
203 std::set<RootWindowController*> roots = 203 std::set<RootWindowController*> roots =
204 test_helper_->window_manager_app()->GetRootControllers(); 204 test_helper_->window_manager_app()->GetRootControllers();
205 std::vector<RootWindowController*> ordered_roots; 205 std::vector<RootWindowController*> ordered_roots;
206 ordered_roots.insert(ordered_roots.begin(), roots.begin(), roots.end()); 206 ordered_roots.insert(ordered_roots.begin(), roots.begin(), roots.end());
207 std::sort(ordered_roots.begin(), ordered_roots.end(), &CompareByDisplayId); 207 std::sort(ordered_roots.begin(), ordered_roots.end(), &CompareByDisplayId);
208 return ordered_roots; 208 return ordered_roots;
209 } 209 }
210 210
211 } // namespace wm 211 } // namespace mus
212 } // namespace mash 212 } // namespace ash
OLDNEW
« no previous file with comments | « ash/mus/test/wm_test_base.h ('k') | ash/mus/test/wm_test_helper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698