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 <queue> | 5 #include <queue> |
6 #include <utility> | 6 #include <utility> |
7 | 7 |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
9 #include "base/memory/linked_ptr.h" | 9 #include "base/memory/linked_ptr.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
12 #include "base/test/scoped_path_override.h" | 12 #include "base/test/scoped_path_override.h" |
13 #include "base/values.h" | 13 #include "base/values.h" |
14 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos.h" | 14 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos.h" |
15 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos_fact
ory.h" | 15 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos_fact
ory.h" |
| 16 #include "chrome/browser/chromeos/settings/cros_settings.h" |
16 #include "chrome/browser/chromeos/settings/device_settings_provider.h" | 17 #include "chrome/browser/chromeos/settings/device_settings_provider.h" |
17 #include "chrome/browser/chromeos/settings/device_settings_test_helper.h" | 18 #include "chrome/browser/chromeos/settings/device_settings_test_helper.h" |
18 #include "chrome/common/chrome_paths.h" | 19 #include "chrome/common/chrome_paths.h" |
19 #include "chrome/test/base/scoped_testing_local_state.h" | 20 #include "chrome/test/base/scoped_testing_local_state.h" |
20 #include "chrome/test/base/testing_browser_process.h" | 21 #include "chrome/test/base/testing_browser_process.h" |
21 #include "chrome/test/base/testing_profile.h" | 22 #include "chrome/test/base/testing_profile.h" |
22 #include "chromeos/settings/cros_settings_names.h" | 23 #include "chromeos/settings/cros_settings_names.h" |
23 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
24 | 25 |
25 namespace em = enterprise_management; | 26 namespace em = enterprise_management; |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 class OwnerSettingsServiceChromeOSTest : public DeviceSettingsTestBase { | 84 class OwnerSettingsServiceChromeOSTest : public DeviceSettingsTestBase { |
84 public: | 85 public: |
85 OwnerSettingsServiceChromeOSTest() | 86 OwnerSettingsServiceChromeOSTest() |
86 : service_(nullptr), | 87 : service_(nullptr), |
87 local_state_(TestingBrowserProcess::GetGlobal()), | 88 local_state_(TestingBrowserProcess::GetGlobal()), |
88 user_data_dir_override_(chrome::DIR_USER_DATA), | 89 user_data_dir_override_(chrome::DIR_USER_DATA), |
89 management_settings_set_(false) {} | 90 management_settings_set_(false) {} |
90 | 91 |
91 void SetUp() override { | 92 void SetUp() override { |
92 DeviceSettingsTestBase::SetUp(); | 93 DeviceSettingsTestBase::SetUp(); |
| 94 |
93 provider_.reset(new DeviceSettingsProvider(base::Bind(&OnPrefChanged), | 95 provider_.reset(new DeviceSettingsProvider(base::Bind(&OnPrefChanged), |
94 &device_settings_service_)); | 96 &device_settings_service_)); |
95 owner_key_util_->SetPrivateKey(device_policy_.GetSigningKey()); | 97 owner_key_util_->SetPrivateKey(device_policy_.GetSigningKey()); |
96 InitOwner(device_policy_.policy_data().username(), true); | 98 InitOwner(device_policy_.policy_data().username(), true); |
97 FlushDeviceSettings(); | 99 FlushDeviceSettings(); |
98 | 100 |
99 service_ = OwnerSettingsServiceChromeOSFactory::GetForBrowserContext( | 101 service_ = OwnerSettingsServiceChromeOSFactory::GetForBrowserContext( |
100 profile_.get()); | 102 profile_.get()); |
101 ASSERT_TRUE(service_); | 103 ASSERT_TRUE(service_); |
102 ASSERT_TRUE(service_->IsOwner()); | 104 ASSERT_TRUE(service_->IsOwner()); |
103 | 105 |
104 device_policy_.policy_data().set_management_mode( | 106 device_policy_.policy_data().set_management_mode( |
105 em::PolicyData::LOCAL_OWNER); | 107 em::PolicyData::LOCAL_OWNER); |
106 device_policy_.Build(); | 108 device_policy_.Build(); |
107 device_settings_test_helper_.set_policy_blob(device_policy_.GetBlob()); | 109 device_settings_test_helper_.set_policy_blob(device_policy_.GetBlob()); |
108 ReloadDeviceSettings(); | 110 ReloadDeviceSettings(); |
109 } | 111 } |
110 | 112 |
111 void TearDown() override { DeviceSettingsTestBase::TearDown(); } | 113 void TearDown() override { |
| 114 DeviceSettingsTestBase::TearDown(); |
| 115 } |
112 | 116 |
113 void TestSingleSet(OwnerSettingsServiceChromeOS* service, | 117 void TestSingleSet(OwnerSettingsServiceChromeOS* service, |
114 const std::string& setting, | 118 const std::string& setting, |
115 const base::Value& in_value) { | 119 const base::Value& in_value) { |
116 PrefsChecker checker(service, provider_.get()); | 120 PrefsChecker checker(service, provider_.get()); |
117 checker.Set(setting, in_value); | 121 checker.Set(setting, in_value); |
118 FlushDeviceSettings(); | 122 FlushDeviceSettings(); |
119 checker.Wait(); | 123 checker.Wait(); |
120 } | 124 } |
121 | 125 |
122 void OnManagementSettingsSet(bool success) { | 126 void OnManagementSettingsSet(bool success) { |
123 management_settings_set_ = success; | 127 management_settings_set_ = success; |
124 } | 128 } |
125 | 129 |
| 130 protected: |
126 OwnerSettingsServiceChromeOS* service_; | 131 OwnerSettingsServiceChromeOS* service_; |
127 ScopedTestingLocalState local_state_; | 132 ScopedTestingLocalState local_state_; |
128 scoped_ptr<DeviceSettingsProvider> provider_; | 133 scoped_ptr<DeviceSettingsProvider> provider_; |
129 base::ScopedPathOverride user_data_dir_override_; | 134 base::ScopedPathOverride user_data_dir_override_; |
130 bool management_settings_set_; | 135 bool management_settings_set_; |
131 | 136 |
132 private: | 137 private: |
133 DISALLOW_COPY_AND_ASSIGN(OwnerSettingsServiceChromeOSTest); | 138 DISALLOW_COPY_AND_ASSIGN(OwnerSettingsServiceChromeOSTest); |
134 }; | 139 }; |
135 | 140 |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 void TearDown() override { DeviceSettingsTestBase::TearDown(); } | 319 void TearDown() override { DeviceSettingsTestBase::TearDown(); } |
315 | 320 |
316 private: | 321 private: |
317 DISALLOW_COPY_AND_ASSIGN(OwnerSettingsServiceChromeOSNoOwnerTest); | 322 DISALLOW_COPY_AND_ASSIGN(OwnerSettingsServiceChromeOSNoOwnerTest); |
318 }; | 323 }; |
319 | 324 |
320 TEST_F(OwnerSettingsServiceChromeOSNoOwnerTest, SingleSetTest) { | 325 TEST_F(OwnerSettingsServiceChromeOSNoOwnerTest, SingleSetTest) { |
321 ASSERT_FALSE(service_->SetBoolean(kAccountsPrefAllowGuest, false)); | 326 ASSERT_FALSE(service_->SetBoolean(kAccountsPrefAllowGuest, false)); |
322 } | 327 } |
323 | 328 |
| 329 class OwnerSettingsServiceChromeOSTakeOwnerTest |
| 330 : public OwnerSettingsServiceChromeOSTest { |
| 331 public: |
| 332 OwnerSettingsServiceChromeOSTakeOwnerTest() {} |
| 333 ~OwnerSettingsServiceChromeOSTakeOwnerTest() override {} |
| 334 |
| 335 void SetUp() override { |
| 336 DeviceSettingsTestBase::SetUp(); |
| 337 |
| 338 owner_key_util_->SetPrivateKey(device_policy_.GetSigningKey()); |
| 339 InitOwner(device_policy_.policy_data().username(), false); |
| 340 FlushDeviceSettings(); |
| 341 |
| 342 service_ = OwnerSettingsServiceChromeOSFactory::GetForBrowserContext( |
| 343 profile_.get()); |
| 344 ASSERT_TRUE(service_); |
| 345 ASSERT_FALSE(service_->IsOwner()); |
| 346 |
| 347 device_policy_.policy_data().set_management_mode( |
| 348 em::PolicyData::LOCAL_OWNER); |
| 349 device_policy_.Build(); |
| 350 device_settings_test_helper_.set_policy_blob(device_policy_.GetBlob()); |
| 351 ReloadDeviceSettings(); |
| 352 } |
| 353 |
| 354 private: |
| 355 DISALLOW_COPY_AND_ASSIGN(OwnerSettingsServiceChromeOSTakeOwnerTest); |
| 356 }; |
| 357 |
| 358 TEST_F(OwnerSettingsServiceChromeOSTakeOwnerTest, SingleSetTest) { |
| 359 bool wildcard_match = false; |
| 360 EXPECT_FALSE( |
| 361 cros_settings_.FindEmailInList(kAccountsPrefUsers, |
| 362 device_policy_.policy_data().username(), |
| 363 &wildcard_match)); |
| 364 |
| 365 base::RunLoop loop; |
| 366 scoped_ptr<CrosSettings::ObserverSubscription> subscription = |
| 367 cros_settings_.AddSettingsObserver( |
| 368 kAccountsPrefUsers, |
| 369 base::Bind(&base::RunLoop::Quit, base::Unretained(&loop))); |
| 370 service_->OnTPMTokenReady(true); |
| 371 ReloadDeviceSettings(); |
| 372 loop.Run(); |
| 373 |
| 374 wildcard_match = false; |
| 375 EXPECT_TRUE( |
| 376 cros_settings_.FindEmailInList(kAccountsPrefUsers, |
| 377 device_policy_.policy_data().username(), |
| 378 &wildcard_match)); |
| 379 EXPECT_FALSE(wildcard_match); |
| 380 } |
324 } // namespace chromeos | 381 } // namespace chromeos |
OLD | NEW |