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