| 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/policy/device_token_fetcher.h" | 5 #include "chrome/browser/policy/device_token_fetcher.h" |
| 6 | 6 |
| 7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
| 8 #include "base/scoped_temp_dir.h" | 8 #include "base/scoped_temp_dir.h" |
| 9 #include "chrome/browser/policy/cloud_policy_data_store.h" | 9 #include "chrome/browser/policy/cloud_policy_data_store.h" |
| 10 #include "chrome/browser/policy/logging_work_scheduler.h" | 10 #include "chrome/browser/policy/logging_work_scheduler.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 namespace policy { | 21 namespace policy { |
| 22 | 22 |
| 23 const char kTestToken[] = "device_token_fetcher_test_auth_token"; | 23 const char kTestToken[] = "device_token_fetcher_test_auth_token"; |
| 24 | 24 |
| 25 using content::BrowserThread; | 25 using content::BrowserThread; |
| 26 using testing::AnyNumber; | 26 using testing::AnyNumber; |
| 27 using testing::Mock; | 27 using testing::Mock; |
| 28 using testing::_; | 28 using testing::_; |
| 29 | 29 |
| 30 ACTION_P(VerifyRegisterRequest, known_machine_id) { | 30 ACTION_P(VerifyRegisterRequest, known_machine_id) { |
| 31 ASSERT_TRUE(arg0); | 31 ASSERT_TRUE(arg6.has_register_request()); |
| 32 ASSERT_TRUE(arg0->GetRequest()); | 32 const em::DeviceRegisterRequest& request = arg6.register_request(); |
| 33 ASSERT_TRUE(arg0->GetRequest()->has_register_request()); | |
| 34 const em::DeviceRegisterRequest& request = | |
| 35 arg0->GetRequest()->register_request(); | |
| 36 if (known_machine_id) { | 33 if (known_machine_id) { |
| 37 EXPECT_TRUE(request.has_auto_enrolled()); | 34 EXPECT_TRUE(request.has_auto_enrolled()); |
| 38 EXPECT_TRUE(request.auto_enrolled()); | 35 EXPECT_TRUE(request.auto_enrolled()); |
| 39 } else { | 36 } else { |
| 40 EXPECT_FALSE(request.has_auto_enrolled()); | 37 EXPECT_FALSE(request.has_auto_enrolled()); |
| 41 } | 38 } |
| 42 } | 39 } |
| 43 | 40 |
| 44 class DeviceTokenFetcherTest : public testing::Test { | 41 class DeviceTokenFetcherTest : public testing::Test { |
| 45 protected: | 42 protected: |
| 46 DeviceTokenFetcherTest() | 43 DeviceTokenFetcherTest() |
| 47 : ui_thread_(BrowserThread::UI, &loop_), | 44 : ui_thread_(BrowserThread::UI, &loop_), |
| 48 file_thread_(BrowserThread::FILE, &loop_) { | 45 file_thread_(BrowserThread::FILE, &loop_) { |
| 49 EXPECT_TRUE(temp_user_data_dir_.CreateUniqueTempDir()); | 46 EXPECT_TRUE(temp_user_data_dir_.CreateUniqueTempDir()); |
| 50 successful_registration_response_.mutable_register_response()-> | 47 successful_registration_response_.mutable_register_response()-> |
| 51 set_device_management_token("fake_token"); | 48 set_device_management_token("fake_token"); |
| 52 successful_registration_response_.mutable_register_response()-> | 49 successful_registration_response_.mutable_register_response()-> |
| 53 set_enrollment_type(em::DeviceRegisterResponse::ENTERPRISE); | 50 set_enrollment_type(em::DeviceRegisterResponse::ENTERPRISE); |
| 54 } | 51 } |
| 55 | 52 |
| 56 virtual void SetUp() { | 53 virtual void SetUp() { |
| 57 cache_.reset(new UserPolicyCache( | 54 cache_.reset(new UserPolicyCache( |
| 58 temp_user_data_dir_.path().AppendASCII("DeviceTokenFetcherTest"), | 55 temp_user_data_dir_.path().AppendASCII("DeviceTokenFetcherTest"), |
| 59 false /* wait_for_policy_fetch */)); | 56 false /* wait_for_policy_fetch */)); |
| 60 EXPECT_CALL(service_, StartJob(_)).Times(AnyNumber()); | 57 EXPECT_CALL(service_, StartJob(_, _, _, _, _, _, _)).Times(AnyNumber()); |
| 61 data_store_.reset(CloudPolicyDataStore::CreateForUserPolicies()); | 58 data_store_.reset(CloudPolicyDataStore::CreateForUserPolicies()); |
| 62 data_store_->AddObserver(&observer_); | 59 data_store_->AddObserver(&observer_); |
| 63 } | 60 } |
| 64 | 61 |
| 65 virtual void TearDown() { | 62 virtual void TearDown() { |
| 66 loop_.RunAllPending(); | 63 loop_.RunAllPending(); |
| 67 data_store_->RemoveObserver(&observer_); | 64 data_store_->RemoveObserver(&observer_); |
| 68 } | 65 } |
| 69 | 66 |
| 70 void FetchToken(DeviceTokenFetcher* fetcher, CloudPolicyDataStore* store) { | 67 void FetchToken(DeviceTokenFetcher* fetcher, CloudPolicyDataStore* store) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 82 cache_->Load(); | 79 cache_->Load(); |
| 83 loop_.RunAllPending(); | 80 loop_.RunAllPending(); |
| 84 ASSERT_TRUE(cache_->last_policy_refresh_time().is_null()); | 81 ASSERT_TRUE(cache_->last_policy_refresh_time().is_null()); |
| 85 ASSERT_FALSE(cache_->IsReady()); | 82 ASSERT_FALSE(cache_->IsReady()); |
| 86 } | 83 } |
| 87 | 84 |
| 88 void SetUpSuccessfulRegistrationExpectation(bool known_machine_id) { | 85 void SetUpSuccessfulRegistrationExpectation(bool known_machine_id) { |
| 89 EXPECT_CALL(service_, | 86 EXPECT_CALL(service_, |
| 90 CreateJob(DeviceManagementRequestJob::TYPE_REGISTRATION)) | 87 CreateJob(DeviceManagementRequestJob::TYPE_REGISTRATION)) |
| 91 .WillOnce(service_.SucceedJob(successful_registration_response_)); | 88 .WillOnce(service_.SucceedJob(successful_registration_response_)); |
| 92 EXPECT_CALL(service_, StartJob(_)) | 89 EXPECT_CALL(service_, StartJob(_, _, _, _, _, _, _)) |
| 93 .WillOnce(VerifyRegisterRequest(known_machine_id)); | 90 .WillOnce(VerifyRegisterRequest(known_machine_id)); |
| 94 } | 91 } |
| 95 | 92 |
| 96 MessageLoop loop_; | 93 MessageLoop loop_; |
| 97 MockDeviceManagementService service_; | 94 MockDeviceManagementService service_; |
| 98 scoped_ptr<CloudPolicyCacheBase> cache_; | 95 scoped_ptr<CloudPolicyCacheBase> cache_; |
| 99 scoped_ptr<CloudPolicyDataStore> data_store_; | 96 scoped_ptr<CloudPolicyDataStore> data_store_; |
| 100 MockCloudPolicyDataStoreObserver observer_; | 97 MockCloudPolicyDataStoreObserver observer_; |
| 101 PolicyNotifier notifier_; | 98 PolicyNotifier notifier_; |
| 102 ScopedTempDir temp_user_data_dir_; | 99 ScopedTempDir temp_user_data_dir_; |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 data_store_->set_known_machine_id(true); | 257 data_store_->set_known_machine_id(true); |
| 261 FetchToken(&fetcher, data_store_.get()); | 258 FetchToken(&fetcher, data_store_.get()); |
| 262 loop_.RunAllPending(); | 259 loop_.RunAllPending(); |
| 263 | 260 |
| 264 Mock::VerifyAndClearExpectations(&observer_); | 261 Mock::VerifyAndClearExpectations(&observer_); |
| 265 std::string token = data_store_->device_token(); | 262 std::string token = data_store_->device_token(); |
| 266 EXPECT_NE("", token); | 263 EXPECT_NE("", token); |
| 267 } | 264 } |
| 268 | 265 |
| 269 } // namespace policy | 266 } // namespace policy |
| OLD | NEW |