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

Side by Side Diff: ash/wm/system_modal_container_layout_manager_unittest.cc

Issue 2071423003: Filter all events in SystemModalContainerEventHandler (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: addressed comments 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 | « ash/wm/system_modal_container_event_filter.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 Reset();
702
703 views::Widget* widget = views::Widget::CreateWindowWithContextAndBounds(
704 new TestWindow(true), Shell::GetPrimaryRootWindow(),
705 gfx::Rect(200, 200, 100, 100));
706 widget->Show();
707 EXPECT_TRUE(WmShell::Get()->IsSystemModalWindowOpen());
708
709 // Events should be blocked.
710 GenerateEvents(window.get());
711
712 EXPECT_EQ(0, mouse_event_count_);
713 EXPECT_EQ(0, scroll_event_count_);
714 EXPECT_EQ(0, touch_event_count_);
715 EXPECT_EQ(0, gesture_event_count_);
716 Reset();
717
718 widget->Close();
719 EXPECT_FALSE(WmShell::Get()->IsSystemModalWindowOpen());
720
721 GenerateEvents(window.get());
722
723 EXPECT_EQ(2, mouse_event_count_);
724 EXPECT_EQ(3, scroll_event_count_);
725 EXPECT_EQ(4, touch_event_count_);
726 EXPECT_EQ(10, gesture_event_count_);
727 }
728
729 private:
689 // ui::EventHandler: 730 // ui::EventHandler:
690 void OnMouseEvent(ui::MouseEvent* event) override { mouse_event_count_++; } 731 void OnMouseEvent(ui::MouseEvent* event) override { mouse_event_count_++; }
732 void OnScrollEvent(ui::ScrollEvent* event) override { scroll_event_count_++; }
733 void OnTouchEvent(ui::TouchEvent* event) override { touch_event_count_++; }
734 void OnGestureEvent(ui::GestureEvent* event) override {
735 gesture_event_count_++;
736 }
691 737
692 int mouse_event_count() const { return mouse_event_count_; } 738 void GenerateEvents(aura::Window* window) {
739 ui::test::EventGenerator event_generator(Shell::GetPrimaryRootWindow(),
740 window);
741 event_generator.ClickLeftButton();
742 event_generator.ScrollSequence(window->bounds().CenterPoint(),
743 base::TimeDelta(), 0, 10, 1, 2);
744 event_generator.PressTouch();
745 event_generator.ReleaseTouch();
746 event_generator.GestureTapAt(window->bounds().CenterPoint());
747 }
693 748
694 private: 749 void Reset() {
750 mouse_event_count_ = 0;
751 scroll_event_count_ = 0;
752 touch_event_count_ = 0;
753 gesture_event_count_ = 0;
754 }
755
695 int mouse_event_count_ = 0; 756 int mouse_event_count_ = 0;
757 int scroll_event_count_ = 0;
758 int touch_event_count_ = 0;
759 int gesture_event_count_ = 0;
696 760
697 DISALLOW_COPY_AND_ASSIGN(InputTestDelegate); 761 DISALLOW_COPY_AND_ASSIGN(InputTestDelegate);
698 }; 762 };
699 763
700 } // namespace 764 } // namespace
701 765
766 TEST_F(SystemModalContainerLayoutManagerTest, BlockAllEvents) {
767 InputTestDelegate delegate;
768 delegate.RunTest(this);
769 }
770
702 // Make sure that events are properly blocked in multi displays environment. 771 // Make sure that events are properly blocked in multi displays environment.
703 TEST_F(SystemModalContainerLayoutManagerTest, BlockEvent) { 772 TEST_F(SystemModalContainerLayoutManagerTest, BlockEventsInMultiDisplays) {
704 UpdateDisplay("500x500, 500x500"); 773 UpdateDisplay("500x500, 500x500");
705 InputTestDelegate delegate; 774 InputTestDelegate delegate;
706 std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithDelegate( 775 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 } 776 }
733 777
734 } // namespace test 778 } // namespace test
735 } // namespace ash 779 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/system_modal_container_event_filter.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698