| 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 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 411 } | 411 } |
| 412 void OnAccelerator(uint32_t id, mojom::EventPtr event) override { | 412 void OnAccelerator(uint32_t id, mojom::EventPtr event) override { |
| 413 NOTIMPLEMENTED(); | 413 NOTIMPLEMENTED(); |
| 414 } | 414 } |
| 415 | 415 |
| 416 TestChangeTracker tracker_; | 416 TestChangeTracker tracker_; |
| 417 | 417 |
| 418 mojom::WindowTreePtr tree_; | 418 mojom::WindowTreePtr tree_; |
| 419 | 419 |
| 420 // If non-null we're waiting for OnEmbed() using this RunLoop. | 420 // If non-null we're waiting for OnEmbed() using this RunLoop. |
| 421 scoped_ptr<base::RunLoop> embed_run_loop_; | 421 std::unique_ptr<base::RunLoop> embed_run_loop_; |
| 422 | 422 |
| 423 // If non-null we're waiting for a certain number of change notifications to | 423 // If non-null we're waiting for a certain number of change notifications to |
| 424 // be encountered. | 424 // be encountered. |
| 425 scoped_ptr<WaitState> wait_state_; | 425 std::unique_ptr<WaitState> wait_state_; |
| 426 | 426 |
| 427 mojo::Binding<WindowTreeClient> binding_; | 427 mojo::Binding<WindowTreeClient> binding_; |
| 428 Id connection_id_; | 428 Id connection_id_; |
| 429 Id root_window_id_; | 429 Id root_window_id_; |
| 430 uint32_t next_change_id_; | 430 uint32_t next_change_id_; |
| 431 uint32_t waiting_change_id_; | 431 uint32_t waiting_change_id_; |
| 432 bool on_change_completed_result_; | 432 bool on_change_completed_result_; |
| 433 bool track_root_bounds_changes_; | 433 bool track_root_bounds_changes_; |
| 434 scoped_ptr<base::RunLoop> change_completed_run_loop_; | 434 std::unique_ptr<base::RunLoop> change_completed_run_loop_; |
| 435 | 435 |
| 436 scoped_ptr<mojo::AssociatedBinding<mojom::WindowManager>> | 436 std::unique_ptr<mojo::AssociatedBinding<mojom::WindowManager>> |
| 437 window_manager_binding_; | 437 window_manager_binding_; |
| 438 mojom::WindowManagerClientAssociatedPtr window_manager_client_; | 438 mojom::WindowManagerClientAssociatedPtr window_manager_client_; |
| 439 | 439 |
| 440 DISALLOW_COPY_AND_ASSIGN(TestWindowTreeClientImpl); | 440 DISALLOW_COPY_AND_ASSIGN(TestWindowTreeClientImpl); |
| 441 }; | 441 }; |
| 442 | 442 |
| 443 // ----------------------------------------------------------------------------- | 443 // ----------------------------------------------------------------------------- |
| 444 | 444 |
| 445 // InterfaceFactory for vending TestWindowTreeClientImpls. | 445 // InterfaceFactory for vending TestWindowTreeClientImpls. |
| 446 class WindowTreeClientFactory | 446 class WindowTreeClientFactory |
| 447 : public shell::InterfaceFactory<WindowTreeClient> { | 447 : public shell::InterfaceFactory<WindowTreeClient> { |
| 448 public: | 448 public: |
| 449 WindowTreeClientFactory() {} | 449 WindowTreeClientFactory() {} |
| 450 ~WindowTreeClientFactory() override {} | 450 ~WindowTreeClientFactory() override {} |
| 451 | 451 |
| 452 // Runs a nested MessageLoop until a new instance has been created. | 452 // Runs a nested MessageLoop until a new instance has been created. |
| 453 scoped_ptr<TestWindowTreeClientImpl> WaitForInstance() { | 453 std::unique_ptr<TestWindowTreeClientImpl> WaitForInstance() { |
| 454 if (!client_impl_.get()) { | 454 if (!client_impl_.get()) { |
| 455 DCHECK(!run_loop_); | 455 DCHECK(!run_loop_); |
| 456 run_loop_.reset(new base::RunLoop); | 456 run_loop_.reset(new base::RunLoop); |
| 457 run_loop_->Run(); | 457 run_loop_->Run(); |
| 458 run_loop_.reset(); | 458 run_loop_.reset(); |
| 459 } | 459 } |
| 460 return std::move(client_impl_); | 460 return std::move(client_impl_); |
| 461 } | 461 } |
| 462 | 462 |
| 463 private: | 463 private: |
| 464 // InterfaceFactory<WindowTreeClient>: | 464 // InterfaceFactory<WindowTreeClient>: |
| 465 void Create(Connection* connection, | 465 void Create(Connection* connection, |
| 466 InterfaceRequest<WindowTreeClient> request) override { | 466 InterfaceRequest<WindowTreeClient> request) override { |
| 467 client_impl_.reset(new TestWindowTreeClientImpl()); | 467 client_impl_.reset(new TestWindowTreeClientImpl()); |
| 468 client_impl_->Bind(std::move(request)); | 468 client_impl_->Bind(std::move(request)); |
| 469 if (run_loop_.get()) | 469 if (run_loop_.get()) |
| 470 run_loop_->Quit(); | 470 run_loop_->Quit(); |
| 471 } | 471 } |
| 472 | 472 |
| 473 scoped_ptr<TestWindowTreeClientImpl> client_impl_; | 473 std::unique_ptr<TestWindowTreeClientImpl> client_impl_; |
| 474 scoped_ptr<base::RunLoop> run_loop_; | 474 std::unique_ptr<base::RunLoop> run_loop_; |
| 475 | 475 |
| 476 DISALLOW_COPY_AND_ASSIGN(WindowTreeClientFactory); | 476 DISALLOW_COPY_AND_ASSIGN(WindowTreeClientFactory); |
| 477 }; | 477 }; |
| 478 | 478 |
| 479 } // namespace | 479 } // namespace |
| 480 | 480 |
| 481 class WindowTreeClientTest : public WindowServerShellTestBase { | 481 class WindowTreeClientTest : public WindowServerShellTestBase { |
| 482 public: | 482 public: |
| 483 WindowTreeClientTest() | 483 WindowTreeClientTest() |
| 484 : connection_id_1_(0), connection_id_2_(0), root_window_id_(0) {} | 484 : connection_id_1_(0), connection_id_2_(0), root_window_id_(0) {} |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 528 ChangeWindowDescription(*changes2())); | 528 ChangeWindowDescription(*changes2())); |
| 529 } | 529 } |
| 530 } | 530 } |
| 531 | 531 |
| 532 void EstablishThirdConnection(WindowTree* owner, Id root_id) { | 532 void EstablishThirdConnection(WindowTree* owner, Id root_id) { |
| 533 ASSERT_TRUE(wt_client3_.get() == nullptr); | 533 ASSERT_TRUE(wt_client3_.get() == nullptr); |
| 534 wt_client3_ = EstablishConnectionViaEmbed(owner, root_id, nullptr); | 534 wt_client3_ = EstablishConnectionViaEmbed(owner, root_id, nullptr); |
| 535 ASSERT_TRUE(wt_client3_.get() != nullptr); | 535 ASSERT_TRUE(wt_client3_.get() != nullptr); |
| 536 } | 536 } |
| 537 | 537 |
| 538 scoped_ptr<TestWindowTreeClientImpl> WaitForWindowTreeClient() { | 538 std::unique_ptr<TestWindowTreeClientImpl> WaitForWindowTreeClient() { |
| 539 return client_factory_->WaitForInstance(); | 539 return client_factory_->WaitForInstance(); |
| 540 } | 540 } |
| 541 | 541 |
| 542 // Establishes a new connection by way of Embed() on the specified | 542 // Establishes a new connection by way of Embed() on the specified |
| 543 // WindowTree. | 543 // WindowTree. |
| 544 scoped_ptr<TestWindowTreeClientImpl> EstablishConnectionViaEmbed( | 544 std::unique_ptr<TestWindowTreeClientImpl> EstablishConnectionViaEmbed( |
| 545 WindowTree* owner, | 545 WindowTree* owner, |
| 546 Id root_id, | 546 Id root_id, |
| 547 int* connection_id) { | 547 int* connection_id) { |
| 548 return EstablishConnectionViaEmbedWithPolicyBitmask(owner, root_id, | 548 return EstablishConnectionViaEmbedWithPolicyBitmask(owner, root_id, |
| 549 connection_id); | 549 connection_id); |
| 550 } | 550 } |
| 551 | 551 |
| 552 scoped_ptr<TestWindowTreeClientImpl> | 552 std::unique_ptr<TestWindowTreeClientImpl> |
| 553 EstablishConnectionViaEmbedWithPolicyBitmask(WindowTree* owner, | 553 EstablishConnectionViaEmbedWithPolicyBitmask(WindowTree* owner, |
| 554 Id root_id, | 554 Id root_id, |
| 555 int* connection_id) { | 555 int* connection_id) { |
| 556 if (!EmbedUrl(connector(), owner, test_name(), root_id)) { | 556 if (!EmbedUrl(connector(), owner, test_name(), root_id)) { |
| 557 ADD_FAILURE() << "Embed() failed"; | 557 ADD_FAILURE() << "Embed() failed"; |
| 558 return nullptr; | 558 return nullptr; |
| 559 } | 559 } |
| 560 scoped_ptr<TestWindowTreeClientImpl> client = | 560 std::unique_ptr<TestWindowTreeClientImpl> client = |
| 561 client_factory_->WaitForInstance(); | 561 client_factory_->WaitForInstance(); |
| 562 if (!client.get()) { | 562 if (!client.get()) { |
| 563 ADD_FAILURE() << "WaitForInstance failed"; | 563 ADD_FAILURE() << "WaitForInstance failed"; |
| 564 return nullptr; | 564 return nullptr; |
| 565 } | 565 } |
| 566 client->WaitForOnEmbed(); | 566 client->WaitForOnEmbed(); |
| 567 | 567 |
| 568 EXPECT_EQ("OnEmbed", | 568 EXPECT_EQ("OnEmbed", |
| 569 SingleChangeToDescription(*client->tracker()->changes())); | 569 SingleChangeToDescription(*client->tracker()->changes())); |
| 570 if (connection_id) | 570 if (connection_id) |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 612 void TearDown() override { | 612 void TearDown() override { |
| 613 // Destroy these before the message loop is destroyed (happens in | 613 // Destroy these before the message loop is destroyed (happens in |
| 614 // WindowServerShellTestBase::TearDown). | 614 // WindowServerShellTestBase::TearDown). |
| 615 wt_client1_.reset(); | 615 wt_client1_.reset(); |
| 616 wt_client2_.reset(); | 616 wt_client2_.reset(); |
| 617 wt_client3_.reset(); | 617 wt_client3_.reset(); |
| 618 client_factory_.reset(); | 618 client_factory_.reset(); |
| 619 WindowServerShellTestBase::TearDown(); | 619 WindowServerShellTestBase::TearDown(); |
| 620 } | 620 } |
| 621 | 621 |
| 622 scoped_ptr<TestWindowTreeClientImpl> wt_client1_; | 622 std::unique_ptr<TestWindowTreeClientImpl> wt_client1_; |
| 623 scoped_ptr<TestWindowTreeClientImpl> wt_client2_; | 623 std::unique_ptr<TestWindowTreeClientImpl> wt_client2_; |
| 624 scoped_ptr<TestWindowTreeClientImpl> wt_client3_; | 624 std::unique_ptr<TestWindowTreeClientImpl> wt_client3_; |
| 625 | 625 |
| 626 mojom::WindowTreeHostPtr host_; | 626 mojom::WindowTreeHostPtr host_; |
| 627 | 627 |
| 628 private: | 628 private: |
| 629 scoped_ptr<WindowTreeClientFactory> client_factory_; | 629 std::unique_ptr<WindowTreeClientFactory> client_factory_; |
| 630 int connection_id_1_; | 630 int connection_id_1_; |
| 631 int connection_id_2_; | 631 int connection_id_2_; |
| 632 Id root_window_id_; | 632 Id root_window_id_; |
| 633 | 633 |
| 634 DISALLOW_COPY_AND_ASSIGN(WindowTreeClientTest); | 634 DISALLOW_COPY_AND_ASSIGN(WindowTreeClientTest); |
| 635 }; | 635 }; |
| 636 | 636 |
| 637 // Verifies two clients/connections get different ids. | 637 // Verifies two clients/connections get different ids. |
| 638 TEST_F(WindowTreeClientTest, TwoClientsGetDifferentConnectionIds) { | 638 TEST_F(WindowTreeClientTest, TwoClientsGetDifferentConnectionIds) { |
| 639 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); | 639 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); |
| (...skipping 723 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1363 EXPECT_EQ("HierarchyChanged window=" + IdToString(window_3_1) + | 1363 EXPECT_EQ("HierarchyChanged window=" + IdToString(window_3_1) + |
| 1364 " old_parent=null new_parent=" + IdToString(window_1_1), | 1364 " old_parent=null new_parent=" + IdToString(window_1_1), |
| 1365 SingleChangeToDescription(*changes1())); | 1365 SingleChangeToDescription(*changes1())); |
| 1366 } | 1366 } |
| 1367 | 1367 |
| 1368 // Embed 1,1 again. | 1368 // Embed 1,1 again. |
| 1369 { | 1369 { |
| 1370 changes3()->clear(); | 1370 changes3()->clear(); |
| 1371 | 1371 |
| 1372 // We should get a new connection for the new embedding. | 1372 // We should get a new connection for the new embedding. |
| 1373 scoped_ptr<TestWindowTreeClientImpl> connection4( | 1373 std::unique_ptr<TestWindowTreeClientImpl> connection4( |
| 1374 EstablishConnectionViaEmbed(wt1(), window_1_1, nullptr)); | 1374 EstablishConnectionViaEmbed(wt1(), window_1_1, nullptr)); |
| 1375 ASSERT_TRUE(connection4.get()); | 1375 ASSERT_TRUE(connection4.get()); |
| 1376 EXPECT_EQ("[" + WindowParentToString(window_1_1, kNullParentId) + "]", | 1376 EXPECT_EQ("[" + WindowParentToString(window_1_1, kNullParentId) + "]", |
| 1377 ChangeWindowDescription(*connection4->tracker()->changes())); | 1377 ChangeWindowDescription(*connection4->tracker()->changes())); |
| 1378 | 1378 |
| 1379 // And 3 should get an unembed and delete. | 1379 // And 3 should get an unembed and delete. |
| 1380 wt_client3_->WaitForChangeCount(2); | 1380 wt_client3_->WaitForChangeCount(2); |
| 1381 EXPECT_EQ("OnUnembed window=" + IdToString(window_1_1), | 1381 EXPECT_EQ("OnUnembed window=" + IdToString(window_1_1), |
| 1382 ChangesToDescription1(*changes3())[0]); | 1382 ChangesToDescription1(*changes3())[0]); |
| 1383 EXPECT_EQ("WindowDeleted window=" + IdToString(window_1_1), | 1383 EXPECT_EQ("WindowDeleted window=" + IdToString(window_1_1), |
| (...skipping 649 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2033 | 2033 |
| 2034 // TODO(sky): make sure coverage of what was | 2034 // TODO(sky): make sure coverage of what was |
| 2035 // WindowManagerTest.SecondEmbedRoot_InitService and | 2035 // WindowManagerTest.SecondEmbedRoot_InitService and |
| 2036 // WindowManagerTest.MultipleEmbedRootsBeforeWTHReady gets added to window | 2036 // WindowManagerTest.MultipleEmbedRootsBeforeWTHReady gets added to window |
| 2037 // manager | 2037 // manager |
| 2038 // tests. | 2038 // tests. |
| 2039 | 2039 |
| 2040 } // namespace test | 2040 } // namespace test |
| 2041 } // namespace ws | 2041 } // namespace ws |
| 2042 } // namespace mus | 2042 } // namespace mus |
| OLD | NEW |