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

Side by Side Diff: sync/notifier/invalidation_notifier_unittest.cc

Issue 10837214: Refactor ModelTypePayloadMap and ObjectIdPayloadMap to StateMaps. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix unit test 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « sync/notifier/invalidation_notifier.cc ('k') | sync/notifier/invalidation_util.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "sync/notifier/invalidation_notifier.h" 5 #include "sync/notifier/invalidation_notifier.h"
6 6
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "jingle/notifier/base/fake_base_task.h" 9 #include "jingle/notifier/base/fake_base_task.h"
10 #include "jingle/notifier/base/notifier_options.h" 10 #include "jingle/notifier/base/notifier_options.h"
11 #include "jingle/notifier/listener/fake_push_client.h" 11 #include "jingle/notifier/listener/fake_push_client.h"
12 #include "net/url_request/url_request_test_util.h" 12 #include "net/url_request/url_request_test_util.h"
13 #include "sync/internal_api/public/base/model_type.h" 13 #include "sync/internal_api/public/base/model_type.h"
14 #include "sync/internal_api/public/base/model_type_payload_map.h" 14 #include "sync/internal_api/public/base/model_type_state_map.h"
15 #include "sync/internal_api/public/util/weak_handle.h" 15 #include "sync/internal_api/public/util/weak_handle.h"
16 #include "sync/notifier/fake_invalidation_state_tracker.h" 16 #include "sync/notifier/fake_invalidation_state_tracker.h"
17 #include "sync/notifier/invalidation_state_tracker.h" 17 #include "sync/notifier/invalidation_state_tracker.h"
18 #include "sync/notifier/mock_sync_notifier_observer.h" 18 #include "sync/notifier/mock_sync_notifier_observer.h"
19 #include "sync/notifier/object_id_state_map_test_util.h"
19 #include "testing/gmock/include/gmock/gmock.h" 20 #include "testing/gmock/include/gmock/gmock.h"
20 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
21 22
22 namespace syncer { 23 namespace syncer {
23 24
24 namespace { 25 namespace {
25 26
26 using ::testing::InSequence; 27 using ::testing::InSequence;
27 using ::testing::StrictMock; 28 using ::testing::StrictMock;
28 29
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 FakeInvalidationStateTracker fake_tracker_; 78 FakeInvalidationStateTracker fake_tracker_;
78 StrictMock<MockSyncNotifierObserver> mock_observer_; 79 StrictMock<MockSyncNotifierObserver> mock_observer_;
79 }; 80 };
80 81
81 TEST_F(InvalidationNotifierTest, Basic) { 82 TEST_F(InvalidationNotifierTest, Basic) {
82 InSequence dummy; 83 InSequence dummy;
83 84
84 CreateNotifier("fake_state"); 85 CreateNotifier("fake_state");
85 86
86 const ModelTypeSet models(PREFERENCES, BOOKMARKS, AUTOFILL); 87 const ModelTypeSet models(PREFERENCES, BOOKMARKS, AUTOFILL);
87 const ModelTypePayloadMap& type_payloads = 88 const ModelTypeStateMap& type_state_map =
88 ModelTypePayloadMapFromEnumSet(models, "payload"); 89 ModelTypeSetToStateMap(models, "payload");
89 EXPECT_CALL(mock_observer_, OnNotificationsEnabled()); 90 EXPECT_CALL(mock_observer_, OnNotificationsEnabled());
90 EXPECT_CALL(mock_observer_, OnIncomingNotification( 91 EXPECT_CALL(mock_observer_, OnIncomingNotification(
91 ModelTypePayloadMapToObjectIdPayloadMap(type_payloads), 92 ModelTypeStateMapToObjectIdStateMap(type_state_map),
92 REMOTE_NOTIFICATION)); 93 REMOTE_NOTIFICATION));
93 EXPECT_CALL(mock_observer_, 94 EXPECT_CALL(mock_observer_,
94 OnNotificationsDisabled(TRANSIENT_NOTIFICATION_ERROR)); 95 OnNotificationsDisabled(TRANSIENT_NOTIFICATION_ERROR));
95 EXPECT_CALL(mock_observer_, 96 EXPECT_CALL(mock_observer_,
96 OnNotificationsDisabled(NOTIFICATION_CREDENTIALS_REJECTED)); 97 OnNotificationsDisabled(NOTIFICATION_CREDENTIALS_REJECTED));
97 98
98 invalidation_notifier_->UpdateRegisteredIds( 99 invalidation_notifier_->UpdateRegisteredIds(
99 &mock_observer_, ModelTypeSetToObjectIdSet(models)); 100 &mock_observer_, ModelTypeSetToObjectIdSet(models));
100 101
101 // TODO(tim): This call should be a no-op, Remove once bug 124140 and 102 // TODO(tim): This call should be a no-op, Remove once bug 124140 and
102 // associated issues are fixed. 103 // associated issues are fixed.
103 invalidation_notifier_->SetStateDeprecated("fake_state"); 104 invalidation_notifier_->SetStateDeprecated("fake_state");
104 // We don't expect |fake_tracker_|'s state to change, as we 105 // We don't expect |fake_tracker_|'s state to change, as we
105 // initialized with non-empty initial_invalidation_state above. 106 // initialized with non-empty initial_invalidation_state above.
106 EXPECT_TRUE(fake_tracker_.GetInvalidationState().empty()); 107 EXPECT_TRUE(fake_tracker_.GetInvalidationState().empty());
107 invalidation_notifier_->SetUniqueId("fake_id"); 108 invalidation_notifier_->SetUniqueId("fake_id");
108 invalidation_notifier_->UpdateCredentials("foo@bar.com", "fake_token"); 109 invalidation_notifier_->UpdateCredentials("foo@bar.com", "fake_token");
109 110
110 invalidation_notifier_->OnNotificationsEnabled(); 111 invalidation_notifier_->OnNotificationsEnabled();
111 112
112 invalidation_notifier_->OnInvalidate( 113 invalidation_notifier_->OnInvalidate(
113 ModelTypePayloadMapToObjectIdPayloadMap(type_payloads)); 114 ModelTypeStateMapToObjectIdStateMap(type_state_map));
114 115
115 invalidation_notifier_->OnNotificationsDisabled( 116 invalidation_notifier_->OnNotificationsDisabled(
116 TRANSIENT_NOTIFICATION_ERROR); 117 TRANSIENT_NOTIFICATION_ERROR);
117 invalidation_notifier_->OnNotificationsDisabled( 118 invalidation_notifier_->OnNotificationsDisabled(
118 NOTIFICATION_CREDENTIALS_REJECTED); 119 NOTIFICATION_CREDENTIALS_REJECTED);
119 } 120 }
120 121
121 TEST_F(InvalidationNotifierTest, MigrateState) { 122 TEST_F(InvalidationNotifierTest, MigrateState) {
122 CreateNotifier(std::string()); 123 CreateNotifier(std::string());
123 124
124 SetStateDeprecated("fake_state"); 125 SetStateDeprecated("fake_state");
125 EXPECT_EQ("fake_state", fake_tracker_.GetInvalidationState()); 126 EXPECT_EQ("fake_state", fake_tracker_.GetInvalidationState());
126 127
127 // Should do nothing. 128 // Should do nothing.
128 SetStateDeprecated("spurious_fake_state"); 129 SetStateDeprecated("spurious_fake_state");
129 EXPECT_EQ("fake_state", fake_tracker_.GetInvalidationState()); 130 EXPECT_EQ("fake_state", fake_tracker_.GetInvalidationState());
130 131
131 // Pretend Chrome shut down. 132 // Pretend Chrome shut down.
132 ResetNotifier(); 133 ResetNotifier();
133 134
134 CreateNotifier("fake_state"); 135 CreateNotifier("fake_state");
135 // Should do nothing. 136 // Should do nothing.
136 SetStateDeprecated("more_spurious_fake_state"); 137 SetStateDeprecated("more_spurious_fake_state");
137 EXPECT_EQ("fake_state", fake_tracker_.GetInvalidationState()); 138 EXPECT_EQ("fake_state", fake_tracker_.GetInvalidationState());
138 } 139 }
139 140
140 } // namespace 141 } // namespace
141 142
142 } // namespace syncer 143 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/notifier/invalidation_notifier.cc ('k') | sync/notifier/invalidation_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698