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 |
| 303 MockPointerDelegate delegate; |
| 304 std::unique_ptr<Pointer> pointer(new Pointer(&delegate)); |
| 305 ui::test::EventGenerator generator(ash::Shell::GetPrimaryRootWindow()); |
| 306 |
| 307 // Create surface for modal window. |
| 308 std::unique_ptr<Surface> surface2(new Surface); |
| 309 std::unique_ptr<ShellSurface> shell_surface2( |
| 310 new ShellSurface(surface2.get(), nullptr, gfx::Rect(0, 0, 5, 5), true, |
| 311 ash::kShellWindowId_SystemModalContainer)); |
| 312 std::unique_ptr<Buffer> buffer2( |
| 313 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(gfx::Size(5, 5)))); |
| 314 surface2->Attach(buffer2.get()); |
| 315 surface2->Commit(); |
| 316 ash::wm::CenterWindow(surface2->window()); |
| 317 gfx::Point location2 = surface2->window()->GetBoundsInScreen().origin(); |
| 318 |
| 319 // Make the window modal. |
| 320 shell_surface2->SetSystemModal(true); |
| 321 EXPECT_TRUE(ash::WmShell::Get()->IsSystemModalWindowOpen()); |
| 322 |
| 323 EXPECT_CALL(delegate, CanAcceptPointerEventsForSurface(surface.get())) |
| 324 .WillRepeatedly(testing::Return(true)); |
| 325 EXPECT_CALL(delegate, CanAcceptPointerEventsForSurface(surface2.get())) |
| 326 .WillRepeatedly(testing::Return(true)); |
| 327 |
| 328 // Check if pointer events on modal window are registered. |
| 329 { |
| 330 testing::InSequence sequence; |
| 331 EXPECT_CALL(delegate, OnPointerEnter(surface2.get(), gfx::PointF(), 0)); |
| 332 } |
| 333 generator.MoveMouseTo(location2); |
| 334 |
| 335 { |
| 336 testing::InSequence sequence; |
| 337 EXPECT_CALL(delegate, OnPointerMotion(testing::_, gfx::PointF(1, 1))); |
| 338 } |
| 339 generator.MoveMouseTo(location2 + gfx::Vector2d(1, 1)); |
| 340 |
| 341 { |
| 342 testing::InSequence sequence; |
| 343 EXPECT_CALL(delegate, |
| 344 OnPointerButton(testing::_, ui::EF_LEFT_MOUSE_BUTTON, true)); |
| 345 EXPECT_CALL(delegate, |
| 346 OnPointerButton(testing::_, ui::EF_LEFT_MOUSE_BUTTON, false)); |
| 347 } |
| 348 generator.ClickLeftButton(); |
| 349 |
| 350 { |
| 351 testing::InSequence sequence; |
| 352 EXPECT_CALL(delegate, OnPointerScrollCancel(testing::_)); |
| 353 EXPECT_CALL(delegate, |
| 354 OnPointerScroll(testing::_, gfx::Vector2dF(1.2, 1.2), false)); |
| 355 EXPECT_CALL(delegate, OnPointerScrollStop(testing::_)); |
| 356 } |
| 357 generator.ScrollSequence(location2, base::TimeDelta(), 1, 1, 1, 1); |
| 358 |
| 359 { |
| 360 testing::InSequence sequence; |
| 361 EXPECT_CALL(delegate, OnPointerLeave(surface2.get())); |
| 362 } |
| 363 generator.MoveMouseTo(surface2->window()->GetBoundsInScreen().bottom_right()); |
| 364 |
| 365 // Check if pointer events on non-modal window are ignored. |
| 366 { |
| 367 testing::InSequence sequence; |
| 368 EXPECT_CALL(delegate, OnPointerEnter(surface.get(), gfx::PointF(), 0)) |
| 369 .Times(0); |
| 370 } |
| 371 generator.MoveMouseTo(location); |
| 372 |
| 373 { |
| 374 testing::InSequence sequence; |
| 375 EXPECT_CALL(delegate, OnPointerMotion(testing::_, gfx::PointF(1, 1))) |
| 376 .Times(0); |
| 377 } |
| 378 generator.MoveMouseTo(location + gfx::Vector2d(1, 1)); |
| 379 |
| 380 { |
| 381 testing::InSequence sequence; |
| 382 EXPECT_CALL(delegate, |
| 383 OnPointerButton(testing::_, ui::EF_LEFT_MOUSE_BUTTON, true)) |
| 384 .Times(0); |
| 385 EXPECT_CALL(delegate, |
| 386 OnPointerButton(testing::_, ui::EF_LEFT_MOUSE_BUTTON, false)) |
| 387 .Times(0); |
| 388 } |
| 389 generator.ClickLeftButton(); |
| 390 |
| 391 { |
| 392 testing::InSequence sequence; |
| 393 EXPECT_CALL(delegate, OnPointerScrollCancel(testing::_)).Times(0); |
| 394 EXPECT_CALL(delegate, |
| 395 OnPointerScroll(testing::_, gfx::Vector2dF(1.2, 1.2), false)) |
| 396 .Times(0); |
| 397 EXPECT_CALL(delegate, OnPointerScrollStop(testing::_)).Times(0); |
| 398 } |
| 399 generator.ScrollSequence(location, base::TimeDelta(), 1, 1, 1, 1); |
| 400 |
| 401 { |
| 402 testing::InSequence sequence; |
| 403 EXPECT_CALL(delegate, OnPointerLeave(surface.get())).Times(0); |
| 404 } |
| 405 generator.MoveMouseTo(surface->window()->GetBoundsInScreen().bottom_right()); |
| 406 |
| 407 // Make the window non-modal. |
| 408 shell_surface2->SetSystemModal(false); |
| 409 EXPECT_FALSE(ash::WmShell::Get()->IsSystemModalWindowOpen()); |
| 410 |
| 411 // Check if pointer events on non-modal window are registered. |
| 412 { |
| 413 testing::InSequence sequence; |
| 414 EXPECT_CALL(delegate, OnPointerEnter(surface.get(), gfx::PointF(), 0)); |
| 415 } |
| 416 generator.MoveMouseTo(location); |
| 417 |
| 418 { |
| 419 testing::InSequence sequence; |
| 420 EXPECT_CALL(delegate, OnPointerMotion(testing::_, gfx::PointF(1, 1))); |
| 421 } |
| 422 generator.MoveMouseTo(location + gfx::Vector2d(1, 1)); |
| 423 |
| 424 { |
| 425 testing::InSequence sequence; |
| 426 EXPECT_CALL(delegate, |
| 427 OnPointerButton(testing::_, ui::EF_LEFT_MOUSE_BUTTON, true)); |
| 428 EXPECT_CALL(delegate, |
| 429 OnPointerButton(testing::_, ui::EF_LEFT_MOUSE_BUTTON, false)); |
| 430 } |
| 431 generator.ClickLeftButton(); |
| 432 |
| 433 { |
| 434 testing::InSequence sequence; |
| 435 EXPECT_CALL(delegate, OnPointerScrollCancel(testing::_)); |
| 436 EXPECT_CALL(delegate, |
| 437 OnPointerScroll(testing::_, gfx::Vector2dF(1.2, 1.2), false)); |
| 438 EXPECT_CALL(delegate, OnPointerScrollStop(testing::_)); |
| 439 } |
| 440 generator.ScrollSequence(location, base::TimeDelta(), 1, 1, 1, 1); |
| 441 |
| 442 { |
| 443 testing::InSequence sequence; |
| 444 EXPECT_CALL(delegate, OnPointerLeave(surface.get())); |
| 445 } |
| 446 generator.MoveMouseTo(surface->window()->GetBoundsInScreen().bottom_right()); |
| 447 |
| 448 EXPECT_CALL(delegate, OnPointerDestroying(pointer.get())); |
| 449 pointer.reset(); |
| 450 } |
| 451 |
292 } // namespace | 452 } // namespace |
293 } // namespace exo | 453 } // namespace exo |
OLD | NEW |