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

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

Issue 1891413002: mash: Convert OnWindowInputEventAck to use an enum for handled status (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: missed a file Created 4 years, 8 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/window_manager_state.cc ('k') | components/mus/ws/window_tree.h » ('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 "base/macros.h" 7 #include "base/macros.h"
8 #include "base/memory/ref_counted.h" 8 #include "base/memory/ref_counted.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/test/test_simple_task_runner.h" 10 #include "base/test/test_simple_task_runner.h"
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 196
197 ServerWindow* target = window(); 197 ServerWindow* target = window();
198 ui::KeyEvent key(ui::ET_KEY_PRESSED, ui::VKEY_W, ui::EF_CONTROL_DOWN); 198 ui::KeyEvent key(ui::ET_KEY_PRESSED, ui::VKEY_W, ui::EF_CONTROL_DOWN);
199 DispatchInputEventToWindow(target, true, key, nullptr); 199 DispatchInputEventToWindow(target, true, key, nullptr);
200 WindowTree* target_tree = tree(); 200 WindowTree* target_tree = tree();
201 TestChangeTracker* tracker = wm_client()->tracker(); 201 TestChangeTracker* tracker = wm_client()->tracker();
202 EXPECT_EQ(1u, tracker->changes()->size()); 202 EXPECT_EQ(1u, tracker->changes()->size());
203 EXPECT_EQ("InputEvent window=1,1 event_action=1", 203 EXPECT_EQ("InputEvent window=1,1 event_action=1",
204 ChangesToDescription1(*tracker->changes())[0]); 204 ChangesToDescription1(*tracker->changes())[0]);
205 205
206 state->OnEventAck(target_tree, false); 206 state->OnEventAck(target_tree, mojom::EventResult::UNHANDLED);
207 EXPECT_FALSE(window_manager()->on_accelerator_called()); 207 EXPECT_FALSE(window_manager()->on_accelerator_called());
208 } 208 }
209 209
210 // Tests that when a post target accelerator is provided on an event, that it is 210 // Tests that when a post target accelerator is provided on an event, that it is
211 // called on ack. 211 // called on ack.
212 TEST_F(WindowManagerStateTest, PostTargetAccelerator) { 212 TEST_F(WindowManagerStateTest, PostTargetAccelerator) {
213 ui::KeyEvent key(ui::ET_KEY_PRESSED, ui::VKEY_W, ui::EF_CONTROL_DOWN); 213 ui::KeyEvent key(ui::ET_KEY_PRESSED, ui::VKEY_W, ui::EF_CONTROL_DOWN);
214 scoped_ptr<Accelerator> accelerator = CreateAccelerator(); 214 scoped_ptr<Accelerator> accelerator = CreateAccelerator();
215 215
216 ServerWindow* target = window(); 216 ServerWindow* target = window();
217 DispatchInputEventToWindow(target, true, key, accelerator.get()); 217 DispatchInputEventToWindow(target, true, key, accelerator.get());
218 TestChangeTracker* tracker = wm_client()->tracker(); 218 TestChangeTracker* tracker = wm_client()->tracker();
219 EXPECT_EQ(1u, tracker->changes()->size()); 219 EXPECT_EQ(1u, tracker->changes()->size());
220 EXPECT_EQ("InputEvent window=1,1 event_action=1", 220 EXPECT_EQ("InputEvent window=1,1 event_action=1",
221 ChangesToDescription1(*tracker->changes())[0]); 221 ChangesToDescription1(*tracker->changes())[0]);
222 222
223 window_manager_state()->OnEventAck(tree(), false); 223 window_manager_state()->OnEventAck(tree(), mojom::EventResult::UNHANDLED);
224 EXPECT_TRUE(window_manager()->on_accelerator_called()); 224 EXPECT_TRUE(window_manager()->on_accelerator_called());
225 EXPECT_EQ(accelerator->id(), window_manager()->on_accelerator_id()); 225 EXPECT_EQ(accelerator->id(), window_manager()->on_accelerator_id());
226 } 226 }
227 227
228 // Tests that when a client handles an event that post target accelerators are 228 // Tests that when a client handles an event that post target accelerators are
229 // not called. 229 // not called.
230 TEST_F(WindowManagerStateTest, ClientHandlesEvent) { 230 TEST_F(WindowManagerStateTest, ClientHandlesEvent) {
231 ui::KeyEvent key(ui::ET_KEY_PRESSED, ui::VKEY_W, ui::EF_CONTROL_DOWN); 231 ui::KeyEvent key(ui::ET_KEY_PRESSED, ui::VKEY_W, ui::EF_CONTROL_DOWN);
232 scoped_ptr<Accelerator> accelerator = CreateAccelerator(); 232 scoped_ptr<Accelerator> accelerator = CreateAccelerator();
233 233
234 ServerWindow* target = window(); 234 ServerWindow* target = window();
235 DispatchInputEventToWindow(target, true, key, accelerator.get()); 235 DispatchInputEventToWindow(target, true, key, accelerator.get());
236 TestChangeTracker* tracker = wm_client()->tracker(); 236 TestChangeTracker* tracker = wm_client()->tracker();
237 EXPECT_EQ(1u, tracker->changes()->size()); 237 EXPECT_EQ(1u, tracker->changes()->size());
238 EXPECT_EQ("InputEvent window=1,1 event_action=1", 238 EXPECT_EQ("InputEvent window=1,1 event_action=1",
239 ChangesToDescription1(*tracker->changes())[0]); 239 ChangesToDescription1(*tracker->changes())[0]);
240 240
241 window_manager_state()->OnEventAck(tree(), true); 241 window_manager_state()->OnEventAck(tree(), mojom::EventResult::HANDLED);
242 EXPECT_FALSE(window_manager()->on_accelerator_called()); 242 EXPECT_FALSE(window_manager()->on_accelerator_called());
243 } 243 }
244 244
245 // Tests that when an accelerator is deleted before an ack, that it is not 245 // Tests that when an accelerator is deleted before an ack, that it is not
246 // called. 246 // called.
247 TEST_F(WindowManagerStateTest, AcceleratorDeleted) { 247 TEST_F(WindowManagerStateTest, AcceleratorDeleted) {
248 ui::KeyEvent key(ui::ET_KEY_PRESSED, ui::VKEY_W, ui::EF_CONTROL_DOWN); 248 ui::KeyEvent key(ui::ET_KEY_PRESSED, ui::VKEY_W, ui::EF_CONTROL_DOWN);
249 scoped_ptr<Accelerator> accelerator(CreateAccelerator()); 249 scoped_ptr<Accelerator> accelerator(CreateAccelerator());
250 250
251 ServerWindow* target = window(); 251 ServerWindow* target = window();
252 DispatchInputEventToWindow(target, true, key, accelerator.get()); 252 DispatchInputEventToWindow(target, true, key, accelerator.get());
253 TestChangeTracker* tracker = wm_client()->tracker(); 253 TestChangeTracker* tracker = wm_client()->tracker();
254 EXPECT_EQ(1u, tracker->changes()->size()); 254 EXPECT_EQ(1u, tracker->changes()->size());
255 EXPECT_EQ("InputEvent window=1,1 event_action=1", 255 EXPECT_EQ("InputEvent window=1,1 event_action=1",
256 ChangesToDescription1(*tracker->changes())[0]); 256 ChangesToDescription1(*tracker->changes())[0]);
257 257
258 accelerator.reset(); 258 accelerator.reset();
259 window_manager_state()->OnEventAck(tree(), false); 259 window_manager_state()->OnEventAck(tree(), mojom::EventResult::UNHANDLED);
260 EXPECT_FALSE(window_manager()->on_accelerator_called()); 260 EXPECT_FALSE(window_manager()->on_accelerator_called());
261 } 261 }
262 262
263 // Tests that a events arriving before an ack don't notify the tree until the 263 // Tests that a events arriving before an ack don't notify the tree until the
264 // ack arrives, and that the correct accelerator is called. 264 // ack arrives, and that the correct accelerator is called.
265 TEST_F(WindowManagerStateTest, EnqueuedAccelerators) { 265 TEST_F(WindowManagerStateTest, EnqueuedAccelerators) {
266 WindowManagerState* state = window_manager_state(); 266 WindowManagerState* state = window_manager_state();
267 267
268 ui::KeyEvent key(ui::ET_KEY_PRESSED, ui::VKEY_W, ui::EF_CONTROL_DOWN); 268 ui::KeyEvent key(ui::ET_KEY_PRESSED, ui::VKEY_W, ui::EF_CONTROL_DOWN);
269 scoped_ptr<Accelerator> accelerator(CreateAccelerator()); 269 scoped_ptr<Accelerator> accelerator(CreateAccelerator());
(...skipping 11 matching lines...) Expand all
281 mus::mojom::KeyboardCode::Y, mus::mojom::kEventFlagControlDown); 281 mus::mojom::KeyboardCode::Y, mus::mojom::kEventFlagControlDown);
282 matcher->accelerator_phase = mojom::AcceleratorPhase::POST_TARGET; 282 matcher->accelerator_phase = mojom::AcceleratorPhase::POST_TARGET;
283 uint32_t accelerator_id = 2; 283 uint32_t accelerator_id = 2;
284 scoped_ptr<Accelerator> accelerator2( 284 scoped_ptr<Accelerator> accelerator2(
285 new Accelerator(accelerator_id, *matcher)); 285 new Accelerator(accelerator_id, *matcher));
286 DispatchInputEventToWindow(target, true, key2, accelerator2.get()); 286 DispatchInputEventToWindow(target, true, key2, accelerator2.get());
287 EXPECT_TRUE(tracker->changes()->empty()); 287 EXPECT_TRUE(tracker->changes()->empty());
288 288
289 WindowTree* target_tree = tree(); 289 WindowTree* target_tree = tree();
290 WindowTreeTestApi(target_tree).ClearAck(); 290 WindowTreeTestApi(target_tree).ClearAck();
291 state->OnEventAck(target_tree, false); 291 state->OnEventAck(target_tree, mojom::EventResult::UNHANDLED);
292 EXPECT_EQ(1u, tracker->changes()->size()); 292 EXPECT_EQ(1u, tracker->changes()->size());
293 EXPECT_EQ("InputEvent window=1,1 event_action=1", 293 EXPECT_EQ("InputEvent window=1,1 event_action=1",
294 ChangesToDescription1(*tracker->changes())[0]); 294 ChangesToDescription1(*tracker->changes())[0]);
295 EXPECT_TRUE(window_manager()->on_accelerator_called()); 295 EXPECT_TRUE(window_manager()->on_accelerator_called());
296 EXPECT_EQ(accelerator->id(), window_manager()->on_accelerator_id()); 296 EXPECT_EQ(accelerator->id(), window_manager()->on_accelerator_id());
297 } 297 }
298 298
299 // Tests that the accelerator is not sent when the tree is dying. 299 // Tests that the accelerator is not sent when the tree is dying.
300 TEST_F(WindowManagerStateTest, DeleteTree) { 300 TEST_F(WindowManagerStateTest, DeleteTree) {
301 ui::KeyEvent key(ui::ET_KEY_PRESSED, ui::VKEY_W, ui::EF_CONTROL_DOWN); 301 ui::KeyEvent key(ui::ET_KEY_PRESSED, ui::VKEY_W, ui::EF_CONTROL_DOWN);
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 ChangesToDescription1(*tracker->changes())[0]); 348 ChangesToDescription1(*tracker->changes())[0]);
349 349
350 OnEventAckTimeout(); 350 OnEventAckTimeout();
351 EXPECT_TRUE(window_manager()->on_accelerator_called()); 351 EXPECT_TRUE(window_manager()->on_accelerator_called());
352 EXPECT_EQ(accelerator->id(), window_manager()->on_accelerator_id()); 352 EXPECT_EQ(accelerator->id(), window_manager()->on_accelerator_id());
353 } 353 }
354 354
355 } // namespace test 355 } // namespace test
356 } // namespace ws 356 } // namespace ws
357 } // namespace mus 357 } // namespace mus
OLDNEW
« no previous file with comments | « components/mus/ws/window_manager_state.cc ('k') | components/mus/ws/window_tree.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698