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

Side by Side Diff: components/mus/ws/window_manager_state_unittest.cc

Issue 1939133002: StructTraits to map mus::mojom::Event to unique_ptr<ui::Event> (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed feedback. Created 4 years, 6 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
« no previous file with comments | « components/mus/ws/test_utils.cc ('k') | components/mus/ws/window_tree.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "components/mus/ws/window_manager_state.h" 5 #include "components/mus/ws/window_manager_state.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 TEST_F(WindowManagerStateTest, NullAccelerator) { 132 TEST_F(WindowManagerStateTest, NullAccelerator) {
133 WindowManagerState* state = window_manager_state(); 133 WindowManagerState* state = window_manager_state();
134 EXPECT_TRUE(state); 134 EXPECT_TRUE(state);
135 135
136 ServerWindow* target = window(); 136 ServerWindow* target = window();
137 ui::KeyEvent key(ui::ET_KEY_PRESSED, ui::VKEY_W, ui::EF_CONTROL_DOWN); 137 ui::KeyEvent key(ui::ET_KEY_PRESSED, ui::VKEY_W, ui::EF_CONTROL_DOWN);
138 DispatchInputEventToWindow(target, true, key, nullptr); 138 DispatchInputEventToWindow(target, true, key, nullptr);
139 WindowTree* target_tree = tree(); 139 WindowTree* target_tree = tree();
140 TestChangeTracker* tracker = wm_client()->tracker(); 140 TestChangeTracker* tracker = wm_client()->tracker();
141 EXPECT_EQ(1u, tracker->changes()->size()); 141 EXPECT_EQ(1u, tracker->changes()->size());
142 EXPECT_EQ("InputEvent window=1,1 event_action=1", 142 EXPECT_EQ("InputEvent window=1,1 event_action=7",
143 ChangesToDescription1(*tracker->changes())[0]); 143 ChangesToDescription1(*tracker->changes())[0]);
144 144
145 state->OnEventAck(target_tree, mojom::EventResult::UNHANDLED); 145 state->OnEventAck(target_tree, mojom::EventResult::UNHANDLED);
146 EXPECT_FALSE(window_manager()->on_accelerator_called()); 146 EXPECT_FALSE(window_manager()->on_accelerator_called());
147 } 147 }
148 148
149 // Tests that when a post target accelerator is provided on an event, that it is 149 // Tests that when a post target accelerator is provided on an event, that it is
150 // called on ack. 150 // called on ack.
151 TEST_F(WindowManagerStateTest, PostTargetAccelerator) { 151 TEST_F(WindowManagerStateTest, PostTargetAccelerator) {
152 ui::KeyEvent key(ui::ET_KEY_PRESSED, ui::VKEY_W, ui::EF_CONTROL_DOWN); 152 ui::KeyEvent key(ui::ET_KEY_PRESSED, ui::VKEY_W, ui::EF_CONTROL_DOWN);
153 std::unique_ptr<Accelerator> accelerator = CreateAccelerator(); 153 std::unique_ptr<Accelerator> accelerator = CreateAccelerator();
154 154
155 ServerWindow* target = window(); 155 ServerWindow* target = window();
156 DispatchInputEventToWindow(target, true, key, accelerator.get()); 156 DispatchInputEventToWindow(target, true, key, accelerator.get());
157 TestChangeTracker* tracker = wm_client()->tracker(); 157 TestChangeTracker* tracker = wm_client()->tracker();
158 EXPECT_EQ(1u, tracker->changes()->size()); 158 EXPECT_EQ(1u, tracker->changes()->size());
159 EXPECT_EQ("InputEvent window=1,1 event_action=1", 159 EXPECT_EQ("InputEvent window=1,1 event_action=7",
160 ChangesToDescription1(*tracker->changes())[0]); 160 ChangesToDescription1(*tracker->changes())[0]);
161 161
162 window_manager_state()->OnEventAck(tree(), mojom::EventResult::UNHANDLED); 162 window_manager_state()->OnEventAck(tree(), mojom::EventResult::UNHANDLED);
163 EXPECT_TRUE(window_manager()->on_accelerator_called()); 163 EXPECT_TRUE(window_manager()->on_accelerator_called());
164 EXPECT_EQ(accelerator->id(), window_manager()->on_accelerator_id()); 164 EXPECT_EQ(accelerator->id(), window_manager()->on_accelerator_id());
165 } 165 }
166 166
167 // Tests that when a client handles an event that post target accelerators are 167 // Tests that when a client handles an event that post target accelerators are
168 // not called. 168 // not called.
169 TEST_F(WindowManagerStateTest, ClientHandlesEvent) { 169 TEST_F(WindowManagerStateTest, ClientHandlesEvent) {
170 ui::KeyEvent key(ui::ET_KEY_PRESSED, ui::VKEY_W, ui::EF_CONTROL_DOWN); 170 ui::KeyEvent key(ui::ET_KEY_PRESSED, ui::VKEY_W, ui::EF_CONTROL_DOWN);
171 std::unique_ptr<Accelerator> accelerator = CreateAccelerator(); 171 std::unique_ptr<Accelerator> accelerator = CreateAccelerator();
172 172
173 ServerWindow* target = window(); 173 ServerWindow* target = window();
174 DispatchInputEventToWindow(target, true, key, accelerator.get()); 174 DispatchInputEventToWindow(target, true, key, accelerator.get());
175 TestChangeTracker* tracker = wm_client()->tracker(); 175 TestChangeTracker* tracker = wm_client()->tracker();
176 EXPECT_EQ(1u, tracker->changes()->size()); 176 EXPECT_EQ(1u, tracker->changes()->size());
177 EXPECT_EQ("InputEvent window=1,1 event_action=1", 177 EXPECT_EQ("InputEvent window=1,1 event_action=7",
178 ChangesToDescription1(*tracker->changes())[0]); 178 ChangesToDescription1(*tracker->changes())[0]);
179 179
180 window_manager_state()->OnEventAck(tree(), mojom::EventResult::HANDLED); 180 window_manager_state()->OnEventAck(tree(), mojom::EventResult::HANDLED);
181 EXPECT_FALSE(window_manager()->on_accelerator_called()); 181 EXPECT_FALSE(window_manager()->on_accelerator_called());
182 } 182 }
183 183
184 // Tests that when an accelerator is deleted before an ack, that it is not 184 // Tests that when an accelerator is deleted before an ack, that it is not
185 // called. 185 // called.
186 TEST_F(WindowManagerStateTest, AcceleratorDeleted) { 186 TEST_F(WindowManagerStateTest, AcceleratorDeleted) {
187 ui::KeyEvent key(ui::ET_KEY_PRESSED, ui::VKEY_W, ui::EF_CONTROL_DOWN); 187 ui::KeyEvent key(ui::ET_KEY_PRESSED, ui::VKEY_W, ui::EF_CONTROL_DOWN);
188 std::unique_ptr<Accelerator> accelerator(CreateAccelerator()); 188 std::unique_ptr<Accelerator> accelerator(CreateAccelerator());
189 189
190 ServerWindow* target = window(); 190 ServerWindow* target = window();
191 DispatchInputEventToWindow(target, true, key, accelerator.get()); 191 DispatchInputEventToWindow(target, true, key, accelerator.get());
192 TestChangeTracker* tracker = wm_client()->tracker(); 192 TestChangeTracker* tracker = wm_client()->tracker();
193 EXPECT_EQ(1u, tracker->changes()->size()); 193 EXPECT_EQ(1u, tracker->changes()->size());
194 EXPECT_EQ("InputEvent window=1,1 event_action=1", 194 EXPECT_EQ("InputEvent window=1,1 event_action=7",
195 ChangesToDescription1(*tracker->changes())[0]); 195 ChangesToDescription1(*tracker->changes())[0]);
196 196
197 accelerator.reset(); 197 accelerator.reset();
198 window_manager_state()->OnEventAck(tree(), mojom::EventResult::UNHANDLED); 198 window_manager_state()->OnEventAck(tree(), mojom::EventResult::UNHANDLED);
199 EXPECT_FALSE(window_manager()->on_accelerator_called()); 199 EXPECT_FALSE(window_manager()->on_accelerator_called());
200 } 200 }
201 201
202 // Tests that a events arriving before an ack don't notify the tree until the 202 // Tests that a events arriving before an ack don't notify the tree until the
203 // ack arrives, and that the correct accelerator is called. 203 // ack arrives, and that the correct accelerator is called.
204 TEST_F(WindowManagerStateTest, EnqueuedAccelerators) { 204 TEST_F(WindowManagerStateTest, EnqueuedAccelerators) {
205 WindowManagerState* state = window_manager_state(); 205 WindowManagerState* state = window_manager_state();
206 206
207 ui::KeyEvent key(ui::ET_KEY_PRESSED, ui::VKEY_W, ui::EF_CONTROL_DOWN); 207 ui::KeyEvent key(ui::ET_KEY_PRESSED, ui::VKEY_W, ui::EF_CONTROL_DOWN);
208 std::unique_ptr<Accelerator> accelerator(CreateAccelerator()); 208 std::unique_ptr<Accelerator> accelerator(CreateAccelerator());
209 209
210 ServerWindow* target = window(); 210 ServerWindow* target = window();
211 DispatchInputEventToWindow(target, true, key, accelerator.get()); 211 DispatchInputEventToWindow(target, true, key, accelerator.get());
212 TestChangeTracker* tracker = wm_client()->tracker(); 212 TestChangeTracker* tracker = wm_client()->tracker();
213 EXPECT_EQ(1u, tracker->changes()->size()); 213 EXPECT_EQ(1u, tracker->changes()->size());
214 EXPECT_EQ("InputEvent window=1,1 event_action=1", 214 EXPECT_EQ("InputEvent window=1,1 event_action=7",
215 ChangesToDescription1(*tracker->changes())[0]); 215 ChangesToDescription1(*tracker->changes())[0]);
216 216
217 tracker->changes()->clear(); 217 tracker->changes()->clear();
218 ui::KeyEvent key2(ui::ET_KEY_PRESSED, ui::VKEY_Y, ui::EF_CONTROL_DOWN); 218 ui::KeyEvent key2(ui::ET_KEY_PRESSED, ui::VKEY_Y, ui::EF_CONTROL_DOWN);
219 mojom::EventMatcherPtr matcher = mus::CreateKeyMatcher( 219 mojom::EventMatcherPtr matcher = mus::CreateKeyMatcher(
220 mus::mojom::KeyboardCode::Y, mus::mojom::kEventFlagControlDown); 220 mus::mojom::KeyboardCode::Y, mus::mojom::kEventFlagControlDown);
221 matcher->accelerator_phase = mojom::AcceleratorPhase::POST_TARGET; 221 matcher->accelerator_phase = mojom::AcceleratorPhase::POST_TARGET;
222 uint32_t accelerator_id = 2; 222 uint32_t accelerator_id = 2;
223 std::unique_ptr<Accelerator> accelerator2( 223 std::unique_ptr<Accelerator> accelerator2(
224 new Accelerator(accelerator_id, *matcher)); 224 new Accelerator(accelerator_id, *matcher));
225 DispatchInputEventToWindow(target, true, key2, accelerator2.get()); 225 DispatchInputEventToWindow(target, true, key2, accelerator2.get());
226 EXPECT_TRUE(tracker->changes()->empty()); 226 EXPECT_TRUE(tracker->changes()->empty());
227 227
228 WindowTree* target_tree = tree(); 228 WindowTree* target_tree = tree();
229 WindowTreeTestApi(target_tree).ClearAck(); 229 WindowTreeTestApi(target_tree).ClearAck();
230 state->OnEventAck(target_tree, mojom::EventResult::UNHANDLED); 230 state->OnEventAck(target_tree, mojom::EventResult::UNHANDLED);
231 EXPECT_EQ(1u, tracker->changes()->size()); 231 EXPECT_EQ(1u, tracker->changes()->size());
232 EXPECT_EQ("InputEvent window=1,1 event_action=1", 232 EXPECT_EQ("InputEvent window=1,1 event_action=7",
233 ChangesToDescription1(*tracker->changes())[0]); 233 ChangesToDescription1(*tracker->changes())[0]);
234 EXPECT_TRUE(window_manager()->on_accelerator_called()); 234 EXPECT_TRUE(window_manager()->on_accelerator_called());
235 EXPECT_EQ(accelerator->id(), window_manager()->on_accelerator_id()); 235 EXPECT_EQ(accelerator->id(), window_manager()->on_accelerator_id());
236 } 236 }
237 237
238 // Tests that the accelerator is not sent when the tree is dying. 238 // Tests that the accelerator is not sent when the tree is dying.
239 TEST_F(WindowManagerStateTest, DeleteTree) { 239 TEST_F(WindowManagerStateTest, DeleteTree) {
240 ui::KeyEvent key(ui::ET_KEY_PRESSED, ui::VKEY_W, ui::EF_CONTROL_DOWN); 240 ui::KeyEvent key(ui::ET_KEY_PRESSED, ui::VKEY_W, ui::EF_CONTROL_DOWN);
241 std::unique_ptr<Accelerator> accelerator = CreateAccelerator(); 241 std::unique_ptr<Accelerator> accelerator = CreateAccelerator();
242 242
243 ServerWindow* target = window(); 243 ServerWindow* target = window();
244 DispatchInputEventToWindow(target, true, key, accelerator.get()); 244 DispatchInputEventToWindow(target, true, key, accelerator.get());
245 TestChangeTracker* tracker = wm_client()->tracker(); 245 TestChangeTracker* tracker = wm_client()->tracker();
246 EXPECT_EQ(1u, tracker->changes()->size()); 246 EXPECT_EQ(1u, tracker->changes()->size());
247 EXPECT_EQ("InputEvent window=1,1 event_action=1", 247 EXPECT_EQ("InputEvent window=1,1 event_action=7",
248 ChangesToDescription1(*tracker->changes())[0]); 248 ChangesToDescription1(*tracker->changes())[0]);
249 249
250 window_manager_state()->OnWillDestroyTree(tree()); 250 window_manager_state()->OnWillDestroyTree(tree());
251 EXPECT_FALSE(window_manager()->on_accelerator_called()); 251 EXPECT_FALSE(window_manager()->on_accelerator_called());
252 } 252 }
253 253
254 // Tests that if a tree is destroyed before acking, that the accelerator is 254 // Tests that if a tree is destroyed before acking, that the accelerator is
255 // still sent if it is not the root tree. 255 // still sent if it is not the root tree.
256 TEST_F(WindowManagerStateTest, DeleteNonRootTree) { 256 TEST_F(WindowManagerStateTest, DeleteNonRootTree) {
257 TestWindowTreeClient* embed_connection = nullptr; 257 TestWindowTreeClient* embed_connection = nullptr;
258 WindowTree* target_tree = nullptr; 258 WindowTree* target_tree = nullptr;
259 ServerWindow* target = nullptr; 259 ServerWindow* target = nullptr;
260 CreateSecondaryTree(&embed_connection, &target_tree, &target); 260 CreateSecondaryTree(&embed_connection, &target_tree, &target);
261 TestWindowManager target_window_manager; 261 TestWindowManager target_window_manager;
262 WindowTreeTestApi(target_tree) 262 WindowTreeTestApi(target_tree)
263 .set_window_manager_internal(&target_window_manager); 263 .set_window_manager_internal(&target_window_manager);
264 264
265 ui::KeyEvent key(ui::ET_KEY_PRESSED, ui::VKEY_W, ui::EF_CONTROL_DOWN); 265 ui::KeyEvent key(ui::ET_KEY_PRESSED, ui::VKEY_W, ui::EF_CONTROL_DOWN);
266 std::unique_ptr<Accelerator> accelerator = CreateAccelerator(); 266 std::unique_ptr<Accelerator> accelerator = CreateAccelerator();
267 DispatchInputEventToWindow(target, true, key, accelerator.get()); 267 DispatchInputEventToWindow(target, true, key, accelerator.get());
268 TestChangeTracker* tracker = embed_connection->tracker(); 268 TestChangeTracker* tracker = embed_connection->tracker();
269 EXPECT_EQ(1u, tracker->changes()->size()); 269 EXPECT_EQ(1u, tracker->changes()->size());
270 EXPECT_EQ("InputEvent window=2,1 event_action=1", 270 EXPECT_EQ("InputEvent window=2,1 event_action=7",
271 ChangesToDescription1(*tracker->changes())[0]); 271 ChangesToDescription1(*tracker->changes())[0]);
272 EXPECT_TRUE(wm_client()->tracker()->changes()->empty()); 272 EXPECT_TRUE(wm_client()->tracker()->changes()->empty());
273 273
274 window_manager_state()->OnWillDestroyTree(target_tree); 274 window_manager_state()->OnWillDestroyTree(target_tree);
275 EXPECT_FALSE(target_window_manager.on_accelerator_called()); 275 EXPECT_FALSE(target_window_manager.on_accelerator_called());
276 EXPECT_TRUE(window_manager()->on_accelerator_called()); 276 EXPECT_TRUE(window_manager()->on_accelerator_called());
277 } 277 }
278 278
279 // Tests that when an ack times out that the accelerator is notified. 279 // Tests that when an ack times out that the accelerator is notified.
280 TEST_F(WindowManagerStateTest, AckTimeout) { 280 TEST_F(WindowManagerStateTest, AckTimeout) {
281 ui::KeyEvent key(ui::ET_KEY_PRESSED, ui::VKEY_W, ui::EF_CONTROL_DOWN); 281 ui::KeyEvent key(ui::ET_KEY_PRESSED, ui::VKEY_W, ui::EF_CONTROL_DOWN);
282 std::unique_ptr<Accelerator> accelerator = CreateAccelerator(); 282 std::unique_ptr<Accelerator> accelerator = CreateAccelerator();
283 DispatchInputEventToWindow(window(), true, key, accelerator.get()); 283 DispatchInputEventToWindow(window(), true, key, accelerator.get());
284 TestChangeTracker* tracker = wm_client()->tracker(); 284 TestChangeTracker* tracker = wm_client()->tracker();
285 EXPECT_EQ(1u, tracker->changes()->size()); 285 EXPECT_EQ(1u, tracker->changes()->size());
286 EXPECT_EQ("InputEvent window=1,1 event_action=1", 286 EXPECT_EQ("InputEvent window=1,1 event_action=7",
287 ChangesToDescription1(*tracker->changes())[0]); 287 ChangesToDescription1(*tracker->changes())[0]);
288 288
289 OnEventAckTimeout(window()->id().client_id); 289 OnEventAckTimeout(window()->id().client_id);
290 EXPECT_TRUE(window_manager()->on_accelerator_called()); 290 EXPECT_TRUE(window_manager()->on_accelerator_called());
291 EXPECT_EQ(accelerator->id(), window_manager()->on_accelerator_id()); 291 EXPECT_EQ(accelerator->id(), window_manager()->on_accelerator_id());
292 } 292 }
293 293
294 } // namespace test 294 } // namespace test
295 } // namespace ws 295 } // namespace ws
296 } // namespace mus 296 } // namespace mus
OLDNEW
« no previous file with comments | « components/mus/ws/test_utils.cc ('k') | components/mus/ws/window_tree.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698