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

Side by Side Diff: components/mus/public/cpp/tests/window_server_test_base.cc

Issue 2119963002: Move mus to //services/ui (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 5 months 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 "components/mus/public/cpp/tests/window_server_test_base.h"
6
7 #include "base/bind.h"
8 #include "base/location.h"
9 #include "base/run_loop.h"
10 #include "base/single_thread_task_runner.h"
11 #include "base/test/test_timeouts.h"
12 #include "base/threading/thread_task_runner_handle.h"
13 #include "components/mus/public/cpp/window.h"
14 #include "components/mus/public/cpp/window_tree_client.h"
15 #include "components/mus/public/cpp/window_tree_host_factory.h"
16 #include "services/shell/public/cpp/connector.h"
17
18 namespace mus {
19 namespace {
20
21 base::RunLoop* current_run_loop = nullptr;
22
23 void TimeoutRunLoop(const base::Closure& timeout_task, bool* timeout) {
24 CHECK(current_run_loop);
25 *timeout = true;
26 timeout_task.Run();
27 }
28
29 } // namespace
30
31 WindowServerTestBase::WindowServerTestBase()
32 : most_recent_client_(nullptr),
33 window_manager_(nullptr),
34 window_manager_delegate_(nullptr),
35 window_manager_client_(nullptr),
36 window_tree_client_destroyed_(false) {}
37
38 WindowServerTestBase::~WindowServerTestBase() {}
39
40 // static
41 bool WindowServerTestBase::DoRunLoopWithTimeout() {
42 if (current_run_loop != nullptr)
43 return false;
44
45 bool timeout = false;
46 base::RunLoop run_loop;
47 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
48 FROM_HERE, base::Bind(&TimeoutRunLoop, run_loop.QuitClosure(), &timeout),
49 TestTimeouts::action_timeout());
50
51 current_run_loop = &run_loop;
52 current_run_loop->Run();
53 current_run_loop = nullptr;
54 return !timeout;
55 }
56
57 // static
58 bool WindowServerTestBase::QuitRunLoop() {
59 if (!current_run_loop)
60 return false;
61
62 current_run_loop->Quit();
63 current_run_loop = nullptr;
64 return true;
65 }
66
67 void WindowServerTestBase::SetUp() {
68 WindowServerShellTestBase::SetUp();
69
70 CreateWindowTreeHost(connector(), this, &host_, this);
71
72 ASSERT_TRUE(DoRunLoopWithTimeout()); // RunLoop should be quit by OnEmbed().
73 std::swap(window_manager_, most_recent_client_);
74 }
75
76 bool WindowServerTestBase::AcceptConnection(shell::Connection* connection) {
77 connection->AddInterface<mojom::WindowTreeClient>(this);
78 return true;
79 }
80
81 void WindowServerTestBase::OnEmbed(Window* root) {
82 most_recent_client_ = root->window_tree();
83 EXPECT_TRUE(QuitRunLoop());
84 ASSERT_TRUE(window_manager_client_);
85 window_manager_client_->AddActivationParent(root);
86 }
87
88 void WindowServerTestBase::OnDidDestroyClient(WindowTreeClient* client) {
89 window_tree_client_destroyed_ = true;
90 }
91
92 void WindowServerTestBase::OnEventObserved(const ui::Event& event,
93 Window* target) {}
94
95 void WindowServerTestBase::SetWindowManagerClient(WindowManagerClient* client) {
96 window_manager_client_ = client;
97 }
98
99 bool WindowServerTestBase::OnWmSetBounds(Window* window, gfx::Rect* bounds) {
100 return window_manager_delegate_
101 ? window_manager_delegate_->OnWmSetBounds(window, bounds)
102 : true;
103 }
104
105 bool WindowServerTestBase::OnWmSetProperty(
106 Window* window,
107 const std::string& name,
108 std::unique_ptr<std::vector<uint8_t>>* new_data) {
109 return window_manager_delegate_
110 ? window_manager_delegate_->OnWmSetProperty(window, name, new_data)
111 : true;
112 }
113
114 Window* WindowServerTestBase::OnWmCreateTopLevelWindow(
115 std::map<std::string, std::vector<uint8_t>>* properties) {
116 return window_manager_delegate_
117 ? window_manager_delegate_->OnWmCreateTopLevelWindow(properties)
118 : nullptr;
119 }
120
121 void WindowServerTestBase::OnWmClientJankinessChanged(
122 const std::set<Window*>& client_windows,
123 bool janky) {
124 if (window_manager_delegate_)
125 window_manager_delegate_->OnWmClientJankinessChanged(client_windows, janky);
126 }
127
128 void WindowServerTestBase::OnWmNewDisplay(Window* window,
129 const display::Display& display) {
130 if (window_manager_delegate_)
131 window_manager_delegate_->OnWmNewDisplay(window, display);
132 }
133
134 void WindowServerTestBase::OnAccelerator(uint32_t id, const ui::Event& event) {
135 if (window_manager_delegate_)
136 window_manager_delegate_->OnAccelerator(id, event);
137 }
138
139 void WindowServerTestBase::Create(shell::Connection* connection,
140 mojom::WindowTreeClientRequest request) {
141 new WindowTreeClient(this, nullptr, std::move(request));
142 }
143
144 } // namespace mus
OLDNEW
« no previous file with comments | « components/mus/public/cpp/tests/window_server_test_base.h ('k') | components/mus/public/cpp/tests/window_server_test_suite.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698