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

Side by Side Diff: components/mus/public/cpp/tests/window_tree_client_unittest.cc

Issue 2018823002: Eliminate WindowTreeConnection (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@connection
Patch Set: . 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "components/mus/public/cpp/lib/window_tree_client_impl.h" 5 #include "components/mus/public/cpp/window_tree_client.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
11 #include "components/mus/common/util.h" 11 #include "components/mus/common/util.h"
12 #include "components/mus/public/cpp/input_event_handler.h" 12 #include "components/mus/public/cpp/input_event_handler.h"
13 #include "components/mus/public/cpp/lib/window_private.h" 13 #include "components/mus/public/cpp/lib/window_private.h"
14 #include "components/mus/public/cpp/property_type_converters.h" 14 #include "components/mus/public/cpp/property_type_converters.h"
15 #include "components/mus/public/cpp/tests/test_window.h" 15 #include "components/mus/public/cpp/tests/test_window.h"
16 #include "components/mus/public/cpp/tests/test_window_tree.h" 16 #include "components/mus/public/cpp/tests/test_window_tree.h"
17 #include "components/mus/public/cpp/tests/window_tree_client_impl_private.h" 17 #include "components/mus/public/cpp/tests/window_tree_client_private.h"
18 #include "components/mus/public/cpp/window.h" 18 #include "components/mus/public/cpp/window.h"
19 #include "components/mus/public/cpp/window_observer.h" 19 #include "components/mus/public/cpp/window_observer.h"
20 #include "components/mus/public/cpp/window_property.h" 20 #include "components/mus/public/cpp/window_property.h"
21 #include "components/mus/public/cpp/window_tracker.h" 21 #include "components/mus/public/cpp/window_tracker.h"
22 #include "components/mus/public/cpp/window_tree_delegate.h" 22 #include "components/mus/public/cpp/window_tree_client_delegate.h"
23 #include "mojo/common/common_type_converters.h" 23 #include "mojo/common/common_type_converters.h"
24 #include "testing/gtest/include/gtest/gtest.h" 24 #include "testing/gtest/include/gtest/gtest.h"
25 #include "ui/events/event.h" 25 #include "ui/events/event.h"
26 #include "ui/events/event_utils.h" 26 #include "ui/events/event_utils.h"
27 #include "ui/events/mojo/input_events_type_converters.h" 27 #include "ui/events/mojo/input_events_type_converters.h"
28 #include "ui/gfx/geometry/mojo/geometry_type_converters.h" 28 #include "ui/gfx/geometry/mojo/geometry_type_converters.h"
29 #include "ui/gfx/geometry/rect.h" 29 #include "ui/gfx/geometry/rect.h"
30 30
31 namespace mus { 31 namespace mus {
32 32
33 namespace { 33 namespace {
34 34
35 void DoNothingWithEventResult(mojom::EventResult result) {} 35 void DoNothingWithEventResult(mojom::EventResult result) {}
36 36
37 Id server_id(mus::Window* window) { 37 Id server_id(mus::Window* window) {
38 return WindowPrivate(window).server_id(); 38 return WindowPrivate(window).server_id();
39 } 39 }
40 40
41 } // namespace 41 } // namespace
42 42
43 mojo::Array<uint8_t> Int32ToPropertyTransportValue(int32_t value) { 43 mojo::Array<uint8_t> Int32ToPropertyTransportValue(int32_t value) {
44 const std::vector<uint8_t> bytes = 44 const std::vector<uint8_t> bytes =
45 mojo::ConvertTo<std::vector<uint8_t>>(value); 45 mojo::ConvertTo<std::vector<uint8_t>>(value);
46 mojo::Array<uint8_t> transport_value; 46 mojo::Array<uint8_t> transport_value;
47 transport_value.resize(bytes.size()); 47 transport_value.resize(bytes.size());
48 memcpy(&transport_value.front(), &(bytes.front()), bytes.size()); 48 memcpy(&transport_value.front(), &(bytes.front()), bytes.size());
49 return transport_value; 49 return transport_value;
50 } 50 }
51 51
52 class TestWindowTreeDelegate : public WindowTreeDelegate { 52 class TestWindowTreeClientDelegate : public WindowTreeClientDelegate {
53 public: 53 public:
54 TestWindowTreeDelegate() {} 54 TestWindowTreeClientDelegate() {}
55 ~TestWindowTreeDelegate() override {} 55 ~TestWindowTreeClientDelegate() override {}
56 56
57 ui::Event* last_event_observed() { return last_event_observed_.get(); } 57 ui::Event* last_event_observed() { return last_event_observed_.get(); }
58 58
59 void Reset() { last_event_observed_.reset(); } 59 void Reset() { last_event_observed_.reset(); }
60 60
61 // WindowTreeDelegate: 61 // WindowTreeClientDelegate:
62 void OnEmbed(Window* root) override {} 62 void OnEmbed(Window* root) override {}
63 void OnConnectionLost(WindowTreeConnection* connection) override {} 63 void OnWindowTreeClientDestroyed(WindowTreeClient* client) override {}
64 void OnEventObserved(const ui::Event& event, Window* target) override { 64 void OnEventObserved(const ui::Event& event, Window* target) override {
65 last_event_observed_ = ui::Event::Clone(event); 65 last_event_observed_ = ui::Event::Clone(event);
66 } 66 }
67 67
68 private: 68 private:
69 std::unique_ptr<ui::Event> last_event_observed_; 69 std::unique_ptr<ui::Event> last_event_observed_;
70 70
71 DISALLOW_COPY_AND_ASSIGN(TestWindowTreeDelegate); 71 DISALLOW_COPY_AND_ASSIGN(TestWindowTreeClientDelegate);
72 }; 72 };
73 73
74 class WindowTreeSetup { 74 class WindowTreeSetup {
75 public: 75 public:
76 WindowTreeSetup() : tree_client_(&window_tree_delegate_, nullptr, nullptr) { 76 WindowTreeSetup() : tree_client_(&window_tree_delegate_, nullptr, nullptr) {
77 WindowTreeClientImplPrivate(&tree_client_).OnEmbed(&window_tree_); 77 WindowTreeClientPrivate(&tree_client_).OnEmbed(&window_tree_);
78 window_tree_.GetAndClearChangeId(nullptr); 78 window_tree_.GetAndClearChangeId(nullptr);
79 } 79 }
80 80
81 WindowTreeConnection* window_tree_connection() { 81 WindowTreeClient* client() {
82 return static_cast<WindowTreeConnection*>(&tree_client_); 82 return &tree_client_;
83 } 83 }
84 84
85 mojom::WindowTreeClient* window_tree_client() { 85 mojom::WindowTreeClient* window_tree_client() {
86 return static_cast<mojom::WindowTreeClient*>(&tree_client_); 86 return static_cast<mojom::WindowTreeClient*>(&tree_client_);
87 } 87 }
88 88
89 TestWindowTree* window_tree() { return &window_tree_; } 89 TestWindowTree* window_tree() { return &window_tree_; }
90 90
91 TestWindowTreeDelegate* window_tree_delegate() { 91 TestWindowTreeClientDelegate* window_tree_delegate() {
92 return &window_tree_delegate_; 92 return &window_tree_delegate_;
93 } 93 }
94 94
95 Window* GetFirstRoot() { 95 Window* GetFirstRoot() {
96 return window_tree_connection()->GetRoots().empty() 96 return client()->GetRoots().empty() ? nullptr
97 ? nullptr 97 : *client()->GetRoots().begin();
98 : *window_tree_connection()->GetRoots().begin();
99 } 98 }
100 99
101 uint32_t GetEventObserverId() { 100 uint32_t GetEventObserverId() {
102 return WindowTreeClientImplPrivate(&tree_client_).event_observer_id(); 101 return WindowTreeClientPrivate(&tree_client_).event_observer_id();
103 } 102 }
104 103
105 private: 104 private:
106 TestWindowTree window_tree_; 105 TestWindowTree window_tree_;
107 TestWindowTreeDelegate window_tree_delegate_; 106 TestWindowTreeClientDelegate window_tree_delegate_;
108 WindowTreeClientImpl tree_client_; 107 WindowTreeClient tree_client_;
109 108
110 DISALLOW_COPY_AND_ASSIGN(WindowTreeSetup); 109 DISALLOW_COPY_AND_ASSIGN(WindowTreeSetup);
111 }; 110 };
112 111
113 class TestInputEventHandler : public InputEventHandler { 112 class TestInputEventHandler : public InputEventHandler {
114 public: 113 public:
115 TestInputEventHandler() 114 TestInputEventHandler()
116 : received_event_(false), should_manually_ack_(false) {} 115 : received_event_(false), should_manually_ack_(false) {}
117 ~TestInputEventHandler() override {} 116 ~TestInputEventHandler() override {}
118 117
(...skipping 28 matching lines...) Expand all
147 } 146 }
148 } 147 }
149 148
150 bool received_event_; 149 bool received_event_;
151 bool should_manually_ack_; 150 bool should_manually_ack_;
152 base::Callback<void(mojom::EventResult)> ack_callback_; 151 base::Callback<void(mojom::EventResult)> ack_callback_;
153 152
154 DISALLOW_COPY_AND_ASSIGN(TestInputEventHandler); 153 DISALLOW_COPY_AND_ASSIGN(TestInputEventHandler);
155 }; 154 };
156 155
157 using WindowTreeClientImplTest = testing::Test; 156 using WindowTreeClientTest = testing::Test;
158 157
159 // Verifies bounds are reverted if the server replied that the change failed. 158 // Verifies bounds are reverted if the server replied that the change failed.
160 TEST_F(WindowTreeClientImplTest, SetBoundsFailed) { 159 TEST_F(WindowTreeClientTest, SetBoundsFailed) {
161 WindowTreeSetup setup; 160 WindowTreeSetup setup;
162 Window* root = setup.GetFirstRoot(); 161 Window* root = setup.GetFirstRoot();
163 ASSERT_TRUE(root); 162 ASSERT_TRUE(root);
164 const gfx::Rect original_bounds(root->bounds()); 163 const gfx::Rect original_bounds(root->bounds());
165 const gfx::Rect new_bounds(gfx::Rect(0, 0, 100, 100)); 164 const gfx::Rect new_bounds(gfx::Rect(0, 0, 100, 100));
166 ASSERT_NE(new_bounds, root->bounds()); 165 ASSERT_NE(new_bounds, root->bounds());
167 root->SetBounds(new_bounds); 166 root->SetBounds(new_bounds);
168 uint32_t change_id; 167 uint32_t change_id;
169 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id)); 168 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id));
170 setup.window_tree_client()->OnChangeCompleted(change_id, false); 169 setup.window_tree_client()->OnChangeCompleted(change_id, false);
171 EXPECT_EQ(original_bounds, root->bounds()); 170 EXPECT_EQ(original_bounds, root->bounds());
172 } 171 }
173 172
174 // Simulates a bounds change, and while the bounds change is in flight the 173 // Simulates a bounds change, and while the bounds change is in flight the
175 // server replies with a new bounds and the original bounds change fails. 174 // server replies with a new bounds and the original bounds change fails.
176 TEST_F(WindowTreeClientImplTest, SetBoundsFailedWithPendingChange) { 175 TEST_F(WindowTreeClientTest, SetBoundsFailedWithPendingChange) {
177 WindowTreeSetup setup; 176 WindowTreeSetup setup;
178 Window* root = setup.GetFirstRoot(); 177 Window* root = setup.GetFirstRoot();
179 ASSERT_TRUE(root); 178 ASSERT_TRUE(root);
180 const gfx::Rect original_bounds(root->bounds()); 179 const gfx::Rect original_bounds(root->bounds());
181 const gfx::Rect new_bounds(gfx::Rect(0, 0, 100, 100)); 180 const gfx::Rect new_bounds(gfx::Rect(0, 0, 100, 100));
182 ASSERT_NE(new_bounds, root->bounds()); 181 ASSERT_NE(new_bounds, root->bounds());
183 root->SetBounds(new_bounds); 182 root->SetBounds(new_bounds);
184 EXPECT_EQ(new_bounds, root->bounds()); 183 EXPECT_EQ(new_bounds, root->bounds());
185 uint32_t change_id; 184 uint32_t change_id;
186 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id)); 185 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id));
(...skipping 12 matching lines...) Expand all
199 setup.window_tree_client()->OnChangeCompleted(change_id, false); 198 setup.window_tree_client()->OnChangeCompleted(change_id, false);
200 EXPECT_EQ(server_changed_bounds, root->bounds()); 199 EXPECT_EQ(server_changed_bounds, root->bounds());
201 200
202 // Simulate server changing back to original bounds. Should take immediately. 201 // Simulate server changing back to original bounds. Should take immediately.
203 setup.window_tree_client()->OnWindowBoundsChanged( 202 setup.window_tree_client()->OnWindowBoundsChanged(
204 server_id(root), mojo::Rect::From(server_changed_bounds), 203 server_id(root), mojo::Rect::From(server_changed_bounds),
205 mojo::Rect::From(original_bounds)); 204 mojo::Rect::From(original_bounds));
206 EXPECT_EQ(original_bounds, root->bounds()); 205 EXPECT_EQ(original_bounds, root->bounds());
207 } 206 }
208 207
209 TEST_F(WindowTreeClientImplTest, TwoInFlightBoundsChangesBothCanceled) { 208 TEST_F(WindowTreeClientTest, TwoInFlightBoundsChangesBothCanceled) {
210 WindowTreeSetup setup; 209 WindowTreeSetup setup;
211 Window* root = setup.GetFirstRoot(); 210 Window* root = setup.GetFirstRoot();
212 ASSERT_TRUE(root); 211 ASSERT_TRUE(root);
213 const gfx::Rect original_bounds(root->bounds()); 212 const gfx::Rect original_bounds(root->bounds());
214 const gfx::Rect bounds1(gfx::Rect(0, 0, 100, 100)); 213 const gfx::Rect bounds1(gfx::Rect(0, 0, 100, 100));
215 const gfx::Rect bounds2(gfx::Rect(0, 0, 100, 102)); 214 const gfx::Rect bounds2(gfx::Rect(0, 0, 100, 102));
216 root->SetBounds(bounds1); 215 root->SetBounds(bounds1);
217 EXPECT_EQ(bounds1, root->bounds()); 216 EXPECT_EQ(bounds1, root->bounds());
218 uint32_t change_id1; 217 uint32_t change_id1;
219 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id1)); 218 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id1));
220 219
221 root->SetBounds(bounds2); 220 root->SetBounds(bounds2);
222 EXPECT_EQ(bounds2, root->bounds()); 221 EXPECT_EQ(bounds2, root->bounds());
223 uint32_t change_id2; 222 uint32_t change_id2;
224 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id2)); 223 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id2));
225 224
226 // Tell the client change 1 failed. As there is a still a change in flight 225 // Tell the client change 1 failed. As there is a still a change in flight
227 // nothing should happen. 226 // nothing should happen.
228 setup.window_tree_client()->OnChangeCompleted(change_id1, false); 227 setup.window_tree_client()->OnChangeCompleted(change_id1, false);
229 EXPECT_EQ(bounds2, root->bounds()); 228 EXPECT_EQ(bounds2, root->bounds());
230 229
231 // And tell the client change 2 failed too. Should now fallback to original 230 // And tell the client change 2 failed too. Should now fallback to original
232 // bounds. 231 // bounds.
233 setup.window_tree_client()->OnChangeCompleted(change_id2, false); 232 setup.window_tree_client()->OnChangeCompleted(change_id2, false);
234 EXPECT_EQ(original_bounds, root->bounds()); 233 EXPECT_EQ(original_bounds, root->bounds());
235 } 234 }
236 235
237 // Verifies properties are reverted if the server replied that the change 236 // Verifies properties are reverted if the server replied that the change
238 // failed. 237 // failed.
239 TEST_F(WindowTreeClientImplTest, SetPropertyFailed) { 238 TEST_F(WindowTreeClientTest, SetPropertyFailed) {
240 WindowTreeSetup setup; 239 WindowTreeSetup setup;
241 Window* root = setup.GetFirstRoot(); 240 Window* root = setup.GetFirstRoot();
242 ASSERT_TRUE(root); 241 ASSERT_TRUE(root);
243 ASSERT_FALSE(root->HasSharedProperty("foo")); 242 ASSERT_FALSE(root->HasSharedProperty("foo"));
244 const int32_t new_value = 11; 243 const int32_t new_value = 11;
245 root->SetSharedProperty("foo", new_value); 244 root->SetSharedProperty("foo", new_value);
246 ASSERT_TRUE(root->HasSharedProperty("foo")); 245 ASSERT_TRUE(root->HasSharedProperty("foo"));
247 EXPECT_EQ(new_value, root->GetSharedProperty<int32_t>("foo")); 246 EXPECT_EQ(new_value, root->GetSharedProperty<int32_t>("foo"));
248 uint32_t change_id; 247 uint32_t change_id;
249 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id)); 248 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id));
250 setup.window_tree_client()->OnChangeCompleted(change_id, false); 249 setup.window_tree_client()->OnChangeCompleted(change_id, false);
251 EXPECT_FALSE(root->HasSharedProperty("foo")); 250 EXPECT_FALSE(root->HasSharedProperty("foo"));
252 } 251 }
253 252
254 // Simulates a property change, and while the property change is in flight the 253 // Simulates a property change, and while the property change is in flight the
255 // server replies with a new property and the original property change fails. 254 // server replies with a new property and the original property change fails.
256 TEST_F(WindowTreeClientImplTest, SetPropertyFailedWithPendingChange) { 255 TEST_F(WindowTreeClientTest, SetPropertyFailedWithPendingChange) {
257 WindowTreeSetup setup; 256 WindowTreeSetup setup;
258 Window* root = setup.GetFirstRoot(); 257 Window* root = setup.GetFirstRoot();
259 ASSERT_TRUE(root); 258 ASSERT_TRUE(root);
260 const int32_t value1 = 11; 259 const int32_t value1 = 11;
261 root->SetSharedProperty("foo", value1); 260 root->SetSharedProperty("foo", value1);
262 ASSERT_TRUE(root->HasSharedProperty("foo")); 261 ASSERT_TRUE(root->HasSharedProperty("foo"));
263 EXPECT_EQ(value1, root->GetSharedProperty<int32_t>("foo")); 262 EXPECT_EQ(value1, root->GetSharedProperty<int32_t>("foo"));
264 uint32_t change_id; 263 uint32_t change_id;
265 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id)); 264 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id));
266 265
(...skipping 13 matching lines...) Expand all
280 EXPECT_EQ(server_value, root->GetSharedProperty<int32_t>("foo")); 279 EXPECT_EQ(server_value, root->GetSharedProperty<int32_t>("foo"));
281 280
282 // Simulate server changing back to value1. Should take immediately. 281 // Simulate server changing back to value1. Should take immediately.
283 setup.window_tree_client()->OnWindowSharedPropertyChanged( 282 setup.window_tree_client()->OnWindowSharedPropertyChanged(
284 server_id(root), "foo", Int32ToPropertyTransportValue(value1)); 283 server_id(root), "foo", Int32ToPropertyTransportValue(value1));
285 ASSERT_TRUE(root->HasSharedProperty("foo")); 284 ASSERT_TRUE(root->HasSharedProperty("foo"));
286 EXPECT_EQ(value1, root->GetSharedProperty<int32_t>("foo")); 285 EXPECT_EQ(value1, root->GetSharedProperty<int32_t>("foo"));
287 } 286 }
288 287
289 // Verifies visible is reverted if the server replied that the change failed. 288 // Verifies visible is reverted if the server replied that the change failed.
290 TEST_F(WindowTreeClientImplTest, SetVisibleFailed) { 289 TEST_F(WindowTreeClientTest, SetVisibleFailed) {
291 WindowTreeSetup setup; 290 WindowTreeSetup setup;
292 Window* root = setup.GetFirstRoot(); 291 Window* root = setup.GetFirstRoot();
293 ASSERT_TRUE(root); 292 ASSERT_TRUE(root);
294 const bool original_visible = root->visible(); 293 const bool original_visible = root->visible();
295 const bool new_visible = !original_visible; 294 const bool new_visible = !original_visible;
296 ASSERT_NE(new_visible, root->visible()); 295 ASSERT_NE(new_visible, root->visible());
297 root->SetVisible(new_visible); 296 root->SetVisible(new_visible);
298 uint32_t change_id; 297 uint32_t change_id;
299 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id)); 298 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id));
300 setup.window_tree_client()->OnChangeCompleted(change_id, false); 299 setup.window_tree_client()->OnChangeCompleted(change_id, false);
301 EXPECT_EQ(original_visible, root->visible()); 300 EXPECT_EQ(original_visible, root->visible());
302 } 301 }
303 302
304 // Simulates a visible change, and while the visible change is in flight the 303 // Simulates a visible change, and while the visible change is in flight the
305 // server replies with a new visible and the original visible change fails. 304 // server replies with a new visible and the original visible change fails.
306 TEST_F(WindowTreeClientImplTest, SetVisibleFailedWithPendingChange) { 305 TEST_F(WindowTreeClientTest, SetVisibleFailedWithPendingChange) {
307 WindowTreeSetup setup; 306 WindowTreeSetup setup;
308 Window* root = setup.GetFirstRoot(); 307 Window* root = setup.GetFirstRoot();
309 ASSERT_TRUE(root); 308 ASSERT_TRUE(root);
310 const bool original_visible = root->visible(); 309 const bool original_visible = root->visible();
311 const bool new_visible = !original_visible; 310 const bool new_visible = !original_visible;
312 ASSERT_NE(new_visible, root->visible()); 311 ASSERT_NE(new_visible, root->visible());
313 root->SetVisible(new_visible); 312 root->SetVisible(new_visible);
314 EXPECT_EQ(new_visible, root->visible()); 313 EXPECT_EQ(new_visible, root->visible());
315 uint32_t change_id; 314 uint32_t change_id;
316 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id)); 315 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id));
(...skipping 12 matching lines...) Expand all
329 EXPECT_EQ(server_changed_visible, root->visible()); 328 EXPECT_EQ(server_changed_visible, root->visible());
330 329
331 // Simulate server changing back to original visible. Should take immediately. 330 // Simulate server changing back to original visible. Should take immediately.
332 setup.window_tree_client()->OnWindowVisibilityChanged(server_id(root), 331 setup.window_tree_client()->OnWindowVisibilityChanged(server_id(root),
333 original_visible); 332 original_visible);
334 EXPECT_EQ(original_visible, root->visible()); 333 EXPECT_EQ(original_visible, root->visible());
335 } 334 }
336 335
337 // Verifies that local opacity is not changed if the server replied that the 336 // Verifies that local opacity is not changed if the server replied that the
338 // change succeeded. 337 // change succeeded.
339 TEST_F(WindowTreeClientImplTest, SetOpacitySucceeds) { 338 TEST_F(WindowTreeClientTest, SetOpacitySucceeds) {
340 WindowTreeSetup setup; 339 WindowTreeSetup setup;
341 Window* root = setup.GetFirstRoot(); 340 Window* root = setup.GetFirstRoot();
342 ASSERT_TRUE(root); 341 ASSERT_TRUE(root);
343 const float original_opacity = root->opacity(); 342 const float original_opacity = root->opacity();
344 const float new_opacity = 0.5f; 343 const float new_opacity = 0.5f;
345 ASSERT_NE(new_opacity, original_opacity); 344 ASSERT_NE(new_opacity, original_opacity);
346 ASSERT_NE(new_opacity, root->opacity()); 345 ASSERT_NE(new_opacity, root->opacity());
347 root->SetOpacity(new_opacity); 346 root->SetOpacity(new_opacity);
348 uint32_t change_id; 347 uint32_t change_id;
349 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id)); 348 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id));
350 setup.window_tree_client()->OnChangeCompleted(change_id, true); 349 setup.window_tree_client()->OnChangeCompleted(change_id, true);
351 EXPECT_EQ(new_opacity, root->opacity()); 350 EXPECT_EQ(new_opacity, root->opacity());
352 } 351 }
353 352
354 // Verifies that opacity is reverted if the server replied that the change 353 // Verifies that opacity is reverted if the server replied that the change
355 // failed. 354 // failed.
356 TEST_F(WindowTreeClientImplTest, SetOpacityFailed) { 355 TEST_F(WindowTreeClientTest, SetOpacityFailed) {
357 WindowTreeSetup setup; 356 WindowTreeSetup setup;
358 Window* root = setup.GetFirstRoot(); 357 Window* root = setup.GetFirstRoot();
359 ASSERT_TRUE(root); 358 ASSERT_TRUE(root);
360 const float original_opacity = root->opacity(); 359 const float original_opacity = root->opacity();
361 const float new_opacity = 0.5f; 360 const float new_opacity = 0.5f;
362 ASSERT_NE(new_opacity, root->opacity()); 361 ASSERT_NE(new_opacity, root->opacity());
363 root->SetOpacity(new_opacity); 362 root->SetOpacity(new_opacity);
364 uint32_t change_id; 363 uint32_t change_id;
365 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id)); 364 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id));
366 setup.window_tree_client()->OnChangeCompleted(change_id, false); 365 setup.window_tree_client()->OnChangeCompleted(change_id, false);
367 EXPECT_EQ(original_opacity, root->opacity()); 366 EXPECT_EQ(original_opacity, root->opacity());
368 } 367 }
369 368
370 // Simulates the server changing the opacitry while there is an opacity change 369 // Simulates the server changing the opacitry while there is an opacity change
371 // in flight, causing the requested change to fail. 370 // in flight, causing the requested change to fail.
372 TEST_F(WindowTreeClientImplTest, SetOpacityFailedWithPendingChange) { 371 TEST_F(WindowTreeClientTest, SetOpacityFailedWithPendingChange) {
373 WindowTreeSetup setup; 372 WindowTreeSetup setup;
374 Window* root = setup.GetFirstRoot(); 373 Window* root = setup.GetFirstRoot();
375 ASSERT_TRUE(root); 374 ASSERT_TRUE(root);
376 const float original_opacity = root->opacity(); 375 const float original_opacity = root->opacity();
377 const float new_opacity = 0.5f; 376 const float new_opacity = 0.5f;
378 ASSERT_NE(new_opacity, root->opacity()); 377 ASSERT_NE(new_opacity, root->opacity());
379 root->SetOpacity(new_opacity); 378 root->SetOpacity(new_opacity);
380 EXPECT_EQ(new_opacity, root->opacity()); 379 EXPECT_EQ(new_opacity, root->opacity());
381 uint32_t change_id; 380 uint32_t change_id;
382 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id)); 381 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id));
(...skipping 12 matching lines...) Expand all
395 EXPECT_EQ(server_changed_opacity, root->opacity()); 394 EXPECT_EQ(server_changed_opacity, root->opacity());
396 395
397 // Simulate server changing back to original opacity. Should take immediately. 396 // Simulate server changing back to original opacity. Should take immediately.
398 setup.window_tree_client()->OnWindowOpacityChanged( 397 setup.window_tree_client()->OnWindowOpacityChanged(
399 server_id(root), server_changed_opacity, original_opacity); 398 server_id(root), server_changed_opacity, original_opacity);
400 EXPECT_EQ(original_opacity, root->opacity()); 399 EXPECT_EQ(original_opacity, root->opacity());
401 } 400 }
402 401
403 // Tests that when there are multiple changes in flight, that failing changes 402 // Tests that when there are multiple changes in flight, that failing changes
404 // update the revert state of subsequent changes. 403 // update the revert state of subsequent changes.
405 TEST_F(WindowTreeClientImplTest, SetOpacityFailedWithMultiplePendingChange) { 404 TEST_F(WindowTreeClientTest, SetOpacityFailedWithMultiplePendingChange) {
406 WindowTreeSetup setup; 405 WindowTreeSetup setup;
407 Window* root = setup.GetFirstRoot(); 406 Window* root = setup.GetFirstRoot();
408 ASSERT_TRUE(root); 407 ASSERT_TRUE(root);
409 const float original_opacity = root->opacity(); 408 const float original_opacity = root->opacity();
410 const float new_opacity = 0.5f; 409 const float new_opacity = 0.5f;
411 ASSERT_NE(new_opacity, root->opacity()); 410 ASSERT_NE(new_opacity, root->opacity());
412 root->SetOpacity(new_opacity); 411 root->SetOpacity(new_opacity);
413 uint32_t change_id1; 412 uint32_t change_id1;
414 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id1)); 413 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id1));
415 414
416 const float second_new_opacity = 0.75f; 415 const float second_new_opacity = 0.75f;
417 ASSERT_NE(second_new_opacity, root->opacity()); 416 ASSERT_NE(second_new_opacity, root->opacity());
418 root->SetOpacity(second_new_opacity); 417 root->SetOpacity(second_new_opacity);
419 uint32_t change_id2; 418 uint32_t change_id2;
420 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id2)); 419 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id2));
421 420
422 // Canceling the first one, while there is another in flight, should not 421 // Canceling the first one, while there is another in flight, should not
423 // change the local opacity. 422 // change the local opacity.
424 setup.window_tree_client()->OnChangeCompleted(change_id1, false); 423 setup.window_tree_client()->OnChangeCompleted(change_id1, false);
425 EXPECT_EQ(second_new_opacity, root->opacity()); 424 EXPECT_EQ(second_new_opacity, root->opacity());
426 425
427 // The previous cancelation should have updated the revert value of the in 426 // The previous cancelation should have updated the revert value of the in
428 // flight change. 427 // flight change.
429 setup.window_tree_client()->OnChangeCompleted(change_id2, false); 428 setup.window_tree_client()->OnChangeCompleted(change_id2, false);
430 EXPECT_EQ(original_opacity, root->opacity()); 429 EXPECT_EQ(original_opacity, root->opacity());
431 } 430 }
432 431
433 // Verifies |is_modal| is reverted if the server replied that the change failed. 432 // Verifies |is_modal| is reverted if the server replied that the change failed.
434 TEST_F(WindowTreeClientImplTest, SetModalFailed) { 433 TEST_F(WindowTreeClientTest, SetModalFailed) {
435 WindowTreeSetup setup; 434 WindowTreeSetup setup;
436 Window* root = setup.GetFirstRoot(); 435 Window* root = setup.GetFirstRoot();
437 ASSERT_TRUE(root); 436 ASSERT_TRUE(root);
438 EXPECT_FALSE(root->is_modal()); 437 EXPECT_FALSE(root->is_modal());
439 root->SetModal(); 438 root->SetModal();
440 uint32_t change_id; 439 uint32_t change_id;
441 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id)); 440 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id));
442 EXPECT_TRUE(root->is_modal()); 441 EXPECT_TRUE(root->is_modal());
443 setup.window_tree_client()->OnChangeCompleted(change_id, false); 442 setup.window_tree_client()->OnChangeCompleted(change_id, false);
444 EXPECT_FALSE(root->is_modal()); 443 EXPECT_FALSE(root->is_modal());
445 } 444 }
446 445
447 TEST_F(WindowTreeClientImplTest, InputEventBasic) { 446 TEST_F(WindowTreeClientTest, InputEventBasic) {
448 WindowTreeSetup setup; 447 WindowTreeSetup setup;
449 Window* root = setup.GetFirstRoot(); 448 Window* root = setup.GetFirstRoot();
450 ASSERT_TRUE(root); 449 ASSERT_TRUE(root);
451 450
452 TestInputEventHandler event_handler; 451 TestInputEventHandler event_handler;
453 root->set_input_event_handler(&event_handler); 452 root->set_input_event_handler(&event_handler);
454 453
455 std::unique_ptr<ui::Event> ui_event( 454 std::unique_ptr<ui::Event> ui_event(
456 new ui::MouseEvent(ui::ET_MOUSE_MOVED, gfx::Point(), gfx::Point(), 455 new ui::MouseEvent(ui::ET_MOUSE_MOVED, gfx::Point(), gfx::Point(),
457 ui::EventTimeForNow(), ui::EF_NONE, 0)); 456 ui::EventTimeForNow(), ui::EF_NONE, 0));
458 setup.window_tree_client()->OnWindowInputEvent( 457 setup.window_tree_client()->OnWindowInputEvent(
459 1, server_id(root), mojom::Event::From(*ui_event.get()), 0); 458 1, server_id(root), mojom::Event::From(*ui_event.get()), 0);
460 EXPECT_TRUE(event_handler.received_event()); 459 EXPECT_TRUE(event_handler.received_event());
461 EXPECT_TRUE(setup.window_tree()->WasEventAcked(1)); 460 EXPECT_TRUE(setup.window_tree()->WasEventAcked(1));
462 event_handler.Reset(); 461 event_handler.Reset();
463 462
464 event_handler.set_should_manually_ack(); 463 event_handler.set_should_manually_ack();
465 setup.window_tree_client()->OnWindowInputEvent( 464 setup.window_tree_client()->OnWindowInputEvent(
466 33, server_id(root), mojom::Event::From(*ui_event.get()), 0); 465 33, server_id(root), mojom::Event::From(*ui_event.get()), 0);
467 EXPECT_TRUE(event_handler.received_event()); 466 EXPECT_TRUE(event_handler.received_event());
468 EXPECT_FALSE(setup.window_tree()->WasEventAcked(33)); 467 EXPECT_FALSE(setup.window_tree()->WasEventAcked(33));
469 468
470 event_handler.AckEvent(); 469 event_handler.AckEvent();
471 EXPECT_TRUE(setup.window_tree()->WasEventAcked(33)); 470 EXPECT_TRUE(setup.window_tree()->WasEventAcked(33));
472 } 471 }
473 472
474 // Tests event observers triggered by events that did not hit a target in this 473 // Tests event observers triggered by events that did not hit a target in this
475 // window tree. 474 // window tree.
476 TEST_F(WindowTreeClientImplTest, OnEventObserved) { 475 TEST_F(WindowTreeClientTest, OnEventObserved) {
477 WindowTreeSetup setup; 476 WindowTreeSetup setup;
478 Window* root = setup.GetFirstRoot(); 477 Window* root = setup.GetFirstRoot();
479 ASSERT_TRUE(root); 478 ASSERT_TRUE(root);
480 479
481 // Set up an event observer. 480 // Set up an event observer.
482 mojom::EventMatcherPtr matcher = mojom::EventMatcher::New(); 481 mojom::EventMatcherPtr matcher = mojom::EventMatcher::New();
483 matcher->type_matcher = mojom::EventTypeMatcher::New(); 482 matcher->type_matcher = mojom::EventTypeMatcher::New();
484 matcher->type_matcher->type = mojom::EventType::POINTER_DOWN; 483 matcher->type_matcher->type = mojom::EventType::POINTER_DOWN;
485 setup.window_tree_connection()->SetEventObserver(std::move(matcher)); 484 setup.client()->SetEventObserver(std::move(matcher));
486 485
487 // Simulate the server sending an observed event. 486 // Simulate the server sending an observed event.
488 uint32_t event_observer_id = setup.GetEventObserverId(); 487 uint32_t event_observer_id = setup.GetEventObserverId();
489 std::unique_ptr<ui::Event> ui_event( 488 std::unique_ptr<ui::Event> ui_event(
490 new ui::MouseEvent(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), 489 new ui::MouseEvent(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(),
491 ui::EventTimeForNow(), ui::EF_CONTROL_DOWN, 0)); 490 ui::EventTimeForNow(), ui::EF_CONTROL_DOWN, 0));
492 setup.window_tree_client()->OnEventObserved( 491 setup.window_tree_client()->OnEventObserved(
493 mojom::Event::From(*ui_event.get()), event_observer_id); 492 mojom::Event::From(*ui_event.get()), event_observer_id);
494 493
495 // Delegate sensed the event. 494 // Delegate sensed the event.
496 ui::Event* last_event = setup.window_tree_delegate()->last_event_observed(); 495 ui::Event* last_event = setup.window_tree_delegate()->last_event_observed();
497 EXPECT_EQ(ui::ET_MOUSE_PRESSED, last_event->type()); 496 EXPECT_EQ(ui::ET_MOUSE_PRESSED, last_event->type());
498 EXPECT_EQ(ui::EF_CONTROL_DOWN, last_event->flags()); 497 EXPECT_EQ(ui::EF_CONTROL_DOWN, last_event->flags());
499 setup.window_tree_delegate()->Reset(); 498 setup.window_tree_delegate()->Reset();
500 499
501 // Clear the event observer. 500 // Clear the event observer.
502 setup.window_tree_connection()->SetEventObserver(nullptr); 501 setup.client()->SetEventObserver(nullptr);
503 502
504 // Simulate another event from the server. 503 // Simulate another event from the server.
505 setup.window_tree_client()->OnEventObserved( 504 setup.window_tree_client()->OnEventObserved(
506 mojom::Event::From(*ui_event.get()), event_observer_id); 505 mojom::Event::From(*ui_event.get()), event_observer_id);
507 506
508 // No event was sensed. 507 // No event was sensed.
509 EXPECT_FALSE(setup.window_tree_delegate()->last_event_observed()); 508 EXPECT_FALSE(setup.window_tree_delegate()->last_event_observed());
510 } 509 }
511 510
512 // Tests event observers triggered by events that hit this window tree. 511 // Tests event observers triggered by events that hit this window tree.
513 TEST_F(WindowTreeClientImplTest, OnWindowInputEventWithEventObserver) { 512 TEST_F(WindowTreeClientTest, OnWindowInputEventWithEventObserver) {
514 WindowTreeSetup setup; 513 WindowTreeSetup setup;
515 Window* root = setup.GetFirstRoot(); 514 Window* root = setup.GetFirstRoot();
516 ASSERT_TRUE(root); 515 ASSERT_TRUE(root);
517 516
518 // Set up an event observer. 517 // Set up an event observer.
519 mojom::EventMatcherPtr matcher = mojom::EventMatcher::New(); 518 mojom::EventMatcherPtr matcher = mojom::EventMatcher::New();
520 matcher->type_matcher = mojom::EventTypeMatcher::New(); 519 matcher->type_matcher = mojom::EventTypeMatcher::New();
521 matcher->type_matcher->type = mojom::EventType::POINTER_DOWN; 520 matcher->type_matcher->type = mojom::EventType::POINTER_DOWN;
522 setup.window_tree_connection()->SetEventObserver(std::move(matcher)); 521 setup.client()->SetEventObserver(std::move(matcher));
523 522
524 // Simulate the server dispatching an event that also matched the observer. 523 // Simulate the server dispatching an event that also matched the observer.
525 uint32_t event_observer_id = setup.GetEventObserverId(); 524 uint32_t event_observer_id = setup.GetEventObserverId();
526 std::unique_ptr<ui::Event> ui_event( 525 std::unique_ptr<ui::Event> ui_event(
527 new ui::MouseEvent(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), 526 new ui::MouseEvent(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(),
528 ui::EventTimeForNow(), ui::EF_CONTROL_DOWN, 0)); 527 ui::EventTimeForNow(), ui::EF_CONTROL_DOWN, 0));
529 setup.window_tree_client()->OnWindowInputEvent( 528 setup.window_tree_client()->OnWindowInputEvent(
530 1, server_id(root), mojom::Event::From(*ui_event.get()), 529 1, server_id(root), mojom::Event::From(*ui_event.get()),
531 event_observer_id); 530 event_observer_id);
532 531
533 // Delegate sensed the event. 532 // Delegate sensed the event.
534 ui::Event* last_event = setup.window_tree_delegate()->last_event_observed(); 533 ui::Event* last_event = setup.window_tree_delegate()->last_event_observed();
535 EXPECT_EQ(ui::ET_MOUSE_PRESSED, last_event->type()); 534 EXPECT_EQ(ui::ET_MOUSE_PRESSED, last_event->type());
536 EXPECT_EQ(ui::EF_CONTROL_DOWN, last_event->flags()); 535 EXPECT_EQ(ui::EF_CONTROL_DOWN, last_event->flags());
537 } 536 }
538 537
539 // Tests that replacing an event observer with a new one results in only new 538 // Tests that replacing an event observer with a new one results in only new
540 // events being observed. 539 // events being observed.
541 TEST_F(WindowTreeClientImplTest, EventObserverReplaced) { 540 TEST_F(WindowTreeClientTest, EventObserverReplaced) {
542 WindowTreeSetup setup; 541 WindowTreeSetup setup;
543 Window* root = setup.GetFirstRoot(); 542 Window* root = setup.GetFirstRoot();
544 ASSERT_TRUE(root); 543 ASSERT_TRUE(root);
545 544
546 // Set up an event observer. 545 // Set up an event observer.
547 mojom::EventMatcherPtr matcher1 = mojom::EventMatcher::New(); 546 mojom::EventMatcherPtr matcher1 = mojom::EventMatcher::New();
548 matcher1->type_matcher = mojom::EventTypeMatcher::New(); 547 matcher1->type_matcher = mojom::EventTypeMatcher::New();
549 matcher1->type_matcher->type = mojom::EventType::POINTER_DOWN; 548 matcher1->type_matcher->type = mojom::EventType::POINTER_DOWN;
550 setup.window_tree_connection()->SetEventObserver(std::move(matcher1)); 549 setup.client()->SetEventObserver(std::move(matcher1));
551 uint32_t event_observer_id1 = setup.GetEventObserverId(); 550 uint32_t event_observer_id1 = setup.GetEventObserverId();
552 551
553 // Replace it with a second observer. 552 // Replace it with a second observer.
554 mojom::EventMatcherPtr matcher2 = mojom::EventMatcher::New(); 553 mojom::EventMatcherPtr matcher2 = mojom::EventMatcher::New();
555 matcher2->type_matcher = mojom::EventTypeMatcher::New(); 554 matcher2->type_matcher = mojom::EventTypeMatcher::New();
556 matcher2->type_matcher->type = mojom::EventType::POINTER_UP; 555 matcher2->type_matcher->type = mojom::EventType::POINTER_UP;
557 setup.window_tree_connection()->SetEventObserver(std::move(matcher2)); 556 setup.client()->SetEventObserver(std::move(matcher2));
558 uint32_t event_observer_id2 = setup.GetEventObserverId(); 557 uint32_t event_observer_id2 = setup.GetEventObserverId();
559 558
560 // Simulate the server sending an observed event that matched the old observer 559 // Simulate the server sending an observed event that matched the old observer
561 // (e.g. that was in-flight when the observer was replaced). 560 // (e.g. that was in-flight when the observer was replaced).
562 std::unique_ptr<ui::Event> pressed_event( 561 std::unique_ptr<ui::Event> pressed_event(
563 new ui::MouseEvent(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), 562 new ui::MouseEvent(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(),
564 ui::EventTimeForNow(), ui::EF_NONE, 0)); 563 ui::EventTimeForNow(), ui::EF_NONE, 0));
565 setup.window_tree_client()->OnEventObserved( 564 setup.window_tree_client()->OnEventObserved(
566 mojom::Event::From(*pressed_event.get()), event_observer_id1); 565 mojom::Event::From(*pressed_event.get()), event_observer_id1);
567 566
568 // The event was not sensed, because it does not match the current observer. 567 // The event was not sensed, because it does not match the current observer.
569 EXPECT_FALSE(setup.window_tree_delegate()->last_event_observed()); 568 EXPECT_FALSE(setup.window_tree_delegate()->last_event_observed());
570 569
571 // Simulate another event that matches the new observer. 570 // Simulate another event that matches the new observer.
572 std::unique_ptr<ui::Event> released_event( 571 std::unique_ptr<ui::Event> released_event(
573 new ui::MouseEvent(ui::ET_MOUSE_RELEASED, gfx::Point(), gfx::Point(), 572 new ui::MouseEvent(ui::ET_MOUSE_RELEASED, gfx::Point(), gfx::Point(),
574 ui::EventTimeForNow(), ui::EF_CONTROL_DOWN, 0)); 573 ui::EventTimeForNow(), ui::EF_CONTROL_DOWN, 0));
575 setup.window_tree_client()->OnEventObserved( 574 setup.window_tree_client()->OnEventObserved(
576 mojom::Event::From(*released_event.get()), event_observer_id2); 575 mojom::Event::From(*released_event.get()), event_observer_id2);
577 576
578 // The delegate sensed the event. 577 // The delegate sensed the event.
579 ui::Event* last_event = setup.window_tree_delegate()->last_event_observed(); 578 ui::Event* last_event = setup.window_tree_delegate()->last_event_observed();
580 EXPECT_EQ(ui::ET_MOUSE_RELEASED, last_event->type()); 579 EXPECT_EQ(ui::ET_MOUSE_RELEASED, last_event->type());
581 EXPECT_EQ(ui::EF_CONTROL_DOWN, last_event->flags()); 580 EXPECT_EQ(ui::EF_CONTROL_DOWN, last_event->flags());
582 } 581 }
583 582
584 // Verifies focus is reverted if the server replied that the change failed. 583 // Verifies focus is reverted if the server replied that the change failed.
585 TEST_F(WindowTreeClientImplTest, SetFocusFailed) { 584 TEST_F(WindowTreeClientTest, SetFocusFailed) {
586 WindowTreeSetup setup; 585 WindowTreeSetup setup;
587 Window* root = setup.GetFirstRoot(); 586 Window* root = setup.GetFirstRoot();
588 ASSERT_TRUE(root); 587 ASSERT_TRUE(root);
589 root->SetVisible(true); 588 root->SetVisible(true);
590 Window* child = setup.window_tree_connection()->NewWindow(); 589 Window* child = setup.client()->NewWindow();
591 child->SetVisible(true); 590 child->SetVisible(true);
592 root->AddChild(child); 591 root->AddChild(child);
593 Window* original_focus = setup.window_tree_connection()->GetFocusedWindow(); 592 Window* original_focus = setup.client()->GetFocusedWindow();
594 Window* new_focus = child; 593 Window* new_focus = child;
595 ASSERT_NE(new_focus, original_focus); 594 ASSERT_NE(new_focus, original_focus);
596 new_focus->SetFocus(); 595 new_focus->SetFocus();
597 ASSERT_TRUE(new_focus->HasFocus()); 596 ASSERT_TRUE(new_focus->HasFocus());
598 uint32_t change_id; 597 uint32_t change_id;
599 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id)); 598 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id));
600 setup.window_tree_client()->OnChangeCompleted(change_id, false); 599 setup.window_tree_client()->OnChangeCompleted(change_id, false);
601 EXPECT_EQ(original_focus, setup.window_tree_connection()->GetFocusedWindow()); 600 EXPECT_EQ(original_focus, setup.client()->GetFocusedWindow());
602 } 601 }
603 602
604 // Simulates a focus change, and while the focus change is in flight the server 603 // Simulates a focus change, and while the focus change is in flight the server
605 // replies with a new focus and the original focus change fails. 604 // replies with a new focus and the original focus change fails.
606 TEST_F(WindowTreeClientImplTest, SetFocusFailedWithPendingChange) { 605 TEST_F(WindowTreeClientTest, SetFocusFailedWithPendingChange) {
607 WindowTreeSetup setup; 606 WindowTreeSetup setup;
608 Window* root = setup.GetFirstRoot(); 607 Window* root = setup.GetFirstRoot();
609 ASSERT_TRUE(root); 608 ASSERT_TRUE(root);
610 root->SetVisible(true); 609 root->SetVisible(true);
611 Window* child1 = setup.window_tree_connection()->NewWindow(); 610 Window* child1 = setup.client()->NewWindow();
612 child1->SetVisible(true); 611 child1->SetVisible(true);
613 root->AddChild(child1); 612 root->AddChild(child1);
614 Window* child2 = setup.window_tree_connection()->NewWindow(); 613 Window* child2 = setup.client()->NewWindow();
615 child2->SetVisible(true); 614 child2->SetVisible(true);
616 root->AddChild(child2); 615 root->AddChild(child2);
617 Window* original_focus = setup.window_tree_connection()->GetFocusedWindow(); 616 Window* original_focus = setup.client()->GetFocusedWindow();
618 Window* new_focus = child1; 617 Window* new_focus = child1;
619 ASSERT_NE(new_focus, original_focus); 618 ASSERT_NE(new_focus, original_focus);
620 new_focus->SetFocus(); 619 new_focus->SetFocus();
621 ASSERT_TRUE(new_focus->HasFocus()); 620 ASSERT_TRUE(new_focus->HasFocus());
622 uint32_t change_id; 621 uint32_t change_id;
623 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id)); 622 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id));
624 623
625 // Simulate the server responding with a focus change. 624 // Simulate the server responding with a focus change.
626 setup.window_tree_client()->OnWindowFocused(server_id(child2)); 625 setup.window_tree_client()->OnWindowFocused(server_id(child2));
627 626
628 // This shouldn't trigger focus changing yet. 627 // This shouldn't trigger focus changing yet.
629 EXPECT_TRUE(child1->HasFocus()); 628 EXPECT_TRUE(child1->HasFocus());
630 629
631 // Tell the client the change failed, which should trigger failing to the 630 // Tell the client the change failed, which should trigger failing to the
632 // most recent focus from server. 631 // most recent focus from server.
633 setup.window_tree_client()->OnChangeCompleted(change_id, false); 632 setup.window_tree_client()->OnChangeCompleted(change_id, false);
634 EXPECT_FALSE(child1->HasFocus()); 633 EXPECT_FALSE(child1->HasFocus());
635 EXPECT_TRUE(child2->HasFocus()); 634 EXPECT_TRUE(child2->HasFocus());
636 EXPECT_EQ(child2, setup.window_tree_connection()->GetFocusedWindow()); 635 EXPECT_EQ(child2, setup.client()->GetFocusedWindow());
637 636
638 // Simulate server changing focus to child1. Should take immediately. 637 // Simulate server changing focus to child1. Should take immediately.
639 setup.window_tree_client()->OnWindowFocused(server_id(child1)); 638 setup.window_tree_client()->OnWindowFocused(server_id(child1));
640 EXPECT_TRUE(child1->HasFocus()); 639 EXPECT_TRUE(child1->HasFocus());
641 } 640 }
642 641
643 TEST_F(WindowTreeClientImplTest, FocusOnRemovedWindowWithInFlightFocusChange) { 642 TEST_F(WindowTreeClientTest, FocusOnRemovedWindowWithInFlightFocusChange) {
644 WindowTreeSetup setup; 643 WindowTreeSetup setup;
645 Window* root = setup.GetFirstRoot(); 644 Window* root = setup.GetFirstRoot();
646 ASSERT_TRUE(root); 645 ASSERT_TRUE(root);
647 root->SetVisible(true); 646 root->SetVisible(true);
648 Window* child1 = setup.window_tree_connection()->NewWindow(); 647 Window* child1 = setup.client()->NewWindow();
649 child1->SetVisible(true); 648 child1->SetVisible(true);
650 root->AddChild(child1); 649 root->AddChild(child1);
651 Window* child2 = setup.window_tree_connection()->NewWindow(); 650 Window* child2 = setup.client()->NewWindow();
652 child2->SetVisible(true); 651 child2->SetVisible(true);
653 root->AddChild(child2); 652 root->AddChild(child2);
654 653
655 child1->SetFocus(); 654 child1->SetFocus();
656 uint32_t change_id; 655 uint32_t change_id;
657 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id)); 656 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id));
658 657
659 // Destroy child1, which should set focus to null. 658 // Destroy child1, which should set focus to null.
660 child1->Destroy(); 659 child1->Destroy();
661 EXPECT_EQ(nullptr, setup.window_tree_connection()->GetFocusedWindow()); 660 EXPECT_EQ(nullptr, setup.client()->GetFocusedWindow());
662 661
663 // Server changes focus to 2. 662 // Server changes focus to 2.
664 setup.window_tree_client()->OnWindowFocused(server_id(child2)); 663 setup.window_tree_client()->OnWindowFocused(server_id(child2));
665 // Shouldn't take immediately. 664 // Shouldn't take immediately.
666 EXPECT_FALSE(child2->HasFocus()); 665 EXPECT_FALSE(child2->HasFocus());
667 666
668 // Ack the change, focus should still be null. 667 // Ack the change, focus should still be null.
669 setup.window_tree_client()->OnChangeCompleted(change_id, true); 668 setup.window_tree_client()->OnChangeCompleted(change_id, true);
670 EXPECT_EQ(nullptr, setup.window_tree_connection()->GetFocusedWindow()); 669 EXPECT_EQ(nullptr, setup.client()->GetFocusedWindow());
671 670
672 // Change to 2 again, this time it should take. 671 // Change to 2 again, this time it should take.
673 setup.window_tree_client()->OnWindowFocused(server_id(child2)); 672 setup.window_tree_client()->OnWindowFocused(server_id(child2));
674 EXPECT_TRUE(child2->HasFocus()); 673 EXPECT_TRUE(child2->HasFocus());
675 } 674 }
676 675
677 class ToggleVisibilityFromDestroyedObserver : public WindowObserver { 676 class ToggleVisibilityFromDestroyedObserver : public WindowObserver {
678 public: 677 public:
679 explicit ToggleVisibilityFromDestroyedObserver(Window* window) 678 explicit ToggleVisibilityFromDestroyedObserver(Window* window)
680 : window_(window) { 679 : window_(window) {
681 window_->AddObserver(this); 680 window_->AddObserver(this);
682 } 681 }
683 682
684 ToggleVisibilityFromDestroyedObserver() { EXPECT_FALSE(window_); } 683 ToggleVisibilityFromDestroyedObserver() { EXPECT_FALSE(window_); }
685 684
686 // WindowObserver: 685 // WindowObserver:
687 void OnWindowDestroyed(Window* window) override { 686 void OnWindowDestroyed(Window* window) override {
688 window_->SetVisible(!window->visible()); 687 window_->SetVisible(!window->visible());
689 window_->RemoveObserver(this); 688 window_->RemoveObserver(this);
690 window_ = nullptr; 689 window_ = nullptr;
691 } 690 }
692 691
693 private: 692 private:
694 Window* window_; 693 Window* window_;
695 694
696 DISALLOW_COPY_AND_ASSIGN(ToggleVisibilityFromDestroyedObserver); 695 DISALLOW_COPY_AND_ASSIGN(ToggleVisibilityFromDestroyedObserver);
697 }; 696 };
698 697
699 TEST_F(WindowTreeClientImplTest, ToggleVisibilityFromWindowDestroyed) { 698 TEST_F(WindowTreeClientTest, ToggleVisibilityFromWindowDestroyed) {
700 WindowTreeSetup setup; 699 WindowTreeSetup setup;
701 Window* root = setup.GetFirstRoot(); 700 Window* root = setup.GetFirstRoot();
702 ASSERT_TRUE(root); 701 ASSERT_TRUE(root);
703 Window* child1 = setup.window_tree_connection()->NewWindow(); 702 Window* child1 = setup.client()->NewWindow();
704 root->AddChild(child1); 703 root->AddChild(child1);
705 ToggleVisibilityFromDestroyedObserver toggler(child1); 704 ToggleVisibilityFromDestroyedObserver toggler(child1);
706 // Destroying the window triggers 705 // Destroying the window triggers
707 // ToggleVisibilityFromDestroyedObserver::OnWindowDestroyed(), which toggles 706 // ToggleVisibilityFromDestroyedObserver::OnWindowDestroyed(), which toggles
708 // the visibility of the window. Ack the change, which should not crash or 707 // the visibility of the window. Ack the change, which should not crash or
709 // trigger DCHECKs. 708 // trigger DCHECKs.
710 child1->Destroy(); 709 child1->Destroy();
711 uint32_t change_id; 710 uint32_t change_id;
712 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id)); 711 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id));
713 setup.window_tree_client()->OnChangeCompleted(change_id, true); 712 setup.window_tree_client()->OnChangeCompleted(change_id, true);
714 } 713 }
715 714
716 TEST_F(WindowTreeClientImplTest, NewTopLevelWindow) { 715 TEST_F(WindowTreeClientTest, NewTopLevelWindow) {
717 WindowTreeSetup setup; 716 WindowTreeSetup setup;
718 Window* root1 = setup.GetFirstRoot(); 717 Window* root1 = setup.GetFirstRoot();
719 ASSERT_TRUE(root1); 718 ASSERT_TRUE(root1);
720 Window* root2 = setup.window_tree_connection()->NewTopLevelWindow(nullptr); 719 Window* root2 = setup.client()->NewTopLevelWindow(nullptr);
721 ASSERT_TRUE(root2); 720 ASSERT_TRUE(root2);
722 EXPECT_TRUE(WindowPrivate(root2).parent_drawn()); 721 EXPECT_TRUE(WindowPrivate(root2).parent_drawn());
723 ASSERT_NE(root2, root1); 722 ASSERT_NE(root2, root1);
724 EXPECT_NE(server_id(root2), server_id(root1)); 723 EXPECT_NE(server_id(root2), server_id(root1));
725 EXPECT_EQ(2u, setup.window_tree_connection()->GetRoots().size()); 724 EXPECT_EQ(2u, setup.client()->GetRoots().size());
726 EXPECT_TRUE(setup.window_tree_connection()->GetRoots().count(root1) > 0u); 725 EXPECT_TRUE(setup.client()->GetRoots().count(root1) > 0u);
727 EXPECT_TRUE(setup.window_tree_connection()->GetRoots().count(root2) > 0u); 726 EXPECT_TRUE(setup.client()->GetRoots().count(root2) > 0u);
728 727
729 // Ack the request to the windowtree to create the new window. 728 // Ack the request to the windowtree to create the new window.
730 uint32_t change_id; 729 uint32_t change_id;
731 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id)); 730 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id));
732 EXPECT_EQ(setup.window_tree()->window_id(), server_id(root2)); 731 EXPECT_EQ(setup.window_tree()->window_id(), server_id(root2));
733 732
734 mojom::WindowDataPtr data = mojom::WindowData::New(); 733 mojom::WindowDataPtr data = mojom::WindowData::New();
735 data->window_id = server_id(root2); 734 data->window_id = server_id(root2);
736 data->display_id = 1; 735 data->display_id = 1;
737 setup.window_tree_client()->OnTopLevelCreated(change_id, std::move(data), 736 setup.window_tree_client()->OnTopLevelCreated(change_id, std::move(data),
738 false); 737 false);
739 738
740 EXPECT_FALSE(WindowPrivate(root2).parent_drawn()); 739 EXPECT_FALSE(WindowPrivate(root2).parent_drawn());
741 740
742 // Should not be able to add a top level as a child of another window. 741 // Should not be able to add a top level as a child of another window.
743 root1->AddChild(root2); 742 root1->AddChild(root2);
744 ASSERT_EQ(nullptr, root2->parent()); 743 ASSERT_EQ(nullptr, root2->parent());
745 744
746 // Destroy the first root, shouldn't initiate tear down. 745 // Destroy the first root, shouldn't initiate tear down.
747 root1->Destroy(); 746 root1->Destroy();
748 root1 = nullptr; 747 root1 = nullptr;
749 EXPECT_EQ(1u, setup.window_tree_connection()->GetRoots().size()); 748 EXPECT_EQ(1u, setup.client()->GetRoots().size());
750 EXPECT_TRUE(setup.window_tree_connection()->GetRoots().count(root2) > 0u); 749 EXPECT_TRUE(setup.client()->GetRoots().count(root2) > 0u);
751 } 750 }
752 751
753 TEST_F(WindowTreeClientImplTest, NewTopLevelWindowGetsPropertiesFromData) { 752 TEST_F(WindowTreeClientTest, NewTopLevelWindowGetsPropertiesFromData) {
754 WindowTreeSetup setup; 753 WindowTreeSetup setup;
755 Window* root1 = setup.GetFirstRoot(); 754 Window* root1 = setup.GetFirstRoot();
756 ASSERT_TRUE(root1); 755 ASSERT_TRUE(root1);
757 Window* root2 = setup.window_tree_connection()->NewTopLevelWindow(nullptr); 756 Window* root2 = setup.client()->NewTopLevelWindow(nullptr);
758 ASSERT_TRUE(root2); 757 ASSERT_TRUE(root2);
759 758
760 EXPECT_FALSE(root2->IsDrawn()); 759 EXPECT_FALSE(root2->IsDrawn());
761 EXPECT_FALSE(root2->visible()); 760 EXPECT_FALSE(root2->visible());
762 761
763 // Ack the request to the windowtree to create the new window. 762 // Ack the request to the windowtree to create the new window.
764 uint32_t change_id; 763 uint32_t change_id;
765 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id)); 764 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id));
766 EXPECT_EQ(setup.window_tree()->window_id(), server_id(root2)); 765 EXPECT_EQ(setup.window_tree()->window_id(), server_id(root2));
767 766
768 mojom::WindowDataPtr data = mojom::WindowData::New(); 767 mojom::WindowDataPtr data = mojom::WindowData::New();
769 data->window_id = server_id(root2); 768 data->window_id = server_id(root2);
770 data->display_id = 1; 769 data->display_id = 1;
771 data->bounds = mojo::Rect::From(gfx::Rect(1, 2, 3, 4)); 770 data->bounds = mojo::Rect::From(gfx::Rect(1, 2, 3, 4));
772 data->visible = true; 771 data->visible = true;
773 setup.window_tree_client()->OnTopLevelCreated(change_id, std::move(data), 772 setup.window_tree_client()->OnTopLevelCreated(change_id, std::move(data),
774 true); 773 true);
775 774
776 // Make sure all the properties took. 775 // Make sure all the properties took.
777 EXPECT_TRUE(root2->IsDrawn()); 776 EXPECT_TRUE(root2->IsDrawn());
778 EXPECT_TRUE(root2->visible()); 777 EXPECT_TRUE(root2->visible());
779 EXPECT_EQ(1, root2->display_id()); 778 EXPECT_EQ(1, root2->display_id());
780 EXPECT_EQ(gfx::Rect(1, 2, 3, 4), root2->bounds()); 779 EXPECT_EQ(gfx::Rect(1, 2, 3, 4), root2->bounds());
781 } 780 }
782 781
783 TEST_F(WindowTreeClientImplTest, NewTopLevelWindowGetsAllChangesInFlight) { 782 TEST_F(WindowTreeClientTest, NewTopLevelWindowGetsAllChangesInFlight) {
784 WindowTreeSetup setup; 783 WindowTreeSetup setup;
785 Window* root1 = setup.GetFirstRoot(); 784 Window* root1 = setup.GetFirstRoot();
786 ASSERT_TRUE(root1); 785 ASSERT_TRUE(root1);
787 Window* root2 = setup.window_tree_connection()->NewTopLevelWindow(nullptr); 786 Window* root2 = setup.client()->NewTopLevelWindow(nullptr);
788 ASSERT_TRUE(root2); 787 ASSERT_TRUE(root2);
789 788
790 EXPECT_FALSE(root2->IsDrawn()); 789 EXPECT_FALSE(root2->IsDrawn());
791 EXPECT_FALSE(root2->visible()); 790 EXPECT_FALSE(root2->visible());
792 791
793 // Get the id of the in flight change for creating the new window. 792 // Get the id of the in flight change for creating the new window.
794 uint32_t new_window_in_flight_change_id; 793 uint32_t new_window_in_flight_change_id;
795 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId( 794 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(
796 &new_window_in_flight_change_id)); 795 &new_window_in_flight_change_id));
797 EXPECT_EQ(setup.window_tree()->window_id(), server_id(root2)); 796 EXPECT_EQ(setup.window_tree()->window_id(), server_id(root2));
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
859 false); 858 false);
860 EXPECT_EQ(2u, root2->shared_properties().size()); 859 EXPECT_EQ(2u, root2->shared_properties().size());
861 ASSERT_TRUE(root2->HasSharedProperty("yy")); 860 ASSERT_TRUE(root2->HasSharedProperty("yy"));
862 EXPECT_EQ("server_yy", root2->GetSharedProperty<std::string>("yy")); 861 EXPECT_EQ("server_yy", root2->GetSharedProperty<std::string>("yy"));
863 ASSERT_TRUE(root2->HasSharedProperty("xx")); 862 ASSERT_TRUE(root2->HasSharedProperty("xx"));
864 EXPECT_EQ("server_xx", root2->GetSharedProperty<std::string>("xx")); 863 EXPECT_EQ("server_xx", root2->GetSharedProperty<std::string>("xx"));
865 } 864 }
866 865
867 // Tests that if the client has multiple unowned windows, and one of them is a 866 // Tests that if the client has multiple unowned windows, and one of them is a
868 // transient child to another, the teardown can happen cleanly. 867 // transient child to another, the teardown can happen cleanly.
869 TEST_F(WindowTreeClientImplTest, MultipleUnOwnedWindowsDuringDestruction) { 868 TEST_F(WindowTreeClientTest, MultipleUnOwnedWindowsDuringDestruction) {
870 std::unique_ptr<WindowTreeSetup> setup(new WindowTreeSetup()); 869 std::unique_ptr<WindowTreeSetup> setup(new WindowTreeSetup());
871 Window* root1 = setup->GetFirstRoot(); 870 Window* root1 = setup->GetFirstRoot();
872 ASSERT_TRUE(root1); 871 ASSERT_TRUE(root1);
873 Window* root2 = setup->window_tree_connection()->NewTopLevelWindow(nullptr); 872 Window* root2 = setup->client()->NewTopLevelWindow(nullptr);
874 ASSERT_TRUE(root2); 873 ASSERT_TRUE(root2);
875 root1->AddTransientWindow(root2); 874 root1->AddTransientWindow(root2);
876 875
877 WindowTracker tracker; 876 WindowTracker tracker;
878 tracker.Add(root1); 877 tracker.Add(root1);
879 tracker.Add(root2); 878 tracker.Add(root2);
880 setup.reset(); 879 setup.reset();
881 EXPECT_TRUE(tracker.windows().empty()); 880 EXPECT_TRUE(tracker.windows().empty());
882 } 881 }
883 882
884 TEST_F(WindowTreeClientImplTest, TopLevelWindowDestroyedBeforeCreateComplete) { 883 TEST_F(WindowTreeClientTest, TopLevelWindowDestroyedBeforeCreateComplete) {
885 WindowTreeSetup setup; 884 WindowTreeSetup setup;
886 Window* root1 = setup.GetFirstRoot(); 885 Window* root1 = setup.GetFirstRoot();
887 ASSERT_TRUE(root1); 886 ASSERT_TRUE(root1);
888 Window* root2 = setup.window_tree_connection()->NewTopLevelWindow(nullptr); 887 Window* root2 = setup.client()->NewTopLevelWindow(nullptr);
889 ASSERT_TRUE(root2); 888 ASSERT_TRUE(root2);
890 ASSERT_EQ(2u, setup.window_tree_connection()->GetRoots().size()); 889 ASSERT_EQ(2u, setup.client()->GetRoots().size());
891 890
892 // Get the id of the in flight change for creating the new window. 891 // Get the id of the in flight change for creating the new window.
893 uint32_t change_id; 892 uint32_t change_id;
894 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id)); 893 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id));
895 EXPECT_EQ(setup.window_tree()->window_id(), server_id(root2)); 894 EXPECT_EQ(setup.window_tree()->window_id(), server_id(root2));
896 895
897 mojom::WindowDataPtr data = mojom::WindowData::New(); 896 mojom::WindowDataPtr data = mojom::WindowData::New();
898 data->window_id = server_id(root2); 897 data->window_id = server_id(root2);
899 data->display_id = 1; 898 data->display_id = 1;
900 899
901 // Destroy the window before the server has a chance to ack the window 900 // Destroy the window before the server has a chance to ack the window
902 // creation. 901 // creation.
903 root2->Destroy(); 902 root2->Destroy();
904 EXPECT_EQ(1u, setup.window_tree_connection()->GetRoots().size()); 903 EXPECT_EQ(1u, setup.client()->GetRoots().size());
905 904
906 setup.window_tree_client()->OnTopLevelCreated(change_id, std::move(data), 905 setup.window_tree_client()->OnTopLevelCreated(change_id, std::move(data),
907 true); 906 true);
908 EXPECT_EQ(1u, setup.window_tree_connection()->GetRoots().size()); 907 EXPECT_EQ(1u, setup.client()->GetRoots().size());
909 } 908 }
910 909
911 // Tests both SetCapture and ReleaseCapture, to ensure that Window is properly 910 // Tests both SetCapture and ReleaseCapture, to ensure that Window is properly
912 // updated on failures. 911 // updated on failures.
913 TEST_F(WindowTreeClientImplTest, ExplicitCapture) { 912 TEST_F(WindowTreeClientTest, ExplicitCapture) {
914 WindowTreeSetup setup; 913 WindowTreeSetup setup;
915 Window* root = setup.GetFirstRoot(); 914 Window* root = setup.GetFirstRoot();
916 ASSERT_TRUE(root); 915 ASSERT_TRUE(root);
917 916
918 root->SetCapture(); 917 root->SetCapture();
919 EXPECT_TRUE(root->HasCapture()); 918 EXPECT_TRUE(root->HasCapture());
920 uint32_t change_id1; 919 uint32_t change_id1;
921 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id1)); 920 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id1));
922 setup.window_tree_client()->OnChangeCompleted(change_id1, false); 921 setup.window_tree_client()->OnChangeCompleted(change_id1, false);
923 EXPECT_FALSE(root->HasCapture()); 922 EXPECT_FALSE(root->HasCapture());
(...skipping 13 matching lines...) Expand all
937 EXPECT_TRUE(root->HasCapture()); 936 EXPECT_TRUE(root->HasCapture());
938 937
939 root->ReleaseCapture(); 938 root->ReleaseCapture();
940 uint32_t change_id4; 939 uint32_t change_id4;
941 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id4)); 940 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id4));
942 setup.window_tree_client()->OnChangeCompleted(change_id4, true); 941 setup.window_tree_client()->OnChangeCompleted(change_id4, true);
943 EXPECT_FALSE(root->HasCapture()); 942 EXPECT_FALSE(root->HasCapture());
944 } 943 }
945 944
946 // Tests that when capture is lost, that the window tree updates properly. 945 // Tests that when capture is lost, that the window tree updates properly.
947 TEST_F(WindowTreeClientImplTest, LostCapture) { 946 TEST_F(WindowTreeClientTest, LostCapture) {
948 WindowTreeSetup setup; 947 WindowTreeSetup setup;
949 Window* root = setup.GetFirstRoot(); 948 Window* root = setup.GetFirstRoot();
950 ASSERT_TRUE(root); 949 ASSERT_TRUE(root);
951 950
952 root->SetCapture(); 951 root->SetCapture();
953 EXPECT_TRUE(root->HasCapture()); 952 EXPECT_TRUE(root->HasCapture());
954 uint32_t change_id1; 953 uint32_t change_id1;
955 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id1)); 954 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id1));
956 setup.window_tree_client()->OnChangeCompleted(change_id1, true); 955 setup.window_tree_client()->OnChangeCompleted(change_id1, true);
957 EXPECT_TRUE(root->HasCapture()); 956 EXPECT_TRUE(root->HasCapture());
958 957
959 // The second SetCapture should be ignored. 958 // The second SetCapture should be ignored.
960 root->SetCapture(); 959 root->SetCapture();
961 uint32_t change_id2; 960 uint32_t change_id2;
962 ASSERT_FALSE(setup.window_tree()->GetAndClearChangeId(&change_id2)); 961 ASSERT_FALSE(setup.window_tree()->GetAndClearChangeId(&change_id2));
963 962
964 setup.window_tree_client()->OnLostCapture(server_id(root)); 963 setup.window_tree_client()->OnLostCapture(server_id(root));
965 EXPECT_FALSE(root->HasCapture()); 964 EXPECT_FALSE(root->HasCapture());
966 } 965 }
967 966
968 // Tests that when capture is lost, while there is a release capture request 967 // Tests that when capture is lost, while there is a release capture request
969 // inflight, that the revert value of that request is updated correctly. 968 // inflight, that the revert value of that request is updated correctly.
970 TEST_F(WindowTreeClientImplTest, LostCaptureDifferentInFlightChange) { 969 TEST_F(WindowTreeClientTest, LostCaptureDifferentInFlightChange) {
971 WindowTreeSetup setup; 970 WindowTreeSetup setup;
972 Window* root = setup.GetFirstRoot(); 971 Window* root = setup.GetFirstRoot();
973 ASSERT_TRUE(root); 972 ASSERT_TRUE(root);
974 973
975 root->SetCapture(); 974 root->SetCapture();
976 EXPECT_TRUE(root->HasCapture()); 975 EXPECT_TRUE(root->HasCapture());
977 uint32_t change_id1; 976 uint32_t change_id1;
978 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id1)); 977 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id1));
979 setup.window_tree_client()->OnChangeCompleted(change_id1, true); 978 setup.window_tree_client()->OnChangeCompleted(change_id1, true);
980 EXPECT_TRUE(root->HasCapture()); 979 EXPECT_TRUE(root->HasCapture());
981 980
982 // The ReleaseCapture should be updated to the revert of the SetCapture. 981 // The ReleaseCapture should be updated to the revert of the SetCapture.
983 root->ReleaseCapture(); 982 root->ReleaseCapture();
984 uint32_t change_id2; 983 uint32_t change_id2;
985 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id2)); 984 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id2));
986 985
987 setup.window_tree_client()->OnLostCapture(server_id(root)); 986 setup.window_tree_client()->OnLostCapture(server_id(root));
988 EXPECT_FALSE(root->HasCapture()); 987 EXPECT_FALSE(root->HasCapture());
989 988
990 setup.window_tree_client()->OnChangeCompleted(change_id2, false); 989 setup.window_tree_client()->OnChangeCompleted(change_id2, false);
991 EXPECT_FALSE(root->HasCapture()); 990 EXPECT_FALSE(root->HasCapture());
992 } 991 }
993 992
994 // Tests that while two windows can inflight capture requests, that the 993 // Tests that while two windows can inflight capture requests, that the
995 // WindowTreeClient only identifies one as having the current capture. 994 // WindowTreeClient only identifies one as having the current capture.
996 TEST_F(WindowTreeClientImplTest, TwoWindowsRequestCapture) { 995 TEST_F(WindowTreeClientTest, TwoWindowsRequestCapture) {
997 WindowTreeSetup setup; 996 WindowTreeSetup setup;
998 Window* root = setup.GetFirstRoot(); 997 Window* root = setup.GetFirstRoot();
999 Window* child = setup.window_tree_connection()->NewWindow(); 998 Window* child = setup.client()->NewWindow();
1000 child->SetVisible(true); 999 child->SetVisible(true);
1001 root->AddChild(child); 1000 root->AddChild(child);
1002 1001
1003 root->SetCapture(); 1002 root->SetCapture();
1004 EXPECT_TRUE(root->HasCapture()); 1003 EXPECT_TRUE(root->HasCapture());
1005 uint32_t change_id1; 1004 uint32_t change_id1;
1006 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id1)); 1005 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id1));
1007 1006
1008 child->SetCapture(); 1007 child->SetCapture();
1009 EXPECT_TRUE(child->HasCapture()); 1008 EXPECT_TRUE(child->HasCapture());
(...skipping 10 matching lines...) Expand all
1020 EXPECT_FALSE(child->HasCapture()); 1019 EXPECT_FALSE(child->HasCapture());
1021 EXPECT_TRUE(root->HasCapture()); 1020 EXPECT_TRUE(root->HasCapture());
1022 1021
1023 setup.window_tree_client()->OnLostCapture(server_id(root)); 1022 setup.window_tree_client()->OnLostCapture(server_id(root));
1024 EXPECT_FALSE(root->HasCapture()); 1023 EXPECT_FALSE(root->HasCapture());
1025 } 1024 }
1026 1025
1027 TEST_F(WindowTreeClientImplTest, WindowDestroyedWhileTransientChildHasCapture) { 1026 TEST_F(WindowTreeClientImplTest, WindowDestroyedWhileTransientChildHasCapture) {
1028 WindowTreeSetup setup; 1027 WindowTreeSetup setup;
1029 Window* root = setup.GetFirstRoot(); 1028 Window* root = setup.GetFirstRoot();
1030 Window* transient_parent = setup.window_tree_connection()->NewWindow(); 1029 Window* transient_parent = setup.window_tree_client()->NewWindow();
1031 Window* transient_child = setup.window_tree_connection()->NewWindow(); 1030 Window* transient_child = setup.window_tree_client()->NewWindow();
1032 transient_parent->SetVisible(true); 1031 transient_parent->SetVisible(true);
1033 transient_child->SetVisible(true); 1032 transient_child->SetVisible(true);
1034 root->AddChild(transient_parent); 1033 root->AddChild(transient_parent);
1035 root->AddChild(transient_child); 1034 root->AddChild(transient_child);
1036 1035
1037 transient_parent->AddTransientWindow(transient_child); 1036 transient_parent->AddTransientWindow(transient_child);
1038 1037
1039 WindowTracker tracker; 1038 WindowTracker tracker;
1040 tracker.Add(transient_parent); 1039 tracker.Add(transient_parent);
1041 tracker.Add(transient_child); 1040 tracker.Add(transient_child);
1042 // Request a capture on the transient child, then destroy the transient 1041 // Request a capture on the transient child, then destroy the transient
1043 // parent. That will destroy both windows, and should reset the capture window 1042 // parent. That will destroy both windows, and should reset the capture window
1044 // correctly. 1043 // correctly.
1045 transient_child->SetCapture(); 1044 transient_child->SetCapture();
1046 transient_parent->Destroy(); 1045 transient_parent->Destroy();
1047 EXPECT_TRUE(tracker.windows().empty()); 1046 EXPECT_TRUE(tracker.windows().empty());
1048 1047
1049 // Create a new Window, and attempt to place capture on that. 1048 // Create a new Window, and attempt to place capture on that.
1050 Window* child = setup.window_tree_connection()->NewWindow(); 1049 Window* child = setup.window_tree_client()->NewWindow();
1051 child->SetVisible(true); 1050 child->SetVisible(true);
1052 root->AddChild(child); 1051 root->AddChild(child);
1053 child->SetCapture(); 1052 child->SetCapture();
1054 EXPECT_TRUE(child->HasCapture()); 1053 EXPECT_TRUE(child->HasCapture());
1055 } 1054 }
1056 1055
1057 } // namespace mus 1056 } // namespace mus
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698