summaryrefslogtreecommitdiffstats
path: root/sync/notifier/invalidation_notifier_unittest.cc
diff options
context:
space:
mode:
authorakalin@chromium.org <akalin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-08-10 04:07:19 +0000
committerakalin@chromium.org <akalin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-08-10 04:07:19 +0000
commit6529382867932acbf83e49bc107fbe4ea28ad311 (patch)
tree9baba790501b4c0e95b59ca72b5c769ca5a28190 /sync/notifier/invalidation_notifier_unittest.cc
parentbfe14502edd281a935198917fc49e30fbef47792 (diff)
downloadchromium_src-6529382867932acbf83e49bc107fbe4ea28ad311.zip
chromium_src-6529382867932acbf83e49bc107fbe4ea28ad311.tar.gz
chromium_src-6529382867932acbf83e49bc107fbe4ea28ad311.tar.bz2
[Sync] Avoid unregistering object IDs on shutdown
Add RegisterHandler() and UnregisterHandler(), which should be called before and after calls to UpdateRegisteredIds(). Use UnregisterHandler() on shutdown instead of UpdateRegisteredIds(_, ObjectIdSet()). Make SyncNotifierHelper non-thread-safe. Fix test breakages that this revealed. Also add GetAllRegisteredIds() instead of making it the return value of UpdateRegisteredIds(). Propagate UpdateRegisteredIds()/RegisterHandler()/UnregisterHandler() all the way up to ProfileSyncService. Make FakeSyncManager be created on the sync thread. Clean up SyncBackendHost startup/shutdown behavior a bit. BUG=140325 Review URL: https://chromiumcodereview.appspot.com/10824161 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@150990 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'sync/notifier/invalidation_notifier_unittest.cc')
-rw-r--r--sync/notifier/invalidation_notifier_unittest.cc25
1 files changed, 13 insertions, 12 deletions
diff --git a/sync/notifier/invalidation_notifier_unittest.cc b/sync/notifier/invalidation_notifier_unittest.cc
index ded6bab..973c26f 100644
--- a/sync/notifier/invalidation_notifier_unittest.cc
+++ b/sync/notifier/invalidation_notifier_unittest.cc
@@ -33,11 +33,10 @@ class InvalidationNotifierTest : public testing::Test {
ResetNotifier();
}
- // Constructs an InvalidationNotifier, places it in
- // |invalidation_notifier_|, and adds |mock_observer_| as an observer. This
- // remains in place until either TearDown (automatic) or ResetNotifier
- // (manual) is called.
- void CreateAndObserveNotifier(
+ // Constructs an InvalidationNotifier, places it in |invalidation_notifier_|,
+ // and registers |mock_observer_| as a handler. This remains in place until
+ // either TearDown (automatic) or ResetNotifier (manual) is called.
+ void CreateNotifier(
const std::string& initial_invalidation_state) {
notifier::NotifierOptions notifier_options;
// Note: URLRequestContextGetters are ref-counted.
@@ -50,10 +49,11 @@ class InvalidationNotifierTest : public testing::Test {
initial_invalidation_state,
MakeWeakHandle(fake_tracker_.AsWeakPtr()),
"fake_client_info"));
+ invalidation_notifier_->RegisterHandler(&mock_observer_);
}
void ResetNotifier() {
- invalidation_notifier_->UpdateRegisteredIds(&mock_observer_, ObjectIdSet());
+ invalidation_notifier_->UnregisterHandler(&mock_observer_);
// Stopping the invalidation notifier stops its scheduler, which deletes any
// pending tasks without running them. Some tasks "run and delete" another
// task, so they must be run in order to avoid leaking the inner task.
@@ -79,13 +79,11 @@ class InvalidationNotifierTest : public testing::Test {
};
TEST_F(InvalidationNotifierTest, Basic) {
- CreateAndObserveNotifier("fake_state");
InSequence dummy;
- ModelTypeSet models(PREFERENCES, BOOKMARKS, AUTOFILL);
- invalidation_notifier_->UpdateRegisteredIds(
- &mock_observer_, ModelTypeSetToObjectIdSet(models));
+ CreateNotifier("fake_state");
+ const ModelTypeSet models(PREFERENCES, BOOKMARKS, AUTOFILL);
const ModelTypePayloadMap& type_payloads =
ModelTypePayloadMapFromEnumSet(models, "payload");
EXPECT_CALL(mock_observer_, OnNotificationsEnabled());
@@ -97,6 +95,9 @@ TEST_F(InvalidationNotifierTest, Basic) {
EXPECT_CALL(mock_observer_,
OnNotificationsDisabled(NOTIFICATION_CREDENTIALS_REJECTED));
+ invalidation_notifier_->UpdateRegisteredIds(
+ &mock_observer_, ModelTypeSetToObjectIdSet(models));
+
// TODO(tim): This call should be a no-op, Remove once bug 124140 and
// associated issues are fixed.
invalidation_notifier_->SetStateDeprecated("fake_state");
@@ -118,7 +119,7 @@ TEST_F(InvalidationNotifierTest, Basic) {
}
TEST_F(InvalidationNotifierTest, MigrateState) {
- CreateAndObserveNotifier(std::string());
+ CreateNotifier(std::string());
SetStateDeprecated("fake_state");
EXPECT_EQ("fake_state", fake_tracker_.GetInvalidationState());
@@ -130,7 +131,7 @@ TEST_F(InvalidationNotifierTest, MigrateState) {
// Pretend Chrome shut down.
ResetNotifier();
- CreateAndObserveNotifier("fake_state");
+ CreateNotifier("fake_state");
// Should do nothing.
SetStateDeprecated("more_spurious_fake_state");
EXPECT_EQ("fake_state", fake_tracker_.GetInvalidationState());