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 <map> |
5 #include <memory> | 6 #include <memory> |
| 7 #include <vector> |
6 | 8 |
7 #include "base/bind.h" | 9 #include "base/bind.h" |
8 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/run_loop.h" |
9 #include "services/service_manager/public/cpp/service_test.h" | 12 #include "services/service_manager/public/cpp/service_test.h" |
10 #include "services/ui/public/cpp/window.h" | 13 #include "services/ui/public/cpp/property_type_converters.h" |
11 #include "services/ui/public/cpp/window_tree_client.h" | |
12 #include "services/ui/public/cpp/window_tree_client_delegate.h" | |
13 #include "services/ui/public/interfaces/window_tree.mojom.h" | 14 #include "services/ui/public/interfaces/window_tree.mojom.h" |
| 15 #include "ui/aura/env.h" |
| 16 #include "ui/aura/mus/property_converter.h" |
| 17 #include "ui/aura/mus/window_tree_client.h" |
| 18 #include "ui/aura/mus/window_tree_client_delegate.h" |
| 19 #include "ui/aura/mus/window_tree_host_mus.h" |
| 20 #include "ui/aura/window.h" |
| 21 #include "ui/display/display.h" |
| 22 #include "ui/display/display_list.h" |
| 23 #include "ui/display/screen_base.h" |
| 24 #include "ui/wm/core/capture_controller.h" |
| 25 #include "ui/wm/core/wm_state.h" |
14 | 26 |
15 namespace ash { | 27 namespace ash { |
16 namespace mus { | 28 namespace mus { |
17 | 29 |
18 class WindowTreeClientDelegate : public ui::WindowTreeClientDelegate { | 30 class WindowTreeClientDelegate : public aura::WindowTreeClientDelegate { |
19 public: | 31 public: |
20 WindowTreeClientDelegate() {} | 32 WindowTreeClientDelegate() {} |
21 ~WindowTreeClientDelegate() override {} | 33 ~WindowTreeClientDelegate() override {} |
22 | 34 |
| 35 void WaitForEmbed() { run_loop_.Run(); } |
| 36 |
| 37 void DestroyWindowTreeHost() { window_tree_host_.reset(); } |
| 38 |
23 private: | 39 private: |
24 // ui::WindowTreeClientDelegate: | 40 // aura::WindowTreeClientDelegate: |
25 void OnEmbed(ui::Window* root) override {} | 41 void OnEmbed( |
26 void OnEmbedRootDestroyed(ui::Window* root) override {} | 42 std::unique_ptr<aura::WindowTreeHostMus> window_tree_host) override { |
27 void OnLostConnection(ui::WindowTreeClient* client) override {} | 43 window_tree_host_ = std::move(window_tree_host); |
| 44 run_loop_.Quit(); |
| 45 } |
| 46 void OnEmbedRootDestroyed(aura::Window* root) override {} |
| 47 void OnLostConnection(aura::WindowTreeClient* client) override {} |
28 void OnPointerEventObserved(const ui::PointerEvent& event, | 48 void OnPointerEventObserved(const ui::PointerEvent& event, |
29 ui::Window* target) override {} | 49 aura::Window* target) override {} |
| 50 aura::client::CaptureClient* GetCaptureClient() override { |
| 51 return wm_state_.capture_controller(); |
| 52 } |
| 53 aura::PropertyConverter* GetPropertyConverter() override { |
| 54 return &property_converter_; |
| 55 } |
| 56 |
| 57 base::RunLoop run_loop_; |
| 58 wm::WMState wm_state_; |
| 59 aura::PropertyConverter property_converter_; |
| 60 std::unique_ptr<aura::WindowTreeHostMus> window_tree_host_; |
30 | 61 |
31 DISALLOW_COPY_AND_ASSIGN(WindowTreeClientDelegate); | 62 DISALLOW_COPY_AND_ASSIGN(WindowTreeClientDelegate); |
32 }; | 63 }; |
33 | 64 |
34 class WindowManagerTest : public service_manager::test::ServiceTest { | 65 class WindowManagerTest : public service_manager::test::ServiceTest { |
35 public: | 66 public: |
36 WindowManagerTest() : service_manager::test::ServiceTest("mash_unittests") {} | 67 WindowManagerTest() : service_manager::test::ServiceTest("mash_unittests") {} |
37 ~WindowManagerTest() override {} | 68 ~WindowManagerTest() override {} |
38 | 69 |
39 private: | 70 private: |
40 DISALLOW_COPY_AND_ASSIGN(WindowManagerTest); | 71 DISALLOW_COPY_AND_ASSIGN(WindowManagerTest); |
41 }; | 72 }; |
42 | 73 |
43 void OnEmbed(bool success) { | 74 void OnEmbed(bool success) { |
44 ASSERT_TRUE(success); | 75 ASSERT_TRUE(success); |
45 } | 76 } |
46 | 77 |
47 // Fails when the Ash material design shelf is enabled by default | 78 // Fails when the Ash material design shelf is enabled by default |
48 // (ash::MaterialDesignController::IsShelfMaterial()). See | 79 // (ash::MaterialDesignController::IsShelfMaterial()). See |
49 // crbug.com/660194 and crbug.com/642879. | 80 // crbug.com/660194 and crbug.com/642879. |
50 // TODO(rockot): Reenable this test. | 81 // TODO(rockot): Reenable this test. |
51 // TODO(sky): convert to using aura. | |
52 TEST_F(WindowManagerTest, DISABLED_OpenWindow) { | 82 TEST_F(WindowManagerTest, DISABLED_OpenWindow) { |
| 83 display::ScreenBase screen; |
| 84 screen.display_list().AddDisplay( |
| 85 display::Display(1, gfx::Rect(0, 0, 200, 200)), |
| 86 display::DisplayList::Type::PRIMARY); |
| 87 display::Screen::SetScreenInstance(&screen); |
| 88 |
53 WindowTreeClientDelegate window_tree_delegate; | 89 WindowTreeClientDelegate window_tree_delegate; |
54 | 90 |
55 connector()->Connect("ash"); | 91 connector()->Connect("ash"); |
56 | 92 |
57 // Connect to mus and create a new top level window. The request goes to | 93 // Connect to mus and create a new top level window. The request goes to |
58 // |ash|, but is async. | 94 // |ash|, but is async. |
59 std::unique_ptr<ui::WindowTreeClient> client( | 95 aura::WindowTreeClient client(connector(), &window_tree_delegate); |
60 new ui::WindowTreeClient(&window_tree_delegate)); | 96 client.ConnectViaWindowTreeFactory(); |
61 client->ConnectViaWindowTreeFactory(connector()); | 97 aura::Env::GetInstance()->SetWindowTreeClient(&client); |
62 ui::Window* top_level_window = client->NewTopLevelWindow(nullptr); | 98 std::map<std::string, std::vector<uint8_t>> properties; |
63 ASSERT_TRUE(top_level_window); | 99 properties[ui::mojom::WindowManager::kWindowType_Property] = |
64 ui::Window* child_window = client->NewWindow(); | 100 mojo::ConvertTo<std::vector<uint8_t>>( |
65 ASSERT_TRUE(child_window); | 101 static_cast<int32_t>(ui::mojom::WindowType::WINDOW)); |
66 top_level_window->AddChild(child_window); | 102 aura::WindowTreeHostMus window_tree_host_mus(&client, &properties); |
| 103 aura::Window* child_window = new aura::Window(nullptr); |
| 104 child_window->Init(ui::LAYER_NOT_DRAWN); |
| 105 window_tree_host_mus.window()->AddChild(child_window); |
67 | 106 |
68 // Create another WindowTreeClient by way of embedding in | 107 // Create another WindowTreeClient by way of embedding in |
69 // |child_window|. This blocks until it succeeds. | 108 // |child_window|. This blocks until it succeeds. |
70 ui::mojom::WindowTreeClientPtr tree_client; | 109 ui::mojom::WindowTreeClientPtr tree_client; |
71 auto tree_client_request = GetProxy(&tree_client); | 110 auto tree_client_request = GetProxy(&tree_client); |
72 child_window->Embed(std::move(tree_client), base::Bind(&OnEmbed)); | 111 client.Embed(child_window, std::move(tree_client), 0u, base::Bind(&OnEmbed)); |
73 std::unique_ptr<ui::WindowTreeClient> child_client(new ui::WindowTreeClient( | 112 aura::WindowTreeClient child_client(connector(), &window_tree_delegate, |
74 &window_tree_delegate, nullptr, std::move(tree_client_request))); | 113 nullptr, std::move(tree_client_request)); |
75 child_client->WaitForEmbed(); | 114 window_tree_delegate.WaitForEmbed(); |
76 ASSERT_TRUE(!child_client->GetRoots().empty()); | 115 ASSERT_TRUE(!child_client.GetRoots().empty()); |
| 116 window_tree_delegate.DestroyWindowTreeHost(); |
77 } | 117 } |
78 | 118 |
79 } // namespace mus | 119 } // namespace mus |
80 } // namespace ash | 120 } // namespace ash |
OLD | NEW |