OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "chrome/browser/chromeos/policy/recommendation_restorer.h" | 5 #include "chrome/browser/chromeos/policy/recommendation_restorer.h" |
6 | 6 |
7 #include "ash/magnifier/magnifier_constants.h" | 7 #include "ash/magnifier/magnifier_constants.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/prefs/pref_notifier_impl.h" | 9 #include "base/prefs/pref_notifier_impl.h" |
10 #include "base/prefs/testing_pref_store.h" | 10 #include "base/prefs/testing_pref_store.h" |
(...skipping 25 matching lines...) Expand all Loading... |
36 const int kRestoreDelayInMs = 60 * 1000; // 1 minute. | 36 const int kRestoreDelayInMs = 60 * 1000; // 1 minute. |
37 } // namespace | 37 } // namespace |
38 | 38 |
39 class RecommendationRestorerTest : public testing::Test { | 39 class RecommendationRestorerTest : public testing::Test { |
40 protected: | 40 protected: |
41 RecommendationRestorerTest(); | 41 RecommendationRestorerTest(); |
42 | 42 |
43 // testing::Test: | 43 // testing::Test: |
44 virtual void SetUp() OVERRIDE; | 44 virtual void SetUp() OVERRIDE; |
45 | 45 |
| 46 void RegisterUserProfilePrefs(); |
| 47 void RegisterLoginProfilePrefs(); |
| 48 |
46 void SetRecommendedValues(); | 49 void SetRecommendedValues(); |
47 void SetUserSettings(); | 50 void SetUserSettings(); |
48 | 51 |
49 void CreateLoginProfile(); | 52 void CreateLoginProfile(); |
50 void CreateUserProfile(); | 53 void CreateUserProfile(); |
51 | 54 |
52 void NotifyOfSessionStart(); | 55 void NotifyOfSessionStart(); |
53 void NotifyOfUserActivity(); | 56 void NotifyOfUserActivity(); |
54 | 57 |
55 void VerifyPrefFollowsUser(const char* pref_name, | 58 void VerifyPrefFollowsUser(const char* pref_name, |
(...skipping 28 matching lines...) Expand all Loading... |
84 new TestingPrefStore, | 87 new TestingPrefStore, |
85 new TestingPrefStore, | 88 new TestingPrefStore, |
86 recommended_prefs_, | 89 recommended_prefs_, |
87 new user_prefs::PrefRegistrySyncable, | 90 new user_prefs::PrefRegistrySyncable, |
88 new PrefNotifierImpl)), | 91 new PrefNotifierImpl)), |
89 restorer_(NULL), | 92 restorer_(NULL), |
90 runner_(new base::TestSimpleTaskRunner), | 93 runner_(new base::TestSimpleTaskRunner), |
91 runner_handler_(runner_), | 94 runner_handler_(runner_), |
92 prefs_owner_(prefs_), | 95 prefs_owner_(prefs_), |
93 profile_manager_(TestingBrowserProcess::GetGlobal()) { | 96 profile_manager_(TestingBrowserProcess::GetGlobal()) { |
94 chrome::RegisterUserPrefs(prefs_->registry()); | |
95 } | 97 } |
96 | 98 |
97 void RecommendationRestorerTest::SetUp() { | 99 void RecommendationRestorerTest::SetUp() { |
98 testing::Test::SetUp(); | 100 testing::Test::SetUp(); |
99 ASSERT_TRUE(profile_manager_.SetUp()); | 101 ASSERT_TRUE(profile_manager_.SetUp()); |
100 } | 102 } |
101 | 103 |
| 104 void RecommendationRestorerTest::RegisterUserProfilePrefs() { |
| 105 chrome::RegisterUserProfilePrefs(prefs_->registry()); |
| 106 } |
| 107 |
| 108 void RecommendationRestorerTest::RegisterLoginProfilePrefs() { |
| 109 chrome::RegisterLoginProfilePrefs(prefs_->registry()); |
| 110 } |
| 111 |
102 void RecommendationRestorerTest::SetRecommendedValues() { | 112 void RecommendationRestorerTest::SetRecommendedValues() { |
103 recommended_prefs_->SetBoolean(prefs::kLargeCursorEnabled, false); | 113 recommended_prefs_->SetBoolean(prefs::kLargeCursorEnabled, false); |
104 recommended_prefs_->SetBoolean(prefs::kSpokenFeedbackEnabled, false); | 114 recommended_prefs_->SetBoolean(prefs::kSpokenFeedbackEnabled, false); |
105 recommended_prefs_->SetBoolean(prefs::kHighContrastEnabled, false); | 115 recommended_prefs_->SetBoolean(prefs::kHighContrastEnabled, false); |
106 recommended_prefs_->SetBoolean(prefs::kScreenMagnifierEnabled, false); | 116 recommended_prefs_->SetBoolean(prefs::kScreenMagnifierEnabled, false); |
107 recommended_prefs_->SetInteger(prefs::kScreenMagnifierType, 0); | 117 recommended_prefs_->SetInteger(prefs::kScreenMagnifierType, 0); |
108 } | 118 } |
109 | 119 |
110 void RecommendationRestorerTest::SetUserSettings() { | 120 void RecommendationRestorerTest::SetUserSettings() { |
111 prefs_->SetBoolean(prefs::kLargeCursorEnabled, true); | 121 prefs_->SetBoolean(prefs::kLargeCursorEnabled, true); |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 EXPECT_TRUE(restorer_->restore_timer_.IsRunning()); | 221 EXPECT_TRUE(restorer_->restore_timer_.IsRunning()); |
212 EXPECT_EQ(base::TimeDelta::FromMilliseconds(kRestoreDelayInMs), | 222 EXPECT_EQ(base::TimeDelta::FromMilliseconds(kRestoreDelayInMs), |
213 restorer_->restore_timer_.GetCurrentDelay()); | 223 restorer_->restore_timer_.GetCurrentDelay()); |
214 } | 224 } |
215 | 225 |
216 TEST_F(RecommendationRestorerTest, CreateForUserProfile) { | 226 TEST_F(RecommendationRestorerTest, CreateForUserProfile) { |
217 // Verifies that when a RecommendationRestorer is created for a user profile, | 227 // Verifies that when a RecommendationRestorer is created for a user profile, |
218 // it does not start listening for any notifications, does not clear user | 228 // it does not start listening for any notifications, does not clear user |
219 // settings on initialization and does not start a timer that will clear user | 229 // settings on initialization and does not start a timer that will clear user |
220 // settings eventually. | 230 // settings eventually. |
| 231 RegisterUserProfilePrefs(); |
221 SetRecommendedValues(); | 232 SetRecommendedValues(); |
222 SetUserSettings(); | 233 SetUserSettings(); |
223 | 234 |
224 CreateUserProfile(); | 235 CreateUserProfile(); |
225 VerifyNotListeningForNotifications(); | 236 VerifyNotListeningForNotifications(); |
226 VerifyPrefsFollowUser(); | 237 VerifyPrefsFollowUser(); |
227 VerifyTimerIsStopped(); | 238 VerifyTimerIsStopped(); |
228 } | 239 } |
229 | 240 |
230 TEST_F(RecommendationRestorerTest, NoRecommendations) { | 241 TEST_F(RecommendationRestorerTest, NoRecommendations) { |
231 // Verifies that when no recommended values have been set and a | 242 // Verifies that when no recommended values have been set and a |
232 // RecommendationRestorer is created for the login profile, it does not clear | 243 // RecommendationRestorer is created for the login profile, it does not clear |
233 // user settings on initialization and does not start a timer that will clear | 244 // user settings on initialization and does not start a timer that will clear |
234 // user settings eventually. | 245 // user settings eventually. |
| 246 RegisterLoginProfilePrefs(); |
235 SetUserSettings(); | 247 SetUserSettings(); |
236 | 248 |
237 CreateLoginProfile(); | 249 CreateLoginProfile(); |
238 VerifyPrefsFollowUser(); | 250 VerifyPrefsFollowUser(); |
239 VerifyTimerIsStopped(); | 251 VerifyTimerIsStopped(); |
240 } | 252 } |
241 | 253 |
242 TEST_F(RecommendationRestorerTest, RestoreOnStartup) { | 254 TEST_F(RecommendationRestorerTest, RestoreOnStartup) { |
243 // Verifies that when recommended values have been set and a | 255 // Verifies that when recommended values have been set and a |
244 // RecommendationRestorer is created for the login profile, it clears user | 256 // RecommendationRestorer is created for the login profile, it clears user |
245 // settings on initialization. | 257 // settings on initialization. |
| 258 RegisterLoginProfilePrefs(); |
246 SetRecommendedValues(); | 259 SetRecommendedValues(); |
247 SetUserSettings(); | 260 SetUserSettings(); |
248 | 261 |
249 CreateLoginProfile(); | 262 CreateLoginProfile(); |
250 VerifyPrefsFollowRecommendations(); | 263 VerifyPrefsFollowRecommendations(); |
251 VerifyTimerIsStopped(); | 264 VerifyTimerIsStopped(); |
252 } | 265 } |
253 | 266 |
254 TEST_F(RecommendationRestorerTest, RestoreOnRecommendationChangeOnLoginScreen) { | 267 TEST_F(RecommendationRestorerTest, RestoreOnRecommendationChangeOnLoginScreen) { |
255 // Verifies that if recommended values change while the login screen is being | 268 // Verifies that if recommended values change while the login screen is being |
256 // shown, a timer is started that will clear user settings eventually. | 269 // shown, a timer is started that will clear user settings eventually. |
| 270 RegisterLoginProfilePrefs(); |
257 SetUserSettings(); | 271 SetUserSettings(); |
258 | 272 |
259 CreateLoginProfile(); | 273 CreateLoginProfile(); |
260 | 274 |
261 VerifyTimerIsStopped(); | 275 VerifyTimerIsStopped(); |
262 recommended_prefs_->SetBoolean(prefs::kLargeCursorEnabled, false); | 276 recommended_prefs_->SetBoolean(prefs::kLargeCursorEnabled, false); |
263 VerifyPrefFollowsUser(prefs::kLargeCursorEnabled, | 277 VerifyPrefFollowsUser(prefs::kLargeCursorEnabled, |
264 base::FundamentalValue(true)); | 278 base::FundamentalValue(true)); |
265 VerifyTimerIsRunning(); | 279 VerifyTimerIsRunning(); |
266 runner_->RunUntilIdle(); | 280 runner_->RunUntilIdle(); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 base::FundamentalValue(false)); | 312 base::FundamentalValue(false)); |
299 VerifyPrefFollowsRecommendation(prefs::kScreenMagnifierType, | 313 VerifyPrefFollowsRecommendation(prefs::kScreenMagnifierType, |
300 base::FundamentalValue(0)); | 314 base::FundamentalValue(0)); |
301 | 315 |
302 VerifyTimerIsStopped(); | 316 VerifyTimerIsStopped(); |
303 } | 317 } |
304 | 318 |
305 TEST_F(RecommendationRestorerTest, RestoreOnRecommendationChangeInUserSession) { | 319 TEST_F(RecommendationRestorerTest, RestoreOnRecommendationChangeInUserSession) { |
306 // Verifies that if recommended values change while a user session is in | 320 // Verifies that if recommended values change while a user session is in |
307 // progress, user settings are cleared immediately. | 321 // progress, user settings are cleared immediately. |
| 322 RegisterLoginProfilePrefs(); |
308 SetUserSettings(); | 323 SetUserSettings(); |
309 | 324 |
310 CreateLoginProfile(); | 325 CreateLoginProfile(); |
311 NotifyOfSessionStart(); | 326 NotifyOfSessionStart(); |
312 | 327 |
313 VerifyPrefFollowsUser(prefs::kLargeCursorEnabled, | 328 VerifyPrefFollowsUser(prefs::kLargeCursorEnabled, |
314 base::FundamentalValue(true)); | 329 base::FundamentalValue(true)); |
315 recommended_prefs_->SetBoolean(prefs::kLargeCursorEnabled, false); | 330 recommended_prefs_->SetBoolean(prefs::kLargeCursorEnabled, false); |
316 VerifyTimerIsStopped(); | 331 VerifyTimerIsStopped(); |
317 VerifyPrefFollowsRecommendation(prefs::kLargeCursorEnabled, | 332 VerifyPrefFollowsRecommendation(prefs::kLargeCursorEnabled, |
(...skipping 23 matching lines...) Expand all Loading... |
341 VerifyPrefFollowsRecommendation(prefs::kScreenMagnifierEnabled, | 356 VerifyPrefFollowsRecommendation(prefs::kScreenMagnifierEnabled, |
342 base::FundamentalValue(false)); | 357 base::FundamentalValue(false)); |
343 VerifyPrefFollowsRecommendation(prefs::kScreenMagnifierType, | 358 VerifyPrefFollowsRecommendation(prefs::kScreenMagnifierType, |
344 base::FundamentalValue(0)); | 359 base::FundamentalValue(0)); |
345 } | 360 } |
346 | 361 |
347 TEST_F(RecommendationRestorerTest, DoNothingOnUserChange) { | 362 TEST_F(RecommendationRestorerTest, DoNothingOnUserChange) { |
348 // Verifies that if no recommended values have been set and user settings | 363 // Verifies that if no recommended values have been set and user settings |
349 // change, the user settings are not cleared immediately and no timer is | 364 // change, the user settings are not cleared immediately and no timer is |
350 // started that will clear the user settings eventually. | 365 // started that will clear the user settings eventually. |
| 366 RegisterLoginProfilePrefs(); |
351 CreateLoginProfile(); | 367 CreateLoginProfile(); |
352 | 368 |
353 prefs_->SetBoolean(prefs::kLargeCursorEnabled, true); | 369 prefs_->SetBoolean(prefs::kLargeCursorEnabled, true); |
354 VerifyPrefFollowsUser(prefs::kLargeCursorEnabled, | 370 VerifyPrefFollowsUser(prefs::kLargeCursorEnabled, |
355 base::FundamentalValue(true)); | 371 base::FundamentalValue(true)); |
356 VerifyTimerIsStopped(); | 372 VerifyTimerIsStopped(); |
357 | 373 |
358 prefs_->SetBoolean(prefs::kSpokenFeedbackEnabled, true); | 374 prefs_->SetBoolean(prefs::kSpokenFeedbackEnabled, true); |
359 VerifyPrefFollowsUser(prefs::kSpokenFeedbackEnabled, | 375 VerifyPrefFollowsUser(prefs::kSpokenFeedbackEnabled, |
360 base::FundamentalValue(true)); | 376 base::FundamentalValue(true)); |
(...skipping 15 matching lines...) Expand all Loading... |
376 base::FundamentalValue(true)); | 392 base::FundamentalValue(true)); |
377 VerifyPrefFollowsUser(prefs::kScreenMagnifierType, | 393 VerifyPrefFollowsUser(prefs::kScreenMagnifierType, |
378 base::FundamentalValue(ash::MAGNIFIER_FULL)); | 394 base::FundamentalValue(ash::MAGNIFIER_FULL)); |
379 VerifyTimerIsStopped(); | 395 VerifyTimerIsStopped(); |
380 } | 396 } |
381 | 397 |
382 TEST_F(RecommendationRestorerTest, RestoreOnUserChange) { | 398 TEST_F(RecommendationRestorerTest, RestoreOnUserChange) { |
383 // Verifies that if recommended values have been set and user settings change | 399 // Verifies that if recommended values have been set and user settings change |
384 // while the login screen is being shown, a timer is started that will clear | 400 // while the login screen is being shown, a timer is started that will clear |
385 // the user settings eventually. | 401 // the user settings eventually. |
| 402 RegisterLoginProfilePrefs(); |
386 SetRecommendedValues(); | 403 SetRecommendedValues(); |
387 | 404 |
388 CreateLoginProfile(); | 405 CreateLoginProfile(); |
389 | 406 |
390 VerifyTimerIsStopped(); | 407 VerifyTimerIsStopped(); |
391 prefs_->SetBoolean(prefs::kLargeCursorEnabled, true); | 408 prefs_->SetBoolean(prefs::kLargeCursorEnabled, true); |
392 VerifyPrefFollowsUser(prefs::kLargeCursorEnabled, | 409 VerifyPrefFollowsUser(prefs::kLargeCursorEnabled, |
393 base::FundamentalValue(true)); | 410 base::FundamentalValue(true)); |
394 VerifyTimerIsRunning(); | 411 VerifyTimerIsRunning(); |
395 runner_->RunUntilIdle(); | 412 runner_->RunUntilIdle(); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
429 base::FundamentalValue(0)); | 446 base::FundamentalValue(0)); |
430 | 447 |
431 VerifyTimerIsStopped(); | 448 VerifyTimerIsStopped(); |
432 } | 449 } |
433 | 450 |
434 TEST_F(RecommendationRestorerTest, RestoreOnSessionStart) { | 451 TEST_F(RecommendationRestorerTest, RestoreOnSessionStart) { |
435 // Verifies that if recommended values have been set, user settings have | 452 // Verifies that if recommended values have been set, user settings have |
436 // changed and a session is then started, the user settings are cleared | 453 // changed and a session is then started, the user settings are cleared |
437 // immediately and the timer that would have cleared them eventually on the | 454 // immediately and the timer that would have cleared them eventually on the |
438 // login screen is stopped. | 455 // login screen is stopped. |
| 456 RegisterLoginProfilePrefs(); |
439 SetRecommendedValues(); | 457 SetRecommendedValues(); |
440 | 458 |
441 CreateLoginProfile(); | 459 CreateLoginProfile(); |
442 SetUserSettings(); | 460 SetUserSettings(); |
443 | 461 |
444 NotifyOfSessionStart(); | 462 NotifyOfSessionStart(); |
445 VerifyPrefsFollowRecommendations(); | 463 VerifyPrefsFollowRecommendations(); |
446 VerifyTimerIsStopped(); | 464 VerifyTimerIsStopped(); |
447 } | 465 } |
448 | 466 |
449 TEST_F(RecommendationRestorerTest, DoNothingOnSessionStart) { | 467 TEST_F(RecommendationRestorerTest, DoNothingOnSessionStart) { |
450 // Verifies that if recommended values have not been set, user settings have | 468 // Verifies that if recommended values have not been set, user settings have |
451 // changed and a session is then started, the user settings are not cleared | 469 // changed and a session is then started, the user settings are not cleared |
452 // immediately. | 470 // immediately. |
| 471 RegisterLoginProfilePrefs(); |
453 CreateLoginProfile(); | 472 CreateLoginProfile(); |
454 SetUserSettings(); | 473 SetUserSettings(); |
455 | 474 |
456 NotifyOfSessionStart(); | 475 NotifyOfSessionStart(); |
457 VerifyPrefsFollowUser(); | 476 VerifyPrefsFollowUser(); |
458 VerifyTimerIsStopped(); | 477 VerifyTimerIsStopped(); |
459 } | 478 } |
460 | 479 |
461 TEST_F(RecommendationRestorerTest, UserActivityResetsTimer) { | 480 TEST_F(RecommendationRestorerTest, UserActivityResetsTimer) { |
462 // Verifies that user activity resets the timer which clears user settings. | 481 // Verifies that user activity resets the timer which clears user settings. |
| 482 RegisterLoginProfilePrefs(); |
| 483 |
463 recommended_prefs_->SetBoolean(prefs::kLargeCursorEnabled, false); | 484 recommended_prefs_->SetBoolean(prefs::kLargeCursorEnabled, false); |
464 | 485 |
465 CreateLoginProfile(); | 486 CreateLoginProfile(); |
466 | 487 |
467 prefs_->SetBoolean(prefs::kLargeCursorEnabled, true); | 488 prefs_->SetBoolean(prefs::kLargeCursorEnabled, true); |
468 VerifyTimerIsRunning(); | 489 VerifyTimerIsRunning(); |
469 | 490 |
470 // Notify that there is user activity, then fast forward until the originally | 491 // Notify that there is user activity, then fast forward until the originally |
471 // set timer fires. | 492 // set timer fires. |
472 NotifyOfUserActivity(); | 493 NotifyOfUserActivity(); |
473 runner_->RunPendingTasks(); | 494 runner_->RunPendingTasks(); |
474 VerifyPrefFollowsUser(prefs::kLargeCursorEnabled, | 495 VerifyPrefFollowsUser(prefs::kLargeCursorEnabled, |
475 base::FundamentalValue(true)); | 496 base::FundamentalValue(true)); |
476 | 497 |
477 // Fast forward until the reset timer fires. | 498 // Fast forward until the reset timer fires. |
478 VerifyTimerIsRunning(); | 499 VerifyTimerIsRunning(); |
479 runner_->RunUntilIdle(); | 500 runner_->RunUntilIdle(); |
480 VerifyPrefFollowsRecommendation(prefs::kLargeCursorEnabled, | 501 VerifyPrefFollowsRecommendation(prefs::kLargeCursorEnabled, |
481 base::FundamentalValue(false)); | 502 base::FundamentalValue(false)); |
482 VerifyTimerIsStopped(); | 503 VerifyTimerIsStopped(); |
483 } | 504 } |
484 | 505 |
485 } // namespace policy | 506 } // namespace policy |
OLD | NEW |