Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(101)

Side by Side Diff: ash/common/system/chromeos/ime_menu/ime_menu_tray_unittest.cc

Issue 2271483003: Updates the IME list when the IME has refreshed. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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>& list,
James Cook 2016/08/24 16:03:53 nit: How about |expected_list| or |expected_imes|
Azure Wei 2016/08/25 02:10:43 Done.
53 const IMEInfo& info) {
54 std::map<views::View*, std::string> ime_map =
55 GetTray()->ime_list_view_->ime_map_;
56 if (ime_map.size() != list.size())
57 return false;
58
59 std::vector<std::string> ime_ids;
James Cook 2016/08/24 16:03:52 nit: |expected_ime_ids| or similar
Azure Wei 2016/08/25 02:10:43 Done.
60 for (auto ime : list) {
James Cook 2016/08/24 16:03:53 nit: Always use const auto& or auto& or const IMEI
Azure Wei 2016/08/25 02:10:43 Done.
61 ime_ids.push_back(ime.id);
62 }
63 for (auto ime : ime_map) {
James Cook 2016/08/24 16:03:52 ditto
Azure Wei 2016/08/25 02:10:43 Done.
64 // Tests that all the IMEs on the view is in the list of selected IMEs.
65 if (std::find(ime_ids.begin(), ime_ids.end(), ime.second) ==
66 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 != info.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());
57 89
58 WmShell::Get()->system_tray_notifier()->NotifyRefreshIMEMenu(true); 90 WmShell::Get()->system_tray_notifier()->NotifyRefreshIMEMenu(true);
59 EXPECT_TRUE(IsVisible()); 91 EXPECT_TRUE(IsVisible());
60 92
61 WmShell::Get()->system_tray_notifier()->NotifyRefreshIMEMenu(false); 93 WmShell::Get()->system_tray_notifier()->NotifyRefreshIMEMenu(false);
62 EXPECT_FALSE(IsVisible()); 94 EXPECT_FALSE(IsVisible());
63 } 95 }
64 96
65 // Tests that IME menu tray shows the right info of the current IME. 97 // Tests that IME menu tray shows the right info of the current IME.
66 TEST_F(ImeMenuTrayTest, TrayLabelTest) { 98 TEST_F(ImeMenuTrayTest, TrayLabelTest) {
67 WmShell::Get()->system_tray_notifier()->NotifyRefreshIMEMenu(true); 99 WmShell::Get()->system_tray_notifier()->NotifyRefreshIMEMenu(true);
68 ASSERT_TRUE(IsVisible()); 100 ASSERT_TRUE(IsVisible());
69 101
70 // Changes the input method to "ime1". 102 // Changes the input method to "ime1".
71 IMEInfo info1; 103 IMEInfo info1(true, false, "ime1", "English", "English", "US");
72 info1.id = "ime1";
73 info1.name = UTF8ToUTF16("English");
74 info1.medium_name = UTF8ToUTF16("English");
75 info1.short_name = UTF8ToUTF16("US");
76 info1.third_party = false;
77 info1.selected = true;
78 GetSystemTrayDelegate()->SetCurrentIME(info1); 104 GetSystemTrayDelegate()->SetCurrentIME(info1);
79 WmShell::Get()->system_tray_notifier()->NotifyRefreshIME(); 105 WmShell::Get()->system_tray_notifier()->NotifyRefreshIME();
80 EXPECT_EQ(UTF8ToUTF16("US"), GetTrayText()); 106 EXPECT_EQ(UTF8ToUTF16("US"), GetTrayText());
81 107
82 // Changes the input method to a third-party IME extension. 108 // Changes the input method to a third-party IME extension.
83 IMEInfo info2; 109 IMEInfo info2(true, true, "ime2", "English UK", "English UK", "UK");
84 info2.id = "ime2";
85 info2.name = UTF8ToUTF16("English UK");
86 info2.medium_name = UTF8ToUTF16("English UK");
87 info2.short_name = UTF8ToUTF16("UK");
88 info2.third_party = true;
89 info2.selected = true;
90 GetSystemTrayDelegate()->SetCurrentIME(info2); 110 GetSystemTrayDelegate()->SetCurrentIME(info2);
91 WmShell::Get()->system_tray_notifier()->NotifyRefreshIME(); 111 WmShell::Get()->system_tray_notifier()->NotifyRefreshIME();
92 EXPECT_EQ(UTF8ToUTF16("UK*"), GetTrayText()); 112 EXPECT_EQ(UTF8ToUTF16("UK*"), GetTrayText());
93 } 113 }
94 114
95 // Tests that IME menu tray changes background color when tapped/clicked. And 115 // Tests that IME menu tray changes background color when tapped/clicked. And
96 // tests that the background color becomes 'inactive' when disabling the IME 116 // tests that the background color becomes 'inactive' when disabling the IME
97 // menu feature. 117 // menu feature.
98 TEST_F(ImeMenuTrayTest, PerformAction) { 118 TEST_F(ImeMenuTrayTest, PerformAction) {
99 WmShell::Get()->system_tray_notifier()->NotifyRefreshIMEMenu(true); 119 WmShell::Get()->system_tray_notifier()->NotifyRefreshIMEMenu(true);
(...skipping 13 matching lines...) Expand all
113 // If disabling the IME menu feature when the menu tray is activated, the tray 133 // If disabling the IME menu feature when the menu tray is activated, the tray
114 // element will be deactivated. 134 // element will be deactivated.
115 GetTray()->PerformAction(tap); 135 GetTray()->PerformAction(tap);
116 EXPECT_TRUE(IsTrayBackgroundActive()); 136 EXPECT_TRUE(IsTrayBackgroundActive());
117 WmShell::Get()->system_tray_notifier()->NotifyRefreshIMEMenu(false); 137 WmShell::Get()->system_tray_notifier()->NotifyRefreshIMEMenu(false);
118 EXPECT_FALSE(IsVisible()); 138 EXPECT_FALSE(IsVisible());
119 EXPECT_FALSE(IsBubbleShown()); 139 EXPECT_FALSE(IsBubbleShown());
120 EXPECT_FALSE(IsTrayBackgroundActive()); 140 EXPECT_FALSE(IsTrayBackgroundActive());
121 } 141 }
122 142
143 // Tests that IME menu list updates when changing the current IME. This should
144 // only happen by using shortcuts (Ctrl + Space / Ctrl + Shift + Space) to
145 // switch IMEs.
146 TEST_F(ImeMenuTrayTest, RefreshImeWithListViewCreated) {
147 WmShell::Get()->system_tray_notifier()->NotifyRefreshIMEMenu(true);
148 ASSERT_TRUE(IsVisible());
149 ASSERT_FALSE(IsTrayBackgroundActive());
150
151 ui::GestureEvent tap(0, 0, 0, base::TimeTicks(),
152 ui::GestureEventDetails(ui::ET_GESTURE_TAP));
153 GetTray()->PerformAction(tap);
154
155 EXPECT_TRUE(IsTrayBackgroundActive());
156 EXPECT_TRUE(IsBubbleShown());
157
158 IMEInfo info1(true, false, "ime", "English", "English", "US");
159 IMEInfo info2(false, true, "ime2", "English UK", "English UK", "UK");
160 IMEInfo info3(false, false, "ime3", "Pinyin", "Chinese Pinyin", "拼");
161 std::vector<IMEInfo> ime_info_list{info1, info2, info3};
162
163 GetSystemTrayDelegate()->SetAvailableIMEList(ime_info_list);
164 GetSystemTrayDelegate()->SetCurrentIME(info1);
165 WmShell::Get()->system_tray_notifier()->NotifyRefreshIME();
166 EXPECT_EQ(UTF8ToUTF16("US"), GetTrayText());
167 EXPECT_TRUE(IsTrayImeListValid(ime_info_list, info1));
168
169 ime_info_list[0].selected = false;
170 ime_info_list[2].selected = true;
171 GetSystemTrayDelegate()->SetAvailableIMEList(ime_info_list);
172 GetSystemTrayDelegate()->SetCurrentIME(info3);
173 WmShell::Get()->system_tray_notifier()->NotifyRefreshIME();
174 EXPECT_EQ(UTF8ToUTF16("拼"), GetTrayText());
175 EXPECT_TRUE(IsTrayImeListValid(ime_info_list, info3));
176 }
James Cook 2016/08/24 16:03:52 Nice test. Easy to read.
177
123 } // namespace ash 178 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698