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

Unified Diff: sync/notifier/invalidation_notifier_unittest.cc

Issue 10824161: [Sync] Avoid unregistering object IDs on shutdown (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Use new API Created 8 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: sync/notifier/invalidation_notifier_unittest.cc
diff --git a/sync/notifier/invalidation_notifier_unittest.cc b/sync/notifier/invalidation_notifier_unittest.cc
index 4a076789b5501237b9b4c63c19a405ea45de2ffe..a1ec5f80e03d6a2ab0c5e01b6c6dda7ec05a1989 100644
--- a/sync/notifier/invalidation_notifier_unittest.cc
+++ b/sync/notifier/invalidation_notifier_unittest.cc
@@ -33,12 +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(
- const std::string& initial_invalidation_state) {
+ // Constructs an InvalidationNotifier and places it in
+ // |invalidation_notifier_|. 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.
notifier_options.request_context_getter =
@@ -50,10 +48,11 @@ class InvalidationNotifierTest : public testing::Test {
initial_invalidation_state,
MakeWeakHandle(mock_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.
@@ -71,13 +70,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());
@@ -88,6 +85,10 @@ TEST_F(InvalidationNotifierTest, Basic) {
OnNotificationsDisabled(TRANSIENT_NOTIFICATION_ERROR));
EXPECT_CALL(mock_observer_,
OnNotificationsDisabled(NOTIFICATION_CREDENTIALS_REJECTED));
+
+ invalidation_notifier_->UpdateRegisteredIds(
+ &mock_observer_, ModelTypeSetToObjectIdSet(models));
+
// Note no expectation on mock_tracker_, as we initialized with
// non-empty initial_invalidation_state above.
@@ -109,9 +110,10 @@ TEST_F(InvalidationNotifierTest, Basic) {
}
TEST_F(InvalidationNotifierTest, MigrateState) {
- CreateAndObserveNotifier(std::string());
InSequence dummy;
+ CreateNotifier(std::string());
+
EXPECT_CALL(mock_tracker_, SetInvalidationState("fake_state"));
invalidation_notifier_->SetStateDeprecated("fake_state");
@@ -121,7 +123,7 @@ TEST_F(InvalidationNotifierTest, MigrateState) {
// Pretend Chrome shut down.
ResetNotifier();
- CreateAndObserveNotifier("fake_state");
+ CreateNotifier("fake_state");
// Should do nothing.
invalidation_notifier_->SetStateDeprecated("more_spurious_fake_state");
}

Powered by Google App Engine
This is Rietveld 408576698