OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h" | |
6 | |
7 #include "ash/magnifier/magnification_controller.h" | |
8 #include "ash/shell.h" | |
9 #include "base/command_line.h" | |
10 #include "base/prefs/pref_service.h" | |
11 #include "chrome/browser/browser_process.h" | |
12 #include "chrome/browser/chromeos/accessibility/magnification_manager.h" | |
13 #include "chrome/browser/chromeos/cros/cros_in_process_browser_test.h" | |
14 #include "chrome/browser/chromeos/login/helper.h" | |
15 #include "chrome/browser/chromeos/login/login_utils.h" | |
16 #include "chrome/browser/chromeos/login/user_manager.h" | |
17 #include "chrome/browser/chromeos/login/user_manager_impl.h" | |
18 #include "chrome/browser/profiles/profile.h" | |
19 #include "chrome/browser/profiles/profile_manager.h" | |
20 #include "chrome/common/chrome_notification_types.h" | |
21 #include "chrome/common/pref_names.h" | |
22 #include "chrome/test/base/testing_profile.h" | |
23 #include "chromeos/chromeos_switches.h" | |
24 #include "content/public/browser/notification_service.h" | |
25 #include "testing/gtest/include/gtest/gtest.h" | |
26 | |
27 namespace chromeos { | |
28 | |
29 namespace { | |
30 | |
31 const char kTestUserName[] = "owner@invalid.domain"; | |
32 | |
33 class MockAccessibilityObserver : public content::NotificationObserver { | |
34 public: | |
35 MockAccessibilityObserver() : observed_(false), | |
36 observed_enabled_(false), | |
37 observed_type_(-1) { | |
38 registrar_.Add( | |
39 this, | |
40 chrome::NOTIFICATION_CROS_ACCESSIBILITY_TOGGLE_SPOKEN_FEEDBACK, | |
41 content::NotificationService::AllSources()); | |
42 registrar_.Add( | |
43 this, | |
44 chrome::NOTIFICATION_CROS_ACCESSIBILITY_TOGGLE_HIGH_CONTRAST_MODE, | |
45 content::NotificationService::AllSources()); | |
46 } | |
47 | |
Daniel Erat
2013/04/26 13:58:58
needs a virtual d'tor
yoshiki
2013/05/24 18:49:45
Done.
| |
48 bool observed() const { return observed_; } | |
49 bool observed_enabled() const { return observed_enabled_; } | |
50 int observed_type() const { return observed_type_; } | |
51 | |
52 void reset() { observed_ = false; } | |
53 | |
54 private: | |
55 // content::NotificationObserver implimentation: | |
56 virtual void Observe(int type, | |
57 const content::NotificationSource& source, | |
58 const content::NotificationDetails& details) OVERRIDE { | |
59 AccessibilityStatusEventDetails* accessibility_status = | |
60 content::Details<AccessibilityStatusEventDetails>( | |
61 details).ptr(); | |
62 ASSERT_FALSE(observed_); | |
63 | |
64 switch (type) { | |
65 case chrome::NOTIFICATION_CROS_ACCESSIBILITY_TOGGLE_SPOKEN_FEEDBACK: | |
66 observed_ = true; | |
67 observed_enabled_ = accessibility_status->enabled; | |
68 observed_type_ = type; | |
69 break; | |
70 case chrome::NOTIFICATION_CROS_ACCESSIBILITY_TOGGLE_HIGH_CONTRAST_MODE: | |
71 observed_ = true; | |
72 observed_enabled_ = accessibility_status->enabled; | |
73 observed_type_ = type; | |
74 break; | |
75 } | |
76 } | |
77 | |
78 bool observed_; | |
79 bool observed_enabled_; | |
80 int observed_type_; | |
81 | |
82 content::NotificationRegistrar registrar_; | |
83 }; | |
Daniel Erat
2013/04/26 13:58:58
DISALLOW_COPY_AND_ASSIGN
yoshiki
2013/05/24 18:49:45
Done.
| |
84 | |
85 void SetHighContrastEnabled(bool enabled) { | |
86 return AccessibilityManager::Get()->EnableHighContrast(enabled); | |
87 } | |
88 | |
89 bool IsHighContrastEnabled() { | |
90 return AccessibilityManager::Get()->IsHighContrastEnabled(); | |
91 } | |
92 | |
93 void SetSpokenFeedbackEnabled(bool enabled) { | |
94 return AccessibilityManager::Get()->EnableSpokenFeedback( | |
95 enabled, NULL, ash::A11Y_NOTIFICATION_NONE); | |
96 } | |
97 | |
98 bool IsSpokenFeedbackEnabled() { | |
99 return AccessibilityManager::Get()->IsSpokenFeedbackEnabled(); | |
100 } | |
101 | |
102 Profile* profile() { | |
Daniel Erat
2013/04/26 13:58:58
i don't think i've seen inline-style lowercase nam
yoshiki
2013/05/24 18:49:45
Done.
| |
103 Profile* profile = ProfileManager::GetDefaultProfileOrOffTheRecord(); | |
104 DCHECK(profile); | |
105 return profile; | |
106 } | |
107 | |
108 PrefService* prefs() { | |
Daniel Erat
2013/04/26 13:58:58
same here
yoshiki
2013/05/24 18:49:45
Done.
| |
109 return profile()->GetPrefs(); | |
110 } | |
111 | |
112 void SetHighContrastEnabledToPref(bool enabled) { | |
113 prefs()->SetBoolean(prefs::kHighContrastEnabled, enabled); | |
114 } | |
115 | |
116 void SetSpokenFeedbackEnabledToPref(bool enabled) { | |
117 prefs()->SetBoolean(prefs::kSpokenFeedbackEnabled, enabled); | |
118 } | |
119 | |
120 } // anonymouse namespace | |
121 | |
122 class AccessibilityManagerTest : public CrosInProcessBrowserTest { | |
123 protected: | |
124 AccessibilityManagerTest() {} | |
125 virtual ~AccessibilityManagerTest() {} | |
126 | |
127 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | |
128 command_line->AppendSwitch(chromeos::switches::kLoginManager); | |
129 command_line->AppendSwitchASCII(chromeos::switches::kLoginProfile, | |
130 TestingProfile::kTestUserProfileDir); | |
131 } | |
132 | |
133 virtual void SetUpOnMainThread() OVERRIDE { | |
134 } | |
135 | |
136 content::NotificationRegistrar registrar_; | |
137 DISALLOW_COPY_AND_ASSIGN(AccessibilityManagerTest); | |
138 }; | |
139 | |
140 IN_PROC_BROWSER_TEST_F(AccessibilityManagerTest, Login) { | |
141 // Confirms that magnifier is disabled on the login screen. | |
142 EXPECT_FALSE(IsSpokenFeedbackEnabled()); | |
143 EXPECT_FALSE(IsHighContrastEnabled()); | |
144 | |
145 // Logs in. | |
146 UserManager::Get()->UserLoggedIn(kTestUserName, kTestUserName, true); | |
147 | |
148 // Confirms that magnifier is still disabled just after login. | |
149 EXPECT_FALSE(IsSpokenFeedbackEnabled()); | |
150 EXPECT_FALSE(IsHighContrastEnabled()); | |
151 | |
152 UserManager::Get()->SessionStarted(); | |
153 | |
154 // Confirms that magnifier is still disabled just after login. | |
155 EXPECT_FALSE(IsSpokenFeedbackEnabled()); | |
156 EXPECT_FALSE(IsHighContrastEnabled()); | |
157 | |
158 // Enables magnifier. | |
159 SetSpokenFeedbackEnabled(true); | |
160 // Confirms that magnifier is enabled. | |
161 EXPECT_TRUE(IsSpokenFeedbackEnabled()); | |
162 | |
163 // Enables magnifier. | |
164 SetHighContrastEnabled(true); | |
165 // Confirms that magnifier is enabled. | |
166 EXPECT_TRUE(IsHighContrastEnabled()); | |
167 } | |
168 | |
169 IN_PROC_BROWSER_TEST_F(AccessibilityManagerTest, TypePref) { | |
170 // Logs in | |
Daniel Erat
2013/04/26 13:58:58
nit: add trailing period
yoshiki
2013/05/24 18:49:45
Done.
| |
171 UserManager::Get()->UserLoggedIn(kTestUserName, kTestUserName, true); | |
172 UserManager::Get()->SessionStarted(); | |
173 | |
174 // Confirms that magnifier is disabled just after login. | |
175 EXPECT_FALSE(IsSpokenFeedbackEnabled()); | |
176 EXPECT_FALSE(IsHighContrastEnabled()); | |
177 | |
178 // Sets the pref as true to enable magnifier. | |
179 SetSpokenFeedbackEnabledToPref(true); | |
180 // Confirms that magnifier is enabled. | |
181 EXPECT_TRUE(IsSpokenFeedbackEnabled()); | |
182 | |
183 // Enables magnifier. | |
184 SetHighContrastEnabled(true); | |
185 // Confirms that magnifier is enabled. | |
186 EXPECT_TRUE(IsHighContrastEnabled()); | |
187 | |
188 SetSpokenFeedbackEnabledToPref(false); | |
189 EXPECT_FALSE(IsSpokenFeedbackEnabled()); | |
190 | |
191 SetHighContrastEnabledToPref(false); | |
192 EXPECT_FALSE(IsHighContrastEnabled()); | |
193 } | |
194 | |
195 IN_PROC_BROWSER_TEST_F(AccessibilityManagerTest, ResumeSavedPref) { | |
196 // Loads the profile of the user. | |
197 UserManager::Get()->UserLoggedIn(kTestUserName, kTestUserName, true); | |
198 | |
199 // Sets the pref as true to enable magnifier before login. | |
200 SetSpokenFeedbackEnabledToPref(true); | |
201 EXPECT_TRUE(IsSpokenFeedbackEnabled()); | |
202 | |
203 // Sets the pref as true to enable magnifier before login. | |
204 SetHighContrastEnabledToPref(true); | |
205 EXPECT_TRUE(IsHighContrastEnabled()); | |
206 | |
207 // Logs in. | |
208 UserManager::Get()->SessionStarted(); | |
209 | |
210 // Confirms that magnifier is enabled just after login. | |
211 EXPECT_TRUE(IsSpokenFeedbackEnabled()); | |
212 EXPECT_TRUE(IsHighContrastEnabled()); | |
213 } | |
214 | |
215 IN_PROC_BROWSER_TEST_F(AccessibilityManagerTest, | |
216 ChangingTypeInvokesNotification) { | |
217 MockAccessibilityObserver observer; | |
218 | |
219 // Logs in | |
Daniel Erat
2013/04/26 13:58:58
nit: add trailing period (or remove unnecessary co
yoshiki
2013/05/24 18:49:45
Done.
| |
220 UserManager::Get()->UserLoggedIn(kTestUserName, kTestUserName, true); | |
221 UserManager::Get()->SessionStarted(); | |
222 | |
223 EXPECT_FALSE(observer.observed()); | |
224 observer.reset(); | |
225 | |
226 SetSpokenFeedbackEnabled(true); | |
227 EXPECT_TRUE(observer.observed()); | |
228 EXPECT_TRUE(observer.observed_enabled()); | |
229 EXPECT_EQ(observer.observed_type(), | |
230 chrome::NOTIFICATION_CROS_ACCESSIBILITY_TOGGLE_SPOKEN_FEEDBACK); | |
231 EXPECT_TRUE(IsSpokenFeedbackEnabled()); | |
232 | |
233 observer.reset(); | |
234 SetSpokenFeedbackEnabled(false); | |
235 EXPECT_TRUE(observer.observed()); | |
236 EXPECT_FALSE(observer.observed_enabled()); | |
237 EXPECT_EQ(observer.observed_type(), | |
238 chrome::NOTIFICATION_CROS_ACCESSIBILITY_TOGGLE_SPOKEN_FEEDBACK); | |
239 EXPECT_FALSE(IsSpokenFeedbackEnabled()); | |
240 | |
241 observer.reset(); | |
242 SetHighContrastEnabled(true); | |
243 EXPECT_TRUE(observer.observed()); | |
244 EXPECT_TRUE(observer.observed_enabled()); | |
245 EXPECT_EQ(observer.observed_type(), | |
246 chrome::NOTIFICATION_CROS_ACCESSIBILITY_TOGGLE_HIGH_CONTRAST_MODE); | |
247 EXPECT_TRUE(IsHighContrastEnabled()); | |
248 | |
249 observer.reset(); | |
250 SetHighContrastEnabled(false); | |
251 EXPECT_TRUE(observer.observed()); | |
252 EXPECT_FALSE(observer.observed_enabled()); | |
253 EXPECT_EQ(observer.observed_type(), | |
254 chrome::NOTIFICATION_CROS_ACCESSIBILITY_TOGGLE_HIGH_CONTRAST_MODE); | |
255 EXPECT_FALSE(IsHighContrastEnabled()); | |
256 } | |
257 | |
258 IN_PROC_BROWSER_TEST_F(AccessibilityManagerTest, | |
259 ChangingTypePrefInvokesNotification) { | |
260 MockAccessibilityObserver observer; | |
261 | |
262 // Logs in | |
Daniel Erat
2013/04/26 13:58:58
here too
yoshiki
2013/05/24 18:49:45
Done.
| |
263 UserManager::Get()->UserLoggedIn(kTestUserName, kTestUserName, true); | |
264 UserManager::Get()->SessionStarted(); | |
265 | |
266 EXPECT_FALSE(observer.observed()); | |
267 observer.reset(); | |
268 | |
269 SetSpokenFeedbackEnabledToPref(true); | |
270 EXPECT_TRUE(observer.observed()); | |
271 EXPECT_TRUE(observer.observed_enabled()); | |
272 EXPECT_EQ(observer.observed_type(), | |
273 chrome::NOTIFICATION_CROS_ACCESSIBILITY_TOGGLE_SPOKEN_FEEDBACK); | |
274 EXPECT_TRUE(IsSpokenFeedbackEnabled()); | |
275 | |
276 observer.reset(); | |
277 SetSpokenFeedbackEnabledToPref(false); | |
278 EXPECT_TRUE(observer.observed()); | |
279 EXPECT_FALSE(observer.observed_enabled()); | |
280 EXPECT_EQ(observer.observed_type(), | |
281 chrome::NOTIFICATION_CROS_ACCESSIBILITY_TOGGLE_SPOKEN_FEEDBACK); | |
282 EXPECT_FALSE(IsSpokenFeedbackEnabled()); | |
283 | |
284 observer.reset(); | |
285 SetHighContrastEnabledToPref(true); | |
286 EXPECT_TRUE(observer.observed()); | |
287 EXPECT_TRUE(observer.observed_enabled()); | |
288 EXPECT_EQ(observer.observed_type(), | |
289 chrome::NOTIFICATION_CROS_ACCESSIBILITY_TOGGLE_HIGH_CONTRAST_MODE); | |
290 EXPECT_TRUE(IsHighContrastEnabled()); | |
291 | |
292 observer.reset(); | |
293 SetHighContrastEnabledToPref(false); | |
294 EXPECT_TRUE(observer.observed()); | |
295 EXPECT_FALSE(observer.observed_enabled()); | |
296 EXPECT_EQ(observer.observed_type(), | |
297 chrome::NOTIFICATION_CROS_ACCESSIBILITY_TOGGLE_HIGH_CONTRAST_MODE); | |
298 EXPECT_FALSE(IsHighContrastEnabled()); | |
299 } | |
300 | |
301 } // namespace chromeos | |
OLD | NEW |