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 3// found in the LICENSE file. 4 5#include "chrome/browser/chromeos/policy/recommendation_restorer.h" 6 7#include "ash/magnifier/magnifier_constants.h" 8#include "base/memory/scoped_ptr.h" 9#include "base/prefs/pref_notifier_impl.h" 10#include "base/prefs/testing_pref_store.h" 11#include "base/strings/utf_string_conversions.h" 12#include "base/test/test_simple_task_runner.h" 13#include "base/thread_task_runner_handle.h" 14#include "base/time/time.h" 15#include "base/values.h" 16#include "chrome/browser/chrome_notification_types.h" 17#include "chrome/browser/chromeos/policy/recommendation_restorer_factory.h" 18#include "chrome/browser/prefs/browser_prefs.h" 19#include "chrome/browser/prefs/pref_service_syncable.h" 20#include "chrome/common/chrome_constants.h" 21#include "chrome/common/pref_names.h" 22#include "chrome/test/base/testing_browser_process.h" 23#include "chrome/test/base/testing_pref_service_syncable.h" 24#include "chrome/test/base/testing_profile.h" 25#include "chrome/test/base/testing_profile_manager.h" 26#include "components/pref_registry/pref_registry_syncable.h" 27#include "content/public/browser/notification_details.h" 28#include "content/public/browser/notification_service.h" 29#include "content/public/browser/notification_source.h" 30#include "testing/gtest/include/gtest/gtest.h" 31 32namespace policy { 33 34namespace { 35 // The amount of idle time after which recommended values are restored. 36 const int kRestoreDelayInMs = 60 * 1000; // 1 minute. 37} // namespace 38 39class RecommendationRestorerTest : public testing::Test { 40 protected: 41 RecommendationRestorerTest(); 42 43 // testing::Test: 44 virtual void SetUp() OVERRIDE; 45 46 void RegisterUserProfilePrefs(); 47 void RegisterLoginProfilePrefs(); 48 49 void SetRecommendedValues(); 50 void SetUserSettings(); 51 52 void CreateLoginProfile(); 53 void CreateUserProfile(); 54 55 void NotifyOfSessionStart(); 56 void NotifyOfUserActivity(); 57 58 void VerifyPrefFollowsUser(const char* pref_name, 59 const base::Value& expected_value) const; 60 void VerifyPrefsFollowUser() const; 61 void VerifyPrefFollowsRecommendation(const char* pref_name, 62 const base::Value& expected_value) const; 63 void VerifyPrefsFollowRecommendations() const; 64 65 void VerifyNotListeningForNotifications() const; 66 void VerifyTimerIsStopped() const; 67 void VerifyTimerIsRunning() const; 68 69 TestingPrefStore* recommended_prefs_; // Not owned. 70 TestingPrefServiceSyncable* prefs_; // Not owned. 71 RecommendationRestorer* restorer_; // Not owned. 72 73 scoped_refptr<base::TestSimpleTaskRunner> runner_; 74 base::ThreadTaskRunnerHandle runner_handler_; 75 76 private: 77 scoped_ptr<PrefServiceSyncable> prefs_owner_; 78 79 TestingProfileManager profile_manager_; 80 81 DISALLOW_COPY_AND_ASSIGN(RecommendationRestorerTest); 82}; 83 84RecommendationRestorerTest::RecommendationRestorerTest() 85 : recommended_prefs_(new TestingPrefStore), 86 prefs_(new TestingPrefServiceSyncable( 87 new TestingPrefStore, 88 new TestingPrefStore, 89 recommended_prefs_, 90 new user_prefs::PrefRegistrySyncable, 91 new PrefNotifierImpl)), 92 restorer_(NULL), 93 runner_(new base::TestSimpleTaskRunner), 94 runner_handler_(runner_), 95 prefs_owner_(prefs_), 96 profile_manager_(TestingBrowserProcess::GetGlobal()) { 97} 98 99void RecommendationRestorerTest::SetUp() { 100 testing::Test::SetUp(); 101 ASSERT_TRUE(profile_manager_.SetUp()); 102} 103 104void RecommendationRestorerTest::RegisterUserProfilePrefs() { 105 chrome::RegisterUserProfilePrefs(prefs_->registry()); 106} 107 108void RecommendationRestorerTest::RegisterLoginProfilePrefs() { 109 chrome::RegisterLoginProfilePrefs(prefs_->registry()); 110} 111 112void RecommendationRestorerTest::SetRecommendedValues() { 113 recommended_prefs_->SetBoolean(prefs::kAccessibilityLargeCursorEnabled, 114 false); 115 recommended_prefs_->SetBoolean(prefs::kAccessibilitySpokenFeedbackEnabled, 116 false); 117 recommended_prefs_->SetBoolean(prefs::kAccessibilityHighContrastEnabled, 118 false); 119 recommended_prefs_->SetBoolean(prefs::kAccessibilityScreenMagnifierEnabled, 120 false); 121 recommended_prefs_->SetInteger(prefs::kAccessibilityScreenMagnifierType, 0); 122 recommended_prefs_->SetBoolean(prefs::kAccessibilityVirtualKeyboardEnabled, 123 false); 124} 125 126void RecommendationRestorerTest::SetUserSettings() { 127 prefs_->SetBoolean(prefs::kAccessibilityLargeCursorEnabled, true); 128 prefs_->SetBoolean(prefs::kAccessibilitySpokenFeedbackEnabled, true); 129 prefs_->SetBoolean(prefs::kAccessibilityHighContrastEnabled, true); 130 prefs_->SetBoolean(prefs::kAccessibilityScreenMagnifierEnabled, true); 131 prefs_->SetInteger(prefs::kAccessibilityScreenMagnifierType, 132 ash::MAGNIFIER_FULL); 133 prefs_->SetBoolean(prefs::kAccessibilityVirtualKeyboardEnabled, true); 134} 135 136void RecommendationRestorerTest::CreateLoginProfile() { 137 ASSERT_FALSE(restorer_); 138 TestingProfile* profile = profile_manager_.CreateTestingProfile( 139 chrome::kInitialProfile, prefs_owner_.Pass(), 140 base::UTF8ToUTF16(chrome::kInitialProfile), 0, std::string(), 141 TestingProfile::TestingFactories()); 142 restorer_ = RecommendationRestorerFactory::GetForProfile(profile); 143 EXPECT_TRUE(restorer_); 144} 145 146void RecommendationRestorerTest::CreateUserProfile() { 147 ASSERT_FALSE(restorer_); 148 TestingProfile* profile = profile_manager_.CreateTestingProfile( 149 "user", prefs_owner_.Pass(), base::UTF8ToUTF16("user"), 0, std::string(), 150 TestingProfile::TestingFactories()); 151 restorer_ = RecommendationRestorerFactory::GetForProfile(profile); 152 EXPECT_TRUE(restorer_); 153} 154 155void RecommendationRestorerTest::NotifyOfSessionStart() { 156 ASSERT_TRUE(restorer_); 157 restorer_->Observe(chrome::NOTIFICATION_LOGIN_USER_CHANGED, 158 content::Source<RecommendationRestorerTest>(this), 159 content::NotificationService::NoDetails()); 160} 161 162void RecommendationRestorerTest::NotifyOfUserActivity() { 163 ASSERT_TRUE(restorer_); 164 restorer_->OnUserActivity(NULL); 165} 166 167void RecommendationRestorerTest::VerifyPrefFollowsUser( 168 const char* pref_name, 169 const base::Value& expected_value) const { 170 const PrefServiceSyncable::Preference* pref = 171 prefs_->FindPreference(pref_name); 172 ASSERT_TRUE(pref); 173 EXPECT_TRUE(pref->HasUserSetting()); 174 const base::Value* value = pref->GetValue(); 175 ASSERT_TRUE(value); 176 EXPECT_TRUE(expected_value.Equals(value)); 177} 178 179void RecommendationRestorerTest::VerifyPrefsFollowUser() const { 180 VerifyPrefFollowsUser(prefs::kAccessibilityLargeCursorEnabled, 181 base::FundamentalValue(true)); 182 VerifyPrefFollowsUser(prefs::kAccessibilitySpokenFeedbackEnabled, 183 base::FundamentalValue(true)); 184 VerifyPrefFollowsUser(prefs::kAccessibilityHighContrastEnabled, 185 base::FundamentalValue(true)); 186 VerifyPrefFollowsUser(prefs::kAccessibilityScreenMagnifierEnabled, 187 base::FundamentalValue(true)); 188 VerifyPrefFollowsUser(prefs::kAccessibilityScreenMagnifierType, 189 base::FundamentalValue(ash::MAGNIFIER_FULL)); 190 VerifyPrefFollowsUser(prefs::kAccessibilityVirtualKeyboardEnabled, 191 base::FundamentalValue(true)); 192} 193 194void RecommendationRestorerTest::VerifyPrefFollowsRecommendation( 195 const char* pref_name, 196 const base::Value& expected_value) const { 197 const PrefServiceSyncable::Preference* pref = 198 prefs_->FindPreference(pref_name); 199 ASSERT_TRUE(pref); 200 EXPECT_TRUE(pref->IsRecommended()); 201 EXPECT_FALSE(pref->HasUserSetting()); 202 const base::Value* value = pref->GetValue(); 203 ASSERT_TRUE(value); 204 EXPECT_TRUE(expected_value.Equals(value)); 205} 206 207void RecommendationRestorerTest::VerifyPrefsFollowRecommendations() const { 208 VerifyPrefFollowsRecommendation(prefs::kAccessibilityLargeCursorEnabled, 209 base::FundamentalValue(false)); 210 VerifyPrefFollowsRecommendation(prefs::kAccessibilitySpokenFeedbackEnabled, 211 base::FundamentalValue(false)); 212 VerifyPrefFollowsRecommendation(prefs::kAccessibilityHighContrastEnabled, 213 base::FundamentalValue(false)); 214 VerifyPrefFollowsRecommendation(prefs::kAccessibilityScreenMagnifierEnabled, 215 base::FundamentalValue(false)); 216 VerifyPrefFollowsRecommendation(prefs::kAccessibilityScreenMagnifierType, 217 base::FundamentalValue(0)); 218 VerifyPrefFollowsRecommendation(prefs::kAccessibilityVirtualKeyboardEnabled, 219 base::FundamentalValue(false)); 220} 221 222void RecommendationRestorerTest::VerifyNotListeningForNotifications() const { 223 ASSERT_TRUE(restorer_); 224 EXPECT_TRUE(restorer_->pref_change_registrar_.IsEmpty()); 225 EXPECT_TRUE(restorer_->notification_registrar_.IsEmpty()); 226} 227 228void RecommendationRestorerTest::VerifyTimerIsStopped() const { 229 ASSERT_TRUE(restorer_); 230 EXPECT_FALSE(restorer_->restore_timer_.IsRunning()); 231} 232 233void RecommendationRestorerTest::VerifyTimerIsRunning() const { 234 ASSERT_TRUE(restorer_); 235 EXPECT_TRUE(restorer_->restore_timer_.IsRunning()); 236 EXPECT_EQ(base::TimeDelta::FromMilliseconds(kRestoreDelayInMs), 237 restorer_->restore_timer_.GetCurrentDelay()); 238} 239 240TEST_F(RecommendationRestorerTest, CreateForUserProfile) { 241 // Verifies that when a RecommendationRestorer is created for a user profile, 242 // it does not start listening for any notifications, does not clear user 243 // settings on initialization and does not start a timer that will clear user 244 // settings eventually. 245 RegisterUserProfilePrefs(); 246 SetRecommendedValues(); 247 SetUserSettings(); 248 249 CreateUserProfile(); 250 VerifyNotListeningForNotifications(); 251 VerifyPrefsFollowUser(); 252 VerifyTimerIsStopped(); 253} 254 255TEST_F(RecommendationRestorerTest, NoRecommendations) { 256 // Verifies that when no recommended values have been set and a 257 // RecommendationRestorer is created for the login profile, it does not clear 258 // user settings on initialization and does not start a timer that will clear 259 // user settings eventually. 260 RegisterLoginProfilePrefs(); 261 SetUserSettings(); 262 263 CreateLoginProfile(); 264 VerifyPrefsFollowUser(); 265 VerifyTimerIsStopped(); 266} 267 268TEST_F(RecommendationRestorerTest, RestoreOnStartup) { 269 // Verifies that when recommended values have been set and a 270 // RecommendationRestorer is created for the login profile, it clears user 271 // settings on initialization. 272 RegisterLoginProfilePrefs(); 273 SetRecommendedValues(); 274 SetUserSettings(); 275 276 CreateLoginProfile(); 277 VerifyPrefsFollowRecommendations(); 278 VerifyTimerIsStopped(); 279} 280 281TEST_F(RecommendationRestorerTest, RestoreOnRecommendationChangeOnLoginScreen) { 282 // Verifies that if recommended values change while the login screen is being 283 // shown, a timer is started that will clear user settings eventually. 284 RegisterLoginProfilePrefs(); 285 SetUserSettings(); 286 287 CreateLoginProfile(); 288 289 VerifyTimerIsStopped(); 290 recommended_prefs_->SetBoolean(prefs::kAccessibilityLargeCursorEnabled, 291 false); 292 VerifyPrefFollowsUser(prefs::kAccessibilityLargeCursorEnabled, 293 base::FundamentalValue(true)); 294 VerifyTimerIsRunning(); 295 runner_->RunUntilIdle(); 296 VerifyPrefFollowsRecommendation(prefs::kAccessibilityLargeCursorEnabled, 297 base::FundamentalValue(false)); 298 299 VerifyTimerIsStopped(); 300 recommended_prefs_->SetBoolean(prefs::kAccessibilitySpokenFeedbackEnabled, 301 false); 302 VerifyPrefFollowsUser(prefs::kAccessibilitySpokenFeedbackEnabled, 303 base::FundamentalValue(true)); 304 VerifyTimerIsRunning(); 305 runner_->RunUntilIdle(); 306 VerifyPrefFollowsRecommendation(prefs::kAccessibilitySpokenFeedbackEnabled, 307 base::FundamentalValue(false)); 308 309 VerifyTimerIsStopped(); 310 recommended_prefs_->SetBoolean(prefs::kAccessibilityHighContrastEnabled, 311 false); 312 VerifyPrefFollowsUser(prefs::kAccessibilityHighContrastEnabled, 313 base::FundamentalValue(true)); 314 VerifyTimerIsRunning(); 315 runner_->RunUntilIdle(); 316 VerifyPrefFollowsRecommendation(prefs::kAccessibilityHighContrastEnabled, 317 base::FundamentalValue(false)); 318 319 VerifyTimerIsStopped(); 320 recommended_prefs_->SetBoolean(prefs::kAccessibilityScreenMagnifierEnabled, 321 false); 322 recommended_prefs_->SetInteger(prefs::kAccessibilityScreenMagnifierType, 0); 323 VerifyPrefFollowsUser(prefs::kAccessibilityScreenMagnifierEnabled, 324 base::FundamentalValue(true)); 325 VerifyPrefFollowsUser(prefs::kAccessibilityScreenMagnifierType, 326 base::FundamentalValue(ash::MAGNIFIER_FULL)); 327 VerifyTimerIsRunning(); 328 runner_->RunUntilIdle(); 329 VerifyPrefFollowsRecommendation(prefs::kAccessibilityScreenMagnifierEnabled, 330 base::FundamentalValue(false)); 331 VerifyPrefFollowsRecommendation(prefs::kAccessibilityScreenMagnifierType, 332 base::FundamentalValue(0)); 333 VerifyTimerIsStopped(); 334 recommended_prefs_->SetBoolean(prefs::kAccessibilityVirtualKeyboardEnabled, 335 false); 336 VerifyPrefFollowsUser(prefs::kAccessibilityVirtualKeyboardEnabled, 337 base::FundamentalValue(true)); 338 VerifyTimerIsRunning(); 339 runner_->RunUntilIdle(); 340 VerifyPrefFollowsRecommendation(prefs::kAccessibilityVirtualKeyboardEnabled, 341 base::FundamentalValue(false)); 342 VerifyTimerIsStopped(); 343} 344 345TEST_F(RecommendationRestorerTest, RestoreOnRecommendationChangeInUserSession) { 346 // Verifies that if recommended values change while a user session is in 347 // progress, user settings are cleared immediately. 348 RegisterLoginProfilePrefs(); 349 SetUserSettings(); 350 351 CreateLoginProfile(); 352 NotifyOfSessionStart(); 353 354 VerifyPrefFollowsUser(prefs::kAccessibilityLargeCursorEnabled, 355 base::FundamentalValue(true)); 356 recommended_prefs_->SetBoolean(prefs::kAccessibilityLargeCursorEnabled, 357 false); 358 VerifyTimerIsStopped(); 359 VerifyPrefFollowsRecommendation(prefs::kAccessibilityLargeCursorEnabled, 360 base::FundamentalValue(false)); 361 362 VerifyPrefFollowsUser(prefs::kAccessibilitySpokenFeedbackEnabled, 363 base::FundamentalValue(true)); 364 recommended_prefs_->SetBoolean(prefs::kAccessibilitySpokenFeedbackEnabled, 365 false); 366 VerifyTimerIsStopped(); 367 VerifyPrefFollowsRecommendation(prefs::kAccessibilitySpokenFeedbackEnabled, 368 base::FundamentalValue(false)); 369 370 VerifyPrefFollowsUser(prefs::kAccessibilityHighContrastEnabled, 371 base::FundamentalValue(true)); 372 recommended_prefs_->SetBoolean(prefs::kAccessibilityHighContrastEnabled, 373 false); 374 VerifyTimerIsStopped(); 375 VerifyPrefFollowsRecommendation(prefs::kAccessibilityHighContrastEnabled, 376 base::FundamentalValue(false)); 377 378 VerifyPrefFollowsUser(prefs::kAccessibilityScreenMagnifierEnabled, 379 base::FundamentalValue(true)); 380 VerifyPrefFollowsUser(prefs::kAccessibilityScreenMagnifierType, 381 base::FundamentalValue(ash::MAGNIFIER_FULL)); 382 recommended_prefs_->SetBoolean(prefs::kAccessibilityScreenMagnifierEnabled, 383 false); 384 recommended_prefs_->SetInteger(prefs::kAccessibilityScreenMagnifierType, 0); 385 VerifyTimerIsStopped(); 386 VerifyPrefFollowsRecommendation(prefs::kAccessibilityScreenMagnifierEnabled, 387 base::FundamentalValue(false)); 388 VerifyPrefFollowsRecommendation(prefs::kAccessibilityScreenMagnifierType, 389 base::FundamentalValue(0)); 390 391 VerifyPrefFollowsUser(prefs::kAccessibilityVirtualKeyboardEnabled, 392 base::FundamentalValue(true)); 393 recommended_prefs_->SetBoolean(prefs::kAccessibilityVirtualKeyboardEnabled, 394 false); 395 VerifyTimerIsStopped(); 396 VerifyPrefFollowsRecommendation(prefs::kAccessibilityVirtualKeyboardEnabled, 397 base::FundamentalValue(false)); 398} 399 400TEST_F(RecommendationRestorerTest, DoNothingOnUserChange) { 401 // Verifies that if no recommended values have been set and user settings 402 // change, the user settings are not cleared immediately and no timer is 403 // started that will clear the user settings eventually. 404 RegisterLoginProfilePrefs(); 405 CreateLoginProfile(); 406 407 prefs_->SetBoolean(prefs::kAccessibilityLargeCursorEnabled, true); 408 VerifyPrefFollowsUser(prefs::kAccessibilityLargeCursorEnabled, 409 base::FundamentalValue(true)); 410 VerifyTimerIsStopped(); 411 412 prefs_->SetBoolean(prefs::kAccessibilitySpokenFeedbackEnabled, true); 413 VerifyPrefFollowsUser(prefs::kAccessibilitySpokenFeedbackEnabled, 414 base::FundamentalValue(true)); 415 VerifyTimerIsStopped(); 416 417 prefs_->SetBoolean(prefs::kAccessibilityHighContrastEnabled, true); 418 VerifyPrefFollowsUser(prefs::kAccessibilityHighContrastEnabled, 419 base::FundamentalValue(true)); 420 VerifyTimerIsStopped(); 421 422 prefs_->SetBoolean(prefs::kAccessibilityScreenMagnifierEnabled, true); 423 VerifyPrefFollowsUser(prefs::kAccessibilityScreenMagnifierEnabled, 424 base::FundamentalValue(true)); 425 VerifyTimerIsStopped(); 426 427 prefs_->SetBoolean(prefs::kAccessibilityScreenMagnifierEnabled, true); 428 prefs_->SetInteger(prefs::kAccessibilityScreenMagnifierType, 429 ash::MAGNIFIER_FULL); 430 VerifyPrefFollowsUser(prefs::kAccessibilityScreenMagnifierEnabled, 431 base::FundamentalValue(true)); 432 VerifyPrefFollowsUser(prefs::kAccessibilityScreenMagnifierType, 433 base::FundamentalValue(ash::MAGNIFIER_FULL)); 434 VerifyTimerIsStopped(); 435 436 prefs_->SetBoolean(prefs::kAccessibilityVirtualKeyboardEnabled, true); 437 VerifyPrefFollowsUser(prefs::kAccessibilityVirtualKeyboardEnabled, 438 base::FundamentalValue(true)); 439 VerifyTimerIsStopped(); 440} 441 442TEST_F(RecommendationRestorerTest, RestoreOnUserChange) { 443 // Verifies that if recommended values have been set and user settings change 444 // while the login screen is being shown, a timer is started that will clear 445 // the user settings eventually. 446 RegisterLoginProfilePrefs(); 447 SetRecommendedValues(); 448 449 CreateLoginProfile(); 450 451 VerifyTimerIsStopped(); 452 prefs_->SetBoolean(prefs::kAccessibilityLargeCursorEnabled, true); 453 VerifyPrefFollowsUser(prefs::kAccessibilityLargeCursorEnabled, 454 base::FundamentalValue(true)); 455 VerifyTimerIsRunning(); 456 runner_->RunUntilIdle(); 457 VerifyPrefFollowsRecommendation(prefs::kAccessibilityLargeCursorEnabled, 458 base::FundamentalValue(false)); 459 460 VerifyTimerIsStopped(); 461 prefs_->SetBoolean(prefs::kAccessibilitySpokenFeedbackEnabled, true); 462 VerifyPrefFollowsUser(prefs::kAccessibilitySpokenFeedbackEnabled, 463 base::FundamentalValue(true)); 464 VerifyTimerIsRunning(); 465 runner_->RunUntilIdle(); 466 VerifyPrefFollowsRecommendation(prefs::kAccessibilitySpokenFeedbackEnabled, 467 base::FundamentalValue(false)); 468 469 VerifyTimerIsStopped(); 470 prefs_->SetBoolean(prefs::kAccessibilityHighContrastEnabled, true); 471 VerifyPrefFollowsUser(prefs::kAccessibilityHighContrastEnabled, 472 base::FundamentalValue(true)); 473 VerifyTimerIsRunning(); 474 runner_->RunUntilIdle(); 475 VerifyPrefFollowsRecommendation(prefs::kAccessibilityHighContrastEnabled, 476 base::FundamentalValue(false)); 477 478 VerifyTimerIsStopped(); 479 prefs_->SetBoolean(prefs::kAccessibilityScreenMagnifierEnabled, true); 480 prefs_->SetInteger(prefs::kAccessibilityScreenMagnifierType, 481 ash::MAGNIFIER_FULL); 482 VerifyPrefFollowsUser(prefs::kAccessibilityScreenMagnifierEnabled, 483 base::FundamentalValue(true)); 484 VerifyPrefFollowsUser(prefs::kAccessibilityScreenMagnifierType, 485 base::FundamentalValue(ash::MAGNIFIER_FULL)); 486 VerifyTimerIsRunning(); 487 runner_->RunUntilIdle(); 488 VerifyPrefFollowsRecommendation(prefs::kAccessibilityScreenMagnifierEnabled, 489 base::FundamentalValue(false)); 490 VerifyPrefFollowsRecommendation(prefs::kAccessibilityScreenMagnifierType, 491 base::FundamentalValue(0)); 492 493 VerifyTimerIsStopped(); 494 prefs_->SetBoolean(prefs::kAccessibilityVirtualKeyboardEnabled, true); 495 VerifyPrefFollowsUser(prefs::kAccessibilityVirtualKeyboardEnabled, 496 base::FundamentalValue(true)); 497 VerifyTimerIsRunning(); 498 runner_->RunUntilIdle(); 499 VerifyPrefFollowsRecommendation(prefs::kAccessibilityVirtualKeyboardEnabled, 500 base::FundamentalValue(false)); 501 502 VerifyTimerIsStopped(); 503} 504 505TEST_F(RecommendationRestorerTest, RestoreOnSessionStart) { 506 // Verifies that if recommended values have been set, user settings have 507 // changed and a session is then started, the user settings are cleared 508 // immediately and the timer that would have cleared them eventually on the 509 // login screen is stopped. 510 RegisterLoginProfilePrefs(); 511 SetRecommendedValues(); 512 513 CreateLoginProfile(); 514 SetUserSettings(); 515 516 NotifyOfSessionStart(); 517 VerifyPrefsFollowRecommendations(); 518 VerifyTimerIsStopped(); 519} 520 521TEST_F(RecommendationRestorerTest, DoNothingOnSessionStart) { 522 // Verifies that if recommended values have not been set, user settings have 523 // changed and a session is then started, the user settings are not cleared 524 // immediately. 525 RegisterLoginProfilePrefs(); 526 CreateLoginProfile(); 527 SetUserSettings(); 528 529 NotifyOfSessionStart(); 530 VerifyPrefsFollowUser(); 531 VerifyTimerIsStopped(); 532} 533 534TEST_F(RecommendationRestorerTest, UserActivityResetsTimer) { 535 // Verifies that user activity resets the timer which clears user settings. 536 RegisterLoginProfilePrefs(); 537 538 recommended_prefs_->SetBoolean(prefs::kAccessibilityLargeCursorEnabled, 539 false); 540 541 CreateLoginProfile(); 542 543 prefs_->SetBoolean(prefs::kAccessibilityLargeCursorEnabled, true); 544 VerifyTimerIsRunning(); 545 546 // Notify that there is user activity, then fast forward until the originally 547 // set timer fires. 548 NotifyOfUserActivity(); 549 runner_->RunPendingTasks(); 550 VerifyPrefFollowsUser(prefs::kAccessibilityLargeCursorEnabled, 551 base::FundamentalValue(true)); 552 553 // Fast forward until the reset timer fires. 554 VerifyTimerIsRunning(); 555 runner_->RunUntilIdle(); 556 VerifyPrefFollowsRecommendation(prefs::kAccessibilityLargeCursorEnabled, 557 base::FundamentalValue(false)); 558 VerifyTimerIsStopped(); 559} 560 561} // namespace policy 562