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

Side by Side Diff: components/mus/ws/window_tree_apptest.cc

Issue 1674903003: Extract shell methods from ApplicationImpl into a base class, and pass this to Initialize() instead. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@mojom
Patch Set: . Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 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"
11 #include "base/run_loop.h" 11 #include "base/run_loop.h"
12 #include "base/strings/stringprintf.h" 12 #include "base/strings/stringprintf.h"
13 #include "components/mus/public/interfaces/window_tree.mojom.h" 13 #include "components/mus/public/interfaces/window_tree.mojom.h"
14 #include "components/mus/public/interfaces/window_tree_host.mojom.h" 14 #include "components/mus/public/interfaces/window_tree_host.mojom.h"
15 #include "components/mus/ws/ids.h" 15 #include "components/mus/ws/ids.h"
16 #include "components/mus/ws/test_change_tracker.h" 16 #include "components/mus/ws/test_change_tracker.h"
17 #include "mojo/converters/geometry/geometry_type_converters.h" 17 #include "mojo/converters/geometry/geometry_type_converters.h"
18 #include "mojo/public/cpp/bindings/associated_binding.h" 18 #include "mojo/public/cpp/bindings/associated_binding.h"
19 #include "mojo/shell/public/cpp/application_delegate.h" 19 #include "mojo/shell/public/cpp/application_delegate.h"
20 #include "mojo/shell/public/cpp/application_impl.h"
21 #include "mojo/shell/public/cpp/application_test_base.h" 20 #include "mojo/shell/public/cpp/application_test_base.h"
22 21
23 using mojo::ApplicationConnection; 22 using mojo::ApplicationConnection;
24 using mojo::ApplicationDelegate; 23 using mojo::ApplicationDelegate;
25 using mojo::Array; 24 using mojo::Array;
26 using mojo::Callback; 25 using mojo::Callback;
27 using mojo::InterfaceRequest; 26 using mojo::InterfaceRequest;
28 using mojo::RectPtr; 27 using mojo::RectPtr;
29 using mojo::String; 28 using mojo::String;
30 using mus::mojom::ErrorCode; 29 using mus::mojom::ErrorCode;
(...skipping 27 matching lines...) Expand all
58 void EmbedCallbackImpl(base::RunLoop* run_loop, 57 void EmbedCallbackImpl(base::RunLoop* run_loop,
59 bool* result_cache, 58 bool* result_cache,
60 bool result, 59 bool result,
61 ConnectionSpecificId connection_id) { 60 ConnectionSpecificId connection_id) {
62 *result_cache = result; 61 *result_cache = result;
63 run_loop->Quit(); 62 run_loop->Quit();
64 } 63 }
65 64
66 // ----------------------------------------------------------------------------- 65 // -----------------------------------------------------------------------------
67 66
68 bool EmbedUrl(mojo::ApplicationImpl* app, 67 bool EmbedUrl(mojo::Shell* shell,
69 WindowTree* ws, 68 WindowTree* ws,
70 const String& url, 69 const String& url,
71 Id root_id) { 70 Id root_id) {
72 bool result = false; 71 bool result = false;
73 base::RunLoop run_loop; 72 base::RunLoop run_loop;
74 { 73 {
75 mojom::WindowTreeClientPtr client; 74 mojom::WindowTreeClientPtr client;
76 app->ConnectToService(url.get(), &client); 75 shell->ConnectToService(url.get(), &client);
77 ws->Embed(root_id, std::move(client), 76 ws->Embed(root_id, std::move(client),
78 mojom::WindowTree::kAccessPolicyDefault, 77 mojom::WindowTree::kAccessPolicyDefault,
79 base::Bind(&EmbedCallbackImpl, &run_loop, &result)); 78 base::Bind(&EmbedCallbackImpl, &run_loop, &result));
80 } 79 }
81 run_loop.Run(); 80 run_loop.Run();
82 return result; 81 return result;
83 } 82 }
84 83
85 bool Embed(WindowTree* ws, Id root_id, mojom::WindowTreeClientPtr client) { 84 bool Embed(WindowTree* ws, Id root_id, mojom::WindowTreeClientPtr client) {
86 bool result = false; 85 bool result = false;
(...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after
535 int* connection_id) { 534 int* connection_id) {
536 return EstablishConnectionViaEmbedWithPolicyBitmask( 535 return EstablishConnectionViaEmbedWithPolicyBitmask(
537 owner, root_id, mojom::WindowTree::kAccessPolicyDefault, connection_id); 536 owner, root_id, mojom::WindowTree::kAccessPolicyDefault, connection_id);
538 } 537 }
539 538
540 scoped_ptr<TestWindowTreeClientImpl> 539 scoped_ptr<TestWindowTreeClientImpl>
541 EstablishConnectionViaEmbedWithPolicyBitmask(WindowTree* owner, 540 EstablishConnectionViaEmbedWithPolicyBitmask(WindowTree* owner,
542 Id root_id, 541 Id root_id,
543 uint32_t policy_bitmask, 542 uint32_t policy_bitmask,
544 int* connection_id) { 543 int* connection_id) {
545 if (!EmbedUrl(application_impl(), owner, application_impl()->url(), 544 if (!EmbedUrl(shell(), owner, shell_url(), root_id)) {
546 root_id)) {
547 ADD_FAILURE() << "Embed() failed"; 545 ADD_FAILURE() << "Embed() failed";
548 return nullptr; 546 return nullptr;
549 } 547 }
550 scoped_ptr<TestWindowTreeClientImpl> client = 548 scoped_ptr<TestWindowTreeClientImpl> client =
551 client_factory_->WaitForInstance(); 549 client_factory_->WaitForInstance();
552 if (!client.get()) { 550 if (!client.get()) {
553 ADD_FAILURE() << "WaitForInstance failed"; 551 ADD_FAILURE() << "WaitForInstance failed";
554 return nullptr; 552 return nullptr;
555 } 553 }
556 client->WaitForOnEmbed(); 554 client->WaitForOnEmbed();
557 555
558 EXPECT_EQ("OnEmbed", 556 EXPECT_EQ("OnEmbed",
559 SingleChangeToDescription(*client->tracker()->changes())); 557 SingleChangeToDescription(*client->tracker()->changes()));
560 if (connection_id) 558 if (connection_id)
561 *connection_id = (*client->tracker()->changes())[0].connection_id; 559 *connection_id = (*client->tracker()->changes())[0].connection_id;
562 return client; 560 return client;
563 } 561 }
564 562
565 // ApplicationTestBase: 563 // ApplicationTestBase:
566 ApplicationDelegate* GetApplicationDelegate() override { return this; } 564 ApplicationDelegate* GetApplicationDelegate() override { return this; }
567 void SetUp() override { 565 void SetUp() override {
568 ApplicationTestBase::SetUp(); 566 ApplicationTestBase::SetUp();
569 client_factory_.reset(new WindowTreeClientFactory()); 567 client_factory_.reset(new WindowTreeClientFactory());
570 568
571 mojom::WindowTreeHostFactoryPtr factory; 569 mojom::WindowTreeHostFactoryPtr factory;
572 application_impl()->ConnectToService("mojo:mus", &factory); 570 shell()->ConnectToService("mojo:mus", &factory);
573 571
574 mojom::WindowTreeClientPtr tree_client_ptr; 572 mojom::WindowTreeClientPtr tree_client_ptr;
575 ws_client1_.reset(new TestWindowTreeClientImpl()); 573 ws_client1_.reset(new TestWindowTreeClientImpl());
576 ws_client1_->Bind(GetProxy(&tree_client_ptr)); 574 ws_client1_->Bind(GetProxy(&tree_client_ptr));
577 575
578 factory->CreateWindowTreeHost(GetProxy(&host_), 576 factory->CreateWindowTreeHost(GetProxy(&host_),
579 std::move(tree_client_ptr)); 577 std::move(tree_client_ptr));
580 578
581 // Next we should get an embed call on the "window manager" client. 579 // Next we should get an embed call on the "window manager" client.
582 ws_client1_->WaitForIncomingMethodCall(); 580 ws_client1_->WaitForIncomingMethodCall();
(...skipping 1130 matching lines...) Expand 10 before | Expand all | Expand 10 after
1713 ASSERT_TRUE(ws_client2()->AddWindow(window_1_1, window_2_1)); 1711 ASSERT_TRUE(ws_client2()->AddWindow(window_1_1, window_2_1));
1714 ASSERT_NO_FATAL_FAILURE(EstablishThirdConnection(ws2(), window_2_1)); 1712 ASSERT_NO_FATAL_FAILURE(EstablishThirdConnection(ws2(), window_2_1));
1715 1713
1716 Id window_3_3 = ws_client3()->NewWindow(3); 1714 Id window_3_3 = ws_client3()->NewWindow(3);
1717 ASSERT_TRUE(window_3_3); 1715 ASSERT_TRUE(window_3_3);
1718 ASSERT_TRUE(ws_client3()->AddWindow(window_2_1, window_3_3)); 1716 ASSERT_TRUE(ws_client3()->AddWindow(window_2_1, window_3_3));
1719 1717
1720 // 2 should not be able to embed in window_3_3 as window_3_3 was not created 1718 // 2 should not be able to embed in window_3_3 as window_3_3 was not created
1721 // by 1719 // by
1722 // 2. 1720 // 2.
1723 EXPECT_FALSE(EmbedUrl(application_impl(), ws2(), application_impl()->url(), 1721 EXPECT_FALSE(EmbedUrl(shell(), ws2(), shell_url(), window_3_3));
1724 window_3_3));
1725 } 1722 }
1726 1723
1727 // Verifies Embed() from window manager on another connections window works. 1724 // Verifies Embed() from window manager on another connections window works.
1728 TEST_F(WindowTreeAppTest, EmbedFromOtherConnection) { 1725 TEST_F(WindowTreeAppTest, EmbedFromOtherConnection) {
1729 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); 1726 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true));
1730 1727
1731 Id window_1_1 = BuildWindowId(connection_id_1(), 1); 1728 Id window_1_1 = BuildWindowId(connection_id_1(), 1);
1732 Id window_2_1 = ws_client2()->NewWindow(1); 1729 Id window_2_1 = ws_client2()->NewWindow(1);
1733 ASSERT_TRUE(window_2_1); 1730 ASSERT_TRUE(window_2_1);
1734 ASSERT_TRUE(ws_client2()->AddWindow(window_1_1, window_2_1)); 1731 ASSERT_TRUE(ws_client2()->AddWindow(window_1_1, window_2_1));
1735 1732
1736 changes2()->clear(); 1733 changes2()->clear();
1737 1734
1738 // Establish a third connection in window_2_1. 1735 // Establish a third connection in window_2_1.
1739 ASSERT_NO_FATAL_FAILURE(EstablishThirdConnection(ws1(), window_2_1)); 1736 ASSERT_NO_FATAL_FAILURE(EstablishThirdConnection(ws1(), window_2_1));
1740 1737
1741 ASSERT_TRUE(ws_client2()->WaitForAllMessages()); 1738 ASSERT_TRUE(ws_client2()->WaitForAllMessages());
1742 EXPECT_EQ(std::string(), SingleChangeToDescription(*changes2())); 1739 EXPECT_EQ(std::string(), SingleChangeToDescription(*changes2()));
1743 } 1740 }
1744 1741
1745 TEST_F(WindowTreeAppTest, CantEmbedFromConnectionRoot) { 1742 TEST_F(WindowTreeAppTest, CantEmbedFromConnectionRoot) {
1746 // Shouldn't be able to embed into the root. 1743 // Shouldn't be able to embed into the root.
1747 ASSERT_FALSE(EmbedUrl(application_impl(), ws1(), application_impl()->url(), 1744 ASSERT_FALSE(EmbedUrl(shell(), ws1(), shell_url(), root_window_id()));
1748 root_window_id()));
1749 1745
1750 // Even though the call above failed a WindowTreeClient was obtained. We need 1746 // Even though the call above failed a WindowTreeClient was obtained. We need
1751 // to 1747 // to
1752 // wait for it else we throw off the next connect. 1748 // wait for it else we throw off the next connect.
1753 WaitForWindowTreeClient(); 1749 WaitForWindowTreeClient();
1754 1750
1755 // Don't allow a connection to embed into its own root. 1751 // Don't allow a connection to embed into its own root.
1756 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); 1752 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true));
1757 EXPECT_FALSE(EmbedUrl(application_impl(), ws2(), application_impl()->url(), 1753 EXPECT_FALSE(EmbedUrl(shell(), ws2(), shell_url(),
1758 BuildWindowId(connection_id_1(), 1))); 1754 BuildWindowId(connection_id_1(), 1)));
1759 1755
1760 // Need to wait for a WindowTreeClient for same reason as above. 1756 // Need to wait for a WindowTreeClient for same reason as above.
1761 WaitForWindowTreeClient(); 1757 WaitForWindowTreeClient();
1762 1758
1763 Id window_1_2 = ws_client1()->NewWindow(2); 1759 Id window_1_2 = ws_client1()->NewWindow(2);
1764 ASSERT_TRUE(window_1_2); 1760 ASSERT_TRUE(window_1_2);
1765 ASSERT_TRUE( 1761 ASSERT_TRUE(
1766 ws_client1()->AddWindow(BuildWindowId(connection_id_1(), 1), window_1_2)); 1762 ws_client1()->AddWindow(BuildWindowId(connection_id_1(), 1), window_1_2));
1767 ASSERT_TRUE(ws_client3_.get() == nullptr); 1763 ASSERT_TRUE(ws_client3_.get() == nullptr);
1768 ws_client3_ = EstablishConnectionViaEmbedWithPolicyBitmask( 1764 ws_client3_ = EstablishConnectionViaEmbedWithPolicyBitmask(
1769 ws1(), window_1_2, mojom::WindowTree::kAccessPolicyEmbedRoot, nullptr); 1765 ws1(), window_1_2, mojom::WindowTree::kAccessPolicyEmbedRoot, nullptr);
1770 ASSERT_TRUE(ws_client3_.get() != nullptr); 1766 ASSERT_TRUE(ws_client3_.get() != nullptr);
1771 1767
1772 // window_1_2 is ws3's root, so even though v3 is an embed root it should not 1768 // window_1_2 is ws3's root, so even though v3 is an embed root it should not
1773 // be able to Embed into itself. 1769 // be able to Embed into itself.
1774 ASSERT_FALSE(EmbedUrl(application_impl(), ws3(), application_impl()->url(), 1770 ASSERT_FALSE(EmbedUrl(shell(), ws3(), shell_url(), window_1_2));
1775 window_1_2));
1776 } 1771 }
1777 1772
1778 // Verifies that a transient window tracks its parent's lifetime. 1773 // Verifies that a transient window tracks its parent's lifetime.
1779 TEST_F(WindowTreeAppTest, TransientWindowTracksTransientParentLifetime) { 1774 TEST_F(WindowTreeAppTest, TransientWindowTracksTransientParentLifetime) {
1780 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); 1775 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true));
1781 Id window_1_1 = BuildWindowId(connection_id_1(), 1); 1776 Id window_1_1 = BuildWindowId(connection_id_1(), 1);
1782 1777
1783 Id window_2_1 = ws_client2()->NewWindow(1); 1778 Id window_2_1 = ws_client2()->NewWindow(1);
1784 Id window_2_2 = ws_client2()->NewWindow(2); 1779 Id window_2_2 = ws_client2()->NewWindow(2);
1785 Id window_2_3 = ws_client2()->NewWindow(3); 1780 Id window_2_3 = ws_client2()->NewWindow(3);
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
1870 // originating connection. 1865 // originating connection.
1871 1866
1872 // TODO(sky): make sure coverage of what was 1867 // TODO(sky): make sure coverage of what was
1873 // WindowManagerTest.SecondEmbedRoot_InitService and 1868 // WindowManagerTest.SecondEmbedRoot_InitService and
1874 // WindowManagerTest.MultipleEmbedRootsBeforeWTHReady gets added to window 1869 // WindowManagerTest.MultipleEmbedRootsBeforeWTHReady gets added to window
1875 // manager 1870 // manager
1876 // tests. 1871 // tests.
1877 1872
1878 } // namespace ws 1873 } // namespace ws
1879 } // namespace mus 1874 } // namespace mus
OLDNEW
« no previous file with comments | « components/mus/ws/window_manager_client_apptest.cc ('k') | components/mus/ws/window_tree_host_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698