Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(796)

Side by Side Diff: services/ui/public/cpp/tests/window_server_test_base.cc

Issue 2559703003: Converts WindowTreeClientTest to be in terms of aura (Closed)
Patch Set: tweak Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "services/ui/public/cpp/tests/window_server_test_base.h"
6
7 #include "base/bind.h"
8 #include "base/location.h"
9 #include "base/memory/ptr_util.h"
10 #include "base/run_loop.h"
11 #include "base/single_thread_task_runner.h"
12 #include "base/test/test_timeouts.h"
13 #include "base/threading/thread_task_runner_handle.h"
14 #include "services/service_manager/public/cpp/connector.h"
15 #include "services/service_manager/public/cpp/interface_registry.h"
16 #include "services/ui/public/cpp/window.h"
17 #include "services/ui/public/cpp/window_tree_client.h"
18
19 namespace ui {
20 namespace {
21
22 base::RunLoop* current_run_loop = nullptr;
23
24 void TimeoutRunLoop(const base::Closure& timeout_task, bool* timeout) {
25 CHECK(current_run_loop);
26 *timeout = true;
27 timeout_task.Run();
28 }
29
30 } // namespace
31
32 WindowServerTestBase::WindowServerTestBase()
33 : window_manager_(nullptr),
34 window_manager_delegate_(nullptr),
35 window_manager_client_(nullptr) {}
36
37 WindowServerTestBase::~WindowServerTestBase() {
38 display::Screen::SetScreenInstance(nullptr);
39 window_tree_clients_.clear();
40 }
41
42 // static
43 bool WindowServerTestBase::DoRunLoopWithTimeout() {
44 if (current_run_loop != nullptr)
45 return false;
46
47 bool timeout = false;
48 base::RunLoop run_loop;
49 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
50 FROM_HERE, base::Bind(&TimeoutRunLoop, run_loop.QuitClosure(), &timeout),
51 TestTimeouts::action_timeout());
52
53 current_run_loop = &run_loop;
54 current_run_loop->Run();
55 current_run_loop = nullptr;
56 return !timeout;
57 }
58
59 // static
60 bool WindowServerTestBase::QuitRunLoop() {
61 if (!current_run_loop)
62 return false;
63
64 current_run_loop->Quit();
65 current_run_loop = nullptr;
66 return true;
67 }
68
69 void WindowServerTestBase::DeleteWindowTreeClient(
70 ui::WindowTreeClient* client) {
71 for (auto iter = window_tree_clients_.begin();
72 iter != window_tree_clients_.end(); ++iter) {
73 if (iter->get() == client) {
74 window_tree_clients_.erase(iter);
75 return;
76 }
77 }
78 NOTREACHED();
79 }
80
81 void WindowServerTestBase::SetUp() {
82 WindowServerServiceTestBase::SetUp();
83
84 display::Screen::SetScreenInstance(&test_screen_);
85 std::unique_ptr<WindowTreeClient> window_manager_window_tree_client =
86 base::MakeUnique<WindowTreeClient>(this, this);
87 window_manager_window_tree_client->ConnectAsWindowManager(connector());
88 window_manager_ = window_manager_window_tree_client.get();
89 window_tree_clients_.insert(std::move(window_manager_window_tree_client));
90
91 ASSERT_TRUE(DoRunLoopWithTimeout()); // RunLoop should be quit by OnEmbed().
92 }
93
94 bool WindowServerTestBase::OnConnect(
95 const service_manager::Identity& remote_identity,
96 service_manager::InterfaceRegistry* registry) {
97 registry->AddInterface<mojom::WindowTreeClient>(this);
98 return true;
99 }
100
101 void WindowServerTestBase::OnEmbed(Window* root) {
102 EXPECT_TRUE(QuitRunLoop());
103 }
104
105 void WindowServerTestBase::OnLostConnection(WindowTreeClient* client) {
106 window_tree_client_lost_connection_ = true;
107 DeleteWindowTreeClient(client);
108 }
109
110 void WindowServerTestBase::OnEmbedRootDestroyed(Window* root) {
111 DeleteWindowTreeClient(root->window_tree());
112 }
113
114 void WindowServerTestBase::OnPointerEventObserved(const ui::PointerEvent& event,
115 Window* target) {}
116
117 void WindowServerTestBase::SetWindowManagerClient(WindowManagerClient* client) {
118 window_manager_client_ = client;
119 }
120
121 bool WindowServerTestBase::OnWmSetBounds(Window* window, gfx::Rect* bounds) {
122 return window_manager_delegate_
123 ? window_manager_delegate_->OnWmSetBounds(window, bounds)
124 : true;
125 }
126
127 bool WindowServerTestBase::OnWmSetProperty(
128 Window* window,
129 const std::string& name,
130 std::unique_ptr<std::vector<uint8_t>>* new_data) {
131 return window_manager_delegate_
132 ? window_manager_delegate_->OnWmSetProperty(window, name, new_data)
133 : true;
134 }
135
136 Window* WindowServerTestBase::OnWmCreateTopLevelWindow(
137 std::map<std::string, std::vector<uint8_t>>* properties) {
138 return window_manager_delegate_
139 ? window_manager_delegate_->OnWmCreateTopLevelWindow(properties)
140 : nullptr;
141 }
142
143 void WindowServerTestBase::OnWmClientJankinessChanged(
144 const std::set<Window*>& client_windows,
145 bool janky) {
146 if (window_manager_delegate_)
147 window_manager_delegate_->OnWmClientJankinessChanged(client_windows, janky);
148 }
149
150 void WindowServerTestBase::OnWmNewDisplay(Window* window,
151 const display::Display& display) {
152 EXPECT_TRUE(QuitRunLoop());
153 ASSERT_TRUE(window_manager_client_);
154 window_manager_client_->AddActivationParent(window);
155
156 if (window_manager_delegate_)
157 window_manager_delegate_->OnWmNewDisplay(window, display);
158 }
159
160 void WindowServerTestBase::OnWmDisplayRemoved(Window* window) {
161 if (window_manager_delegate_)
162 window_manager_delegate_->OnWmDisplayRemoved(window);
163 }
164
165 void WindowServerTestBase::OnWmDisplayModified(
166 const display::Display& display) {
167 if (window_manager_delegate_)
168 window_manager_delegate_->OnWmDisplayModified(display);
169 }
170
171 void WindowServerTestBase::OnWmPerformMoveLoop(
172 Window* window,
173 mojom::MoveLoopSource source,
174 const gfx::Point& cursor_location,
175 const base::Callback<void(bool)>& on_done) {
176 if (window_manager_delegate_) {
177 window_manager_delegate_->OnWmPerformMoveLoop(window, source,
178 cursor_location, on_done);
179 }
180 }
181
182 void WindowServerTestBase::OnWmCancelMoveLoop(Window* window) {
183 if (window_manager_delegate_)
184 window_manager_delegate_->OnWmCancelMoveLoop(window);
185 }
186
187 mojom::EventResult WindowServerTestBase::OnAccelerator(uint32_t accelerator_id,
188 const ui::Event& event) {
189 return window_manager_delegate_
190 ? window_manager_delegate_->OnAccelerator(accelerator_id, event)
191 : mojom::EventResult::UNHANDLED;
192 }
193
194 void WindowServerTestBase::Create(
195 const service_manager::Identity& remote_identity,
196 mojom::WindowTreeClientRequest request) {
197 window_tree_clients_.insert(
198 base::MakeUnique<WindowTreeClient>(this, nullptr, std::move(request)));
199 }
200
201 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698