| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <stdint.h> | 5 #include <stdint.h> |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/run_loop.h" | 12 #include "base/run_loop.h" |
| 13 #include "components/mus/public/cpp/window.h" | 13 #include "components/mus/public/cpp/window.h" |
| 14 #include "components/mus/public/cpp/window_tree_connection.h" | 14 #include "components/mus/public/cpp/window_tree_client.h" |
| 15 #include "components/mus/public/cpp/window_tree_delegate.h" | 15 #include "components/mus/public/cpp/window_tree_client_delegate.h" |
| 16 #include "components/mus/public/interfaces/window_tree.mojom.h" | 16 #include "components/mus/public/interfaces/window_tree.mojom.h" |
| 17 #include "mash/wm/public/interfaces/user_window_controller.mojom.h" | 17 #include "mash/wm/public/interfaces/user_window_controller.mojom.h" |
| 18 #include "services/shell/public/cpp/shell_test.h" | 18 #include "services/shell/public/cpp/shell_test.h" |
| 19 | 19 |
| 20 namespace mash { | 20 namespace mash { |
| 21 namespace wm { | 21 namespace wm { |
| 22 | 22 |
| 23 class WindowTreeDelegateImpl : public mus::WindowTreeDelegate { | 23 class WindowTreeClientDelegate : public mus::WindowTreeClientDelegate { |
| 24 public: | 24 public: |
| 25 WindowTreeDelegateImpl() {} | 25 WindowTreeClientDelegate() {} |
| 26 ~WindowTreeDelegateImpl() override {} | 26 ~WindowTreeClientDelegate() override {} |
| 27 | 27 |
| 28 private: | 28 private: |
| 29 // mus::WindowTreeDelegate: | 29 // mus::WindowTreeClientDelegate: |
| 30 void OnEmbed(mus::Window* root) override {} | 30 void OnEmbed(mus::Window* root) override {} |
| 31 void OnConnectionLost(mus::WindowTreeConnection* connection) override {} | 31 void OnWindowTreeClientDestroyed(mus::WindowTreeClient* client) override {} |
| 32 void OnEventObserved(const ui::Event& event, mus::Window* target) override {} | 32 void OnEventObserved(const ui::Event& event, mus::Window* target) override {} |
| 33 | 33 |
| 34 DISALLOW_COPY_AND_ASSIGN(WindowTreeDelegateImpl); | 34 DISALLOW_COPY_AND_ASSIGN(WindowTreeClientDelegate); |
| 35 }; | 35 }; |
| 36 | 36 |
| 37 class WindowManagerTest : public shell::test::ShellTest { | 37 class WindowManagerTest : public shell::test::ShellTest { |
| 38 public: | 38 public: |
| 39 WindowManagerTest() : shell::test::ShellTest("exe:mash_unittests") {} | 39 WindowManagerTest() : shell::test::ShellTest("exe:mash_unittests") {} |
| 40 ~WindowManagerTest() override {} | 40 ~WindowManagerTest() override {} |
| 41 | 41 |
| 42 private: | 42 private: |
| 43 DISALLOW_COPY_AND_ASSIGN(WindowManagerTest); | 43 DISALLOW_COPY_AND_ASSIGN(WindowManagerTest); |
| 44 }; | 44 }; |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 mojo::Binding<mojom::UserWindowObserver> binding_; | 104 mojo::Binding<mojom::UserWindowObserver> binding_; |
| 105 | 105 |
| 106 size_t window_count_; | 106 size_t window_count_; |
| 107 size_t expected_window_count_; | 107 size_t expected_window_count_; |
| 108 base::Closure quit_callback_; | 108 base::Closure quit_callback_; |
| 109 | 109 |
| 110 DISALLOW_COPY_AND_ASSIGN(TestUserWindowObserver); | 110 DISALLOW_COPY_AND_ASSIGN(TestUserWindowObserver); |
| 111 }; | 111 }; |
| 112 | 112 |
| 113 TEST_F(WindowManagerTest, OpenWindow) { | 113 TEST_F(WindowManagerTest, OpenWindow) { |
| 114 WindowTreeDelegateImpl window_tree_delegate; | 114 WindowTreeClientDelegate window_tree_delegate; |
| 115 | 115 |
| 116 // Bring up the the desktop_wm. | 116 // Bring up the the desktop_wm. |
| 117 connector()->Connect("mojo:desktop_wm"); | 117 connector()->Connect("mojo:desktop_wm"); |
| 118 | 118 |
| 119 // Connect to mus and create a new top level window. The request goes to | 119 // Connect to mus and create a new top level window. The request goes to |
| 120 // the |desktop_wm|, but is async. | 120 // the |desktop_wm|, but is async. |
| 121 std::unique_ptr<mus::WindowTreeConnection> connection( | 121 std::unique_ptr<mus::WindowTreeClient> client( |
| 122 mus::WindowTreeConnection::Create(&window_tree_delegate, connector())); | 122 new mus::WindowTreeClient(&window_tree_delegate, nullptr, nullptr)); |
| 123 mus::Window* top_level_window = connection->NewTopLevelWindow(nullptr); | 123 client->ConnectViaWindowTreeFactory(connector()); |
| 124 mus::Window* top_level_window = client->NewTopLevelWindow(nullptr); |
| 124 ASSERT_TRUE(top_level_window); | 125 ASSERT_TRUE(top_level_window); |
| 125 mus::Window* child_window = connection->NewWindow(); | 126 mus::Window* child_window = client->NewWindow(); |
| 126 ASSERT_TRUE(child_window); | 127 ASSERT_TRUE(child_window); |
| 127 top_level_window->AddChild(child_window); | 128 top_level_window->AddChild(child_window); |
| 128 | 129 |
| 129 // Create another WindowTreeConnection by way of embedding in | 130 // Create another WindowTreeClient by way of embedding in |
| 130 // |child_window|. This blocks until it succeeds. | 131 // |child_window|. This blocks until it succeeds. |
| 131 mus::mojom::WindowTreeClientPtr tree_client; | 132 mus::mojom::WindowTreeClientPtr tree_client; |
| 132 auto tree_client_request = GetProxy(&tree_client); | 133 auto tree_client_request = GetProxy(&tree_client); |
| 133 child_window->Embed(std::move(tree_client), base::Bind(&OnEmbed)); | 134 child_window->Embed(std::move(tree_client), base::Bind(&OnEmbed)); |
| 134 std::unique_ptr<mus::WindowTreeConnection> child_connection( | 135 std::unique_ptr<mus::WindowTreeClient> child_client( |
| 135 mus::WindowTreeConnection::Create( | 136 new mus::WindowTreeClient(&window_tree_delegate, nullptr, |
| 136 &window_tree_delegate, std::move(tree_client_request), | 137 std::move(tree_client_request))); |
| 137 mus::WindowTreeConnection::CreateType::WAIT_FOR_EMBED)); | 138 child_client->WaitForEmbed(); |
| 138 ASSERT_TRUE(!child_connection->GetRoots().empty()); | 139 ASSERT_TRUE(!child_client->GetRoots().empty()); |
| 139 } | 140 } |
| 140 | 141 |
| 141 TEST_F(WindowManagerTest, OpenWindowAndClose) { | 142 TEST_F(WindowManagerTest, OpenWindowAndClose) { |
| 142 // Bring up the the desktop_wm. | 143 // Bring up the the desktop_wm. |
| 143 connector()->Connect("mojo:desktop_wm"); | 144 connector()->Connect("mojo:desktop_wm"); |
| 144 | 145 |
| 145 TestUserWindowObserver observer(connector()); | 146 TestUserWindowObserver observer(connector()); |
| 146 | 147 |
| 147 // Connect to mus and create a new top level window. | 148 // Connect to mus and create a new top level window. |
| 148 WindowTreeDelegateImpl window_tree_delegate; | 149 WindowTreeClientDelegate window_tree_delegate; |
| 149 std::unique_ptr<mus::WindowTreeConnection> connection( | 150 std::unique_ptr<mus::WindowTreeClient> client( |
| 150 mus::WindowTreeConnection::Create(&window_tree_delegate, connector())); | 151 new mus::WindowTreeClient(&window_tree_delegate, nullptr, nullptr)); |
| 151 mus::Window* top_level_window = connection->NewTopLevelWindow(nullptr); | 152 client->ConnectViaWindowTreeFactory(connector()); |
| 153 mus::Window* top_level_window = client->NewTopLevelWindow(nullptr); |
| 152 ASSERT_TRUE(top_level_window); | 154 ASSERT_TRUE(top_level_window); |
| 153 | 155 |
| 154 observer.WaitUntilWindowCountReaches(1u); | 156 observer.WaitUntilWindowCountReaches(1u); |
| 155 connection.reset(); | 157 client.reset(); |
| 156 observer.WaitUntilWindowCountReaches(0u); | 158 observer.WaitUntilWindowCountReaches(0u); |
| 157 } | 159 } |
| 158 | 160 |
| 159 } // namespace wm | 161 } // namespace wm |
| 160 } // namespace mash | 162 } // namespace mash |
| OLD | NEW |