OLD | NEW |
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/macros.h" | 9 #include "base/macros.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 public TestChangeTracker::Delegate { | 122 public TestChangeTracker::Delegate { |
123 public: | 123 public: |
124 TestWindowTreeClientImpl() | 124 TestWindowTreeClientImpl() |
125 : binding_(this), | 125 : binding_(this), |
126 connection_id_(0), | 126 connection_id_(0), |
127 root_window_id_(0), | 127 root_window_id_(0), |
128 // Start with a random large number so tests can use lower ids if they | 128 // Start with a random large number so tests can use lower ids if they |
129 // want. | 129 // want. |
130 next_change_id_(10000), | 130 next_change_id_(10000), |
131 waiting_change_id_(0), | 131 waiting_change_id_(0), |
132 on_change_completed_result_(false) { | 132 on_change_completed_result_(false), |
| 133 track_root_bounds_changes_(false) { |
133 tracker_.set_delegate(this); | 134 tracker_.set_delegate(this); |
134 } | 135 } |
135 | 136 |
136 void Bind(mojo::InterfaceRequest<mojom::WindowTreeClient> request) { | 137 void Bind(mojo::InterfaceRequest<mojom::WindowTreeClient> request) { |
137 binding_.Bind(std::move(request)); | 138 binding_.Bind(std::move(request)); |
138 } | 139 } |
139 | 140 |
140 mojom::WindowTree* tree() { return tree_.get(); } | 141 mojom::WindowTree* tree() { return tree_.get(); } |
141 TestChangeTracker* tracker() { return &tracker_; } | 142 TestChangeTracker* tracker() { return &tracker_; } |
| 143 Id root_window_id() const { return root_window_id_; } |
| 144 |
| 145 // Sets whether changes to the bounds of the root should be tracked. Normally |
| 146 // they are ignored (as during startup we often times get random size |
| 147 // changes). |
| 148 void set_track_root_bounds_changes(bool value) { |
| 149 track_root_bounds_changes_ = value; |
| 150 } |
142 | 151 |
143 // Runs a nested MessageLoop until |count| changes (calls to | 152 // Runs a nested MessageLoop until |count| changes (calls to |
144 // WindowTreeClient functions) have been received. | 153 // WindowTreeClient functions) have been received. |
145 void WaitForChangeCount(size_t count) { | 154 void WaitForChangeCount(size_t count) { |
146 if (tracker_.changes()->size() >= count) | 155 if (tracker_.changes()->size() >= count) |
147 return; | 156 return; |
148 | 157 |
149 ASSERT_TRUE(wait_state_.get() == nullptr); | 158 ASSERT_TRUE(wait_state_.get() == nullptr); |
150 wait_state_.reset(new WaitState); | 159 wait_state_.reset(new WaitState); |
151 wait_state_->change_count = count; | 160 wait_state_->change_count = count; |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 | 224 |
216 // Generally you want NewWindow(), but use this if you need to test given | 225 // Generally you want NewWindow(), but use this if you need to test given |
217 // a complete window id (NewWindow() ors with the connection id). | 226 // a complete window id (NewWindow() ors with the connection id). |
218 Id NewWindowWithCompleteId(Id id) { | 227 Id NewWindowWithCompleteId(Id id) { |
219 mojo::Map<mojo::String, mojo::Array<uint8_t>> properties; | 228 mojo::Map<mojo::String, mojo::Array<uint8_t>> properties; |
220 const uint32_t change_id = GetAndAdvanceChangeId(); | 229 const uint32_t change_id = GetAndAdvanceChangeId(); |
221 tree()->NewWindow(change_id, id, std::move(properties)); | 230 tree()->NewWindow(change_id, id, std::move(properties)); |
222 return WaitForChangeCompleted(change_id) ? id : 0; | 231 return WaitForChangeCompleted(change_id) ? id : 0; |
223 } | 232 } |
224 | 233 |
225 void set_root_window(Id root_window_id) { root_window_id_ = root_window_id; } | |
226 | |
227 bool SetWindowProperty(Id window_id, | 234 bool SetWindowProperty(Id window_id, |
228 const std::string& name, | 235 const std::string& name, |
229 const std::vector<uint8_t>* data) { | 236 const std::vector<uint8_t>* data) { |
230 Array<uint8_t> mojo_data; | 237 Array<uint8_t> mojo_data; |
231 if (data) | 238 if (data) |
232 mojo_data = Array<uint8_t>::From(*data); | 239 mojo_data = Array<uint8_t>::From(*data); |
233 const uint32_t change_id = GetAndAdvanceChangeId(); | 240 const uint32_t change_id = GetAndAdvanceChangeId(); |
234 tree()->SetWindowProperty(change_id, window_id, name, std::move(mojo_data)); | 241 tree()->SetWindowProperty(change_id, window_id, name, std::move(mojo_data)); |
235 return WaitForChangeCompleted(change_id); | 242 return WaitForChangeCompleted(change_id); |
236 } | 243 } |
(...skipping 28 matching lines...) Expand all Loading... |
265 } | 272 } |
266 } | 273 } |
267 | 274 |
268 // WindowTreeClient: | 275 // WindowTreeClient: |
269 void OnEmbed(ConnectionSpecificId connection_id, | 276 void OnEmbed(ConnectionSpecificId connection_id, |
270 WindowDataPtr root, | 277 WindowDataPtr root, |
271 mojom::WindowTreePtr tree, | 278 mojom::WindowTreePtr tree, |
272 Id focused_window_id, | 279 Id focused_window_id, |
273 uint32_t access_policy) override { | 280 uint32_t access_policy) override { |
274 // TODO(sky): add coverage of |focused_window_id|. | 281 // TODO(sky): add coverage of |focused_window_id|. |
| 282 ASSERT_TRUE(root); |
| 283 root_window_id_ = root->window_id; |
275 tree_ = std::move(tree); | 284 tree_ = std::move(tree); |
276 connection_id_ = connection_id; | 285 connection_id_ = connection_id; |
277 tracker()->OnEmbed(connection_id, std::move(root)); | 286 tracker()->OnEmbed(connection_id, std::move(root)); |
278 if (embed_run_loop_) | 287 if (embed_run_loop_) |
279 embed_run_loop_->Quit(); | 288 embed_run_loop_->Quit(); |
280 } | 289 } |
281 void OnEmbeddedAppDisconnected(Id window_id) override { | 290 void OnEmbeddedAppDisconnected(Id window_id) override { |
282 tracker()->OnEmbeddedAppDisconnected(window_id); | 291 tracker()->OnEmbeddedAppDisconnected(window_id); |
283 } | 292 } |
284 void OnUnembed(Id window_id) override { tracker()->OnUnembed(window_id); } | 293 void OnUnembed(Id window_id) override { tracker()->OnUnembed(window_id); } |
285 void OnTopLevelCreated(uint32_t change_id, | 294 void OnTopLevelCreated(uint32_t change_id, |
286 mojom::WindowDataPtr data) override { | 295 mojom::WindowDataPtr data) override { |
287 tracker()->OnTopLevelCreated(change_id, std::move(data)); | 296 tracker()->OnTopLevelCreated(change_id, std::move(data)); |
288 } | 297 } |
289 void OnWindowBoundsChanged(Id window_id, | 298 void OnWindowBoundsChanged(Id window_id, |
290 RectPtr old_bounds, | 299 RectPtr old_bounds, |
291 RectPtr new_bounds) override { | 300 RectPtr new_bounds) override { |
292 // The bounds of the root may change during startup on Android at random | 301 // The bounds of the root may change during startup on Android at random |
293 // times. As this doesn't matter, and shouldn't impact test exepctations, | 302 // times. As this doesn't matter, and shouldn't impact test exepctations, |
294 // it is ignored. | 303 // it is ignored. |
295 if (window_id == root_window_id_) | 304 if (window_id == root_window_id_ && !track_root_bounds_changes_) |
296 return; | 305 return; |
297 tracker()->OnWindowBoundsChanged(window_id, std::move(old_bounds), | 306 tracker()->OnWindowBoundsChanged(window_id, std::move(old_bounds), |
298 std::move(new_bounds)); | 307 std::move(new_bounds)); |
299 } | 308 } |
300 void OnClientAreaChanged( | 309 void OnClientAreaChanged( |
301 uint32_t window_id, | 310 uint32_t window_id, |
302 mojo::InsetsPtr new_client_area, | 311 mojo::InsetsPtr new_client_area, |
303 mojo::Array<mojo::RectPtr> new_additional_client_areas) override {} | 312 mojo::Array<mojo::RectPtr> new_additional_client_areas) override {} |
304 void OnTransientWindowAdded(uint32_t window_id, | 313 void OnTransientWindowAdded(uint32_t window_id, |
305 uint32_t transient_window_id) override { | 314 uint32_t transient_window_id) override { |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
374 // If non-null we're waiting for a certain number of change notifications to | 383 // If non-null we're waiting for a certain number of change notifications to |
375 // be encountered. | 384 // be encountered. |
376 scoped_ptr<WaitState> wait_state_; | 385 scoped_ptr<WaitState> wait_state_; |
377 | 386 |
378 mojo::Binding<WindowTreeClient> binding_; | 387 mojo::Binding<WindowTreeClient> binding_; |
379 Id connection_id_; | 388 Id connection_id_; |
380 Id root_window_id_; | 389 Id root_window_id_; |
381 uint32_t next_change_id_; | 390 uint32_t next_change_id_; |
382 uint32_t waiting_change_id_; | 391 uint32_t waiting_change_id_; |
383 bool on_change_completed_result_; | 392 bool on_change_completed_result_; |
| 393 bool track_root_bounds_changes_; |
384 scoped_ptr<base::RunLoop> change_completed_run_loop_; | 394 scoped_ptr<base::RunLoop> change_completed_run_loop_; |
385 | 395 |
386 DISALLOW_COPY_AND_ASSIGN(TestWindowTreeClientImpl); | 396 DISALLOW_COPY_AND_ASSIGN(TestWindowTreeClientImpl); |
387 }; | 397 }; |
388 | 398 |
389 // ----------------------------------------------------------------------------- | 399 // ----------------------------------------------------------------------------- |
390 | 400 |
391 // InterfaceFactory for vending TestWindowTreeClientImpls. | 401 // InterfaceFactory for vending TestWindowTreeClientImpls. |
392 class WindowTreeClientFactory | 402 class WindowTreeClientFactory |
393 : public mojo::InterfaceFactory<WindowTreeClient> { | 403 : public mojo::InterfaceFactory<WindowTreeClient> { |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
451 | 461 |
452 int connection_id_1() const { return connection_id_1_; } | 462 int connection_id_1() const { return connection_id_1_; } |
453 int connection_id_2() const { return connection_id_2_; } | 463 int connection_id_2() const { return connection_id_2_; } |
454 | 464 |
455 void EstablishSecondConnectionWithRoot(Id root_id) { | 465 void EstablishSecondConnectionWithRoot(Id root_id) { |
456 ASSERT_TRUE(ws_client2_.get() == nullptr); | 466 ASSERT_TRUE(ws_client2_.get() == nullptr); |
457 ws_client2_ = | 467 ws_client2_ = |
458 EstablishConnectionViaEmbed(ws1(), root_id, &connection_id_2_); | 468 EstablishConnectionViaEmbed(ws1(), root_id, &connection_id_2_); |
459 ASSERT_GT(connection_id_2_, 0); | 469 ASSERT_GT(connection_id_2_, 0); |
460 ASSERT_TRUE(ws_client2_.get() != nullptr); | 470 ASSERT_TRUE(ws_client2_.get() != nullptr); |
461 ws_client2_->set_root_window(root_window_id_); | |
462 } | 471 } |
463 | 472 |
464 void EstablishSecondConnection(bool create_initial_window) { | 473 void EstablishSecondConnection(bool create_initial_window) { |
465 Id window_1_1 = 0; | 474 Id window_1_1 = 0; |
466 if (create_initial_window) { | 475 if (create_initial_window) { |
467 window_1_1 = ws_client1()->NewWindow(1); | 476 window_1_1 = ws_client1()->NewWindow(1); |
468 ASSERT_TRUE(window_1_1); | 477 ASSERT_TRUE(window_1_1); |
469 } | 478 } |
470 ASSERT_NO_FATAL_FAILURE( | 479 ASSERT_NO_FATAL_FAILURE( |
471 EstablishSecondConnectionWithRoot(BuildWindowId(connection_id_1(), 1))); | 480 EstablishSecondConnectionWithRoot(BuildWindowId(connection_id_1(), 1))); |
472 | 481 |
473 if (create_initial_window) { | 482 if (create_initial_window) { |
474 EXPECT_EQ("[" + WindowParentToString(window_1_1, kNullParentId) + "]", | 483 EXPECT_EQ("[" + WindowParentToString(window_1_1, kNullParentId) + "]", |
475 ChangeWindowDescription(*changes2())); | 484 ChangeWindowDescription(*changes2())); |
476 } | 485 } |
477 } | 486 } |
478 | 487 |
479 void EstablishThirdConnection(WindowTree* owner, Id root_id) { | 488 void EstablishThirdConnection(WindowTree* owner, Id root_id) { |
480 ASSERT_TRUE(ws_client3_.get() == nullptr); | 489 ASSERT_TRUE(ws_client3_.get() == nullptr); |
481 ws_client3_ = EstablishConnectionViaEmbed(owner, root_id, nullptr); | 490 ws_client3_ = EstablishConnectionViaEmbed(owner, root_id, nullptr); |
482 ASSERT_TRUE(ws_client3_.get() != nullptr); | 491 ASSERT_TRUE(ws_client3_.get() != nullptr); |
483 ws_client3_->set_root_window(root_window_id_); | |
484 } | 492 } |
485 | 493 |
486 scoped_ptr<TestWindowTreeClientImpl> WaitForWindowTreeClient() { | 494 scoped_ptr<TestWindowTreeClientImpl> WaitForWindowTreeClient() { |
487 return client_factory_->WaitForInstance(); | 495 return client_factory_->WaitForInstance(); |
488 } | 496 } |
489 | 497 |
490 // Establishes a new connection by way of Embed() on the specified | 498 // Establishes a new connection by way of Embed() on the specified |
491 // WindowTree. | 499 // WindowTree. |
492 scoped_ptr<TestWindowTreeClientImpl> EstablishConnectionViaEmbed( | 500 scoped_ptr<TestWindowTreeClientImpl> EstablishConnectionViaEmbed( |
493 WindowTree* owner, | 501 WindowTree* owner, |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
544 | 552 |
545 ASSERT_EQ(1u, changes1()->size()); | 553 ASSERT_EQ(1u, changes1()->size()); |
546 EXPECT_EQ(CHANGE_TYPE_EMBED, (*changes1())[0].type); | 554 EXPECT_EQ(CHANGE_TYPE_EMBED, (*changes1())[0].type); |
547 // All these tests assume 1 for the client id. The only real assertion here | 555 // All these tests assume 1 for the client id. The only real assertion here |
548 // is the client id is not zero, but adding this as rest of code here | 556 // is the client id is not zero, but adding this as rest of code here |
549 // assumes 1. | 557 // assumes 1. |
550 ASSERT_GT((*changes1())[0].connection_id, 0); | 558 ASSERT_GT((*changes1())[0].connection_id, 0); |
551 connection_id_1_ = (*changes1())[0].connection_id; | 559 connection_id_1_ = (*changes1())[0].connection_id; |
552 ASSERT_FALSE((*changes1())[0].windows.empty()); | 560 ASSERT_FALSE((*changes1())[0].windows.empty()); |
553 root_window_id_ = (*changes1())[0].windows[0].window_id; | 561 root_window_id_ = (*changes1())[0].windows[0].window_id; |
554 ws_client1_->set_root_window(root_window_id_); | 562 ASSERT_EQ(root_window_id_, ws_client1_->root_window_id()); |
555 changes1()->clear(); | 563 changes1()->clear(); |
556 } | 564 } |
557 | 565 |
558 // ApplicationDelegate implementation. | 566 // ApplicationDelegate implementation. |
559 bool ConfigureIncomingConnection(ApplicationConnection* connection) override { | 567 bool ConfigureIncomingConnection(ApplicationConnection* connection) override { |
560 connection->AddService(client_factory_.get()); | 568 connection->AddService(client_factory_.get()); |
561 return true; | 569 return true; |
562 } | 570 } |
563 | 571 |
564 scoped_ptr<TestWindowTreeClientImpl> ws_client1_; | 572 scoped_ptr<TestWindowTreeClientImpl> ws_client1_; |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
642 windows.clear(); | 650 windows.clear(); |
643 GetWindowTree(ws2(), window_2_4, &windows); | 651 GetWindowTree(ws2(), window_2_4, &windows); |
644 EXPECT_EQ(WindowParentToString(window_2_4, kNullParentId), | 652 EXPECT_EQ(WindowParentToString(window_2_4, kNullParentId), |
645 SingleWindowDescription(windows)); | 653 SingleWindowDescription(windows)); |
646 } | 654 } |
647 | 655 |
648 // And window 4 should not be visible to connection 3. | 656 // And window 4 should not be visible to connection 3. |
649 { | 657 { |
650 std::vector<TestWindow> windows; | 658 std::vector<TestWindow> windows; |
651 GetWindowTree(ws3(), window_2_3, &windows); | 659 GetWindowTree(ws3(), window_2_3, &windows); |
652 EXPECT_EQ(WindowParentToString(window_2_3, kNullParentId), | 660 EXPECT_EQ("no windows", SingleWindowDescription(windows)); |
653 SingleWindowDescription(windows)); | |
654 } | 661 } |
655 } | 662 } |
656 | 663 |
657 // Verifies once Embed() has been invoked the parent connection can't see any | 664 // Verifies once Embed() has been invoked the parent connection can't see any |
658 // children. | 665 // children. |
659 TEST_F(WindowTreeAppTest, CantAccessChildrenOfEmbeddedWindow) { | 666 TEST_F(WindowTreeAppTest, CantAccessChildrenOfEmbeddedWindow) { |
660 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); | 667 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); |
661 | 668 |
662 Id window_1_1 = BuildWindowId(connection_id_1(), 1); | 669 Id window_1_1 = BuildWindowId(connection_id_1(), 1); |
663 Id window_2_2 = ws_client2()->NewWindow(2); | 670 Id window_2_2 = ws_client2()->NewWindow(2); |
664 ASSERT_TRUE(window_2_2); | 671 ASSERT_TRUE(window_2_2); |
665 ASSERT_TRUE(ws_client2()->AddWindow(window_1_1, window_2_2)); | 672 ASSERT_TRUE(ws_client2()->AddWindow(window_1_1, window_2_2)); |
666 | 673 |
667 ASSERT_NO_FATAL_FAILURE(EstablishThirdConnection(ws2(), window_2_2)); | 674 ASSERT_NO_FATAL_FAILURE(EstablishThirdConnection(ws2(), window_2_2)); |
668 | 675 |
669 Id window_3_3 = ws_client3()->NewWindow(3); | 676 Id window_3_3 = ws_client3()->NewWindow(3); |
670 ASSERT_TRUE(window_3_3); | 677 ASSERT_TRUE(window_3_3); |
671 ASSERT_TRUE(ws_client3()->AddWindow(window_2_2, window_3_3)); | 678 ASSERT_TRUE( |
| 679 ws_client3()->AddWindow(ws_client3()->root_window_id(), window_3_3)); |
672 | 680 |
673 // Even though 3 is a child of 2 connection 2 can't see 3 as it's from a | 681 // Even though 3 is a child of 2 connection 2 can't see 3 as it's from a |
674 // different connection. | 682 // different connection. |
675 { | 683 { |
676 std::vector<TestWindow> windows; | 684 std::vector<TestWindow> windows; |
677 GetWindowTree(ws2(), window_2_2, &windows); | 685 GetWindowTree(ws2(), window_2_2, &windows); |
678 EXPECT_EQ(WindowParentToString(window_2_2, window_1_1), | 686 EXPECT_EQ(WindowParentToString(window_2_2, window_1_1), |
679 SingleWindowDescription(windows)); | 687 SingleWindowDescription(windows)); |
680 } | 688 } |
681 | 689 |
682 // Connection 2 shouldn't be able to get window 3 at all. | 690 // Connection 2 shouldn't be able to get window 3 at all. |
683 { | 691 { |
684 std::vector<TestWindow> windows; | 692 std::vector<TestWindow> windows; |
685 GetWindowTree(ws2(), window_3_3, &windows); | 693 GetWindowTree(ws2(), window_3_3, &windows); |
686 EXPECT_TRUE(windows.empty()); | 694 EXPECT_TRUE(windows.empty()); |
687 } | 695 } |
688 | 696 |
689 // Connection 1 should be able to see it all (its the root). | 697 // Connection 1 should be able to see it all (its the root). |
690 { | 698 { |
691 std::vector<TestWindow> windows; | 699 std::vector<TestWindow> windows; |
692 GetWindowTree(ws1(), window_1_1, &windows); | 700 GetWindowTree(ws1(), window_1_1, &windows); |
693 ASSERT_EQ(3u, windows.size()); | 701 ASSERT_EQ(3u, windows.size()); |
694 EXPECT_EQ(WindowParentToString(window_1_1, kNullParentId), | 702 EXPECT_EQ(WindowParentToString(window_1_1, kNullParentId), |
695 windows[0].ToString()); | 703 windows[0].ToString()); |
696 EXPECT_EQ(WindowParentToString(window_2_2, window_1_1), | 704 // NOTE: we expect a match of WindowParentToString(window_2_2, window_1_1), |
697 windows[1].ToString()); | 705 // but the ids are in the id space of client2, which is not the same as |
698 EXPECT_EQ(WindowParentToString(window_3_3, window_2_2), | 706 // the id space of ws1(). |
699 windows[2].ToString()); | 707 EXPECT_EQ("window=2,1 parent=1,1", windows[1].ToString()); |
| 708 // Same thing here, we really want to test for |
| 709 // WindowParentToString(window_3_3, window_2_2). |
| 710 EXPECT_EQ("window=3,1 parent=2,1", windows[2].ToString()); |
700 } | 711 } |
701 } | 712 } |
702 | 713 |
703 // Verifies once Embed() has been invoked the parent can't mutate the children. | 714 // Verifies once Embed() has been invoked the parent can't mutate the children. |
704 TEST_F(WindowTreeAppTest, CantModifyChildrenOfEmbeddedWindow) { | 715 TEST_F(WindowTreeAppTest, CantModifyChildrenOfEmbeddedWindow) { |
705 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); | 716 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); |
706 | 717 |
707 Id window_1_1 = BuildWindowId(connection_id_1(), 1); | 718 Id window_1_1 = BuildWindowId(connection_id_1(), 1); |
| 719 Id window_2_1 = ws_client2()->NewWindow(1); |
| 720 ASSERT_TRUE(window_2_1); |
| 721 ASSERT_TRUE(ws_client2()->AddWindow(window_1_1, window_2_1)); |
| 722 |
| 723 ASSERT_NO_FATAL_FAILURE(EstablishThirdConnection(ws2(), window_2_1)); |
| 724 |
708 Id window_2_2 = ws_client2()->NewWindow(2); | 725 Id window_2_2 = ws_client2()->NewWindow(2); |
709 ASSERT_TRUE(window_2_2); | 726 ASSERT_TRUE(window_2_2); |
710 ASSERT_TRUE(ws_client2()->AddWindow(window_1_1, window_2_2)); | |
711 | |
712 ASSERT_NO_FATAL_FAILURE(EstablishThirdConnection(ws2(), window_2_2)); | |
713 | |
714 Id window_2_3 = ws_client2()->NewWindow(3); | |
715 ASSERT_TRUE(window_2_3); | |
716 // Connection 2 shouldn't be able to add anything to the window anymore. | 727 // Connection 2 shouldn't be able to add anything to the window anymore. |
717 ASSERT_FALSE(ws_client2()->AddWindow(window_2_2, window_2_3)); | 728 ASSERT_FALSE(ws_client2()->AddWindow(window_2_1, window_2_2)); |
718 | 729 |
719 // Create window 3 in connection 3 and add it to window 3. | 730 // Create window 3 in connection 3 and add it to window 3. |
720 Id window_3_3 = ws_client3()->NewWindow(3); | 731 Id window_3_1 = ws_client3()->NewWindow(1); |
721 ASSERT_TRUE(window_3_3); | 732 ASSERT_TRUE(window_3_1); |
722 ASSERT_TRUE(ws_client3()->AddWindow(window_2_2, window_3_3)); | 733 ASSERT_TRUE(ws_client3()->AddWindow(window_2_1, window_3_1)); |
723 | 734 |
724 // Connection 2 shouldn't be able to remove window 3. | 735 // Connection 2 shouldn't be able to remove window 3. |
725 ASSERT_FALSE(ws_client2()->RemoveWindowFromParent(window_3_3)); | 736 ASSERT_FALSE(ws_client2()->RemoveWindowFromParent(window_3_1)); |
726 } | 737 } |
727 | 738 |
728 // Verifies client gets a valid id. | 739 // Verifies client gets a valid id. |
729 TEST_F(WindowTreeAppTest, NewWindow) { | 740 TEST_F(WindowTreeAppTest, NewWindow) { |
730 Id window_1_1 = ws_client1()->NewWindow(1); | 741 Id window_1_1 = ws_client1()->NewWindow(1); |
731 ASSERT_TRUE(window_1_1); | 742 ASSERT_TRUE(window_1_1); |
732 EXPECT_TRUE(changes1()->empty()); | 743 EXPECT_TRUE(changes1()->empty()); |
733 | 744 |
734 // Can't create a window with the same id. | 745 // Can't create a window with the same id. |
735 ASSERT_EQ(0u, ws_client1()->NewWindowWithCompleteId(window_1_1)); | 746 ASSERT_EQ(0u, ws_client1()->NewWindowWithCompleteId(window_1_1)); |
736 EXPECT_TRUE(changes1()->empty()); | 747 EXPECT_TRUE(changes1()->empty()); |
737 | 748 |
738 // Can't create a window with a bogus connection id. | 749 // Can't create a window with a bogus connection id. |
739 ASSERT_EQ(0u, ws_client1()->NewWindowWithCompleteId( | 750 ASSERT_EQ(0u, ws_client1()->NewWindowWithCompleteId( |
740 BuildWindowId(connection_id_1() + 1, 1))); | 751 BuildWindowId(connection_id_1() + 1, 1))); |
741 EXPECT_TRUE(changes1()->empty()); | 752 EXPECT_TRUE(changes1()->empty()); |
742 } | 753 } |
743 | 754 |
744 // Verifies AddWindow fails when window is already in position. | 755 // Verifies AddWindow fails when window is already in position. |
745 TEST_F(WindowTreeAppTest, AddWindowWithNoChange) { | 756 TEST_F(WindowTreeAppTest, AddWindowWithNoChange) { |
| 757 // Create the embed point now so that the ids line up. |
| 758 ASSERT_TRUE(ws_client1()->NewWindow(1)); |
746 Id window_1_2 = ws_client1()->NewWindow(2); | 759 Id window_1_2 = ws_client1()->NewWindow(2); |
747 Id window_1_3 = ws_client1()->NewWindow(3); | 760 Id window_1_3 = ws_client1()->NewWindow(3); |
748 ASSERT_TRUE(window_1_2); | 761 ASSERT_TRUE(window_1_2); |
749 ASSERT_TRUE(window_1_3); | 762 ASSERT_TRUE(window_1_3); |
750 | 763 |
751 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); | 764 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(false)); |
752 | 765 |
753 // Make 3 a child of 2. | 766 // Make 3 a child of 2. |
754 ASSERT_TRUE(ws_client1()->AddWindow(window_1_2, window_1_3)); | 767 ASSERT_TRUE(ws_client1()->AddWindow(window_1_2, window_1_3)); |
755 | 768 |
756 // Try again, this should fail. | 769 // Try again, this should fail. |
757 EXPECT_FALSE(ws_client1()->AddWindow(window_1_2, window_1_3)); | 770 EXPECT_FALSE(ws_client1()->AddWindow(window_1_2, window_1_3)); |
758 } | 771 } |
759 | 772 |
760 // Verifies AddWindow fails when window is already in position. | 773 // Verifies AddWindow fails when window is already in position. |
761 TEST_F(WindowTreeAppTest, AddAncestorFails) { | 774 TEST_F(WindowTreeAppTest, AddAncestorFails) { |
| 775 // Create the embed point now so that the ids line up. |
| 776 ASSERT_TRUE(ws_client1()->NewWindow(1)); |
762 Id window_1_2 = ws_client1()->NewWindow(2); | 777 Id window_1_2 = ws_client1()->NewWindow(2); |
763 Id window_1_3 = ws_client1()->NewWindow(3); | 778 Id window_1_3 = ws_client1()->NewWindow(3); |
764 ASSERT_TRUE(window_1_2); | 779 ASSERT_TRUE(window_1_2); |
765 ASSERT_TRUE(window_1_3); | 780 ASSERT_TRUE(window_1_3); |
766 | 781 |
767 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); | 782 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(false)); |
768 | 783 |
769 // Make 3 a child of 2. | 784 // Make 3 a child of 2. |
770 ASSERT_TRUE(ws_client1()->AddWindow(window_1_2, window_1_3)); | 785 ASSERT_TRUE(ws_client1()->AddWindow(window_1_2, window_1_3)); |
771 | 786 |
772 // Try to make 2 a child of 3, this should fail since 2 is an ancestor of 3. | 787 // Try to make 2 a child of 3, this should fail since 2 is an ancestor of 3. |
773 EXPECT_FALSE(ws_client1()->AddWindow(window_1_3, window_1_2)); | 788 EXPECT_FALSE(ws_client1()->AddWindow(window_1_3, window_1_2)); |
774 } | 789 } |
775 | 790 |
776 // Verifies adding to root sends right notifications. | 791 // Verifies adding to root sends right notifications. |
777 TEST_F(WindowTreeAppTest, AddToRoot) { | 792 TEST_F(WindowTreeAppTest, AddToRoot) { |
| 793 // Create the embed point now so that the ids line up. |
| 794 Id window_1_1 = ws_client1()->NewWindow(1); |
| 795 ASSERT_TRUE(window_1_1); |
778 Id window_1_21 = ws_client1()->NewWindow(21); | 796 Id window_1_21 = ws_client1()->NewWindow(21); |
779 Id window_1_3 = ws_client1()->NewWindow(3); | 797 Id window_1_3 = ws_client1()->NewWindow(3); |
780 ASSERT_TRUE(window_1_21); | 798 ASSERT_TRUE(window_1_21); |
781 ASSERT_TRUE(window_1_3); | 799 ASSERT_TRUE(window_1_3); |
782 | 800 |
783 Id window_1_1 = BuildWindowId(connection_id_1(), 1); | 801 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(false)); |
784 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); | |
785 changes2()->clear(); | 802 changes2()->clear(); |
786 | 803 |
787 // Make 3 a child of 21. | 804 // Make 3 a child of 21. |
788 ASSERT_TRUE(ws_client1()->AddWindow(window_1_21, window_1_3)); | 805 ASSERT_TRUE(ws_client1()->AddWindow(window_1_21, window_1_3)); |
789 | 806 |
790 // Make 21 a child of 1. | 807 // Make 21 a child of 1. |
791 ASSERT_TRUE(ws_client1()->AddWindow(window_1_1, window_1_21)); | 808 ASSERT_TRUE(ws_client1()->AddWindow(window_1_1, window_1_21)); |
792 | 809 |
793 // Connection 2 should not be told anything (because the window is from a | 810 // Connection 2 should not be told anything (because the window is from a |
794 // different connection). Create a window to ensure we got a response from | 811 // different connection). Create a window to ensure we got a response from |
795 // the server. | 812 // the server. |
796 ASSERT_TRUE(ws_client2()->NewWindow(100)); | 813 ASSERT_TRUE(ws_client2()->NewWindow(100)); |
797 EXPECT_TRUE(changes2()->empty()); | 814 EXPECT_TRUE(changes2()->empty()); |
798 } | 815 } |
799 | 816 |
800 // Verifies HierarchyChanged is correctly sent for various adds/removes. | 817 // Verifies HierarchyChanged is correctly sent for various adds/removes. |
801 TEST_F(WindowTreeAppTest, WindowHierarchyChangedWindows) { | 818 TEST_F(WindowTreeAppTest, WindowHierarchyChangedWindows) { |
| 819 // Create the embed point now so that the ids line up. |
| 820 Id window_1_1 = ws_client1()->NewWindow(1); |
802 // 1,2->1,11. | 821 // 1,2->1,11. |
803 Id window_1_2 = ws_client1()->NewWindow(2); | 822 Id window_1_2 = ws_client1()->NewWindow(2); |
804 ASSERT_TRUE(window_1_2); | 823 ASSERT_TRUE(window_1_2); |
805 ASSERT_TRUE(ws_client1()->SetWindowVisibility(window_1_2, true)); | 824 ASSERT_TRUE(ws_client1()->SetWindowVisibility(window_1_2, true)); |
806 Id window_1_11 = ws_client1()->NewWindow(11); | 825 Id window_1_11 = ws_client1()->NewWindow(11); |
807 ASSERT_TRUE(window_1_11); | 826 ASSERT_TRUE(window_1_11); |
808 ASSERT_TRUE(ws_client1()->SetWindowVisibility(window_1_11, true)); | 827 ASSERT_TRUE(ws_client1()->SetWindowVisibility(window_1_11, true)); |
809 ASSERT_TRUE(ws_client1()->AddWindow(window_1_2, window_1_11)); | 828 ASSERT_TRUE(ws_client1()->AddWindow(window_1_2, window_1_11)); |
810 | 829 |
811 Id window_1_1 = BuildWindowId(connection_id_1(), 1); | 830 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(false)); |
812 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); | |
813 ASSERT_TRUE(ws_client1()->SetWindowVisibility(window_1_1, true)); | 831 ASSERT_TRUE(ws_client1()->SetWindowVisibility(window_1_1, true)); |
814 | 832 |
815 ASSERT_TRUE(ws_client2()->WaitForAllMessages()); | 833 ASSERT_TRUE(ws_client2()->WaitForAllMessages()); |
816 changes2()->clear(); | 834 changes2()->clear(); |
817 | 835 |
818 // 1,1->1,2->1,11 | 836 // 1,1->1,2->1,11 |
819 { | 837 { |
820 // Client 2 should not get anything (1,2 is from another connection). | 838 // Client 2 should not get anything (1,2 is from another connection). |
821 ASSERT_TRUE(ws_client1()->AddWindow(window_1_1, window_1_2)); | 839 ASSERT_TRUE(ws_client1()->AddWindow(window_1_1, window_1_2)); |
822 ASSERT_TRUE(ws_client2()->WaitForAllMessages()); | 840 ASSERT_TRUE(ws_client2()->WaitForAllMessages()); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
885 ASSERT_TRUE(ws_client1()->AddWindow(root_window_id(), window_1_1)); | 903 ASSERT_TRUE(ws_client1()->AddWindow(root_window_id(), window_1_1)); |
886 ASSERT_TRUE(ws_client2()->AddWindow(window_1_1, window_2_11)); | 904 ASSERT_TRUE(ws_client2()->AddWindow(window_1_1, window_2_11)); |
887 ASSERT_TRUE(ws_client2()->AddWindow(window_2_2, window_2_21)); | 905 ASSERT_TRUE(ws_client2()->AddWindow(window_2_2, window_2_21)); |
888 | 906 |
889 // Remove 11, should result in a hierarchy change for the root. | 907 // Remove 11, should result in a hierarchy change for the root. |
890 { | 908 { |
891 changes1()->clear(); | 909 changes1()->clear(); |
892 ASSERT_TRUE(ws_client2()->RemoveWindowFromParent(window_2_11)); | 910 ASSERT_TRUE(ws_client2()->RemoveWindowFromParent(window_2_11)); |
893 | 911 |
894 ws_client1_->WaitForChangeCount(1); | 912 ws_client1_->WaitForChangeCount(1); |
895 EXPECT_EQ("HierarchyChanged window=" + IdToString(window_2_11) + | 913 // 2,1 should be IdToString(window_2_11), but window_2_11 is in the id |
896 " new_parent=null old_parent=" + IdToString(window_1_1), | 914 // space of client2, not client1. |
| 915 EXPECT_EQ("HierarchyChanged window=2,1 new_parent=null old_parent=" + |
| 916 IdToString(window_1_1), |
897 SingleChangeToDescription(*changes1())); | 917 SingleChangeToDescription(*changes1())); |
898 } | 918 } |
899 | 919 |
900 // Add 2 to 1. | 920 // Add 2 to 1. |
901 { | 921 { |
902 changes1()->clear(); | 922 changes1()->clear(); |
903 ASSERT_TRUE(ws_client2()->AddWindow(window_1_1, window_2_2)); | 923 ASSERT_TRUE(ws_client2()->AddWindow(window_1_1, window_2_2)); |
904 ws_client1_->WaitForChangeCount(1); | 924 ws_client1_->WaitForChangeCount(1); |
905 EXPECT_EQ("HierarchyChanged window=" + IdToString(window_2_2) + | 925 EXPECT_EQ("HierarchyChanged window=" + IdToString(window_2_2) + |
906 " new_parent=" + IdToString(window_1_1) + " old_parent=null", | 926 " new_parent=" + IdToString(window_1_1) + " old_parent=null", |
907 SingleChangeToDescription(*changes1())); | 927 SingleChangeToDescription(*changes1())); |
908 EXPECT_EQ("[" + WindowParentToString(window_2_2, window_1_1) + "],[" + | 928 // "window=2,3 parent=2,2]" should be, |
909 WindowParentToString(window_2_21, window_2_2) + "]", | 929 // WindowParentToString(window_2_21, window_2_2), but isn't because of |
| 930 // differing id spaces. |
| 931 EXPECT_EQ("[" + WindowParentToString(window_2_2, window_1_1) + |
| 932 "],[window=2,3 parent=2,2]", |
910 ChangeWindowDescription(*changes1())); | 933 ChangeWindowDescription(*changes1())); |
911 } | 934 } |
912 } | 935 } |
913 | 936 |
914 TEST_F(WindowTreeAppTest, ReorderWindow) { | 937 TEST_F(WindowTreeAppTest, ReorderWindow) { |
915 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); | 938 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); |
916 | 939 |
917 Id window_2_1 = ws_client2()->NewWindow(1); | 940 Id window_2_1 = ws_client2()->NewWindow(1); |
918 Id window_2_2 = ws_client2()->NewWindow(2); | 941 Id window_2_2 = ws_client2()->NewWindow(2); |
919 Id window_2_3 = ws_client2()->NewWindow(3); | 942 Id window_2_3 = ws_client2()->NewWindow(3); |
920 Id window_1_4 = ws_client1()->NewWindow(4); // Peer to 1,1 | 943 Id window_1_4 = ws_client1()->NewWindow(4); // Peer to 1,1 |
921 Id window_1_5 = ws_client1()->NewWindow(5); // Peer to 1,1 | 944 Id window_1_5 = ws_client1()->NewWindow(5); // Peer to 1,1 |
922 Id window_2_6 = ws_client2()->NewWindow(6); // Child of 1,2. | 945 Id window_2_6 = ws_client2()->NewWindow(6); // Child of 1,2. |
923 Id window_2_7 = ws_client2()->NewWindow(7); // Unparented. | 946 Id window_2_7 = ws_client2()->NewWindow(7); // Unparented. |
924 Id window_2_8 = ws_client2()->NewWindow(8); // Unparented. | 947 Id window_2_8 = ws_client2()->NewWindow(8); // Unparented. |
925 ASSERT_TRUE(window_2_1); | 948 ASSERT_TRUE(window_2_1); |
926 ASSERT_TRUE(window_2_2); | 949 ASSERT_TRUE(window_2_2); |
927 ASSERT_TRUE(window_2_3); | 950 ASSERT_TRUE(window_2_3); |
928 ASSERT_TRUE(window_1_4); | 951 ASSERT_TRUE(window_1_4); |
929 ASSERT_TRUE(window_1_5); | 952 ASSERT_TRUE(window_1_5); |
930 ASSERT_TRUE(window_2_6); | 953 ASSERT_TRUE(window_2_6); |
931 ASSERT_TRUE(window_2_7); | 954 ASSERT_TRUE(window_2_7); |
932 ASSERT_TRUE(window_2_8); | 955 ASSERT_TRUE(window_2_8); |
933 | 956 |
934 ASSERT_TRUE(ws_client2()->AddWindow(window_2_1, window_2_2)); | 957 ASSERT_TRUE(ws_client2()->AddWindow(window_2_1, window_2_2)); |
935 ASSERT_TRUE(ws_client2()->AddWindow(window_2_2, window_2_6)); | 958 ASSERT_TRUE(ws_client2()->AddWindow(window_2_2, window_2_6)); |
936 ASSERT_TRUE(ws_client2()->AddWindow(window_2_1, window_2_3)); | 959 ASSERT_TRUE(ws_client2()->AddWindow(window_2_1, window_2_3)); |
937 ASSERT_TRUE(ws_client1()->AddWindow(root_window_id(), window_1_4)); | 960 ASSERT_TRUE(ws_client1()->AddWindow(root_window_id(), window_1_4)); |
938 ASSERT_TRUE(ws_client1()->AddWindow(root_window_id(), window_1_5)); | 961 ASSERT_TRUE(ws_client1()->AddWindow(root_window_id(), window_1_5)); |
939 ASSERT_TRUE(ws_client1()->AddWindow(root_window_id(), window_2_1)); | 962 ASSERT_TRUE( |
| 963 ws_client2()->AddWindow(BuildWindowId(connection_id_1(), 1), window_2_1)); |
940 | 964 |
941 { | 965 { |
942 changes1()->clear(); | 966 changes1()->clear(); |
943 ASSERT_TRUE(ws_client2()->ReorderWindow(window_2_2, window_2_3, | 967 ASSERT_TRUE(ws_client2()->ReorderWindow(window_2_2, window_2_3, |
944 mojom::OrderDirection::ABOVE)); | 968 mojom::OrderDirection::ABOVE)); |
945 | 969 |
946 ws_client1_->WaitForChangeCount(1); | 970 ws_client1_->WaitForChangeCount(1); |
947 EXPECT_EQ("Reordered window=" + IdToString(window_2_2) + " relative=" + | 971 EXPECT_EQ("Reordered window=" + IdToString(window_2_2) + " relative=" + |
948 IdToString(window_2_3) + " direction=above", | 972 IdToString(window_2_3) + " direction=above", |
949 SingleChangeToDescription(*changes1())); | 973 SingleChangeToDescription(*changes1())); |
(...skipping 29 matching lines...) Expand all Loading... |
979 | 1003 |
980 // view7 & view8 are un-parented. | 1004 // view7 & view8 are un-parented. |
981 EXPECT_FALSE(ws_client1()->ReorderWindow(window_2_7, window_2_8, | 1005 EXPECT_FALSE(ws_client1()->ReorderWindow(window_2_7, window_2_8, |
982 mojom::OrderDirection::ABOVE)); | 1006 mojom::OrderDirection::ABOVE)); |
983 } | 1007 } |
984 | 1008 |
985 // Verifies DeleteWindow works. | 1009 // Verifies DeleteWindow works. |
986 TEST_F(WindowTreeAppTest, DeleteWindow) { | 1010 TEST_F(WindowTreeAppTest, DeleteWindow) { |
987 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); | 1011 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); |
988 Id window_1_1 = BuildWindowId(connection_id_1(), 1); | 1012 Id window_1_1 = BuildWindowId(connection_id_1(), 1); |
989 Id window_2_2 = ws_client2()->NewWindow(2); | 1013 Id window_2_1 = ws_client2()->NewWindow(1); |
990 ASSERT_TRUE(window_2_2); | 1014 ASSERT_TRUE(window_2_1); |
991 | 1015 |
992 // Make 2 a child of 1. | 1016 // Make 2 a child of 1. |
993 { | 1017 { |
994 changes1()->clear(); | 1018 changes1()->clear(); |
995 ASSERT_TRUE(ws_client2()->AddWindow(window_1_1, window_2_2)); | 1019 ASSERT_TRUE(ws_client2()->AddWindow(window_1_1, window_2_1)); |
996 ws_client1_->WaitForChangeCount(1); | 1020 ws_client1_->WaitForChangeCount(1); |
997 EXPECT_EQ("HierarchyChanged window=" + IdToString(window_2_2) + | 1021 EXPECT_EQ("HierarchyChanged window=" + IdToString(window_2_1) + |
998 " new_parent=" + IdToString(window_1_1) + " old_parent=null", | 1022 " new_parent=" + IdToString(window_1_1) + " old_parent=null", |
999 SingleChangeToDescription(*changes1())); | 1023 SingleChangeToDescription(*changes1())); |
1000 } | 1024 } |
1001 | 1025 |
1002 // Delete 2. | 1026 // Delete 2. |
1003 { | 1027 { |
1004 changes1()->clear(); | 1028 changes1()->clear(); |
1005 changes2()->clear(); | 1029 changes2()->clear(); |
1006 ASSERT_TRUE(ws_client2()->DeleteWindow(window_2_2)); | 1030 ASSERT_TRUE(ws_client2()->DeleteWindow(window_2_1)); |
1007 EXPECT_TRUE(changes2()->empty()); | 1031 EXPECT_TRUE(changes2()->empty()); |
1008 | 1032 |
1009 ws_client1_->WaitForChangeCount(1); | 1033 ws_client1_->WaitForChangeCount(1); |
1010 EXPECT_EQ("WindowDeleted window=" + IdToString(window_2_2), | 1034 EXPECT_EQ("WindowDeleted window=" + IdToString(window_2_1), |
1011 SingleChangeToDescription(*changes1())); | 1035 SingleChangeToDescription(*changes1())); |
1012 } | 1036 } |
1013 } | 1037 } |
1014 | 1038 |
1015 // Verifies DeleteWindow isn't allowed from a separate connection. | 1039 // Verifies DeleteWindow isn't allowed from a separate connection. |
1016 TEST_F(WindowTreeAppTest, DeleteWindowFromAnotherConnectionDisallowed) { | 1040 TEST_F(WindowTreeAppTest, DeleteWindowFromAnotherConnectionDisallowed) { |
1017 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); | 1041 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); |
1018 EXPECT_FALSE(ws_client2()->DeleteWindow(BuildWindowId(connection_id_1(), 1))); | 1042 EXPECT_FALSE(ws_client2()->DeleteWindow(BuildWindowId(connection_id_1(), 1))); |
1019 } | 1043 } |
1020 | 1044 |
1021 // Verifies if a window was deleted and then reused that other clients are | 1045 // Verifies if a window was deleted and then reused that other clients are |
1022 // properly notified. | 1046 // properly notified. |
1023 TEST_F(WindowTreeAppTest, ReuseDeletedWindowId) { | 1047 TEST_F(WindowTreeAppTest, ReuseDeletedWindowId) { |
1024 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); | 1048 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); |
1025 Id window_1_1 = BuildWindowId(connection_id_1(), 1); | 1049 Id window_1_1 = BuildWindowId(connection_id_1(), 1); |
1026 Id window_2_2 = ws_client2()->NewWindow(2); | 1050 Id window_2_1 = ws_client2()->NewWindow(1); |
1027 ASSERT_TRUE(window_2_2); | 1051 ASSERT_TRUE(window_2_1); |
1028 | 1052 |
1029 // Add 2 to 1. | 1053 // Add 2 to 1. |
1030 { | 1054 { |
1031 changes1()->clear(); | 1055 changes1()->clear(); |
1032 ASSERT_TRUE(ws_client2()->AddWindow(window_1_1, window_2_2)); | 1056 ASSERT_TRUE(ws_client2()->AddWindow(window_1_1, window_2_1)); |
1033 ws_client1_->WaitForChangeCount(1); | 1057 ws_client1_->WaitForChangeCount(1); |
1034 EXPECT_EQ("HierarchyChanged window=" + IdToString(window_2_2) + | 1058 EXPECT_EQ("HierarchyChanged window=" + IdToString(window_2_1) + |
1035 " new_parent=" + IdToString(window_1_1) + " old_parent=null", | 1059 " new_parent=" + IdToString(window_1_1) + " old_parent=null", |
1036 SingleChangeToDescription(*changes1())); | 1060 SingleChangeToDescription(*changes1())); |
1037 EXPECT_EQ("[" + WindowParentToString(window_2_2, window_1_1) + "]", | 1061 EXPECT_EQ("[" + WindowParentToString(window_2_1, window_1_1) + "]", |
1038 ChangeWindowDescription(*changes1())); | 1062 ChangeWindowDescription(*changes1())); |
1039 } | 1063 } |
1040 | 1064 |
1041 // Delete 2. | 1065 // Delete 2. |
1042 { | 1066 { |
1043 changes1()->clear(); | 1067 changes1()->clear(); |
1044 ASSERT_TRUE(ws_client2()->DeleteWindow(window_2_2)); | 1068 ASSERT_TRUE(ws_client2()->DeleteWindow(window_2_1)); |
1045 | 1069 |
1046 ws_client1_->WaitForChangeCount(1); | 1070 ws_client1_->WaitForChangeCount(1); |
1047 EXPECT_EQ("WindowDeleted window=" + IdToString(window_2_2), | 1071 EXPECT_EQ("WindowDeleted window=" + IdToString(window_2_1), |
1048 SingleChangeToDescription(*changes1())); | 1072 SingleChangeToDescription(*changes1())); |
1049 } | 1073 } |
1050 | 1074 |
1051 // Create 2 again, and add it back to 1. Should get the same notification. | 1075 // Create 2 again, and add it back to 1. Should get the same notification. |
1052 window_2_2 = ws_client2()->NewWindow(2); | 1076 window_2_1 = ws_client2()->NewWindow(2); |
1053 ASSERT_TRUE(window_2_2); | 1077 ASSERT_TRUE(window_2_1); |
1054 { | 1078 { |
1055 changes1()->clear(); | 1079 changes1()->clear(); |
1056 ASSERT_TRUE(ws_client2()->AddWindow(window_1_1, window_2_2)); | 1080 ASSERT_TRUE(ws_client2()->AddWindow(window_1_1, window_2_1)); |
1057 | 1081 |
1058 ws_client1_->WaitForChangeCount(1); | 1082 ws_client1_->WaitForChangeCount(1); |
1059 EXPECT_EQ("HierarchyChanged window=" + IdToString(window_2_2) + | 1083 EXPECT_EQ("HierarchyChanged window=" + IdToString(window_2_1) + |
1060 " new_parent=" + IdToString(window_1_1) + " old_parent=null", | 1084 " new_parent=" + IdToString(window_1_1) + " old_parent=null", |
1061 SingleChangeToDescription(*changes1())); | 1085 SingleChangeToDescription(*changes1())); |
1062 EXPECT_EQ("[" + WindowParentToString(window_2_2, window_1_1) + "]", | 1086 EXPECT_EQ("[" + WindowParentToString(window_2_1, window_1_1) + "]", |
1063 ChangeWindowDescription(*changes1())); | 1087 ChangeWindowDescription(*changes1())); |
1064 } | 1088 } |
1065 } | 1089 } |
1066 | 1090 |
1067 // Assertions for GetWindowTree. | 1091 // Assertions for GetWindowTree. |
1068 TEST_F(WindowTreeAppTest, GetWindowTree) { | 1092 TEST_F(WindowTreeAppTest, GetWindowTree) { |
1069 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); | 1093 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); |
1070 Id window_1_1 = BuildWindowId(connection_id_1(), 1); | 1094 Id window_1_1 = BuildWindowId(connection_id_1(), 1); |
1071 | 1095 |
1072 // Create 11 in first connection and make it a child of 1. | 1096 // Create 11 in first connection and make it a child of 1. |
1073 Id window_1_11 = ws_client1()->NewWindow(11); | 1097 Id window_1_11 = ws_client1()->NewWindow(11); |
1074 ASSERT_TRUE(window_1_11); | 1098 ASSERT_TRUE(window_1_11); |
1075 ASSERT_TRUE(ws_client1()->AddWindow(root_window_id(), window_1_1)); | 1099 ASSERT_TRUE(ws_client1()->AddWindow(root_window_id(), window_1_1)); |
1076 ASSERT_TRUE(ws_client1()->AddWindow(window_1_1, window_1_11)); | 1100 ASSERT_TRUE(ws_client1()->AddWindow(window_1_1, window_1_11)); |
1077 | 1101 |
1078 // Create two windows in second connection, 2 and 3, both children of 1. | 1102 // Create two windows in second connection, 2 and 3, both children of 1. |
| 1103 Id window_2_1 = ws_client2()->NewWindow(1); |
1079 Id window_2_2 = ws_client2()->NewWindow(2); | 1104 Id window_2_2 = ws_client2()->NewWindow(2); |
1080 Id window_2_3 = ws_client2()->NewWindow(3); | 1105 ASSERT_TRUE(window_2_1); |
1081 ASSERT_TRUE(window_2_2); | 1106 ASSERT_TRUE(window_2_2); |
1082 ASSERT_TRUE(window_2_3); | 1107 ASSERT_TRUE(ws_client2()->AddWindow(window_1_1, window_2_1)); |
1083 ASSERT_TRUE(ws_client2()->AddWindow(window_1_1, window_2_2)); | 1108 ASSERT_TRUE(ws_client2()->AddWindow(window_1_1, window_2_2)); |
1084 ASSERT_TRUE(ws_client2()->AddWindow(window_1_1, window_2_3)); | |
1085 | 1109 |
1086 // Verifies GetWindowTree() on the root. The root connection sees all. | 1110 // Verifies GetWindowTree() on the root. The root connection sees all. |
1087 { | 1111 { |
1088 std::vector<TestWindow> windows; | 1112 std::vector<TestWindow> windows; |
1089 GetWindowTree(ws1(), root_window_id(), &windows); | 1113 GetWindowTree(ws1(), root_window_id(), &windows); |
1090 ASSERT_EQ(5u, windows.size()); | 1114 ASSERT_EQ(5u, windows.size()); |
1091 EXPECT_EQ(WindowParentToString(root_window_id(), kNullParentId), | 1115 EXPECT_EQ(WindowParentToString(root_window_id(), kNullParentId), |
1092 windows[0].ToString()); | 1116 windows[0].ToString()); |
1093 EXPECT_EQ(WindowParentToString(window_1_1, root_window_id()), | 1117 EXPECT_EQ(WindowParentToString(window_1_1, root_window_id()), |
1094 windows[1].ToString()); | 1118 windows[1].ToString()); |
1095 EXPECT_EQ(WindowParentToString(window_1_11, window_1_1), | 1119 EXPECT_EQ(WindowParentToString(window_1_11, window_1_1), |
1096 windows[2].ToString()); | 1120 windows[2].ToString()); |
| 1121 EXPECT_EQ(WindowParentToString(window_2_1, window_1_1), |
| 1122 windows[3].ToString()); |
1097 EXPECT_EQ(WindowParentToString(window_2_2, window_1_1), | 1123 EXPECT_EQ(WindowParentToString(window_2_2, window_1_1), |
1098 windows[3].ToString()); | |
1099 EXPECT_EQ(WindowParentToString(window_2_3, window_1_1), | |
1100 windows[4].ToString()); | 1124 windows[4].ToString()); |
1101 } | 1125 } |
1102 | 1126 |
1103 // Verifies GetWindowTree() on the window 1,1 from ws2(). ws2() sees 1,1 as | 1127 // Verifies GetWindowTree() on the window 1,1 from ws2(). ws2() sees 1,1 as |
1104 // 1,1 | 1128 // 1,1 |
1105 // is ws2()'s root and ws2() sees all the windows it created. | 1129 // is ws2()'s root and ws2() sees all the windows it created. |
1106 { | 1130 { |
1107 std::vector<TestWindow> windows; | 1131 std::vector<TestWindow> windows; |
1108 GetWindowTree(ws2(), window_1_1, &windows); | 1132 GetWindowTree(ws2(), window_1_1, &windows); |
1109 ASSERT_EQ(3u, windows.size()); | 1133 ASSERT_EQ(3u, windows.size()); |
1110 EXPECT_EQ(WindowParentToString(window_1_1, kNullParentId), | 1134 EXPECT_EQ(WindowParentToString(window_1_1, kNullParentId), |
1111 windows[0].ToString()); | 1135 windows[0].ToString()); |
| 1136 EXPECT_EQ(WindowParentToString(window_2_1, window_1_1), |
| 1137 windows[1].ToString()); |
1112 EXPECT_EQ(WindowParentToString(window_2_2, window_1_1), | 1138 EXPECT_EQ(WindowParentToString(window_2_2, window_1_1), |
1113 windows[1].ToString()); | |
1114 EXPECT_EQ(WindowParentToString(window_2_3, window_1_1), | |
1115 windows[2].ToString()); | 1139 windows[2].ToString()); |
1116 } | 1140 } |
1117 | 1141 |
1118 // Connection 2 shouldn't be able to get the root tree. | 1142 // Connection 2 shouldn't be able to get the root tree. |
1119 { | 1143 { |
1120 std::vector<TestWindow> windows; | 1144 std::vector<TestWindow> windows; |
1121 GetWindowTree(ws2(), root_window_id(), &windows); | 1145 GetWindowTree(ws2(), root_window_id(), &windows); |
1122 ASSERT_EQ(0u, windows.size()); | 1146 ASSERT_EQ(0u, windows.size()); |
1123 } | 1147 } |
1124 } | 1148 } |
1125 | 1149 |
1126 TEST_F(WindowTreeAppTest, SetWindowBounds) { | 1150 TEST_F(WindowTreeAppTest, SetWindowBounds) { |
1127 Id window_1_1 = ws_client1()->NewWindow(1); | 1151 Id window_1_1 = ws_client1()->NewWindow(1); |
1128 ASSERT_TRUE(window_1_1); | 1152 ASSERT_TRUE(window_1_1); |
1129 ASSERT_TRUE(ws_client1()->AddWindow(root_window_id(), window_1_1)); | 1153 ASSERT_TRUE(ws_client1()->AddWindow(root_window_id(), window_1_1)); |
1130 | 1154 |
1131 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(false)); | 1155 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(false)); |
1132 | 1156 |
1133 changes2()->clear(); | 1157 changes2()->clear(); |
1134 | 1158 |
| 1159 ws_client2_->set_track_root_bounds_changes(true); |
| 1160 |
1135 ws1()->SetWindowBounds(10, window_1_1, | 1161 ws1()->SetWindowBounds(10, window_1_1, |
1136 mojo::Rect::From(gfx::Rect(0, 0, 100, 100))); | 1162 mojo::Rect::From(gfx::Rect(0, 0, 100, 100))); |
1137 ASSERT_TRUE(ws_client1()->WaitForChangeCompleted(10)); | 1163 ASSERT_TRUE(ws_client1()->WaitForChangeCompleted(10)); |
1138 | 1164 |
1139 ws_client2_->WaitForChangeCount(1); | 1165 ws_client2_->WaitForChangeCount(1); |
1140 EXPECT_EQ("BoundsChanged window=" + IdToString(window_1_1) + | 1166 EXPECT_EQ("BoundsChanged window=" + IdToString(window_1_1) + |
1141 " old_bounds=0,0 0x0 new_bounds=0,0 100x100", | 1167 " old_bounds=0,0 0x0 new_bounds=0,0 100x100", |
1142 SingleChangeToDescription(*changes2())); | 1168 SingleChangeToDescription(*changes2())); |
1143 | 1169 |
1144 // Should not be possible to change the bounds of a window created by another | 1170 // Should not be possible to change the bounds of a window created by another |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1435 Id window_1_2 = ws_client1()->NewWindow(2); | 1461 Id window_1_2 = ws_client1()->NewWindow(2); |
1436 ASSERT_TRUE(window_1_2); | 1462 ASSERT_TRUE(window_1_2); |
1437 ASSERT_TRUE(ws_client1()->SetWindowVisibility(window_1_2, true)); | 1463 ASSERT_TRUE(ws_client1()->SetWindowVisibility(window_1_2, true)); |
1438 ASSERT_TRUE(ws_client1()->AddWindow(root_window_id(), window_1_1)); | 1464 ASSERT_TRUE(ws_client1()->AddWindow(root_window_id(), window_1_1)); |
1439 ASSERT_TRUE(ws_client1()->AddWindow(window_1_1, window_1_2)); | 1465 ASSERT_TRUE(ws_client1()->AddWindow(window_1_1, window_1_2)); |
1440 | 1466 |
1441 // Establish the second connection at 1,2. | 1467 // Establish the second connection at 1,2. |
1442 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnectionWithRoot(window_1_2)); | 1468 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnectionWithRoot(window_1_2)); |
1443 | 1469 |
1444 // Add 2,3 as a child of 1,2. | 1470 // Add 2,3 as a child of 1,2. |
1445 Id window_2_3 = ws_client2()->NewWindow(3); | 1471 Id window_2_1 = ws_client2()->NewWindow(1); |
1446 ASSERT_TRUE(window_2_3); | 1472 ASSERT_TRUE(window_2_1); |
1447 ASSERT_TRUE(ws_client2()->SetWindowVisibility(window_2_3, true)); | 1473 ASSERT_TRUE(ws_client2()->SetWindowVisibility(window_2_1, true)); |
1448 ASSERT_TRUE(ws_client2()->AddWindow(window_1_2, window_2_3)); | 1474 ASSERT_TRUE(ws_client2()->AddWindow(window_1_2, window_2_1)); |
1449 ASSERT_TRUE(ws_client1()->WaitForAllMessages()); | 1475 ASSERT_TRUE(ws_client1()->WaitForAllMessages()); |
1450 | 1476 |
1451 changes2()->clear(); | 1477 changes2()->clear(); |
1452 // Hide 1,2 from connection 1. Connection 2 should see this. | 1478 // Hide 1,2 from connection 1. Connection 2 should see this. |
1453 ASSERT_TRUE(ws_client1()->SetWindowVisibility(window_1_2, false)); | 1479 ASSERT_TRUE(ws_client1()->SetWindowVisibility(window_1_2, false)); |
1454 { | 1480 { |
1455 ws_client2_->WaitForChangeCount(1); | 1481 ws_client2_->WaitForChangeCount(1); |
1456 EXPECT_EQ( | 1482 EXPECT_EQ( |
1457 "VisibilityChanged window=" + IdToString(window_1_2) + " visible=false", | 1483 "VisibilityChanged window=" + IdToString(window_1_2) + " visible=false", |
1458 SingleChangeToDescription(*changes2())); | 1484 SingleChangeToDescription(*changes2())); |
(...skipping 24 matching lines...) Expand all Loading... |
1483 ASSERT_TRUE(ws_client1()->SetWindowVisibility(window_1_1, true)); | 1509 ASSERT_TRUE(ws_client1()->SetWindowVisibility(window_1_1, true)); |
1484 { | 1510 { |
1485 ws_client2_->WaitForChangeCount(1); | 1511 ws_client2_->WaitForChangeCount(1); |
1486 EXPECT_EQ( | 1512 EXPECT_EQ( |
1487 "DrawnStateChanged window=" + IdToString(window_1_2) + " drawn=true", | 1513 "DrawnStateChanged window=" + IdToString(window_1_2) + " drawn=true", |
1488 SingleChangeToDescription(*changes2())); | 1514 SingleChangeToDescription(*changes2())); |
1489 } | 1515 } |
1490 | 1516 |
1491 // Change visibility of 2,3, connection 1 should see this. | 1517 // Change visibility of 2,3, connection 1 should see this. |
1492 changes1()->clear(); | 1518 changes1()->clear(); |
1493 ASSERT_TRUE(ws_client2()->SetWindowVisibility(window_2_3, false)); | 1519 ASSERT_TRUE(ws_client2()->SetWindowVisibility(window_2_1, false)); |
1494 { | 1520 { |
1495 ws_client1_->WaitForChangeCount(1); | 1521 ws_client1_->WaitForChangeCount(1); |
1496 EXPECT_EQ( | 1522 EXPECT_EQ( |
1497 "VisibilityChanged window=" + IdToString(window_2_3) + " visible=false", | 1523 "VisibilityChanged window=" + IdToString(window_2_1) + " visible=false", |
1498 SingleChangeToDescription(*changes1())); | 1524 SingleChangeToDescription(*changes1())); |
1499 } | 1525 } |
1500 | 1526 |
1501 changes2()->clear(); | 1527 changes2()->clear(); |
1502 // Remove 1,1 from the root, connection 2 should see drawn state changed. | 1528 // Remove 1,1 from the root, connection 2 should see drawn state changed. |
1503 ASSERT_TRUE(ws_client1()->RemoveWindowFromParent(window_1_1)); | 1529 ASSERT_TRUE(ws_client1()->RemoveWindowFromParent(window_1_1)); |
1504 { | 1530 { |
1505 ws_client2_->WaitForChangeCount(1); | 1531 ws_client2_->WaitForChangeCount(1); |
1506 EXPECT_EQ( | 1532 EXPECT_EQ( |
1507 "DrawnStateChanged window=" + IdToString(window_1_2) + " drawn=false", | 1533 "DrawnStateChanged window=" + IdToString(window_1_2) + " drawn=false", |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1564 EXPECT_EQ("PropertyChanged window=" + IdToString(window_1_1) + | 1590 EXPECT_EQ("PropertyChanged window=" + IdToString(window_1_1) + |
1565 " key=one value=NULL", | 1591 " key=one value=NULL", |
1566 SingleChangeToDescription(*changes2())); | 1592 SingleChangeToDescription(*changes2())); |
1567 } | 1593 } |
1568 } | 1594 } |
1569 | 1595 |
1570 TEST_F(WindowTreeAppTest, OnEmbeddedAppDisconnected) { | 1596 TEST_F(WindowTreeAppTest, OnEmbeddedAppDisconnected) { |
1571 // Create connection 2 and 3. | 1597 // Create connection 2 and 3. |
1572 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); | 1598 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); |
1573 Id window_1_1 = BuildWindowId(connection_id_1(), 1); | 1599 Id window_1_1 = BuildWindowId(connection_id_1(), 1); |
1574 Id window_2_2 = ws_client2()->NewWindow(2); | 1600 Id window_2_1 = ws_client2()->NewWindow(1); |
1575 ASSERT_TRUE(window_2_2); | 1601 ASSERT_TRUE(window_2_1); |
1576 ASSERT_TRUE(ws_client2()->AddWindow(window_1_1, window_2_2)); | 1602 ASSERT_TRUE(ws_client2()->AddWindow(window_1_1, window_2_1)); |
1577 changes2()->clear(); | 1603 changes2()->clear(); |
1578 ASSERT_NO_FATAL_FAILURE(EstablishThirdConnection(ws2(), window_2_2)); | 1604 ASSERT_NO_FATAL_FAILURE(EstablishThirdConnection(ws2(), window_2_1)); |
1579 | 1605 |
1580 // Connection 1 should get a hierarchy change for window_2_2. | 1606 // Connection 1 should get a hierarchy change for window_2_1. |
1581 ws_client1_->WaitForChangeCount(1); | 1607 ws_client1_->WaitForChangeCount(1); |
1582 changes1()->clear(); | 1608 changes1()->clear(); |
1583 | 1609 |
1584 // Close connection 3. Connection 2 (which had previously embedded 3) should | 1610 // Close connection 3. Connection 2 (which had previously embedded 3) should |
1585 // be notified of this. | 1611 // be notified of this. |
1586 ws_client3_.reset(); | 1612 ws_client3_.reset(); |
1587 ws_client2_->WaitForChangeCount(1); | 1613 ws_client2_->WaitForChangeCount(1); |
1588 EXPECT_EQ("OnEmbeddedAppDisconnected window=" + IdToString(window_2_2), | 1614 EXPECT_EQ("OnEmbeddedAppDisconnected window=" + IdToString(window_2_1), |
1589 SingleChangeToDescription(*changes2())); | 1615 SingleChangeToDescription(*changes2())); |
1590 | 1616 |
1591 ws_client1_->WaitForChangeCount(1); | 1617 ws_client1_->WaitForChangeCount(1); |
1592 EXPECT_EQ("OnEmbeddedAppDisconnected window=" + IdToString(window_2_2), | 1618 EXPECT_EQ("OnEmbeddedAppDisconnected window=" + IdToString(window_2_1), |
1593 SingleChangeToDescription(*changes1())); | 1619 SingleChangeToDescription(*changes1())); |
1594 } | 1620 } |
1595 | 1621 |
1596 // Verifies when the parent of an Embed() is destroyed the embedded app gets | 1622 // Verifies when the parent of an Embed() is destroyed the embedded app gets |
1597 // a WindowDeleted (and doesn't trigger a DCHECK). | 1623 // a WindowDeleted (and doesn't trigger a DCHECK). |
1598 TEST_F(WindowTreeAppTest, OnParentOfEmbedDisconnects) { | 1624 TEST_F(WindowTreeAppTest, OnParentOfEmbedDisconnects) { |
1599 // Create connection 2 and 3. | 1625 // Create connection 2 and 3. |
1600 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); | 1626 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); |
1601 Id window_1_1 = BuildWindowId(connection_id_1(), 1); | 1627 Id window_1_1 = BuildWindowId(connection_id_1(), 1); |
1602 ASSERT_TRUE(ws_client1()->AddWindow(root_window_id(), window_1_1)); | 1628 ASSERT_TRUE(ws_client1()->AddWindow(root_window_id(), window_1_1)); |
| 1629 Id window_2_1 = ws_client2()->NewWindow(1); |
1603 Id window_2_2 = ws_client2()->NewWindow(2); | 1630 Id window_2_2 = ws_client2()->NewWindow(2); |
1604 Id window_2_3 = ws_client2()->NewWindow(3); | 1631 ASSERT_TRUE(window_2_1); |
1605 ASSERT_TRUE(window_2_2); | 1632 ASSERT_TRUE(window_2_2); |
1606 ASSERT_TRUE(window_2_3); | 1633 ASSERT_TRUE(ws_client2()->AddWindow(window_1_1, window_2_1)); |
1607 ASSERT_TRUE(ws_client2()->AddWindow(window_1_1, window_2_2)); | 1634 ASSERT_TRUE(ws_client2()->AddWindow(window_2_1, window_2_2)); |
1608 ASSERT_TRUE(ws_client2()->AddWindow(window_2_2, window_2_3)); | |
1609 changes2()->clear(); | 1635 changes2()->clear(); |
1610 ASSERT_NO_FATAL_FAILURE(EstablishThirdConnection(ws2(), window_2_3)); | 1636 ASSERT_NO_FATAL_FAILURE(EstablishThirdConnection(ws2(), window_2_2)); |
1611 changes3()->clear(); | 1637 changes3()->clear(); |
1612 | 1638 |
1613 // Close connection 2. Connection 3 should get a delete (for its root). | 1639 // Close connection 2. Connection 3 should get a delete (for its root). |
1614 ws_client2_.reset(); | 1640 ws_client2_.reset(); |
1615 ws_client3_->WaitForChangeCount(1); | 1641 ws_client3_->WaitForChangeCount(1); |
1616 EXPECT_EQ("WindowDeleted window=" + IdToString(window_2_3), | 1642 EXPECT_EQ("WindowDeleted window=" + IdToString(window_2_2), |
1617 SingleChangeToDescription(*changes3())); | 1643 SingleChangeToDescription(*changes3())); |
1618 } | 1644 } |
1619 | 1645 |
1620 // Verifies WindowTreeImpl doesn't incorrectly erase from its internal | 1646 // Verifies WindowTreeImpl doesn't incorrectly erase from its internal |
1621 // map when a window from another connection with the same window_id is removed. | 1647 // map when a window from another connection with the same window_id is removed. |
1622 TEST_F(WindowTreeAppTest, DontCleanMapOnDestroy) { | 1648 TEST_F(WindowTreeAppTest, DontCleanMapOnDestroy) { |
1623 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); | 1649 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); |
1624 Id window_1_1 = BuildWindowId(connection_id_1(), 1); | 1650 Id window_1_1 = BuildWindowId(connection_id_1(), 1); |
1625 ASSERT_TRUE(ws_client2()->NewWindow(1)); | 1651 ASSERT_TRUE(ws_client2()->NewWindow(1)); |
1626 changes1()->clear(); | 1652 changes1()->clear(); |
(...skipping 17 matching lines...) Expand all Loading... |
1644 std::move(client2_ptr))); | 1670 std::move(client2_ptr))); |
1645 client2.WaitForOnEmbed(); | 1671 client2.WaitForOnEmbed(); |
1646 EXPECT_EQ("OnEmbed", | 1672 EXPECT_EQ("OnEmbed", |
1647 SingleChangeToDescription(*client2.tracker()->changes())); | 1673 SingleChangeToDescription(*client2.tracker()->changes())); |
1648 } | 1674 } |
1649 | 1675 |
1650 TEST_F(WindowTreeAppTest, EmbedFailsFromOtherConnection) { | 1676 TEST_F(WindowTreeAppTest, EmbedFailsFromOtherConnection) { |
1651 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); | 1677 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); |
1652 | 1678 |
1653 Id window_1_1 = BuildWindowId(connection_id_1(), 1); | 1679 Id window_1_1 = BuildWindowId(connection_id_1(), 1); |
1654 Id window_2_2 = ws_client2()->NewWindow(2); | 1680 Id window_2_1 = ws_client2()->NewWindow(1); |
1655 ASSERT_TRUE(window_2_2); | 1681 ASSERT_TRUE(window_2_1); |
1656 ASSERT_TRUE(ws_client2()->AddWindow(window_1_1, window_2_2)); | 1682 ASSERT_TRUE(ws_client2()->AddWindow(window_1_1, window_2_1)); |
1657 ASSERT_NO_FATAL_FAILURE(EstablishThirdConnection(ws2(), window_2_2)); | 1683 ASSERT_NO_FATAL_FAILURE(EstablishThirdConnection(ws2(), window_2_1)); |
1658 | 1684 |
1659 Id window_3_3 = ws_client3()->NewWindow(3); | 1685 Id window_3_3 = ws_client3()->NewWindow(3); |
1660 ASSERT_TRUE(window_3_3); | 1686 ASSERT_TRUE(window_3_3); |
1661 ASSERT_TRUE(ws_client3()->AddWindow(window_2_2, window_3_3)); | 1687 ASSERT_TRUE(ws_client3()->AddWindow(window_2_1, window_3_3)); |
1662 | 1688 |
1663 // 2 should not be able to embed in window_3_3 as window_3_3 was not created | 1689 // 2 should not be able to embed in window_3_3 as window_3_3 was not created |
1664 // by | 1690 // by |
1665 // 2. | 1691 // 2. |
1666 EXPECT_FALSE(EmbedUrl(application_impl(), ws2(), application_impl()->url(), | 1692 EXPECT_FALSE(EmbedUrl(application_impl(), ws2(), application_impl()->url(), |
1667 window_3_3)); | 1693 window_3_3)); |
1668 } | 1694 } |
1669 | 1695 |
1670 // Verifies Embed() from window manager on another connections window works. | 1696 // Verifies Embed() from window manager on another connections window works. |
1671 TEST_F(WindowTreeAppTest, EmbedFromOtherConnection) { | 1697 TEST_F(WindowTreeAppTest, EmbedFromOtherConnection) { |
1672 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); | 1698 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); |
1673 | 1699 |
1674 Id window_1_1 = BuildWindowId(connection_id_1(), 1); | 1700 Id window_1_1 = BuildWindowId(connection_id_1(), 1); |
1675 Id window_2_2 = ws_client2()->NewWindow(2); | 1701 Id window_2_1 = ws_client2()->NewWindow(1); |
1676 ASSERT_TRUE(window_2_2); | 1702 ASSERT_TRUE(window_2_1); |
1677 ASSERT_TRUE(ws_client2()->AddWindow(window_1_1, window_2_2)); | 1703 ASSERT_TRUE(ws_client2()->AddWindow(window_1_1, window_2_1)); |
1678 | 1704 |
1679 changes2()->clear(); | 1705 changes2()->clear(); |
1680 | 1706 |
1681 // Establish a third connection in window_2_2. | 1707 // Establish a third connection in window_2_1. |
1682 ASSERT_NO_FATAL_FAILURE(EstablishThirdConnection(ws1(), window_2_2)); | 1708 ASSERT_NO_FATAL_FAILURE(EstablishThirdConnection(ws1(), window_2_1)); |
1683 | 1709 |
1684 ASSERT_TRUE(ws_client2()->WaitForAllMessages()); | 1710 ASSERT_TRUE(ws_client2()->WaitForAllMessages()); |
1685 EXPECT_EQ(std::string(), SingleChangeToDescription(*changes2())); | 1711 EXPECT_EQ(std::string(), SingleChangeToDescription(*changes2())); |
1686 } | 1712 } |
1687 | 1713 |
1688 TEST_F(WindowTreeAppTest, CantEmbedFromConnectionRoot) { | 1714 TEST_F(WindowTreeAppTest, CantEmbedFromConnectionRoot) { |
1689 // Shouldn't be able to embed into the root. | 1715 // Shouldn't be able to embed into the root. |
1690 ASSERT_FALSE(EmbedUrl(application_impl(), ws1(), application_impl()->url(), | 1716 ASSERT_FALSE(EmbedUrl(application_impl(), ws1(), application_impl()->url(), |
1691 root_window_id())); | 1717 root_window_id())); |
1692 | 1718 |
(...skipping 11 matching lines...) Expand all Loading... |
1704 WaitForWindowTreeClient(); | 1730 WaitForWindowTreeClient(); |
1705 | 1731 |
1706 Id window_1_2 = ws_client1()->NewWindow(2); | 1732 Id window_1_2 = ws_client1()->NewWindow(2); |
1707 ASSERT_TRUE(window_1_2); | 1733 ASSERT_TRUE(window_1_2); |
1708 ASSERT_TRUE( | 1734 ASSERT_TRUE( |
1709 ws_client1()->AddWindow(BuildWindowId(connection_id_1(), 1), window_1_2)); | 1735 ws_client1()->AddWindow(BuildWindowId(connection_id_1(), 1), window_1_2)); |
1710 ASSERT_TRUE(ws_client3_.get() == nullptr); | 1736 ASSERT_TRUE(ws_client3_.get() == nullptr); |
1711 ws_client3_ = EstablishConnectionViaEmbedWithPolicyBitmask( | 1737 ws_client3_ = EstablishConnectionViaEmbedWithPolicyBitmask( |
1712 ws1(), window_1_2, mojom::WindowTree::kAccessPolicyEmbedRoot, nullptr); | 1738 ws1(), window_1_2, mojom::WindowTree::kAccessPolicyEmbedRoot, nullptr); |
1713 ASSERT_TRUE(ws_client3_.get() != nullptr); | 1739 ASSERT_TRUE(ws_client3_.get() != nullptr); |
1714 ws_client3_->set_root_window(root_window_id()); | |
1715 | 1740 |
1716 // window_1_2 is ws3's root, so even though v3 is an embed root it should not | 1741 // window_1_2 is ws3's root, so even though v3 is an embed root it should not |
1717 // be able to Embed into itself. | 1742 // be able to Embed into itself. |
1718 ASSERT_FALSE(EmbedUrl(application_impl(), ws3(), application_impl()->url(), | 1743 ASSERT_FALSE(EmbedUrl(application_impl(), ws3(), application_impl()->url(), |
1719 window_1_2)); | 1744 window_1_2)); |
1720 } | 1745 } |
1721 | 1746 |
1722 // Verifies that a transient window tracks its parent's lifetime. | 1747 // Verifies that a transient window tracks its parent's lifetime. |
1723 TEST_F(WindowTreeAppTest, TransientWindowTracksTransientParentLifetime) { | 1748 TEST_F(WindowTreeAppTest, TransientWindowTracksTransientParentLifetime) { |
1724 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); | 1749 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1758 | 1783 |
1759 changes1()->clear(); | 1784 changes1()->clear(); |
1760 ASSERT_TRUE(ws_client2()->DeleteWindow(window_2_1)); | 1785 ASSERT_TRUE(ws_client2()->DeleteWindow(window_2_1)); |
1761 ws_client1()->WaitForChangeCount(2); | 1786 ws_client1()->WaitForChangeCount(2); |
1762 EXPECT_EQ("WindowDeleted window=" + IdToString(window_2_2), | 1787 EXPECT_EQ("WindowDeleted window=" + IdToString(window_2_2), |
1763 ChangesToDescription1(*changes1())[0]); | 1788 ChangesToDescription1(*changes1())[0]); |
1764 EXPECT_EQ("WindowDeleted window=" + IdToString(window_2_1), | 1789 EXPECT_EQ("WindowDeleted window=" + IdToString(window_2_1), |
1765 ChangesToDescription1(*changes1())[1]); | 1790 ChangesToDescription1(*changes1())[1]); |
1766 } | 1791 } |
1767 | 1792 |
| 1793 TEST_F(WindowTreeAppTest, Ids) { |
| 1794 const Id window_1_100 = ws_client1()->NewWindow(100); |
| 1795 ASSERT_TRUE(window_1_100); |
| 1796 ASSERT_TRUE(ws_client1()->AddWindow(root_window_id(), window_1_100)); |
| 1797 |
| 1798 // Establish the second connection at 1,100. |
| 1799 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnectionWithRoot(window_1_100)); |
| 1800 |
| 1801 // 1,100 is the id in the ws_client1's id space. The new client should see |
| 1802 // 2,1 (the server id). |
| 1803 const Id window_1_100_in_ws2 = BuildWindowId(connection_id_1(), 1); |
| 1804 EXPECT_EQ(window_1_100_in_ws2, ws_client2()->root_window_id()); |
| 1805 |
| 1806 // The first window created in the second connection gets a server id of 2,1 |
| 1807 // regardless of the id the client uses. |
| 1808 const Id window_2_101 = ws_client2()->NewWindow(101); |
| 1809 ASSERT_TRUE(ws_client2()->AddWindow(window_1_100_in_ws2, window_2_101)); |
| 1810 const Id window_2_101_in_ws1 = BuildWindowId(connection_id_2(), 1); |
| 1811 ws_client1()->WaitForChangeCount(1); |
| 1812 EXPECT_EQ("HierarchyChanged window=" + IdToString(window_2_101_in_ws1) + |
| 1813 " new_parent=" + IdToString(window_1_100) + " old_parent=null", |
| 1814 SingleChangeToDescription(*changes1())); |
| 1815 changes1()->clear(); |
| 1816 |
| 1817 // Change the bounds of window_2_101 and make sure server gets it. |
| 1818 ws2()->SetWindowBounds(11, window_2_101, |
| 1819 mojo::Rect::From(gfx::Rect(1, 2, 3, 4))); |
| 1820 ASSERT_TRUE(ws_client2()->WaitForChangeCompleted(11)); |
| 1821 ws_client1()->WaitForChangeCount(1); |
| 1822 EXPECT_EQ("BoundsChanged window=" + IdToString(window_2_101_in_ws1) + |
| 1823 " old_bounds=0,0 0x0 new_bounds=1,2 3x4", |
| 1824 SingleChangeToDescription(*changes1())); |
| 1825 changes2()->clear(); |
| 1826 |
| 1827 // Remove 2_101 from wm, client1 should see the change. |
| 1828 ws1()->RemoveWindowFromParent(12, window_2_101_in_ws1); |
| 1829 ASSERT_TRUE(ws_client1()->WaitForChangeCompleted(12)); |
| 1830 ws_client2()->WaitForChangeCount(1); |
| 1831 EXPECT_EQ("HierarchyChanged window=" + IdToString(window_2_101) + |
| 1832 " new_parent=null old_parent=" + |
| 1833 IdToString(window_1_100_in_ws2), |
| 1834 SingleChangeToDescription(*changes2())); |
| 1835 } |
| 1836 |
1768 // TODO(sky): need to better track changes to initial connection. For example, | 1837 // TODO(sky): need to better track changes to initial connection. For example, |
1769 // that SetBounsdWindows/AddWindow and the like don't result in messages to the | 1838 // that SetBounsdWindows/AddWindow and the like don't result in messages to the |
1770 // originating connection. | 1839 // originating connection. |
1771 | 1840 |
1772 // TODO(sky): make sure coverage of what was | 1841 // TODO(sky): make sure coverage of what was |
1773 // WindowManagerTest.SecondEmbedRoot_InitService and | 1842 // WindowManagerTest.SecondEmbedRoot_InitService and |
1774 // WindowManagerTest.MultipleEmbedRootsBeforeWTHReady gets added to window | 1843 // WindowManagerTest.MultipleEmbedRootsBeforeWTHReady gets added to window |
1775 // manager | 1844 // manager |
1776 // tests. | 1845 // tests. |
1777 | 1846 |
1778 } // namespace ws | 1847 } // namespace ws |
1779 } // namespace mus | 1848 } // namespace mus |
OLD | NEW |