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 <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 EnterpriseInstallAttributes::LockResult result) { | 62 EnterpriseInstallAttributes::LockResult result) { |
63 *out = result; | 63 *out = result; |
64 loop->Quit(); | 64 loop->Quit(); |
65 } | 65 } |
66 | 66 |
67 class DeviceCloudPolicyManagerChromeOSTest | 67 class DeviceCloudPolicyManagerChromeOSTest |
68 : public chromeos::DeviceSettingsTestBase { | 68 : public chromeos::DeviceSettingsTestBase { |
69 protected: | 69 protected: |
70 DeviceCloudPolicyManagerChromeOSTest() | 70 DeviceCloudPolicyManagerChromeOSTest() |
71 : state_keys_broker_(&fake_session_manager_client_, | 71 : state_keys_broker_(&fake_session_manager_client_, |
72 loop_.message_loop_proxy()), | 72 base::MessageLoopProxy::current()), |
73 store_(NULL) { | 73 store_(NULL) { |
74 EXPECT_CALL(mock_statistics_provider_, | 74 EXPECT_CALL(mock_statistics_provider_, |
75 GetMachineStatistic(_, _)) | 75 GetMachineStatistic(_, _)) |
76 .WillRepeatedly(Return(false)); | 76 .WillRepeatedly(Return(false)); |
77 EXPECT_CALL(mock_statistics_provider_, | 77 EXPECT_CALL(mock_statistics_provider_, |
78 GetMachineStatistic("serial_number", _)) | 78 GetMachineStatistic("serial_number", _)) |
79 .WillRepeatedly(DoAll(SetArgumentPointee<1>(std::string("test_sn")), | 79 .WillRepeatedly(DoAll(SetArgumentPointee<1>(std::string("test_sn")), |
80 Return(true))); | 80 Return(true))); |
81 chromeos::system::StatisticsProvider::SetTestProvider( | 81 chromeos::system::StatisticsProvider::SetTestProvider( |
82 &mock_statistics_provider_); | 82 &mock_statistics_provider_); |
83 std::vector<std::string> state_keys; | 83 std::vector<std::string> state_keys; |
84 state_keys.push_back("1"); | 84 state_keys.push_back("1"); |
85 state_keys.push_back("2"); | 85 state_keys.push_back("2"); |
86 state_keys.push_back("3"); | 86 state_keys.push_back("3"); |
87 fake_session_manager_client_.set_server_backed_state_keys(state_keys); | 87 fake_session_manager_client_.set_server_backed_state_keys(state_keys); |
88 } | 88 } |
89 | 89 |
90 virtual ~DeviceCloudPolicyManagerChromeOSTest() { | 90 virtual ~DeviceCloudPolicyManagerChromeOSTest() { |
91 chromeos::system::StatisticsProvider::SetTestProvider(NULL); | 91 chromeos::system::StatisticsProvider::SetTestProvider(NULL); |
92 } | 92 } |
93 | 93 |
94 virtual void SetUp() OVERRIDE { | 94 virtual void SetUp() OVERRIDE { |
95 DeviceSettingsTestBase::SetUp(); | 95 DeviceSettingsTestBase::SetUp(); |
96 | 96 |
97 // DBusThreadManager is set up in DeviceSettingsTestBase::SetUp(). | 97 // DBusThreadManager is set up in DeviceSettingsTestBase::SetUp(). |
98 install_attributes_.reset(new EnterpriseInstallAttributes( | 98 install_attributes_.reset(new EnterpriseInstallAttributes( |
99 chromeos::DBusThreadManager::Get()->GetCryptohomeClient())); | 99 chromeos::DBusThreadManager::Get()->GetCryptohomeClient())); |
100 store_ = new DeviceCloudPolicyStoreChromeOS(&device_settings_service_, | 100 store_ = |
101 install_attributes_.get(), | 101 new DeviceCloudPolicyStoreChromeOS(&device_settings_service_, |
102 loop_.message_loop_proxy()); | 102 install_attributes_.get(), |
| 103 base::MessageLoopProxy::current()); |
103 manager_.reset(new DeviceCloudPolicyManagerChromeOS( | 104 manager_.reset(new DeviceCloudPolicyManagerChromeOS( |
104 make_scoped_ptr(store_), | 105 make_scoped_ptr(store_), |
105 loop_.message_loop_proxy(), | 106 base::MessageLoopProxy::current(), |
106 loop_.message_loop_proxy(), | 107 base::MessageLoopProxy::current(), |
107 install_attributes_.get(), | 108 install_attributes_.get(), |
108 &state_keys_broker_)); | 109 &state_keys_broker_)); |
109 | 110 |
110 chrome::RegisterLocalState(local_state_.registry()); | 111 chrome::RegisterLocalState(local_state_.registry()); |
111 manager_->Init(&schema_registry_); | 112 manager_->Init(&schema_registry_); |
112 | 113 |
113 // DeviceOAuth2TokenService uses the system request context to fetch | 114 // DeviceOAuth2TokenService uses the system request context to fetch |
114 // OAuth tokens, then writes the token to local state, encrypting it | 115 // OAuth tokens, then writes the token to local state, encrypting it |
115 // first with methods in CryptohomeTokenEncryptor. | 116 // first with methods in CryptohomeTokenEncryptor. |
116 request_context_getter_ = new net::TestURLRequestContextGetter( | 117 request_context_getter_ = new net::TestURLRequestContextGetter( |
117 loop_.message_loop_proxy()); | 118 base::MessageLoopProxy::current()); |
118 TestingBrowserProcess::GetGlobal()->SetSystemRequestContext( | 119 TestingBrowserProcess::GetGlobal()->SetSystemRequestContext( |
119 request_context_getter_.get()); | 120 request_context_getter_.get()); |
120 TestingBrowserProcess::GetGlobal()->SetLocalState(&local_state_); | 121 TestingBrowserProcess::GetGlobal()->SetLocalState(&local_state_); |
121 // SystemSaltGetter is used in DeviceOAuth2TokenService. | 122 // SystemSaltGetter is used in DeviceOAuth2TokenService. |
122 chromeos::SystemSaltGetter::Initialize(); | 123 chromeos::SystemSaltGetter::Initialize(); |
123 chromeos::DeviceOAuth2TokenServiceFactory::Initialize(); | 124 chromeos::DeviceOAuth2TokenServiceFactory::Initialize(); |
124 url_fetcher_response_code_ = 200; | 125 url_fetcher_response_code_ = 200; |
125 url_fetcher_response_string_ = "{\"access_token\":\"accessToken4Test\"," | 126 url_fetcher_response_string_ = "{\"access_token\":\"accessToken4Test\"," |
126 "\"expires_in\":1234," | 127 "\"expires_in\":1234," |
127 "\"refresh_token\":\"refreshToken4Test\"}"; | 128 "\"refresh_token\":\"refreshToken4Test\"}"; |
(...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
589 | 590 |
590 TEST_F(DeviceCloudPolicyManagerChromeOSEnrollmentBlankSystemSaltTest, | 591 TEST_F(DeviceCloudPolicyManagerChromeOSEnrollmentBlankSystemSaltTest, |
591 RobotRefreshSaveFailed) { | 592 RobotRefreshSaveFailed) { |
592 // Without the system salt, the robot token can't be stored. | 593 // Without the system salt, the robot token can't be stored. |
593 RunTest(); | 594 RunTest(); |
594 ExpectFailedEnrollment(EnrollmentStatus::STATUS_ROBOT_REFRESH_STORE_FAILED); | 595 ExpectFailedEnrollment(EnrollmentStatus::STATUS_ROBOT_REFRESH_STORE_FAILED); |
595 } | 596 } |
596 | 597 |
597 } // namespace | 598 } // namespace |
598 } // namespace policy | 599 } // namespace policy |
OLD | NEW |