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/common/system/chromeos/ime_menu/ime_menu_tray.h" | 5 #include "ash/common/system/chromeos/ime_menu/ime_menu_tray.h" |
6 | 6 |
7 #include "ash/common/system/chromeos/ime_menu/ime_list_view.h" | |
8 #include "ash/common/system/status_area_widget.h" | 7 #include "ash/common/system/status_area_widget.h" |
9 #include "ash/common/system/tray/ime_info.h" | 8 #include "ash/common/system/tray/ime_info.h" |
10 #include "ash/common/system/tray/system_tray_notifier.h" | 9 #include "ash/common/system/tray/system_tray_notifier.h" |
11 #include "ash/common/wm_shell.h" | 10 #include "ash/common/wm_shell.h" |
12 #include "ash/test/ash_test_base.h" | 11 #include "ash/test/ash_test_base.h" |
13 #include "ash/test/status_area_widget_test_helper.h" | 12 #include "ash/test/status_area_widget_test_helper.h" |
14 #include "ash/test/test_system_tray_delegate.h" | 13 #include "ash/test/test_system_tray_delegate.h" |
15 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
16 #include "ui/accessibility/ax_view_state.h" | |
17 #include "ui/events/event.h" | 15 #include "ui/events/event.h" |
18 #include "ui/views/controls/label.h" | 16 #include "ui/views/controls/label.h" |
19 | 17 |
20 using base::UTF8ToUTF16; | 18 using base::UTF8ToUTF16; |
21 | 19 |
22 namespace ash { | 20 namespace ash { |
23 | 21 |
24 ImeMenuTray* GetTray() { | 22 ImeMenuTray* GetTray() { |
25 return StatusAreaWidgetTestHelper::GetStatusAreaWidget() | 23 return StatusAreaWidgetTestHelper::GetStatusAreaWidget() |
26 ->ime_menu_tray_for_testing(); | 24 ->ime_menu_tray_for_testing(); |
(...skipping 11 matching lines...) Expand all Loading... |
38 // Returns the label text of the tray. | 36 // Returns the label text of the tray. |
39 const base::string16& GetTrayText() { return GetTray()->label_->text(); } | 37 const base::string16& GetTrayText() { return GetTray()->label_->text(); } |
40 | 38 |
41 // Returns true if the background color of the tray is active. | 39 // Returns true if the background color of the tray is active. |
42 bool IsTrayBackgroundActive() { | 40 bool IsTrayBackgroundActive() { |
43 return GetTray()->draw_background_as_active(); | 41 return GetTray()->draw_background_as_active(); |
44 } | 42 } |
45 | 43 |
46 // Returns true if the IME menu bubble has been shown. | 44 // Returns true if the IME menu bubble has been shown. |
47 bool IsBubbleShown() { | 45 bool IsBubbleShown() { |
48 return GetTray()->bubble_ && GetTray()->bubble_->bubble_view(); | 46 return (GetTray()->bubble_ && GetTray()->bubble_->bubble_view()); |
49 } | |
50 | |
51 // Returns true if the IME menu list has been updated with the right IME list. | |
52 bool IsTrayImeListValid(const std::vector<IMEInfo>& expected_imes, | |
53 const IMEInfo& expected_current_ime) { | |
54 std::map<views::View*, std::string> ime_map = | |
55 GetTray()->ime_list_view_->ime_map_; | |
56 if (ime_map.size() != expected_imes.size()) | |
57 return false; | |
58 | |
59 std::vector<std::string> expected_ime_ids; | |
60 for (const auto& ime : expected_imes) { | |
61 expected_ime_ids.push_back(ime.id); | |
62 } | |
63 for (const auto& ime : ime_map) { | |
64 // Tests that all the IMEs on the view is in the list of selected IMEs. | |
65 if (std::find(expected_ime_ids.begin(), expected_ime_ids.end(), | |
66 ime.second) == expected_ime_ids.end()) { | |
67 return false; | |
68 } | |
69 | |
70 // Tests that the checked IME is the current IME. | |
71 ui::AXViewState state; | |
72 ime.first->GetAccessibleState(&state); | |
73 if (state.HasStateFlag(ui::AX_STATE_CHECKED)) { | |
74 if (ime.second != expected_current_ime.id) | |
75 return false; | |
76 } | |
77 } | |
78 return true; | |
79 } | 47 } |
80 | 48 |
81 private: | 49 private: |
82 DISALLOW_COPY_AND_ASSIGN(ImeMenuTrayTest); | 50 DISALLOW_COPY_AND_ASSIGN(ImeMenuTrayTest); |
83 }; | 51 }; |
84 | 52 |
85 // Tests that visibility of IME menu tray should be consistent with the | 53 // Tests that visibility of IME menu tray should be consistent with the |
86 // activation of the IME menu. | 54 // activation of the IME menu. |
87 TEST_F(ImeMenuTrayTest, ImeMenuTrayVisibility) { | 55 TEST_F(ImeMenuTrayTest, ImeMenuTrayVisibility) { |
88 ASSERT_FALSE(IsVisible()); | 56 ASSERT_FALSE(IsVisible()); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 // If disabling the IME menu feature when the menu tray is activated, the tray | 113 // If disabling the IME menu feature when the menu tray is activated, the tray |
146 // element will be deactivated. | 114 // element will be deactivated. |
147 GetTray()->PerformAction(tap); | 115 GetTray()->PerformAction(tap); |
148 EXPECT_TRUE(IsTrayBackgroundActive()); | 116 EXPECT_TRUE(IsTrayBackgroundActive()); |
149 WmShell::Get()->system_tray_notifier()->NotifyRefreshIMEMenu(false); | 117 WmShell::Get()->system_tray_notifier()->NotifyRefreshIMEMenu(false); |
150 EXPECT_FALSE(IsVisible()); | 118 EXPECT_FALSE(IsVisible()); |
151 EXPECT_FALSE(IsBubbleShown()); | 119 EXPECT_FALSE(IsBubbleShown()); |
152 EXPECT_FALSE(IsTrayBackgroundActive()); | 120 EXPECT_FALSE(IsTrayBackgroundActive()); |
153 } | 121 } |
154 | 122 |
155 // Tests that IME menu list updates when changing the current IME. This should | |
156 // only happen by using shortcuts (Ctrl + Space / Ctrl + Shift + Space) to | |
157 // switch IMEs. | |
158 TEST_F(ImeMenuTrayTest, RefreshImeWithListViewCreated) { | |
159 WmShell::Get()->system_tray_notifier()->NotifyRefreshIMEMenu(true); | |
160 ASSERT_TRUE(IsVisible()); | |
161 ASSERT_FALSE(IsTrayBackgroundActive()); | |
162 | |
163 ui::GestureEvent tap(0, 0, 0, base::TimeTicks(), | |
164 ui::GestureEventDetails(ui::ET_GESTURE_TAP)); | |
165 GetTray()->PerformAction(tap); | |
166 | |
167 EXPECT_TRUE(IsTrayBackgroundActive()); | |
168 EXPECT_TRUE(IsBubbleShown()); | |
169 | |
170 IMEInfo info1, info2, info3; | |
171 info1.id = "ime1"; | |
172 info1.name = UTF8ToUTF16("English"); | |
173 info1.medium_name = UTF8ToUTF16("English"); | |
174 info1.short_name = UTF8ToUTF16("US"); | |
175 info1.third_party = false; | |
176 info1.selected = true; | |
177 | |
178 info2.id = "ime2"; | |
179 info2.name = UTF8ToUTF16("English UK"); | |
180 info2.medium_name = UTF8ToUTF16("English UK"); | |
181 info2.short_name = UTF8ToUTF16("UK"); | |
182 info2.third_party = true; | |
183 info2.selected = false; | |
184 | |
185 info3.id = "ime3"; | |
186 info3.name = UTF8ToUTF16("Pinyin"); | |
187 info3.medium_name = UTF8ToUTF16("Chinese Pinyin"); | |
188 info3.short_name = UTF8ToUTF16("拼"); | |
189 info3.third_party = false; | |
190 info3.selected = false; | |
191 | |
192 std::vector<IMEInfo> ime_info_list{info1, info2, info3}; | |
193 | |
194 GetSystemTrayDelegate()->SetAvailableIMEList(ime_info_list); | |
195 GetSystemTrayDelegate()->SetCurrentIME(info1); | |
196 WmShell::Get()->system_tray_notifier()->NotifyRefreshIME(); | |
197 EXPECT_EQ(UTF8ToUTF16("US"), GetTrayText()); | |
198 EXPECT_TRUE(IsTrayImeListValid(ime_info_list, info1)); | |
199 | |
200 ime_info_list[0].selected = false; | |
201 ime_info_list[2].selected = true; | |
202 GetSystemTrayDelegate()->SetAvailableIMEList(ime_info_list); | |
203 GetSystemTrayDelegate()->SetCurrentIME(info3); | |
204 WmShell::Get()->system_tray_notifier()->NotifyRefreshIME(); | |
205 EXPECT_EQ(UTF8ToUTF16("拼"), GetTrayText()); | |
206 EXPECT_TRUE(IsTrayImeListValid(ime_info_list, info3)); | |
207 } | |
208 | |
209 } // namespace ash | 123 } // namespace ash |
OLD | NEW |