Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/wm/system_modal_container_layout_manager.h" | 5 #include "ash/wm/system_modal_container_layout_manager.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "ash/common/session/session_state_delegate.h" | 9 #include "ash/common/session/session_state_delegate.h" |
| 10 #include "ash/common/shell_window_ids.h" | 10 #include "ash/common/shell_window_ids.h" |
| (...skipping 668 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 679 EXPECT_FALSE(WmShell::Get()->IsSystemModalWindowOpen()); | 679 EXPECT_FALSE(WmShell::Get()->IsSystemModalWindowOpen()); |
| 680 } | 680 } |
| 681 | 681 |
| 682 namespace { | 682 namespace { |
| 683 | 683 |
| 684 class InputTestDelegate : public aura::test::TestWindowDelegate { | 684 class InputTestDelegate : public aura::test::TestWindowDelegate { |
| 685 public: | 685 public: |
| 686 InputTestDelegate() {} | 686 InputTestDelegate() {} |
| 687 ~InputTestDelegate() override {} | 687 ~InputTestDelegate() override {} |
| 688 | 688 |
| 689 void RunTest(test::AshTestBase* test_base) { | |
| 690 std::unique_ptr<aura::Window> window( | |
| 691 test_base->CreateTestWindowInShellWithDelegate( | |
| 692 this, 0, gfx::Rect(0, 0, 100, 100))); | |
| 693 window->Show(); | |
| 694 | |
| 695 GenerateEvents(window.get()); | |
| 696 | |
| 697 EXPECT_EQ(2, mouse_event_count_); | |
| 698 EXPECT_EQ(3, scroll_event_count_); | |
| 699 EXPECT_EQ(4, touch_event_count_); | |
| 700 EXPECT_EQ(10, gesture_event_count_); | |
| 701 | |
| 702 views::Widget* widget = views::Widget::CreateWindowWithContextAndBounds( | |
| 703 new TestWindow(true), Shell::GetPrimaryRootWindow(), | |
| 704 gfx::Rect(200, 200, 100, 100)); | |
| 705 widget->Show(); | |
| 706 EXPECT_TRUE(WmShell::Get()->IsSystemModalWindowOpen()); | |
| 707 | |
| 708 // Events should be blocked. | |
| 709 GenerateEvents(window.get()); | |
| 710 | |
| 711 EXPECT_EQ(2, mouse_event_count_); | |
|
James Cook
2016/06/20 17:33:20
nit: Can you add a Reset() method that puts all th
oshima
2016/06/20 18:23:54
Done.
| |
| 712 EXPECT_EQ(3, scroll_event_count_); | |
| 713 EXPECT_EQ(4, touch_event_count_); | |
| 714 EXPECT_EQ(10, gesture_event_count_); | |
| 715 | |
| 716 widget->Close(); | |
| 717 EXPECT_FALSE(WmShell::Get()->IsSystemModalWindowOpen()); | |
| 718 | |
| 719 GenerateEvents(window.get()); | |
| 720 | |
| 721 EXPECT_EQ(4, mouse_event_count_); | |
| 722 EXPECT_EQ(6, scroll_event_count_); | |
| 723 EXPECT_EQ(8, touch_event_count_); | |
| 724 EXPECT_EQ(20, gesture_event_count_); | |
| 725 } | |
| 726 | |
| 727 private: | |
| 689 // ui::EventHandler: | 728 // ui::EventHandler: |
| 690 void OnMouseEvent(ui::MouseEvent* event) override { mouse_event_count_++; } | 729 void OnMouseEvent(ui::MouseEvent* event) override { mouse_event_count_++; } |
| 730 void OnScrollEvent(ui::ScrollEvent* event) override { scroll_event_count_++; } | |
| 731 void OnTouchEvent(ui::TouchEvent* event) override { touch_event_count_++; } | |
| 732 void OnGestureEvent(ui::GestureEvent* event) override { | |
| 733 gesture_event_count_++; | |
| 734 } | |
| 691 | 735 |
| 692 int mouse_event_count() const { return mouse_event_count_; } | 736 void GenerateEvents(aura::Window* window) { |
| 737 ui::test::EventGenerator event_generator(Shell::GetPrimaryRootWindow(), | |
| 738 window); | |
| 739 event_generator.ClickLeftButton(); | |
| 740 event_generator.ScrollSequence(window->bounds().CenterPoint(), | |
| 741 base::TimeDelta(), 0, 10, 1, 2); | |
| 742 event_generator.PressTouch(); | |
| 743 event_generator.ReleaseTouch(); | |
| 744 event_generator.GestureTapAt(window->bounds().CenterPoint()); | |
| 745 } | |
| 693 | 746 |
| 694 private: | |
| 695 int mouse_event_count_ = 0; | 747 int mouse_event_count_ = 0; |
| 748 int scroll_event_count_ = 0; | |
| 749 int touch_event_count_ = 0; | |
| 750 int gesture_event_count_ = 0; | |
| 696 | 751 |
| 697 DISALLOW_COPY_AND_ASSIGN(InputTestDelegate); | 752 DISALLOW_COPY_AND_ASSIGN(InputTestDelegate); |
| 698 }; | 753 }; |
| 699 | 754 |
| 700 } // namespace | 755 } // namespace |
| 701 | 756 |
| 757 TEST_F(SystemModalContainerLayoutManagerTest, BlockAllEvents) { | |
| 758 InputTestDelegate delegate; | |
| 759 delegate.RunTest(this); | |
| 760 } | |
| 761 | |
| 702 // Make sure that events are properly blocked in multi displays environment. | 762 // Make sure that events are properly blocked in multi displays environment. |
| 703 TEST_F(SystemModalContainerLayoutManagerTest, BlockEvent) { | 763 TEST_F(SystemModalContainerLayoutManagerTest, BlockEventsInMultiDisplays) { |
| 704 UpdateDisplay("500x500, 500x500"); | 764 UpdateDisplay("500x500, 500x500"); |
| 705 InputTestDelegate delegate; | 765 InputTestDelegate delegate; |
| 706 std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithDelegate( | 766 delegate.RunTest(this); |
| 707 &delegate, 0, gfx::Rect(0, 0, 100, 100))); | |
| 708 window->Show(); | |
| 709 | |
| 710 ui::test::EventGenerator event_generator(Shell::GetPrimaryRootWindow(), | |
| 711 window.get()); | |
| 712 event_generator.ClickLeftButton(); | |
| 713 EXPECT_EQ(2, delegate.mouse_event_count()); | |
| 714 | |
| 715 views::Widget* widget = views::Widget::CreateWindowWithContextAndBounds( | |
| 716 new TestWindow(true), Shell::GetPrimaryRootWindow(), | |
| 717 gfx::Rect(200, 200, 100, 100)); | |
| 718 widget->Show(); | |
| 719 EXPECT_TRUE(WmShell::Get()->IsSystemModalWindowOpen()); | |
| 720 | |
| 721 // Events should be blocked. | |
| 722 event_generator.ClickLeftButton(); | |
| 723 EXPECT_EQ(2, delegate.mouse_event_count()); | |
| 724 widget->Close(); | |
| 725 | |
| 726 EXPECT_FALSE(WmShell::Get()->IsSystemModalWindowOpen()); | |
| 727 event_generator.ClickLeftButton(); | |
| 728 EXPECT_EQ(4, delegate.mouse_event_count()); | |
| 729 | |
| 730 // We need to delete window here because delegate is on the stack. | |
| 731 window.reset(); | |
| 732 } | 767 } |
| 733 | 768 |
| 734 } // namespace test | 769 } // namespace test |
| 735 } // namespace ash | 770 } // namespace ash |
| OLD | NEW |