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

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

Issue 11052007: Rename ModelType/ObjectIdStateMap to InvalidationMap. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 2 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"
11 #include "base/location.h" 11 #include "base/location.h"
12 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "base/message_loop.h" 14 #include "base/message_loop.h"
15 #include "base/message_loop_proxy.h" 15 #include "base/message_loop_proxy.h"
16 #include "base/run_loop.h" 16 #include "base/run_loop.h"
17 #include "base/sequenced_task_runner.h" 17 #include "base/sequenced_task_runner.h"
18 #include "base/threading/thread.h" 18 #include "base/threading/thread.h"
19 #include "chrome/common/chrome_notification_types.h" 19 #include "chrome/common/chrome_notification_types.h"
20 #include "chrome/test/base/profile_mock.h" 20 #include "chrome/test/base/profile_mock.h"
21 #include "content/public/browser/notification_details.h" 21 #include "content/public/browser/notification_details.h"
22 #include "content/public/browser/notification_service.h" 22 #include "content/public/browser/notification_service.h"
23 #include "content/public/test/test_browser_thread.h" 23 #include "content/public/test/test_browser_thread.h"
24 #include "sync/internal_api/public/base/model_type.h" 24 #include "sync/internal_api/public/base/model_type.h"
25 #include "sync/internal_api/public/base/model_type_state_map.h" 25 #include "sync/internal_api/public/base/model_type_invalidation_map.h"
26 #include "sync/notifier/fake_invalidation_handler.h" 26 #include "sync/notifier/fake_invalidation_handler.h"
27 #include "sync/notifier/object_id_state_map_test_util.h" 27 #include "sync/notifier/object_id_invalidation_map_test_util.h"
28 #include "testing/gmock/include/gmock/gmock.h" 28 #include "testing/gmock/include/gmock/gmock.h"
29 #include "testing/gtest/include/gtest/gtest.h" 29 #include "testing/gtest/include/gtest/gtest.h"
30 30
31 namespace browser_sync { 31 namespace browser_sync {
32 namespace { 32 namespace {
33 33
34 using ::testing::NiceMock; 34 using ::testing::NiceMock;
35 35
36 // Needed by BlockForSyncThread(). 36 // Needed by BlockForSyncThread().
37 void DoNothing() {} 37 void DoNothing() {}
(...skipping 23 matching lines...) Expand all
61 bridge_->StopForShutdown(); 61 bridge_->StopForShutdown();
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::ModelTypeInvalidationMap& expected_invalidations,
72 syncer::IncomingInvalidationSource 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_invalidations,
79 expected_source))); 79 expected_source)));
80 BlockForSyncThread(); 80 BlockForSyncThread();
81 } 81 }
82 82
83 void CreateObserver() { 83 void CreateObserver() {
84 ASSERT_TRUE(sync_thread_.message_loop_proxy()->PostTask( 84 ASSERT_TRUE(sync_thread_.message_loop_proxy()->PostTask(
85 FROM_HERE, 85 FROM_HERE,
86 base::Bind( 86 base::Bind(
87 &ChromeSyncNotificationBridgeTest::CreateObserverOnSyncThread, 87 &ChromeSyncNotificationBridgeTest::CreateObserverOnSyncThread,
88 base::Unretained(this)))); 88 base::Unretained(this))));
89 BlockForSyncThread(); 89 BlockForSyncThread();
90 } 90 }
91 91
92 void UpdateEnabledTypes(syncer::ModelTypeSet enabled_types) { 92 void UpdateEnabledTypes(syncer::ModelTypeSet enabled_types) {
93 ASSERT_TRUE(sync_thread_.message_loop_proxy()->PostTask( 93 ASSERT_TRUE(sync_thread_.message_loop_proxy()->PostTask(
94 FROM_HERE, 94 FROM_HERE,
95 base::Bind( 95 base::Bind(
96 &ChromeSyncNotificationBridgeTest:: 96 &ChromeSyncNotificationBridgeTest::
97 UpdateEnabledTypesOnSyncThread, 97 UpdateEnabledTypesOnSyncThread,
98 base::Unretained(this), 98 base::Unretained(this),
99 enabled_types))); 99 enabled_types)));
100 BlockForSyncThread(); 100 BlockForSyncThread();
101 } 101 }
102 102
103 void TriggerRefreshNotification( 103 void TriggerRefreshNotification(
104 int type, 104 int type,
105 const syncer::ModelTypeStateMap& state_map) { 105 const syncer::ModelTypeInvalidationMap& invalidation_map) {
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::ModelTypeInvalidationMap>(
110 &invalidation_map));
110 BlockForSyncThread(); 111 BlockForSyncThread();
111 } 112 }
112 113
113 private: 114 private:
114 void VerifyAndDestroyObserverOnSyncThread( 115 void VerifyAndDestroyObserverOnSyncThread(
115 const syncer::ModelTypeStateMap& expected_states, 116 const syncer::ModelTypeInvalidationMap& expected_invalidations,
116 syncer::IncomingInvalidationSource expected_source) { 117 syncer::IncomingInvalidationSource expected_source) {
117 DCHECK(sync_thread_.message_loop_proxy()->RunsTasksOnCurrentThread()); 118 DCHECK(sync_thread_.message_loop_proxy()->RunsTasksOnCurrentThread());
118 if (sync_handler_.get()) { 119 if (sync_handler_.get()) {
119 sync_handler_notification_success_ = 120 sync_handler_notification_success_ =
120 (sync_handler_->GetInvalidationCount() == 1) && 121 (sync_handler_->GetInvalidationCount() == 1) &&
121 ObjectIdStateMapEquals( 122 ObjectIdInvalidationMapEquals(
122 sync_handler_->GetLastInvalidationIdStateMap(), 123 sync_handler_->GetLastInvalidationMap(),
123 syncer::ModelTypeStateMapToObjectIdStateMap(expected_states)) && 124 syncer::ModelTypeInvalidationMapToObjectIdInvalidationMap(
125 expected_invalidations)) &&
124 (sync_handler_->GetLastInvalidationSource() == expected_source); 126 (sync_handler_->GetLastInvalidationSource() == expected_source);
125 bridge_->UnregisterHandler(sync_handler_.get()); 127 bridge_->UnregisterHandler(sync_handler_.get());
126 } else { 128 } else {
127 sync_handler_notification_success_ = false; 129 sync_handler_notification_success_ = false;
128 } 130 }
129 sync_handler_.reset(); 131 sync_handler_.reset();
130 } 132 }
131 133
132 void CreateObserverOnSyncThread() { 134 void CreateObserverOnSyncThread() {
133 DCHECK(sync_thread_.message_loop_proxy()->RunsTasksOnCurrentThread()); 135 DCHECK(sync_thread_.message_loop_proxy()->RunsTasksOnCurrentThread());
(...skipping 26 matching lines...) Expand all
160 // Created/used/destroyed on sync thread. 162 // Created/used/destroyed on sync thread.
161 scoped_ptr<syncer::FakeInvalidationHandler> sync_handler_; 163 scoped_ptr<syncer::FakeInvalidationHandler> sync_handler_;
162 bool sync_handler_notification_success_; 164 bool sync_handler_notification_success_;
163 scoped_ptr<ChromeSyncNotificationBridge> bridge_; 165 scoped_ptr<ChromeSyncNotificationBridge> bridge_;
164 }; 166 };
165 167
166 // Adds an observer on the sync thread, triggers a local refresh 168 // Adds an observer on the sync thread, triggers a local refresh
167 // invalidation, and ensures the bridge posts a LOCAL_INVALIDATION 169 // invalidation, and ensures the bridge posts a LOCAL_INVALIDATION
168 // with the proper state to it. 170 // with the proper state to it.
169 TEST_F(ChromeSyncNotificationBridgeTest, LocalNotification) { 171 TEST_F(ChromeSyncNotificationBridgeTest, LocalNotification) {
170 syncer::ModelTypeStateMap state_map; 172 const syncer::ModelTypeSet types(syncer::SESSIONS);
171 state_map.insert( 173 const syncer::ModelTypeInvalidationMap& invalidation_map =
172 std::make_pair(syncer::SESSIONS, syncer::InvalidationState())); 174 ModelTypeSetToInvalidationMap(types, std::string());
173 CreateObserver(); 175 CreateObserver();
174 UpdateEnabledTypes(syncer::ModelTypeSet(syncer::SESSIONS)); 176 UpdateEnabledTypes(syncer::ModelTypeSet(syncer::SESSIONS));
175 TriggerRefreshNotification(chrome::NOTIFICATION_SYNC_REFRESH_LOCAL, 177 TriggerRefreshNotification(chrome::NOTIFICATION_SYNC_REFRESH_LOCAL,
176 state_map); 178 invalidation_map);
177 VerifyAndDestroyObserver(state_map, syncer::LOCAL_INVALIDATION); 179 VerifyAndDestroyObserver(invalidation_map, syncer::LOCAL_INVALIDATION);
178 } 180 }
179 181
180 // Adds an observer on the sync thread, triggers a remote refresh 182 // Adds an observer on the sync thread, triggers a remote refresh
181 // invalidation, and ensures the bridge posts a REMOTE_INVALIDATION 183 // invalidation, and ensures the bridge posts a REMOTE_INVALIDATION
182 // with the proper state to it. 184 // with the proper state to it.
183 TEST_F(ChromeSyncNotificationBridgeTest, RemoteNotification) { 185 TEST_F(ChromeSyncNotificationBridgeTest, RemoteNotification) {
184 syncer::ModelTypeStateMap state_map; 186 const syncer::ModelTypeSet types(syncer::SESSIONS);
185 state_map.insert( 187 const syncer::ModelTypeInvalidationMap& invalidation_map =
186 std::make_pair(syncer::SESSIONS, syncer::InvalidationState())); 188 ModelTypeSetToInvalidationMap(types, std::string());
187 CreateObserver(); 189 CreateObserver();
188 UpdateEnabledTypes(syncer::ModelTypeSet(syncer::SESSIONS)); 190 UpdateEnabledTypes(syncer::ModelTypeSet(syncer::SESSIONS));
189 TriggerRefreshNotification(chrome::NOTIFICATION_SYNC_REFRESH_REMOTE, 191 TriggerRefreshNotification(chrome::NOTIFICATION_SYNC_REFRESH_REMOTE,
190 state_map); 192 invalidation_map);
191 VerifyAndDestroyObserver(state_map, syncer::REMOTE_INVALIDATION); 193 VerifyAndDestroyObserver(invalidation_map, syncer::REMOTE_INVALIDATION);
192 } 194 }
193 195
194 // Adds an observer on the sync thread, triggers a local refresh 196 // Adds an observer on the sync thread, triggers a local refresh
195 // notification with empty state map and ensures the bridge posts a 197 // notification with empty state map and ensures the bridge posts a
196 // LOCAL_INVALIDATION with the proper state to it. 198 // LOCAL_INVALIDATION with the proper state to it.
197 TEST_F(ChromeSyncNotificationBridgeTest, LocalNotificationEmptyPayloadMap) { 199 TEST_F(ChromeSyncNotificationBridgeTest, LocalNotificationEmptyPayloadMap) {
198 const syncer::ModelTypeSet enabled_types( 200 const syncer::ModelTypeSet enabled_types(
199 syncer::BOOKMARKS, syncer::PASSWORDS); 201 syncer::BOOKMARKS, syncer::PASSWORDS);
200 const syncer::ModelTypeStateMap enabled_types_state_map = 202 const syncer::ModelTypeInvalidationMap enabled_types_invalidation_map =
201 syncer::ModelTypeSetToStateMap(enabled_types, std::string()); 203 syncer::ModelTypeSetToInvalidationMap(enabled_types, std::string());
202 CreateObserver(); 204 CreateObserver();
203 UpdateEnabledTypes(enabled_types); 205 UpdateEnabledTypes(enabled_types);
204 TriggerRefreshNotification(chrome::NOTIFICATION_SYNC_REFRESH_LOCAL, 206 TriggerRefreshNotification(chrome::NOTIFICATION_SYNC_REFRESH_LOCAL,
205 syncer::ModelTypeStateMap()); 207 syncer::ModelTypeInvalidationMap());
206 VerifyAndDestroyObserver( 208 VerifyAndDestroyObserver(
207 enabled_types_state_map, syncer::LOCAL_INVALIDATION); 209 enabled_types_invalidation_map, syncer::LOCAL_INVALIDATION);
208 } 210 }
209 211
210 // Adds an observer on the sync thread, triggers a remote refresh 212 // Adds an observer on the sync thread, triggers a remote refresh
211 // notification with empty state map and ensures the bridge posts a 213 // notification with empty state map and ensures the bridge posts a
212 // REMOTE_INVALIDATION with the proper state to it. 214 // REMOTE_INVALIDATION with the proper state to it.
213 TEST_F(ChromeSyncNotificationBridgeTest, RemoteNotificationEmptyPayloadMap) { 215 TEST_F(ChromeSyncNotificationBridgeTest, RemoteNotificationEmptyPayloadMap) {
214 const syncer::ModelTypeSet enabled_types( 216 const syncer::ModelTypeSet enabled_types(
215 syncer::BOOKMARKS, syncer::TYPED_URLS); 217 syncer::BOOKMARKS, syncer::TYPED_URLS);
216 const syncer::ModelTypeStateMap enabled_types_state_map = 218 const syncer::ModelTypeInvalidationMap enabled_types_invalidation_map =
217 syncer::ModelTypeSetToStateMap(enabled_types, std::string()); 219 syncer::ModelTypeSetToInvalidationMap(enabled_types, std::string());
218 CreateObserver(); 220 CreateObserver();
219 UpdateEnabledTypes(enabled_types); 221 UpdateEnabledTypes(enabled_types);
220 TriggerRefreshNotification(chrome::NOTIFICATION_SYNC_REFRESH_REMOTE, 222 TriggerRefreshNotification(chrome::NOTIFICATION_SYNC_REFRESH_REMOTE,
221 syncer::ModelTypeStateMap()); 223 syncer::ModelTypeInvalidationMap());
222 VerifyAndDestroyObserver( 224 VerifyAndDestroyObserver(
223 enabled_types_state_map, syncer::REMOTE_INVALIDATION); 225 enabled_types_invalidation_map, syncer::REMOTE_INVALIDATION);
224 } 226 }
225 227
226 } // namespace 228 } // namespace
227 } // namespace browser_sync 229 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/glue/chrome_sync_notification_bridge.cc ('k') | chrome/browser/sync/glue/session_change_processor.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698