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" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 }; | 45 }; |
46 | 46 |
47 void OnEmbed(bool success) { | 47 void OnEmbed(bool success) { |
48 ASSERT_TRUE(success); | 48 ASSERT_TRUE(success); |
49 } | 49 } |
50 | 50 |
51 class TestUserWindowObserver : public mojom::UserWindowObserver { | 51 class TestUserWindowObserver : public mojom::UserWindowObserver { |
52 public: | 52 public: |
53 explicit TestUserWindowObserver(shell::Connector* connector) | 53 explicit TestUserWindowObserver(shell::Connector* connector) |
54 : binding_(this), window_count_(0u), expected_window_count_(0u) { | 54 : binding_(this), window_count_(0u), expected_window_count_(0u) { |
55 connector->ConnectToInterface("mojo:desktop_wm", &user_window_controller_); | 55 connector->ConnectToInterface("mojo:ash", &user_window_controller_); |
56 user_window_controller_->AddUserWindowObserver( | 56 user_window_controller_->AddUserWindowObserver( |
57 binding_.CreateInterfacePtrAndBind()); | 57 binding_.CreateInterfacePtrAndBind()); |
58 } | 58 } |
59 | 59 |
60 ~TestUserWindowObserver() override {} | 60 ~TestUserWindowObserver() override {} |
61 | 61 |
62 bool WaitUntilWindowCountReaches(size_t expected) { | 62 bool WaitUntilWindowCountReaches(size_t expected) { |
63 DCHECK(quit_callback_.is_null()); | 63 DCHECK(quit_callback_.is_null()); |
64 if (window_count_ != expected) { | 64 if (window_count_ != expected) { |
65 base::RunLoop loop; | 65 base::RunLoop loop; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 size_t window_count_; | 107 size_t window_count_; |
108 size_t expected_window_count_; | 108 size_t expected_window_count_; |
109 base::Closure quit_callback_; | 109 base::Closure quit_callback_; |
110 | 110 |
111 DISALLOW_COPY_AND_ASSIGN(TestUserWindowObserver); | 111 DISALLOW_COPY_AND_ASSIGN(TestUserWindowObserver); |
112 }; | 112 }; |
113 | 113 |
114 TEST_F(WindowManagerTest, OpenWindow) { | 114 TEST_F(WindowManagerTest, OpenWindow) { |
115 WindowTreeClientDelegate window_tree_delegate; | 115 WindowTreeClientDelegate window_tree_delegate; |
116 | 116 |
117 // Bring up the the desktop_wm. | 117 connector()->Connect("mojo:ash"); |
118 connector()->Connect("mojo:desktop_wm"); | |
119 | 118 |
120 // 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 |
121 // the |desktop_wm|, but is async. | 120 // |ash|, but is async. |
122 std::unique_ptr<::mus::WindowTreeClient> client( | 121 std::unique_ptr<::mus::WindowTreeClient> client( |
123 new ::mus::WindowTreeClient(&window_tree_delegate, nullptr, nullptr)); | 122 new ::mus::WindowTreeClient(&window_tree_delegate, nullptr, nullptr)); |
124 client->ConnectViaWindowTreeFactory(connector()); | 123 client->ConnectViaWindowTreeFactory(connector()); |
125 ::mus::Window* top_level_window = client->NewTopLevelWindow(nullptr); | 124 ::mus::Window* top_level_window = client->NewTopLevelWindow(nullptr); |
126 ASSERT_TRUE(top_level_window); | 125 ASSERT_TRUE(top_level_window); |
127 ::mus::Window* child_window = client->NewWindow(); | 126 ::mus::Window* child_window = client->NewWindow(); |
128 ASSERT_TRUE(child_window); | 127 ASSERT_TRUE(child_window); |
129 top_level_window->AddChild(child_window); | 128 top_level_window->AddChild(child_window); |
130 | 129 |
131 // Create another WindowTreeClient by way of embedding in | 130 // Create another WindowTreeClient by way of embedding in |
132 // |child_window|. This blocks until it succeeds. | 131 // |child_window|. This blocks until it succeeds. |
133 ::mus::mojom::WindowTreeClientPtr tree_client; | 132 ::mus::mojom::WindowTreeClientPtr tree_client; |
134 auto tree_client_request = GetProxy(&tree_client); | 133 auto tree_client_request = GetProxy(&tree_client); |
135 child_window->Embed(std::move(tree_client), base::Bind(&OnEmbed)); | 134 child_window->Embed(std::move(tree_client), base::Bind(&OnEmbed)); |
136 std::unique_ptr<::mus::WindowTreeClient> child_client( | 135 std::unique_ptr<::mus::WindowTreeClient> child_client( |
137 new ::mus::WindowTreeClient(&window_tree_delegate, nullptr, | 136 new ::mus::WindowTreeClient(&window_tree_delegate, nullptr, |
138 std::move(tree_client_request))); | 137 std::move(tree_client_request))); |
139 child_client->WaitForEmbed(); | 138 child_client->WaitForEmbed(); |
140 ASSERT_TRUE(!child_client->GetRoots().empty()); | 139 ASSERT_TRUE(!child_client->GetRoots().empty()); |
141 } | 140 } |
142 | 141 |
143 TEST_F(WindowManagerTest, OpenWindowAndClose) { | 142 TEST_F(WindowManagerTest, OpenWindowAndClose) { |
144 // Bring up the the desktop_wm. | 143 connector()->Connect("mojo:ash"); |
145 connector()->Connect("mojo:desktop_wm"); | |
146 | 144 |
147 TestUserWindowObserver observer(connector()); | 145 TestUserWindowObserver observer(connector()); |
148 | 146 |
149 // Connect to mus and create a new top level window. | 147 // Connect to mus and create a new top level window. |
150 WindowTreeClientDelegate window_tree_delegate; | 148 WindowTreeClientDelegate window_tree_delegate; |
151 std::unique_ptr<::mus::WindowTreeClient> client( | 149 std::unique_ptr<::mus::WindowTreeClient> client( |
152 new ::mus::WindowTreeClient(&window_tree_delegate, nullptr, nullptr)); | 150 new ::mus::WindowTreeClient(&window_tree_delegate, nullptr, nullptr)); |
153 client->ConnectViaWindowTreeFactory(connector()); | 151 client->ConnectViaWindowTreeFactory(connector()); |
154 ::mus::Window* top_level_window = client->NewTopLevelWindow(nullptr); | 152 ::mus::Window* top_level_window = client->NewTopLevelWindow(nullptr); |
155 ASSERT_TRUE(top_level_window); | 153 ASSERT_TRUE(top_level_window); |
156 | 154 |
157 observer.WaitUntilWindowCountReaches(1u); | 155 observer.WaitUntilWindowCountReaches(1u); |
158 client.reset(); | 156 client.reset(); |
159 observer.WaitUntilWindowCountReaches(0u); | 157 observer.WaitUntilWindowCountReaches(0u); |
160 } | 158 } |
161 | 159 |
162 } // namespace mus | 160 } // namespace mus |
163 } // namespace ash | 161 } // namespace ash |
OLD | NEW |