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 "ash/common/shell_window_ids.h" | 5 #include "ash/common/shell_window_ids.h" |
6 #include "ash/common/wm_shell.h" | |
6 #include "ash/shell.h" | 7 #include "ash/shell.h" |
8 #include "ash/wm/window_util.h" | |
7 #include "components/exo/buffer.h" | 9 #include "components/exo/buffer.h" |
8 #include "components/exo/pointer.h" | 10 #include "components/exo/pointer.h" |
9 #include "components/exo/pointer_delegate.h" | 11 #include "components/exo/pointer_delegate.h" |
10 #include "components/exo/shell_surface.h" | 12 #include "components/exo/shell_surface.h" |
11 #include "components/exo/surface.h" | 13 #include "components/exo/surface.h" |
12 #include "components/exo/test/exo_test_base.h" | 14 #include "components/exo/test/exo_test_base.h" |
13 #include "components/exo/test/exo_test_helper.h" | 15 #include "components/exo/test/exo_test_helper.h" |
14 #include "testing/gmock/include/gmock/gmock.h" | 16 #include "testing/gmock/include/gmock/gmock.h" |
15 #include "ui/events/event_utils.h" | 17 #include "ui/events/event_utils.h" |
16 #include "ui/events/test/event_generator.h" | 18 #include "ui/events/test/event_generator.h" |
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
282 generator.MoveMouseTo(surface->window()->GetBoundsInScreen().origin()); | 284 generator.MoveMouseTo(surface->window()->GetBoundsInScreen().origin()); |
283 | 285 |
284 EXPECT_CALL(delegate, | 286 EXPECT_CALL(delegate, |
285 OnPointerScroll(testing::_, gfx::Vector2dF(1, 1), true)); | 287 OnPointerScroll(testing::_, gfx::Vector2dF(1, 1), true)); |
286 generator.MoveMouseWheel(1, 1); | 288 generator.MoveMouseWheel(1, 1); |
287 | 289 |
288 EXPECT_CALL(delegate, OnPointerDestroying(pointer.get())); | 290 EXPECT_CALL(delegate, OnPointerDestroying(pointer.get())); |
289 pointer.reset(); | 291 pointer.reset(); |
290 } | 292 } |
291 | 293 |
294 TEST_F(PointerTest, IgnorePointerEventDuringModal) { | |
295 std::unique_ptr<Surface> surface(new Surface); | |
296 std::unique_ptr<ShellSurface> shell_surface(new ShellSurface(surface.get())); | |
297 std::unique_ptr<Buffer> buffer( | |
298 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(gfx::Size(10, 10)))); | |
299 surface->Attach(buffer.get()); | |
300 surface->Commit(); | |
301 gfx::Point location = surface->window()->GetBoundsInScreen().origin(); | |
302 gfx::Point location2 = | |
303 surface->window()->GetBoundsInScreen().origin() + gfx::Vector2d(1, 1); | |
oshima
2016/07/08 21:26:51
since this is used only once, you can just inline
hariank
2016/07/08 22:47:07
Done.
| |
304 gfx::Point location3 = surface->window()->GetBoundsInScreen().bottom_right(); | |
oshima
2016/07/08 21:26:51
ditto.
hariank
2016/07/08 22:47:07
Done.
| |
305 | |
306 MockPointerDelegate delegate; | |
307 std::unique_ptr<Pointer> pointer(new Pointer(&delegate)); | |
308 ui::test::EventGenerator generator(ash::Shell::GetPrimaryRootWindow()); | |
309 | |
310 // Create surface for modal window. | |
311 std::unique_ptr<Surface> surface2(new Surface); | |
312 std::unique_ptr<ShellSurface> shell_surface2( | |
313 new ShellSurface(surface2.get(), nullptr, gfx::Rect(0, 0, 5, 5), true, | |
314 ash::kShellWindowId_SystemModalContainer)); | |
315 std::unique_ptr<Buffer> buffer2( | |
316 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(gfx::Size(5, 5)))); | |
317 surface2->Attach(buffer2.get()); | |
318 surface2->Commit(); | |
319 ash::wm::CenterWindow(surface2->window()); | |
320 | |
321 // Make the window modal. | |
322 shell_surface2->SetSystemModal(true); | |
323 EXPECT_TRUE(ash::WmShell::Get()->IsSystemModalWindowOpen()); | |
324 | |
325 EXPECT_CALL(delegate, CanAcceptPointerEventsForSurface(surface.get())) | |
326 .WillRepeatedly(testing::Return(true)); | |
327 | |
328 // Check if pointer events on non-modal window are ignored. | |
329 testing::Sequence s1, s2; | |
oshima
2016/07/08 21:26:51
Can you do the following? I think it's easier to u
hariank
2016/07/08 22:47:07
Done.
| |
330 | |
331 EXPECT_CALL(delegate, OnPointerEnter(surface.get(), gfx::PointF(), 0)) | |
332 .Times(0) | |
333 .InSequence(s1); | |
334 generator.MoveMouseTo(location); | |
335 | |
336 EXPECT_CALL(delegate, OnPointerMotion(testing::_, gfx::PointF(1, 1))) | |
337 .Times(0) | |
338 .InSequence(s1); | |
339 generator.MoveMouseTo(location2); | |
340 | |
341 EXPECT_CALL(delegate, | |
342 OnPointerButton(testing::_, ui::EF_LEFT_MOUSE_BUTTON, true)) | |
343 .Times(0) | |
344 .InSequence(s1); | |
345 EXPECT_CALL(delegate, | |
346 OnPointerButton(testing::_, ui::EF_LEFT_MOUSE_BUTTON, false)) | |
347 .Times(0) | |
348 .InSequence(s1); | |
349 generator.ClickLeftButton(); | |
350 | |
351 EXPECT_CALL(delegate, OnPointerScrollCancel(testing::_)) | |
352 .Times(0) | |
353 .InSequence(s1); | |
354 EXPECT_CALL(delegate, | |
355 OnPointerScroll(testing::_, gfx::Vector2dF(1.2, 1.2), false)) | |
356 .Times(0) | |
357 .InSequence(s1); | |
358 EXPECT_CALL(delegate, OnPointerScrollStop(testing::_)) | |
359 .Times(0) | |
360 .InSequence(s1); | |
361 generator.ScrollSequence(location, base::TimeDelta(), 1, 1, 1, 1); | |
362 | |
363 EXPECT_CALL(delegate, OnPointerLeave(surface.get())).Times(0).InSequence(s1); | |
364 generator.MoveMouseTo(location3); | |
365 | |
366 // Make the window non-modal. | |
367 shell_surface2->SetSystemModal(false); | |
368 EXPECT_FALSE(ash::WmShell::Get()->IsSystemModalWindowOpen()); | |
369 | |
370 // Check if pointer events on non-modal window are registered. | |
371 EXPECT_CALL(delegate, OnPointerEnter(surface.get(), gfx::PointF(), 0)) | |
372 .InSequence(s2); | |
373 generator.MoveMouseTo(location); | |
374 | |
375 EXPECT_CALL(delegate, OnPointerMotion(testing::_, gfx::PointF(1, 1))) | |
376 .InSequence(s2); | |
377 generator.MoveMouseTo(location2); | |
378 | |
379 EXPECT_CALL(delegate, | |
380 OnPointerButton(testing::_, ui::EF_LEFT_MOUSE_BUTTON, true)) | |
381 .InSequence(s2); | |
382 EXPECT_CALL(delegate, | |
383 OnPointerButton(testing::_, ui::EF_LEFT_MOUSE_BUTTON, false)) | |
384 .InSequence(s2); | |
385 generator.ClickLeftButton(); | |
386 | |
387 EXPECT_CALL(delegate, OnPointerScrollCancel(testing::_)).InSequence(s2); | |
388 EXPECT_CALL(delegate, | |
389 OnPointerScroll(testing::_, gfx::Vector2dF(1.2, 1.2), false)) | |
390 .InSequence(s2); | |
391 EXPECT_CALL(delegate, OnPointerScrollStop(testing::_)).InSequence(s2); | |
392 generator.ScrollSequence(location, base::TimeDelta(), 1, 1, 1, 1); | |
393 | |
394 EXPECT_CALL(delegate, OnPointerLeave(surface.get())).InSequence(s2); | |
395 generator.MoveMouseTo(location3); | |
396 | |
397 EXPECT_CALL(delegate, OnPointerDestroying(pointer.get())).InSequence(s2); | |
398 pointer.reset(); | |
399 } | |
400 | |
292 } // namespace | 401 } // namespace |
293 } // namespace exo | 402 } // namespace exo |
OLD | NEW |