OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
6 #include "base/compiler_specific.h" | 6 #include "base/compiler_specific.h" |
7 #include "base/prefs/pref_service.h" | 7 #include "base/prefs/pref_service.h" |
8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
9 #include "chrome/browser/chromeos/login/login_manager_test.h" | 9 #include "chrome/browser/chromeos/login/login_manager_test.h" |
10 #include "chrome/browser/chromeos/login/startup_utils.h" | 10 #include "chrome/browser/chromeos/login/startup_utils.h" |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 { kStatsReportingPref, true, true }, | 79 { kStatsReportingPref, true, true }, |
80 { prefs::kSpellCheckUseSpellingService, false, false }, | 80 { prefs::kSpellCheckUseSpellingService, false, false }, |
81 #endif | 81 #endif |
82 }; | 82 }; |
83 | 83 |
84 } // namespace | 84 } // namespace |
85 | 85 |
86 class SharedOptionsTest : public LoginManagerTest { | 86 class SharedOptionsTest : public LoginManagerTest { |
87 public: | 87 public: |
88 SharedOptionsTest() | 88 SharedOptionsTest() |
89 : LoginManagerTest(false), | 89 : LoginManagerTest(false), |
90 device_settings_provider_(NULL), | 90 device_settings_provider_(NULL) { |
91 test_owner_account_id_(AccountId::FromUserEmail(kTestOwner)), | |
92 test_non_owner_account_id_(AccountId::FromUserEmail(kTestNonOwner)) { | |
93 stub_settings_provider_.Set(kDeviceOwner, base::StringValue(kTestOwner)); | 91 stub_settings_provider_.Set(kDeviceOwner, base::StringValue(kTestOwner)); |
94 } | 92 } |
95 | 93 |
96 ~SharedOptionsTest() override {} | 94 ~SharedOptionsTest() override {} |
97 | 95 |
98 void SetUpOnMainThread() override { | 96 void SetUpOnMainThread() override { |
99 LoginManagerTest::SetUpOnMainThread(); | 97 LoginManagerTest::SetUpOnMainThread(); |
100 | 98 |
101 CrosSettings* settings = CrosSettings::Get(); | 99 CrosSettings* settings = CrosSettings::Get(); |
102 | 100 |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 !is_owner); | 259 !is_owner); |
262 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( | 260 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( |
263 contents, js_expression, &success)); | 261 contents, js_expression, &success)); |
264 EXPECT_TRUE(success) << "Accounts overlay incorrect for " << | 262 EXPECT_TRUE(success) << "Accounts overlay incorrect for " << |
265 (is_owner ? "owner." : "non-owner."); | 263 (is_owner ? "owner." : "non-owner."); |
266 } | 264 } |
267 | 265 |
268 StubAccountSettingsProvider stub_settings_provider_; | 266 StubAccountSettingsProvider stub_settings_provider_; |
269 CrosSettingsProvider* device_settings_provider_; | 267 CrosSettingsProvider* device_settings_provider_; |
270 | 268 |
271 const AccountId test_owner_account_id_; | |
272 const AccountId test_non_owner_account_id_; | |
273 | |
274 private: | 269 private: |
275 DISALLOW_COPY_AND_ASSIGN(SharedOptionsTest); | 270 DISALLOW_COPY_AND_ASSIGN(SharedOptionsTest); |
276 }; | 271 }; |
277 | 272 |
278 IN_PROC_BROWSER_TEST_F(SharedOptionsTest, PRE_SharedOptions) { | 273 IN_PROC_BROWSER_TEST_F(SharedOptionsTest, PRE_SharedOptions) { |
279 RegisterUser(test_owner_account_id_.GetUserEmail()); | 274 RegisterUser(kTestOwner); |
280 RegisterUser(test_non_owner_account_id_.GetUserEmail()); | 275 RegisterUser(kTestNonOwner); |
281 StartupUtils::MarkOobeCompleted(); | 276 StartupUtils::MarkOobeCompleted(); |
282 } | 277 } |
283 | 278 |
284 IN_PROC_BROWSER_TEST_F(SharedOptionsTest, SharedOptions) { | 279 IN_PROC_BROWSER_TEST_F(SharedOptionsTest, SharedOptions) { |
285 // Log in the owner first, then add a secondary user. | 280 // Log in the owner first, then add a secondary user. |
286 LoginUser(test_owner_account_id_.GetUserEmail()); | 281 LoginUser(kTestOwner); |
287 UserAddingScreen::Get()->Start(); | 282 UserAddingScreen::Get()->Start(); |
288 content::RunAllPendingInMessageLoop(); | 283 content::RunAllPendingInMessageLoop(); |
289 AddUser(test_non_owner_account_id_.GetUserEmail()); | 284 AddUser(kTestNonOwner); |
290 | 285 |
291 user_manager::UserManager* manager = user_manager::UserManager::Get(); | 286 user_manager::UserManager* manager = user_manager::UserManager::Get(); |
292 ASSERT_EQ(2u, manager->GetLoggedInUsers().size()); | 287 ASSERT_EQ(2u, manager->GetLoggedInUsers().size()); |
293 { | 288 { |
294 SCOPED_TRACE("Checking settings for owner, primary user."); | 289 SCOPED_TRACE("Checking settings for owner, primary user."); |
295 CheckOptionsUI(manager->FindUser(manager->GetOwnerAccountId()), true, true); | 290 CheckOptionsUI(manager->FindUser(manager->GetOwnerEmail()), true, true); |
296 } | 291 } |
297 { | 292 { |
298 SCOPED_TRACE("Checking settings for non-owner, secondary user."); | 293 SCOPED_TRACE("Checking settings for non-owner, secondary user."); |
299 CheckOptionsUI(manager->FindUser(test_non_owner_account_id_), false, false); | 294 CheckOptionsUI(manager->FindUser(kTestNonOwner), false, false); |
300 } | 295 } |
301 // TODO(michaelpg): Add tests for non-primary owner and primary non-owner | 296 // TODO(michaelpg): Add tests for non-primary owner and primary non-owner |
302 // when the owner-only multiprofile restriction is removed, probably M38. | 297 // when the owner-only multiprofile restriction is removed, probably M38. |
303 } | 298 } |
304 | 299 |
305 IN_PROC_BROWSER_TEST_F(SharedOptionsTest, PRE_ScreenLockPreferencePrimary) { | 300 IN_PROC_BROWSER_TEST_F(SharedOptionsTest, PRE_ScreenLockPreferencePrimary) { |
306 RegisterUser(test_owner_account_id_.GetUserEmail()); | 301 RegisterUser(kTestOwner); |
307 RegisterUser(test_non_owner_account_id_.GetUserEmail()); | 302 RegisterUser(kTestNonOwner); |
308 StartupUtils::MarkOobeCompleted(); | 303 StartupUtils::MarkOobeCompleted(); |
309 } | 304 } |
310 | 305 |
311 // Tests the shared setting indicator for the primary user's auto-lock setting | 306 // Tests the shared setting indicator for the primary user's auto-lock setting |
312 // when the secondary user has enabled or disabled their preference. | 307 // when the secondary user has enabled or disabled their preference. |
313 // (The checkbox is unset if the current user's preference is false, but if any | 308 // (The checkbox is unset if the current user's preference is false, but if any |
314 // other signed-in user has enabled this preference, the shared setting | 309 // other signed-in user has enabled this preference, the shared setting |
315 // indicator explains this.) | 310 // indicator explains this.) |
316 IN_PROC_BROWSER_TEST_F(SharedOptionsTest, ScreenLockPreferencePrimary) { | 311 IN_PROC_BROWSER_TEST_F(SharedOptionsTest, ScreenLockPreferencePrimary) { |
317 LoginUser(test_owner_account_id_.GetUserEmail()); | 312 LoginUser(kTestOwner); |
318 UserAddingScreen::Get()->Start(); | 313 UserAddingScreen::Get()->Start(); |
319 content::RunAllPendingInMessageLoop(); | 314 content::RunAllPendingInMessageLoop(); |
320 AddUser(test_non_owner_account_id_.GetUserEmail()); | 315 AddUser(kTestNonOwner); |
321 | 316 |
322 user_manager::UserManager* manager = user_manager::UserManager::Get(); | 317 user_manager::UserManager* manager = user_manager::UserManager::Get(); |
323 const user_manager::User* user1 = manager->FindUser(test_owner_account_id_); | 318 const user_manager::User* user1 = manager->FindUser(kTestOwner); |
324 const user_manager::User* user2 = | 319 const user_manager::User* user2 = manager->FindUser(kTestNonOwner); |
325 manager->FindUser(test_non_owner_account_id_); | |
326 | 320 |
327 PrefService* prefs1 = | 321 PrefService* prefs1 = |
328 ProfileHelper::Get()->GetProfileByUserUnsafe(user1)->GetPrefs(); | 322 ProfileHelper::Get()->GetProfileByUserUnsafe(user1)->GetPrefs(); |
329 PrefService* prefs2 = | 323 PrefService* prefs2 = |
330 ProfileHelper::Get()->GetProfileByUserUnsafe(user2)->GetPrefs(); | 324 ProfileHelper::Get()->GetProfileByUserUnsafe(user2)->GetPrefs(); |
331 | 325 |
332 // Set both users' preference to false, then change the secondary user's to | 326 // Set both users' preference to false, then change the secondary user's to |
333 // true. We'll do the opposite in the next test. Doesn't provide 100% coverage | 327 // true. We'll do the opposite in the next test. Doesn't provide 100% coverage |
334 // but reloading the settings page is super slow on debug builds. | 328 // but reloading the settings page is super slow on debug builds. |
335 prefs1->SetBoolean(prefs::kEnableAutoScreenLock, false); | 329 prefs1->SetBoolean(prefs::kEnableAutoScreenLock, false); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
368 prefs1->SetBoolean(prefs::kEnableAutoScreenLock, true); | 362 prefs1->SetBoolean(prefs::kEnableAutoScreenLock, true); |
369 { | 363 { |
370 SCOPED_TRACE("Screen lock true for both users"); | 364 SCOPED_TRACE("Screen lock true for both users"); |
371 expected_value = true; | 365 expected_value = true; |
372 CheckBooleanPreference(contents, prefs::kEnableAutoScreenLock, disabled, | 366 CheckBooleanPreference(contents, prefs::kEnableAutoScreenLock, disabled, |
373 empty_controlled, expected_value); | 367 empty_controlled, expected_value); |
374 } | 368 } |
375 } | 369 } |
376 | 370 |
377 IN_PROC_BROWSER_TEST_F(SharedOptionsTest, PRE_ScreenLockPreferenceSecondary) { | 371 IN_PROC_BROWSER_TEST_F(SharedOptionsTest, PRE_ScreenLockPreferenceSecondary) { |
378 RegisterUser(test_owner_account_id_.GetUserEmail()); | 372 RegisterUser(kTestOwner); |
379 RegisterUser(test_non_owner_account_id_.GetUserEmail()); | 373 RegisterUser(kTestNonOwner); |
380 StartupUtils::MarkOobeCompleted(); | 374 StartupUtils::MarkOobeCompleted(); |
381 } | 375 } |
382 | 376 |
383 // Tests the shared setting indicator for the secondary user's auto-lock setting | 377 // Tests the shared setting indicator for the secondary user's auto-lock setting |
384 // when the primary user has enabled or disabled their preference. | 378 // when the primary user has enabled or disabled their preference. |
385 // (The checkbox is unset if the current user's preference is false, but if any | 379 // (The checkbox is unset if the current user's preference is false, but if any |
386 // other signed-in user has enabled this preference, the shared setting | 380 // other signed-in user has enabled this preference, the shared setting |
387 // indicator explains this.) | 381 // indicator explains this.) |
388 IN_PROC_BROWSER_TEST_F(SharedOptionsTest, ScreenLockPreferenceSecondary) { | 382 IN_PROC_BROWSER_TEST_F(SharedOptionsTest, ScreenLockPreferenceSecondary) { |
389 LoginUser(test_owner_account_id_.GetUserEmail()); | 383 LoginUser(kTestOwner); |
390 UserAddingScreen::Get()->Start(); | 384 UserAddingScreen::Get()->Start(); |
391 content::RunAllPendingInMessageLoop(); | 385 content::RunAllPendingInMessageLoop(); |
392 AddUser(test_non_owner_account_id_.GetUserEmail()); | 386 AddUser(kTestNonOwner); |
393 | 387 |
394 user_manager::UserManager* manager = user_manager::UserManager::Get(); | 388 user_manager::UserManager* manager = user_manager::UserManager::Get(); |
395 const user_manager::User* user1 = manager->FindUser(test_owner_account_id_); | 389 const user_manager::User* user1 = manager->FindUser(kTestOwner); |
396 const user_manager::User* user2 = | 390 const user_manager::User* user2 = manager->FindUser(kTestNonOwner); |
397 manager->FindUser(test_non_owner_account_id_); | |
398 | 391 |
399 PrefService* prefs1 = | 392 PrefService* prefs1 = |
400 ProfileHelper::Get()->GetProfileByUserUnsafe(user1)->GetPrefs(); | 393 ProfileHelper::Get()->GetProfileByUserUnsafe(user1)->GetPrefs(); |
401 PrefService* prefs2 = | 394 PrefService* prefs2 = |
402 ProfileHelper::Get()->GetProfileByUserUnsafe(user2)->GetPrefs(); | 395 ProfileHelper::Get()->GetProfileByUserUnsafe(user2)->GetPrefs(); |
403 | 396 |
404 // Set both users' preference to true, then change the secondary user's to | 397 // Set both users' preference to true, then change the secondary user's to |
405 // false. | 398 // false. |
406 prefs1->SetBoolean(prefs::kEnableAutoScreenLock, true); | 399 prefs1->SetBoolean(prefs::kEnableAutoScreenLock, true); |
407 prefs2->SetBoolean(prefs::kEnableAutoScreenLock, true); | 400 prefs2->SetBoolean(prefs::kEnableAutoScreenLock, true); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
439 content::WaitForLoadStop(contents); | 432 content::WaitForLoadStop(contents); |
440 { | 433 { |
441 SCOPED_TRACE("Screen lock false for both users"); | 434 SCOPED_TRACE("Screen lock false for both users"); |
442 expected_value = false; | 435 expected_value = false; |
443 CheckBooleanPreference(contents, prefs::kEnableAutoScreenLock, disabled, | 436 CheckBooleanPreference(contents, prefs::kEnableAutoScreenLock, disabled, |
444 empty_controlled, expected_value); | 437 empty_controlled, expected_value); |
445 } | 438 } |
446 } | 439 } |
447 | 440 |
448 } // namespace chromeos | 441 } // namespace chromeos |
OLD | NEW |