| 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_manager_chromeos.h" | 5 #include "chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 #include "chrome/browser/policy/cloud/cloud_policy_client.h" | 21 #include "chrome/browser/policy/cloud/cloud_policy_client.h" |
| 22 #include "chrome/browser/policy/cloud/mock_device_management_service.h" | 22 #include "chrome/browser/policy/cloud/mock_device_management_service.h" |
| 23 #include "chrome/browser/policy/external_data_fetcher.h" | 23 #include "chrome/browser/policy/external_data_fetcher.h" |
| 24 #include "chrome/browser/policy/proto/chromeos/chrome_device_policy.pb.h" | 24 #include "chrome/browser/policy/proto/chromeos/chrome_device_policy.pb.h" |
| 25 #include "chrome/browser/policy/proto/cloud/device_management_backend.pb.h" | 25 #include "chrome/browser/policy/proto/cloud/device_management_backend.pb.h" |
| 26 #include "chrome/browser/prefs/browser_prefs.h" | 26 #include "chrome/browser/prefs/browser_prefs.h" |
| 27 #include "chrome/test/base/testing_browser_process.h" | 27 #include "chrome/test/base/testing_browser_process.h" |
| 28 #include "chromeos/cryptohome/cryptohome_library.h" | 28 #include "chromeos/cryptohome/cryptohome_library.h" |
| 29 #include "chromeos/dbus/dbus_client_implementation_type.h" | 29 #include "chromeos/dbus/dbus_client_implementation_type.h" |
| 30 #include "chromeos/dbus/fake_cryptohome_client.h" | 30 #include "chromeos/dbus/fake_cryptohome_client.h" |
| 31 #include "chromeos/system/mock_statistics_provider.h" |
| 32 #include "chromeos/system/statistics_provider.h" |
| 31 #include "google_apis/gaia/gaia_oauth_client.h" | 33 #include "google_apis/gaia/gaia_oauth_client.h" |
| 32 #include "net/url_request/test_url_fetcher_factory.h" | 34 #include "net/url_request/test_url_fetcher_factory.h" |
| 33 #include "net/url_request/url_request_test_util.h" | 35 #include "net/url_request/url_request_test_util.h" |
| 34 #include "policy/policy_constants.h" | 36 #include "policy/policy_constants.h" |
| 35 #include "testing/gmock/include/gmock/gmock.h" | 37 #include "testing/gmock/include/gmock/gmock.h" |
| 36 #include "testing/gtest/include/gtest/gtest.h" | 38 #include "testing/gtest/include/gtest/gtest.h" |
| 37 | 39 |
| 38 using testing::AnyNumber; | 40 using testing::AnyNumber; |
| 39 using testing::AtMost; | 41 using testing::AtMost; |
| 40 using testing::DoAll; | 42 using testing::DoAll; |
| 41 using testing::Mock; | 43 using testing::Mock; |
| 44 using testing::Return; |
| 42 using testing::SaveArg; | 45 using testing::SaveArg; |
| 46 using testing::SetArgumentPointee; |
| 43 using testing::_; | 47 using testing::_; |
| 44 | 48 |
| 45 namespace em = enterprise_management; | 49 namespace em = enterprise_management; |
| 46 | 50 |
| 47 namespace policy { | 51 namespace policy { |
| 48 namespace { | 52 namespace { |
| 49 | 53 |
| 50 void CopyLockResult(base::RunLoop* loop, | 54 void CopyLockResult(base::RunLoop* loop, |
| 51 EnterpriseInstallAttributes::LockResult* out, | 55 EnterpriseInstallAttributes::LockResult* out, |
| 52 EnterpriseInstallAttributes::LockResult result) { | 56 EnterpriseInstallAttributes::LockResult result) { |
| 53 *out = result; | 57 *out = result; |
| 54 loop->Quit(); | 58 loop->Quit(); |
| 55 } | 59 } |
| 56 | 60 |
| 57 class DeviceCloudPolicyManagerChromeOSTest | 61 class DeviceCloudPolicyManagerChromeOSTest |
| 58 : public chromeos::DeviceSettingsTestBase { | 62 : public chromeos::DeviceSettingsTestBase { |
| 59 protected: | 63 protected: |
| 60 DeviceCloudPolicyManagerChromeOSTest() | 64 DeviceCloudPolicyManagerChromeOSTest() |
| 61 : cryptohome_library_(chromeos::CryptohomeLibrary::GetTestImpl()), | 65 : cryptohome_library_(chromeos::CryptohomeLibrary::GetTestImpl()), |
| 62 fake_cryptohome_client_(new chromeos::FakeCryptohomeClient()), | 66 fake_cryptohome_client_(new chromeos::FakeCryptohomeClient()), |
| 63 install_attributes_(fake_cryptohome_client_.get()), | 67 install_attributes_(fake_cryptohome_client_.get()), |
| 64 store_(new DeviceCloudPolicyStoreChromeOS(&device_settings_service_, | 68 store_(new DeviceCloudPolicyStoreChromeOS(&device_settings_service_, |
| 65 &install_attributes_)), | 69 &install_attributes_)), |
| 66 manager_(make_scoped_ptr(store_), | 70 manager_(make_scoped_ptr(store_), |
| 67 loop_.message_loop_proxy(), | 71 loop_.message_loop_proxy(), |
| 68 &install_attributes_) { | 72 &install_attributes_) { |
| 69 fake_cryptohome_client_->Init(NULL /* no dbus::Bus */); | 73 fake_cryptohome_client_->Init(NULL /* no dbus::Bus */); |
| 74 EXPECT_CALL(mock_statistics_provider_, |
| 75 GetMachineStatistic(_, _)) |
| 76 .WillRepeatedly(Return(false)); |
| 77 EXPECT_CALL(mock_statistics_provider_, |
| 78 GetMachineStatistic("serial_number", _)) |
| 79 .WillRepeatedly(DoAll(SetArgumentPointee<1>(std::string("test_sn")), |
| 80 Return(true))); |
| 81 chromeos::system::StatisticsProvider::SetTestProvider( |
| 82 &mock_statistics_provider_); |
| 83 } |
| 84 virtual ~DeviceCloudPolicyManagerChromeOSTest() { |
| 85 chromeos::system::StatisticsProvider::SetTestProvider(NULL); |
| 70 } | 86 } |
| 71 | 87 |
| 72 virtual void SetUp() OVERRIDE { | 88 virtual void SetUp() OVERRIDE { |
| 73 DeviceSettingsTestBase::SetUp(); | 89 DeviceSettingsTestBase::SetUp(); |
| 74 chrome::RegisterLocalState(local_state_.registry()); | 90 chrome::RegisterLocalState(local_state_.registry()); |
| 75 manager_.Init(); | 91 manager_.Init(); |
| 76 | 92 |
| 77 // DeviceOAuth2TokenService uses the system request context to fetch | 93 // DeviceOAuth2TokenService uses the system request context to fetch |
| 78 // OAuth tokens, then writes the token to local state, encrypting it | 94 // OAuth tokens, then writes the token to local state, encrypting it |
| 79 // first with methods in CryptohomeLibrary. | 95 // first with methods in CryptohomeLibrary. |
| (...skipping 26 matching lines...) Expand all Loading... |
| 106 EnterpriseInstallAttributes install_attributes_; | 122 EnterpriseInstallAttributes install_attributes_; |
| 107 | 123 |
| 108 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; | 124 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; |
| 109 net::TestURLFetcherFactory url_fetcher_factory_; | 125 net::TestURLFetcherFactory url_fetcher_factory_; |
| 110 int url_fetcher_response_code_; | 126 int url_fetcher_response_code_; |
| 111 string url_fetcher_response_string_; | 127 string url_fetcher_response_string_; |
| 112 TestingPrefServiceSimple local_state_; | 128 TestingPrefServiceSimple local_state_; |
| 113 MockDeviceManagementService device_management_service_; | 129 MockDeviceManagementService device_management_service_; |
| 114 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; | 130 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; |
| 115 chromeos::ScopedTestCrosSettings test_cros_settings_; | 131 chromeos::ScopedTestCrosSettings test_cros_settings_; |
| 132 chromeos::system::MockStatisticsProvider mock_statistics_provider_; |
| 116 | 133 |
| 117 DeviceCloudPolicyStoreChromeOS* store_; | 134 DeviceCloudPolicyStoreChromeOS* store_; |
| 118 DeviceCloudPolicyManagerChromeOS manager_; | 135 DeviceCloudPolicyManagerChromeOS manager_; |
| 119 | 136 |
| 120 private: | 137 private: |
| 121 DISALLOW_COPY_AND_ASSIGN(DeviceCloudPolicyManagerChromeOSTest); | 138 DISALLOW_COPY_AND_ASSIGN(DeviceCloudPolicyManagerChromeOSTest); |
| 122 }; | 139 }; |
| 123 | 140 |
| 124 TEST_F(DeviceCloudPolicyManagerChromeOSTest, FreshDevice) { | 141 TEST_F(DeviceCloudPolicyManagerChromeOSTest, FreshDevice) { |
| 125 owner_key_util_->Clear(); | 142 owner_key_util_->Clear(); |
| (...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 491 TEST_F(DeviceCloudPolicyManagerChromeOSEnrollmentTest, LoadError) { | 508 TEST_F(DeviceCloudPolicyManagerChromeOSEnrollmentTest, LoadError) { |
| 492 loaded_blob_.clear(); | 509 loaded_blob_.clear(); |
| 493 RunTest(); | 510 RunTest(); |
| 494 ExpectFailedEnrollment(EnrollmentStatus::STATUS_STORE_ERROR); | 511 ExpectFailedEnrollment(EnrollmentStatus::STATUS_STORE_ERROR); |
| 495 EXPECT_EQ(CloudPolicyStore::STATUS_LOAD_ERROR, | 512 EXPECT_EQ(CloudPolicyStore::STATUS_LOAD_ERROR, |
| 496 status_.store_status()); | 513 status_.store_status()); |
| 497 } | 514 } |
| 498 | 515 |
| 499 } // namespace | 516 } // namespace |
| 500 } // namespace policy | 517 } // namespace policy |
| OLD | NEW |