| 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 "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
| 7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
| 8 #include "base/string_number_conversions.h" | 8 #include "base/string_number_conversions.h" |
| 9 #include "chrome/browser/extensions/app_notification.h" | 9 #include "chrome/browser/extensions/app_notification.h" |
| 10 #include "chrome/browser/extensions/app_notification_manager.h" | 10 #include "chrome/browser/extensions/app_notification_manager.h" |
| 11 #include "chrome/test/base/testing_profile.h" | 11 #include "chrome/test/base/testing_profile.h" |
| 12 #include "content/public/test/test_browser_thread.h" | 12 #include "content/public/test/test_browser_thread.h" |
| 13 #include "sync/api/sync_error_factory.h" | 13 #include "sync/api/sync_error_factory.h" |
| 14 #include "sync/api/sync_error_factory_mock.h" | 14 #include "sync/api/sync_error_factory_mock.h" |
| 15 #include "sync/protocol/app_notification_specifics.pb.h" | 15 #include "sync/protocol/app_notification_specifics.pb.h" |
| 16 #include "sync/protocol/sync.pb.h" | 16 #include "sync/protocol/sync.pb.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 18 | 18 |
| 19 using content::BrowserThread; | 19 using content::BrowserThread; |
| 20 using ::testing::_; | 20 using ::testing::_; |
| 21 using ::testing::Return; | 21 using ::testing::Return; |
| 22 | 22 |
| 23 namespace { | 23 namespace { |
| 24 | 24 |
| 25 // Extract notification guid from SyncData. | 25 // Extract notification guid from csync::SyncData. |
| 26 std::string GetGuid(const SyncData& sync_data) { | 26 std::string GetGuid(const csync::SyncData& sync_data) { |
| 27 return sync_data.GetSpecifics().app_notification().guid(); | 27 return sync_data.GetSpecifics().app_notification().guid(); |
| 28 } | 28 } |
| 29 | 29 |
| 30 // Dummy SyncChangeProcessor used to help review what SyncChanges are pushed | 30 // Dummy SyncChangeProcessor used to help review what SyncChanges are pushed |
| 31 // back up to Sync. | 31 // back up to Sync. |
| 32 class TestChangeProcessor : public SyncChangeProcessor { | 32 class TestChangeProcessor : public csync::SyncChangeProcessor { |
| 33 public: | 33 public: |
| 34 TestChangeProcessor() { } | 34 TestChangeProcessor() { } |
| 35 virtual ~TestChangeProcessor() { } | 35 virtual ~TestChangeProcessor() { } |
| 36 | 36 |
| 37 // Store a copy of all the changes passed in so we can examine them later. | 37 // Store a copy of all the changes passed in so we can examine them later. |
| 38 virtual SyncError ProcessSyncChanges( | 38 virtual csync::SyncError ProcessSyncChanges( |
| 39 const tracked_objects::Location& from_here, | 39 const tracked_objects::Location& from_here, |
| 40 const SyncChangeList& change_list) { | 40 const csync::SyncChangeList& change_list) { |
| 41 // change_map_.erase(change_map_.begin(), change_map_.end()); | 41 // change_map_.erase(change_map_.begin(), change_map_.end()); |
| 42 for (SyncChangeList::const_iterator iter = change_list.begin(); | 42 for (csync::SyncChangeList::const_iterator iter = change_list.begin(); |
| 43 iter != change_list.end(); ++iter) { | 43 iter != change_list.end(); ++iter) { |
| 44 change_map_[GetGuid(iter->sync_data())] = *iter; | 44 change_map_[GetGuid(iter->sync_data())] = *iter; |
| 45 } | 45 } |
| 46 | 46 |
| 47 return SyncError(); | 47 return csync::SyncError(); |
| 48 } | 48 } |
| 49 | 49 |
| 50 bool ContainsGuid(const std::string& guid) { | 50 bool ContainsGuid(const std::string& guid) { |
| 51 return change_map_.find(guid) != change_map_.end(); | 51 return change_map_.find(guid) != change_map_.end(); |
| 52 } | 52 } |
| 53 | 53 |
| 54 SyncChange GetChangeByGuid(const std::string& guid) { | 54 csync::SyncChange GetChangeByGuid(const std::string& guid) { |
| 55 DCHECK(ContainsGuid(guid)); | 55 DCHECK(ContainsGuid(guid)); |
| 56 return change_map_[guid]; | 56 return change_map_[guid]; |
| 57 } | 57 } |
| 58 | 58 |
| 59 size_t change_list_size() { return change_map_.size(); } | 59 size_t change_list_size() { return change_map_.size(); } |
| 60 | 60 |
| 61 private: | 61 private: |
| 62 // Track the changes received in ProcessSyncChanges. | 62 // Track the changes received in ProcessSyncChanges. |
| 63 std::map<std::string, SyncChange> change_map_; | 63 std::map<std::string, csync::SyncChange> change_map_; |
| 64 | 64 |
| 65 DISALLOW_COPY_AND_ASSIGN(TestChangeProcessor); | 65 DISALLOW_COPY_AND_ASSIGN(TestChangeProcessor); |
| 66 }; | 66 }; |
| 67 | 67 |
| 68 class SyncChangeProcessorDelegate : public SyncChangeProcessor { | 68 class SyncChangeProcessorDelegate : public csync::SyncChangeProcessor { |
| 69 public: | 69 public: |
| 70 explicit SyncChangeProcessorDelegate(SyncChangeProcessor* recipient) | 70 explicit SyncChangeProcessorDelegate(csync::SyncChangeProcessor* recipient) |
| 71 : recipient_(recipient) { | 71 : recipient_(recipient) { |
| 72 DCHECK(recipient_); | 72 DCHECK(recipient_); |
| 73 } | 73 } |
| 74 virtual ~SyncChangeProcessorDelegate() {} | 74 virtual ~SyncChangeProcessorDelegate() {} |
| 75 | 75 |
| 76 // SyncChangeProcessor implementation. | 76 // csync::SyncChangeProcessor implementation. |
| 77 virtual SyncError ProcessSyncChanges( | 77 virtual csync::SyncError ProcessSyncChanges( |
| 78 const tracked_objects::Location& from_here, | 78 const tracked_objects::Location& from_here, |
| 79 const SyncChangeList& change_list) OVERRIDE { | 79 const csync::SyncChangeList& change_list) OVERRIDE { |
| 80 return recipient_->ProcessSyncChanges(from_here, change_list); | 80 return recipient_->ProcessSyncChanges(from_here, change_list); |
| 81 } | 81 } |
| 82 | 82 |
| 83 private: | 83 private: |
| 84 // The recipient of all sync changes. | 84 // The recipient of all sync changes. |
| 85 SyncChangeProcessor* recipient_; | 85 csync::SyncChangeProcessor* recipient_; |
| 86 | 86 |
| 87 DISALLOW_COPY_AND_ASSIGN(SyncChangeProcessorDelegate); | 87 DISALLOW_COPY_AND_ASSIGN(SyncChangeProcessorDelegate); |
| 88 }; | 88 }; |
| 89 | 89 |
| 90 } // namespace | 90 } // namespace |
| 91 | 91 |
| 92 class AppNotificationManagerSyncTest : public testing::Test { | 92 class AppNotificationManagerSyncTest : public testing::Test { |
| 93 public: | 93 public: |
| 94 AppNotificationManagerSyncTest() | 94 AppNotificationManagerSyncTest() |
| 95 : ui_thread_(BrowserThread::UI, &ui_loop_), | 95 : ui_thread_(BrowserThread::UI, &ui_loop_), |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 static void WaitForFileThread() { | 128 static void WaitForFileThread() { |
| 129 BrowserThread::PostTask(BrowserThread::FILE, | 129 BrowserThread::PostTask(BrowserThread::FILE, |
| 130 FROM_HERE, | 130 FROM_HERE, |
| 131 base::Bind(&PostQuitToUIThread)); | 131 base::Bind(&PostQuitToUIThread)); |
| 132 MessageLoop::current()->Run(); | 132 MessageLoop::current()->Run(); |
| 133 } | 133 } |
| 134 | 134 |
| 135 AppNotificationManager* model() { return model_.get(); } | 135 AppNotificationManager* model() { return model_.get(); } |
| 136 TestChangeProcessor* processor() { return sync_processor_.get(); } | 136 TestChangeProcessor* processor() { return sync_processor_.get(); } |
| 137 | 137 |
| 138 scoped_ptr<SyncChangeProcessor> PassProcessor() { | 138 scoped_ptr<csync::SyncChangeProcessor> PassProcessor() { |
| 139 return sync_processor_delegate_.PassAs<SyncChangeProcessor>(); | 139 return sync_processor_delegate_.PassAs<csync::SyncChangeProcessor>(); |
| 140 } | 140 } |
| 141 | 141 |
| 142 // Creates a notification whose properties are set from the given integer. | 142 // Creates a notification whose properties are set from the given integer. |
| 143 static AppNotification* CreateNotification(int suffix) { | 143 static AppNotification* CreateNotification(int suffix) { |
| 144 return CreateNotification(false, suffix); | 144 return CreateNotification(false, suffix); |
| 145 } | 145 } |
| 146 static AppNotification* CreateNotification(bool is_local, int suffix) { | 146 static AppNotification* CreateNotification(bool is_local, int suffix) { |
| 147 std::string s = base::IntToString(suffix); | 147 std::string s = base::IntToString(suffix); |
| 148 return CreateNotification( | 148 return CreateNotification( |
| 149 is_local, suffix, "guid" + s, "ext" + s, "text" + s, "body" + s, | 149 is_local, suffix, "guid" + s, "ext" + s, "text" + s, "body" + s, |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 AppNotification* notif = new AppNotification( | 181 AppNotification* notif = new AppNotification( |
| 182 is_local, base::Time::FromInternalValue(time), | 182 is_local, base::Time::FromInternalValue(time), |
| 183 guid, extension_id, title, body); | 183 guid, extension_id, title, body); |
| 184 if (!link_url.empty()) | 184 if (!link_url.empty()) |
| 185 notif->set_link_url(GURL(link_url)); | 185 notif->set_link_url(GURL(link_url)); |
| 186 if (!link_text.empty()) | 186 if (!link_text.empty()) |
| 187 notif->set_link_text(link_text); | 187 notif->set_link_text(link_text); |
| 188 return notif; | 188 return notif; |
| 189 } | 189 } |
| 190 | 190 |
| 191 static SyncData CreateSyncData(int suffix) { | 191 static csync::SyncData CreateSyncData(int suffix) { |
| 192 scoped_ptr<AppNotification> notif(CreateNotification(suffix)); | 192 scoped_ptr<AppNotification> notif(CreateNotification(suffix)); |
| 193 return AppNotificationManager::CreateSyncDataFromNotification(*notif); | 193 return AppNotificationManager::CreateSyncDataFromNotification(*notif); |
| 194 } | 194 } |
| 195 static SyncData CreateSyncData(int suffix, const std::string& extension_id) { | 195 static csync::SyncData CreateSyncData( |
| 196 int suffix, const std::string& extension_id) { |
| 196 scoped_ptr<AppNotification> notif( | 197 scoped_ptr<AppNotification> notif( |
| 197 CreateNotification(false, suffix, extension_id)); | 198 CreateNotification(false, suffix, extension_id)); |
| 198 return AppNotificationManager::CreateSyncDataFromNotification(*notif); | 199 return AppNotificationManager::CreateSyncDataFromNotification(*notif); |
| 199 } | 200 } |
| 200 | 201 |
| 201 // Helper to create SyncChange. Takes ownership of |notif|. | 202 // Helper to create csync::SyncChange. Takes ownership of |notif|. |
| 202 static SyncChange CreateSyncChange(SyncChange::SyncChangeType type, | 203 static csync::SyncChange CreateSyncChange( |
| 203 AppNotification* notif) { | 204 csync::SyncChange::SyncChangeType type, |
| 205 AppNotification* notif) { |
| 204 // Take control of notif to clean it up after we create data out of it. | 206 // Take control of notif to clean it up after we create data out of it. |
| 205 scoped_ptr<AppNotification> scoped_notif(notif); | 207 scoped_ptr<AppNotification> scoped_notif(notif); |
| 206 return SyncChange( | 208 return csync::SyncChange( |
| 207 type, AppNotificationManager::CreateSyncDataFromNotification(*notif)); | 209 type, AppNotificationManager::CreateSyncDataFromNotification(*notif)); |
| 208 } | 210 } |
| 209 | 211 |
| 210 void AssertSyncChange(const SyncChange& change, | 212 void AssertSyncChange(const csync::SyncChange& change, |
| 211 SyncChange::SyncChangeType type, | 213 csync::SyncChange::SyncChangeType type, |
| 212 const AppNotification& notif) { | 214 const AppNotification& notif) { |
| 213 ASSERT_EQ(type, change.change_type()); | 215 ASSERT_EQ(type, change.change_type()); |
| 214 scoped_ptr<AppNotification> notif2( | 216 scoped_ptr<AppNotification> notif2( |
| 215 AppNotificationManager::CreateNotificationFromSyncData( | 217 AppNotificationManager::CreateNotificationFromSyncData( |
| 216 change.sync_data())); | 218 change.sync_data())); |
| 217 ASSERT_TRUE(notif.Equals(*notif2)); | 219 ASSERT_TRUE(notif.Equals(*notif2)); |
| 218 } | 220 } |
| 219 | 221 |
| 220 protected: | 222 protected: |
| 221 MessageLoop ui_loop_; | 223 MessageLoop ui_loop_; |
| 222 content::TestBrowserThread ui_thread_; | 224 content::TestBrowserThread ui_thread_; |
| 223 content::TestBrowserThread file_thread_; | 225 content::TestBrowserThread file_thread_; |
| 224 | 226 |
| 225 // We keep two TemplateURLServices to test syncing between them. | 227 // We keep two TemplateURLServices to test syncing between them. |
| 226 ScopedTempDir temp_dir_; | 228 ScopedTempDir temp_dir_; |
| 227 scoped_ptr<TestingProfile> profile_; | 229 scoped_ptr<TestingProfile> profile_; |
| 228 scoped_refptr<AppNotificationManager> model_; | 230 scoped_refptr<AppNotificationManager> model_; |
| 229 | 231 |
| 230 scoped_ptr<TestChangeProcessor> sync_processor_; | 232 scoped_ptr<TestChangeProcessor> sync_processor_; |
| 231 scoped_ptr<SyncChangeProcessorDelegate> sync_processor_delegate_; | 233 scoped_ptr<SyncChangeProcessorDelegate> sync_processor_delegate_; |
| 232 | 234 |
| 233 DISALLOW_COPY_AND_ASSIGN(AppNotificationManagerSyncTest); | 235 DISALLOW_COPY_AND_ASSIGN(AppNotificationManagerSyncTest); |
| 234 }; | 236 }; |
| 235 | 237 |
| 236 // Create an AppNotification, convert it to SyncData and convert it back. | 238 // Create an AppNotification, convert it to csync::SyncData and convert it back. |
| 237 TEST_F(AppNotificationManagerSyncTest, NotificationToSyncDataToNotification) { | 239 TEST_F(AppNotificationManagerSyncTest, NotificationToSyncDataToNotification) { |
| 238 { // Partial properties set. | 240 { // Partial properties set. |
| 239 scoped_ptr<AppNotification> notif1(CreateNotificationNoLink(1)); | 241 scoped_ptr<AppNotification> notif1(CreateNotificationNoLink(1)); |
| 240 SyncData sync_data = | 242 csync::SyncData sync_data = |
| 241 AppNotificationManager::CreateSyncDataFromNotification(*notif1); | 243 AppNotificationManager::CreateSyncDataFromNotification(*notif1); |
| 242 scoped_ptr<AppNotification> notif2( | 244 scoped_ptr<AppNotification> notif2( |
| 243 AppNotificationManager::CreateNotificationFromSyncData(sync_data)); | 245 AppNotificationManager::CreateNotificationFromSyncData(sync_data)); |
| 244 EXPECT_TRUE(notif2.get()); | 246 EXPECT_TRUE(notif2.get()); |
| 245 EXPECT_TRUE(notif1->Equals(*notif2)); | 247 EXPECT_TRUE(notif1->Equals(*notif2)); |
| 246 } | 248 } |
| 247 { // All properties set. | 249 { // All properties set. |
| 248 scoped_ptr<AppNotification> notif1(CreateNotification(1)); | 250 scoped_ptr<AppNotification> notif1(CreateNotification(1)); |
| 249 SyncData sync_data = | 251 csync::SyncData sync_data = |
| 250 AppNotificationManager::CreateSyncDataFromNotification(*notif1); | 252 AppNotificationManager::CreateSyncDataFromNotification(*notif1); |
| 251 scoped_ptr<AppNotification> notif2( | 253 scoped_ptr<AppNotification> notif2( |
| 252 AppNotificationManager::CreateNotificationFromSyncData(sync_data)); | 254 AppNotificationManager::CreateNotificationFromSyncData(sync_data)); |
| 253 EXPECT_TRUE(notif2.get()); | 255 EXPECT_TRUE(notif2.get()); |
| 254 EXPECT_TRUE(notif1->Equals(*notif2)); | 256 EXPECT_TRUE(notif1->Equals(*notif2)); |
| 255 } | 257 } |
| 256 } | 258 } |
| 257 | 259 |
| 258 // GetAllSyncData returns all notifications since none are marked local only. | 260 // GetAllSyncData returns all notifications since none are marked local only. |
| 259 TEST_F(AppNotificationManagerSyncTest, GetAllSyncDataNoLocal) { | 261 TEST_F(AppNotificationManagerSyncTest, GetAllSyncDataNoLocal) { |
| 260 model()->Add(CreateNotificationNoLink(1)); | 262 model()->Add(CreateNotificationNoLink(1)); |
| 261 model()->Add(CreateNotification(2)); | 263 model()->Add(CreateNotification(2)); |
| 262 model()->Add(CreateNotification(3)); | 264 model()->Add(CreateNotification(3)); |
| 263 SyncDataList all_sync_data = | 265 csync::SyncDataList all_sync_data = |
| 264 model()->GetAllSyncData(syncable::APP_NOTIFICATIONS); | 266 model()->GetAllSyncData(syncable::APP_NOTIFICATIONS); |
| 265 | 267 |
| 266 EXPECT_EQ(3U, all_sync_data.size()); | 268 EXPECT_EQ(3U, all_sync_data.size()); |
| 267 | 269 |
| 268 for (SyncDataList::const_iterator iter = all_sync_data.begin(); | 270 for (csync::SyncDataList::const_iterator iter = all_sync_data.begin(); |
| 269 iter != all_sync_data.end(); ++iter) { | 271 iter != all_sync_data.end(); ++iter) { |
| 270 scoped_ptr<AppNotification> notif1( | 272 scoped_ptr<AppNotification> notif1( |
| 271 AppNotificationManager::CreateNotificationFromSyncData(*iter)); | 273 AppNotificationManager::CreateNotificationFromSyncData(*iter)); |
| 272 | 274 |
| 273 const std::string& guid = notif1->guid(); | 275 const std::string& guid = notif1->guid(); |
| 274 const std::string& ext_id = notif1->extension_id(); | 276 const std::string& ext_id = notif1->extension_id(); |
| 275 | 277 |
| 276 const AppNotification* notif2 = model()->GetNotification(ext_id, guid); | 278 const AppNotification* notif2 = model()->GetNotification(ext_id, guid); |
| 277 ASSERT_TRUE(notif1->Equals(*notif2)); | 279 ASSERT_TRUE(notif1->Equals(*notif2)); |
| 278 } | 280 } |
| 279 } | 281 } |
| 280 | 282 |
| 281 // GetAllSyncData should not return notifications marked as local only. | 283 // GetAllSyncData should not return notifications marked as local only. |
| 282 TEST_F(AppNotificationManagerSyncTest, GetAllSyncDataSomeLocal) { | 284 TEST_F(AppNotificationManagerSyncTest, GetAllSyncDataSomeLocal) { |
| 283 model()->Add(CreateNotificationNoLink(1)); | 285 model()->Add(CreateNotificationNoLink(1)); |
| 284 model()->Add(CreateNotification(true, 2)); | 286 model()->Add(CreateNotification(true, 2)); |
| 285 model()->Add(CreateNotification(3)); | 287 model()->Add(CreateNotification(3)); |
| 286 model()->Add(CreateNotification(true, 4)); | 288 model()->Add(CreateNotification(true, 4)); |
| 287 model()->Add(CreateNotification(5)); | 289 model()->Add(CreateNotification(5)); |
| 288 SyncDataList all_sync_data = | 290 csync::SyncDataList all_sync_data = |
| 289 model()->GetAllSyncData(syncable::APP_NOTIFICATIONS); | 291 model()->GetAllSyncData(syncable::APP_NOTIFICATIONS); |
| 290 | 292 |
| 291 EXPECT_EQ(3U, all_sync_data.size()); | 293 EXPECT_EQ(3U, all_sync_data.size()); |
| 292 | 294 |
| 293 for (SyncDataList::const_iterator iter = all_sync_data.begin(); | 295 for (csync::SyncDataList::const_iterator iter = all_sync_data.begin(); |
| 294 iter != all_sync_data.end(); ++iter) { | 296 iter != all_sync_data.end(); ++iter) { |
| 295 scoped_ptr<AppNotification> notif1( | 297 scoped_ptr<AppNotification> notif1( |
| 296 AppNotificationManager::CreateNotificationFromSyncData(*iter)); | 298 AppNotificationManager::CreateNotificationFromSyncData(*iter)); |
| 297 const std::string& guid = notif1->guid(); | 299 const std::string& guid = notif1->guid(); |
| 298 const std::string& ext_id = notif1->extension_id(); | 300 const std::string& ext_id = notif1->extension_id(); |
| 299 | 301 |
| 300 const AppNotification* notif2 = model()->GetNotification(ext_id, guid); | 302 const AppNotification* notif2 = model()->GetNotification(ext_id, guid); |
| 301 ASSERT_TRUE(notif1->Equals(*notif2)); | 303 ASSERT_TRUE(notif1->Equals(*notif2)); |
| 302 } | 304 } |
| 303 } | 305 } |
| 304 | 306 |
| 305 // Model assocation: both models are empty. | 307 // Model assocation: both models are empty. |
| 306 TEST_F(AppNotificationManagerSyncTest, ModelAssocBothEmpty) { | 308 TEST_F(AppNotificationManagerSyncTest, ModelAssocBothEmpty) { |
| 307 model()->MergeDataAndStartSyncing( | 309 model()->MergeDataAndStartSyncing( |
| 308 syncable::APP_NOTIFICATIONS, | 310 syncable::APP_NOTIFICATIONS, |
| 309 SyncDataList(), // Empty. | 311 csync::SyncDataList(), // Empty. |
| 310 PassProcessor(), | 312 PassProcessor(), |
| 311 scoped_ptr<SyncErrorFactory>(new SyncErrorFactoryMock())); | 313 scoped_ptr<csync::SyncErrorFactory>(new csync::SyncErrorFactoryMock())); |
| 312 | 314 |
| 313 EXPECT_EQ(0U, model()->GetAllSyncData(syncable::APP_NOTIFICATIONS).size()); | 315 EXPECT_EQ(0U, model()->GetAllSyncData(syncable::APP_NOTIFICATIONS).size()); |
| 314 EXPECT_EQ(0U, processor()->change_list_size()); | 316 EXPECT_EQ(0U, processor()->change_list_size()); |
| 315 } | 317 } |
| 316 | 318 |
| 317 // Model assocation: empty sync model and non-empty local model. | 319 // Model assocation: empty sync model and non-empty local model. |
| 318 TEST_F(AppNotificationManagerSyncTest, ModelAssocModelEmpty) { | 320 TEST_F(AppNotificationManagerSyncTest, ModelAssocModelEmpty) { |
| 319 SyncDataList initial_data; | 321 csync::SyncDataList initial_data; |
| 320 initial_data.push_back(CreateSyncData(1)); | 322 initial_data.push_back(CreateSyncData(1)); |
| 321 initial_data.push_back(CreateSyncData(2)); | 323 initial_data.push_back(CreateSyncData(2)); |
| 322 initial_data.push_back(CreateSyncData(3)); | 324 initial_data.push_back(CreateSyncData(3)); |
| 323 initial_data.push_back(CreateSyncData(4)); | 325 initial_data.push_back(CreateSyncData(4)); |
| 324 | 326 |
| 325 model()->MergeDataAndStartSyncing( | 327 model()->MergeDataAndStartSyncing( |
| 326 syncable::APP_NOTIFICATIONS, | 328 syncable::APP_NOTIFICATIONS, |
| 327 initial_data, | 329 initial_data, |
| 328 PassProcessor(), | 330 PassProcessor(), |
| 329 scoped_ptr<SyncErrorFactory>(new SyncErrorFactoryMock())); | 331 scoped_ptr<csync::SyncErrorFactory>(new csync::SyncErrorFactoryMock())); |
| 330 | 332 |
| 331 EXPECT_EQ(4U, model()->GetAllSyncData(syncable::APP_NOTIFICATIONS).size()); | 333 EXPECT_EQ(4U, model()->GetAllSyncData(syncable::APP_NOTIFICATIONS).size()); |
| 332 // Model should all of the initial sync data. | 334 // Model should all of the initial sync data. |
| 333 for (SyncDataList::const_iterator iter = initial_data.begin(); | 335 for (csync::SyncDataList::const_iterator iter = initial_data.begin(); |
| 334 iter != initial_data.end(); ++iter) { | 336 iter != initial_data.end(); ++iter) { |
| 335 scoped_ptr<AppNotification> notif1( | 337 scoped_ptr<AppNotification> notif1( |
| 336 AppNotificationManager::CreateNotificationFromSyncData(*iter)); | 338 AppNotificationManager::CreateNotificationFromSyncData(*iter)); |
| 337 const std::string& ext_id = notif1->extension_id(); | 339 const std::string& ext_id = notif1->extension_id(); |
| 338 const std::string& guid = notif1->guid(); | 340 const std::string& guid = notif1->guid(); |
| 339 const AppNotification* notif2 = model()->GetNotification(ext_id, guid); | 341 const AppNotification* notif2 = model()->GetNotification(ext_id, guid); |
| 340 EXPECT_TRUE(notif2); | 342 EXPECT_TRUE(notif2); |
| 341 EXPECT_TRUE(notif1->Equals(*notif2)); | 343 EXPECT_TRUE(notif1->Equals(*notif2)); |
| 342 } | 344 } |
| 343 | 345 |
| 344 EXPECT_EQ(0U, processor()->change_list_size()); | 346 EXPECT_EQ(0U, processor()->change_list_size()); |
| 345 } | 347 } |
| 346 | 348 |
| 347 // Model has some notifications, some of them are local only. Sync has some | 349 // Model has some notifications, some of them are local only. Sync has some |
| 348 // notifications. No items match up. | 350 // notifications. No items match up. |
| 349 TEST_F(AppNotificationManagerSyncTest, ModelAssocBothNonEmptyNoOverlap) { | 351 TEST_F(AppNotificationManagerSyncTest, ModelAssocBothNonEmptyNoOverlap) { |
| 350 AppNotification* n1 = CreateNotification(1); | 352 AppNotification* n1 = CreateNotification(1); |
| 351 model()->Add(n1); | 353 model()->Add(n1); |
| 352 AppNotification* n2 = CreateNotification(true, 2); | 354 AppNotification* n2 = CreateNotification(true, 2); |
| 353 model()->Add(n2); | 355 model()->Add(n2); |
| 354 AppNotification* n3 = CreateNotification(3); | 356 AppNotification* n3 = CreateNotification(3); |
| 355 model()->Add(n3); | 357 model()->Add(n3); |
| 356 | 358 |
| 357 SyncDataList initial_data; | 359 csync::SyncDataList initial_data; |
| 358 initial_data.push_back(CreateSyncData(4)); | 360 initial_data.push_back(CreateSyncData(4)); |
| 359 initial_data.push_back(CreateSyncData(5)); | 361 initial_data.push_back(CreateSyncData(5)); |
| 360 initial_data.push_back(CreateSyncData(6)); | 362 initial_data.push_back(CreateSyncData(6)); |
| 361 initial_data.push_back(CreateSyncData(7)); | 363 initial_data.push_back(CreateSyncData(7)); |
| 362 | 364 |
| 363 model()->MergeDataAndStartSyncing( | 365 model()->MergeDataAndStartSyncing( |
| 364 syncable::APP_NOTIFICATIONS, | 366 syncable::APP_NOTIFICATIONS, |
| 365 initial_data, | 367 initial_data, |
| 366 PassProcessor(), | 368 PassProcessor(), |
| 367 scoped_ptr<SyncErrorFactory>(new SyncErrorFactoryMock())); | 369 scoped_ptr<csync::SyncErrorFactory>(new csync::SyncErrorFactoryMock())); |
| 368 | 370 |
| 369 EXPECT_EQ(6U, model()->GetAllSyncData(syncable::APP_NOTIFICATIONS).size()); | 371 EXPECT_EQ(6U, model()->GetAllSyncData(syncable::APP_NOTIFICATIONS).size()); |
| 370 for (SyncDataList::const_iterator iter = initial_data.begin(); | 372 for (csync::SyncDataList::const_iterator iter = initial_data.begin(); |
| 371 iter != initial_data.end(); ++iter) { | 373 iter != initial_data.end(); ++iter) { |
| 372 scoped_ptr<AppNotification> notif1( | 374 scoped_ptr<AppNotification> notif1( |
| 373 AppNotificationManager::CreateNotificationFromSyncData(*iter)); | 375 AppNotificationManager::CreateNotificationFromSyncData(*iter)); |
| 374 const std::string& ext_id = notif1->extension_id(); | 376 const std::string& ext_id = notif1->extension_id(); |
| 375 const std::string& guid = notif1->guid(); | 377 const std::string& guid = notif1->guid(); |
| 376 const AppNotification* notif2 = model()->GetNotification(ext_id, guid); | 378 const AppNotification* notif2 = model()->GetNotification(ext_id, guid); |
| 377 EXPECT_TRUE(notif2); | 379 EXPECT_TRUE(notif2); |
| 378 EXPECT_TRUE(notif1->Equals(*notif2)); | 380 EXPECT_TRUE(notif1->Equals(*notif2)); |
| 379 } | 381 } |
| 380 EXPECT_TRUE(model()->GetNotification(n1->extension_id(), n1->guid())); | 382 EXPECT_TRUE(model()->GetNotification(n1->extension_id(), n1->guid())); |
| 381 EXPECT_TRUE(model()->GetNotification(n2->extension_id(), n2->guid())); | 383 EXPECT_TRUE(model()->GetNotification(n2->extension_id(), n2->guid())); |
| 382 EXPECT_TRUE(model()->GetNotification(n3->extension_id(), n3->guid())); | 384 EXPECT_TRUE(model()->GetNotification(n3->extension_id(), n3->guid())); |
| 383 | 385 |
| 384 EXPECT_EQ(2U, processor()->change_list_size()); | 386 EXPECT_EQ(2U, processor()->change_list_size()); |
| 385 EXPECT_TRUE(processor()->ContainsGuid(n1->guid())); | 387 EXPECT_TRUE(processor()->ContainsGuid(n1->guid())); |
| 386 EXPECT_EQ(SyncChange::ACTION_ADD, | 388 EXPECT_EQ(csync::SyncChange::ACTION_ADD, |
| 387 processor()->GetChangeByGuid(n1->guid()).change_type()); | 389 processor()->GetChangeByGuid(n1->guid()).change_type()); |
| 388 EXPECT_FALSE(processor()->ContainsGuid(n2->guid())); | 390 EXPECT_FALSE(processor()->ContainsGuid(n2->guid())); |
| 389 EXPECT_TRUE(processor()->ContainsGuid(n3->guid())); | 391 EXPECT_TRUE(processor()->ContainsGuid(n3->guid())); |
| 390 EXPECT_EQ(SyncChange::ACTION_ADD, | 392 EXPECT_EQ(csync::SyncChange::ACTION_ADD, |
| 391 processor()->GetChangeByGuid(n3->guid()).change_type()); | 393 processor()->GetChangeByGuid(n3->guid()).change_type()); |
| 392 } | 394 } |
| 393 | 395 |
| 394 // Model has some notifications, some of them are local only. Sync has some | 396 // Model has some notifications, some of them are local only. Sync has some |
| 395 // notifications. Some items match up. | 397 // notifications. Some items match up. |
| 396 TEST_F(AppNotificationManagerSyncTest, ModelAssocBothNonEmptySomeOverlap) { | 398 TEST_F(AppNotificationManagerSyncTest, ModelAssocBothNonEmptySomeOverlap) { |
| 397 AppNotification* n1 = CreateNotification(1); | 399 AppNotification* n1 = CreateNotification(1); |
| 398 model()->Add(n1); | 400 model()->Add(n1); |
| 399 AppNotification* n2 = CreateNotification(true, 2); | 401 AppNotification* n2 = CreateNotification(true, 2); |
| 400 model()->Add(n2); | 402 model()->Add(n2); |
| 401 AppNotification* n3 = CreateNotification(3); | 403 AppNotification* n3 = CreateNotification(3); |
| 402 model()->Add(n3); | 404 model()->Add(n3); |
| 403 AppNotification* n4 = CreateNotification(4); | 405 AppNotification* n4 = CreateNotification(4); |
| 404 model()->Add(n4); | 406 model()->Add(n4); |
| 405 | 407 |
| 406 SyncDataList initial_data; | 408 csync::SyncDataList initial_data; |
| 407 initial_data.push_back(CreateSyncData(5)); | 409 initial_data.push_back(CreateSyncData(5)); |
| 408 initial_data.push_back( | 410 initial_data.push_back( |
| 409 AppNotificationManager::CreateSyncDataFromNotification(*n1)); | 411 AppNotificationManager::CreateSyncDataFromNotification(*n1)); |
| 410 initial_data.push_back(CreateSyncData(6)); | 412 initial_data.push_back(CreateSyncData(6)); |
| 411 initial_data.push_back( | 413 initial_data.push_back( |
| 412 AppNotificationManager::CreateSyncDataFromNotification(*n4)); | 414 AppNotificationManager::CreateSyncDataFromNotification(*n4)); |
| 413 initial_data.push_back(CreateSyncData(7)); | 415 initial_data.push_back(CreateSyncData(7)); |
| 414 | 416 |
| 415 model()->MergeDataAndStartSyncing( | 417 model()->MergeDataAndStartSyncing( |
| 416 syncable::APP_NOTIFICATIONS, | 418 syncable::APP_NOTIFICATIONS, |
| 417 initial_data, | 419 initial_data, |
| 418 PassProcessor(), | 420 PassProcessor(), |
| 419 scoped_ptr<SyncErrorFactory>(new SyncErrorFactoryMock())); | 421 scoped_ptr<csync::SyncErrorFactory>(new csync::SyncErrorFactoryMock())); |
| 420 | 422 |
| 421 EXPECT_EQ(6U, model()->GetAllSyncData(syncable::APP_NOTIFICATIONS).size()); | 423 EXPECT_EQ(6U, model()->GetAllSyncData(syncable::APP_NOTIFICATIONS).size()); |
| 422 for (SyncDataList::const_iterator iter = initial_data.begin(); | 424 for (csync::SyncDataList::const_iterator iter = initial_data.begin(); |
| 423 iter != initial_data.end(); ++iter) { | 425 iter != initial_data.end(); ++iter) { |
| 424 scoped_ptr<AppNotification> notif1( | 426 scoped_ptr<AppNotification> notif1( |
| 425 AppNotificationManager::CreateNotificationFromSyncData(*iter)); | 427 AppNotificationManager::CreateNotificationFromSyncData(*iter)); |
| 426 const std::string& ext_id = notif1->extension_id(); | 428 const std::string& ext_id = notif1->extension_id(); |
| 427 const std::string& guid = notif1->guid(); | 429 const std::string& guid = notif1->guid(); |
| 428 const AppNotification* notif2 = model()->GetNotification(ext_id, guid); | 430 const AppNotification* notif2 = model()->GetNotification(ext_id, guid); |
| 429 EXPECT_TRUE(notif2); | 431 EXPECT_TRUE(notif2); |
| 430 EXPECT_TRUE(notif1->Equals(*notif2)); | 432 EXPECT_TRUE(notif1->Equals(*notif2)); |
| 431 } | 433 } |
| 432 EXPECT_TRUE(model()->GetNotification(n1->extension_id(), n1->guid())); | 434 EXPECT_TRUE(model()->GetNotification(n1->extension_id(), n1->guid())); |
| 433 EXPECT_TRUE(model()->GetNotification(n2->extension_id(), n2->guid())); | 435 EXPECT_TRUE(model()->GetNotification(n2->extension_id(), n2->guid())); |
| 434 EXPECT_TRUE(model()->GetNotification(n3->extension_id(), n3->guid())); | 436 EXPECT_TRUE(model()->GetNotification(n3->extension_id(), n3->guid())); |
| 435 EXPECT_TRUE(model()->GetNotification(n4->extension_id(), n4->guid())); | 437 EXPECT_TRUE(model()->GetNotification(n4->extension_id(), n4->guid())); |
| 436 | 438 |
| 437 EXPECT_EQ(1U, processor()->change_list_size()); | 439 EXPECT_EQ(1U, processor()->change_list_size()); |
| 438 EXPECT_FALSE(processor()->ContainsGuid(n1->guid())); | 440 EXPECT_FALSE(processor()->ContainsGuid(n1->guid())); |
| 439 EXPECT_FALSE(processor()->ContainsGuid(n2->guid())); | 441 EXPECT_FALSE(processor()->ContainsGuid(n2->guid())); |
| 440 EXPECT_TRUE(processor()->ContainsGuid(n3->guid())); | 442 EXPECT_TRUE(processor()->ContainsGuid(n3->guid())); |
| 441 EXPECT_EQ(SyncChange::ACTION_ADD, | 443 EXPECT_EQ(csync::SyncChange::ACTION_ADD, |
| 442 processor()->GetChangeByGuid(n3->guid()).change_type()); | 444 processor()->GetChangeByGuid(n3->guid()).change_type()); |
| 443 EXPECT_FALSE(processor()->ContainsGuid(n4->guid())); | 445 EXPECT_FALSE(processor()->ContainsGuid(n4->guid())); |
| 444 } | 446 } |
| 445 | 447 |
| 446 // When an item that matches up in model and sync is different, an error | 448 // When an item that matches up in model and sync is different, an error |
| 447 // should be returned. | 449 // should be returned. |
| 448 TEST_F(AppNotificationManagerSyncTest, ModelAssocBothNonEmptyTitleMismatch) { | 450 TEST_F(AppNotificationManagerSyncTest, ModelAssocBothNonEmptyTitleMismatch) { |
| 449 AppNotification* n1 = CreateNotification(1); | 451 AppNotification* n1 = CreateNotification(1); |
| 450 model()->Add(n1); | 452 model()->Add(n1); |
| 451 AppNotification* n2 = CreateNotification(true, 2); | 453 AppNotification* n2 = CreateNotification(true, 2); |
| 452 model()->Add(n2); | 454 model()->Add(n2); |
| 453 | 455 |
| 454 SyncDataList initial_data; | 456 csync::SyncDataList initial_data; |
| 455 initial_data.push_back(CreateSyncData(1)); | 457 initial_data.push_back(CreateSyncData(1)); |
| 456 scoped_ptr<AppNotification> n1_a(CreateNotification( | 458 scoped_ptr<AppNotification> n1_a(CreateNotification( |
| 457 n1->is_local(), n1->creation_time().ToInternalValue(), | 459 n1->is_local(), n1->creation_time().ToInternalValue(), |
| 458 n1->guid(), n1->extension_id(), | 460 n1->guid(), n1->extension_id(), |
| 459 n1->title() + "_changed", // different title | 461 n1->title() + "_changed", // different title |
| 460 n1->body(), n1->link_url().spec(), n1->link_text())); | 462 n1->body(), n1->link_url().spec(), n1->link_text())); |
| 461 initial_data.push_back( | 463 initial_data.push_back( |
| 462 AppNotificationManager::CreateSyncDataFromNotification(*n1_a)); | 464 AppNotificationManager::CreateSyncDataFromNotification(*n1_a)); |
| 463 | 465 |
| 464 scoped_ptr<SyncErrorFactoryMock> error_handler(new SyncErrorFactoryMock()); | 466 scoped_ptr<csync::SyncErrorFactoryMock> error_handler( |
| 467 new csync::SyncErrorFactoryMock()); |
| 465 EXPECT_CALL(*error_handler, CreateAndUploadError(_, _)). | 468 EXPECT_CALL(*error_handler, CreateAndUploadError(_, _)). |
| 466 WillOnce( | 469 WillOnce( |
| 467 Return(SyncError(FROM_HERE, "error", syncable::APP_NOTIFICATIONS))); | 470 Return( |
| 471 csync::SyncError( |
| 472 FROM_HERE, "error", syncable::APP_NOTIFICATIONS))); |
| 468 | 473 |
| 469 SyncError sync_error = model()->MergeDataAndStartSyncing( | 474 csync::SyncError sync_error = model()->MergeDataAndStartSyncing( |
| 470 syncable::APP_NOTIFICATIONS, | 475 syncable::APP_NOTIFICATIONS, |
| 471 initial_data, | 476 initial_data, |
| 472 PassProcessor(), | 477 PassProcessor(), |
| 473 error_handler.PassAs<SyncErrorFactory>()); | 478 error_handler.PassAs<csync::SyncErrorFactory>()); |
| 474 | 479 |
| 475 EXPECT_TRUE(sync_error.IsSet()); | 480 EXPECT_TRUE(sync_error.IsSet()); |
| 476 EXPECT_EQ(syncable::APP_NOTIFICATIONS, sync_error.type()); | 481 EXPECT_EQ(syncable::APP_NOTIFICATIONS, sync_error.type()); |
| 477 EXPECT_EQ(0U, processor()->change_list_size()); | 482 EXPECT_EQ(0U, processor()->change_list_size()); |
| 478 } | 483 } |
| 479 | 484 |
| 480 // When an item in sync matches with a local-only item in model, an error | 485 // When an item in sync matches with a local-only item in model, an error |
| 481 // should be returned. | 486 // should be returned. |
| 482 TEST_F(AppNotificationManagerSyncTest, ModelAssocBothNonEmptyMatchesLocal) { | 487 TEST_F(AppNotificationManagerSyncTest, ModelAssocBothNonEmptyMatchesLocal) { |
| 483 AppNotification* n1 = CreateNotification(1); | 488 AppNotification* n1 = CreateNotification(1); |
| 484 model()->Add(n1); | 489 model()->Add(n1); |
| 485 AppNotification* n2 = CreateNotification(true, 2); | 490 AppNotification* n2 = CreateNotification(true, 2); |
| 486 model()->Add(n2); | 491 model()->Add(n2); |
| 487 | 492 |
| 488 SyncDataList initial_data; | 493 csync::SyncDataList initial_data; |
| 489 initial_data.push_back(CreateSyncData(1)); | 494 initial_data.push_back(CreateSyncData(1)); |
| 490 scoped_ptr<AppNotification> n2_a(CreateNotification(2)); | 495 scoped_ptr<AppNotification> n2_a(CreateNotification(2)); |
| 491 initial_data.push_back( | 496 initial_data.push_back( |
| 492 AppNotificationManager::CreateSyncDataFromNotification(*n2_a)); | 497 AppNotificationManager::CreateSyncDataFromNotification(*n2_a)); |
| 493 | 498 |
| 494 scoped_ptr<SyncErrorFactoryMock> error_handler(new SyncErrorFactoryMock()); | 499 scoped_ptr<csync::SyncErrorFactoryMock> error_handler( |
| 500 new csync::SyncErrorFactoryMock()); |
| 495 EXPECT_CALL(*error_handler, CreateAndUploadError(_, _)). | 501 EXPECT_CALL(*error_handler, CreateAndUploadError(_, _)). |
| 496 WillOnce( | 502 WillOnce( |
| 497 Return(SyncError(FROM_HERE, "error", syncable::APP_NOTIFICATIONS))); | 503 Return( |
| 504 csync::SyncError( |
| 505 FROM_HERE, "error", syncable::APP_NOTIFICATIONS))); |
| 498 | 506 |
| 499 SyncError sync_error = model()->MergeDataAndStartSyncing( | 507 csync::SyncError sync_error = model()->MergeDataAndStartSyncing( |
| 500 syncable::APP_NOTIFICATIONS, | 508 syncable::APP_NOTIFICATIONS, |
| 501 initial_data, | 509 initial_data, |
| 502 PassProcessor(), | 510 PassProcessor(), |
| 503 error_handler.PassAs<SyncErrorFactory>()); | 511 error_handler.PassAs<csync::SyncErrorFactory>()); |
| 504 | 512 |
| 505 EXPECT_TRUE(sync_error.IsSet()); | 513 EXPECT_TRUE(sync_error.IsSet()); |
| 506 EXPECT_EQ(syncable::APP_NOTIFICATIONS, sync_error.type()); | 514 EXPECT_EQ(syncable::APP_NOTIFICATIONS, sync_error.type()); |
| 507 EXPECT_EQ(0U, processor()->change_list_size()); | 515 EXPECT_EQ(0U, processor()->change_list_size()); |
| 508 } | 516 } |
| 509 | 517 |
| 510 // Process sync changes when model is empty. | 518 // Process sync changes when model is empty. |
| 511 TEST_F(AppNotificationManagerSyncTest, ProcessSyncChangesEmptyModel) { | 519 TEST_F(AppNotificationManagerSyncTest, ProcessSyncChangesEmptyModel) { |
| 512 // We initially have no data. | 520 // We initially have no data. |
| 513 model()->MergeDataAndStartSyncing( | 521 model()->MergeDataAndStartSyncing( |
| 514 syncable::APP_NOTIFICATIONS, | 522 syncable::APP_NOTIFICATIONS, |
| 515 SyncDataList(), | 523 csync::SyncDataList(), |
| 516 PassProcessor(), | 524 PassProcessor(), |
| 517 scoped_ptr<SyncErrorFactory>(new SyncErrorFactoryMock())); | 525 scoped_ptr<csync::SyncErrorFactory>(new csync::SyncErrorFactoryMock())); |
| 518 | 526 |
| 519 // Set up a bunch of ADDs. | 527 // Set up a bunch of ADDs. |
| 520 SyncChangeList changes; | 528 csync::SyncChangeList changes; |
| 521 changes.push_back(CreateSyncChange( | 529 changes.push_back(CreateSyncChange( |
| 522 SyncChange::ACTION_ADD, CreateNotification(1))); | 530 csync::SyncChange::ACTION_ADD, CreateNotification(1))); |
| 523 changes.push_back(CreateSyncChange( | 531 changes.push_back(CreateSyncChange( |
| 524 SyncChange::ACTION_ADD, CreateNotification(2))); | 532 csync::SyncChange::ACTION_ADD, CreateNotification(2))); |
| 525 changes.push_back(CreateSyncChange( | 533 changes.push_back(CreateSyncChange( |
| 526 SyncChange::ACTION_ADD, CreateNotification(3))); | 534 csync::SyncChange::ACTION_ADD, CreateNotification(3))); |
| 527 | 535 |
| 528 model()->ProcessSyncChanges(FROM_HERE, changes); | 536 model()->ProcessSyncChanges(FROM_HERE, changes); |
| 529 | 537 |
| 530 EXPECT_EQ(3U, model()->GetAllSyncData(syncable::APP_NOTIFICATIONS).size()); | 538 EXPECT_EQ(3U, model()->GetAllSyncData(syncable::APP_NOTIFICATIONS).size()); |
| 531 EXPECT_EQ(0U, processor()->change_list_size()); | 539 EXPECT_EQ(0U, processor()->change_list_size()); |
| 532 } | 540 } |
| 533 | 541 |
| 534 // Process sync changes when model is not empty. | 542 // Process sync changes when model is not empty. |
| 535 TEST_F(AppNotificationManagerSyncTest, ProcessSyncChangesNonEmptyModel) { | 543 TEST_F(AppNotificationManagerSyncTest, ProcessSyncChangesNonEmptyModel) { |
| 536 AppNotification* n1 = CreateNotification(1); | 544 AppNotification* n1 = CreateNotification(1); |
| 537 model()->Add(n1); | 545 model()->Add(n1); |
| 538 AppNotification* n2 = CreateNotification(2); | 546 AppNotification* n2 = CreateNotification(2); |
| 539 model()->Add(n2); | 547 model()->Add(n2); |
| 540 model()->MergeDataAndStartSyncing( | 548 model()->MergeDataAndStartSyncing( |
| 541 syncable::APP_NOTIFICATIONS, | 549 syncable::APP_NOTIFICATIONS, |
| 542 SyncDataList(), | 550 csync::SyncDataList(), |
| 543 PassProcessor(), | 551 PassProcessor(), |
| 544 scoped_ptr<SyncErrorFactory>(new SyncErrorFactoryMock())); | 552 scoped_ptr<csync::SyncErrorFactory>(new csync::SyncErrorFactoryMock())); |
| 545 | 553 |
| 546 // Some adds and some deletes. | 554 // Some adds and some deletes. |
| 547 SyncChangeList changes; | 555 csync::SyncChangeList changes; |
| 548 changes.push_back(CreateSyncChange( | 556 changes.push_back(CreateSyncChange( |
| 549 SyncChange::ACTION_ADD, CreateNotification(3))); | 557 csync::SyncChange::ACTION_ADD, CreateNotification(3))); |
| 550 changes.push_back(CreateSyncChange(SyncChange::ACTION_DELETE, n1->Copy())); | |
| 551 changes.push_back(CreateSyncChange( | 558 changes.push_back(CreateSyncChange( |
| 552 SyncChange::ACTION_ADD, CreateNotification(4))); | 559 csync::SyncChange::ACTION_DELETE, n1->Copy())); |
| 560 changes.push_back(CreateSyncChange( |
| 561 csync::SyncChange::ACTION_ADD, CreateNotification(4))); |
| 553 | 562 |
| 554 model()->ProcessSyncChanges(FROM_HERE, changes); | 563 model()->ProcessSyncChanges(FROM_HERE, changes); |
| 555 | 564 |
| 556 EXPECT_EQ(3U, model()->GetAllSyncData(syncable::APP_NOTIFICATIONS).size()); | 565 EXPECT_EQ(3U, model()->GetAllSyncData(syncable::APP_NOTIFICATIONS).size()); |
| 557 EXPECT_EQ(2U, processor()->change_list_size()); | 566 EXPECT_EQ(2U, processor()->change_list_size()); |
| 558 } | 567 } |
| 559 | 568 |
| 560 // Process sync changes should ignore a bad ADD. | 569 // Process sync changes should ignore a bad ADD. |
| 561 TEST_F(AppNotificationManagerSyncTest, ProcessSyncChangesIgnoreBadAdd) { | 570 TEST_F(AppNotificationManagerSyncTest, ProcessSyncChangesIgnoreBadAdd) { |
| 562 AppNotification* n1 = CreateNotification(1); | 571 AppNotification* n1 = CreateNotification(1); |
| 563 model()->Add(n1); | 572 model()->Add(n1); |
| 564 AppNotification* n2 = CreateNotification(2); | 573 AppNotification* n2 = CreateNotification(2); |
| 565 model()->Add(n2); | 574 model()->Add(n2); |
| 566 model()->MergeDataAndStartSyncing( | 575 model()->MergeDataAndStartSyncing( |
| 567 syncable::APP_NOTIFICATIONS, | 576 syncable::APP_NOTIFICATIONS, |
| 568 SyncDataList(), | 577 csync::SyncDataList(), |
| 569 PassProcessor(), | 578 PassProcessor(), |
| 570 scoped_ptr<SyncErrorFactory>(new SyncErrorFactoryMock())); | 579 scoped_ptr<csync::SyncErrorFactory>(new csync::SyncErrorFactoryMock())); |
| 571 | 580 |
| 572 // Some adds and some deletes. | 581 // Some adds and some deletes. |
| 573 SyncChangeList changes; | 582 csync::SyncChangeList changes; |
| 574 changes.push_back(CreateSyncChange( | 583 changes.push_back(CreateSyncChange( |
| 575 SyncChange::ACTION_ADD, CreateNotification(1))); | 584 csync::SyncChange::ACTION_ADD, CreateNotification(1))); |
| 576 | 585 |
| 577 SyncError error = model()->ProcessSyncChanges(FROM_HERE, changes); | 586 csync::SyncError error = model()->ProcessSyncChanges(FROM_HERE, changes); |
| 578 EXPECT_FALSE(error.IsSet()); | 587 EXPECT_FALSE(error.IsSet()); |
| 579 | 588 |
| 580 EXPECT_EQ(2U, model()->GetAllSyncData(syncable::APP_NOTIFICATIONS).size()); | 589 EXPECT_EQ(2U, model()->GetAllSyncData(syncable::APP_NOTIFICATIONS).size()); |
| 581 EXPECT_EQ(2U, processor()->change_list_size()); | 590 EXPECT_EQ(2U, processor()->change_list_size()); |
| 582 } | 591 } |
| 583 | 592 |
| 584 // Process sync changes should ignore a bad DELETE. | 593 // Process sync changes should ignore a bad DELETE. |
| 585 TEST_F(AppNotificationManagerSyncTest, ProcessSyncChangesIgnoreBadDelete) { | 594 TEST_F(AppNotificationManagerSyncTest, ProcessSyncChangesIgnoreBadDelete) { |
| 586 AppNotification* n1 = CreateNotification(1); | 595 AppNotification* n1 = CreateNotification(1); |
| 587 model()->Add(n1); | 596 model()->Add(n1); |
| 588 AppNotification* n2 = CreateNotification(2); | 597 AppNotification* n2 = CreateNotification(2); |
| 589 model()->Add(n2); | 598 model()->Add(n2); |
| 590 model()->MergeDataAndStartSyncing( | 599 model()->MergeDataAndStartSyncing( |
| 591 syncable::APP_NOTIFICATIONS, | 600 syncable::APP_NOTIFICATIONS, |
| 592 SyncDataList(), | 601 csync::SyncDataList(), |
| 593 PassProcessor(), | 602 PassProcessor(), |
| 594 scoped_ptr<SyncErrorFactory>(new SyncErrorFactoryMock())); | 603 scoped_ptr<csync::SyncErrorFactory>(new csync::SyncErrorFactoryMock())); |
| 595 | 604 |
| 596 // Some adds and some deletes. | 605 // Some adds and some deletes. |
| 597 SyncChangeList changes; | 606 csync::SyncChangeList changes; |
| 598 changes.push_back(CreateSyncChange( | 607 changes.push_back(CreateSyncChange( |
| 599 SyncChange::ACTION_DELETE, CreateNotification(3))); | 608 csync::SyncChange::ACTION_DELETE, CreateNotification(3))); |
| 600 | 609 |
| 601 SyncError error = model()->ProcessSyncChanges(FROM_HERE, changes); | 610 csync::SyncError error = model()->ProcessSyncChanges(FROM_HERE, changes); |
| 602 EXPECT_FALSE(error.IsSet()); | 611 EXPECT_FALSE(error.IsSet()); |
| 603 | 612 |
| 604 EXPECT_EQ(2U, model()->GetAllSyncData(syncable::APP_NOTIFICATIONS).size()); | 613 EXPECT_EQ(2U, model()->GetAllSyncData(syncable::APP_NOTIFICATIONS).size()); |
| 605 EXPECT_EQ(2U, processor()->change_list_size()); | 614 EXPECT_EQ(2U, processor()->change_list_size()); |
| 606 } | 615 } |
| 607 | 616 |
| 608 // Process sync changes should ignore bad UPDATEs. | 617 // Process sync changes should ignore bad UPDATEs. |
| 609 TEST_F(AppNotificationManagerSyncTest, ProcessSyncChangesIgnoreBadUpdates) { | 618 TEST_F(AppNotificationManagerSyncTest, ProcessSyncChangesIgnoreBadUpdates) { |
| 610 AppNotification* n1 = CreateNotification(1); | 619 AppNotification* n1 = CreateNotification(1); |
| 611 model()->Add(n1); | 620 model()->Add(n1); |
| 612 AppNotification* n2 = CreateNotification(2); | 621 AppNotification* n2 = CreateNotification(2); |
| 613 model()->Add(n2); | 622 model()->Add(n2); |
| 614 model()->MergeDataAndStartSyncing( | 623 model()->MergeDataAndStartSyncing( |
| 615 syncable::APP_NOTIFICATIONS, | 624 syncable::APP_NOTIFICATIONS, |
| 616 SyncDataList(), | 625 csync::SyncDataList(), |
| 617 PassProcessor(), | 626 PassProcessor(), |
| 618 scoped_ptr<SyncErrorFactory>(new SyncErrorFactoryMock())); | 627 scoped_ptr<csync::SyncErrorFactory>(new csync::SyncErrorFactoryMock())); |
| 619 | 628 |
| 620 // Some adds and some deletes. | 629 // Some adds and some deletes. |
| 621 SyncChangeList changes; | 630 csync::SyncChangeList changes; |
| 622 changes.push_back(CreateSyncChange( | 631 changes.push_back(CreateSyncChange( |
| 623 SyncChange::ACTION_UPDATE, CreateNotification(3))); | 632 csync::SyncChange::ACTION_UPDATE, CreateNotification(3))); |
| 624 AppNotification* n2_changed = n2->Copy(); | 633 AppNotification* n2_changed = n2->Copy(); |
| 625 n2_changed->set_link_text(n2_changed->link_text() + "-changed"); | 634 n2_changed->set_link_text(n2_changed->link_text() + "-changed"); |
| 626 changes.push_back(CreateSyncChange( | 635 changes.push_back(CreateSyncChange( |
| 627 SyncChange::ACTION_UPDATE, n2_changed)); | 636 csync::SyncChange::ACTION_UPDATE, n2_changed)); |
| 628 | 637 |
| 629 SyncError error = model()->ProcessSyncChanges(FROM_HERE, changes); | 638 csync::SyncError error = model()->ProcessSyncChanges(FROM_HERE, changes); |
| 630 EXPECT_FALSE(error.IsSet()); | 639 EXPECT_FALSE(error.IsSet()); |
| 631 | 640 |
| 632 EXPECT_EQ(2U, model()->GetAllSyncData(syncable::APP_NOTIFICATIONS).size()); | 641 EXPECT_EQ(2U, model()->GetAllSyncData(syncable::APP_NOTIFICATIONS).size()); |
| 633 EXPECT_EQ(2U, processor()->change_list_size()); | 642 EXPECT_EQ(2U, processor()->change_list_size()); |
| 634 } | 643 } |
| 635 | 644 |
| 636 // Process over 15 changes when model is not empty. | 645 // Process over 15 changes when model is not empty. |
| 637 TEST_F(AppNotificationManagerSyncTest, ProcessSyncChangesEmptyModelWithMax) { | 646 TEST_F(AppNotificationManagerSyncTest, ProcessSyncChangesEmptyModelWithMax) { |
| 638 const std::string& ext_id = "e1"; | 647 const std::string& ext_id = "e1"; |
| 639 model()->MergeDataAndStartSyncing( | 648 model()->MergeDataAndStartSyncing( |
| 640 syncable::APP_NOTIFICATIONS, | 649 syncable::APP_NOTIFICATIONS, |
| 641 SyncDataList(), | 650 csync::SyncDataList(), |
| 642 PassProcessor(), | 651 PassProcessor(), |
| 643 scoped_ptr<SyncErrorFactory>(new SyncErrorFactoryMock())); | 652 scoped_ptr<csync::SyncErrorFactory>(new csync::SyncErrorFactoryMock())); |
| 644 for (unsigned int i = 0; | 653 for (unsigned int i = 0; |
| 645 i < AppNotificationManager::kMaxNotificationPerApp * 2; i++) { | 654 i < AppNotificationManager::kMaxNotificationPerApp * 2; i++) { |
| 646 SyncChangeList changes; | 655 csync::SyncChangeList changes; |
| 647 changes.push_back(CreateSyncChange( | 656 changes.push_back(CreateSyncChange( |
| 648 SyncChange::ACTION_ADD, CreateNotification(false, i, ext_id))); | 657 csync::SyncChange::ACTION_ADD, CreateNotification(false, i, ext_id))); |
| 649 model()->ProcessSyncChanges(FROM_HERE, changes); | 658 model()->ProcessSyncChanges(FROM_HERE, changes); |
| 650 if (i < AppNotificationManager::kMaxNotificationPerApp) { | 659 if (i < AppNotificationManager::kMaxNotificationPerApp) { |
| 651 EXPECT_EQ(i + 1, | 660 EXPECT_EQ(i + 1, |
| 652 model()->GetAllSyncData(syncable::APP_NOTIFICATIONS).size()); | 661 model()->GetAllSyncData(syncable::APP_NOTIFICATIONS).size()); |
| 653 } else { | 662 } else { |
| 654 EXPECT_EQ(AppNotificationManager::kMaxNotificationPerApp, | 663 EXPECT_EQ(AppNotificationManager::kMaxNotificationPerApp, |
| 655 model()->GetAllSyncData(syncable::APP_NOTIFICATIONS).size()); | 664 model()->GetAllSyncData(syncable::APP_NOTIFICATIONS).size()); |
| 656 for (unsigned int j = i; j > i - 5; j--) { | 665 for (unsigned int j = i; j > i - 5; j--) { |
| 657 EXPECT_EQ( | 666 EXPECT_EQ( |
| 658 AppNotificationManager::kMaxNotificationPerApp, | 667 AppNotificationManager::kMaxNotificationPerApp, |
| 659 model()->GetAllSyncData(syncable::APP_NOTIFICATIONS).size()); | 668 model()->GetAllSyncData(syncable::APP_NOTIFICATIONS).size()); |
| 660 } | 669 } |
| 661 } | 670 } |
| 662 } | 671 } |
| 663 } | 672 } |
| 664 | 673 |
| 665 // Stop syncing sets state correctly. | 674 // Stop syncing sets state correctly. |
| 666 TEST_F(AppNotificationManagerSyncTest, StopSyncing) { | 675 TEST_F(AppNotificationManagerSyncTest, StopSyncing) { |
| 667 EXPECT_FALSE(model()->sync_processor_.get()); | 676 EXPECT_FALSE(model()->sync_processor_.get()); |
| 668 EXPECT_FALSE(model()->models_associated_); | 677 EXPECT_FALSE(model()->models_associated_); |
| 669 | 678 |
| 670 model()->MergeDataAndStartSyncing( | 679 model()->MergeDataAndStartSyncing( |
| 671 syncable::APP_NOTIFICATIONS, | 680 syncable::APP_NOTIFICATIONS, |
| 672 SyncDataList(), | 681 csync::SyncDataList(), |
| 673 PassProcessor(), | 682 PassProcessor(), |
| 674 scoped_ptr<SyncErrorFactory>(new SyncErrorFactoryMock())); | 683 scoped_ptr<csync::SyncErrorFactory>(new csync::SyncErrorFactoryMock())); |
| 675 | 684 |
| 676 EXPECT_TRUE(model()->sync_processor_.get()); | 685 EXPECT_TRUE(model()->sync_processor_.get()); |
| 677 EXPECT_TRUE(model()->models_associated_); | 686 EXPECT_TRUE(model()->models_associated_); |
| 678 | 687 |
| 679 model()->StopSyncing(syncable::APP_NOTIFICATIONS); | 688 model()->StopSyncing(syncable::APP_NOTIFICATIONS); |
| 680 EXPECT_FALSE(model()->sync_processor_.get()); | 689 EXPECT_FALSE(model()->sync_processor_.get()); |
| 681 EXPECT_FALSE(model()->models_associated_); | 690 EXPECT_FALSE(model()->models_associated_); |
| 682 } | 691 } |
| 683 | 692 |
| 684 // Adds get pushed to sync but local only are skipped. | 693 // Adds get pushed to sync but local only are skipped. |
| 685 TEST_F(AppNotificationManagerSyncTest, AddsGetsSynced) { | 694 TEST_F(AppNotificationManagerSyncTest, AddsGetsSynced) { |
| 686 model()->MergeDataAndStartSyncing( | 695 model()->MergeDataAndStartSyncing( |
| 687 syncable::APP_NOTIFICATIONS, | 696 syncable::APP_NOTIFICATIONS, |
| 688 SyncDataList(), | 697 csync::SyncDataList(), |
| 689 PassProcessor(), | 698 PassProcessor(), |
| 690 scoped_ptr<SyncErrorFactory>(new SyncErrorFactoryMock())); | 699 scoped_ptr<csync::SyncErrorFactory>(new csync::SyncErrorFactoryMock())); |
| 691 | 700 |
| 692 AppNotification* n1 = CreateNotification(1); | 701 AppNotification* n1 = CreateNotification(1); |
| 693 model()->Add(n1); | 702 model()->Add(n1); |
| 694 AppNotification* n2 = CreateNotification(2); | 703 AppNotification* n2 = CreateNotification(2); |
| 695 model()->Add(n2); | 704 model()->Add(n2); |
| 696 AppNotification* n3 = CreateNotification(true, 2); | 705 AppNotification* n3 = CreateNotification(true, 2); |
| 697 model()->Add(n3); | 706 model()->Add(n3); |
| 698 | 707 |
| 699 EXPECT_EQ(2U, processor()->change_list_size()); | 708 EXPECT_EQ(2U, processor()->change_list_size()); |
| 700 EXPECT_TRUE(processor()->ContainsGuid(n1->guid())); | 709 EXPECT_TRUE(processor()->ContainsGuid(n1->guid())); |
| 701 SyncChange c1 = processor()->GetChangeByGuid(n1->guid()); | 710 csync::SyncChange c1 = processor()->GetChangeByGuid(n1->guid()); |
| 702 AssertSyncChange(c1, SyncChange::ACTION_ADD, *n1); | 711 AssertSyncChange(c1, csync::SyncChange::ACTION_ADD, *n1); |
| 703 SyncChange c2 = processor()->GetChangeByGuid(n2->guid()); | 712 csync::SyncChange c2 = processor()->GetChangeByGuid(n2->guid()); |
| 704 AssertSyncChange(c2, SyncChange::ACTION_ADD, *n2); | 713 AssertSyncChange(c2, csync::SyncChange::ACTION_ADD, *n2); |
| 705 } | 714 } |
| 706 | 715 |
| 707 // Clear all gets pushed to sync. | 716 // Clear all gets pushed to sync. |
| 708 TEST_F(AppNotificationManagerSyncTest, ClearAllGetsSynced) { | 717 TEST_F(AppNotificationManagerSyncTest, ClearAllGetsSynced) { |
| 709 const std::string& ext_id = "e1"; | 718 const std::string& ext_id = "e1"; |
| 710 scoped_ptr<AppNotification> n1(CreateNotification(false, 1, ext_id)); | 719 scoped_ptr<AppNotification> n1(CreateNotification(false, 1, ext_id)); |
| 711 scoped_ptr<AppNotification> n2(CreateNotification(false, 2, ext_id)); | 720 scoped_ptr<AppNotification> n2(CreateNotification(false, 2, ext_id)); |
| 712 scoped_ptr<AppNotification> n3(CreateNotification(false, 3, ext_id)); | 721 scoped_ptr<AppNotification> n3(CreateNotification(false, 3, ext_id)); |
| 713 scoped_ptr<AppNotification> n4(CreateNotification(4)); | 722 scoped_ptr<AppNotification> n4(CreateNotification(4)); |
| 714 | 723 |
| 715 SyncDataList initial_data; | 724 csync::SyncDataList initial_data; |
| 716 initial_data.push_back( | 725 initial_data.push_back( |
| 717 AppNotificationManager::CreateSyncDataFromNotification(*n1)); | 726 AppNotificationManager::CreateSyncDataFromNotification(*n1)); |
| 718 initial_data.push_back( | 727 initial_data.push_back( |
| 719 AppNotificationManager::CreateSyncDataFromNotification(*n2)); | 728 AppNotificationManager::CreateSyncDataFromNotification(*n2)); |
| 720 initial_data.push_back( | 729 initial_data.push_back( |
| 721 AppNotificationManager::CreateSyncDataFromNotification(*n3)); | 730 AppNotificationManager::CreateSyncDataFromNotification(*n3)); |
| 722 initial_data.push_back( | 731 initial_data.push_back( |
| 723 AppNotificationManager::CreateSyncDataFromNotification(*n4)); | 732 AppNotificationManager::CreateSyncDataFromNotification(*n4)); |
| 724 model()->MergeDataAndStartSyncing( | 733 model()->MergeDataAndStartSyncing( |
| 725 syncable::APP_NOTIFICATIONS, | 734 syncable::APP_NOTIFICATIONS, |
| 726 initial_data, | 735 initial_data, |
| 727 PassProcessor(), | 736 PassProcessor(), |
| 728 scoped_ptr<SyncErrorFactory>(new SyncErrorFactoryMock())); | 737 scoped_ptr<csync::SyncErrorFactory>(new csync::SyncErrorFactoryMock())); |
| 729 | 738 |
| 730 model()->ClearAll(ext_id); | 739 model()->ClearAll(ext_id); |
| 731 | 740 |
| 732 EXPECT_EQ(3U, processor()->change_list_size()); | 741 EXPECT_EQ(3U, processor()->change_list_size()); |
| 733 EXPECT_TRUE(processor()->ContainsGuid(n1->guid())); | 742 EXPECT_TRUE(processor()->ContainsGuid(n1->guid())); |
| 734 SyncChange c1 = processor()->GetChangeByGuid(n1->guid()); | 743 csync::SyncChange c1 = processor()->GetChangeByGuid(n1->guid()); |
| 735 AssertSyncChange(c1, SyncChange::ACTION_DELETE, *n1); | 744 AssertSyncChange(c1, csync::SyncChange::ACTION_DELETE, *n1); |
| 736 SyncChange c2 = processor()->GetChangeByGuid(n2->guid()); | 745 csync::SyncChange c2 = processor()->GetChangeByGuid(n2->guid()); |
| 737 AssertSyncChange(c2, SyncChange::ACTION_DELETE, *n2); | 746 AssertSyncChange(c2, csync::SyncChange::ACTION_DELETE, *n2); |
| 738 SyncChange c3 = processor()->GetChangeByGuid(n3->guid()); | 747 csync::SyncChange c3 = processor()->GetChangeByGuid(n3->guid()); |
| 739 AssertSyncChange(c3, SyncChange::ACTION_DELETE, *n3); | 748 AssertSyncChange(c3, csync::SyncChange::ACTION_DELETE, *n3); |
| 740 } | 749 } |
| OLD | NEW |