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/ime/tray_ime_chromeos.h" |
| 6 |
| 7 #include "ash/accessibility_delegate.h" |
| 8 #include "ash/shell.h" |
| 9 #include "ash/system/status_area_widget.h" |
| 10 #include "ash/system/tray/system_tray_notifier.h" |
| 11 #include "ash/test/ash_test_base.h" |
| 12 #include "ash/test/status_area_widget_test_helper.h" |
| 13 #include "ash/test/virtual_keyboard_test_helper.h" |
| 14 #include "base/command_line.h" |
| 15 #include "ui/keyboard/keyboard_switches.h" |
| 16 #include "ui/keyboard/keyboard_util.h" |
| 17 |
| 18 namespace ash { |
| 19 |
| 20 class TrayIMETest : public test::AshTestBase { |
| 21 public: |
| 22 TrayIMETest() {} |
| 23 virtual ~TrayIMETest() {} |
| 24 |
| 25 TrayIME* tray() { return tray_.get(); } |
| 26 |
| 27 views::View* default_view() { return default_view_.get(); } |
| 28 |
| 29 views::View* detailed_view() { return detailed_view_.get(); } |
| 30 |
| 31 // Sets up a TrayIME and its default view. |
| 32 void SetUpForStatusAreaWidget(StatusAreaWidget* status_area_widget); |
| 33 |
| 34 // Mocks enabling the a11y virtual keyboard since the actual a11y manager |
| 35 // is not created in ash tests. |
| 36 void SetAccessibilityKeyboardEnabled(bool enabled); |
| 37 |
| 38 // Resets |tray_| and |default_view_| so that all components of |
| 39 // TrayIME have been cleared. Tests may then call |
| 40 // SetUpForStatusAreaWidget in order to initialize the components. |
| 41 void TearDownViews(); |
| 42 |
| 43 // Sets the current number of active IMEs. |
| 44 void SetIMELength(int length); |
| 45 |
| 46 // Returns the view in the detailed views scroll content at the provided |
| 47 // index. |
| 48 views::View* GetScrollChildView(int index); |
| 49 |
| 50 // test::AshTestBase: |
| 51 virtual void SetUp() override; |
| 52 virtual void TearDown() override; |
| 53 |
| 54 private: |
| 55 scoped_ptr<TrayIME> tray_; |
| 56 scoped_ptr<views::View> default_view_; |
| 57 scoped_ptr<views::View> detailed_view_; |
| 58 }; |
| 59 |
| 60 void TrayIMETest::SetUpForStatusAreaWidget( |
| 61 StatusAreaWidget* status_area_widget) { |
| 62 tray_.reset(new TrayIME(status_area_widget->system_tray())); |
| 63 default_view_.reset(tray_->CreateDefaultView( |
| 64 StatusAreaWidgetTestHelper::GetUserLoginStatus())); |
| 65 detailed_view_.reset(tray_->CreateDetailedView( |
| 66 StatusAreaWidgetTestHelper::GetUserLoginStatus())); |
| 67 } |
| 68 |
| 69 void TrayIMETest::SetAccessibilityKeyboardEnabled(bool enabled) { |
| 70 Shell::GetInstance()->accessibility_delegate()->SetVirtualKeyboardEnabled( |
| 71 enabled); |
| 72 keyboard::SetAccessibilityKeyboardEnabled(enabled); |
| 73 ui::AccessibilityNotificationVisibility notification = |
| 74 enabled ? ui::AccessibilityNotificationVisibility::A11Y_NOTIFICATION_SHOW |
| 75 : ui::AccessibilityNotificationVisibility::A11Y_NOTIFICATION_NONE; |
| 76 Shell::GetInstance()->system_tray_notifier()->NotifyAccessibilityModeChanged( |
| 77 notification); |
| 78 } |
| 79 |
| 80 void TrayIMETest::TearDownViews() { |
| 81 tray_.reset(); |
| 82 default_view_.reset(); |
| 83 detailed_view_.reset(); |
| 84 } |
| 85 |
| 86 void TrayIMETest::SetIMELength(int length) { |
| 87 tray_->ime_list_.clear(); |
| 88 IMEInfo ime; |
| 89 for (int i = 0; i < length; i++) { |
| 90 tray_->ime_list_.push_back(ime); |
| 91 } |
| 92 tray_->Update(); |
| 93 } |
| 94 |
| 95 views::View* TrayIMETest::GetScrollChildView(int index) { |
| 96 TrayDetailsView* details = static_cast<TrayDetailsView*>(detailed_view()); |
| 97 views::View* content = details->scroll_content(); |
| 98 EXPECT_TRUE(content); |
| 99 EXPECT_GT(content->child_count(), index); |
| 100 return content->child_at(index); |
| 101 } |
| 102 |
| 103 void TrayIMETest::SetUp() { |
| 104 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 105 keyboard::switches::kEnableAutoVirtualKeyboard); |
| 106 test::AshTestBase::SetUp(); |
| 107 SetUpForStatusAreaWidget(StatusAreaWidgetTestHelper::GetStatusAreaWidget()); |
| 108 } |
| 109 |
| 110 void TrayIMETest::TearDown() { |
| 111 SetAccessibilityKeyboardEnabled(false); |
| 112 TearDownViews(); |
| 113 test::AshTestBase::TearDown(); |
| 114 } |
| 115 |
| 116 // Tests that if the keyboard is not suppressed the default view is hidden |
| 117 // if less than 2 IMEs are present. |
| 118 TEST_F(TrayIMETest, HiddenWithNoIMEs) { |
| 119 SetIMELength(0); |
| 120 EXPECT_FALSE(default_view()->visible()); |
| 121 SetIMELength(1); |
| 122 EXPECT_FALSE(default_view()->visible()); |
| 123 SetIMELength(2); |
| 124 EXPECT_TRUE(default_view()->visible()); |
| 125 } |
| 126 |
| 127 // Tests that if no IMEs are present the default view is hidden when a11y is |
| 128 // enabled. |
| 129 TEST_F(TrayIMETest, HidesOnA11yEnabled) { |
| 130 SetIMELength(0); |
| 131 test::VirtualKeyboardTestHelper::SuppressKeyboard(); |
| 132 EXPECT_TRUE(default_view()->visible()); |
| 133 // Enable a11y keyboard. |
| 134 SetAccessibilityKeyboardEnabled(true); |
| 135 EXPECT_FALSE(default_view()->visible()); |
| 136 // Disable the a11y keyboard. |
| 137 SetAccessibilityKeyboardEnabled(false); |
| 138 EXPECT_TRUE(default_view()->visible()); |
| 139 } |
| 140 |
| 141 // Tests that clicking on the keyboard toggle causes the virtual keyboard |
| 142 // to toggle between enabled and disabled. |
| 143 TEST_F(TrayIMETest, PerformActionOnDetailedView) { |
| 144 SetIMELength(0); |
| 145 test::VirtualKeyboardTestHelper::SuppressKeyboard(); |
| 146 EXPECT_FALSE(keyboard::IsKeyboardEnabled()); |
| 147 views::View* toggle = GetScrollChildView(0); |
| 148 ui::GestureEvent tap(0, 0, 0, base::TimeDelta(), |
| 149 ui::GestureEventDetails(ui::ET_GESTURE_TAP)); |
| 150 // Enable the keyboard. |
| 151 toggle->OnGestureEvent(&tap); |
| 152 EXPECT_TRUE(keyboard::IsKeyboardEnabled()); |
| 153 EXPECT_TRUE(default_view()->visible()); |
| 154 // With no IMEs the toggle should be the first child. |
| 155 toggle = GetScrollChildView(0); |
| 156 // Clicking again should disable the keyboard. |
| 157 tap = ui::GestureEvent(0, 0, 0, base::TimeDelta(), |
| 158 ui::GestureEventDetails(ui::ET_GESTURE_TAP)); |
| 159 toggle->OnGestureEvent(&tap); |
| 160 EXPECT_FALSE(keyboard::IsKeyboardEnabled()); |
| 161 EXPECT_TRUE(default_view()->visible()); |
| 162 } |
| 163 |
| 164 } // namespace ash |
OLD | NEW |