OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/ime_menu/ime_menu_tray.h" | 5 #include "ash/system/ime_menu/ime_menu_tray.h" |
6 | 6 |
7 #include "ash/accelerators/accelerator_controller.h" | 7 #include "ash/accelerators/accelerator_controller.h" |
8 #include "ash/accessibility_delegate.h" | 8 #include "ash/accessibility_delegate.h" |
9 #include "ash/shell.h" | 9 #include "ash/shell.h" |
| 10 #include "ash/system/ime/ime_util.h" |
10 #include "ash/system/ime_menu/ime_list_view.h" | 11 #include "ash/system/ime_menu/ime_list_view.h" |
11 #include "ash/system/status_area_widget.h" | 12 #include "ash/system/status_area_widget.h" |
12 #include "ash/system/tray/ime_info.h" | 13 #include "ash/system/tray/ime_info.h" |
13 #include "ash/system/tray/system_tray_notifier.h" | 14 #include "ash/system/tray/system_tray_notifier.h" |
14 #include "ash/test/ash_test_base.h" | 15 #include "ash/test/ash_test_base.h" |
15 #include "ash/test/status_area_widget_test_helper.h" | 16 #include "ash/test/status_area_widget_test_helper.h" |
16 #include "ash/test/test_system_tray_delegate.h" | 17 #include "ash/test/test_system_tray_delegate.h" |
17 #include "base/run_loop.h" | 18 #include "base/run_loop.h" |
18 #include "base/strings/utf_string_conversions.h" | 19 #include "base/strings/utf_string_conversions.h" |
19 #include "ui/accessibility/ax_node_data.h" | 20 #include "ui/accessibility/ax_node_data.h" |
(...skipping 26 matching lines...) Expand all Loading... |
46 } | 47 } |
47 | 48 |
48 scoped_refptr<MockInputMethodManager::State> state_; | 49 scoped_refptr<MockInputMethodManager::State> state_; |
49 | 50 |
50 private: | 51 private: |
51 DISALLOW_COPY_AND_ASSIGN(TestInputMethodManager); | 52 DISALLOW_COPY_AND_ASSIGN(TestInputMethodManager); |
52 }; | 53 }; |
53 | 54 |
54 class ImeMenuTrayTest : public test::AshTestBase { | 55 class ImeMenuTrayTest : public test::AshTestBase { |
55 public: | 56 public: |
56 ImeMenuTrayTest() = default; | 57 ImeMenuTrayTest() |
| 58 : scoped_current_ime_(¤t_ime_), |
| 59 scoped_available_ime_list_(&available_ime_list_) {} |
57 ~ImeMenuTrayTest() override = default; | 60 ~ImeMenuTrayTest() override = default; |
58 | 61 |
59 // test::AshTestBase: | 62 // test::AshTestBase: |
60 void SetUp() override { | 63 void SetUp() override { |
61 test::AshTestBase::SetUp(); | 64 test::AshTestBase::SetUp(); |
62 // Takes ownership. | 65 // Takes ownership. |
63 InputMethodManager::Initialize(new TestInputMethodManager); | 66 InputMethodManager::Initialize(new TestInputMethodManager); |
64 } | 67 } |
65 void TearDown() override { | 68 void TearDown() override { |
66 InputMethodManager::Shutdown(); | 69 InputMethodManager::Shutdown(); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 return true; | 115 return true; |
113 } | 116 } |
114 | 117 |
115 // Focuses in the given type of input context. | 118 // Focuses in the given type of input context. |
116 void FocusInInputContext(ui::TextInputType input_type) { | 119 void FocusInInputContext(ui::TextInputType input_type) { |
117 ui::IMEEngineHandlerInterface::InputContext input_context( | 120 ui::IMEEngineHandlerInterface::InputContext input_context( |
118 input_type, ui::TEXT_INPUT_MODE_DEFAULT, ui::TEXT_INPUT_FLAG_NONE); | 121 input_type, ui::TEXT_INPUT_MODE_DEFAULT, ui::TEXT_INPUT_FLAG_NONE); |
119 ui::IMEBridge::Get()->SetCurrentInputContext(input_context); | 122 ui::IMEBridge::Get()->SetCurrentInputContext(input_context); |
120 } | 123 } |
121 | 124 |
| 125 void SetCurrentIme(const IMEInfo& info) { current_ime_ = info; } |
| 126 |
| 127 void SetAvailableImeList(const std::vector<IMEInfo>& list) { |
| 128 available_ime_list_ = list; |
| 129 } |
| 130 |
122 private: | 131 private: |
| 132 IMEInfo current_ime_; |
| 133 ime_util::ScopedCurrentImeForTesting scoped_current_ime_; |
| 134 |
| 135 std::vector<IMEInfo> available_ime_list_; |
| 136 ime_util::ScopedAvailableImeListForTesting scoped_available_ime_list_; |
| 137 |
123 DISALLOW_COPY_AND_ASSIGN(ImeMenuTrayTest); | 138 DISALLOW_COPY_AND_ASSIGN(ImeMenuTrayTest); |
124 }; | 139 }; |
125 | 140 |
126 // Tests that visibility of IME menu tray should be consistent with the | 141 // Tests that visibility of IME menu tray should be consistent with the |
127 // activation of the IME menu. | 142 // activation of the IME menu. |
128 TEST_F(ImeMenuTrayTest, ImeMenuTrayVisibility) { | 143 TEST_F(ImeMenuTrayTest, ImeMenuTrayVisibility) { |
129 ASSERT_FALSE(IsVisible()); | 144 ASSERT_FALSE(IsVisible()); |
130 | 145 |
131 Shell::Get()->system_tray_notifier()->NotifyRefreshIMEMenu(true); | 146 Shell::Get()->system_tray_notifier()->NotifyRefreshIMEMenu(true); |
132 EXPECT_TRUE(IsVisible()); | 147 EXPECT_TRUE(IsVisible()); |
133 | 148 |
134 Shell::Get()->system_tray_notifier()->NotifyRefreshIMEMenu(false); | 149 Shell::Get()->system_tray_notifier()->NotifyRefreshIMEMenu(false); |
135 EXPECT_FALSE(IsVisible()); | 150 EXPECT_FALSE(IsVisible()); |
136 } | 151 } |
137 | 152 |
138 // Tests that IME menu tray shows the right info of the current IME. | 153 // Tests that IME menu tray shows the right info of the current IME. |
139 TEST_F(ImeMenuTrayTest, TrayLabelTest) { | 154 TEST_F(ImeMenuTrayTest, TrayLabelTest) { |
140 Shell::Get()->system_tray_notifier()->NotifyRefreshIMEMenu(true); | 155 Shell::Get()->system_tray_notifier()->NotifyRefreshIMEMenu(true); |
141 ASSERT_TRUE(IsVisible()); | 156 ASSERT_TRUE(IsVisible()); |
142 | 157 |
143 // Changes the input method to "ime1". | 158 // Changes the input method to "ime1". |
144 IMEInfo info1; | 159 IMEInfo info1; |
145 info1.id = "ime1"; | 160 info1.id = "ime1"; |
146 info1.name = UTF8ToUTF16("English"); | 161 info1.name = UTF8ToUTF16("English"); |
147 info1.medium_name = UTF8ToUTF16("English"); | 162 info1.medium_name = UTF8ToUTF16("English"); |
148 info1.short_name = UTF8ToUTF16("US"); | 163 info1.short_name = UTF8ToUTF16("US"); |
149 info1.third_party = false; | 164 info1.third_party = false; |
150 info1.selected = true; | 165 info1.selected = true; |
151 GetSystemTrayDelegate()->SetCurrentIME(info1); | 166 SetCurrentIme(info1); |
152 Shell::Get()->system_tray_notifier()->NotifyRefreshIME(); | 167 Shell::Get()->system_tray_notifier()->NotifyRefreshIME(); |
153 EXPECT_EQ(UTF8ToUTF16("US"), GetTrayText()); | 168 EXPECT_EQ(UTF8ToUTF16("US"), GetTrayText()); |
154 | 169 |
155 // Changes the input method to a third-party IME extension. | 170 // Changes the input method to a third-party IME extension. |
156 IMEInfo info2; | 171 IMEInfo info2; |
157 info2.id = "ime2"; | 172 info2.id = "ime2"; |
158 info2.name = UTF8ToUTF16("English UK"); | 173 info2.name = UTF8ToUTF16("English UK"); |
159 info2.medium_name = UTF8ToUTF16("English UK"); | 174 info2.medium_name = UTF8ToUTF16("English UK"); |
160 info2.short_name = UTF8ToUTF16("UK"); | 175 info2.short_name = UTF8ToUTF16("UK"); |
161 info2.third_party = true; | 176 info2.third_party = true; |
162 info2.selected = true; | 177 info2.selected = true; |
163 GetSystemTrayDelegate()->SetCurrentIME(info2); | 178 SetCurrentIme(info2); |
164 Shell::Get()->system_tray_notifier()->NotifyRefreshIME(); | 179 Shell::Get()->system_tray_notifier()->NotifyRefreshIME(); |
165 EXPECT_EQ(UTF8ToUTF16("UK*"), GetTrayText()); | 180 EXPECT_EQ(UTF8ToUTF16("UK*"), GetTrayText()); |
166 } | 181 } |
167 | 182 |
168 // Tests that IME menu tray changes background color when tapped/clicked. And | 183 // Tests that IME menu tray changes background color when tapped/clicked. And |
169 // tests that the background color becomes 'inactive' when disabling the IME | 184 // tests that the background color becomes 'inactive' when disabling the IME |
170 // menu feature. Also makes sure that the shelf won't autohide as long as the | 185 // menu feature. Also makes sure that the shelf won't autohide as long as the |
171 // IME menu is open. | 186 // IME menu is open. |
172 TEST_F(ImeMenuTrayTest, PerformAction) { | 187 TEST_F(ImeMenuTrayTest, PerformAction) { |
173 Shell::Get()->system_tray_notifier()->NotifyRefreshIMEMenu(true); | 188 Shell::Get()->system_tray_notifier()->NotifyRefreshIMEMenu(true); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 info2.third_party = true; | 242 info2.third_party = true; |
228 info2.selected = false; | 243 info2.selected = false; |
229 | 244 |
230 info3.id = "ime3"; | 245 info3.id = "ime3"; |
231 info3.name = UTF8ToUTF16("Pinyin"); | 246 info3.name = UTF8ToUTF16("Pinyin"); |
232 info3.medium_name = UTF8ToUTF16("Chinese Pinyin"); | 247 info3.medium_name = UTF8ToUTF16("Chinese Pinyin"); |
233 info3.short_name = UTF8ToUTF16("拼"); | 248 info3.short_name = UTF8ToUTF16("拼"); |
234 info3.third_party = false; | 249 info3.third_party = false; |
235 info3.selected = false; | 250 info3.selected = false; |
236 | 251 |
237 std::vector<IMEInfo> ime_info_list{info1, info2, info3}; | 252 std::vector<IMEInfo> ime_info_list = {info1, info2, info3}; |
238 | 253 |
239 GetSystemTrayDelegate()->SetAvailableIMEList(ime_info_list); | 254 // Simulate switch to IME 1. |
240 GetSystemTrayDelegate()->SetCurrentIME(info1); | 255 SetAvailableImeList(ime_info_list); |
| 256 SetCurrentIme(info1); |
241 Shell::Get()->system_tray_notifier()->NotifyRefreshIME(); | 257 Shell::Get()->system_tray_notifier()->NotifyRefreshIME(); |
242 EXPECT_EQ(UTF8ToUTF16("US"), GetTrayText()); | 258 EXPECT_EQ(UTF8ToUTF16("US"), GetTrayText()); |
243 EXPECT_TRUE(IsTrayImeListValid(ime_info_list, info1)); | 259 EXPECT_TRUE(IsTrayImeListValid(ime_info_list, info1)); |
244 | 260 |
| 261 // Simulate switch to IME 3. |
245 ime_info_list[0].selected = false; | 262 ime_info_list[0].selected = false; |
246 ime_info_list[2].selected = true; | 263 ime_info_list[2].selected = true; |
247 GetSystemTrayDelegate()->SetAvailableIMEList(ime_info_list); | 264 SetAvailableImeList(ime_info_list); |
248 GetSystemTrayDelegate()->SetCurrentIME(info3); | 265 SetCurrentIme(info3); |
249 Shell::Get()->system_tray_notifier()->NotifyRefreshIME(); | 266 Shell::Get()->system_tray_notifier()->NotifyRefreshIME(); |
250 EXPECT_EQ(UTF8ToUTF16("拼"), GetTrayText()); | 267 EXPECT_EQ(UTF8ToUTF16("拼"), GetTrayText()); |
251 EXPECT_TRUE(IsTrayImeListValid(ime_info_list, info3)); | 268 EXPECT_TRUE(IsTrayImeListValid(ime_info_list, info3)); |
252 | 269 |
253 // Closes the menu before quitting. | 270 // Closes the menu before quitting. |
254 GetTray()->PerformAction(tap); | 271 GetTray()->PerformAction(tap); |
255 EXPECT_FALSE(IsTrayBackgroundActive()); | 272 EXPECT_FALSE(IsTrayBackgroundActive()); |
256 EXPECT_FALSE(IsBubbleShown()); | 273 EXPECT_FALSE(IsBubbleShown()); |
257 } | 274 } |
258 | 275 |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
347 FocusInInputContext(ui::TEXT_INPUT_TYPE_PASSWORD); | 364 FocusInInputContext(ui::TEXT_INPUT_TYPE_PASSWORD); |
348 EXPECT_FALSE(GetTray()->ShouldShowEmojiHandwritingVoiceButtons()); | 365 EXPECT_FALSE(GetTray()->ShouldShowEmojiHandwritingVoiceButtons()); |
349 | 366 |
350 // Lock screen should not show the buttons. | 367 // Lock screen should not show the buttons. |
351 BlockUserSession(BLOCKED_BY_LOCK_SCREEN); | 368 BlockUserSession(BLOCKED_BY_LOCK_SCREEN); |
352 FocusInInputContext(ui::TEXT_INPUT_TYPE_TEXT); | 369 FocusInInputContext(ui::TEXT_INPUT_TYPE_TEXT); |
353 EXPECT_FALSE(GetTray()->ShouldShowEmojiHandwritingVoiceButtons()); | 370 EXPECT_FALSE(GetTray()->ShouldShowEmojiHandwritingVoiceButtons()); |
354 } | 371 } |
355 | 372 |
356 } // namespace ash | 373 } // namespace ash |
OLD | NEW |