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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 void EmbedCallbackImpl(base::RunLoop* run_loop, | 56 void EmbedCallbackImpl(base::RunLoop* run_loop, |
57 bool* result_cache, | 57 bool* result_cache, |
58 bool result, | 58 bool result, |
59 ConnectionSpecificId connection_id) { | 59 ConnectionSpecificId connection_id) { |
60 *result_cache = result; | 60 *result_cache = result; |
61 run_loop->Quit(); | 61 run_loop->Quit(); |
62 } | 62 } |
63 | 63 |
64 // ----------------------------------------------------------------------------- | 64 // ----------------------------------------------------------------------------- |
65 | 65 |
66 bool EmbedUrl(mojo::Shell* shell, | 66 bool EmbedUrl(mojo::Connector* connector, |
67 WindowTree* ws, | 67 WindowTree* ws, |
68 const String& url, | 68 const String& url, |
69 Id root_id) { | 69 Id root_id) { |
70 bool result = false; | 70 bool result = false; |
71 base::RunLoop run_loop; | 71 base::RunLoop run_loop; |
72 { | 72 { |
73 mojom::WindowTreeClientPtr client; | 73 mojom::WindowTreeClientPtr client; |
74 shell->ConnectToInterface(url.get(), &client); | 74 connector->ConnectToInterface(url.get(), &client); |
75 ws->Embed(root_id, std::move(client), | 75 ws->Embed(root_id, std::move(client), |
76 mojom::WindowTree::kAccessPolicyDefault, | 76 mojom::WindowTree::kAccessPolicyDefault, |
77 base::Bind(&EmbedCallbackImpl, &run_loop, &result)); | 77 base::Bind(&EmbedCallbackImpl, &run_loop, &result)); |
78 } | 78 } |
79 run_loop.Run(); | 79 run_loop.Run(); |
80 return result; | 80 return result; |
81 } | 81 } |
82 | 82 |
83 bool Embed(WindowTree* ws, Id root_id, mojom::WindowTreeClientPtr client) { | 83 bool Embed(WindowTree* ws, Id root_id, mojom::WindowTreeClientPtr client) { |
84 bool result = false; | 84 bool result = false; |
(...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
540 int* connection_id) { | 540 int* connection_id) { |
541 return EstablishConnectionViaEmbedWithPolicyBitmask( | 541 return EstablishConnectionViaEmbedWithPolicyBitmask( |
542 owner, root_id, mojom::WindowTree::kAccessPolicyDefault, connection_id); | 542 owner, root_id, mojom::WindowTree::kAccessPolicyDefault, connection_id); |
543 } | 543 } |
544 | 544 |
545 scoped_ptr<TestWindowTreeClientImpl> | 545 scoped_ptr<TestWindowTreeClientImpl> |
546 EstablishConnectionViaEmbedWithPolicyBitmask(WindowTree* owner, | 546 EstablishConnectionViaEmbedWithPolicyBitmask(WindowTree* owner, |
547 Id root_id, | 547 Id root_id, |
548 uint32_t policy_bitmask, | 548 uint32_t policy_bitmask, |
549 int* connection_id) { | 549 int* connection_id) { |
550 if (!EmbedUrl(shell(), owner, shell_url(), root_id)) { | 550 if (!EmbedUrl(connector(), owner, test_url(), root_id)) { |
551 ADD_FAILURE() << "Embed() failed"; | 551 ADD_FAILURE() << "Embed() failed"; |
552 return nullptr; | 552 return nullptr; |
553 } | 553 } |
554 scoped_ptr<TestWindowTreeClientImpl> client = | 554 scoped_ptr<TestWindowTreeClientImpl> client = |
555 client_factory_->WaitForInstance(); | 555 client_factory_->WaitForInstance(); |
556 if (!client.get()) { | 556 if (!client.get()) { |
557 ADD_FAILURE() << "WaitForInstance failed"; | 557 ADD_FAILURE() << "WaitForInstance failed"; |
558 return nullptr; | 558 return nullptr; |
559 } | 559 } |
560 client->WaitForOnEmbed(); | 560 client->WaitForOnEmbed(); |
561 | 561 |
562 EXPECT_EQ("OnEmbed", | 562 EXPECT_EQ("OnEmbed", |
563 SingleChangeToDescription(*client->tracker()->changes())); | 563 SingleChangeToDescription(*client->tracker()->changes())); |
564 if (connection_id) | 564 if (connection_id) |
565 *connection_id = (*client->tracker()->changes())[0].connection_id; | 565 *connection_id = (*client->tracker()->changes())[0].connection_id; |
566 return client; | 566 return client; |
567 } | 567 } |
568 | 568 |
569 // ApplicationTestBase: | 569 // ApplicationTestBase: |
570 mojo::ShellClient* GetShellClient() override { return this; } | 570 mojo::ShellClient* GetShellClient() override { return this; } |
571 void SetUp() override { | 571 void SetUp() override { |
572 ApplicationTestBase::SetUp(); | 572 ApplicationTestBase::SetUp(); |
573 client_factory_.reset(new WindowTreeClientFactory()); | 573 client_factory_.reset(new WindowTreeClientFactory()); |
574 | 574 |
575 mojom::WindowTreeHostFactoryPtr factory; | 575 mojom::WindowTreeHostFactoryPtr factory; |
576 shell()->ConnectToInterface("mojo:mus", &factory); | 576 connector()->ConnectToInterface("mojo:mus", &factory); |
577 | 577 |
578 mojom::WindowTreeClientPtr tree_client_ptr; | 578 mojom::WindowTreeClientPtr tree_client_ptr; |
579 ws_client1_.reset(new TestWindowTreeClientImpl()); | 579 ws_client1_.reset(new TestWindowTreeClientImpl()); |
580 ws_client1_->Bind(GetProxy(&tree_client_ptr)); | 580 ws_client1_->Bind(GetProxy(&tree_client_ptr)); |
581 | 581 |
582 factory->CreateWindowTreeHost(GetProxy(&host_), | 582 factory->CreateWindowTreeHost(GetProxy(&host_), |
583 std::move(tree_client_ptr)); | 583 std::move(tree_client_ptr)); |
584 | 584 |
585 // Next we should get an embed call on the "window manager" client. | 585 // Next we should get an embed call on the "window manager" client. |
586 ws_client1_->WaitForIncomingMethodCall(); | 586 ws_client1_->WaitForIncomingMethodCall(); |
(...skipping 1130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1717 ASSERT_TRUE(ws_client2()->AddWindow(window_1_1, window_2_1)); | 1717 ASSERT_TRUE(ws_client2()->AddWindow(window_1_1, window_2_1)); |
1718 ASSERT_NO_FATAL_FAILURE(EstablishThirdConnection(ws2(), window_2_1)); | 1718 ASSERT_NO_FATAL_FAILURE(EstablishThirdConnection(ws2(), window_2_1)); |
1719 | 1719 |
1720 Id window_3_3 = ws_client3()->NewWindow(3); | 1720 Id window_3_3 = ws_client3()->NewWindow(3); |
1721 ASSERT_TRUE(window_3_3); | 1721 ASSERT_TRUE(window_3_3); |
1722 ASSERT_TRUE(ws_client3()->AddWindow(window_2_1, window_3_3)); | 1722 ASSERT_TRUE(ws_client3()->AddWindow(window_2_1, window_3_3)); |
1723 | 1723 |
1724 // 2 should not be able to embed in window_3_3 as window_3_3 was not created | 1724 // 2 should not be able to embed in window_3_3 as window_3_3 was not created |
1725 // by | 1725 // by |
1726 // 2. | 1726 // 2. |
1727 EXPECT_FALSE(EmbedUrl(shell(), ws2(), shell_url(), window_3_3)); | 1727 EXPECT_FALSE(EmbedUrl(connector(), ws2(), test_url(), window_3_3)); |
1728 } | 1728 } |
1729 | 1729 |
1730 // Verifies Embed() from window manager on another connections window works. | 1730 // Verifies Embed() from window manager on another connections window works. |
1731 TEST_F(WindowTreeAppTest, EmbedFromOtherConnection) { | 1731 TEST_F(WindowTreeAppTest, EmbedFromOtherConnection) { |
1732 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); | 1732 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); |
1733 | 1733 |
1734 Id window_1_1 = BuildWindowId(connection_id_1(), 1); | 1734 Id window_1_1 = BuildWindowId(connection_id_1(), 1); |
1735 Id window_2_1 = ws_client2()->NewWindow(1); | 1735 Id window_2_1 = ws_client2()->NewWindow(1); |
1736 ASSERT_TRUE(window_2_1); | 1736 ASSERT_TRUE(window_2_1); |
1737 ASSERT_TRUE(ws_client2()->AddWindow(window_1_1, window_2_1)); | 1737 ASSERT_TRUE(ws_client2()->AddWindow(window_1_1, window_2_1)); |
1738 | 1738 |
1739 changes2()->clear(); | 1739 changes2()->clear(); |
1740 | 1740 |
1741 // Establish a third connection in window_2_1. | 1741 // Establish a third connection in window_2_1. |
1742 ASSERT_NO_FATAL_FAILURE(EstablishThirdConnection(ws1(), window_2_1)); | 1742 ASSERT_NO_FATAL_FAILURE(EstablishThirdConnection(ws1(), window_2_1)); |
1743 | 1743 |
1744 ASSERT_TRUE(ws_client2()->WaitForAllMessages()); | 1744 ASSERT_TRUE(ws_client2()->WaitForAllMessages()); |
1745 EXPECT_EQ(std::string(), SingleChangeToDescription(*changes2())); | 1745 EXPECT_EQ(std::string(), SingleChangeToDescription(*changes2())); |
1746 } | 1746 } |
1747 | 1747 |
1748 TEST_F(WindowTreeAppTest, CantEmbedFromConnectionRoot) { | 1748 TEST_F(WindowTreeAppTest, CantEmbedFromConnectionRoot) { |
1749 // Shouldn't be able to embed into the root. | 1749 // Shouldn't be able to embed into the root. |
1750 ASSERT_FALSE(EmbedUrl(shell(), ws1(), shell_url(), root_window_id())); | 1750 ASSERT_FALSE(EmbedUrl(connector(), ws1(), test_url(), root_window_id())); |
1751 | 1751 |
1752 // Even though the call above failed a WindowTreeClient was obtained. We need | 1752 // Even though the call above failed a WindowTreeClient was obtained. We need |
1753 // to | 1753 // to |
1754 // wait for it else we throw off the next connect. | 1754 // wait for it else we throw off the next connect. |
1755 WaitForWindowTreeClient(); | 1755 WaitForWindowTreeClient(); |
1756 | 1756 |
1757 // Don't allow a connection to embed into its own root. | 1757 // Don't allow a connection to embed into its own root. |
1758 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); | 1758 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); |
1759 EXPECT_FALSE(EmbedUrl(shell(), ws2(), shell_url(), | 1759 EXPECT_FALSE(EmbedUrl(connector(), ws2(), test_url(), |
1760 BuildWindowId(connection_id_1(), 1))); | 1760 BuildWindowId(connection_id_1(), 1))); |
1761 | 1761 |
1762 // Need to wait for a WindowTreeClient for same reason as above. | 1762 // Need to wait for a WindowTreeClient for same reason as above. |
1763 WaitForWindowTreeClient(); | 1763 WaitForWindowTreeClient(); |
1764 | 1764 |
1765 Id window_1_2 = ws_client1()->NewWindow(2); | 1765 Id window_1_2 = ws_client1()->NewWindow(2); |
1766 ASSERT_TRUE(window_1_2); | 1766 ASSERT_TRUE(window_1_2); |
1767 ASSERT_TRUE( | 1767 ASSERT_TRUE( |
1768 ws_client1()->AddWindow(BuildWindowId(connection_id_1(), 1), window_1_2)); | 1768 ws_client1()->AddWindow(BuildWindowId(connection_id_1(), 1), window_1_2)); |
1769 ASSERT_TRUE(ws_client3_.get() == nullptr); | 1769 ASSERT_TRUE(ws_client3_.get() == nullptr); |
1770 ws_client3_ = EstablishConnectionViaEmbedWithPolicyBitmask( | 1770 ws_client3_ = EstablishConnectionViaEmbedWithPolicyBitmask( |
1771 ws1(), window_1_2, mojom::WindowTree::kAccessPolicyEmbedRoot, nullptr); | 1771 ws1(), window_1_2, mojom::WindowTree::kAccessPolicyEmbedRoot, nullptr); |
1772 ASSERT_TRUE(ws_client3_.get() != nullptr); | 1772 ASSERT_TRUE(ws_client3_.get() != nullptr); |
1773 | 1773 |
1774 // window_1_2 is ws3's root, so even though v3 is an embed root it should not | 1774 // window_1_2 is ws3's root, so even though v3 is an embed root it should not |
1775 // be able to Embed into itself. | 1775 // be able to Embed into itself. |
1776 ASSERT_FALSE(EmbedUrl(shell(), ws3(), shell_url(), window_1_2)); | 1776 ASSERT_FALSE(EmbedUrl(connector(), ws3(), test_url(), window_1_2)); |
1777 } | 1777 } |
1778 | 1778 |
1779 // Verifies that a transient window tracks its parent's lifetime. | 1779 // Verifies that a transient window tracks its parent's lifetime. |
1780 TEST_F(WindowTreeAppTest, TransientWindowTracksTransientParentLifetime) { | 1780 TEST_F(WindowTreeAppTest, TransientWindowTracksTransientParentLifetime) { |
1781 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); | 1781 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); |
1782 Id window_1_1 = BuildWindowId(connection_id_1(), 1); | 1782 Id window_1_1 = BuildWindowId(connection_id_1(), 1); |
1783 | 1783 |
1784 Id window_2_1 = ws_client2()->NewWindow(1); | 1784 Id window_2_1 = ws_client2()->NewWindow(1); |
1785 Id window_2_2 = ws_client2()->NewWindow(2); | 1785 Id window_2_2 = ws_client2()->NewWindow(2); |
1786 Id window_2_3 = ws_client2()->NewWindow(3); | 1786 Id window_2_3 = ws_client2()->NewWindow(3); |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1922 // originating connection. | 1922 // originating connection. |
1923 | 1923 |
1924 // TODO(sky): make sure coverage of what was | 1924 // TODO(sky): make sure coverage of what was |
1925 // WindowManagerTest.SecondEmbedRoot_InitService and | 1925 // WindowManagerTest.SecondEmbedRoot_InitService and |
1926 // WindowManagerTest.MultipleEmbedRootsBeforeWTHReady gets added to window | 1926 // WindowManagerTest.MultipleEmbedRootsBeforeWTHReady gets added to window |
1927 // manager | 1927 // manager |
1928 // tests. | 1928 // tests. |
1929 | 1929 |
1930 } // namespace ws | 1930 } // namespace ws |
1931 } // namespace mus | 1931 } // namespace mus |
OLD | NEW |