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

Side by Side Diff: services/ui/ws/window_manager_client_unittest.cc

Issue 2559703003: Converts WindowTreeClientTest to be in terms of aura (Closed)
Patch Set: tweak Created 4 years 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 <stddef.h> 5 #include <stddef.h>
6 #include <stdint.h> 6 #include <stdint.h>
7 7
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
11 #include "base/run_loop.h" 11 #include "base/run_loop.h"
12 #include "services/ui/common/util.h" 12 #include "services/ui/common/util.h"
13 #include "services/ui/public/cpp/tests/window_server_test_base.h" 13 #include "services/ui/ws/window_server_test_base.h"
14 #include "services/ui/public/cpp/window_observer.h" 14 #include "ui/aura/env.h"
15 #include "services/ui/public/cpp/window_private.h" 15 #include "ui/aura/mus/window_port_mus.h"
16 #include "services/ui/public/cpp/window_tree_client.h" 16 #include "ui/aura/mus/window_tree_client.h"
17 #include "services/ui/public/cpp/window_tree_client_delegate.h" 17 #include "ui/aura/mus/window_tree_client_delegate.h"
18 #include "services/ui/public/cpp/window_tree_client_observer.h" 18 #include "ui/aura/mus/window_tree_host_mus.h"
19 #include "ui/aura/test/mus/window_tree_client_private.h"
20 #include "ui/aura/window.h"
21 #include "ui/aura/window_observer.h"
22 #include "ui/aura/window_tracker.h"
19 #include "ui/gfx/geometry/rect.h" 23 #include "ui/gfx/geometry/rect.h"
20 24
21 namespace ui { 25 namespace ui {
22 namespace ws { 26 namespace ws {
23 27
24 namespace { 28 namespace {
25 29
26 Id server_id(ui::Window* window) { 30 Id server_id(aura::Window* window) {
27 return WindowPrivate(window).server_id(); 31 return aura::WindowMus::Get(window)->server_id();
28 } 32 }
29 33
30 ui::Window* GetChildWindowByServerId(WindowTreeClient* client, uint32_t id) { 34 aura::Window* GetChildWindowByServerId(aura::WindowTreeClient* client,
31 return client->GetWindowByServerId(id); 35 aura::Id id) {
36 return aura::WindowTreeClientPrivate(client).GetWindowByServerId(id);
32 } 37 }
33 38
34 int ValidIndexOf(const Window::Children& windows, Window* window) { 39 class TestWindowManagerDelegate : public aura::WindowManagerDelegate {
35 Window::Children::const_iterator it =
36 std::find(windows.begin(), windows.end(), window);
37 return (it != windows.end()) ? (it - windows.begin()) : -1;
38 }
39
40 class TestWindowManagerDelegate : public WindowManagerDelegate {
41 public: 40 public:
42 TestWindowManagerDelegate() {} 41 TestWindowManagerDelegate() {}
43 ~TestWindowManagerDelegate() override {} 42 ~TestWindowManagerDelegate() override {}
44 43
45 // WindowManagerDelegate: 44 // WindowManagerDelegate:
46 void SetWindowManagerClient(WindowManagerClient* client) override {} 45 void SetWindowManagerClient(aura::WindowManagerClient* client) override {}
47 bool OnWmSetBounds(Window* window, gfx::Rect* bounds) override { 46 bool OnWmSetBounds(aura::Window* window, gfx::Rect* bounds) override {
48 return false; 47 return false;
49 } 48 }
50 bool OnWmSetProperty( 49 bool OnWmSetProperty(
51 Window* window, 50 aura::Window* window,
52 const std::string& name, 51 const std::string& name,
53 std::unique_ptr<std::vector<uint8_t>>* new_data) override { 52 std::unique_ptr<std::vector<uint8_t>>* new_data) override {
54 return true; 53 return false;
55 } 54 }
56 Window* OnWmCreateTopLevelWindow( 55 aura::Window* OnWmCreateTopLevelWindow(
56 ui::mojom::WindowType window_type,
57 std::map<std::string, std::vector<uint8_t>>* properties) override { 57 std::map<std::string, std::vector<uint8_t>>* properties) override {
58 return nullptr; 58 return nullptr;
59 } 59 }
60 void OnWmDisplayRemoved(ui::Window* window) override {} 60 void OnWmClientJankinessChanged(const std::set<aura::Window*>& client_windows,
61 void OnWmClientJankinessChanged(const std::set<Window*>& client_windows, 61 bool not_responding) override {}
62 bool janky) override {} 62 void OnWmWillCreateDisplay(const display::Display& display) override {}
63 void OnWmNewDisplay(Window* window, 63 void OnWmNewDisplay(std::unique_ptr<aura::WindowTreeHostMus> window_tree_host,
64 const display::Display& display) override {} 64 const display::Display& display) override {}
65 void OnWmDisplayRemoved(aura::WindowTreeHostMus* window_tree_host) override {}
65 void OnWmDisplayModified(const display::Display& display) override {} 66 void OnWmDisplayModified(const display::Display& display) override {}
66 void OnWmPerformMoveLoop(Window* window, 67 mojom::EventResult OnAccelerator(uint32_t accelerator_id,
68 const ui::Event& event) override {
69 return ui::mojom::EventResult::UNHANDLED;
70 }
71 void OnWmPerformMoveLoop(aura::Window* window,
67 mojom::MoveLoopSource source, 72 mojom::MoveLoopSource source,
68 const gfx::Point& cursor_location, 73 const gfx::Point& cursor_location,
69 const base::Callback<void(bool)>& on_done) override { 74 const base::Callback<void(bool)>& on_done) override {
70 } 75 }
71 void OnWmCancelMoveLoop(Window* window) override {} 76 void OnWmCancelMoveLoop(aura::Window* window) override {}
77 void OnWmSetClientArea(
78 aura::Window* window,
79 const gfx::Insets& insets,
80 const std::vector<gfx::Rect>& additional_client_areas) override {}
72 81
73 private: 82 private:
74 DISALLOW_COPY_AND_ASSIGN(TestWindowManagerDelegate); 83 DISALLOW_COPY_AND_ASSIGN(TestWindowManagerDelegate);
75 }; 84 };
76 85
77 class BoundsChangeObserver : public WindowObserver { 86 class BoundsChangeObserver : public aura::WindowObserver {
78 public: 87 public:
79 explicit BoundsChangeObserver(Window* window) : window_(window) { 88 explicit BoundsChangeObserver(aura::Window* window) : window_(window) {
80 window_->AddObserver(this); 89 window_->AddObserver(this);
81 } 90 }
82 ~BoundsChangeObserver() override { window_->RemoveObserver(this); } 91 ~BoundsChangeObserver() override { window_->RemoveObserver(this); }
83 92
84 private: 93 private:
85 // Overridden from WindowObserver: 94 // Overridden from WindowObserver:
86 void OnWindowBoundsChanged(Window* window, 95 void OnWindowBoundsChanged(aura::Window* window,
87 const gfx::Rect& old_bounds, 96 const gfx::Rect& old_bounds,
88 const gfx::Rect& new_bounds) override { 97 const gfx::Rect& new_bounds) override {
89 DCHECK_EQ(window, window_); 98 DCHECK_EQ(window, window_);
90 EXPECT_TRUE(WindowServerTestBase::QuitRunLoop()); 99 EXPECT_TRUE(WindowServerTestBase::QuitRunLoop());
91 } 100 }
92 101
93 Window* window_; 102 aura::Window* window_;
94 103
95 DISALLOW_COPY_AND_ASSIGN(BoundsChangeObserver); 104 DISALLOW_COPY_AND_ASSIGN(BoundsChangeObserver);
96 }; 105 };
97 106
98 // Wait until the bounds of the supplied window change; returns false on 107 // Wait until the bounds of the supplied window change; returns false on
99 // timeout. 108 // timeout.
100 bool WaitForBoundsToChange(Window* window) { 109 bool WaitForBoundsToChange(aura::Window* window) {
101 BoundsChangeObserver observer(window); 110 BoundsChangeObserver observer(window);
102 return WindowServerTestBase::DoRunLoopWithTimeout(); 111 return WindowServerTestBase::DoRunLoopWithTimeout();
103 } 112 }
104 113
105 class ClientAreaChangeObserver : public WindowObserver {
106 public:
107 explicit ClientAreaChangeObserver(Window* window) : window_(window) {
108 window_->AddObserver(this);
109 }
110 ~ClientAreaChangeObserver() override { window_->RemoveObserver(this); }
111
112 private:
113 // Overridden from WindowObserver:
114 void OnWindowClientAreaChanged(
115 Window* window,
116 const gfx::Insets& old_client_area,
117 const std::vector<gfx::Rect>& old_additional_client_areas) override {
118 DCHECK_EQ(window, window_);
119 EXPECT_TRUE(WindowServerTestBase::QuitRunLoop());
120 }
121
122 Window* window_;
123
124 DISALLOW_COPY_AND_ASSIGN(ClientAreaChangeObserver);
125 };
126
127 // Wait until the bounds of the supplied window change; returns false on
128 // timeout.
129 bool WaitForClientAreaToChange(Window* window) {
130 ClientAreaChangeObserver observer(window);
131 return WindowServerTestBase::DoRunLoopWithTimeout();
132 }
133 114
134 // Spins a run loop until the tree beginning at |root| has |tree_size| windows 115 // Spins a run loop until the tree beginning at |root| has |tree_size| windows
135 // (including |root|). 116 // (including |root|).
136 class TreeSizeMatchesObserver : public WindowObserver { 117 class TreeSizeMatchesObserver : public aura::WindowObserver {
137 public: 118 public:
138 TreeSizeMatchesObserver(Window* tree, size_t tree_size) 119 TreeSizeMatchesObserver(aura::Window* tree, size_t tree_size)
139 : tree_(tree), tree_size_(tree_size) { 120 : tree_(tree), tree_size_(tree_size) {
140 tree_->AddObserver(this); 121 tree_->AddObserver(this);
141 } 122 }
142 ~TreeSizeMatchesObserver() override { tree_->RemoveObserver(this); } 123 ~TreeSizeMatchesObserver() override { tree_->RemoveObserver(this); }
143 124
144 bool IsTreeCorrectSize() { return CountWindows(tree_) == tree_size_; } 125 bool IsTreeCorrectSize() { return CountWindows(tree_) == tree_size_; }
145 126
146 private: 127 private:
147 // Overridden from WindowObserver: 128 // Overridden from WindowObserver:
148 void OnTreeChanged(const TreeChangeParams& params) override { 129 void OnWindowHierarchyChanged(const HierarchyChangeParams& params) override {
149 if (IsTreeCorrectSize()) 130 if (IsTreeCorrectSize())
150 EXPECT_TRUE(WindowServerTestBase::QuitRunLoop()); 131 EXPECT_TRUE(WindowServerTestBase::QuitRunLoop());
151 } 132 }
152 133
153 size_t CountWindows(const Window* window) const { 134 size_t CountWindows(const aura::Window* window) const {
154 size_t count = 1; 135 size_t count = 1;
155 Window::Children::const_iterator it = window->children().begin(); 136 for (auto it = window->children().begin(); it != window->children().end();
msw 2016/12/08 01:20:11 optional nit: range-based for loop?
sky 2016/12/08 04:59:44 Done.
156 for (; it != window->children().end(); ++it) 137 ++it) {
157 count += CountWindows(*it); 138 count += CountWindows(*it);
139 }
158 return count; 140 return count;
159 } 141 }
160 142
161 Window* tree_; 143 aura::Window* tree_;
162 size_t tree_size_; 144 size_t tree_size_;
163 145
164 DISALLOW_COPY_AND_ASSIGN(TreeSizeMatchesObserver); 146 DISALLOW_COPY_AND_ASSIGN(TreeSizeMatchesObserver);
165 }; 147 };
166 148
167 // Wait until |window| has |tree_size| descendants; returns false on timeout. 149 // Wait until |window| has |tree_size| descendants; returns false on timeout.
168 // The count includes |window|. For example, if you want to wait for |window| to 150 // The count includes |window|. For example, if you want to wait for |window| to
169 // have a single child, use a |tree_size| of 2. 151 // have a single child, use a |tree_size| of 2.
170 bool WaitForTreeSizeToMatch(Window* window, size_t tree_size) { 152 bool WaitForTreeSizeToMatch(aura::Window* window, size_t tree_size) {
171 TreeSizeMatchesObserver observer(window, tree_size); 153 TreeSizeMatchesObserver observer(window, tree_size);
172 return observer.IsTreeCorrectSize() || 154 return observer.IsTreeCorrectSize() ||
173 WindowServerTestBase::DoRunLoopWithTimeout(); 155 WindowServerTestBase::DoRunLoopWithTimeout();
174 } 156 }
175 157
176 class OrderChangeObserver : public WindowObserver { 158 class StackingOrderChangeObserver : public aura::WindowObserver {
177 public: 159 public:
178 OrderChangeObserver(Window* window) : window_(window) { 160 StackingOrderChangeObserver(aura::Window* window) : window_(window) {
179 window_->AddObserver(this); 161 window_->AddObserver(this);
180 } 162 }
181 ~OrderChangeObserver() override { window_->RemoveObserver(this); } 163 ~StackingOrderChangeObserver() override { window_->RemoveObserver(this); }
182 164
183 private: 165 private:
184 // Overridden from WindowObserver: 166 // Overridden from aura::WindowObserver:
185 void OnWindowReordered(Window* window, 167 void OnWindowStackingChanged(aura::Window* window) override {
186 Window* relative_window,
187 mojom::OrderDirection direction) override {
188 DCHECK_EQ(window, window_); 168 DCHECK_EQ(window, window_);
189 EXPECT_TRUE(WindowServerTestBase::QuitRunLoop()); 169 EXPECT_TRUE(WindowServerTestBase::QuitRunLoop());
190 } 170 }
191 171
192 Window* window_; 172 aura::Window* window_;
193 173
194 DISALLOW_COPY_AND_ASSIGN(OrderChangeObserver); 174 DISALLOW_COPY_AND_ASSIGN(StackingOrderChangeObserver);
195 }; 175 };
196 176
197 // Wait until |window|'s tree size matches |tree_size|; returns false on 177 // Wait until |window|'s tree size matches |tree_size|; returns false on
198 // timeout. 178 // timeout.
199 bool WaitForOrderChange(WindowTreeClient* client, Window* window) { 179 bool WaitForStackingOrderChange(aura::Window* window) {
200 OrderChangeObserver observer(window); 180 StackingOrderChangeObserver observer(window);
201 return WindowServerTestBase::DoRunLoopWithTimeout(); 181 return WindowServerTestBase::DoRunLoopWithTimeout();
202 } 182 }
203 183
204 // Tracks a window's destruction. Query is_valid() for current state. 184 // Tracks a window's destruction. Query is_valid() for current state.
205 class WindowTracker : public WindowObserver { 185 class WindowTracker : public aura::WindowObserver {
206 public: 186 public:
207 explicit WindowTracker(Window* window) : window_(window) { 187 explicit WindowTracker(aura::Window* window) : window_(window) {
208 window_->AddObserver(this); 188 window_->AddObserver(this);
209 } 189 }
210 ~WindowTracker() override { 190 ~WindowTracker() override {
211 if (window_) 191 if (window_)
212 window_->RemoveObserver(this); 192 window_->RemoveObserver(this);
213 } 193 }
214 194
215 bool is_valid() const { return !!window_; } 195 bool is_valid() const { return !!window_; }
216 196
217 private: 197 private:
218 // Overridden from WindowObserver: 198 // Overridden from WindowObserver:
219 void OnWindowDestroyed(Window* window) override { 199 void OnWindowDestroyed(aura::Window* window) override {
220 DCHECK_EQ(window, window_); 200 DCHECK_EQ(window, window_);
221 window_ = nullptr; 201 window_ = nullptr;
222 } 202 }
223 203
224 Window* window_; 204 aura::Window* window_;
225 205
226 DISALLOW_COPY_AND_ASSIGN(WindowTracker); 206 DISALLOW_COPY_AND_ASSIGN(WindowTracker);
227 }; 207 };
228 208
209 // Creates a new Window parented to |parent| that is made visible.
210 aura::Window* NewVisibleWindow(aura::Window* parent,
211 aura::WindowTreeClient* client) {
212 std::unique_ptr<aura::WindowPortMus> window_port_mus =
213 base::MakeUnique<aura::WindowPortMus>(client, aura::WindowMusType::LOCAL);
214 aura::Window* window = new aura::Window(nullptr, std::move(window_port_mus));
215 window->Init(ui::LAYER_NOT_DRAWN);
216 window->Show();
217 parent->AddChild(window);
218 return window;
219 }
220
229 } // namespace 221 } // namespace
230 222
231 // WindowServer 223 // WindowServer
232 // ----------------------------------------------------------------- 224 // -----------------------------------------------------------------
233 225
234 struct EmbedResult { 226 struct EmbedResult {
235 EmbedResult(WindowTreeClient* client, ClientSpecificId id) 227 bool IsValid() const {
236 : client(client), client_id(id) {} 228 return window_tree_client.get() != nullptr &&
237 EmbedResult() : client(nullptr), client_id(0) {} 229 window_tree_host.get() != nullptr;
230 }
238 231
239 WindowTreeClient* client; 232 std::unique_ptr<aura::WindowTreeClient> window_tree_client;
240 233 std::unique_ptr<aura::WindowTreeHostMus> window_tree_host;
241 // The id supplied to the callback from OnEmbed(). Depending upon the
242 // access policy this may or may not match the client id of
243 // |client|.
244 ClientSpecificId client_id;
245 }; 234 };
246 235
247 Window* GetFirstRoot(WindowTreeClient* client) { 236 aura::Window* GetFirstRoot(aura::WindowTreeClient* client) {
248 return client->GetRoots().empty() ? nullptr : *client->GetRoots().begin(); 237 return client->GetRoots().empty() ? nullptr : *client->GetRoots().begin();
249 } 238 }
250 239
251 // These tests model synchronization of two peer clients of the window server, 240 // These tests model synchronization of two peer clients of the window server,
252 // that are given access to some root window. 241 // that are given access to some root window.
253 242
254 class WindowServerTest : public WindowServerTestBase { 243 class WindowServerTest : public WindowServerTestBase {
255 public: 244 public:
245 struct ClientAreaChange {
246 aura::Window* window;
msw 2016/12/08 01:20:11 nit: = nullptr
sky 2016/12/08 04:59:44 Done.
247 gfx::Insets insets;
248 };
249
256 WindowServerTest() {} 250 WindowServerTest() {}
257 251
258 Window* GetFirstWMRoot() { return GetFirstRoot(window_manager()); } 252 aura::Window* GetFirstWMRoot() { return GetFirstRoot(window_manager()); }
259
260 Window* NewVisibleWindow(Window* parent, WindowTreeClient* client) {
261 Window* window = client->NewWindow();
262 window->SetVisible(true);
263 parent->AddChild(window);
264 return window;
265 }
266 253
267 // Embeds another version of the test app @ window. This runs a run loop until 254 // Embeds another version of the test app @ window. This runs a run loop until
268 // a response is received, or a timeout. On success the new WindowServer is 255 // a response is received, or a timeout. The return value is always non-null,
269 // returned. 256 // but if there is an error there is no WindowTreeClient. Always use
270 EmbedResult Embed(Window* window) { 257 // ASSERT_EQ(result->IsValid()) on the return value.
258 std::unique_ptr<EmbedResult> Embed(aura::WindowTreeClient* window_tree_client,
259 aura::Window* window) {
271 DCHECK(!embed_details_); 260 DCHECK(!embed_details_);
272 embed_details_ = base::MakeUnique<EmbedDetails>(); 261 embed_details_ = base::MakeUnique<EmbedDetails>();
273 window->Embed(ConnectAndGetWindowServerClient(), 262 window_tree_client->Embed(window, ConnectAndGetWindowServerClient(), 0,
274 base::Bind(&WindowServerTest::EmbedCallbackImpl, 263 base::Bind(&WindowServerTest::EmbedCallbackImpl,
275 base::Unretained(this))); 264 base::Unretained(this)));
265 if (embed_details_->callback_run) {
msw 2016/12/08 01:20:11 nit: maybe explain why checking if the callback ha
sky 2016/12/08 04:59:44 I added more docs here.
msw 2016/12/08 19:07:41 Much appreciated; now it makes sense.
266 embed_details_.reset();
267 return base::MakeUnique<EmbedResult>();
268 }
276 embed_details_->waiting = true; 269 embed_details_->waiting = true;
277 if (!WindowServerTestBase::DoRunLoopWithTimeout()) 270 if (!WindowServerTestBase::DoRunLoopWithTimeout()) {
278 return EmbedResult(); 271 embed_details_.reset();
279 const EmbedResult result(embed_details_->client, 272 return base::MakeUnique<EmbedResult>();
280 embed_details_->client_id); 273 }
274 std::unique_ptr<EmbedResult> result = std::move(embed_details_->result);
281 embed_details_.reset(); 275 embed_details_.reset();
282 return result; 276 return result;
283 } 277 }
284 278
285 // Establishes a connection to this application and asks for a 279 // Establishes a connection to this application and asks for a
286 // WindowTreeClient. 280 // WindowTreeClient.
287 ui::mojom::WindowTreeClientPtr ConnectAndGetWindowServerClient() { 281 ui::mojom::WindowTreeClientPtr ConnectAndGetWindowServerClient() {
288 ui::mojom::WindowTreeClientPtr client; 282 ui::mojom::WindowTreeClientPtr client;
289 connector()->ConnectToInterface(test_name(), &client); 283 connector()->ConnectToInterface(test_name(), &client);
290 return client; 284 return client;
291 } 285 }
292 286
287 std::unique_ptr<ClientAreaChange> WaitForClientAreaToChange() {
msw 2016/12/08 01:20:11 nit: maybe comment on why the pattern is different
sky 2016/12/08 04:59:44 Done.
288 client_area_change_ = base::MakeUnique<ClientAreaChange>();
289 if (!WindowServerTestBase::DoRunLoopWithTimeout()) {
290 client_area_change_.reset();
291 return nullptr;
292 }
293 return std::move(client_area_change_);
294 }
295
293 // WindowServerTestBase: 296 // WindowServerTestBase:
294 void OnEmbed(Window* root) override { 297 void OnEmbed(
298 std::unique_ptr<aura::WindowTreeHostMus> window_tree_host) override {
295 if (!embed_details_) { 299 if (!embed_details_) {
296 WindowServerTestBase::OnEmbed(root); 300 WindowServerTestBase::OnEmbed(std::move(window_tree_host));
297 return; 301 return;
298 } 302 }
299 303
300 embed_details_->client = root->window_tree(); 304 embed_details_->result->window_tree_host = std::move(window_tree_host);
305 embed_details_->result->window_tree_client = ReleaseMostRecentClient();
301 if (embed_details_->callback_run) 306 if (embed_details_->callback_run)
302 EXPECT_TRUE(WindowServerTestBase::QuitRunLoop()); 307 EXPECT_TRUE(WindowServerTestBase::QuitRunLoop());
303 } 308 }
309 void OnWmSetClientArea(
310 aura::Window* window,
311 const gfx::Insets& insets,
312 const std::vector<gfx::Rect>& additional_client_areas) override {
313 if (!client_area_change_.get())
314 return;
315
316 client_area_change_->window = window;
317 client_area_change_->insets = insets;
318 EXPECT_TRUE(WindowServerTestBase::QuitRunLoop());
319 }
304 320
305 private: 321 private:
306 // Used to track the state of a call to window->Embed(). 322 // Used to track the state of a call to window->Embed().
307 struct EmbedDetails { 323 struct EmbedDetails {
308 EmbedDetails() 324 EmbedDetails() : result(base::MakeUnique<EmbedResult>()) {}
309 : callback_run(false),
310 result(false),
311 waiting(false),
312 client(nullptr) {}
313 325
314 // The callback supplied to Embed() was received. 326 // The callback supplied to Embed() was received.
315 bool callback_run; 327 bool callback_run = false;
316 328
317 // The boolean supplied to the Embed() callback. 329 // The boolean supplied to the Embed() callback.
318 bool result; 330 bool embed_result = false;
319 331
320 // Whether a MessageLoop is running. 332 // Whether a MessageLoop is running.
321 bool waiting; 333 bool waiting = false;
322 334
323 // Client id supplied to the Embed() callback. 335 std::unique_ptr<EmbedResult> result;
324 ClientSpecificId client_id;
325
326 // The WindowTreeClient that resulted from the Embed(). null if |result| is
327 // false.
328 WindowTreeClient* client;
329 }; 336 };
330 337
331 void EmbedCallbackImpl(bool result) { 338 void EmbedCallbackImpl(bool result) {
332 embed_details_->callback_run = true; 339 embed_details_->callback_run = true;
333 embed_details_->result = result; 340 embed_details_->embed_result = result;
334 if (embed_details_->waiting && (!result || embed_details_->client)) 341 if (embed_details_->waiting &&
342 (!result || embed_details_->result->window_tree_client))
335 EXPECT_TRUE(WindowServerTestBase::QuitRunLoop()); 343 EXPECT_TRUE(WindowServerTestBase::QuitRunLoop());
336 } 344 }
337 345
338 std::unique_ptr<EmbedDetails> embed_details_; 346 std::unique_ptr<EmbedDetails> embed_details_;
339 347
348 std::unique_ptr<ClientAreaChange> client_area_change_;
349
340 DISALLOW_COPY_AND_ASSIGN(WindowServerTest); 350 DISALLOW_COPY_AND_ASSIGN(WindowServerTest);
341 }; 351 };
342 352
343 TEST_F(WindowServerTest, RootWindow) { 353 TEST_F(WindowServerTest, RootWindow) {
344 ASSERT_NE(nullptr, window_manager()); 354 ASSERT_NE(nullptr, window_manager());
345 EXPECT_EQ(1u, window_manager()->GetRoots().size()); 355 EXPECT_EQ(1u, window_manager()->GetRoots().size());
346 } 356 }
347 357
348 TEST_F(WindowServerTest, Embed) { 358 TEST_F(WindowServerTest, Embed) {
349 Window* window = window_manager()->NewWindow(); 359 aura::Window* window = NewVisibleWindow(GetFirstWMRoot(), window_manager());
350 ASSERT_NE(nullptr, window); 360 std::unique_ptr<EmbedResult> embed_result = Embed(window_manager(), window);
351 window->SetVisible(true); 361 ASSERT_TRUE(embed_result->IsValid());
352 GetFirstWMRoot()->AddChild(window);
353 WindowTreeClient* embedded = Embed(window).client;
354 ASSERT_NE(nullptr, embedded);
355 362
356 Window* window_in_embedded = GetFirstRoot(embedded); 363 aura::Window* window_in_embedded =
msw 2016/12/08 01:20:11 nit: explain why this is different than the |windo
sky 2016/12/08 04:59:44 They are the same. I added a couple more assertion
357 ASSERT_NE(nullptr, window_in_embedded); 364 GetFirstRoot(embed_result->window_tree_client.get());
365 ASSERT_TRUE(window_in_embedded);
358 EXPECT_EQ(server_id(window), server_id(window_in_embedded)); 366 EXPECT_EQ(server_id(window), server_id(window_in_embedded));
359 EXPECT_EQ(nullptr, window_in_embedded->parent()); 367 EXPECT_EQ(nullptr, window_in_embedded->parent());
360 EXPECT_TRUE(window_in_embedded->children().empty()); 368 EXPECT_TRUE(window_in_embedded->children().empty());
361 } 369 }
362 370
363 // Window manager has two windows, N1 and N11. Embeds A at N1. A should not see 371 // Window manager has two windows, N1 and N11. Embeds A at N1. A should not see
364 // N11. 372 // N11.
365 TEST_F(WindowServerTest, EmbeddedDoesntSeeChild) { 373 TEST_F(WindowServerTest, EmbeddedDoesntSeeChild) {
366 Window* window = window_manager()->NewWindow(); 374 aura::Window* window = NewVisibleWindow(GetFirstWMRoot(), window_manager());
367 ASSERT_NE(nullptr, window); 375 std::unique_ptr<EmbedResult> embed_result = Embed(window_manager(), window);
368 window->SetVisible(true); 376 ASSERT_TRUE(embed_result->IsValid());
369 GetFirstWMRoot()->AddChild(window); 377 aura::Window* window_in_embedded = embed_result->window_tree_host->window();
370 Window* nested = window_manager()->NewWindow();
371 ASSERT_NE(nullptr, nested);
372 nested->SetVisible(true);
373 window->AddChild(nested);
374
375 WindowTreeClient* embedded = Embed(window).client;
376 ASSERT_NE(nullptr, embedded);
377 Window* window_in_embedded = GetFirstRoot(embedded);
378 EXPECT_EQ(server_id(window), server_id(window_in_embedded)); 378 EXPECT_EQ(server_id(window), server_id(window_in_embedded));
379 EXPECT_EQ(nullptr, window_in_embedded->parent()); 379 EXPECT_EQ(nullptr, window_in_embedded->parent());
380 EXPECT_TRUE(window_in_embedded->children().empty()); 380 EXPECT_TRUE(window_in_embedded->children().empty());
381 } 381 }
382 382
383 // TODO(beng): write a replacement test for the one that once existed here: 383 // TODO(beng): write a replacement test for the one that once existed here:
384 // This test validates the following scenario: 384 // This test validates the following scenario:
385 // - a window originating from one client 385 // - a window originating from one client
386 // - a window originating from a second client 386 // - a window originating from a second client
387 // + the client originating the window is destroyed 387 // + the client originating the window is destroyed
388 // -> the window should still exist (since the second client is live) but 388 // -> the window should still exist (since the second client is live) but
389 // should be disconnected from any windows. 389 // should be disconnected from any windows.
390 // http://crbug.com/396300 390 // http://crbug.com/396300
391 // 391 //
392 // TODO(beng): The new test should validate the scenario as described above 392 // TODO(beng): The new test should validate the scenario as described above
393 // except that the second client still has a valid tree. 393 // except that the second client still has a valid tree.
394 394
395 // Verifies that bounds changes applied to a window hierarchy in one client 395 // Verifies that bounds changes applied to a window hierarchy in one client
396 // are reflected to another. 396 // are reflected to another.
397 TEST_F(WindowServerTest, SetBounds) { 397 TEST_F(WindowServerTest, SetBounds) {
398 Window* window = window_manager()->NewWindow(); 398 aura::Window* window = NewVisibleWindow(GetFirstWMRoot(), window_manager());
399 window->SetVisible(true);
400 GetFirstWMRoot()->AddChild(window);
401 WindowTreeClient* embedded = Embed(window).client;
402 ASSERT_NE(nullptr, embedded);
403 399
404 Window* window_in_embedded = 400 std::unique_ptr<EmbedResult> embed_result = Embed(window_manager(), window);
405 GetChildWindowByServerId(embedded, server_id(window)); 401 ASSERT_TRUE(embed_result->IsValid());
402 aura::Window* window_in_embedded = embed_result->window_tree_host->window();
406 EXPECT_EQ(window->bounds(), window_in_embedded->bounds()); 403 EXPECT_EQ(window->bounds(), window_in_embedded->bounds());
407 404
408 window->SetBounds(gfx::Rect(0, 0, 100, 100)); 405 window->SetBounds(gfx::Rect(0, 0, 100, 100));
409 ASSERT_TRUE(WaitForBoundsToChange(window_in_embedded)); 406 ASSERT_TRUE(WaitForBoundsToChange(window_in_embedded));
410 EXPECT_TRUE(window->bounds() == window_in_embedded->bounds()); 407 EXPECT_EQ(window->bounds(), window_in_embedded->bounds());
411 } 408 }
412 409
413 // Verifies that bounds changes applied to a window owned by a different 410 // Verifies that bounds changes applied to a window owned by a different
414 // client can be refused. 411 // client can be refused.
415 TEST_F(WindowServerTest, SetBoundsSecurity) { 412 TEST_F(WindowServerTest, SetBoundsSecurity) {
416 TestWindowManagerDelegate wm_delegate; 413 TestWindowManagerDelegate wm_delegate;
417 set_window_manager_delegate(&wm_delegate); 414 set_window_manager_delegate(&wm_delegate);
418 415
419 Window* window = window_manager()->NewWindow(); 416 aura::Window* window = NewVisibleWindow(GetFirstWMRoot(), window_manager());
420 window->SetVisible(true);
421 GetFirstWMRoot()->AddChild(window);
422 WindowTreeClient* embedded = Embed(window).client;
423 ASSERT_NE(nullptr, embedded);
424 417
425 Window* window_in_embedded = 418 std::unique_ptr<EmbedResult> embed_result = Embed(window_manager(), window);
426 GetChildWindowByServerId(embedded, server_id(window)); 419 ASSERT_TRUE(embed_result->IsValid());
420 aura::Window* window_in_embedded = embed_result->window_tree_host->window();
427 window->SetBounds(gfx::Rect(0, 0, 800, 600)); 421 window->SetBounds(gfx::Rect(0, 0, 800, 600));
428 ASSERT_TRUE(WaitForBoundsToChange(window_in_embedded)); 422 ASSERT_TRUE(WaitForBoundsToChange(window_in_embedded));
429 423
430 window_in_embedded->SetBounds(gfx::Rect(0, 0, 1024, 768)); 424 embed_result->window_tree_host->SetBoundsInPixels(gfx::Rect(0, 0, 1024, 768));
431 // Bounds change is initially accepted, but the server declines the request. 425 // Bounds change is initially accepted, but the server declines the request.
432 EXPECT_FALSE(window->bounds() == window_in_embedded->bounds()); 426 EXPECT_NE(window->bounds(), window_in_embedded->bounds());
433 427
434 // The client is notified when the requested is declined, and updates the 428 // The client is notified when the requested is declined, and updates the
435 // local bounds accordingly. 429 // local bounds accordingly.
436 ASSERT_TRUE(WaitForBoundsToChange(window_in_embedded)); 430 ASSERT_TRUE(WaitForBoundsToChange(window_in_embedded));
437 EXPECT_TRUE(window->bounds() == window_in_embedded->bounds()); 431 EXPECT_EQ(window->bounds(), window_in_embedded->bounds());
438 set_window_manager_delegate(nullptr); 432 set_window_manager_delegate(nullptr);
439 } 433 }
440 434
441 // Verifies that a root window can always be destroyed. 435 // Verifies that a root window can always be destroyed.
442 TEST_F(WindowServerTest, DestroySecurity) { 436 TEST_F(WindowServerTest, DestroySecurity) {
443 Window* window = window_manager()->NewWindow(); 437 aura::Window* window = NewVisibleWindow(GetFirstWMRoot(), window_manager());
444 window->SetVisible(true);
445 GetFirstWMRoot()->AddChild(window);
446 438
447 WindowTreeClient* embedded = Embed(window).client; 439 std::unique_ptr<EmbedResult> embed_result = Embed(window_manager(), window);
448 ASSERT_NE(nullptr, embedded); 440 ASSERT_TRUE(embed_result->IsValid());
441 aura::Window* window_in_embedded = embed_result->window_tree_host->window();
449 442
450 // The root can be destroyed, even though it was not created by the client. 443 // The root can be destroyed, even though it was not created by the client.
451 Window* embed_root = GetChildWindowByServerId(embedded, server_id(window)); 444 aura::WindowTracker tracker;
452 WindowTracker tracker1(window); 445 tracker.Add(window);
453 WindowTracker tracker2(embed_root); 446 tracker.Add(window_in_embedded);
454 embed_root->Destroy(); 447 embed_result->window_tree_host.reset();
455 EXPECT_FALSE(tracker2.is_valid()); 448 EXPECT_FALSE(tracker.Contains(window_in_embedded));
456 EXPECT_TRUE(tracker1.is_valid()); 449 EXPECT_TRUE(tracker.Contains(window));
457 450
458 window->Destroy(); 451 delete window;
459 EXPECT_FALSE(tracker1.is_valid()); 452 EXPECT_FALSE(tracker.Contains(window));
460 } 453 }
461 454
462 TEST_F(WindowServerTest, MultiRoots) { 455 TEST_F(WindowServerTest, MultiRoots) {
463 Window* window1 = window_manager()->NewWindow(); 456 aura::Window* window1 = NewVisibleWindow(GetFirstWMRoot(), window_manager());
464 window1->SetVisible(true); 457 aura::Window* window2 = NewVisibleWindow(GetFirstWMRoot(), window_manager());
465 GetFirstWMRoot()->AddChild(window1); 458 std::unique_ptr<EmbedResult> embed_result1 = Embed(window_manager(), window1);
466 Window* window2 = window_manager()->NewWindow(); 459 ASSERT_TRUE(embed_result1->IsValid());
467 window2->SetVisible(true); 460 std::unique_ptr<EmbedResult> embed_result2 = Embed(window_manager(), window2);
468 GetFirstWMRoot()->AddChild(window2); 461 ASSERT_TRUE(embed_result2->IsValid());
469 WindowTreeClient* embedded1 = Embed(window1).client;
470 ASSERT_NE(nullptr, embedded1);
471 WindowTreeClient* embedded2 = Embed(window2).client;
472 ASSERT_NE(nullptr, embedded2);
473 EXPECT_NE(embedded1, embedded2);
474 } 462 }
475 463
476 TEST_F(WindowServerTest, Reorder) { 464 TEST_F(WindowServerTest, Reorder) {
477 Window* window1 = window_manager()->NewWindow(); 465 aura::Window* window1 = NewVisibleWindow(GetFirstWMRoot(), window_manager());
478 window1->SetVisible(true);
479 GetFirstWMRoot()->AddChild(window1);
480 466
481 WindowTreeClient* embedded = Embed(window1).client; 467 std::unique_ptr<EmbedResult> embed_result = Embed(window_manager(), window1);
482 ASSERT_NE(nullptr, embedded); 468 ASSERT_TRUE(embed_result->IsValid());
469 aura::WindowTreeClient* embedded = embed_result->window_tree_client.get();
470 aura::Window* root_in_embedded = embed_result->window_tree_host->window();
msw 2016/12/08 01:20:11 optional nit: name window_in_embedded like above?
sky 2016/12/08 04:59:45 Done.
483 471
484 Window* window11 = embedded->NewWindow(); 472 aura::Window* window11 = NewVisibleWindow(root_in_embedded, embedded);
485 window11->SetVisible(true); 473 aura::Window* window12 = NewVisibleWindow(root_in_embedded, embedded);
486 GetFirstRoot(embedded)->AddChild(window11);
487 Window* window12 = embedded->NewWindow();
488 window12->SetVisible(true);
489 GetFirstRoot(embedded)->AddChild(window12);
490 ASSERT_TRUE(WaitForTreeSizeToMatch(window1, 3u)); 474 ASSERT_TRUE(WaitForTreeSizeToMatch(window1, 3u));
491 475
492 Window* root_in_embedded = GetFirstRoot(embedded);
493 476
494 { 477 {
495 window11->MoveToFront(); 478 window11->parent()->StackChildAtTop(window11);
496 // The |embedded| tree should be updated immediately. 479 // The |embedded| tree should be updated immediately.
497 EXPECT_EQ(root_in_embedded->children().front(), 480 EXPECT_EQ(root_in_embedded->children().front(),
498 GetChildWindowByServerId(embedded, server_id(window12))); 481 GetChildWindowByServerId(embedded, server_id(window12)));
499 EXPECT_EQ(root_in_embedded->children().back(), 482 EXPECT_EQ(root_in_embedded->children().back(),
500 GetChildWindowByServerId(embedded, server_id(window11))); 483 GetChildWindowByServerId(embedded, server_id(window11)));
501 484
502 // The |window_manager()| tree is still not updated. 485 // The window_manager() tree is still not updated.
503 EXPECT_EQ(window1->children().back(), 486 EXPECT_EQ(window1->children().back(),
504 GetChildWindowByServerId(window_manager(), server_id(window12))); 487 GetChildWindowByServerId(window_manager(), server_id(window12)));
505 488
506 // Wait until |window_manager()| tree is updated. 489 // Wait until window_manager() tree is updated.
507 ASSERT_TRUE(WaitForOrderChange( 490 ASSERT_TRUE(WaitForStackingOrderChange(
508 window_manager(),
509 GetChildWindowByServerId(window_manager(), server_id(window11)))); 491 GetChildWindowByServerId(window_manager(), server_id(window11))));
510 EXPECT_EQ(window1->children().front(), 492 EXPECT_EQ(window1->children().front(),
511 GetChildWindowByServerId(window_manager(), server_id(window12))); 493 GetChildWindowByServerId(window_manager(), server_id(window12)));
512 EXPECT_EQ(window1->children().back(), 494 EXPECT_EQ(window1->children().back(),
513 GetChildWindowByServerId(window_manager(), server_id(window11))); 495 GetChildWindowByServerId(window_manager(), server_id(window11)));
514 } 496 }
515 497
516 { 498 {
517 window11->MoveToBack(); 499 window11->parent()->StackChildAtBottom(window11);
518 // |embedded| should be updated immediately. 500 // |embedded| should be updated immediately.
519 EXPECT_EQ(root_in_embedded->children().front(), 501 EXPECT_EQ(root_in_embedded->children().front(),
520 GetChildWindowByServerId(embedded, server_id(window11))); 502 GetChildWindowByServerId(embedded, server_id(window11)));
521 EXPECT_EQ(root_in_embedded->children().back(), 503 EXPECT_EQ(root_in_embedded->children().back(),
522 GetChildWindowByServerId(embedded, server_id(window12))); 504 GetChildWindowByServerId(embedded, server_id(window12)));
523 505
524 // |window_manager()| is also eventually updated. 506 // |window_manager()| is also eventually updated.
525 EXPECT_EQ(window1->children().back(), 507 EXPECT_EQ(window1->children().back(),
526 GetChildWindowByServerId(window_manager(), server_id(window11))); 508 GetChildWindowByServerId(window_manager(), server_id(window11)));
527 ASSERT_TRUE(WaitForOrderChange( 509 ASSERT_TRUE(WaitForStackingOrderChange(
528 window_manager(),
529 GetChildWindowByServerId(window_manager(), server_id(window11)))); 510 GetChildWindowByServerId(window_manager(), server_id(window11))));
530 EXPECT_EQ(window1->children().front(), 511 EXPECT_EQ(window1->children().front(),
531 GetChildWindowByServerId(window_manager(), server_id(window11))); 512 GetChildWindowByServerId(window_manager(), server_id(window11)));
532 EXPECT_EQ(window1->children().back(), 513 EXPECT_EQ(window1->children().back(),
533 GetChildWindowByServerId(window_manager(), server_id(window12))); 514 GetChildWindowByServerId(window_manager(), server_id(window12)));
534 } 515 }
535 } 516 }
536 517
537 namespace { 518 namespace {
538 519
539 class VisibilityChangeObserver : public WindowObserver { 520 class VisibilityChangeObserver : public aura::WindowObserver {
540 public: 521 public:
541 explicit VisibilityChangeObserver(Window* window) : window_(window) { 522 explicit VisibilityChangeObserver(aura::Window* window) : window_(window) {
542 window_->AddObserver(this); 523 window_->AddObserver(this);
543 } 524 }
544 ~VisibilityChangeObserver() override { window_->RemoveObserver(this); } 525 ~VisibilityChangeObserver() override { window_->RemoveObserver(this); }
545 526
546 private: 527 private:
547 // Overridden from WindowObserver: 528 // Overridden from WindowObserver:
548 void OnWindowVisibilityChanged(Window* window, bool visible) override { 529 void OnWindowVisibilityChanged(aura::Window* window, bool visible) override {
549 EXPECT_EQ(window, window_); 530 EXPECT_EQ(window, window_);
550 EXPECT_TRUE(WindowServerTestBase::QuitRunLoop()); 531 EXPECT_TRUE(WindowServerTestBase::QuitRunLoop());
551 } 532 }
552 533
553 Window* window_; 534 aura::Window* window_;
554 535
555 DISALLOW_COPY_AND_ASSIGN(VisibilityChangeObserver); 536 DISALLOW_COPY_AND_ASSIGN(VisibilityChangeObserver);
556 }; 537 };
557 538
558 } // namespace 539 } // namespace
559 540
560 TEST_F(WindowServerTest, Visible) { 541 TEST_F(WindowServerTest, Visible) {
561 Window* window1 = window_manager()->NewWindow(); 542 aura::Window* window1 = NewVisibleWindow(GetFirstWMRoot(), window_manager());
562 window1->SetVisible(true);
563 GetFirstWMRoot()->AddChild(window1);
564 543
565 // Embed another app and verify initial state. 544 // Embed another app and verify initial state.
566 WindowTreeClient* embedded = Embed(window1).client; 545 std::unique_ptr<EmbedResult> embed_result = Embed(window_manager(), window1);
567 ASSERT_NE(nullptr, embedded); 546 ASSERT_TRUE(embed_result->IsValid());
568 ASSERT_NE(nullptr, GetFirstRoot(embedded)); 547 aura::Window* embedded_root = embed_result->window_tree_host->window();
msw 2016/12/08 01:20:11 ditto optional nit: name window_in_embedded like a
sky 2016/12/08 04:59:44 I went with embed_root every where, but I'm open t
569 Window* embedded_root = GetFirstRoot(embedded); 548 EXPECT_TRUE(embedded_root->TargetVisibility());
570 EXPECT_TRUE(embedded_root->visible()); 549 EXPECT_TRUE(embedded_root->IsVisible());
571 EXPECT_TRUE(embedded_root->IsDrawn());
572 550
573 // Change the visible state from the first client and verify its mirrored 551 // Change the visible state from the first client and verify its mirrored
574 // correctly to the embedded app. 552 // correctly to the embedded app.
575 { 553 {
576 VisibilityChangeObserver observer(embedded_root); 554 VisibilityChangeObserver observer(embedded_root);
577 window1->SetVisible(false); 555 window1->Hide();
578 ASSERT_TRUE(WindowServerTestBase::DoRunLoopWithTimeout()); 556 ASSERT_TRUE(WindowServerTestBase::DoRunLoopWithTimeout());
579 } 557 }
580 558
581 EXPECT_FALSE(window1->visible()); 559 EXPECT_FALSE(window1->TargetVisibility());
582 EXPECT_FALSE(window1->IsDrawn()); 560 EXPECT_FALSE(window1->IsVisible());
583 561
584 EXPECT_FALSE(embedded_root->visible()); 562 EXPECT_FALSE(embedded_root->TargetVisibility());
585 EXPECT_FALSE(embedded_root->IsDrawn()); 563 EXPECT_FALSE(embedded_root->IsVisible());
586 564
587 // Make the node visible again. 565 // Make the node visible again.
588 { 566 {
589 VisibilityChangeObserver observer(embedded_root); 567 VisibilityChangeObserver observer(embedded_root);
590 window1->SetVisible(true); 568 window1->Show();
591 ASSERT_TRUE(WindowServerTestBase::DoRunLoopWithTimeout()); 569 ASSERT_TRUE(WindowServerTestBase::DoRunLoopWithTimeout());
592 } 570 }
593 571
594 EXPECT_TRUE(window1->visible()); 572 EXPECT_TRUE(window1->TargetVisibility());
595 EXPECT_TRUE(window1->IsDrawn()); 573 EXPECT_TRUE(window1->IsVisible());
596 574
597 EXPECT_TRUE(embedded_root->visible()); 575 EXPECT_TRUE(embedded_root->TargetVisibility());
598 EXPECT_TRUE(embedded_root->IsDrawn()); 576 EXPECT_TRUE(embedded_root->IsVisible());
599 }
600
601 namespace {
602
603 class DrawnChangeObserver : public WindowObserver {
604 public:
605 explicit DrawnChangeObserver(Window* window) : window_(window) {
606 window_->AddObserver(this);
607 }
608 ~DrawnChangeObserver() override { window_->RemoveObserver(this); }
609
610 private:
611 // Overridden from WindowObserver:
612 void OnWindowDrawnChanged(Window* window) override {
613 EXPECT_EQ(window, window_);
614 EXPECT_TRUE(WindowServerTestBase::QuitRunLoop());
615 }
616
617 Window* window_;
618
619 DISALLOW_COPY_AND_ASSIGN(DrawnChangeObserver);
620 };
621
622 } // namespace
623
624 TEST_F(WindowServerTest, Drawn) {
625 Window* window1 = window_manager()->NewWindow();
626 window1->SetVisible(true);
627 GetFirstWMRoot()->AddChild(window1);
628
629 // Embed another app and verify initial state.
630 WindowTreeClient* embedded = Embed(window1).client;
631 ASSERT_NE(nullptr, embedded);
632 ASSERT_NE(nullptr, GetFirstRoot(embedded));
633 Window* embedded_root = GetFirstRoot(embedded);
634 EXPECT_TRUE(embedded_root->visible());
635 EXPECT_TRUE(embedded_root->IsDrawn());
636
637 // Change the visibility of the root, this should propagate a drawn state
638 // change to |embedded|.
639 {
640 DrawnChangeObserver observer(embedded_root);
641 GetFirstWMRoot()->SetVisible(false);
642 ASSERT_TRUE(DoRunLoopWithTimeout());
643 }
644
645 EXPECT_TRUE(window1->visible());
646 EXPECT_FALSE(window1->IsDrawn());
647
648 EXPECT_TRUE(embedded_root->visible());
649 EXPECT_FALSE(embedded_root->IsDrawn());
650 } 577 }
651 578
652 // TODO(beng): tests for window event dispatcher. 579 // TODO(beng): tests for window event dispatcher.
653 // - verify that we see events for all windows. 580 // - verify that we see events for all windows.
654 581
655 namespace { 582 TEST_F(WindowServerTest, EmbedFailsWithChildren) {
656 583 aura::Window* window1 = NewVisibleWindow(GetFirstWMRoot(), window_manager());
657 class FocusChangeObserver : public WindowObserver { 584 NewVisibleWindow(window1, window_manager());
msw 2016/12/08 01:20:11 nit: check the return value? name child or similar
sky 2016/12/08 04:59:45 I had it named, but the compiler complains as it i
658 public: 585 std::unique_ptr<EmbedResult> embed_result = Embed(window_manager(), window1);
659 explicit FocusChangeObserver(Window* window) 586 // Embed() should fail as |window1| has a child.
660 : window_(window), 587 EXPECT_FALSE(embed_result->IsValid());
661 last_gained_focus_(nullptr),
662 last_lost_focus_(nullptr),
663 quit_on_change_(true) {
664 window_->AddObserver(this);
665 }
666 ~FocusChangeObserver() override { window_->RemoveObserver(this); }
667
668 void set_quit_on_change(bool value) { quit_on_change_ = value; }
669
670 Window* last_gained_focus() { return last_gained_focus_; }
671
672 Window* last_lost_focus() { return last_lost_focus_; }
673
674 private:
675 // Overridden from WindowObserver.
676 void OnWindowFocusChanged(Window* gained_focus, Window* lost_focus) override {
677 EXPECT_TRUE(!gained_focus || gained_focus->HasFocus());
678 EXPECT_FALSE(lost_focus && lost_focus->HasFocus());
679 last_gained_focus_ = gained_focus;
680 last_lost_focus_ = lost_focus;
681 if (quit_on_change_)
682 EXPECT_TRUE(WindowServerTestBase::QuitRunLoop());
683 }
684
685 Window* window_;
686 Window* last_gained_focus_;
687 Window* last_lost_focus_;
688 bool quit_on_change_;
689
690 DISALLOW_COPY_AND_ASSIGN(FocusChangeObserver);
691 };
692
693 class NullFocusChangeObserver : public WindowTreeClientObserver {
694 public:
695 explicit NullFocusChangeObserver(WindowTreeClient* client)
696 : client_(client) {
697 client_->AddObserver(this);
698 }
699 ~NullFocusChangeObserver() override { client_->RemoveObserver(this); }
700
701 private:
702 // Overridden from WindowTreeClientObserver.
703 void OnWindowTreeFocusChanged(Window* gained_focus,
704 Window* lost_focus) override {
705 if (!gained_focus)
706 EXPECT_TRUE(WindowServerTestBase::QuitRunLoop());
707 }
708
709 WindowTreeClient* client_;
710
711 DISALLOW_COPY_AND_ASSIGN(NullFocusChangeObserver);
712 };
713
714 bool WaitForWindowToHaveFocus(Window* window) {
715 if (window->HasFocus())
716 return true;
717 FocusChangeObserver observer(window);
718 return WindowServerTestBase::DoRunLoopWithTimeout();
719 }
720
721 bool WaitForNoWindowToHaveFocus(WindowTreeClient* client) {
722 if (!client->GetFocusedWindow())
723 return true;
724 NullFocusChangeObserver observer(client);
725 return WindowServerTestBase::DoRunLoopWithTimeout();
726 }
727
728 } // namespace
729
730 TEST_F(WindowServerTest, Focus) {
731 Window* window1 = window_manager()->NewWindow();
732 window1->SetVisible(true);
733 GetFirstWMRoot()->AddChild(window1);
734
735 WindowTreeClient* embedded = Embed(window1).client;
736 ASSERT_NE(nullptr, embedded);
737 Window* window11 = embedded->NewWindow();
738 window11->SetVisible(true);
739 GetFirstRoot(embedded)->AddChild(window11);
740
741 {
742 // Focus the embed root in |embedded|.
743 Window* embedded_root = GetFirstRoot(embedded);
744 FocusChangeObserver observer(embedded_root);
745 observer.set_quit_on_change(false);
746 embedded_root->SetFocus();
747 ASSERT_TRUE(embedded_root->HasFocus());
748 ASSERT_NE(nullptr, observer.last_gained_focus());
749 EXPECT_EQ(server_id(embedded_root),
750 server_id(observer.last_gained_focus()));
751
752 // |embedded_root| is the same as |window1|, make sure |window1| got
753 // focus too.
754 ASSERT_TRUE(WaitForWindowToHaveFocus(window1));
755 }
756
757 // Focus a child of GetFirstRoot(embedded).
758 {
759 FocusChangeObserver observer(window11);
760 observer.set_quit_on_change(false);
761 window11->SetFocus();
762 ASSERT_TRUE(window11->HasFocus());
763 ASSERT_NE(nullptr, observer.last_gained_focus());
764 ASSERT_NE(nullptr, observer.last_lost_focus());
765 EXPECT_EQ(server_id(window11), server_id(observer.last_gained_focus()));
766 EXPECT_EQ(server_id(GetFirstRoot(embedded)),
767 server_id(observer.last_lost_focus()));
768 }
769
770 {
771 // Add an observer on the Window that loses focus, and make sure the
772 // observer sees the right values.
773 FocusChangeObserver observer(window11);
774 observer.set_quit_on_change(false);
775 GetFirstRoot(embedded)->SetFocus();
776 ASSERT_NE(nullptr, observer.last_gained_focus());
777 ASSERT_NE(nullptr, observer.last_lost_focus());
778 EXPECT_EQ(server_id(window11), server_id(observer.last_lost_focus()));
779 EXPECT_EQ(server_id(GetFirstRoot(embedded)),
780 server_id(observer.last_gained_focus()));
781 }
782 }
783
784 TEST_F(WindowServerTest, ClearFocus) {
785 Window* window1 = window_manager()->NewWindow();
786 window1->SetVisible(true);
787 GetFirstWMRoot()->AddChild(window1);
788
789 WindowTreeClient* embedded = Embed(window1).client;
790 ASSERT_NE(nullptr, embedded);
791 Window* window11 = embedded->NewWindow();
792 window11->SetVisible(true);
793 GetFirstRoot(embedded)->AddChild(window11);
794
795 // Focus the embed root in |embedded|.
796 Window* embedded_root = GetFirstRoot(embedded);
797 {
798 FocusChangeObserver observer(embedded_root);
799 observer.set_quit_on_change(false);
800 embedded_root->SetFocus();
801 ASSERT_TRUE(embedded_root->HasFocus());
802 ASSERT_NE(nullptr, observer.last_gained_focus());
803 EXPECT_EQ(server_id(embedded_root),
804 server_id(observer.last_gained_focus()));
805
806 // |embedded_root| is the same as |window1|, make sure |window1| got
807 // focus too.
808 ASSERT_TRUE(WaitForWindowToHaveFocus(window1));
809 }
810
811 {
812 FocusChangeObserver observer(window1);
813 embedded->ClearFocus();
814 ASSERT_FALSE(embedded_root->HasFocus());
815 EXPECT_FALSE(embedded->GetFocusedWindow());
816
817 ASSERT_TRUE(WindowServerTestBase::DoRunLoopWithTimeout());
818 EXPECT_FALSE(window1->HasFocus());
819 EXPECT_FALSE(window_manager()->GetFocusedWindow());
820 }
821 }
822
823 TEST_F(WindowServerTest, FocusNonFocusableWindow) {
824 Window* window = window_manager()->NewWindow();
825 window->SetVisible(true);
826 GetFirstWMRoot()->AddChild(window);
827
828 WindowTreeClient* client = Embed(window).client;
829 ASSERT_NE(nullptr, client);
830 ASSERT_FALSE(client->GetRoots().empty());
831 Window* client_window = *client->GetRoots().begin();
832 client_window->SetCanFocus(false);
833
834 client_window->SetFocus();
835 ASSERT_TRUE(client_window->HasFocus());
836
837 WaitForNoWindowToHaveFocus(client);
838 ASSERT_FALSE(client_window->HasFocus());
839 }
840
841 TEST_F(WindowServerTest, Activation) {
842 Window* parent = NewVisibleWindow(GetFirstWMRoot(), window_manager());
843
844 // Allow the child windows to be activated. Do this before we wait, that way
845 // we're guaranteed that when we request focus from a separate client the
846 // requests are processed in order.
847 window_manager_client()->AddActivationParent(parent);
848
849 Window* child1 = NewVisibleWindow(parent, window_manager());
850 Window* child2 = NewVisibleWindow(parent, window_manager());
851 Window* child3 = NewVisibleWindow(parent, window_manager());
852
853 child1->AddTransientWindow(child3);
854
855 WindowTreeClient* embedded1 = Embed(child1).client;
856 ASSERT_NE(nullptr, embedded1);
857 WindowTreeClient* embedded2 = Embed(child2).client;
858 ASSERT_NE(nullptr, embedded2);
859
860 Window* child11 = NewVisibleWindow(GetFirstRoot(embedded1), embedded1);
861 Window* child21 = NewVisibleWindow(GetFirstRoot(embedded2), embedded2);
862
863 WaitForTreeSizeToMatch(parent, 6);
864
865 EXPECT_EQ(0, ValidIndexOf(parent->children(), child1));
866 // NOTE: |child3| is after |child1| as |child3| is a transient child of
867 // |child1|.
868 EXPECT_EQ(1, ValidIndexOf(parent->children(), child3));
869 EXPECT_EQ(2, ValidIndexOf(parent->children(), child2));
870
871 // Set focus on |child11|, order of windows should not change.
872 child11->SetFocus();
873 ASSERT_TRUE(WaitForWindowToHaveFocus(child11));
874 ASSERT_TRUE(WaitForWindowToHaveFocus(
875 GetChildWindowByServerId(window_manager(), server_id(child11))));
876 EXPECT_EQ(server_id(child11),
877 server_id(window_manager()->GetFocusedWindow()));
878 EXPECT_EQ(server_id(child11), server_id(embedded1->GetFocusedWindow()));
879 EXPECT_EQ(nullptr, embedded2->GetFocusedWindow());
880 EXPECT_EQ(0, ValidIndexOf(parent->children(), child1));
881 EXPECT_EQ(1, ValidIndexOf(parent->children(), child3));
882 EXPECT_EQ(2, ValidIndexOf(parent->children(), child2));
883
884 // Set focus on |child21|. This should activate |child2|. Again, order should
885 // not change.
886 child21->SetFocus();
887 ASSERT_TRUE(WaitForWindowToHaveFocus(child21));
888 ASSERT_TRUE(WaitForWindowToHaveFocus(
889 GetChildWindowByServerId(window_manager(), server_id(child21))));
890 EXPECT_EQ(server_id(child21),
891 server_id(window_manager()->GetFocusedWindow()));
892 EXPECT_EQ(server_id(child21), server_id(embedded2->GetFocusedWindow()));
893 EXPECT_TRUE(WaitForNoWindowToHaveFocus(embedded1));
894 EXPECT_EQ(nullptr, embedded1->GetFocusedWindow());
895 EXPECT_EQ(0, ValidIndexOf(parent->children(), child1));
896 EXPECT_EQ(1, ValidIndexOf(parent->children(), child3));
897 EXPECT_EQ(2, ValidIndexOf(parent->children(), child2));
898 }
899
900 TEST_F(WindowServerTest, ActivationNext) {
901 Window* parent = GetFirstWMRoot();
902 Window* child1 = NewVisibleWindow(parent, window_manager());
903 Window* child2 = NewVisibleWindow(parent, window_manager());
904 Window* child3 = NewVisibleWindow(parent, window_manager());
905
906 WindowTreeClient* embedded1 = Embed(child1).client;
907 ASSERT_NE(nullptr, embedded1);
908 WindowTreeClient* embedded2 = Embed(child2).client;
909 ASSERT_NE(nullptr, embedded2);
910 WindowTreeClient* embedded3 = Embed(child3).client;
911 ASSERT_NE(nullptr, embedded3);
912
913 Window* child11 = NewVisibleWindow(GetFirstRoot(embedded1), embedded1);
914 Window* child21 = NewVisibleWindow(GetFirstRoot(embedded2), embedded2);
915 Window* child31 = NewVisibleWindow(GetFirstRoot(embedded3), embedded3);
916 WaitForTreeSizeToMatch(parent, 7);
917
918 Window* focused[] = { child31, child21, child11, child31, nullptr };
919 for (size_t index = 0; focused[index]; ++index) {
920 window_manager_client()->ActivateNextWindow();
921 WaitForWindowToHaveFocus(focused[index]);
922 EXPECT_TRUE(focused[index]->HasFocus());
923 }
924 } 588 }
925 589
926 namespace { 590 namespace {
927 591
928 class DestroyedChangedObserver : public WindowObserver { 592 class DestroyObserver : public aura::WindowObserver {
929 public: 593 public:
930 DestroyedChangedObserver(Window* window, bool* got_destroy) 594 DestroyObserver(aura::WindowTreeClient* client, bool* got_destroy)
931 : window_(window), got_destroy_(got_destroy) {
932 window_->AddObserver(this);
933 }
934 ~DestroyedChangedObserver() override {
935 if (window_)
936 window_->RemoveObserver(this);
937 }
938
939 private:
940 // Overridden from WindowObserver:
941 void OnWindowDestroyed(Window* window) override {
942 EXPECT_EQ(window, window_);
943 window_->RemoveObserver(this);
944 *got_destroy_ = true;
945 window_ = nullptr;
946 }
947
948 Window* window_;
949 bool* got_destroy_;
950
951 DISALLOW_COPY_AND_ASSIGN(DestroyedChangedObserver);
952 };
953
954 } // namespace
955
956 // Verifies deleting a WindowServer sends the right notifications.
957 TEST_F(WindowServerTest, DeleteWindowServer) {
958 Window* window = window_manager()->NewWindow();
959 ASSERT_NE(nullptr, window);
960 window->SetVisible(true);
961 GetFirstWMRoot()->AddChild(window);
962 WindowTreeClient* client = Embed(window).client;
963 ASSERT_TRUE(client);
964 bool got_destroy = false;
965 DestroyedChangedObserver observer(GetFirstRoot(client), &got_destroy);
966 DeleteWindowTreeClient(client);
967 EXPECT_TRUE(got_destroy);
968 }
969
970 class WindowRemovedFromParentObserver : public WindowObserver {
971 public:
972 explicit WindowRemovedFromParentObserver(Window* window)
973 : window_(window), was_removed_(false) {
974 window_->AddObserver(this);
975 }
976 ~WindowRemovedFromParentObserver() override { window_->RemoveObserver(this); }
977
978 bool was_removed() const { return was_removed_; }
979
980 private:
981 // Overridden from WindowObserver:
982 void OnTreeChanged(const TreeChangeParams& params) override {
983 if (params.target == window_ && !params.new_parent)
984 was_removed_ = true;
985 }
986
987 Window* window_;
988 bool was_removed_;
989
990 DISALLOW_COPY_AND_ASSIGN(WindowRemovedFromParentObserver);
991 };
992
993 TEST_F(WindowServerTest, EmbedRemovesChildren) {
994 Window* window1 = window_manager()->NewWindow();
995 Window* window2 = window_manager()->NewWindow();
996 GetFirstWMRoot()->AddChild(window1);
997 window1->AddChild(window2);
998
999 WindowRemovedFromParentObserver observer(window2);
1000 window1->Embed(ConnectAndGetWindowServerClient());
1001 EXPECT_TRUE(observer.was_removed());
1002 EXPECT_EQ(nullptr, window2->parent());
1003 EXPECT_TRUE(window1->children().empty());
1004
1005 // Run the message loop so the Embed() call above completes. Without this
1006 // we may end up reconnecting to the test and rerunning the test, which is
1007 // problematic since the other services don't shut down.
1008 ASSERT_TRUE(DoRunLoopWithTimeout());
1009 }
1010
1011 namespace {
1012
1013 class DestroyObserver : public WindowObserver {
1014 public:
1015 DestroyObserver(WindowTreeClient* client, bool* got_destroy)
1016 : got_destroy_(got_destroy) { 595 : got_destroy_(got_destroy) {
1017 GetFirstRoot(client)->AddObserver(this); 596 GetFirstRoot(client)->AddObserver(this);
1018 } 597 }
1019 ~DestroyObserver() override {} 598 ~DestroyObserver() override {}
1020 599
1021 private: 600 private:
1022 // Overridden from WindowObserver: 601 // Overridden from aura::WindowObserver:
1023 void OnWindowDestroyed(Window* window) override { 602 void OnWindowDestroyed(aura::Window* window) override {
1024 *got_destroy_ = true; 603 *got_destroy_ = true;
1025 window->RemoveObserver(this); 604 window->RemoveObserver(this);
1026 605
1027 EXPECT_TRUE(WindowServerTestBase::QuitRunLoop()); 606 EXPECT_TRUE(WindowServerTestBase::QuitRunLoop());
1028 } 607 }
1029 608
1030 bool* got_destroy_; 609 bool* got_destroy_;
1031 610
1032 DISALLOW_COPY_AND_ASSIGN(DestroyObserver); 611 DISALLOW_COPY_AND_ASSIGN(DestroyObserver);
1033 }; 612 };
1034 613
1035 } // namespace 614 } // namespace
1036 615
1037 // Verifies deleting a Window that is the root of another client notifies 616 // Verifies deleting a Window that is the root of another client notifies
1038 // observers in the right order (OnWindowDestroyed() before 617 // observers in the right order (OnWindowDestroyed() before
1039 // OnWindowManagerDestroyed()). 618 // OnWindowManagerDestroyed()).
1040 TEST_F(WindowServerTest, WindowServerDestroyedAfterRootObserver) { 619 TEST_F(WindowServerTest, WindowServerDestroyedAfterRootObserver) {
1041 Window* embed_window = window_manager()->NewWindow(); 620 aura::Window* embed_window =
msw 2016/12/08 01:20:11 nit: try to use consistent naming throughout
sky 2016/12/08 04:59:44 Done (hopefully).
1042 GetFirstWMRoot()->AddChild(embed_window); 621 NewVisibleWindow(GetFirstWMRoot(), window_manager());
1043 622
1044 WindowTreeClient* embedded_client = Embed(embed_window).client; 623 std::unique_ptr<EmbedResult> embed_result =
624 Embed(window_manager(), embed_window);
625 ASSERT_TRUE(embed_result->IsValid());
626 aura::WindowTreeClient* embedded_client =
627 embed_result->window_tree_client.get();
1045 628
1046 bool got_destroy = false; 629 bool got_destroy = false;
1047 DestroyObserver observer(embedded_client, &got_destroy); 630 DestroyObserver observer(embedded_client, &got_destroy);
1048 // Delete the window |embedded_client| is embedded in. This is async, 631 // Delete the window |embedded_client| is embedded in. |embedded_client| is
1049 // but will eventually trigger deleting |embedded_client|. 632 // asynchronously notified and cleans up.
1050 embed_window->Destroy(); 633 delete embed_window;
1051 EXPECT_TRUE(DoRunLoopWithTimeout()); 634 EXPECT_TRUE(DoRunLoopWithTimeout());
1052 EXPECT_TRUE(got_destroy); 635 ASSERT_TRUE(got_destroy);
636 // The WindowTreeHost was destroyed as well (by
637 // WindowServerTestBase::OnEmbedRootDestroyed()).
638 embed_result->window_tree_host.release();
639 EXPECT_EQ(0u, embed_result->window_tree_client->GetRoots().size());
1053 } 640 }
1054 641
1055 TEST_F(WindowServerTest, ClientAreaChanged) { 642 TEST_F(WindowServerTest, ClientAreaChanged) {
1056 Window* embed_window = window_manager()->NewWindow(); 643 aura::Window* embed_window =
1057 GetFirstWMRoot()->AddChild(embed_window); 644 NewVisibleWindow(GetFirstWMRoot(), window_manager());
1058 645
1059 WindowTreeClient* embedded_client = Embed(embed_window).client; 646 std::unique_ptr<EmbedResult> embed_result =
647 Embed(window_manager(), embed_window);
648 ASSERT_TRUE(embed_result->IsValid());
1060 649
1061 // Verify change from embedded makes it to parent. 650 // Verify change from embedded makes it to parent.
1062 GetFirstRoot(embedded_client)->SetClientArea(gfx::Insets(1, 2, 3, 4)); 651 const gfx::Insets insets(1, 2, 3, 4);
1063 ASSERT_TRUE(WaitForClientAreaToChange(embed_window)); 652 embed_result->window_tree_host->SetClientArea(insets);
1064 EXPECT_TRUE(gfx::Insets(1, 2, 3, 4) == embed_window->client_area()); 653 std::unique_ptr<ClientAreaChange> client_area_change =
1065 654 WaitForClientAreaToChange();
1066 // Changing bounds shouldn't effect client area. 655 ASSERT_TRUE(client_area_change);
1067 embed_window->SetBounds(gfx::Rect(21, 22, 23, 24)); 656 EXPECT_EQ(embed_window, client_area_change->window);
1068 WaitForBoundsToChange(GetFirstRoot(embedded_client)); 657 EXPECT_EQ(insets, client_area_change->insets);
1069 EXPECT_TRUE(gfx::Rect(21, 22, 23, 24) ==
1070 GetFirstRoot(embedded_client)->bounds());
1071 EXPECT_TRUE(gfx::Insets(1, 2, 3, 4) ==
1072 GetFirstRoot(embedded_client)->client_area());
1073 } 658 }
1074 659
1075 class EstablishConnectionViaFactoryDelegate : public TestWindowManagerDelegate { 660 class EstablishConnectionViaFactoryDelegate : public TestWindowManagerDelegate {
1076 public: 661 public:
1077 explicit EstablishConnectionViaFactoryDelegate( 662 explicit EstablishConnectionViaFactoryDelegate(aura::WindowTreeClient* client)
1078 WindowTreeClient* client)
1079 : client_(client), run_loop_(nullptr), created_window_(nullptr) {} 663 : client_(client), run_loop_(nullptr), created_window_(nullptr) {}
1080 ~EstablishConnectionViaFactoryDelegate() override {} 664 ~EstablishConnectionViaFactoryDelegate() override {}
1081 665
1082 bool QuitOnCreate() { 666 bool QuitOnCreate() {
1083 if (run_loop_) 667 if (run_loop_)
1084 return false; 668 return false;
1085 669
1086 created_window_ = nullptr; 670 created_window_ = nullptr;
1087 run_loop_ = base::MakeUnique<base::RunLoop>(); 671 run_loop_ = base::MakeUnique<base::RunLoop>();
1088 run_loop_->Run(); 672 run_loop_->Run();
1089 run_loop_.reset(); 673 run_loop_.reset();
1090 return created_window_ != nullptr; 674 return created_window_ != nullptr;
1091 } 675 }
1092 676
1093 Window* created_window() { return created_window_; } 677 aura::Window* created_window() { return created_window_; }
1094 678
1095 // WindowManagerDelegate: 679 // WindowManagerDelegate:
1096 Window* OnWmCreateTopLevelWindow( 680 aura::Window* OnWmCreateTopLevelWindow(
681 ui::mojom::WindowType window_type,
1097 std::map<std::string, std::vector<uint8_t>>* properties) override { 682 std::map<std::string, std::vector<uint8_t>>* properties) override {
1098 created_window_ = client_->NewWindow(properties); 683 created_window_ = NewVisibleWindow((*client_->GetRoots().begin()), client_);
1099 (*client_->GetRoots().begin())->AddChild(created_window_);
1100 if (run_loop_) 684 if (run_loop_)
1101 run_loop_->Quit(); 685 run_loop_->Quit();
1102 return created_window_; 686 return created_window_;
1103 } 687 }
1104 688
1105 private: 689 private:
1106 WindowTreeClient* client_; 690 aura::WindowTreeClient* client_;
1107 std::unique_ptr<base::RunLoop> run_loop_; 691 std::unique_ptr<base::RunLoop> run_loop_;
1108 Window* created_window_; 692 aura::Window* created_window_;
1109 693
1110 DISALLOW_COPY_AND_ASSIGN(EstablishConnectionViaFactoryDelegate); 694 DISALLOW_COPY_AND_ASSIGN(EstablishConnectionViaFactoryDelegate);
1111 }; 695 };
1112 696
1113 TEST_F(WindowServerTest, EstablishConnectionViaFactory) { 697 TEST_F(WindowServerTest, EstablishConnectionViaFactory) {
1114 EstablishConnectionViaFactoryDelegate delegate(window_manager()); 698 EstablishConnectionViaFactoryDelegate delegate(window_manager());
1115 set_window_manager_delegate(&delegate); 699 set_window_manager_delegate(&delegate);
1116 WindowTreeClient second_client(this, nullptr, nullptr); 700 aura::WindowTreeClient second_client(connector(), this);
1117 second_client.ConnectViaWindowTreeFactory(connector()); 701 second_client.ConnectViaWindowTreeFactory();
1118 Window* window_in_second_client = second_client.NewTopLevelWindow(nullptr); 702 aura::WindowTreeHostMus window_tree_host_in_second_client(&second_client);
1119 ASSERT_TRUE(window_in_second_client); 703 ASSERT_TRUE(second_client.GetRoots().count(
1120 ASSERT_TRUE(second_client.GetRoots().count(window_in_second_client) > 0); 704 window_tree_host_in_second_client.window()) > 0);
1121 // Wait for the window to appear in the wm. 705 // Wait for the window to appear in the wm.
1122 ASSERT_TRUE(delegate.QuitOnCreate()); 706 ASSERT_TRUE(delegate.QuitOnCreate());
1123 707
1124 Window* window_in_wm = delegate.created_window(); 708 aura::Window* window_in_wm = delegate.created_window();
1125 ASSERT_TRUE(window_in_wm); 709 ASSERT_TRUE(window_in_wm);
1126 710
1127 // Change the bounds in the wm, and make sure the child sees it. 711 // Change the bounds in the wm, and make sure the child sees it.
1128 window_in_wm->SetBounds(gfx::Rect(1, 11, 12, 101)); 712 const gfx::Rect window_bounds(1, 11, 12, 101);
1129 ASSERT_TRUE(WaitForBoundsToChange(window_in_second_client)); 713 window_in_wm->SetBounds(window_bounds);
1130 EXPECT_EQ(gfx::Rect(1, 11, 12, 101), window_in_second_client->bounds()); 714 ASSERT_TRUE(
715 WaitForBoundsToChange(window_tree_host_in_second_client.window()));
716 EXPECT_EQ(window_bounds,
717 window_tree_host_in_second_client.GetBoundsInPixels());
1131 } 718 }
1132 719
1133 } // namespace ws 720 } // namespace ws
1134 } // namespace ui 721 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698