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

Side by Side Diff: chrome/browser/chromeos/policy/recommendation_restorer_unittest.cc

Issue 155573003: Add policy management for on-screen keyboard. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Update recommendation restorer. Created 6 years, 10 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 | Annotate | Revision Log
OLDNEW
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 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 void RecommendationRestorerTest::RegisterLoginProfilePrefs() { 108 void RecommendationRestorerTest::RegisterLoginProfilePrefs() {
109 chrome::RegisterLoginProfilePrefs(prefs_->registry()); 109 chrome::RegisterLoginProfilePrefs(prefs_->registry());
110 } 110 }
111 111
112 void RecommendationRestorerTest::SetRecommendedValues() { 112 void RecommendationRestorerTest::SetRecommendedValues() {
113 recommended_prefs_->SetBoolean(prefs::kLargeCursorEnabled, false); 113 recommended_prefs_->SetBoolean(prefs::kLargeCursorEnabled, false);
114 recommended_prefs_->SetBoolean(prefs::kSpokenFeedbackEnabled, false); 114 recommended_prefs_->SetBoolean(prefs::kSpokenFeedbackEnabled, false);
115 recommended_prefs_->SetBoolean(prefs::kHighContrastEnabled, false); 115 recommended_prefs_->SetBoolean(prefs::kHighContrastEnabled, false);
116 recommended_prefs_->SetBoolean(prefs::kScreenMagnifierEnabled, false); 116 recommended_prefs_->SetBoolean(prefs::kScreenMagnifierEnabled, false);
117 recommended_prefs_->SetInteger(prefs::kScreenMagnifierType, 0); 117 recommended_prefs_->SetInteger(prefs::kScreenMagnifierType, 0);
118 recommended_prefs_->SetBoolean(prefs::kVirtualKeyboardEnabled, false);
118 } 119 }
119 120
120 void RecommendationRestorerTest::SetUserSettings() { 121 void RecommendationRestorerTest::SetUserSettings() {
121 prefs_->SetBoolean(prefs::kLargeCursorEnabled, true); 122 prefs_->SetBoolean(prefs::kLargeCursorEnabled, true);
122 prefs_->SetBoolean(prefs::kSpokenFeedbackEnabled, true); 123 prefs_->SetBoolean(prefs::kSpokenFeedbackEnabled, true);
123 prefs_->SetBoolean(prefs::kHighContrastEnabled, true); 124 prefs_->SetBoolean(prefs::kHighContrastEnabled, true);
124 prefs_->SetBoolean(prefs::kScreenMagnifierEnabled, true); 125 prefs_->SetBoolean(prefs::kScreenMagnifierEnabled, true);
125 prefs_->SetInteger(prefs::kScreenMagnifierType, ash::MAGNIFIER_FULL); 126 prefs_->SetInteger(prefs::kScreenMagnifierType, ash::MAGNIFIER_FULL);
127 prefs_->SetBoolean(prefs::kVirtualKeyboardEnabled, true);
126 } 128 }
127 129
128 void RecommendationRestorerTest::CreateLoginProfile() { 130 void RecommendationRestorerTest::CreateLoginProfile() {
129 ASSERT_FALSE(restorer_); 131 ASSERT_FALSE(restorer_);
130 TestingProfile* profile = profile_manager_.CreateTestingProfile( 132 TestingProfile* profile = profile_manager_.CreateTestingProfile(
131 chrome::kInitialProfile, prefs_owner_.Pass(), 133 chrome::kInitialProfile, prefs_owner_.Pass(),
132 base::UTF8ToUTF16(chrome::kInitialProfile), 0, std::string(), 134 base::UTF8ToUTF16(chrome::kInitialProfile), 0, std::string(),
133 TestingProfile::TestingFactories()); 135 TestingProfile::TestingFactories());
134 restorer_ = RecommendationRestorerFactory::GetForProfile(profile); 136 restorer_ = RecommendationRestorerFactory::GetForProfile(profile);
135 EXPECT_TRUE(restorer_); 137 EXPECT_TRUE(restorer_);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 VerifyPrefFollowsUser(prefs::kLargeCursorEnabled, 174 VerifyPrefFollowsUser(prefs::kLargeCursorEnabled,
173 base::FundamentalValue(true)); 175 base::FundamentalValue(true));
174 VerifyPrefFollowsUser(prefs::kSpokenFeedbackEnabled, 176 VerifyPrefFollowsUser(prefs::kSpokenFeedbackEnabled,
175 base::FundamentalValue(true)); 177 base::FundamentalValue(true));
176 VerifyPrefFollowsUser(prefs::kHighContrastEnabled, 178 VerifyPrefFollowsUser(prefs::kHighContrastEnabled,
177 base::FundamentalValue(true)); 179 base::FundamentalValue(true));
178 VerifyPrefFollowsUser(prefs::kScreenMagnifierEnabled, 180 VerifyPrefFollowsUser(prefs::kScreenMagnifierEnabled,
179 base::FundamentalValue(true)); 181 base::FundamentalValue(true));
180 VerifyPrefFollowsUser(prefs::kScreenMagnifierType, 182 VerifyPrefFollowsUser(prefs::kScreenMagnifierType,
181 base::FundamentalValue(ash::MAGNIFIER_FULL)); 183 base::FundamentalValue(ash::MAGNIFIER_FULL));
184 VerifyPrefFollowsUser(prefs::kVirtualKeyboardEnabled,
185 base::FundamentalValue(true));
182 } 186 }
183 187
184 void RecommendationRestorerTest::VerifyPrefFollowsRecommendation( 188 void RecommendationRestorerTest::VerifyPrefFollowsRecommendation(
185 const char* pref_name, 189 const char* pref_name,
186 const base::Value& expected_value) const { 190 const base::Value& expected_value) const {
187 const PrefServiceSyncable::Preference* pref = 191 const PrefServiceSyncable::Preference* pref =
188 prefs_->FindPreference(pref_name); 192 prefs_->FindPreference(pref_name);
189 ASSERT_TRUE(pref); 193 ASSERT_TRUE(pref);
190 EXPECT_TRUE(pref->IsRecommended()); 194 EXPECT_TRUE(pref->IsRecommended());
191 EXPECT_FALSE(pref->HasUserSetting()); 195 EXPECT_FALSE(pref->HasUserSetting());
192 const base::Value* value = pref->GetValue(); 196 const base::Value* value = pref->GetValue();
193 ASSERT_TRUE(value); 197 ASSERT_TRUE(value);
194 EXPECT_TRUE(expected_value.Equals(value)); 198 EXPECT_TRUE(expected_value.Equals(value));
195 } 199 }
196 200
197 void RecommendationRestorerTest::VerifyPrefsFollowRecommendations() const { 201 void RecommendationRestorerTest::VerifyPrefsFollowRecommendations() const {
198 VerifyPrefFollowsRecommendation(prefs::kLargeCursorEnabled, 202 VerifyPrefFollowsRecommendation(prefs::kLargeCursorEnabled,
199 base::FundamentalValue(false)); 203 base::FundamentalValue(false));
200 VerifyPrefFollowsRecommendation(prefs::kSpokenFeedbackEnabled, 204 VerifyPrefFollowsRecommendation(prefs::kSpokenFeedbackEnabled,
201 base::FundamentalValue(false)); 205 base::FundamentalValue(false));
202 VerifyPrefFollowsRecommendation(prefs::kHighContrastEnabled, 206 VerifyPrefFollowsRecommendation(prefs::kHighContrastEnabled,
203 base::FundamentalValue(false)); 207 base::FundamentalValue(false));
204 VerifyPrefFollowsRecommendation(prefs::kScreenMagnifierEnabled, 208 VerifyPrefFollowsRecommendation(prefs::kScreenMagnifierEnabled,
205 base::FundamentalValue(false)); 209 base::FundamentalValue(false));
206 VerifyPrefFollowsRecommendation(prefs::kScreenMagnifierType, 210 VerifyPrefFollowsRecommendation(prefs::kScreenMagnifierType,
207 base::FundamentalValue(0)); 211 base::FundamentalValue(0));
212 VerifyPrefFollowsRecommendation(prefs::kVirtualKeyboardEnabled,
213 base::FundamentalValue(false));
208 } 214 }
209 215
210 void RecommendationRestorerTest::VerifyNotListeningForNotifications() const { 216 void RecommendationRestorerTest::VerifyNotListeningForNotifications() const {
211 ASSERT_TRUE(restorer_); 217 ASSERT_TRUE(restorer_);
212 EXPECT_TRUE(restorer_->pref_change_registrar_.IsEmpty()); 218 EXPECT_TRUE(restorer_->pref_change_registrar_.IsEmpty());
213 EXPECT_TRUE(restorer_->notification_registrar_.IsEmpty()); 219 EXPECT_TRUE(restorer_->notification_registrar_.IsEmpty());
214 } 220 }
215 221
216 void RecommendationRestorerTest::VerifyTimerIsStopped() const { 222 void RecommendationRestorerTest::VerifyTimerIsStopped() const {
217 ASSERT_TRUE(restorer_); 223 ASSERT_TRUE(restorer_);
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 VerifyPrefFollowsUser(prefs::kScreenMagnifierEnabled, 313 VerifyPrefFollowsUser(prefs::kScreenMagnifierEnabled,
308 base::FundamentalValue(true)); 314 base::FundamentalValue(true));
309 VerifyPrefFollowsUser(prefs::kScreenMagnifierType, 315 VerifyPrefFollowsUser(prefs::kScreenMagnifierType,
310 base::FundamentalValue(ash::MAGNIFIER_FULL)); 316 base::FundamentalValue(ash::MAGNIFIER_FULL));
311 VerifyTimerIsRunning(); 317 VerifyTimerIsRunning();
312 runner_->RunUntilIdle(); 318 runner_->RunUntilIdle();
313 VerifyPrefFollowsRecommendation(prefs::kScreenMagnifierEnabled, 319 VerifyPrefFollowsRecommendation(prefs::kScreenMagnifierEnabled,
314 base::FundamentalValue(false)); 320 base::FundamentalValue(false));
315 VerifyPrefFollowsRecommendation(prefs::kScreenMagnifierType, 321 VerifyPrefFollowsRecommendation(prefs::kScreenMagnifierType,
316 base::FundamentalValue(0)); 322 base::FundamentalValue(0));
317 323 VerifyTimerIsStopped();
324 recommended_prefs_->SetBoolean(prefs::kVirtualKeyboardEnabled, false);
325 VerifyPrefFollowsUser(prefs::kVirtualKeyboardEnabled,
326 base::FundamentalValue(true));
327 VerifyTimerIsRunning();
328 runner_->RunUntilIdle();
329 VerifyPrefFollowsRecommendation(prefs::kVirtualKeyboardEnabled,
330 base::FundamentalValue(false));
318 VerifyTimerIsStopped(); 331 VerifyTimerIsStopped();
319 } 332 }
320 333
321 TEST_F(RecommendationRestorerTest, RestoreOnRecommendationChangeInUserSession) { 334 TEST_F(RecommendationRestorerTest, RestoreOnRecommendationChangeInUserSession) {
322 // Verifies that if recommended values change while a user session is in 335 // Verifies that if recommended values change while a user session is in
323 // progress, user settings are cleared immediately. 336 // progress, user settings are cleared immediately.
324 RegisterLoginProfilePrefs(); 337 RegisterLoginProfilePrefs();
325 SetUserSettings(); 338 SetUserSettings();
326 339
327 CreateLoginProfile(); 340 CreateLoginProfile();
(...skipping 24 matching lines...) Expand all
352 base::FundamentalValue(true)); 365 base::FundamentalValue(true));
353 VerifyPrefFollowsUser(prefs::kScreenMagnifierType, 366 VerifyPrefFollowsUser(prefs::kScreenMagnifierType,
354 base::FundamentalValue(ash::MAGNIFIER_FULL)); 367 base::FundamentalValue(ash::MAGNIFIER_FULL));
355 recommended_prefs_->SetBoolean(prefs::kScreenMagnifierEnabled, false); 368 recommended_prefs_->SetBoolean(prefs::kScreenMagnifierEnabled, false);
356 recommended_prefs_->SetInteger(prefs::kScreenMagnifierType, 0); 369 recommended_prefs_->SetInteger(prefs::kScreenMagnifierType, 0);
357 VerifyTimerIsStopped(); 370 VerifyTimerIsStopped();
358 VerifyPrefFollowsRecommendation(prefs::kScreenMagnifierEnabled, 371 VerifyPrefFollowsRecommendation(prefs::kScreenMagnifierEnabled,
359 base::FundamentalValue(false)); 372 base::FundamentalValue(false));
360 VerifyPrefFollowsRecommendation(prefs::kScreenMagnifierType, 373 VerifyPrefFollowsRecommendation(prefs::kScreenMagnifierType,
361 base::FundamentalValue(0)); 374 base::FundamentalValue(0));
375
376 VerifyPrefFollowsUser(prefs::kVirtualKeyboardEnabled,
377 base::FundamentalValue(true));
378 recommended_prefs_->SetBoolean(prefs::kVirtualKeyboardEnabled, false);
379 VerifyTimerIsStopped();
380 VerifyPrefFollowsRecommendation(prefs::kVirtualKeyboardEnabled,
381 base::FundamentalValue(false));
362 } 382 }
363 383
364 TEST_F(RecommendationRestorerTest, DoNothingOnUserChange) { 384 TEST_F(RecommendationRestorerTest, DoNothingOnUserChange) {
365 // Verifies that if no recommended values have been set and user settings 385 // Verifies that if no recommended values have been set and user settings
366 // change, the user settings are not cleared immediately and no timer is 386 // change, the user settings are not cleared immediately and no timer is
367 // started that will clear the user settings eventually. 387 // started that will clear the user settings eventually.
368 RegisterLoginProfilePrefs(); 388 RegisterLoginProfilePrefs();
369 CreateLoginProfile(); 389 CreateLoginProfile();
370 390
371 prefs_->SetBoolean(prefs::kLargeCursorEnabled, true); 391 prefs_->SetBoolean(prefs::kLargeCursorEnabled, true);
(...skipping 16 matching lines...) Expand all
388 base::FundamentalValue(true)); 408 base::FundamentalValue(true));
389 VerifyTimerIsStopped(); 409 VerifyTimerIsStopped();
390 410
391 prefs_->SetBoolean(prefs::kScreenMagnifierEnabled, true); 411 prefs_->SetBoolean(prefs::kScreenMagnifierEnabled, true);
392 prefs_->SetInteger(prefs::kScreenMagnifierType, ash::MAGNIFIER_FULL); 412 prefs_->SetInteger(prefs::kScreenMagnifierType, ash::MAGNIFIER_FULL);
393 VerifyPrefFollowsUser(prefs::kScreenMagnifierEnabled, 413 VerifyPrefFollowsUser(prefs::kScreenMagnifierEnabled,
394 base::FundamentalValue(true)); 414 base::FundamentalValue(true));
395 VerifyPrefFollowsUser(prefs::kScreenMagnifierType, 415 VerifyPrefFollowsUser(prefs::kScreenMagnifierType,
396 base::FundamentalValue(ash::MAGNIFIER_FULL)); 416 base::FundamentalValue(ash::MAGNIFIER_FULL));
397 VerifyTimerIsStopped(); 417 VerifyTimerIsStopped();
418
419 prefs_->SetBoolean(prefs::kVirtualKeyboardEnabled, true);
420 VerifyPrefFollowsUser(prefs::kVirtualKeyboardEnabled,
421 base::FundamentalValue(true));
422 VerifyTimerIsStopped();
398 } 423 }
399 424
400 TEST_F(RecommendationRestorerTest, RestoreOnUserChange) { 425 TEST_F(RecommendationRestorerTest, RestoreOnUserChange) {
401 // Verifies that if recommended values have been set and user settings change 426 // Verifies that if recommended values have been set and user settings change
402 // while the login screen is being shown, a timer is started that will clear 427 // while the login screen is being shown, a timer is started that will clear
403 // the user settings eventually. 428 // the user settings eventually.
404 RegisterLoginProfilePrefs(); 429 RegisterLoginProfilePrefs();
405 SetRecommendedValues(); 430 SetRecommendedValues();
406 431
407 CreateLoginProfile(); 432 CreateLoginProfile();
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
441 VerifyPrefFollowsUser(prefs::kScreenMagnifierType, 466 VerifyPrefFollowsUser(prefs::kScreenMagnifierType,
442 base::FundamentalValue(ash::MAGNIFIER_FULL)); 467 base::FundamentalValue(ash::MAGNIFIER_FULL));
443 VerifyTimerIsRunning(); 468 VerifyTimerIsRunning();
444 runner_->RunUntilIdle(); 469 runner_->RunUntilIdle();
445 VerifyPrefFollowsRecommendation(prefs::kScreenMagnifierEnabled, 470 VerifyPrefFollowsRecommendation(prefs::kScreenMagnifierEnabled,
446 base::FundamentalValue(false)); 471 base::FundamentalValue(false));
447 VerifyPrefFollowsRecommendation(prefs::kScreenMagnifierType, 472 VerifyPrefFollowsRecommendation(prefs::kScreenMagnifierType,
448 base::FundamentalValue(0)); 473 base::FundamentalValue(0));
449 474
450 VerifyTimerIsStopped(); 475 VerifyTimerIsStopped();
476 prefs_->SetBoolean(prefs::kVirtualKeyboardEnabled, true);
477 VerifyPrefFollowsUser(prefs::kVirtualKeyboardEnabled,
478 base::FundamentalValue(true));
479 VerifyTimerIsRunning();
480 runner_->RunUntilIdle();
481 VerifyPrefFollowsRecommendation(prefs::kVirtualKeyboardEnabled,
482 base::FundamentalValue(false));
483
484 VerifyTimerIsStopped();
451 } 485 }
452 486
453 TEST_F(RecommendationRestorerTest, RestoreOnSessionStart) { 487 TEST_F(RecommendationRestorerTest, RestoreOnSessionStart) {
454 // Verifies that if recommended values have been set, user settings have 488 // Verifies that if recommended values have been set, user settings have
455 // changed and a session is then started, the user settings are cleared 489 // changed and a session is then started, the user settings are cleared
456 // immediately and the timer that would have cleared them eventually on the 490 // immediately and the timer that would have cleared them eventually on the
457 // login screen is stopped. 491 // login screen is stopped.
458 RegisterLoginProfilePrefs(); 492 RegisterLoginProfilePrefs();
459 SetRecommendedValues(); 493 SetRecommendedValues();
460 494
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
499 533
500 // Fast forward until the reset timer fires. 534 // Fast forward until the reset timer fires.
501 VerifyTimerIsRunning(); 535 VerifyTimerIsRunning();
502 runner_->RunUntilIdle(); 536 runner_->RunUntilIdle();
503 VerifyPrefFollowsRecommendation(prefs::kLargeCursorEnabled, 537 VerifyPrefFollowsRecommendation(prefs::kLargeCursorEnabled,
504 base::FundamentalValue(false)); 538 base::FundamentalValue(false));
505 VerifyTimerIsStopped(); 539 VerifyTimerIsStopped();
506 } 540 }
507 541
508 } // namespace policy 542 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698