| 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/cloud/cloud_policy_service.h" | 5 #include "chrome/browser/policy/cloud/cloud_policy_service.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "chrome/browser/policy/cloud/cloud_policy_constants.h" | 9 #include "chrome/browser/policy/cloud/cloud_policy_constants.h" |
| 10 #include "chrome/browser/policy/cloud/mock_cloud_policy_client.h" | 10 #include "chrome/browser/policy/cloud/mock_cloud_policy_client.h" |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 | 98 |
| 99 // Trigger a fetch on the client. | 99 // Trigger a fetch on the client. |
| 100 EXPECT_CALL(client_, FetchPolicy()).Times(1); | 100 EXPECT_CALL(client_, FetchPolicy()).Times(1); |
| 101 service_.RefreshPolicy(base::Bind(&CloudPolicyServiceTest::OnPolicyRefresh, | 101 service_.RefreshPolicy(base::Bind(&CloudPolicyServiceTest::OnPolicyRefresh, |
| 102 base::Unretained(this))); | 102 base::Unretained(this))); |
| 103 | 103 |
| 104 // Client responds, push policy to store. | 104 // Client responds, push policy to store. |
| 105 em::PolicyFetchResponse policy; | 105 em::PolicyFetchResponse policy; |
| 106 policy.set_policy_data("fake policy"); | 106 policy.set_policy_data("fake policy"); |
| 107 client_.SetPolicy(policy_ns_key_, policy); | 107 client_.SetPolicy(policy_ns_key_, policy); |
| 108 client_.fetched_invalidation_version_ = 12345; |
| 108 EXPECT_CALL(store_, Store(ProtoMatches(policy))).Times(1); | 109 EXPECT_CALL(store_, Store(ProtoMatches(policy))).Times(1); |
| 110 EXPECT_EQ(0, store_.invalidation_version()); |
| 109 client_.NotifyPolicyFetched(); | 111 client_.NotifyPolicyFetched(); |
| 112 EXPECT_EQ(12345, store_.invalidation_version()); |
| 110 | 113 |
| 111 // Store reloads policy, callback gets triggered. | 114 // Store reloads policy, callback gets triggered. |
| 112 store_.policy_.reset(new em::PolicyData()); | 115 store_.policy_.reset(new em::PolicyData()); |
| 113 store_.policy_->set_request_token("token"); | 116 store_.policy_->set_request_token("token"); |
| 114 store_.policy_->set_device_id("device-id"); | 117 store_.policy_->set_device_id("device-id"); |
| 115 EXPECT_CALL(*this, OnPolicyRefresh(true)).Times(1); | 118 EXPECT_CALL(*this, OnPolicyRefresh(true)).Times(1); |
| 116 store_.NotifyStoreLoaded(); | 119 store_.NotifyStoreLoaded(); |
| 117 } | 120 } |
| 118 | 121 |
| 119 TEST_F(CloudPolicyServiceTest, RefreshPolicyNotRegistered) { | 122 TEST_F(CloudPolicyServiceTest, RefreshPolicyNotRegistered) { |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 testing::Mock::VerifyAndClearExpectations(&observer); | 231 testing::Mock::VerifyAndClearExpectations(&observer); |
| 229 | 232 |
| 230 // Now, the next time the store is loaded, the observer should not be called | 233 // Now, the next time the store is loaded, the observer should not be called |
| 231 // again. | 234 // again. |
| 232 EXPECT_CALL(observer, OnInitializationCompleted(&service_)).Times(0); | 235 EXPECT_CALL(observer, OnInitializationCompleted(&service_)).Times(0); |
| 233 store_.NotifyStoreLoaded(); | 236 store_.NotifyStoreLoaded(); |
| 234 service_.RemoveObserver(&observer); | 237 service_.RemoveObserver(&observer); |
| 235 } | 238 } |
| 236 | 239 |
| 237 } // namespace policy | 240 } // namespace policy |
| OLD | NEW |