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.h" | 10 #include "base/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/proto/chromeos/chrome_device_policy.pb.h" | 23 #include "chrome/browser/policy/proto/chromeos/chrome_device_policy.pb.h" |
24 #include "chrome/browser/policy/proto/cloud/device_management_backend.pb.h" | 24 #include "chrome/browser/policy/proto/cloud/device_management_backend.pb.h" |
25 #include "chrome/browser/prefs/browser_prefs.h" | 25 #include "chrome/browser/prefs/browser_prefs.h" |
26 #include "chrome/test/base/testing_browser_process.h" | 26 #include "chrome/test/base/testing_browser_process.h" |
27 #include "chromeos/cryptohome/cryptohome_library.h" | 27 #include "chromeos/cryptohome/cryptohome_library.h" |
28 #include "chromeos/cryptohome/mock_cryptohome_library.h" | 28 #include "chromeos/cryptohome/mock_cryptohome_library.h" |
29 #include "chromeos/dbus/cryptohome_client.h" | 29 #include "chromeos/dbus/cryptohome_client.h" |
30 #include "chromeos/dbus/dbus_client_implementation_type.h" | 30 #include "chromeos/dbus/dbus_client_implementation_type.h" |
| 31 #include "google_apis/gaia/gaia_oauth_client.h" |
31 #include "net/url_request/test_url_fetcher_factory.h" | 32 #include "net/url_request/test_url_fetcher_factory.h" |
32 #include "net/url_request/url_request_test_util.h" | 33 #include "net/url_request/url_request_test_util.h" |
33 #include "policy/policy_constants.h" | 34 #include "policy/policy_constants.h" |
34 #include "testing/gmock/include/gmock/gmock.h" | 35 #include "testing/gmock/include/gmock/gmock.h" |
35 #include "testing/gtest/include/gtest/gtest.h" | 36 #include "testing/gtest/include/gtest/gtest.h" |
36 | 37 |
37 using testing::AnyNumber; | 38 using testing::AnyNumber; |
38 using testing::AtMost; | 39 using testing::AtMost; |
39 using testing::DoAll; | 40 using testing::DoAll; |
40 using testing::Mock; | 41 using testing::Mock; |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 Value::CreateBooleanValue(false)); | 152 Value::CreateBooleanValue(false)); |
152 EXPECT_TRUE(manager_.policies().Equals(bundle)); | 153 EXPECT_TRUE(manager_.policies().Equals(bundle)); |
153 | 154 |
154 manager_.Connect(&local_state_, | 155 manager_.Connect(&local_state_, |
155 &device_management_service_, | 156 &device_management_service_, |
156 scoped_ptr<CloudPolicyClient::StatusProvider>()); | 157 scoped_ptr<CloudPolicyClient::StatusProvider>()); |
157 EXPECT_TRUE(manager_.policies().Equals(bundle)); | 158 EXPECT_TRUE(manager_.policies().Equals(bundle)); |
158 | 159 |
159 manager_.Shutdown(); | 160 manager_.Shutdown(); |
160 EXPECT_TRUE(manager_.policies().Equals(bundle)); | 161 EXPECT_TRUE(manager_.policies().Equals(bundle)); |
| 162 |
| 163 EXPECT_EQ(manager_.GetRobotAccountId(), |
| 164 PolicyBuilder::kFakeServiceAccountIdentity); |
161 } | 165 } |
162 | 166 |
163 TEST_F(DeviceCloudPolicyManagerChromeOSTest, ConsumerDevice) { | 167 TEST_F(DeviceCloudPolicyManagerChromeOSTest, ConsumerDevice) { |
164 FlushDeviceSettings(); | 168 FlushDeviceSettings(); |
165 EXPECT_EQ(CloudPolicyStore::STATUS_BAD_STATE, store_->status()); | 169 EXPECT_EQ(CloudPolicyStore::STATUS_BAD_STATE, store_->status()); |
166 EXPECT_TRUE(manager_.IsInitializationComplete(POLICY_DOMAIN_CHROME)); | 170 EXPECT_TRUE(manager_.IsInitializationComplete(POLICY_DOMAIN_CHROME)); |
167 | 171 |
168 PolicyBundle bundle; | 172 PolicyBundle bundle; |
169 EXPECT_TRUE(manager_.policies().Equals(bundle)); | 173 EXPECT_TRUE(manager_.policies().Equals(bundle)); |
170 | 174 |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
319 | 323 |
320 if (done_) | 324 if (done_) |
321 return; | 325 return; |
322 | 326 |
323 // Process robot refresh token fetch if the auth code fetch succeeded. | 327 // Process robot refresh token fetch if the auth code fetch succeeded. |
324 // DeviceCloudPolicyManagerChromeOS holds an EnrollmentHandlerChromeOS which | 328 // DeviceCloudPolicyManagerChromeOS holds an EnrollmentHandlerChromeOS which |
325 // holds a GaiaOAuthClient that fetches the refresh token during enrollment. | 329 // holds a GaiaOAuthClient that fetches the refresh token during enrollment. |
326 // We return a successful OAuth response via a TestURLFetcher to trigger the | 330 // We return a successful OAuth response via a TestURLFetcher to trigger the |
327 // happy path for these classes so that enrollment can continue. | 331 // happy path for these classes so that enrollment can continue. |
328 if (robot_auth_fetch_status_ == DM_STATUS_SUCCESS) { | 332 if (robot_auth_fetch_status_ == DM_STATUS_SUCCESS) { |
329 net::TestURLFetcher* url_fetcher = url_fetcher_factory_.GetFetcherByID(0); | 333 net::TestURLFetcher* url_fetcher = url_fetcher_factory_.GetFetcherByID( |
| 334 gaia::GaiaOAuthClient::kUrlFetcherId); |
330 ASSERT_TRUE(url_fetcher); | 335 ASSERT_TRUE(url_fetcher); |
331 url_fetcher->SetMaxRetriesOn5xx(0); | 336 url_fetcher->SetMaxRetriesOn5xx(0); |
332 url_fetcher->set_status(net::URLRequestStatus()); | 337 url_fetcher->set_status(net::URLRequestStatus()); |
333 url_fetcher->set_response_code(url_fetcher_response_code_); | 338 url_fetcher->set_response_code(url_fetcher_response_code_); |
334 url_fetcher->SetResponseString(url_fetcher_response_string_); | 339 url_fetcher->SetResponseString(url_fetcher_response_string_); |
335 url_fetcher->delegate()->OnURLFetchComplete(url_fetcher); | 340 url_fetcher->delegate()->OnURLFetchComplete(url_fetcher); |
336 } | 341 } |
337 base::RunLoop().RunUntilIdle(); | 342 base::RunLoop().RunUntilIdle(); |
338 | 343 |
339 // Process policy store. | 344 // Process policy store. |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
477 } | 482 } |
478 | 483 |
479 TEST_F(DeviceCloudPolicyManagerChromeOSEnrollmentTest, LoadError) { | 484 TEST_F(DeviceCloudPolicyManagerChromeOSEnrollmentTest, LoadError) { |
480 loaded_blob_.clear(); | 485 loaded_blob_.clear(); |
481 RunTest(); | 486 RunTest(); |
482 ExpectFailedEnrollment(EnrollmentStatus::STATUS_STORE_ERROR); | 487 ExpectFailedEnrollment(EnrollmentStatus::STATUS_STORE_ERROR); |
483 EXPECT_EQ(CloudPolicyStore::STATUS_LOAD_ERROR, | 488 EXPECT_EQ(CloudPolicyStore::STATUS_LOAD_ERROR, |
484 status_.store_status()); | 489 status_.store_status()); |
485 } | 490 } |
486 | 491 |
487 } // namespace test | 492 } // namespace |
488 } // namespace policy | 493 } // namespace policy |
OLD | NEW |