| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/device_cloud_policy_store_chromeos.h" | 5 #include "chrome/browser/chromeos/policy/device_cloud_policy_store_chromeos.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/message_loop/message_loop_proxy.h" | 12 #include "base/message_loop/message_loop_proxy.h" |
| 13 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
| 14 #include "chrome/browser/chromeos/policy/enterprise_install_attributes.h" | 14 #include "chrome/browser/chromeos/policy/enterprise_install_attributes.h" |
| 15 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h" | 15 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h" |
| 16 #include "chrome/browser/chromeos/settings/device_settings_test_helper.h" | 16 #include "chrome/browser/chromeos/settings/device_settings_test_helper.h" |
| 17 #include "chrome/test/base/scoped_testing_local_state.h" | 17 #include "chrome/test/base/scoped_testing_local_state.h" |
| 18 #include "chrome/test/base/testing_browser_process.h" | 18 #include "chrome/test/base/testing_browser_process.h" |
| 19 #include "chromeos/cryptohome/cryptohome_util.h" | 19 #include "chromeos/cryptohome/cryptohome_util.h" |
| 20 #include "chromeos/dbus/dbus_thread_manager.h" |
| 20 #include "chromeos/dbus/fake_cryptohome_client.h" | 21 #include "chromeos/dbus/fake_cryptohome_client.h" |
| 21 #include "chromeos/dbus/fake_dbus_thread_manager.h" | |
| 22 #include "policy/policy_constants.h" | 22 #include "policy/policy_constants.h" |
| 23 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
| 24 | 24 |
| 25 namespace policy { | 25 namespace policy { |
| 26 | 26 |
| 27 namespace { | 27 namespace { |
| 28 | 28 |
| 29 void CopyLockResult(base::RunLoop* loop, | 29 void CopyLockResult(base::RunLoop* loop, |
| 30 EnterpriseInstallAttributes::LockResult* out, | 30 EnterpriseInstallAttributes::LockResult* out, |
| 31 EnterpriseInstallAttributes::LockResult result) { | 31 EnterpriseInstallAttributes::LockResult result) { |
| 32 *out = result; | 32 *out = result; |
| 33 loop->Quit(); | 33 loop->Quit(); |
| 34 } | 34 } |
| 35 | 35 |
| 36 } // namespace | 36 } // namespace |
| 37 | 37 |
| 38 class DeviceCloudPolicyStoreChromeOSTest | 38 class DeviceCloudPolicyStoreChromeOSTest |
| 39 : public chromeos::DeviceSettingsTestBase { | 39 : public chromeos::DeviceSettingsTestBase { |
| 40 protected: | 40 protected: |
| 41 DeviceCloudPolicyStoreChromeOSTest() | 41 DeviceCloudPolicyStoreChromeOSTest() |
| 42 : local_state_(TestingBrowserProcess::GetGlobal()), | 42 : local_state_(TestingBrowserProcess::GetGlobal()), |
| 43 fake_cryptohome_client_(new chromeos::FakeCryptohomeClient()), | 43 fake_cryptohome_client_(new chromeos::FakeCryptohomeClient()), |
| 44 install_attributes_( | 44 install_attributes_( |
| 45 new EnterpriseInstallAttributes(fake_cryptohome_client_)), | 45 new EnterpriseInstallAttributes(fake_cryptohome_client_)), |
| 46 store_(new DeviceCloudPolicyStoreChromeOS( | 46 store_(new DeviceCloudPolicyStoreChromeOS( |
| 47 &device_settings_service_, | 47 &device_settings_service_, |
| 48 install_attributes_.get(), | 48 install_attributes_.get(), |
| 49 base::MessageLoopProxy::current())) { | 49 base::MessageLoopProxy::current())) { |
| 50 fake_dbus_thread_manager_->SetCryptohomeClient( | |
| 51 scoped_ptr<chromeos::CryptohomeClient>(fake_cryptohome_client_)); | |
| 52 } | 50 } |
| 53 | 51 |
| 54 virtual void SetUp() OVERRIDE { | 52 virtual void SetUp() OVERRIDE { |
| 55 DeviceSettingsTestBase::SetUp(); | 53 DeviceSettingsTestBase::SetUp(); |
| 56 | 54 |
| 55 dbus_helper_->SetCryptohomeClient( |
| 56 scoped_ptr<chromeos::CryptohomeClient>(fake_cryptohome_client_)); |
| 57 |
| 57 base::RunLoop loop; | 58 base::RunLoop loop; |
| 58 EnterpriseInstallAttributes::LockResult result; | 59 EnterpriseInstallAttributes::LockResult result; |
| 59 install_attributes_->LockDevice( | 60 install_attributes_->LockDevice( |
| 60 PolicyBuilder::kFakeUsername, | 61 PolicyBuilder::kFakeUsername, |
| 61 DEVICE_MODE_ENTERPRISE, | 62 DEVICE_MODE_ENTERPRISE, |
| 62 PolicyBuilder::kFakeDeviceId, | 63 PolicyBuilder::kFakeDeviceId, |
| 63 base::Bind(&CopyLockResult, &loop, &result)); | 64 base::Bind(&CopyLockResult, &loop, &result)); |
| 64 loop.Run(); | 65 loop.Run(); |
| 65 ASSERT_EQ(EnterpriseInstallAttributes::LOCK_SUCCESS, result); | 66 ASSERT_EQ(EnterpriseInstallAttributes::LOCK_SUCCESS, result); |
| 66 } | 67 } |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 | 270 |
| 270 TEST_F(DeviceCloudPolicyStoreChromeOSTest, InstallInitialPolicyNotEnterprise) { | 271 TEST_F(DeviceCloudPolicyStoreChromeOSTest, InstallInitialPolicyNotEnterprise) { |
| 271 PrepareNewSigningKey(); | 272 PrepareNewSigningKey(); |
| 272 ResetToNonEnterprise(); | 273 ResetToNonEnterprise(); |
| 273 store_->InstallInitialPolicy(device_policy_.policy()); | 274 store_->InstallInitialPolicy(device_policy_.policy()); |
| 274 FlushDeviceSettings(); | 275 FlushDeviceSettings(); |
| 275 ExpectFailure(CloudPolicyStore::STATUS_BAD_STATE); | 276 ExpectFailure(CloudPolicyStore::STATUS_BAD_STATE); |
| 276 } | 277 } |
| 277 | 278 |
| 278 } // namespace policy | 279 } // namespace policy |
| OLD | NEW |