| 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 "ash/public/interfaces/user_window_controller.mojom.h" | 10 #include "ash/public/interfaces/user_window_controller.mojom.h" |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
| 14 #include "components/mus/public/cpp/window.h" | 14 #include "components/mus/public/cpp/window.h" |
| 15 #include "components/mus/public/cpp/window_tree_client.h" | 15 #include "components/mus/public/cpp/window_tree_client.h" |
| 16 #include "components/mus/public/cpp/window_tree_client_delegate.h" | 16 #include "components/mus/public/cpp/window_tree_client_delegate.h" |
| 17 #include "components/mus/public/interfaces/window_tree.mojom.h" | 17 #include "components/mus/public/interfaces/window_tree.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 ash { |
| 21 namespace wm { | 21 namespace mus { |
| 22 | 22 |
| 23 class WindowTreeClientDelegate : public mus::WindowTreeClientDelegate { | 23 class WindowTreeClientDelegate : public ::mus::WindowTreeClientDelegate { |
| 24 public: | 24 public: |
| 25 WindowTreeClientDelegate() {} | 25 WindowTreeClientDelegate() {} |
| 26 ~WindowTreeClientDelegate() override {} | 26 ~WindowTreeClientDelegate() override {} |
| 27 | 27 |
| 28 private: | 28 private: |
| 29 // mus::WindowTreeClientDelegate: | 29 // mus::WindowTreeClientDelegate: |
| 30 void OnEmbed(mus::Window* root) override {} | 30 void OnEmbed(::mus::Window* root) override {} |
| 31 void OnWindowTreeClientDestroyed(mus::WindowTreeClient* client) 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 |
| 34 DISALLOW_COPY_AND_ASSIGN(WindowTreeClientDelegate); | 35 DISALLOW_COPY_AND_ASSIGN(WindowTreeClientDelegate); |
| 35 }; | 36 }; |
| 36 | 37 |
| 37 class WindowManagerTest : public shell::test::ShellTest { | 38 class WindowManagerTest : public shell::test::ShellTest { |
| 38 public: | 39 public: |
| 39 WindowManagerTest() : shell::test::ShellTest("exe:mash_unittests") {} | 40 WindowManagerTest() : shell::test::ShellTest("exe:mash_unittests") {} |
| 40 ~WindowManagerTest() override {} | 41 ~WindowManagerTest() override {} |
| 41 | 42 |
| 42 private: | 43 private: |
| 43 DISALLOW_COPY_AND_ASSIGN(WindowManagerTest); | 44 DISALLOW_COPY_AND_ASSIGN(WindowManagerTest); |
| 44 }; | 45 }; |
| 45 | 46 |
| 46 void OnEmbed(bool success) { | 47 void OnEmbed(bool success) { |
| 47 ASSERT_TRUE(success); | 48 ASSERT_TRUE(success); |
| 48 } | 49 } |
| 49 | 50 |
| 50 class TestUserWindowObserver : public ash::mojom::UserWindowObserver { | 51 class TestUserWindowObserver : public mojom::UserWindowObserver { |
| 51 public: | 52 public: |
| 52 explicit TestUserWindowObserver(shell::Connector* connector) | 53 explicit TestUserWindowObserver(shell::Connector* connector) |
| 53 : binding_(this), window_count_(0u), expected_window_count_(0u) { | 54 : binding_(this), window_count_(0u), expected_window_count_(0u) { |
| 54 connector->ConnectToInterface("mojo:desktop_wm", &user_window_controller_); | 55 connector->ConnectToInterface("mojo:desktop_wm", &user_window_controller_); |
| 55 user_window_controller_->AddUserWindowObserver( | 56 user_window_controller_->AddUserWindowObserver( |
| 56 binding_.CreateInterfacePtrAndBind()); | 57 binding_.CreateInterfacePtrAndBind()); |
| 57 } | 58 } |
| 58 | 59 |
| 59 ~TestUserWindowObserver() override {} | 60 ~TestUserWindowObserver() override {} |
| 60 | 61 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 71 } | 72 } |
| 72 | 73 |
| 73 private: | 74 private: |
| 74 void QuitIfNecessary() { | 75 void QuitIfNecessary() { |
| 75 if (window_count_ == expected_window_count_ && !quit_callback_.is_null()) | 76 if (window_count_ == expected_window_count_ && !quit_callback_.is_null()) |
| 76 quit_callback_.Run(); | 77 quit_callback_.Run(); |
| 77 } | 78 } |
| 78 | 79 |
| 79 // mojom::UserWindowObserver: | 80 // mojom::UserWindowObserver: |
| 80 void OnUserWindowObserverAdded( | 81 void OnUserWindowObserverAdded( |
| 81 mojo::Array<ash::mojom::UserWindowPtr> user_windows) override { | 82 mojo::Array<mojom::UserWindowPtr> user_windows) override { |
| 82 window_count_ = user_windows.size(); | 83 window_count_ = user_windows.size(); |
| 83 QuitIfNecessary(); | 84 QuitIfNecessary(); |
| 84 } | 85 } |
| 85 | 86 |
| 86 void OnUserWindowAdded(ash::mojom::UserWindowPtr user_window) override { | 87 void OnUserWindowAdded(mojom::UserWindowPtr user_window) override { |
| 87 ++window_count_; | 88 ++window_count_; |
| 88 QuitIfNecessary(); | 89 QuitIfNecessary(); |
| 89 } | 90 } |
| 90 | 91 |
| 91 void OnUserWindowRemoved(uint32_t window_id) override { | 92 void OnUserWindowRemoved(uint32_t window_id) override { |
| 92 ASSERT_TRUE(window_count_); | 93 ASSERT_TRUE(window_count_); |
| 93 --window_count_; | 94 --window_count_; |
| 94 QuitIfNecessary(); | 95 QuitIfNecessary(); |
| 95 } | 96 } |
| 96 | 97 |
| 97 void OnUserWindowTitleChanged(uint32_t window_id, | 98 void OnUserWindowTitleChanged(uint32_t window_id, |
| 98 const mojo::String& window_title) override {} | 99 const mojo::String& window_title) override {} |
| 99 void OnUserWindowFocusChanged(uint32_t window_id, bool has_focus) override {} | 100 void OnUserWindowFocusChanged(uint32_t window_id, bool has_focus) override {} |
| 100 void OnUserWindowAppIconChanged(uint32_t window_id, | 101 void OnUserWindowAppIconChanged(uint32_t window_id, |
| 101 mojo::Array<uint8_t> app_icon) override {} | 102 mojo::Array<uint8_t> app_icon) override {} |
| 102 | 103 |
| 103 ash::mojom::UserWindowControllerPtr user_window_controller_; | 104 mojom::UserWindowControllerPtr user_window_controller_; |
| 104 mojo::Binding<ash::mojom::UserWindowObserver> binding_; | 105 mojo::Binding<mojom::UserWindowObserver> binding_; |
| 105 | 106 |
| 106 size_t window_count_; | 107 size_t window_count_; |
| 107 size_t expected_window_count_; | 108 size_t expected_window_count_; |
| 108 base::Closure quit_callback_; | 109 base::Closure quit_callback_; |
| 109 | 110 |
| 110 DISALLOW_COPY_AND_ASSIGN(TestUserWindowObserver); | 111 DISALLOW_COPY_AND_ASSIGN(TestUserWindowObserver); |
| 111 }; | 112 }; |
| 112 | 113 |
| 113 TEST_F(WindowManagerTest, OpenWindow) { | 114 TEST_F(WindowManagerTest, OpenWindow) { |
| 114 WindowTreeClientDelegate window_tree_delegate; | 115 WindowTreeClientDelegate window_tree_delegate; |
| 115 | 116 |
| 116 // Bring up the the desktop_wm. | 117 // Bring up the the desktop_wm. |
| 117 connector()->Connect("mojo:desktop_wm"); | 118 connector()->Connect("mojo:desktop_wm"); |
| 118 | 119 |
| 119 // Connect to mus and create a new top level window. The request goes to | 120 // Connect to mus and create a new top level window. The request goes to |
| 120 // the |desktop_wm|, but is async. | 121 // the |desktop_wm|, but is async. |
| 121 std::unique_ptr<mus::WindowTreeClient> client( | 122 std::unique_ptr<::mus::WindowTreeClient> client( |
| 122 new mus::WindowTreeClient(&window_tree_delegate, nullptr, nullptr)); | 123 new ::mus::WindowTreeClient(&window_tree_delegate, nullptr, nullptr)); |
| 123 client->ConnectViaWindowTreeFactory(connector()); | 124 client->ConnectViaWindowTreeFactory(connector()); |
| 124 mus::Window* top_level_window = client->NewTopLevelWindow(nullptr); | 125 ::mus::Window* top_level_window = client->NewTopLevelWindow(nullptr); |
| 125 ASSERT_TRUE(top_level_window); | 126 ASSERT_TRUE(top_level_window); |
| 126 mus::Window* child_window = client->NewWindow(); | 127 ::mus::Window* child_window = client->NewWindow(); |
| 127 ASSERT_TRUE(child_window); | 128 ASSERT_TRUE(child_window); |
| 128 top_level_window->AddChild(child_window); | 129 top_level_window->AddChild(child_window); |
| 129 | 130 |
| 130 // Create another WindowTreeClient by way of embedding in | 131 // Create another WindowTreeClient by way of embedding in |
| 131 // |child_window|. This blocks until it succeeds. | 132 // |child_window|. This blocks until it succeeds. |
| 132 mus::mojom::WindowTreeClientPtr tree_client; | 133 ::mus::mojom::WindowTreeClientPtr tree_client; |
| 133 auto tree_client_request = GetProxy(&tree_client); | 134 auto tree_client_request = GetProxy(&tree_client); |
| 134 child_window->Embed(std::move(tree_client), base::Bind(&OnEmbed)); | 135 child_window->Embed(std::move(tree_client), base::Bind(&OnEmbed)); |
| 135 std::unique_ptr<mus::WindowTreeClient> child_client( | 136 std::unique_ptr<::mus::WindowTreeClient> child_client( |
| 136 new mus::WindowTreeClient(&window_tree_delegate, nullptr, | 137 new ::mus::WindowTreeClient(&window_tree_delegate, nullptr, |
| 137 std::move(tree_client_request))); | 138 std::move(tree_client_request))); |
| 138 child_client->WaitForEmbed(); | 139 child_client->WaitForEmbed(); |
| 139 ASSERT_TRUE(!child_client->GetRoots().empty()); | 140 ASSERT_TRUE(!child_client->GetRoots().empty()); |
| 140 } | 141 } |
| 141 | 142 |
| 142 TEST_F(WindowManagerTest, OpenWindowAndClose) { | 143 TEST_F(WindowManagerTest, OpenWindowAndClose) { |
| 143 // Bring up the the desktop_wm. | 144 // Bring up the the desktop_wm. |
| 144 connector()->Connect("mojo:desktop_wm"); | 145 connector()->Connect("mojo:desktop_wm"); |
| 145 | 146 |
| 146 TestUserWindowObserver observer(connector()); | 147 TestUserWindowObserver observer(connector()); |
| 147 | 148 |
| 148 // Connect to mus and create a new top level window. | 149 // Connect to mus and create a new top level window. |
| 149 WindowTreeClientDelegate window_tree_delegate; | 150 WindowTreeClientDelegate window_tree_delegate; |
| 150 std::unique_ptr<mus::WindowTreeClient> client( | 151 std::unique_ptr<::mus::WindowTreeClient> client( |
| 151 new mus::WindowTreeClient(&window_tree_delegate, nullptr, nullptr)); | 152 new ::mus::WindowTreeClient(&window_tree_delegate, nullptr, nullptr)); |
| 152 client->ConnectViaWindowTreeFactory(connector()); | 153 client->ConnectViaWindowTreeFactory(connector()); |
| 153 mus::Window* top_level_window = client->NewTopLevelWindow(nullptr); | 154 ::mus::Window* top_level_window = client->NewTopLevelWindow(nullptr); |
| 154 ASSERT_TRUE(top_level_window); | 155 ASSERT_TRUE(top_level_window); |
| 155 | 156 |
| 156 observer.WaitUntilWindowCountReaches(1u); | 157 observer.WaitUntilWindowCountReaches(1u); |
| 157 client.reset(); | 158 client.reset(); |
| 158 observer.WaitUntilWindowCountReaches(0u); | 159 observer.WaitUntilWindowCountReaches(0u); |
| 159 } | 160 } |
| 160 | 161 |
| 161 } // namespace wm | 162 } // namespace mus |
| 162 } // namespace mash | 163 } // namespace ash |
| OLD | NEW |