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 "services/ui/public/cpp/tests/window_server_test_base.h" | 5 #include "services/ui/public/cpp/tests/window_server_test_base.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/location.h" | 8 #include "base/location.h" |
9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
11 #include "base/single_thread_task_runner.h" | 11 #include "base/single_thread_task_runner.h" |
12 #include "base/test/test_timeouts.h" | 12 #include "base/test/test_timeouts.h" |
13 #include "base/threading/thread_task_runner_handle.h" | 13 #include "base/threading/thread_task_runner_handle.h" |
14 #include "services/service_manager/public/cpp/connector.h" | 14 #include "services/service_manager/public/cpp/connector.h" |
15 #include "services/ui/public/cpp/window.h" | 15 #include "services/ui/public/cpp/window.h" |
16 #include "services/ui/public/cpp/window_tree_client.h" | 16 #include "services/ui/public/cpp/window_tree_client.h" |
17 #include "services/ui/public/cpp/window_tree_host_factory.h" | |
18 | 17 |
19 namespace ui { | 18 namespace ui { |
20 namespace { | 19 namespace { |
21 | 20 |
22 base::RunLoop* current_run_loop = nullptr; | 21 base::RunLoop* current_run_loop = nullptr; |
23 | 22 |
24 void TimeoutRunLoop(const base::Closure& timeout_task, bool* timeout) { | 23 void TimeoutRunLoop(const base::Closure& timeout_task, bool* timeout) { |
25 CHECK(current_run_loop); | 24 CHECK(current_run_loop); |
26 *timeout = true; | 25 *timeout = true; |
27 timeout_task.Run(); | 26 timeout_task.Run(); |
28 } | 27 } |
29 | 28 |
30 } // namespace | 29 } // namespace |
31 | 30 |
32 WindowServerTestBase::WindowServerTestBase() | 31 WindowServerTestBase::WindowServerTestBase() |
33 : most_recent_client_(nullptr), | 32 : window_manager_(nullptr), |
34 window_manager_(nullptr), | |
35 window_manager_delegate_(nullptr), | 33 window_manager_delegate_(nullptr), |
36 window_manager_client_(nullptr) {} | 34 window_manager_client_(nullptr) {} |
37 | 35 |
38 WindowServerTestBase::~WindowServerTestBase() { | 36 WindowServerTestBase::~WindowServerTestBase() { |
39 window_tree_clients_.clear(); | 37 window_tree_clients_.clear(); |
40 } | 38 } |
41 | 39 |
42 // static | 40 // static |
43 bool WindowServerTestBase::DoRunLoopWithTimeout() { | 41 bool WindowServerTestBase::DoRunLoopWithTimeout() { |
44 if (current_run_loop != nullptr) | 42 if (current_run_loop != nullptr) |
(...skipping 30 matching lines...) Expand all Loading... |
75 return; | 73 return; |
76 } | 74 } |
77 } | 75 } |
78 NOTREACHED(); | 76 NOTREACHED(); |
79 } | 77 } |
80 | 78 |
81 void WindowServerTestBase::SetUp() { | 79 void WindowServerTestBase::SetUp() { |
82 WindowServerServiceTestBase::SetUp(); | 80 WindowServerServiceTestBase::SetUp(); |
83 | 81 |
84 std::unique_ptr<WindowTreeClient> window_manager_window_tree_client = | 82 std::unique_ptr<WindowTreeClient> window_manager_window_tree_client = |
85 CreateWindowTreeHost(connector(), this, &host_, this); | 83 base::MakeUnique<WindowTreeClient>(this, this); |
| 84 window_manager_window_tree_client->ConnectAsWindowManager(connector()); |
86 window_manager_ = window_manager_window_tree_client.get(); | 85 window_manager_ = window_manager_window_tree_client.get(); |
87 window_tree_clients_.insert(std::move(window_manager_window_tree_client)); | 86 window_tree_clients_.insert(std::move(window_manager_window_tree_client)); |
88 | 87 |
89 ASSERT_TRUE(DoRunLoopWithTimeout()); // RunLoop should be quit by OnEmbed(). | 88 ASSERT_TRUE(DoRunLoopWithTimeout()); // RunLoop should be quit by OnEmbed(). |
90 } | 89 } |
91 | 90 |
92 bool WindowServerTestBase::OnConnect( | 91 bool WindowServerTestBase::OnConnect( |
93 const service_manager::Identity& remote_identity, | 92 const service_manager::Identity& remote_identity, |
94 service_manager::InterfaceRegistry* registry) { | 93 service_manager::InterfaceRegistry* registry) { |
95 registry->AddInterface<mojom::WindowTreeClient>(this); | 94 registry->AddInterface<mojom::WindowTreeClient>(this); |
96 return true; | 95 return true; |
97 } | 96 } |
98 | 97 |
99 void WindowServerTestBase::OnEmbed(Window* root) { | 98 void WindowServerTestBase::OnEmbed(Window* root) { |
100 most_recent_client_ = root->window_tree(); | |
101 EXPECT_TRUE(QuitRunLoop()); | 99 EXPECT_TRUE(QuitRunLoop()); |
102 ASSERT_TRUE(window_manager_client_); | |
103 window_manager_client_->AddActivationParent(root); | |
104 } | 100 } |
105 | 101 |
106 void WindowServerTestBase::OnLostConnection(WindowTreeClient* client) { | 102 void WindowServerTestBase::OnLostConnection(WindowTreeClient* client) { |
107 window_tree_client_lost_connection_ = true; | 103 window_tree_client_lost_connection_ = true; |
108 DeleteWindowTreeClient(client); | 104 DeleteWindowTreeClient(client); |
109 } | 105 } |
110 | 106 |
111 void WindowServerTestBase::OnEmbedRootDestroyed(Window* root) { | 107 void WindowServerTestBase::OnEmbedRootDestroyed(Window* root) { |
112 DeleteWindowTreeClient(root->window_tree()); | 108 DeleteWindowTreeClient(root->window_tree()); |
113 } | 109 } |
(...skipping 29 matching lines...) Expand all Loading... |
143 | 139 |
144 void WindowServerTestBase::OnWmClientJankinessChanged( | 140 void WindowServerTestBase::OnWmClientJankinessChanged( |
145 const std::set<Window*>& client_windows, | 141 const std::set<Window*>& client_windows, |
146 bool janky) { | 142 bool janky) { |
147 if (window_manager_delegate_) | 143 if (window_manager_delegate_) |
148 window_manager_delegate_->OnWmClientJankinessChanged(client_windows, janky); | 144 window_manager_delegate_->OnWmClientJankinessChanged(client_windows, janky); |
149 } | 145 } |
150 | 146 |
151 void WindowServerTestBase::OnWmNewDisplay(Window* window, | 147 void WindowServerTestBase::OnWmNewDisplay(Window* window, |
152 const display::Display& display) { | 148 const display::Display& display) { |
| 149 EXPECT_TRUE(QuitRunLoop()); |
| 150 ASSERT_TRUE(window_manager_client_); |
| 151 window_manager_client_->AddActivationParent(window); |
| 152 |
153 if (window_manager_delegate_) | 153 if (window_manager_delegate_) |
154 window_manager_delegate_->OnWmNewDisplay(window, display); | 154 window_manager_delegate_->OnWmNewDisplay(window, display); |
155 } | 155 } |
156 | 156 |
157 void WindowServerTestBase::OnWmDisplayRemoved(Window* window) { | 157 void WindowServerTestBase::OnWmDisplayRemoved(Window* window) { |
158 if (window_manager_delegate_) | 158 if (window_manager_delegate_) |
159 window_manager_delegate_->OnWmDisplayRemoved(window); | 159 window_manager_delegate_->OnWmDisplayRemoved(window); |
160 } | 160 } |
161 | 161 |
162 void WindowServerTestBase::OnWmDisplayModified( | 162 void WindowServerTestBase::OnWmDisplayModified( |
(...skipping 26 matching lines...) Expand all Loading... |
189 } | 189 } |
190 | 190 |
191 void WindowServerTestBase::Create( | 191 void WindowServerTestBase::Create( |
192 const service_manager::Identity& remote_identity, | 192 const service_manager::Identity& remote_identity, |
193 mojom::WindowTreeClientRequest request) { | 193 mojom::WindowTreeClientRequest request) { |
194 window_tree_clients_.insert( | 194 window_tree_clients_.insert( |
195 base::MakeUnique<WindowTreeClient>(this, nullptr, std::move(request))); | 195 base::MakeUnique<WindowTreeClient>(this, nullptr, std::move(request))); |
196 } | 196 } |
197 | 197 |
198 } // namespace ui | 198 } // namespace ui |
OLD | NEW |