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

Side by Side Diff: chrome/browser/sync/glue/chrome_sync_notification_bridge_unittest.cc

Issue 10916131: [Invalidations] Add GetInvalidatorState() to Invalidator{,Frontend} (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix android Created 8 years, 3 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
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 "chrome/browser/sync/glue/chrome_sync_notification_bridge.h" 5 #include "chrome/browser/sync/glue/chrome_sync_notification_bridge.h"
6 6
7 #include <cstddef> 7 #include <cstddef>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 sync_thread_.Stop(); 62 sync_thread_.Stop();
63 // Must be reset only after the sync thread is stopped. 63 // Must be reset only after the sync thread is stopped.
64 bridge_.reset(); 64 bridge_.reset();
65 EXPECT_EQ(NULL, sync_handler_.get()); 65 EXPECT_EQ(NULL, sync_handler_.get());
66 if (!sync_handler_notification_success_) 66 if (!sync_handler_notification_success_)
67 ADD_FAILURE() << "Sync handler did not receive proper notification."; 67 ADD_FAILURE() << "Sync handler did not receive proper notification.";
68 } 68 }
69 69
70 void VerifyAndDestroyObserver( 70 void VerifyAndDestroyObserver(
71 const syncer::ModelTypeStateMap& expected_states, 71 const syncer::ModelTypeStateMap& expected_states,
72 syncer::IncomingNotificationSource expected_source) { 72 syncer::IncomingInvalidationSource expected_source) {
73 ASSERT_TRUE(sync_thread_.message_loop_proxy()->PostTask( 73 ASSERT_TRUE(sync_thread_.message_loop_proxy()->PostTask(
74 FROM_HERE, 74 FROM_HERE,
75 base::Bind(&ChromeSyncNotificationBridgeTest:: 75 base::Bind(&ChromeSyncNotificationBridgeTest::
76 VerifyAndDestroyObserverOnSyncThread, 76 VerifyAndDestroyObserverOnSyncThread,
77 base::Unretained(this), 77 base::Unretained(this),
78 expected_states, 78 expected_states,
79 expected_source))); 79 expected_source)));
80 BlockForSyncThread(); 80 BlockForSyncThread();
81 } 81 }
82 82
(...skipping 23 matching lines...) Expand all
106 content::NotificationService::current()->Notify( 106 content::NotificationService::current()->Notify(
107 type, 107 type,
108 content::Source<Profile>(&mock_profile_), 108 content::Source<Profile>(&mock_profile_),
109 content::Details<const syncer::ModelTypeStateMap>(&state_map)); 109 content::Details<const syncer::ModelTypeStateMap>(&state_map));
110 BlockForSyncThread(); 110 BlockForSyncThread();
111 } 111 }
112 112
113 private: 113 private:
114 void VerifyAndDestroyObserverOnSyncThread( 114 void VerifyAndDestroyObserverOnSyncThread(
115 const syncer::ModelTypeStateMap& expected_states, 115 const syncer::ModelTypeStateMap& expected_states,
116 syncer::IncomingNotificationSource expected_source) { 116 syncer::IncomingInvalidationSource expected_source) {
117 DCHECK(sync_thread_.message_loop_proxy()->RunsTasksOnCurrentThread()); 117 DCHECK(sync_thread_.message_loop_proxy()->RunsTasksOnCurrentThread());
118 if (sync_handler_.get()) { 118 if (sync_handler_.get()) {
119 sync_handler_notification_success_ = 119 sync_handler_notification_success_ =
120 (sync_handler_->GetNotificationCount() == 1) && 120 (sync_handler_->GetInvalidationCount() == 1) &&
121 ObjectIdStateMapEquals( 121 ObjectIdStateMapEquals(
122 sync_handler_->GetLastNotificationIdStateMap(), 122 sync_handler_->GetLastInvalidationIdStateMap(),
123 syncer::ModelTypeStateMapToObjectIdStateMap(expected_states)) && 123 syncer::ModelTypeStateMapToObjectIdStateMap(expected_states)) &&
124 (sync_handler_->GetLastNotificationSource() == expected_source); 124 (sync_handler_->GetLastInvalidationSource() == expected_source);
125 bridge_->UnregisterHandler(sync_handler_.get()); 125 bridge_->UnregisterHandler(sync_handler_.get());
126 } else { 126 } else {
127 sync_handler_notification_success_ = false; 127 sync_handler_notification_success_ = false;
128 } 128 }
129 sync_handler_.reset(); 129 sync_handler_.reset();
130 } 130 }
131 131
132 void CreateObserverOnSyncThread() { 132 void CreateObserverOnSyncThread() {
133 DCHECK(sync_thread_.message_loop_proxy()->RunsTasksOnCurrentThread()); 133 DCHECK(sync_thread_.message_loop_proxy()->RunsTasksOnCurrentThread());
134 sync_handler_.reset(new syncer::FakeInvalidationHandler()); 134 sync_handler_.reset(new syncer::FakeInvalidationHandler());
(...skipping 22 matching lines...) Expand all
157 content::TestBrowserThread ui_thread_; 157 content::TestBrowserThread ui_thread_;
158 base::Thread sync_thread_; 158 base::Thread sync_thread_;
159 NiceMock<ProfileMock> mock_profile_; 159 NiceMock<ProfileMock> mock_profile_;
160 // Created/used/destroyed on sync thread. 160 // Created/used/destroyed on sync thread.
161 scoped_ptr<syncer::FakeInvalidationHandler> sync_handler_; 161 scoped_ptr<syncer::FakeInvalidationHandler> sync_handler_;
162 bool sync_handler_notification_success_; 162 bool sync_handler_notification_success_;
163 scoped_ptr<ChromeSyncNotificationBridge> bridge_; 163 scoped_ptr<ChromeSyncNotificationBridge> bridge_;
164 }; 164 };
165 165
166 // Adds an observer on the sync thread, triggers a local refresh 166 // Adds an observer on the sync thread, triggers a local refresh
167 // notification, and ensures the bridge posts a LOCAL_NOTIFICATION 167 // invalidation, and ensures the bridge posts a LOCAL_INVALIDATION
168 // with the proper state to it. 168 // with the proper state to it.
169 TEST_F(ChromeSyncNotificationBridgeTest, LocalNotification) { 169 TEST_F(ChromeSyncNotificationBridgeTest, LocalNotification) {
170 syncer::ModelTypeStateMap state_map; 170 syncer::ModelTypeStateMap state_map;
171 state_map.insert( 171 state_map.insert(
172 std::make_pair(syncer::SESSIONS, syncer::InvalidationState())); 172 std::make_pair(syncer::SESSIONS, syncer::InvalidationState()));
173 CreateObserver(); 173 CreateObserver();
174 UpdateEnabledTypes(syncer::ModelTypeSet(syncer::SESSIONS)); 174 UpdateEnabledTypes(syncer::ModelTypeSet(syncer::SESSIONS));
175 TriggerRefreshNotification(chrome::NOTIFICATION_SYNC_REFRESH_LOCAL, 175 TriggerRefreshNotification(chrome::NOTIFICATION_SYNC_REFRESH_LOCAL,
176 state_map); 176 state_map);
177 VerifyAndDestroyObserver(state_map, syncer::LOCAL_NOTIFICATION); 177 VerifyAndDestroyObserver(state_map, syncer::LOCAL_INVALIDATION);
178 } 178 }
179 179
180 // Adds an observer on the sync thread, triggers a remote refresh 180 // Adds an observer on the sync thread, triggers a remote refresh
181 // notification, and ensures the bridge posts a REMOTE_NOTIFICATION 181 // invalidation, and ensures the bridge posts a REMOTE_INVALIDATION
182 // with the proper state to it. 182 // with the proper state to it.
183 TEST_F(ChromeSyncNotificationBridgeTest, RemoteNotification) { 183 TEST_F(ChromeSyncNotificationBridgeTest, RemoteNotification) {
184 syncer::ModelTypeStateMap state_map; 184 syncer::ModelTypeStateMap state_map;
185 state_map.insert( 185 state_map.insert(
186 std::make_pair(syncer::SESSIONS, syncer::InvalidationState())); 186 std::make_pair(syncer::SESSIONS, syncer::InvalidationState()));
187 CreateObserver(); 187 CreateObserver();
188 UpdateEnabledTypes(syncer::ModelTypeSet(syncer::SESSIONS)); 188 UpdateEnabledTypes(syncer::ModelTypeSet(syncer::SESSIONS));
189 TriggerRefreshNotification(chrome::NOTIFICATION_SYNC_REFRESH_REMOTE, 189 TriggerRefreshNotification(chrome::NOTIFICATION_SYNC_REFRESH_REMOTE,
190 state_map); 190 state_map);
191 VerifyAndDestroyObserver(state_map, syncer::REMOTE_NOTIFICATION); 191 VerifyAndDestroyObserver(state_map, syncer::REMOTE_INVALIDATION);
192 } 192 }
193 193
194 // Adds an observer on the sync thread, triggers a local refresh 194 // Adds an observer on the sync thread, triggers a local refresh
195 // notification with empty state map and ensures the bridge posts a 195 // notification with empty state map and ensures the bridge posts a
196 // LOCAL_NOTIFICATION with the proper state to it. 196 // LOCAL_INVALIDATION with the proper state to it.
197 TEST_F(ChromeSyncNotificationBridgeTest, LocalNotificationEmptyPayloadMap) { 197 TEST_F(ChromeSyncNotificationBridgeTest, LocalNotificationEmptyPayloadMap) {
198 const syncer::ModelTypeSet enabled_types( 198 const syncer::ModelTypeSet enabled_types(
199 syncer::BOOKMARKS, syncer::PASSWORDS); 199 syncer::BOOKMARKS, syncer::PASSWORDS);
200 const syncer::ModelTypeStateMap enabled_types_state_map = 200 const syncer::ModelTypeStateMap enabled_types_state_map =
201 syncer::ModelTypeSetToStateMap(enabled_types, std::string()); 201 syncer::ModelTypeSetToStateMap(enabled_types, std::string());
202 CreateObserver(); 202 CreateObserver();
203 UpdateEnabledTypes(enabled_types); 203 UpdateEnabledTypes(enabled_types);
204 TriggerRefreshNotification(chrome::NOTIFICATION_SYNC_REFRESH_LOCAL, 204 TriggerRefreshNotification(chrome::NOTIFICATION_SYNC_REFRESH_LOCAL,
205 syncer::ModelTypeStateMap()); 205 syncer::ModelTypeStateMap());
206 VerifyAndDestroyObserver( 206 VerifyAndDestroyObserver(
207 enabled_types_state_map, syncer::LOCAL_NOTIFICATION); 207 enabled_types_state_map, syncer::LOCAL_INVALIDATION);
208 } 208 }
209 209
210 // Adds an observer on the sync thread, triggers a remote refresh 210 // Adds an observer on the sync thread, triggers a remote refresh
211 // notification with empty state map and ensures the bridge posts a 211 // notification with empty state map and ensures the bridge posts a
212 // REMOTE_NOTIFICATION with the proper state to it. 212 // REMOTE_INVALIDATION with the proper state to it.
213 TEST_F(ChromeSyncNotificationBridgeTest, RemoteNotificationEmptyPayloadMap) { 213 TEST_F(ChromeSyncNotificationBridgeTest, RemoteNotificationEmptyPayloadMap) {
214 const syncer::ModelTypeSet enabled_types( 214 const syncer::ModelTypeSet enabled_types(
215 syncer::BOOKMARKS, syncer::TYPED_URLS); 215 syncer::BOOKMARKS, syncer::TYPED_URLS);
216 const syncer::ModelTypeStateMap enabled_types_state_map = 216 const syncer::ModelTypeStateMap enabled_types_state_map =
217 syncer::ModelTypeSetToStateMap(enabled_types, std::string()); 217 syncer::ModelTypeSetToStateMap(enabled_types, std::string());
218 CreateObserver(); 218 CreateObserver();
219 UpdateEnabledTypes(enabled_types); 219 UpdateEnabledTypes(enabled_types);
220 TriggerRefreshNotification(chrome::NOTIFICATION_SYNC_REFRESH_REMOTE, 220 TriggerRefreshNotification(chrome::NOTIFICATION_SYNC_REFRESH_REMOTE,
221 syncer::ModelTypeStateMap()); 221 syncer::ModelTypeStateMap());
222 VerifyAndDestroyObserver( 222 VerifyAndDestroyObserver(
223 enabled_types_state_map, syncer::REMOTE_NOTIFICATION); 223 enabled_types_state_map, syncer::REMOTE_INVALIDATION);
224 } 224 }
225 225
226 } // namespace 226 } // namespace
227 } // namespace browser_sync 227 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/glue/chrome_sync_notification_bridge.cc ('k') | chrome/browser/sync/glue/sync_backend_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698