Updating XTBs based on .GRDs from branch master
[chromium-blink-merge.git] / ash / accelerators / magnifier_key_scroller_unittest.cc
blobd24e9c343fb9cba3fecaf20f6c3955d2ae57eaa0
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
3 // found in the LICENSE file.
5 #include "ash/accelerators/magnifier_key_scroller.h"
7 #include "ash/magnifier/magnification_controller.h"
8 #include "ash/shell.h"
9 #include "ash/test/ash_test_base.h"
10 #include "ash/wm/window_util.h"
11 #include "ui/aura/test/test_window_delegate.h"
12 #include "ui/events/event.h"
13 #include "ui/events/test/event_generator.h"
15 namespace ash {
16 namespace {
18 class KeyEventDelegate : public aura::test::TestWindowDelegate {
19 public:
20 KeyEventDelegate() {}
21 ~KeyEventDelegate() override {}
23 // ui::EventHandler overrides:
24 void OnKeyEvent(ui::KeyEvent* event) override {
25 key_event.reset(new ui::KeyEvent(
26 event->type(), event->key_code(), event->flags()));
29 const ui::KeyEvent* event() const { return key_event.get(); }
30 void reset() { key_event.reset(); }
32 private:
33 scoped_ptr<ui::KeyEvent> key_event;
35 DISALLOW_COPY_AND_ASSIGN(KeyEventDelegate);
38 } // namespace
40 typedef ash::test::AshTestBase MagnifierKeyScrollerTest;
42 TEST_F(MagnifierKeyScrollerTest, Basic) {
43 KeyEventDelegate delegate;
44 scoped_ptr<aura::Window> window(CreateTestWindowInShellWithDelegate(
45 &delegate,
47 gfx::Rect(10, 10, 100, 100)));
48 wm::ActivateWindow(window.get());
50 MagnifierKeyScroller::ScopedEnablerForTest scoped;
51 Shell* shell = Shell::GetInstance();
52 MagnificationController* controller = shell->magnification_controller();
53 controller->SetEnabled(true);
55 EXPECT_EQ("200,150", controller->GetWindowPosition().ToString());
56 ui::test::EventGenerator& generator = GetEventGenerator();
58 // Click and Release generates the press event upon release.
59 generator.PressKey(ui::VKEY_DOWN, ui::EF_SHIFT_DOWN);
60 EXPECT_EQ("200,150", controller->GetWindowPosition().ToString());
61 EXPECT_FALSE(delegate.event());
63 generator.ReleaseKey(ui::VKEY_DOWN, 0);
64 EXPECT_EQ("200,150", controller->GetWindowPosition().ToString());
65 RunAllPendingInMessageLoop();
66 ASSERT_TRUE(delegate.event());
67 EXPECT_EQ(ui::ET_KEY_PRESSED, delegate.event()->type());
68 delegate.reset();
70 // Click and hold scrolls the magnifier screen.
71 generator.PressKey(ui::VKEY_DOWN, ui::EF_SHIFT_DOWN);
72 EXPECT_EQ("200,150", controller->GetWindowPosition().ToString());
73 EXPECT_FALSE(delegate.event());
75 generator.PressKey(ui::VKEY_DOWN, ui::EF_SHIFT_DOWN);
76 EXPECT_EQ("200,300", controller->GetWindowPosition().ToString());
77 EXPECT_FALSE(delegate.event());
79 generator.ReleaseKey(ui::VKEY_DOWN, 0);
80 EXPECT_EQ("200,300", controller->GetWindowPosition().ToString());
81 EXPECT_FALSE(delegate.event());
83 // Events are passed normally when the magnifier is off.
84 controller->SetEnabled(false);
86 generator.PressKey(ui::VKEY_DOWN, ui::EF_SHIFT_DOWN);
87 ASSERT_TRUE(delegate.event());
88 EXPECT_EQ(ui::ET_KEY_PRESSED, delegate.event()->type());
89 delegate.reset();
91 generator.ReleaseKey(ui::VKEY_DOWN, 0);
92 ASSERT_TRUE(delegate.event());
93 EXPECT_EQ(ui::ET_KEY_RELEASED, delegate.event()->type());
94 delegate.reset();
96 generator.PressKey(ui::VKEY_DOWN, ui::EF_SHIFT_DOWN);
97 ASSERT_TRUE(delegate.event());
98 EXPECT_EQ(ui::ET_KEY_PRESSED, delegate.event()->type());
99 delegate.reset();
101 generator.PressKey(ui::VKEY_DOWN, ui::EF_SHIFT_DOWN);
102 ASSERT_TRUE(delegate.event());
103 EXPECT_EQ(ui::ET_KEY_PRESSED, delegate.event()->type());
104 delegate.reset();
106 generator.ReleaseKey(ui::VKEY_DOWN, 0);
107 ASSERT_TRUE(delegate.event());
108 EXPECT_EQ(ui::ET_KEY_RELEASED, delegate.event()->type());
109 delegate.reset();
112 } // namespace ash