Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(229)

Side by Side Diff: chrome/browser/policy/cloud/cloud_policy_manager_unittest.cc

Issue 19733003: Implement cloud policy invalidations using the invalidation service framework. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_manager.h" 5 #include "chrome/browser/policy/cloud/cloud_policy_manager.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
11 #include "base/message_loop/message_loop.h" 11 #include "base/message_loop/message_loop.h"
12 #include "chrome/browser/invalidation/fake_invalidation_service.h"
12 #include "chrome/browser/policy/cloud/cloud_policy_constants.h" 13 #include "chrome/browser/policy/cloud/cloud_policy_constants.h"
13 #include "chrome/browser/policy/cloud/mock_cloud_policy_client.h" 14 #include "chrome/browser/policy/cloud/mock_cloud_policy_client.h"
14 #include "chrome/browser/policy/cloud/mock_cloud_policy_store.h" 15 #include "chrome/browser/policy/cloud/mock_cloud_policy_store.h"
15 #include "chrome/browser/policy/cloud/policy_builder.h" 16 #include "chrome/browser/policy/cloud/policy_builder.h"
16 #include "chrome/browser/policy/configuration_policy_provider_test.h" 17 #include "chrome/browser/policy/configuration_policy_provider_test.h"
17 #include "chrome/browser/policy/external_data_fetcher.h" 18 #include "chrome/browser/policy/external_data_fetcher.h"
18 #include "chrome/browser/policy/mock_configuration_policy_provider.h" 19 #include "chrome/browser/policy/mock_configuration_policy_provider.h"
20 #include "sync/notifier/invalidation_util.h"
19 #include "testing/gmock/include/gmock/gmock.h" 21 #include "testing/gmock/include/gmock/gmock.h"
20 #include "testing/gtest/include/gtest/gtest.h" 22 #include "testing/gtest/include/gtest/gtest.h"
21 23
22 using testing::Mock; 24 using testing::Mock;
23 using testing::_; 25 using testing::_;
24 26
25 namespace em = enterprise_management; 27 namespace em = enterprise_management;
26 28
27 namespace policy { 29 namespace policy {
28 namespace { 30 namespace {
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 dm_protocol::kChromeUserPolicyType, 138 dm_protocol::kChromeUserPolicyType,
137 std::string()), 139 std::string()),
138 store) {} 140 store) {}
139 virtual ~TestCloudPolicyManager() {} 141 virtual ~TestCloudPolicyManager() {}
140 142
141 // Publish the protected members for testing. 143 // Publish the protected members for testing.
142 using CloudPolicyManager::client; 144 using CloudPolicyManager::client;
143 using CloudPolicyManager::store; 145 using CloudPolicyManager::store;
144 using CloudPolicyManager::service; 146 using CloudPolicyManager::service;
145 using CloudPolicyManager::CheckAndPublishPolicy; 147 using CloudPolicyManager::CheckAndPublishPolicy;
148 using CloudPolicyManager::CreateInvalidator;
149 using CloudPolicyManager::UnregisterInvalidator;
146 150
147 private: 151 private:
148 DISALLOW_COPY_AND_ASSIGN(TestCloudPolicyManager); 152 DISALLOW_COPY_AND_ASSIGN(TestCloudPolicyManager);
149 }; 153 };
150 154
151 MATCHER_P(ProtoMatches, proto, "") { 155 MATCHER_P(ProtoMatches, proto, "") {
152 return arg.SerializePartialAsString() == proto.SerializePartialAsString(); 156 return arg.SerializePartialAsString() == proto.SerializePartialAsString();
153 } 157 }
154 158
155 class CloudPolicyManagerTest : public testing::Test { 159 class CloudPolicyManagerTest : public testing::Test {
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 TEST_F(CloudPolicyManagerTest, SignalOnError) { 334 TEST_F(CloudPolicyManagerTest, SignalOnError) {
331 // Simulate a failed load and verify that it triggers OnUpdatePolicy(). 335 // Simulate a failed load and verify that it triggers OnUpdatePolicy().
332 store_.policy_.reset(new em::PolicyData(policy_.policy_data())); 336 store_.policy_.reset(new em::PolicyData(policy_.policy_data()));
333 EXPECT_CALL(observer_, OnUpdatePolicy(manager_.get())); 337 EXPECT_CALL(observer_, OnUpdatePolicy(manager_.get()));
334 store_.NotifyStoreError(); 338 store_.NotifyStoreError();
335 Mock::VerifyAndClearExpectations(&observer_); 339 Mock::VerifyAndClearExpectations(&observer_);
336 340
337 EXPECT_TRUE(manager_->IsInitializationComplete(POLICY_DOMAIN_CHROME)); 341 EXPECT_TRUE(manager_->IsInitializationComplete(POLICY_DOMAIN_CHROME));
338 } 342 }
339 343
344 TEST_F(CloudPolicyManagerTest, CreateAndUnregisterInvalidator) {
345 // Add the invalidation registration info to the policy data.
346 em::PolicyData* policy_data = new em::PolicyData(policy_.policy_data());
347 policy_data->set_invalidation_source(12345);
348 policy_data->set_invalidation_name("12345");
349 store_.policy_.reset(policy_data);
350
351 // Expect registration to occur when the invalidator is created.
352 invalidation::FakeInvalidationService invalidation_service;
353 MockCloudPolicyClient* client = new MockCloudPolicyClient();
354 EXPECT_CALL(*client, SetupRegistration(_, _));
355 manager_->core()->Connect(scoped_ptr<CloudPolicyClient>(client));
356 manager_->core()->StartRefreshScheduler();
357 manager_->CreateInvalidator(&invalidation_service, true /* ignore_switch */);
358 syncer::ObjectIdSet object_ids =
359 invalidation_service.invalidator_registrar().GetAllRegisteredIds();
360 ASSERT_EQ(1U, object_ids.size());
361 EXPECT_EQ(12345, object_ids.begin()->source());
362 EXPECT_EQ("12345", object_ids.begin()->name());
363
364 // Expect unregistration to occur.
365 manager_->UnregisterInvalidator();
366 object_ids =
367 invalidation_service.invalidator_registrar().GetAllRegisteredIds();
368 EXPECT_TRUE(object_ids.empty());
369 }
370
340 } // namespace 371 } // namespace
341 } // namespace policy 372 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698