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

Side by Side Diff: ash/mus/test/wm_test_helper.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_helper.h" 5 #include "ash/mus/test/wm_test_helper.h"
6 6
7 #include "ash/common/material_design/material_design_controller.h" 7 #include "ash/common/material_design/material_design_controller.h"
8 #include "ash/common/test/material_design_controller_test_api.h" 8 #include "ash/common/test/material_design_controller_test_api.h"
9 #include "ash/mus/root_window_controller.h" 9 #include "ash/mus/root_window_controller.h"
10 #include "ash/mus/test/wm_test_screen.h" 10 #include "ash/mus/test/wm_test_screen.h"
11 #include "ash/mus/window_manager.h" 11 #include "ash/mus/window_manager.h"
12 #include "ash/mus/window_manager_application.h" 12 #include "ash/mus/window_manager_application.h"
13 #include "base/memory/ptr_util.h" 13 #include "base/memory/ptr_util.h"
14 #include "base/message_loop/message_loop.h" 14 #include "base/message_loop/message_loop.h"
15 #include "base/strings/string_number_conversions.h"
16 #include "base/strings/string_split.h"
15 #include "base/test/sequenced_worker_pool_owner.h" 17 #include "base/test/sequenced_worker_pool_owner.h"
16 #include "services/ui/public/cpp/property_type_converters.h" 18 #include "services/ui/public/cpp/property_type_converters.h"
17 #include "services/ui/public/cpp/tests/window_tree_client_private.h" 19 #include "services/ui/public/cpp/tests/window_tree_client_private.h"
18 #include "services/ui/public/cpp/window_tree_client.h" 20 #include "services/ui/public/cpp/window_tree_client.h"
19 #include "ui/base/material_design/material_design_controller.h" 21 #include "ui/base/material_design/material_design_controller.h"
20 #include "ui/base/test/material_design_controller_test_api.h" 22 #include "ui/base/test/material_design_controller_test_api.h"
21 #include "ui/display/display.h" 23 #include "ui/display/display.h"
24 #include "ui/display/display_list.h"
22 25
23 namespace ash { 26 namespace ash {
24 namespace mus { 27 namespace mus {
28 namespace {
29
30 bool CompareByDisplayId(const RootWindowController* root1,
31 const RootWindowController* root2) {
32 return root1->display().id() < root2->display().id();
33 }
34
35 // TODO(sky): at some point this needs to support everything in DisplayInfo,
36 // for now just the bare minimum, which is [x+y-]wxh.
37 gfx::Rect ParseDisplayBounds(const std::string& spec) {
38 gfx::Rect bounds;
39 const std::vector<std::string> parts =
40 base::SplitString(spec, "-", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
41 std::string size_spec;
42 if (parts.size() == 2u) {
43 size_spec = parts[1];
44 const std::vector<std::string> origin_parts = base::SplitString(
45 parts[0], "+", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
46 CHECK_EQ(2u, origin_parts.size());
47 int x, y;
48 CHECK(base::StringToInt(origin_parts[0], &x));
49 CHECK(base::StringToInt(origin_parts[1], &y));
50 bounds.set_origin(gfx::Point(x, y));
51 } else {
52 CHECK_EQ(1u, parts.size());
53 size_spec = spec;
54 }
55 const std::vector<std::string> size_parts = base::SplitString(
56 size_spec, "x", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
57 CHECK_EQ(2u, size_parts.size());
58 int w, h;
msw 2016/09/12 22:01:51 nit: = 0 ?
sky 2016/09/12 23:11:27 Done.
59 CHECK(base::StringToInt(size_parts[0], &w));
60 CHECK(base::StringToInt(size_parts[1], &h));
61 bounds.set_size(gfx::Size(w, h));
62 return bounds;
63 }
64
65 } // namespace
25 66
26 WmTestHelper::WmTestHelper() {} 67 WmTestHelper::WmTestHelper() {}
27 68
28 WmTestHelper::~WmTestHelper() { 69 WmTestHelper::~WmTestHelper() {
29 // Needs to be destroyed before material design. 70 // Needs to be destroyed before material design.
30 window_manager_app_.reset(); 71 window_manager_app_.reset();
31 72
32 base::RunLoop().RunUntilIdle(); 73 base::RunLoop().RunUntilIdle();
33 blocking_pool_owner_.reset(); 74 blocking_pool_owner_.reset();
34 base::RunLoop().RunUntilIdle(); 75 base::RunLoop().RunUntilIdle();
(...skipping 12 matching lines...) Expand all
47 88
48 const size_t kMaxNumberThreads = 3u; // Matches that of content. 89 const size_t kMaxNumberThreads = 3u; // Matches that of content.
49 const char kThreadNamePrefix[] = "MashBlockingForTesting"; 90 const char kThreadNamePrefix[] = "MashBlockingForTesting";
50 blocking_pool_owner_ = base::MakeUnique<base::SequencedWorkerPoolOwner>( 91 blocking_pool_owner_ = base::MakeUnique<base::SequencedWorkerPoolOwner>(
51 kMaxNumberThreads, kThreadNamePrefix); 92 kMaxNumberThreads, kThreadNamePrefix);
52 93
53 window_manager_app_->window_manager_.reset(new WindowManager(nullptr)); 94 window_manager_app_->window_manager_.reset(new WindowManager(nullptr));
54 screen_ = new WmTestScreen; 95 screen_ = new WmTestScreen;
55 window_manager_app_->window_manager_->screen_.reset(screen_); 96 window_manager_app_->window_manager_->screen_.reset(screen_);
56 97
57 // Need an id other than kInvalidDisplayID so the Display is considered valid. 98 // Need an id other than kInvalidDisplayID so the Display is considered valid.
msw 2016/09/12 22:01:51 nit: could this call CreateRootWindowController wi
sky 2016/09/12 23:11:27 This resulted in a bit more changes, but it's wher
58 display::Display display(1); 99 display::Display display(next_display_id_++);
59 const gfx::Rect display_bounds(0, 0, 800, 600); 100 const gfx::Rect display_bounds(0, 0, 800, 600);
60 display.set_bounds(display_bounds); 101 display.set_bounds(display_bounds);
61 // Offset the height slightly to give a different work area. -20 is arbitrary, 102 // Offset the height slightly to give a different work area. -20 is arbitrary,
62 // it could be anything. 103 // it could be anything.
63 const gfx::Rect work_area(0, 0, display_bounds.width(), 104 const gfx::Rect work_area(0, 0, display_bounds.width(),
64 display_bounds.height() - 20); 105 display_bounds.height() - 20);
65 display.set_work_area(work_area); 106 display.set_work_area(work_area);
66 window_tree_client_setup_.InitForWindowManager( 107 window_tree_client_setup_.InitForWindowManager(
67 window_manager_app_->window_manager_.get(), 108 window_manager_app_->window_manager_.get(),
68 window_manager_app_->window_manager_.get(), display); 109 window_manager_app_->window_manager_.get(), display);
69 110
70 window_manager_app_->InitWindowManager( 111 window_manager_app_->InitWindowManager(
71 window_tree_client_setup_.OwnWindowTreeClient(), 112 window_tree_client_setup_.OwnWindowTreeClient(),
72 blocking_pool_owner_->pool()); 113 blocking_pool_owner_->pool());
73 ui::WindowTreeClient* window_tree_client = 114 ui::WindowTreeClient* window_tree_client =
74 window_manager_app_->window_manager()->window_tree_client(); 115 window_manager_app_->window_manager()->window_tree_client();
75 116
76 screen_->display_list()->AddDisplay(display, 117 screen_->display_list()->AddDisplay(display,
77 display::DisplayList::Type::PRIMARY); 118 display::DisplayList::Type::PRIMARY);
78 119
79 ui::WindowTreeClientPrivate(window_tree_client) 120 window_tree_client_private_ =
80 .CallWmNewDisplayAdded(display); 121 base::MakeUnique<ui::WindowTreeClientPrivate>(window_tree_client);
122 window_tree_client_private_->CallWmNewDisplayAdded(display);
123 }
124
125 std::vector<RootWindowController*> WmTestHelper::GetRootsOrderedByDisplayId() {
126 std::set<RootWindowController*> roots =
127 window_manager_app_->window_manager()->GetRootWindowControllers();
128 std::vector<RootWindowController*> ordered_roots;
129 ordered_roots.insert(ordered_roots.begin(), roots.begin(), roots.end());
130 std::sort(ordered_roots.begin(), ordered_roots.end(), &CompareByDisplayId);
131 return ordered_roots;
132 }
133
134 void WmTestHelper::UpdateDisplay(const std::string& display_spec) {
135 const std::vector<std::string> parts = base::SplitString(
136 display_spec, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
137 std::vector<RootWindowController*> root_window_controllers =
138 GetRootsOrderedByDisplayId();
139 for (size_t i = 0,
140 end = std::min(parts.size(), root_window_controllers.size());
141 i < end; ++i) {
142 UpdateDisplay(root_window_controllers[i], parts[i]);
143 }
144 for (size_t i = root_window_controllers.size(); i < parts.size(); ++i)
145 root_window_controllers.push_back(CreateRootWindowController(parts[i]));
146 while (root_window_controllers.size() > parts.size()) {
147 DestroyRootWindowController(root_window_controllers.back());
148 root_window_controllers.pop_back();
149 }
150 }
151
152 RootWindowController* WmTestHelper::CreateRootWindowController(
153 const std::string& display_spec) {
154 display::Display display(next_display_id_++,
155 ParseDisplayBounds(display_spec));
156 gfx::Rect work_area(display.bounds());
157 // Offset the height slightly to give a different work area. -2 is arbitrary,
msw 2016/09/12 22:01:51 q: Why -2 here and below, but -20 above?
sky 2016/09/12 23:11:27 Fixed.
158 // it could be anything.
159 work_area.set_height(std::max(0, work_area.height() - 2));
160 display.set_work_area(work_area);
161 window_tree_client_private_->CallWmNewDisplayAdded(display);
162 return GetRootsOrderedByDisplayId().back();
163 }
164
165 void WmTestHelper::UpdateDisplay(RootWindowController* root_window_controller,
166 const std::string& display_spec) {
167 gfx::Rect bounds = ParseDisplayBounds(display_spec);
168 root_window_controller->display_.set_bounds(bounds);
169 gfx::Rect work_area(bounds);
170 // Offset the height slightly to give a different work area. -2 is arbitrary,
171 // it could be anything.
172 work_area.set_height(std::max(0, work_area.height() - 2));
173 root_window_controller->display_.set_work_area(work_area);
174 root_window_controller->root()->SetBounds(gfx::Rect(bounds.size()));
175 const bool is_primary = screen_->display_list()->FindDisplayById(
176 root_window_controller->display().id()) ==
177 screen_->display_list()->GetPrimaryDisplayIterator();
178 screen_->display_list()->UpdateDisplay(
179 root_window_controller->display(),
180 is_primary ? display::DisplayList::Type::PRIMARY
181 : display::DisplayList::Type::NOT_PRIMARY);
182 }
183
184 void WmTestHelper::DestroyRootWindowController(
185 RootWindowController* root_window_controller) {
186 window_manager_app_->window_manager()->RemoveDisplay(
187 root_window_controller->root());
81 } 188 }
82 189
83 } // namespace mus 190 } // namespace mus
84 } // namespace ash 191 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698