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

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

Issue 1083093006: Prevent delivery of tab release key events while alt tabbing. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Handle all key events during alt tab window cycling. 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/window_cycle_controller.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/wm/window_cycle_controller.h" 5 #include "ash/wm/window_cycle_controller.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <memory> 8 #include <memory>
9 9
10 #include "ash/session/session_state_delegate.h" 10 #include "ash/session/session_state_delegate.h"
11 #include "ash/shelf/shelf.h" 11 #include "ash/shelf/shelf.h"
12 #include "ash/shelf/shelf_widget.h" 12 #include "ash/shelf/shelf_widget.h"
13 #include "ash/shell.h" 13 #include "ash/shell.h"
14 #include "ash/shell_window_ids.h" 14 #include "ash/shell_window_ids.h"
15 #include "ash/test/ash_test_base.h" 15 #include "ash/test/ash_test_base.h"
16 #include "ash/test/shelf_test_api.h" 16 #include "ash/test/shelf_test_api.h"
17 #include "ash/test/shelf_view_test_api.h" 17 #include "ash/test/shelf_view_test_api.h"
18 #include "ash/test/test_shelf_delegate.h" 18 #include "ash/test/test_shelf_delegate.h"
19 #include "ash/test/test_shell_delegate.h" 19 #include "ash/test/test_shell_delegate.h"
20 #include "ash/wm/common/window_state.h" 20 #include "ash/wm/common/window_state.h"
21 #include "ash/wm/window_cycle_list.h" 21 #include "ash/wm/window_cycle_list.h"
22 #include "ash/wm/window_state_aura.h" 22 #include "ash/wm/window_state_aura.h"
23 #include "ash/wm/window_util.h" 23 #include "ash/wm/window_util.h"
24 #include "ui/aura/client/aura_constants.h" 24 #include "ui/aura/client/aura_constants.h"
25 #include "ui/aura/client/screen_position_client.h" 25 #include "ui/aura/client/screen_position_client.h"
26 #include "ui/aura/env.h" 26 #include "ui/aura/env.h"
27 #include "ui/aura/test/test_windows.h" 27 #include "ui/aura/test/test_windows.h"
28 #include "ui/aura/window.h" 28 #include "ui/aura/window.h"
29 #include "ui/aura/window_event_dispatcher.h" 29 #include "ui/aura/window_event_dispatcher.h"
30 #include "ui/events/event_handler.h"
31 #include "ui/events/test/event_generator.h"
30 #include "ui/gfx/geometry/rect.h" 32 #include "ui/gfx/geometry/rect.h"
31 33
32 namespace ash { 34 namespace ash {
33 35
36 namespace {
37
38 class KeyEventCounter : public ui::EventHandler {
39 public:
40 KeyEventCounter() : key_events_(0) {}
41 ~KeyEventCounter() override {}
42
43 size_t GetCountAndReset() {
44 size_t count = key_events_;
45 key_events_ = 0;
46 return count;
47 }
48
49 // ui::EventHandler:
50 void OnKeyEvent(ui::KeyEvent* event) override { key_events_++; }
51
52 private:
53 size_t key_events_;
54
55 DISALLOW_COPY_AND_ASSIGN(KeyEventCounter);
56 };
57
58 } // namespace
59
34 using aura::test::CreateTestWindowWithId; 60 using aura::test::CreateTestWindowWithId;
35 using aura::test::TestWindowDelegate; 61 using aura::test::TestWindowDelegate;
36 using aura::Window; 62 using aura::Window;
37 63
38 class WindowCycleControllerTest : public test::AshTestBase { 64 class WindowCycleControllerTest : public test::AshTestBase {
39 public: 65 public:
40 WindowCycleControllerTest() {} 66 WindowCycleControllerTest() {}
41 ~WindowCycleControllerTest() override {} 67 ~WindowCycleControllerTest() override {}
42 68
43 void SetUp() override { 69 void SetUp() override {
(...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after
583 609
584 // Panel 1 is the next item as the MRU panel, removing it should make panel 2 610 // Panel 1 is the next item as the MRU panel, removing it should make panel 2
585 // the next window to be selected. 611 // the next window to be selected.
586 panel0.reset(); 612 panel0.reset();
587 // Cycling again should now select panel1. 613 // Cycling again should now select panel1.
588 controller->HandleCycleWindow(WindowCycleController::FORWARD); 614 controller->HandleCycleWindow(WindowCycleController::FORWARD);
589 controller->StopCycling(); 615 controller->StopCycling();
590 EXPECT_TRUE(wm::IsActiveWindow(panel1.get())); 616 EXPECT_TRUE(wm::IsActiveWindow(panel1.get()));
591 } 617 }
592 618
619 // Tests that the tab key events are not sent to the window.
620 TEST_F(WindowCycleControllerTest, TabKeyNotLeaked) {
621 std::unique_ptr<Window> w0(CreateTestWindowInShellWithId(0));
622 std::unique_ptr<Window> w1(CreateTestWindowInShellWithId(1));
623 KeyEventCounter key_count;
624 w0->AddPreTargetHandler(&key_count);
625 w1->AddPreTargetHandler(&key_count);
626 ui::test::EventGenerator& generator = GetEventGenerator();
627 wm::GetWindowState(w0.get())->Activate();
628 generator.PressKey(ui::VKEY_MENU, ui::EF_NONE);
629 EXPECT_EQ(1u, key_count.GetCountAndReset());
630 generator.PressKey(ui::VKEY_TAB, ui::EF_ALT_DOWN);
631 EXPECT_EQ(0u, key_count.GetCountAndReset());
632 generator.ReleaseKey(ui::VKEY_TAB, ui::EF_ALT_DOWN);
633 EXPECT_EQ(0u, key_count.GetCountAndReset());
634 generator.ReleaseKey(ui::VKEY_MENU, ui::EF_NONE);
635 EXPECT_TRUE(wm::GetWindowState(w1.get())->IsActive());
636 EXPECT_EQ(0u, key_count.GetCountAndReset());
637 }
638
593 } // namespace ash 639 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/window_cycle_controller.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698