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