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/common/system/ime/tray_ime_chromeos.h" | 5 #include "ash/common/system/ime/tray_ime_chromeos.h" |
6 | 6 |
7 #include "ash/common/accessibility_delegate.h" | 7 #include "ash/common/accessibility_delegate.h" |
8 #include "ash/common/accessibility_types.h" | 8 #include "ash/common/accessibility_types.h" |
9 #include "ash/common/system/chromeos/ime_menu/ime_list_view.h" | 9 #include "ash/common/system/chromeos/ime_menu/ime_list_view.h" |
10 #include "ash/common/system/tray/system_tray_notifier.h" | 10 #include "ash/common/system/tray/system_tray_notifier.h" |
11 #include "ash/common/wm_shell.h" | 11 #include "ash/common/wm_shell.h" |
12 #include "ash/test/ash_test_base.h" | 12 #include "ash/test/ash_test_base.h" |
| 13 #include "base/strings/utf_string_conversions.h" |
13 #include "ui/events/devices/device_data_manager.h" | 14 #include "ui/events/devices/device_data_manager.h" |
14 #include "ui/keyboard/keyboard_util.h" | 15 #include "ui/keyboard/keyboard_util.h" |
15 | 16 |
16 namespace ash { | 17 namespace ash { |
17 | 18 |
18 class TrayIMETest : public test::AshTestBase { | 19 class TrayIMETest : public test::AshTestBase { |
19 public: | 20 public: |
20 TrayIMETest() {} | 21 TrayIMETest() {} |
21 ~TrayIMETest() override {} | 22 ~TrayIMETest() override {} |
22 | 23 |
23 views::View* default_view() const { return default_view_.get(); } | 24 views::View* default_view() const { return default_view_.get(); } |
24 | 25 |
25 views::View* detailed_view() const { return detailed_view_.get(); } | 26 views::View* detailed_view() const { return detailed_view_.get(); } |
26 | 27 |
27 // Mocks enabling the a11y virtual keyboard since the actual a11y manager | 28 // Mocks enabling the a11y virtual keyboard since the actual a11y manager |
28 // is not created in ash tests. | 29 // is not created in ash tests. |
29 void SetAccessibilityKeyboardEnabled(bool enabled); | 30 void SetAccessibilityKeyboardEnabled(bool enabled); |
30 | 31 |
31 // Sets the current number of active IMEs. | 32 // Sets the current number of active IMEs. |
32 void SetIMELength(int length); | 33 void SetIMELength(int length); |
33 | 34 |
34 // Returns the view responsible for toggling virtual keyboard. | 35 // Returns the view responsible for toggling virtual keyboard. |
35 views::View* GetToggleView() const; | 36 views::View* GetToggleView() const; |
36 | 37 |
| 38 // Sets the managed IMEs tooltip message (and thus also if IMEs are managed = |
| 39 // non-empty or not = empty) |
| 40 void SetManagedMessage(base::string16 managed_message); |
| 41 |
37 void SuppressKeyboard(); | 42 void SuppressKeyboard(); |
38 void RestoreKeyboard(); | 43 void RestoreKeyboard(); |
39 | 44 |
40 // test::AshTestBase: | 45 // test::AshTestBase: |
41 void SetUp() override; | 46 void SetUp() override; |
42 void TearDown() override; | 47 void TearDown() override; |
43 | 48 |
44 private: | 49 private: |
45 std::unique_ptr<TrayIME> tray_; | 50 std::unique_ptr<TrayIME> tray_; |
46 std::unique_ptr<views::View> default_view_; | 51 std::unique_ptr<views::View> default_view_; |
(...skipping 22 matching lines...) Expand all Loading... |
69 tray_->ime_list_.push_back(ime); | 74 tray_->ime_list_.push_back(ime); |
70 } | 75 } |
71 tray_->Update(); | 76 tray_->Update(); |
72 } | 77 } |
73 | 78 |
74 views::View* TrayIMETest::GetToggleView() const { | 79 views::View* TrayIMETest::GetToggleView() const { |
75 ImeListViewTestApi test_api(static_cast<ImeListView*>(detailed_view())); | 80 ImeListViewTestApi test_api(static_cast<ImeListView*>(detailed_view())); |
76 return test_api.GetToggleView(); | 81 return test_api.GetToggleView(); |
77 } | 82 } |
78 | 83 |
| 84 void TrayIMETest::SetManagedMessage(base::string16 managed_message) { |
| 85 tray_->ime_managed_message_ = managed_message; |
| 86 tray_->Update(); |
| 87 } |
| 88 |
79 void TrayIMETest::SuppressKeyboard() { | 89 void TrayIMETest::SuppressKeyboard() { |
80 DCHECK(!keyboard_suppressed_); | 90 DCHECK(!keyboard_suppressed_); |
81 keyboard_suppressed_ = true; | 91 keyboard_suppressed_ = true; |
82 | 92 |
83 ui::DeviceDataManager* device_manager = ui::DeviceDataManager::GetInstance(); | 93 ui::DeviceDataManager* device_manager = ui::DeviceDataManager::GetInstance(); |
84 touchscreen_devices_to_restore_ = device_manager->GetTouchscreenDevices(); | 94 touchscreen_devices_to_restore_ = device_manager->GetTouchscreenDevices(); |
85 keyboard_devices_to_restore_ = device_manager->GetKeyboardDevices(); | 95 keyboard_devices_to_restore_ = device_manager->GetKeyboardDevices(); |
86 | 96 |
87 ui::DeviceHotplugEventObserver* manager = | 97 ui::DeviceHotplugEventObserver* manager = |
88 ui::DeviceDataManager::GetInstance(); | 98 ui::DeviceDataManager::GetInstance(); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 // if less than 2 IMEs are present. | 137 // if less than 2 IMEs are present. |
128 TEST_F(TrayIMETest, HiddenWithNoIMEs) { | 138 TEST_F(TrayIMETest, HiddenWithNoIMEs) { |
129 SetIMELength(0); | 139 SetIMELength(0); |
130 EXPECT_FALSE(default_view()->visible()); | 140 EXPECT_FALSE(default_view()->visible()); |
131 SetIMELength(1); | 141 SetIMELength(1); |
132 EXPECT_FALSE(default_view()->visible()); | 142 EXPECT_FALSE(default_view()->visible()); |
133 SetIMELength(2); | 143 SetIMELength(2); |
134 EXPECT_TRUE(default_view()->visible()); | 144 EXPECT_TRUE(default_view()->visible()); |
135 } | 145 } |
136 | 146 |
| 147 // Tests that if IMEs are managed, the default view is displayed even for a |
| 148 // single IME. |
| 149 TEST_F(TrayIMETest, ShownWithSingleIMEWhenManaged) { |
| 150 SetManagedMessage(base::ASCIIToUTF16("managed")); |
| 151 SetIMELength(0); |
| 152 EXPECT_FALSE(default_view()->visible()); |
| 153 SetIMELength(1); |
| 154 EXPECT_TRUE(default_view()->visible()); |
| 155 SetIMELength(2); |
| 156 EXPECT_TRUE(default_view()->visible()); |
| 157 } |
| 158 |
137 // Tests that if no IMEs are present the default view is hidden when a11y is | 159 // Tests that if no IMEs are present the default view is hidden when a11y is |
138 // enabled. | 160 // enabled. |
139 TEST_F(TrayIMETest, HidesOnA11yEnabled) { | 161 TEST_F(TrayIMETest, HidesOnA11yEnabled) { |
140 SetIMELength(0); | 162 SetIMELength(0); |
141 SuppressKeyboard(); | 163 SuppressKeyboard(); |
142 EXPECT_TRUE(default_view()->visible()); | 164 EXPECT_TRUE(default_view()->visible()); |
143 // Enable a11y keyboard. | 165 // Enable a11y keyboard. |
144 SetAccessibilityKeyboardEnabled(true); | 166 SetAccessibilityKeyboardEnabled(true); |
145 EXPECT_FALSE(default_view()->visible()); | 167 EXPECT_FALSE(default_view()->visible()); |
146 // Disable the a11y keyboard. | 168 // Disable the a11y keyboard. |
(...skipping 18 matching lines...) Expand all Loading... |
165 // Clicking again should disable the keyboard. | 187 // Clicking again should disable the keyboard. |
166 toggle = GetToggleView(); | 188 toggle = GetToggleView(); |
167 tap = ui::GestureEvent(0, 0, 0, base::TimeTicks(), | 189 tap = ui::GestureEvent(0, 0, 0, base::TimeTicks(), |
168 ui::GestureEventDetails(ui::ET_GESTURE_TAP)); | 190 ui::GestureEventDetails(ui::ET_GESTURE_TAP)); |
169 toggle->OnGestureEvent(&tap); | 191 toggle->OnGestureEvent(&tap); |
170 EXPECT_FALSE(keyboard::IsKeyboardEnabled()); | 192 EXPECT_FALSE(keyboard::IsKeyboardEnabled()); |
171 EXPECT_TRUE(default_view()->visible()); | 193 EXPECT_TRUE(default_view()->visible()); |
172 } | 194 } |
173 | 195 |
174 } // namespace ash | 196 } // namespace ash |
OLD | NEW |