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