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 #include <utility> | 6 #include <utility> |
7 | 7 |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "components/mus/public/cpp/window.h" | 10 #include "components/mus/public/cpp/window.h" |
11 #include "components/mus/public/cpp/window_tree_connection.h" | 11 #include "components/mus/public/cpp/window_tree_connection.h" |
12 #include "components/mus/public/cpp/window_tree_delegate.h" | 12 #include "components/mus/public/cpp/window_tree_delegate.h" |
13 #include "components/mus/public/interfaces/window_tree.mojom.h" | 13 #include "components/mus/public/interfaces/window_tree.mojom.h" |
14 #include "mojo/shell/public/cpp/application_impl.h" | |
15 #include "mojo/shell/public/cpp/application_test_base.h" | 14 #include "mojo/shell/public/cpp/application_test_base.h" |
16 | 15 |
17 namespace mash { | 16 namespace mash { |
18 namespace wm { | 17 namespace wm { |
19 | 18 |
20 class WindowTreeDelegateImpl : public mus::WindowTreeDelegate { | 19 class WindowTreeDelegateImpl : public mus::WindowTreeDelegate { |
21 public: | 20 public: |
22 WindowTreeDelegateImpl() {} | 21 WindowTreeDelegateImpl() {} |
23 ~WindowTreeDelegateImpl() override {} | 22 ~WindowTreeDelegateImpl() override {} |
24 | 23 |
25 private: | 24 private: |
26 // mus::WindowTreeDelegate: | 25 // mus::WindowTreeDelegate: |
27 void OnEmbed(mus::Window* root) override {} | 26 void OnEmbed(mus::Window* root) override {} |
28 void OnConnectionLost(mus::WindowTreeConnection* connection) override {} | 27 void OnConnectionLost(mus::WindowTreeConnection* connection) override {} |
29 | 28 |
30 DISALLOW_COPY_AND_ASSIGN(WindowTreeDelegateImpl); | 29 DISALLOW_COPY_AND_ASSIGN(WindowTreeDelegateImpl); |
31 }; | 30 }; |
32 | 31 |
33 using WindowManagerAppTest = mojo::test::ApplicationTestBase; | 32 using WindowManagerAppTest = mojo::test::ApplicationTestBase; |
34 | 33 |
35 void OnEmbed(bool success, uint16_t id) { | 34 void OnEmbed(bool success, uint16_t id) { |
36 ASSERT_TRUE(success); | 35 ASSERT_TRUE(success); |
37 } | 36 } |
38 | 37 |
39 TEST_F(WindowManagerAppTest, OpenWindow) { | 38 TEST_F(WindowManagerAppTest, OpenWindow) { |
40 WindowTreeDelegateImpl window_tree_delegate; | 39 WindowTreeDelegateImpl window_tree_delegate; |
41 | 40 |
42 // Bring up the the desktop_wm. | 41 // Bring up the the desktop_wm. |
43 application_impl()->ConnectToApplication("mojo:desktop_wm"); | 42 shell()->ConnectToApplication("mojo:desktop_wm"); |
44 | 43 |
45 // Connect to mus and create a new top level window. The request goes to | 44 // Connect to mus and create a new top level window. The request goes to |
46 // the |desktop_wm|, but is async. | 45 // the |desktop_wm|, but is async. |
47 scoped_ptr<mus::WindowTreeConnection> connection( | 46 scoped_ptr<mus::WindowTreeConnection> connection( |
48 mus::WindowTreeConnection::Create(&window_tree_delegate, | 47 mus::WindowTreeConnection::Create(&window_tree_delegate, shell())); |
49 application_impl())); | |
50 mus::Window* top_level_window = connection->NewTopLevelWindow(nullptr); | 48 mus::Window* top_level_window = connection->NewTopLevelWindow(nullptr); |
51 ASSERT_TRUE(top_level_window); | 49 ASSERT_TRUE(top_level_window); |
52 mus::Window* child_window = connection->NewWindow(); | 50 mus::Window* child_window = connection->NewWindow(); |
53 ASSERT_TRUE(child_window); | 51 ASSERT_TRUE(child_window); |
54 top_level_window->AddChild(child_window); | 52 top_level_window->AddChild(child_window); |
55 | 53 |
56 // Create another WindowTreeConnection by way of embedding in | 54 // Create another WindowTreeConnection by way of embedding in |
57 // |child_window|. This blocks until it succeeds. | 55 // |child_window|. This blocks until it succeeds. |
58 mus::mojom::WindowTreeClientPtr tree_client; | 56 mus::mojom::WindowTreeClientPtr tree_client; |
59 auto tree_client_request = GetProxy(&tree_client); | 57 auto tree_client_request = GetProxy(&tree_client); |
60 child_window->Embed(std::move(tree_client), | 58 child_window->Embed(std::move(tree_client), |
61 mus::mojom::WindowTree::kAccessPolicyDefault, | 59 mus::mojom::WindowTree::kAccessPolicyDefault, |
62 base::Bind(&OnEmbed)); | 60 base::Bind(&OnEmbed)); |
63 scoped_ptr<mus::WindowTreeConnection> child_connection( | 61 scoped_ptr<mus::WindowTreeConnection> child_connection( |
64 mus::WindowTreeConnection::Create( | 62 mus::WindowTreeConnection::Create( |
65 &window_tree_delegate, std::move(tree_client_request), | 63 &window_tree_delegate, std::move(tree_client_request), |
66 mus::WindowTreeConnection::CreateType::WAIT_FOR_EMBED)); | 64 mus::WindowTreeConnection::CreateType::WAIT_FOR_EMBED)); |
67 ASSERT_TRUE(!child_connection->GetRoots().empty()); | 65 ASSERT_TRUE(!child_connection->GetRoots().empty()); |
68 } | 66 } |
69 | 67 |
70 } // namespace wm | 68 } // namespace wm |
71 } // namespace mash | 69 } // namespace mash |
OLD | NEW |