| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #include "ash/system/chromeos/virtual_keyboard/tray_keyboard_lock.h" | |
| 6 | |
| 7 #include "ash/accessibility_delegate.h" | |
| 8 #include "ash/shell.h" | |
| 9 #include "ash/system/status_area_widget.h" | |
| 10 #include "ash/test/ash_test_base.h" | |
| 11 #include "ash/test/status_area_widget_test_helper.h" | |
| 12 #include "ash/test/virtual_keyboard_test_helper.h" | |
| 13 #include "base/command_line.h" | |
| 14 #include "ui/keyboard/keyboard_switches.h" | |
| 15 #include "ui/keyboard/keyboard_util.h" | |
| 16 | |
| 17 namespace ash { | |
| 18 | |
| 19 class TrayKeyboardLockTest : public test::AshTestBase { | |
| 20 public: | |
| 21 TrayKeyboardLockTest() {} | |
| 22 virtual ~TrayKeyboardLockTest() {} | |
| 23 | |
| 24 TrayKeyboardLock* tray() { return tray_.get(); } | |
| 25 | |
| 26 views::View* default_view() { return default_view_.get(); } | |
| 27 | |
| 28 // Sets up a TrayKeyboardLock and its default view. | |
| 29 void SetUpForStatusAreaWidget(StatusAreaWidget* status_area_widget); | |
| 30 | |
| 31 // Mocks enabling the a11y virtual keyboard since the actual a11y manager | |
| 32 // is not created in ash tests. | |
| 33 void SetAccessibilityKeyboardEnabled(bool enabled); | |
| 34 | |
| 35 // Resets |tray_| and |default_view_| so that all components of | |
| 36 // TrayKeyboardLock have been cleared. Tests may then call | |
| 37 // SetUpForStatusAreaWidget in order to initialize the components. | |
| 38 void TearDownViews(); | |
| 39 | |
| 40 // test::AshTestBase: | |
| 41 virtual void SetUp() override; | |
| 42 virtual void TearDown() override; | |
| 43 | |
| 44 private: | |
| 45 scoped_ptr<TrayKeyboardLock> tray_; | |
| 46 scoped_ptr<views::View> default_view_; | |
| 47 }; | |
| 48 | |
| 49 void TrayKeyboardLockTest::SetUpForStatusAreaWidget( | |
| 50 StatusAreaWidget* status_area_widget) { | |
| 51 tray_.reset(new TrayKeyboardLock(status_area_widget->system_tray())); | |
| 52 default_view_.reset(tray_->CreateDefaultView( | |
| 53 StatusAreaWidgetTestHelper::GetUserLoginStatus())); | |
| 54 } | |
| 55 | |
| 56 void TrayKeyboardLockTest::SetAccessibilityKeyboardEnabled(bool enabled) { | |
| 57 Shell::GetInstance()->accessibility_delegate()->SetVirtualKeyboardEnabled( | |
| 58 enabled); | |
| 59 keyboard::SetAccessibilityKeyboardEnabled(enabled); | |
| 60 ui::AccessibilityNotificationVisibility notification = | |
| 61 enabled ? ui::AccessibilityNotificationVisibility::A11Y_NOTIFICATION_SHOW | |
| 62 : ui::AccessibilityNotificationVisibility::A11Y_NOTIFICATION_NONE; | |
| 63 Shell::GetInstance()->system_tray_notifier()->NotifyAccessibilityModeChanged( | |
| 64 notification); | |
| 65 } | |
| 66 | |
| 67 void TrayKeyboardLockTest::TearDownViews() { | |
| 68 default_view_.reset(); | |
| 69 tray_.reset(); | |
| 70 } | |
| 71 | |
| 72 void TrayKeyboardLockTest::SetUp() { | |
| 73 base::CommandLine::ForCurrentProcess()->AppendSwitch( | |
| 74 keyboard::switches::kEnableAutoVirtualKeyboard); | |
| 75 test::AshTestBase::SetUp(); | |
| 76 SetUpForStatusAreaWidget(StatusAreaWidgetTestHelper::GetStatusAreaWidget()); | |
| 77 } | |
| 78 | |
| 79 void TrayKeyboardLockTest::TearDown() { | |
| 80 SetAccessibilityKeyboardEnabled(false); | |
| 81 TearDownViews(); | |
| 82 test::AshTestBase::TearDown(); | |
| 83 } | |
| 84 | |
| 85 // Tests that when the tray is initially created that the default view is | |
| 86 // hidden. | |
| 87 TEST_F(TrayKeyboardLockTest, HiddenOnCreation) { | |
| 88 EXPECT_FALSE(default_view()->visible()); | |
| 89 } | |
| 90 | |
| 91 // Tests that the default view and tray are hidden when a11y is enabled. | |
| 92 TEST_F(TrayKeyboardLockTest, HidesOnA11yEnabled) { | |
| 93 test::VirtualKeyboardTestHelper::SuppressKeyboard(); | |
| 94 EXPECT_TRUE(default_view()->visible()); | |
| 95 // Enable a11y keyboard. | |
| 96 SetAccessibilityKeyboardEnabled(true); | |
| 97 EXPECT_FALSE(default_view()->visible()); | |
| 98 // Disable the a11y keyboard. | |
| 99 SetAccessibilityKeyboardEnabled(false); | |
| 100 EXPECT_TRUE(default_view()->visible()); | |
| 101 } | |
| 102 | |
| 103 TEST_F(TrayKeyboardLockTest, PerformActionOnDefaultView) { | |
| 104 test::VirtualKeyboardTestHelper::SuppressKeyboard(); | |
| 105 EXPECT_FALSE(keyboard::IsKeyboardEnabled()); | |
| 106 EXPECT_TRUE(default_view()->visible()); | |
| 107 | |
| 108 ui::GestureEvent tap( | |
| 109 0, 0, 0, base::TimeDelta(), ui::GestureEventDetails(ui::ET_GESTURE_TAP)); | |
| 110 default_view()->OnGestureEvent(&tap); | |
| 111 EXPECT_TRUE(keyboard::IsKeyboardEnabled()); | |
| 112 EXPECT_TRUE(default_view()->visible()); | |
| 113 | |
| 114 tap = ui::GestureEvent( | |
| 115 0, 0, 0, base::TimeDelta(), ui::GestureEventDetails(ui::ET_GESTURE_TAP)); | |
| 116 default_view()->OnGestureEvent(&tap); | |
| 117 EXPECT_FALSE(keyboard::IsKeyboardEnabled()); | |
| 118 EXPECT_TRUE(default_view()->visible()); | |
| 119 } | |
| 120 | |
| 121 } // namespace ash | |
| OLD | NEW |