summaryrefslogtreecommitdiffstats
path: root/sync/internal_api/sync_manager_impl_unittest.cc
diff options
context:
space:
mode:
authorrlarocque@chromium.org <rlarocque@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-06-25 01:47:46 +0000
committerrlarocque@chromium.org <rlarocque@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-06-25 01:47:46 +0000
commit1691f004283eca700aa101b784bdec5a8c3b24cb (patch)
tree51686e63df183d4ea60fb38be4400db97fedbf18 /sync/internal_api/sync_manager_impl_unittest.cc
parent9f9309fbb4f1ff34330a9ba3879011cad09f05e5 (diff)
downloadchromium_src-1691f004283eca700aa101b784bdec5a8c3b24cb.zip
chromium_src-1691f004283eca700aa101b784bdec5a8c3b24cb.tar.gz
chromium_src-1691f004283eca700aa101b784bdec5a8c3b24cb.tar.bz2
Revert 208315 "Make use of InvalidationService"
> Make use of InvalidationService > > The InvalidationService was introduced r199520. That commit added the > InvalidationService interface and several implementations of it, but > made no use of the new code. This commit builds on that work. > > Up until now, TICL invalidations were handled on the sync thread. The > related objects were instantiated and owned by the SyncBackendHost and > SyncManager. All requests to update the set of object registrations had > to be passed to the sync thread. Components that wanted to receive > invalidations but were not part of sync had to route their communication > with the invalidations server through ProfileSyncService to get to the > sync thread. Things were a bit different on Android, but the system > still tried to pretend that invalidations were owned by the sync thread. > > The new InvalidationService implementation is a ProfileKeyedService that > is mostly independent from sync. It still relies on sync to manage sign > in and fetch the appropriate auth tokens. However, it's now much easier > for components outside of sync to communication with the invalidations > server. > > The new system allows us to remove a lot of invalidations-related code > from the ProfileSyncService, SyncBackendHost and SyncManager. Sync is > now just one of many clients of the InvalidationService. The > SyncBackendHost is responsible for forwarding messages back and forth > between the InvalidationService and the sync thread. > > TBR=sky,erg > BUG=124137 > > Review URL: https://chromiumcodereview.appspot.com/15580002 TBR=rlarocque@chromium.org Review URL: https://codereview.chromium.org/17610004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@208347 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'sync/internal_api/sync_manager_impl_unittest.cc')
-rw-r--r--sync/internal_api/sync_manager_impl_unittest.cc62
1 files changed, 61 insertions, 1 deletions
diff --git a/sync/internal_api/sync_manager_impl_unittest.cc b/sync/internal_api/sync_manager_impl_unittest.cc
index 2085ec3..a1ddd7f 100644
--- a/sync/internal_api/sync_manager_impl_unittest.cc
+++ b/sync/internal_api/sync_manager_impl_unittest.cc
@@ -46,6 +46,7 @@
#include "sync/js/js_reply_handler.h"
#include "sync/js/js_test_util.h"
#include "sync/notifier/fake_invalidation_handler.h"
+#include "sync/notifier/fake_invalidator.h"
#include "sync/notifier/invalidation_handler.h"
#include "sync/notifier/invalidator.h"
#include "sync/protocol/bookmark_specifics.pb.h"
@@ -788,12 +789,14 @@ class SyncManagerTest : public testing::Test,
};
SyncManagerTest()
- : sync_manager_("Test sync manager") {
+ : fake_invalidator_(NULL),
+ sync_manager_("Test sync manager") {
switches_.encryption_method =
InternalComponentsFactory::ENCRYPTION_KEYSTORE;
}
virtual ~SyncManagerTest() {
+ EXPECT_FALSE(fake_invalidator_);
}
// Test implementation.
@@ -804,6 +807,8 @@ class SyncManagerTest : public testing::Test,
credentials.email = "foo@bar.com";
credentials.sync_token = "sometoken";
+ fake_invalidator_ = new FakeInvalidator();
+
sync_manager_.AddObserver(&manager_observer_);
EXPECT_CALL(manager_observer_, OnInitializationComplete(_, _, _, _)).
WillOnce(SaveArg<0>(&js_backend_));
@@ -826,6 +831,7 @@ class SyncManagerTest : public testing::Test,
&extensions_activity_monitor_,
this,
credentials,
+ scoped_ptr<Invalidator>(fake_invalidator_),
"fake_invalidator_client_id",
std::string(),
std::string(), // bootstrap tokens
@@ -845,11 +851,17 @@ class SyncManagerTest : public testing::Test,
sync_manager_.GetUserShare(), i->first);
}
PumpLoop();
+
+ EXPECT_TRUE(fake_invalidator_->IsHandlerRegistered(&sync_manager_));
}
void TearDown() {
sync_manager_.RemoveObserver(&manager_observer_);
sync_manager_.ShutdownOnSyncThread();
+ // We can't assert that |sync_manager_| isn't registered with
+ // |fake_invalidator_| anymore because |fake_invalidator_| is now
+ // destroyed.
+ fake_invalidator_ = NULL;
PumpLoop();
}
@@ -1015,6 +1027,7 @@ class SyncManagerTest : public testing::Test,
protected:
FakeEncryptor encryptor_;
TestUnrecoverableErrorHandler handler_;
+ FakeInvalidator* fake_invalidator_;
SyncManagerImpl sync_manager_;
WeakHandle<JsBackend> js_backend_;
StrictMock<SyncManagerObserverMock> manager_observer_;
@@ -1022,6 +1035,29 @@ class SyncManagerTest : public testing::Test,
InternalComponentsFactory::Switches switches_;
};
+TEST_F(SyncManagerTest, UpdateEnabledTypes) {
+ ModelSafeRoutingInfo routes;
+ GetModelSafeRoutingInfo(&routes);
+ const ModelTypeSet enabled_types = GetRoutingInfoTypes(routes);
+ sync_manager_.UpdateEnabledTypes(enabled_types);
+ EXPECT_EQ(ModelTypeSetToObjectIdSet(enabled_types),
+ fake_invalidator_->GetRegisteredIds(&sync_manager_));
+}
+
+TEST_F(SyncManagerTest, RegisterInvalidationHandler) {
+ FakeInvalidationHandler fake_handler;
+ sync_manager_.RegisterInvalidationHandler(&fake_handler);
+ EXPECT_TRUE(fake_invalidator_->IsHandlerRegistered(&fake_handler));
+
+ const ObjectIdSet& ids =
+ ModelTypeSetToObjectIdSet(ModelTypeSet(BOOKMARKS, PREFERENCES));
+ sync_manager_.UpdateRegisteredInvalidationIds(&fake_handler, ids);
+ EXPECT_EQ(ids, fake_invalidator_->GetRegisteredIds(&fake_handler));
+
+ sync_manager_.UnregisterInvalidationHandler(&fake_handler);
+ EXPECT_FALSE(fake_invalidator_->IsHandlerRegistered(&fake_handler));
+}
+
TEST_F(SyncManagerTest, ProcessJsMessage) {
const JsArgList kNoArgs;
@@ -1326,6 +1362,14 @@ TEST_F(SyncManagerTest, OnInvalidatorStateChangeJsEvents) {
base::DictionaryValue auth_error_details;
auth_error_details.SetString("status", "CONNECTION_AUTH_ERROR");
+ EXPECT_CALL(manager_observer_,
+ OnConnectionStatusChange(CONNECTION_AUTH_ERROR));
+
+ EXPECT_CALL(
+ event_handler,
+ HandleJsEvent("onConnectionStatusChange",
+ HasDetailsAsDictionary(auth_error_details)));
+
EXPECT_CALL(event_handler,
HandleJsEvent("onNotificationStateChange",
HasDetailsAsDictionary(enabled_details)));
@@ -1366,6 +1410,22 @@ TEST_F(SyncManagerTest, OnInvalidatorStateChangeJsEvents) {
PumpLoop();
}
+// Simulate the invalidator's credentials being rejected. That should
+// also clear the sync token.
+TEST_F(SyncManagerTest, OnInvalidatorStateChangeCredentialsRejected) {
+ EXPECT_CALL(manager_observer_,
+ OnConnectionStatusChange(CONNECTION_AUTH_ERROR));
+
+ EXPECT_FALSE(sync_manager_.GetHasInvalidAuthTokenForTest());
+
+ SimulateInvalidatorStateChangeForTest(INVALIDATION_CREDENTIALS_REJECTED);
+
+ EXPECT_TRUE(sync_manager_.GetHasInvalidAuthTokenForTest());
+
+ // Should trigger the replies.
+ PumpLoop();
+}
+
TEST_F(SyncManagerTest, OnIncomingNotification) {
StrictMock<MockJsEventHandler> event_handler;