OLD | NEW |
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/android_invalidator_bridge.h" | 5 #include "chrome/browser/sync/glue/android_invalidator_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/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 bridge_->StopForShutdown(); | 59 bridge_->StopForShutdown(); |
60 sync_thread_.Stop(); | 60 sync_thread_.Stop(); |
61 // Must be reset only after the sync thread is stopped. | 61 // Must be reset only after the sync thread is stopped. |
62 bridge_.reset(); | 62 bridge_.reset(); |
63 EXPECT_EQ(NULL, sync_handler_.get()); | 63 EXPECT_EQ(NULL, sync_handler_.get()); |
64 if (!sync_handler_notification_success_) | 64 if (!sync_handler_notification_success_) |
65 ADD_FAILURE() << "Sync handler did not receive proper notification."; | 65 ADD_FAILURE() << "Sync handler did not receive proper notification."; |
66 } | 66 } |
67 | 67 |
68 void VerifyAndDestroyObserver( | 68 void VerifyAndDestroyObserver( |
69 const syncer::ModelTypeInvalidationMap& expected_invalidations, | 69 const syncer::ModelTypeInvalidationMap& expected_invalidations) { |
70 syncer::IncomingInvalidationSource expected_source) { | |
71 ASSERT_TRUE(sync_thread_.message_loop_proxy()->PostTask( | 70 ASSERT_TRUE(sync_thread_.message_loop_proxy()->PostTask( |
72 FROM_HERE, | 71 FROM_HERE, |
73 base::Bind(&AndroidInvalidatorBridgeTest:: | 72 base::Bind(&AndroidInvalidatorBridgeTest:: |
74 VerifyAndDestroyObserverOnSyncThread, | 73 VerifyAndDestroyObserverOnSyncThread, |
75 base::Unretained(this), | 74 base::Unretained(this), |
76 expected_invalidations, | 75 expected_invalidations))); |
77 expected_source))); | |
78 BlockForSyncThread(); | 76 BlockForSyncThread(); |
79 } | 77 } |
80 | 78 |
81 void CreateObserver() { | 79 void CreateObserver() { |
82 ASSERT_TRUE(sync_thread_.message_loop_proxy()->PostTask( | 80 ASSERT_TRUE(sync_thread_.message_loop_proxy()->PostTask( |
83 FROM_HERE, | 81 FROM_HERE, |
84 base::Bind( | 82 base::Bind( |
85 &AndroidInvalidatorBridgeTest::CreateObserverOnSyncThread, | 83 &AndroidInvalidatorBridgeTest::CreateObserverOnSyncThread, |
86 base::Unretained(this)))); | 84 base::Unretained(this)))); |
87 BlockForSyncThread(); | 85 BlockForSyncThread(); |
(...skipping 16 matching lines...) Expand all Loading... |
104 content::NotificationService::current()->Notify( | 102 content::NotificationService::current()->Notify( |
105 type, | 103 type, |
106 content::Source<Profile>(&mock_profile_), | 104 content::Source<Profile>(&mock_profile_), |
107 content::Details<const syncer::ModelTypeInvalidationMap>( | 105 content::Details<const syncer::ModelTypeInvalidationMap>( |
108 &invalidation_map)); | 106 &invalidation_map)); |
109 BlockForSyncThread(); | 107 BlockForSyncThread(); |
110 } | 108 } |
111 | 109 |
112 private: | 110 private: |
113 void VerifyAndDestroyObserverOnSyncThread( | 111 void VerifyAndDestroyObserverOnSyncThread( |
114 const syncer::ModelTypeInvalidationMap& expected_invalidations, | 112 const syncer::ModelTypeInvalidationMap& expected_invalidations) { |
115 syncer::IncomingInvalidationSource expected_source) { | |
116 DCHECK(sync_thread_.message_loop_proxy()->RunsTasksOnCurrentThread()); | 113 DCHECK(sync_thread_.message_loop_proxy()->RunsTasksOnCurrentThread()); |
117 if (sync_handler_.get()) { | 114 if (sync_handler_.get()) { |
118 sync_handler_notification_success_ = | 115 sync_handler_notification_success_ = |
119 (sync_handler_->GetInvalidationCount() == 1) && | 116 (sync_handler_->GetInvalidationCount() == 1) && |
120 ObjectIdInvalidationMapEquals( | 117 ObjectIdInvalidationMapEquals( |
121 sync_handler_->GetLastInvalidationMap(), | 118 sync_handler_->GetLastInvalidationMap(), |
122 syncer::ModelTypeInvalidationMapToObjectIdInvalidationMap( | 119 syncer::ModelTypeInvalidationMapToObjectIdInvalidationMap( |
123 expected_invalidations)) && | 120 expected_invalidations)); |
124 (sync_handler_->GetLastInvalidationSource() == expected_source); | |
125 bridge_->UnregisterHandler(sync_handler_.get()); | 121 bridge_->UnregisterHandler(sync_handler_.get()); |
126 } else { | 122 } else { |
127 sync_handler_notification_success_ = false; | 123 sync_handler_notification_success_ = false; |
128 } | 124 } |
129 sync_handler_.reset(); | 125 sync_handler_.reset(); |
130 } | 126 } |
131 | 127 |
132 void CreateObserverOnSyncThread() { | 128 void CreateObserverOnSyncThread() { |
133 DCHECK(sync_thread_.message_loop_proxy()->RunsTasksOnCurrentThread()); | 129 DCHECK(sync_thread_.message_loop_proxy()->RunsTasksOnCurrentThread()); |
134 sync_handler_.reset(new syncer::FakeInvalidationHandler()); | 130 sync_handler_.reset(new syncer::FakeInvalidationHandler()); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 // invalidation, and ensures the bridge posts a REMOTE_INVALIDATION | 163 // invalidation, and ensures the bridge posts a REMOTE_INVALIDATION |
168 // with the proper state to it. | 164 // with the proper state to it. |
169 TEST_F(AndroidInvalidatorBridgeTest, RemoteNotification) { | 165 TEST_F(AndroidInvalidatorBridgeTest, RemoteNotification) { |
170 const syncer::ModelTypeSet types(syncer::SESSIONS); | 166 const syncer::ModelTypeSet types(syncer::SESSIONS); |
171 const syncer::ModelTypeInvalidationMap& invalidation_map = | 167 const syncer::ModelTypeInvalidationMap& invalidation_map = |
172 ModelTypeSetToInvalidationMap(types, std::string()); | 168 ModelTypeSetToInvalidationMap(types, std::string()); |
173 CreateObserver(); | 169 CreateObserver(); |
174 UpdateEnabledTypes(syncer::ModelTypeSet(syncer::SESSIONS)); | 170 UpdateEnabledTypes(syncer::ModelTypeSet(syncer::SESSIONS)); |
175 TriggerRefreshNotification(chrome::NOTIFICATION_SYNC_REFRESH_REMOTE, | 171 TriggerRefreshNotification(chrome::NOTIFICATION_SYNC_REFRESH_REMOTE, |
176 invalidation_map); | 172 invalidation_map); |
177 VerifyAndDestroyObserver(invalidation_map, syncer::REMOTE_INVALIDATION); | 173 VerifyAndDestroyObserver(invalidation_map); |
178 } | 174 } |
179 | 175 |
180 // Adds an observer on the sync thread, triggers a remote refresh | 176 // Adds an observer on the sync thread, triggers a remote refresh |
181 // notification with empty state map and ensures the bridge posts a | 177 // notification with empty state map and ensures the bridge posts a |
182 // REMOTE_INVALIDATION with the proper state to it. | 178 // REMOTE_INVALIDATION with the proper state to it. |
183 TEST_F(AndroidInvalidatorBridgeTest, RemoteNotificationEmptyPayloadMap) { | 179 TEST_F(AndroidInvalidatorBridgeTest, RemoteNotificationEmptyPayloadMap) { |
184 const syncer::ModelTypeSet enabled_types( | 180 const syncer::ModelTypeSet enabled_types( |
185 syncer::BOOKMARKS, syncer::TYPED_URLS); | 181 syncer::BOOKMARKS, syncer::TYPED_URLS); |
186 const syncer::ModelTypeInvalidationMap enabled_types_invalidation_map = | 182 const syncer::ModelTypeInvalidationMap enabled_types_invalidation_map = |
187 syncer::ModelTypeSetToInvalidationMap(enabled_types, std::string()); | 183 syncer::ModelTypeSetToInvalidationMap(enabled_types, std::string()); |
188 CreateObserver(); | 184 CreateObserver(); |
189 UpdateEnabledTypes(enabled_types); | 185 UpdateEnabledTypes(enabled_types); |
190 TriggerRefreshNotification(chrome::NOTIFICATION_SYNC_REFRESH_REMOTE, | 186 TriggerRefreshNotification(chrome::NOTIFICATION_SYNC_REFRESH_REMOTE, |
191 syncer::ModelTypeInvalidationMap()); | 187 syncer::ModelTypeInvalidationMap()); |
192 VerifyAndDestroyObserver( | 188 VerifyAndDestroyObserver(enabled_types_invalidation_map); |
193 enabled_types_invalidation_map, syncer::REMOTE_INVALIDATION); | |
194 } | 189 } |
195 | 190 |
196 } // namespace | 191 } // namespace |
197 } // namespace browser_sync | 192 } // namespace browser_sync |
OLD | NEW |