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" |
7 #include "ash/common/system/status_area_widget.h" | 8 #include "ash/common/system/status_area_widget.h" |
8 #include "ash/common/system/tray/ime_info.h" | 9 #include "ash/common/system/tray/ime_info.h" |
9 #include "ash/common/system/tray/system_tray_notifier.h" | 10 #include "ash/common/system/tray/system_tray_notifier.h" |
10 #include "ash/common/wm_shell.h" | 11 #include "ash/common/wm_shell.h" |
11 #include "ash/test/ash_test_base.h" | 12 #include "ash/test/ash_test_base.h" |
12 #include "ash/test/status_area_widget_test_helper.h" | 13 #include "ash/test/status_area_widget_test_helper.h" |
13 #include "ash/test/test_system_tray_delegate.h" | 14 #include "ash/test/test_system_tray_delegate.h" |
14 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
| 16 #include "ui/accessibility/ax_view_state.h" |
15 #include "ui/events/event.h" | 17 #include "ui/events/event.h" |
16 #include "ui/views/controls/label.h" | 18 #include "ui/views/controls/label.h" |
17 | 19 |
18 using base::UTF8ToUTF16; | 20 using base::UTF8ToUTF16; |
19 | 21 |
20 namespace ash { | 22 namespace ash { |
21 | 23 |
22 ImeMenuTray* GetTray() { | 24 ImeMenuTray* GetTray() { |
23 return StatusAreaWidgetTestHelper::GetStatusAreaWidget() | 25 return StatusAreaWidgetTestHelper::GetStatusAreaWidget() |
24 ->ime_menu_tray_for_testing(); | 26 ->ime_menu_tray_for_testing(); |
(...skipping 11 matching lines...) Expand all Loading... |
36 // Returns the label text of the tray. | 38 // Returns the label text of the tray. |
37 const base::string16& GetTrayText() { return GetTray()->label_->text(); } | 39 const base::string16& GetTrayText() { return GetTray()->label_->text(); } |
38 | 40 |
39 // Returns true if the background color of the tray is active. | 41 // Returns true if the background color of the tray is active. |
40 bool IsTrayBackgroundActive() { | 42 bool IsTrayBackgroundActive() { |
41 return GetTray()->draw_background_as_active(); | 43 return GetTray()->draw_background_as_active(); |
42 } | 44 } |
43 | 45 |
44 // Returns true if the IME menu bubble has been shown. | 46 // Returns true if the IME menu bubble has been shown. |
45 bool IsBubbleShown() { | 47 bool IsBubbleShown() { |
46 return (GetTray()->bubble_ && GetTray()->bubble_->bubble_view()); | 48 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; |
47 } | 79 } |
48 | 80 |
49 private: | 81 private: |
50 DISALLOW_COPY_AND_ASSIGN(ImeMenuTrayTest); | 82 DISALLOW_COPY_AND_ASSIGN(ImeMenuTrayTest); |
51 }; | 83 }; |
52 | 84 |
53 // Tests that visibility of IME menu tray should be consistent with the | 85 // Tests that visibility of IME menu tray should be consistent with the |
54 // activation of the IME menu. | 86 // activation of the IME menu. |
55 TEST_F(ImeMenuTrayTest, ImeMenuTrayVisibility) { | 87 TEST_F(ImeMenuTrayTest, ImeMenuTrayVisibility) { |
56 ASSERT_FALSE(IsVisible()); | 88 ASSERT_FALSE(IsVisible()); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 // If disabling the IME menu feature when the menu tray is activated, the tray | 145 // If disabling the IME menu feature when the menu tray is activated, the tray |
114 // element will be deactivated. | 146 // element will be deactivated. |
115 GetTray()->PerformAction(tap); | 147 GetTray()->PerformAction(tap); |
116 EXPECT_TRUE(IsTrayBackgroundActive()); | 148 EXPECT_TRUE(IsTrayBackgroundActive()); |
117 WmShell::Get()->system_tray_notifier()->NotifyRefreshIMEMenu(false); | 149 WmShell::Get()->system_tray_notifier()->NotifyRefreshIMEMenu(false); |
118 EXPECT_FALSE(IsVisible()); | 150 EXPECT_FALSE(IsVisible()); |
119 EXPECT_FALSE(IsBubbleShown()); | 151 EXPECT_FALSE(IsBubbleShown()); |
120 EXPECT_FALSE(IsTrayBackgroundActive()); | 152 EXPECT_FALSE(IsTrayBackgroundActive()); |
121 } | 153 } |
122 | 154 |
| 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 // Closes the menu before quitting. |
| 209 GetTray()->PerformAction(tap); |
| 210 EXPECT_FALSE(IsTrayBackgroundActive()); |
| 211 EXPECT_FALSE(IsBubbleShown()); |
| 212 } |
| 213 |
| 214 // Tests that quits Chrome with IME menu openned will not crash. |
| 215 TEST_F(ImeMenuTrayTest, QuitChromeWithMenuOpen) { |
| 216 WmShell::Get()->system_tray_notifier()->NotifyRefreshIMEMenu(true); |
| 217 ASSERT_TRUE(IsVisible()); |
| 218 ASSERT_FALSE(IsTrayBackgroundActive()); |
| 219 |
| 220 ui::GestureEvent tap(0, 0, 0, base::TimeTicks(), |
| 221 ui::GestureEventDetails(ui::ET_GESTURE_TAP)); |
| 222 GetTray()->PerformAction(tap); |
| 223 EXPECT_TRUE(IsTrayBackgroundActive()); |
| 224 EXPECT_TRUE(IsBubbleShown()); |
| 225 } |
| 226 |
123 } // namespace ash | 227 } // namespace ash |
OLD | NEW |