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

Unified Diff: chrome/browser/chromeos/policy/device_cloud_policy_invalidator_unittest.cc

Issue 460573005: Pass highest handled invalidation version between invalidators (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed nits. Created 6 years, 4 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/chromeos/policy/device_cloud_policy_invalidator_unittest.cc
diff --git a/chrome/browser/chromeos/policy/device_cloud_policy_invalidator_unittest.cc b/chrome/browser/chromeos/policy/device_cloud_policy_invalidator_unittest.cc
index 3f5f6e1854fd7fca3c91b143405747482d30971b..cd3363b8331f2486925bb0106d2605f7abfcf1c2 100644
--- a/chrome/browser/chromeos/policy/device_cloud_policy_invalidator_unittest.cc
+++ b/chrome/browser/chromeos/policy/device_cloud_policy_invalidator_unittest.cc
@@ -9,28 +9,61 @@
#include "base/memory/ref_counted.h"
#include "base/message_loop/message_loop_proxy.h"
#include "base/run_loop.h"
+#include "chrome/browser/browser_process_platform_part.h"
#include "chrome/browser/chrome_notification_types.h"
+#include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
+#include "chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.h"
+#include "chrome/browser/chromeos/policy/device_cloud_policy_store_chromeos.h"
+#include "chrome/browser/chromeos/policy/device_policy_builder.h"
+#include "chrome/browser/chromeos/policy/stub_enterprise_install_attributes.h"
#include "chrome/browser/chromeos/settings/cros_settings.h"
#include "chrome/browser/chromeos/settings/device_oauth2_token_service_factory.h"
#include "chrome/browser/chromeos/settings/device_settings_service.h"
+#include "chrome/browser/chromeos/settings/device_settings_test_helper.h"
+#include "chrome/browser/chromeos/settings/mock_owner_key_util.h"
+#include "chrome/browser/invalidation/fake_invalidation_service.h"
#include "chrome/browser/invalidation/profile_invalidation_provider_factory.h"
+#include "chrome/browser/policy/cloud/cloud_policy_invalidator.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/test/base/testing_browser_process.h"
#include "chrome/test/base/testing_profile_manager.h"
#include "chromeos/cryptohome/system_salt_getter.h"
#include "chromeos/dbus/dbus_thread_manager.h"
+#include "components/invalidation/invalidation_service.h"
#include "components/invalidation/invalidator_state.h"
#include "components/invalidation/profile_invalidation_provider.h"
#include "components/invalidation/ticl_invalidation_service.h"
+#include "components/keyed_service/core/keyed_service.h"
+#include "components/policy/core/common/cloud/cloud_policy_client.h"
+#include "components/policy/core/common/cloud/cloud_policy_constants.h"
+#include "components/policy/core/common/cloud/cloud_policy_core.h"
+#include "components/policy/core/common/cloud/mock_cloud_policy_client.h"
+#include "content/public/browser/browser_context.h"
#include "content/public/browser/notification_details.h"
#include "content/public/browser/notification_service.h"
#include "content/public/test/test_browser_thread_bundle.h"
#include "net/url_request/url_request_context_getter.h"
#include "net/url_request/url_request_test_util.h"
+#include "policy/proto/device_management_backend.pb.h"
+#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace policy {
+namespace {
+
+KeyedService* BuildProfileInvalidationProvider(
+ content::BrowserContext* context) {
+ scoped_ptr<invalidation::FakeInvalidationService> invalidation_service(
+ new invalidation::FakeInvalidationService);
+ invalidation_service->SetInvalidatorState(
+ syncer::TRANSIENT_INVALIDATION_ERROR);
+ return new invalidation::ProfileInvalidationProvider(
+ invalidation_service.PassAs<invalidation::InvalidationService>());
+}
+
+} // namespace
+
class DeviceCloudPolicyInvalidatorTest : public testing::Test {
public:
DeviceCloudPolicyInvalidatorTest();
@@ -46,22 +79,27 @@ class DeviceCloudPolicyInvalidatorTest : public testing::Test {
invalidation::TiclInvalidationService* GetDeviceInvalidationService();
bool HasDeviceInvalidationServiceObserver() const;
- invalidation::TiclInvalidationService* GetProfileInvalidationService(
+ invalidation::FakeInvalidationService* GetProfileInvalidationService(
Profile* profile);
int GetProfileInvalidationServiceObserverCount() const;
- const invalidation::TiclInvalidationService* GetInvalidationService() const;
- bool HasCloudPolicyInvalidator() const;
+ const invalidation::InvalidationService* GetInvalidationService() const;
+ CloudPolicyInvalidator* GetCloudPolicyInvalidator() const;
void ConnectDeviceInvalidationService();
+ protected:
+ DevicePolicyBuilder device_policy_;
+
private:
content::TestBrowserThreadBundle thread_bundle_;
scoped_refptr<net::URLRequestContextGetter> system_request_context_;
TestingProfileManager profile_manager_;
+ ScopedStubEnterpriseInstallAttributes install_attributes_;
scoped_ptr<chromeos::ScopedTestDeviceSettingsService>
test_device_settings_service_;
scoped_ptr<chromeos::ScopedTestCrosSettings> test_cros_settings_;
+ chromeos::DeviceSettingsTestHelper device_settings_test_helper_;
scoped_ptr<DeviceCloudPolicyInvalidator> invalidator_;
};
@@ -70,7 +108,11 @@ DeviceCloudPolicyInvalidatorTest::DeviceCloudPolicyInvalidatorTest()
: thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP),
system_request_context_(new net::TestURLRequestContextGetter(
base::MessageLoopProxy::current())),
- profile_manager_(TestingBrowserProcess::GetGlobal()) {
+ profile_manager_(TestingBrowserProcess::GetGlobal()),
+ install_attributes_("example.com",
+ "user@example.com",
+ "device_id",
+ DEVICE_MODE_ENTERPRISE) {
}
DeviceCloudPolicyInvalidatorTest::~DeviceCloudPolicyInvalidatorTest() {
@@ -83,9 +125,34 @@ void DeviceCloudPolicyInvalidatorTest::SetUp() {
TestingBrowserProcess::GetGlobal()->SetSystemRequestContext(
system_request_context_.get());
ASSERT_TRUE(profile_manager_.SetUp());
+
test_device_settings_service_.reset(new
chromeos::ScopedTestDeviceSettingsService);
test_cros_settings_.reset(new chromeos::ScopedTestCrosSettings);
+ scoped_refptr<chromeos::MockOwnerKeyUtil> owner_key_util(
+ new chromeos::MockOwnerKeyUtil);
+ owner_key_util->SetPublicKeyFromPrivateKey(
+ *device_policy_.GetSigningKey());
+ chromeos::DeviceSettingsService::Get()->SetSessionManager(
+ &device_settings_test_helper_,
+ owner_key_util);
+
+ device_policy_.policy_data().set_invalidation_source(123);
+ device_policy_.policy_data().set_invalidation_name("invalidation");
+ device_policy_.Build();
+ device_settings_test_helper_.set_policy_blob(device_policy_.GetBlob());
+ device_settings_test_helper_.Flush();
+
+ scoped_ptr<MockCloudPolicyClient> policy_client(new MockCloudPolicyClient);
+ EXPECT_CALL(*policy_client, SetupRegistration("token", "device-id"));
+ CloudPolicyCore* core = TestingBrowserProcess::GetGlobal()->platform_part()->
+ browser_policy_connector_chromeos()->GetDeviceCloudPolicyManager()->
+ core();
+ core->Connect(policy_client.PassAs<CloudPolicyClient>());
+ core->StartRefreshScheduler();
+
+ invalidation::ProfileInvalidationProviderFactory::GetInstance()->
+ RegisterTestingFactory(BuildProfileInvalidationProvider);
invalidator_.reset(new DeviceCloudPolicyInvalidator);
}
@@ -94,6 +161,9 @@ void DeviceCloudPolicyInvalidatorTest::TearDown() {
invalidator_.reset();
base::RunLoop().RunUntilIdle();
+ invalidation::ProfileInvalidationProviderFactory::GetInstance()->
+ RegisterTestingFactory(NULL);
+ chromeos::DeviceSettingsService::Get()->UnsetSessionManager();
TestingBrowserProcess::GetGlobal()->SetBrowserPolicyConnector(NULL);
chromeos::DeviceOAuth2TokenServiceFactory::Shutdown();
chromeos::DBusThreadManager::Shutdown();
@@ -120,7 +190,7 @@ bool DeviceCloudPolicyInvalidatorTest::HasDeviceInvalidationServiceObserver(
return invalidator_->device_invalidation_service_observer_.get();
}
-invalidation::TiclInvalidationService*
+invalidation::FakeInvalidationService*
DeviceCloudPolicyInvalidatorTest::GetProfileInvalidationService(
Profile* profile) {
invalidation::ProfileInvalidationProvider* invalidation_provider =
@@ -129,7 +199,7 @@ DeviceCloudPolicyInvalidatorTest::GetProfileInvalidationService(
GetServiceForBrowserContext(profile, false));
if (!invalidation_provider)
return NULL;
- return static_cast<invalidation::TiclInvalidationService*>(
+ return static_cast<invalidation::FakeInvalidationService*>(
invalidation_provider->GetInvalidationService());
}
@@ -138,13 +208,13 @@ int DeviceCloudPolicyInvalidatorTest::
return invalidator_->profile_invalidation_service_observers_.size();
}
-const invalidation::TiclInvalidationService*
+const invalidation::InvalidationService*
DeviceCloudPolicyInvalidatorTest::GetInvalidationService() const {
- return static_cast<invalidation::TiclInvalidationService*>(
- invalidator_->invalidation_service_);
+ return invalidator_->invalidation_service_;
}
-bool DeviceCloudPolicyInvalidatorTest::HasCloudPolicyInvalidator() const {
+CloudPolicyInvalidator*
+DeviceCloudPolicyInvalidatorTest::GetCloudPolicyInvalidator() const {
return invalidator_->invalidator_.get();
}
@@ -158,7 +228,7 @@ void DeviceCloudPolicyInvalidatorTest::ConnectDeviceInvalidationService() {
EXPECT_EQ(0, GetProfileInvalidationServiceObserverCount());
// Verify that no invalidator exists yet
- EXPECT_FALSE(HasCloudPolicyInvalidator());
+ EXPECT_FALSE(GetCloudPolicyInvalidator());
EXPECT_FALSE(GetInvalidationService());
// Indicate that the device-global invalidation service has connected.
@@ -172,7 +242,7 @@ void DeviceCloudPolicyInvalidatorTest::ConnectDeviceInvalidationService() {
// Verify that an invalidator backed by the device-global invalidation service
// has been created.
- EXPECT_TRUE(HasCloudPolicyInvalidator());
+ EXPECT_TRUE(GetCloudPolicyInvalidator());
EXPECT_EQ(GetDeviceInvalidationService(), GetInvalidationService());
}
@@ -195,7 +265,7 @@ TEST_F(DeviceCloudPolicyInvalidatorTest, UseDeviceInvalidationService) {
EXPECT_TRUE(HasDeviceInvalidationServiceObserver());
// Verify that the invalidator has been destroyed.
- EXPECT_FALSE(HasCloudPolicyInvalidator());
+ EXPECT_FALSE(GetCloudPolicyInvalidator());
EXPECT_FALSE(GetInvalidationService());
}
@@ -212,19 +282,18 @@ TEST_F(DeviceCloudPolicyInvalidatorTest, UseProfileInvalidationService) {
EXPECT_TRUE(HasDeviceInvalidationServiceObserver());
// Verify that a per-profile invalidation service has been created.
- invalidation::TiclInvalidationService* profile_invalidation_service =
+ invalidation::FakeInvalidationService* profile_invalidation_service =
GetProfileInvalidationService(profile);
ASSERT_TRUE(profile_invalidation_service);
EXPECT_EQ(1, GetProfileInvalidationServiceObserverCount());
// Verify that no invalidator exists yet
- EXPECT_FALSE(HasCloudPolicyInvalidator());
+ EXPECT_FALSE(GetCloudPolicyInvalidator());
EXPECT_FALSE(GetInvalidationService());
// Indicate that the per-profile invalidation service has connected.
- profile_invalidation_service->OnInvalidatorStateChange(
+ profile_invalidation_service->SetInvalidatorState(
syncer::INVALIDATIONS_ENABLED);
- base::RunLoop().RunUntilIdle();
// Verify that the device-global invalidator has been destroyed.
EXPECT_FALSE(GetDeviceInvalidationService());
@@ -237,13 +306,12 @@ TEST_F(DeviceCloudPolicyInvalidatorTest, UseProfileInvalidationService) {
// Verify that an invalidator backed by the per-profile invalidation service
// has been created.
- EXPECT_TRUE(HasCloudPolicyInvalidator());
+ EXPECT_TRUE(GetCloudPolicyInvalidator());
EXPECT_EQ(profile_invalidation_service, GetInvalidationService());
// Indicate that the per-profile invalidation service has disconnected.
- profile_invalidation_service->OnInvalidatorStateChange(
+ profile_invalidation_service->SetInvalidatorState(
syncer::INVALIDATION_CREDENTIALS_REJECTED);
- base::RunLoop().RunUntilIdle();
// Verify that a device-global invalidation service has been created.
EXPECT_TRUE(GetDeviceInvalidationService());
@@ -255,7 +323,7 @@ TEST_F(DeviceCloudPolicyInvalidatorTest, UseProfileInvalidationService) {
EXPECT_EQ(1, GetProfileInvalidationServiceObserverCount());
// Verify that the invalidator has been destroyed.
- EXPECT_FALSE(HasCloudPolicyInvalidator());
+ EXPECT_FALSE(GetCloudPolicyInvalidator());
EXPECT_FALSE(GetInvalidationService());
}
@@ -263,12 +331,26 @@ TEST_F(DeviceCloudPolicyInvalidatorTest, UseProfileInvalidationService) {
// invalidation service is available, automatically switching between
// device-global and per-profile invalidation services as they
// connect/disconnect, giving priority to per-profile invalidation services.
+// Also verifies that the highest handled invalidation version is preserved when
+// switching invalidation services.
TEST_F(DeviceCloudPolicyInvalidatorTest, SwitchInvalidationServices) {
+ CloudPolicyStore* store = static_cast<CloudPolicyStore*>(
+ TestingBrowserProcess::GetGlobal()->platform_part()->
+ browser_policy_connector_chromeos()->GetDeviceCloudPolicyManager()->
+ device_store());
+ ASSERT_TRUE(store);
+
// Verify that an invalidator backed by the device-global invalidation service
// is created when the service connects.
ConnectDeviceInvalidationService();
+ CloudPolicyInvalidator* invalidator = GetCloudPolicyInvalidator();
+ ASSERT_TRUE(invalidator);
ASSERT_TRUE(GetDeviceInvalidationService());
+ // Verify that the invalidator's highest handled invalidation version starts
+ // out as zero.
+ EXPECT_EQ(0, invalidator->highest_handled_invalidation_version());
+
// Create a first user profile.
Profile* profile_1 = CreateProfile("test_1");
ASSERT_TRUE(profile_1);
@@ -279,21 +361,20 @@ TEST_F(DeviceCloudPolicyInvalidatorTest, SwitchInvalidationServices) {
// Verify that a per-profile invalidation service has been created for the
// first user profile.
- invalidation::TiclInvalidationService* profile_1_invalidation_service =
+ invalidation::FakeInvalidationService* profile_1_invalidation_service =
GetProfileInvalidationService(profile_1);
ASSERT_TRUE(profile_1_invalidation_service);
EXPECT_EQ(1, GetProfileInvalidationServiceObserverCount());
// Verify that an invalidator backed by the device-global invalidation service
// still exists.
- EXPECT_TRUE(HasCloudPolicyInvalidator());
+ EXPECT_TRUE(GetCloudPolicyInvalidator());
EXPECT_EQ(GetDeviceInvalidationService(), GetInvalidationService());
// Indicate that the first user profile's per-profile invalidation service has
// connected.
- profile_1_invalidation_service->OnInvalidatorStateChange(
+ profile_1_invalidation_service->SetInvalidatorState(
syncer::INVALIDATIONS_ENABLED);
- base::RunLoop().RunUntilIdle();
// Verify that the device-global invalidator has been destroyed.
EXPECT_FALSE(GetDeviceInvalidationService());
@@ -307,9 +388,20 @@ TEST_F(DeviceCloudPolicyInvalidatorTest, SwitchInvalidationServices) {
// Verify that an invalidator backed by the per-profile invalidation service
// for the first user profile has been created.
- EXPECT_TRUE(HasCloudPolicyInvalidator());
+ invalidator = GetCloudPolicyInvalidator();
+ ASSERT_TRUE(invalidator);
EXPECT_EQ(profile_1_invalidation_service, GetInvalidationService());
+ // Verify that the invalidator's highest handled invalidation version starts
+ // out as zero.
+ EXPECT_EQ(0, invalidator->highest_handled_invalidation_version());
+
+ // Handle an invalidation with version 1. Verify that the invalidator's
+ // highest handled invalidation version is updated accordingly.
+ store->Store(device_policy_.policy(), 1);
+ invalidator->OnStoreLoaded(store);
+ EXPECT_EQ(1, invalidator->highest_handled_invalidation_version());
+
// Create a second user profile.
Profile* profile_2 = CreateProfile("test_2");
ASSERT_TRUE(profile_2);
@@ -322,21 +414,20 @@ TEST_F(DeviceCloudPolicyInvalidatorTest, SwitchInvalidationServices) {
// user profile and one has been created for the second user profile.
profile_1_invalidation_service = GetProfileInvalidationService(profile_1);
EXPECT_TRUE(profile_1_invalidation_service);
- invalidation::TiclInvalidationService* profile_2_invalidation_service =
+ invalidation::FakeInvalidationService* profile_2_invalidation_service =
GetProfileInvalidationService(profile_2);
ASSERT_TRUE(profile_2_invalidation_service);
EXPECT_EQ(2, GetProfileInvalidationServiceObserverCount());
// Verify that an invalidator backed by the per-profile invalidation service
// for the first user profile still exists.
- EXPECT_TRUE(HasCloudPolicyInvalidator());
+ EXPECT_TRUE(GetCloudPolicyInvalidator());
EXPECT_EQ(profile_1_invalidation_service, GetInvalidationService());
// Indicate that the second user profile's per-profile invalidation service
// has connected.
- profile_2_invalidation_service->OnInvalidatorStateChange(
+ profile_2_invalidation_service->SetInvalidatorState(
syncer::INVALIDATIONS_ENABLED);
- base::RunLoop().RunUntilIdle();
// Verify that the device-global invalidator still does not exist.
EXPECT_FALSE(GetDeviceInvalidationService());
@@ -352,14 +443,13 @@ TEST_F(DeviceCloudPolicyInvalidatorTest, SwitchInvalidationServices) {
// Verify that an invalidator backed by the per-profile invalidation service
// for the first user profile still exists.
- EXPECT_TRUE(HasCloudPolicyInvalidator());
+ EXPECT_TRUE(GetCloudPolicyInvalidator());
EXPECT_EQ(profile_1_invalidation_service, GetInvalidationService());
// Indicate that the per-profile invalidation service for the first user
// profile has disconnected.
- profile_1_invalidation_service->OnInvalidatorStateChange(
+ profile_1_invalidation_service->SetInvalidatorState(
syncer::INVALIDATION_CREDENTIALS_REJECTED);
- base::RunLoop().RunUntilIdle();
// Verify that the device-global invalidator still does not exist.
EXPECT_FALSE(GetDeviceInvalidationService());
@@ -375,14 +465,24 @@ TEST_F(DeviceCloudPolicyInvalidatorTest, SwitchInvalidationServices) {
// Verify that an invalidator backed by the per-profile invalidation service
// for the second user profile has been created.
- EXPECT_TRUE(HasCloudPolicyInvalidator());
+ invalidator = GetCloudPolicyInvalidator();
+ ASSERT_TRUE(invalidator);
EXPECT_EQ(profile_2_invalidation_service, GetInvalidationService());
+ // Verify that the invalidator's highest handled invalidation version starts
+ // out as 1.
+ EXPECT_EQ(1, invalidator->highest_handled_invalidation_version());
+
+ // Handle an invalidation with version 2. Verify that the invalidator's
+ // highest handled invalidation version is updated accordingly.
+ store->Store(device_policy_.policy(), 2);
+ invalidator->OnStoreLoaded(store);
+ EXPECT_EQ(2, invalidator->highest_handled_invalidation_version());
+
// Indicate that the per-profile invalidation service for the second user
// profile has disconnected.
- profile_2_invalidation_service->OnInvalidatorStateChange(
+ profile_2_invalidation_service->SetInvalidatorState(
syncer::INVALIDATION_CREDENTIALS_REJECTED);
- base::RunLoop().RunUntilIdle();
// Verify that a device-global invalidation service has been created.
ASSERT_TRUE(GetDeviceInvalidationService());
@@ -397,7 +497,7 @@ TEST_F(DeviceCloudPolicyInvalidatorTest, SwitchInvalidationServices) {
EXPECT_EQ(2, GetProfileInvalidationServiceObserverCount());
// Verify that the invalidator has been destroyed.
- EXPECT_FALSE(HasCloudPolicyInvalidator());
+ EXPECT_FALSE(GetCloudPolicyInvalidator());
EXPECT_FALSE(GetInvalidationService());
// Indicate that the device-global invalidation service has connected.
@@ -419,8 +519,13 @@ TEST_F(DeviceCloudPolicyInvalidatorTest, SwitchInvalidationServices) {
// Verify that an invalidator backed by the device-global invalidation service
// has been created.
- EXPECT_TRUE(HasCloudPolicyInvalidator());
+ invalidator = GetCloudPolicyInvalidator();
+ ASSERT_TRUE(invalidator);
EXPECT_EQ(GetDeviceInvalidationService(), GetInvalidationService());
+
+ // Verify that the invalidator's highest handled invalidation version starts
+ // out as 2.
+ EXPECT_EQ(2, invalidator->highest_handled_invalidation_version());
}
} // namespace policy

Powered by Google App Engine
This is Rietveld 408576698