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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/policy/cloud/cloud_policy_manager_unittest.cc
diff --git a/chrome/browser/policy/cloud/cloud_policy_manager_unittest.cc b/chrome/browser/policy/cloud/cloud_policy_manager_unittest.cc
index cbcb4d418e7ba566cbfb080405c2ddbdde9d8349..98a4213bf6240e6ac6b93e29f0614ff719889bcd 100644
--- a/chrome/browser/policy/cloud/cloud_policy_manager_unittest.cc
+++ b/chrome/browser/policy/cloud/cloud_policy_manager_unittest.cc
@@ -5,17 +5,22 @@
#include "chrome/browser/policy/cloud/cloud_policy_manager.h"
#include "base/basictypes.h"
+#include "base/bind.h"
#include "base/callback.h"
#include "base/compiler_specific.h"
#include "base/memory/scoped_ptr.h"
#include "base/message_loop/message_loop.h"
+#include "base/test/test_simple_task_runner.h"
+#include "chrome/browser/invalidation/fake_invalidation_service.h"
#include "chrome/browser/policy/cloud/cloud_policy_constants.h"
+#include "chrome/browser/policy/cloud/cloud_policy_invalidator.h"
#include "chrome/browser/policy/cloud/mock_cloud_policy_client.h"
#include "chrome/browser/policy/cloud/mock_cloud_policy_store.h"
#include "chrome/browser/policy/cloud/policy_builder.h"
#include "chrome/browser/policy/configuration_policy_provider_test.h"
#include "chrome/browser/policy/external_data_fetcher.h"
#include "chrome/browser/policy/mock_configuration_policy_provider.h"
+#include "sync/notifier/invalidation_util.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -143,6 +148,7 @@ class TestCloudPolicyManager : public CloudPolicyManager {
using CloudPolicyManager::store;
using CloudPolicyManager::service;
using CloudPolicyManager::CheckAndPublishPolicy;
+ using CloudPolicyManager::StartRefreshScheduler;
private:
DISALLOW_COPY_AND_ASSIGN(TestCloudPolicyManager);
@@ -179,6 +185,60 @@ class CloudPolicyManagerTest : public testing::Test {
manager_->Shutdown();
}
+ // Sets up for an invalidations test.
+ void CreateInvalidator() {
+ // Add the invalidation registration info to the policy data.
+ em::PolicyData* policy_data = new em::PolicyData(policy_.policy_data());
+ policy_data->set_invalidation_source(12345);
+ policy_data->set_invalidation_name("12345");
+ store_.policy_.reset(policy_data);
+
+ // Connect the core.
+ MockCloudPolicyClient* client = new MockCloudPolicyClient();
+ EXPECT_CALL(*client, SetupRegistration(_, _));
+ manager_->core()->Connect(scoped_ptr<CloudPolicyClient>(client));
+
+ // Create invalidation objects.
+ task_runner_ = new base::TestSimpleTaskRunner();
+ invalidation_service_.reset(new invalidation::FakeInvalidationService());
+ invalidator_.reset(new CloudPolicyInvalidator(
+ manager_.get(),
+ manager_->core()->store(),
+ task_runner_));
+ }
+
+ void ShutdownInvalidator() {
+ invalidator_->Shutdown();
+ }
+
+ // Call EnableInvalidations on the manager.
+ void EnableInvalidations() {
+ void (CloudPolicyInvalidator::*initialize)
+ (invalidation::InvalidationService*) =
+ &CloudPolicyInvalidator::Initialize;
Joao da Silva 2013/07/29 19:44:32 Don't do this. Rename the Initialize() methods ins
Steve Condie 2013/07/29 20:44:51 Done.
+ manager_->EnableInvalidations(
+ base::Bind(
+ initialize,
+ base::Unretained(invalidator_.get()),
+ base::Unretained(invalidation_service_.get())));
+ }
+
+ // Determine if the invalidator has registered with the invalidation service.
+ bool IsInvalidatorRegistered() {
+ syncer::ObjectIdSet object_ids =
+ invalidation_service_->invalidator_registrar().GetAllRegisteredIds();
+ return object_ids.size() == 1 &&
+ object_ids.begin()->source() == 12345 &&
+ object_ids.begin()->name() == "12345";
+ }
+
+ // Determine if the invalidator is unregistered with the invalidation service.
+ bool IsInvalidatorUnregistered() {
+ syncer::ObjectIdSet object_ids =
+ invalidation_service_->invalidator_registrar().GetAllRegisteredIds();
+ return object_ids.empty();
+ }
+
// Required by the refresh scheduler that's created by the manager.
base::MessageLoop loop_;
@@ -193,6 +253,11 @@ class CloudPolicyManagerTest : public testing::Test {
MockCloudPolicyStore store_;
scoped_ptr<TestCloudPolicyManager> manager_;
+ // Invalidation objects.
+ scoped_refptr<base::TestSimpleTaskRunner> task_runner_;
+ scoped_ptr<invalidation::FakeInvalidationService> invalidation_service_;
+ scoped_ptr<CloudPolicyInvalidator> invalidator_;
+
private:
DISALLOW_COPY_AND_ASSIGN(CloudPolicyManagerTest);
};
@@ -337,5 +402,26 @@ TEST_F(CloudPolicyManagerTest, SignalOnError) {
EXPECT_TRUE(manager_->IsInitializationComplete(POLICY_DOMAIN_CHROME));
}
+TEST_F(CloudPolicyManagerTest, EnableInvalidationsBeforeRefreshScheduler) {
+ CreateInvalidator();
+ EXPECT_TRUE(IsInvalidatorUnregistered());
+ EnableInvalidations();
+ EXPECT_TRUE(IsInvalidatorUnregistered());
+ manager_->StartRefreshScheduler();
+ EXPECT_TRUE(IsInvalidatorRegistered());
+ ShutdownInvalidator();
+}
+
+TEST_F(CloudPolicyManagerTest, EnableInvalidationsAfterRefreshScheduler) {
+ CreateInvalidator();
+ EXPECT_TRUE(IsInvalidatorUnregistered());
+ manager_->StartRefreshScheduler();
+ EXPECT_TRUE(IsInvalidatorUnregistered());
+ EnableInvalidations();
+ EXPECT_TRUE(IsInvalidatorRegistered());
+ ShutdownInvalidator();
+}
+
+
Joao da Silva 2013/07/29 19:44:32 nit: remove extra newline
Steve Condie 2013/07/29 20:44:51 Done.
} // namespace
} // namespace policy

Powered by Google App Engine
This is Rietveld 408576698