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

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

Issue 2294723002: Revert of Redirect all mouse input to Alt+Tab window when it's visible, (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 3 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/common/wm/window_cycle_list.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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/wm/window_cycle_controller.h" 5 #include "ash/common/wm/window_cycle_controller.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <memory> 8 #include <memory>
9 9
10 #include "ash/aura/wm_window_aura.h" 10 #include "ash/aura/wm_window_aura.h"
(...skipping 22 matching lines...) Expand all
33 #include "ui/aura/window.h" 33 #include "ui/aura/window.h"
34 #include "ui/aura/window_event_dispatcher.h" 34 #include "ui/aura/window_event_dispatcher.h"
35 #include "ui/events/event_handler.h" 35 #include "ui/events/event_handler.h"
36 #include "ui/events/test/event_generator.h" 36 #include "ui/events/test/event_generator.h"
37 #include "ui/gfx/geometry/rect.h" 37 #include "ui/gfx/geometry/rect.h"
38 38
39 namespace ash { 39 namespace ash {
40 40
41 namespace { 41 namespace {
42 42
43 class EventCounter : public ui::EventHandler { 43 class KeyEventCounter : public ui::EventHandler {
44 public: 44 public:
45 EventCounter() : key_events_(0), mouse_events_(0) {} 45 KeyEventCounter() : key_events_(0) {}
46 ~EventCounter() override {} 46 ~KeyEventCounter() override {}
47 47
48 int GetKeyEventCountAndReset() { 48 size_t GetCountAndReset() {
49 int count = key_events_; 49 size_t count = key_events_;
50 key_events_ = 0; 50 key_events_ = 0;
51 return count; 51 return count;
52 } 52 }
53 53
54 int GetMouseEventCountAndReset() {
55 int count = mouse_events_;
56 mouse_events_ = 0;
57 return count;
58 }
59
60 // ui::EventHandler: 54 // ui::EventHandler:
61 void OnKeyEvent(ui::KeyEvent* event) override { key_events_++; } 55 void OnKeyEvent(ui::KeyEvent* event) override { key_events_++; }
62 void OnMouseEvent(ui::MouseEvent* event) override { mouse_events_++; }
63 56
64 private: 57 private:
65 int key_events_; 58 size_t key_events_;
66 int mouse_events_;
67 59
68 DISALLOW_COPY_AND_ASSIGN(EventCounter); 60 DISALLOW_COPY_AND_ASSIGN(KeyEventCounter);
69 }; 61 };
70 62
71 bool IsWindowMinimized(aura::Window* window) { 63 bool IsWindowMinimized(aura::Window* window) {
72 return WmWindowAura::Get(window)->GetWindowState()->IsMinimized(); 64 return WmWindowAura::Get(window)->GetWindowState()->IsMinimized();
73 } 65 }
74 66
75 } // namespace 67 } // namespace
76 68
77 using aura::test::CreateTestWindowWithId; 69 using aura::test::CreateTestWindowWithId;
78 using aura::test::TestWindowDelegate; 70 using aura::test::TestWindowDelegate;
(...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after
559 // Cycling again should now select panel1. 551 // Cycling again should now select panel1.
560 controller->HandleCycleWindow(WindowCycleController::FORWARD); 552 controller->HandleCycleWindow(WindowCycleController::FORWARD);
561 controller->StopCycling(); 553 controller->StopCycling();
562 EXPECT_TRUE(wm::IsActiveWindow(panel1.get())); 554 EXPECT_TRUE(wm::IsActiveWindow(panel1.get()));
563 } 555 }
564 556
565 // Tests that the tab key events are not sent to the window. 557 // Tests that the tab key events are not sent to the window.
566 TEST_F(WindowCycleControllerTest, TabKeyNotLeaked) { 558 TEST_F(WindowCycleControllerTest, TabKeyNotLeaked) {
567 std::unique_ptr<Window> w0(CreateTestWindowInShellWithId(0)); 559 std::unique_ptr<Window> w0(CreateTestWindowInShellWithId(0));
568 std::unique_ptr<Window> w1(CreateTestWindowInShellWithId(1)); 560 std::unique_ptr<Window> w1(CreateTestWindowInShellWithId(1));
569 EventCounter event_count; 561 KeyEventCounter key_count;
570 w0->AddPreTargetHandler(&event_count); 562 w0->AddPreTargetHandler(&key_count);
571 w1->AddPreTargetHandler(&event_count); 563 w1->AddPreTargetHandler(&key_count);
572 ui::test::EventGenerator& generator = GetEventGenerator(); 564 ui::test::EventGenerator& generator = GetEventGenerator();
573 wm::GetWindowState(w0.get())->Activate(); 565 wm::GetWindowState(w0.get())->Activate();
574 generator.PressKey(ui::VKEY_MENU, ui::EF_NONE); 566 generator.PressKey(ui::VKEY_MENU, ui::EF_NONE);
575 EXPECT_EQ(1, event_count.GetKeyEventCountAndReset()); 567 EXPECT_EQ(1u, key_count.GetCountAndReset());
576 generator.PressKey(ui::VKEY_TAB, ui::EF_ALT_DOWN); 568 generator.PressKey(ui::VKEY_TAB, ui::EF_ALT_DOWN);
577 EXPECT_EQ(0, event_count.GetKeyEventCountAndReset()); 569 EXPECT_EQ(0u, key_count.GetCountAndReset());
578 generator.ReleaseKey(ui::VKEY_TAB, ui::EF_ALT_DOWN); 570 generator.ReleaseKey(ui::VKEY_TAB, ui::EF_ALT_DOWN);
579 EXPECT_EQ(0, event_count.GetKeyEventCountAndReset()); 571 EXPECT_EQ(0u, key_count.GetCountAndReset());
580 generator.ReleaseKey(ui::VKEY_MENU, ui::EF_NONE); 572 generator.ReleaseKey(ui::VKEY_MENU, ui::EF_NONE);
581 EXPECT_TRUE(wm::GetWindowState(w1.get())->IsActive()); 573 EXPECT_TRUE(wm::GetWindowState(w1.get())->IsActive());
582 EXPECT_EQ(0, event_count.GetKeyEventCountAndReset()); 574 EXPECT_EQ(0u, key_count.GetCountAndReset());
583 }
584
585 // While the UI is active, mouse events are captured.
586 TEST_F(WindowCycleControllerTest, MouseEventsCaptured) {
587 // This delegate allows the window to receive mouse events.
588 aura::test::TestWindowDelegate delegate;
589 std::unique_ptr<Window> w0(CreateTestWindowInShellWithDelegate(
590 &delegate, 0, gfx::Rect(0, 0, 100, 100)));
591 std::unique_ptr<Window> w1(CreateTestWindowInShellWithId(1));
592 EventCounter event_count;
593 w0->AddPreTargetHandler(&event_count);
594 w1->SetTargetHandler(&event_count);
595 ui::test::EventGenerator& generator = GetEventGenerator();
596 wm::ActivateWindow(w0.get());
597
598 // Events get through.
599 generator.MoveMouseToCenterOf(w0.get());
600 generator.ClickLeftButton();
601 EXPECT_LT(0, event_count.GetMouseEventCountAndReset());
602
603 // Start cycling.
604 WindowCycleController* controller = WmShell::Get()->window_cycle_controller();
605 controller->HandleCycleWindow(WindowCycleController::FORWARD);
606
607 // Events don't get through.
608 generator.ClickLeftButton();
609 EXPECT_EQ(0, event_count.GetMouseEventCountAndReset());
610
611 // Stop cycling: once again, events get through.
612 controller->StopCycling();
613 generator.ClickLeftButton();
614 EXPECT_LT(0, event_count.GetMouseEventCountAndReset());
615 }
616
617 // If mouse capture is lost, the UI closes.
618 TEST_F(WindowCycleControllerTest, MouseCaptureLost) {
619 // This delegate allows the window to receive mouse events.
620 aura::test::TestWindowDelegate delegate;
621 std::unique_ptr<Window> w0(CreateTestWindowInShellWithDelegate(
622 &delegate, 0, gfx::Rect(0, 0, 100, 100)));
623 std::unique_ptr<Window> w1(CreateTestWindowInShellWithId(1));
624
625 // Start cycling.
626 WindowCycleController* controller = WmShell::Get()->window_cycle_controller();
627 controller->HandleCycleWindow(WindowCycleController::FORWARD);
628
629 // Some other widget grabs capture and this causes Alt+Tab to cease.
630 std::unique_ptr<views::Widget> widget = CreateTestWidget(
631 nullptr, kShellWindowId_DefaultContainer, gfx::Rect(1, 2, 3, 4));
632 widget.get()->SetCapture(nullptr);
633 EXPECT_FALSE(controller->IsCycling());
634 } 575 }
635 576
636 // Tests that we can cycle past fullscreen windows: https://crbug.com/622396. 577 // Tests that we can cycle past fullscreen windows: https://crbug.com/622396.
637 // Fullscreen windows are special in that they are allowed to handle alt+tab 578 // Fullscreen windows are special in that they are allowed to handle alt+tab
638 // keypresses, which means the window cycle event filter should not handle 579 // keypresses, which means the window cycle event filter should not handle
639 // the tab press else it prevents cycling past that window. 580 // the tab press else it prevents cycling past that window.
640 TEST_F(WindowCycleControllerTest, TabPastFullscreenWindow) { 581 TEST_F(WindowCycleControllerTest, TabPastFullscreenWindow) {
641 std::unique_ptr<Window> w0(CreateTestWindowInShellWithId(0)); 582 std::unique_ptr<Window> w0(CreateTestWindowInShellWithId(0));
642 std::unique_ptr<Window> w1(CreateTestWindowInShellWithId(1)); 583 std::unique_ptr<Window> w1(CreateTestWindowInShellWithId(1));
643 wm::WMEvent maximize_event(wm::WM_EVENT_FULLSCREEN); 584 wm::WMEvent maximize_event(wm::WM_EVENT_FULLSCREEN);
(...skipping 12 matching lines...) Expand all
656 generator.PressKey(ui::VKEY_MENU, ui::EF_NONE); 597 generator.PressKey(ui::VKEY_MENU, ui::EF_NONE);
657 598
658 generator.PressKey(ui::VKEY_TAB, ui::EF_ALT_DOWN); 599 generator.PressKey(ui::VKEY_TAB, ui::EF_ALT_DOWN);
659 generator.ReleaseKey(ui::VKEY_TAB, ui::EF_ALT_DOWN); 600 generator.ReleaseKey(ui::VKEY_TAB, ui::EF_ALT_DOWN);
660 601
661 // Because w0 and w1 are full-screen, the event should be passed to the 602 // Because w0 and w1 are full-screen, the event should be passed to the
662 // browser window to handle it (which if the browser doesn't handle it will 603 // browser window to handle it (which if the browser doesn't handle it will
663 // pass on the alt+tab to continue cycling). To make this test work with or 604 // pass on the alt+tab to continue cycling). To make this test work with or
664 // without the new alt+tab selector we check for the event on either 605 // without the new alt+tab selector we check for the event on either
665 // fullscreen window. 606 // fullscreen window.
666 EventCounter event_count; 607 KeyEventCounter key_count;
667 w0->AddPreTargetHandler(&event_count); 608 w0->AddPreTargetHandler(&key_count);
668 w1->AddPreTargetHandler(&event_count); 609 w1->AddPreTargetHandler(&key_count);
669 generator.PressKey(ui::VKEY_TAB, ui::EF_ALT_DOWN); 610 generator.PressKey(ui::VKEY_TAB, ui::EF_ALT_DOWN);
670 EXPECT_EQ(1, event_count.GetKeyEventCountAndReset()); 611 EXPECT_EQ(1u, key_count.GetCountAndReset());
671 } 612 }
672 613
673 } // namespace ash 614 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/wm/window_cycle_list.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698