| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/notifications/sync_notifier/synced_notification_app_inf
o_service.h" | 5 #include "chrome/browser/notifications/sync_notifier/synced_notification_app_inf
o_service.h" |
| 6 | 6 |
| 7 #include "chrome/browser/notifications/sync_notifier/sync_notifier_test_utils.h" | 7 #include "chrome/browser/notifications/sync_notifier/sync_notifier_test_utils.h" |
| 8 #include "chrome/browser/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
| 9 #include "chrome/test/base/testing_pref_service_syncable.h" | 9 #include "chrome/test/base/testing_pref_service_syncable.h" |
| 10 #include "chrome/test/base/testing_profile.h" | 10 #include "chrome/test/base/testing_profile.h" |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 // Add to the list. | 130 // Add to the list. |
| 131 app_info_service->sending_service_infos_.push_back(test_item2); | 131 app_info_service->sending_service_infos_.push_back(test_item2); |
| 132 } | 132 } |
| 133 | 133 |
| 134 // Put some representative test data into the AppInfo protobuf. | 134 // Put some representative test data into the AppInfo protobuf. |
| 135 static void FillProtobufWithTestData1( | 135 static void FillProtobufWithTestData1( |
| 136 sync_pb::SyncedNotificationAppInfo& protobuf) { | 136 sync_pb::SyncedNotificationAppInfo& protobuf) { |
| 137 protobuf.add_app_id(std::string(kAppId1)); | 137 protobuf.add_app_id(std::string(kAppId1)); |
| 138 protobuf.add_app_id(std::string(kAppId2)); | 138 protobuf.add_app_id(std::string(kAppId2)); |
| 139 protobuf.set_settings_display_name(kSendingService1Name); | 139 protobuf.set_settings_display_name(kSendingService1Name); |
| 140 protobuf.set_info_url(kTestInfoUrl); |
| 140 protobuf.mutable_icon()->set_url(kTestIconUrl); | 141 protobuf.mutable_icon()->set_url(kTestIconUrl); |
| 141 } | 142 } |
| 142 | 143 |
| 143 static void FillProtobufWithTestData2( | 144 static void FillProtobufWithTestData2( |
| 144 sync_pb::SyncedNotificationAppInfo& protobuf) { | 145 sync_pb::SyncedNotificationAppInfo& protobuf) { |
| 145 protobuf.add_app_id(std::string(kAppId3)); | 146 protobuf.add_app_id(std::string(kAppId3)); |
| 146 protobuf.set_settings_display_name(kSendingService1Name); | 147 protobuf.set_settings_display_name(kSendingService1Name); |
| 147 protobuf.mutable_icon()->set_url(kTestIconUrl); | 148 protobuf.mutable_icon()->set_url(kTestIconUrl); |
| 148 } | 149 } |
| 149 | 150 |
| 150 // Helper to create syncer::SyncChange. | 151 // Helper to create syncer::SyncChange. |
| 151 static SyncChange CreateSyncChange(SyncChange::SyncChangeType type, | 152 static SyncChange CreateSyncChange(SyncChange::SyncChangeType type, |
| 152 const std::string& settings_display_name, | 153 const std::string& settings_display_name, |
| 154 const std::string& info_url, |
| 153 const std::string& icon_url, | 155 const std::string& icon_url, |
| 154 const std::string& app_id1, | 156 const std::string& app_id1, |
| 155 const std::string& app_id2) { | 157 const std::string& app_id2) { |
| 156 | 158 |
| 157 return SyncChange( | 159 return SyncChange( |
| 158 FROM_HERE, | 160 FROM_HERE, |
| 159 type, | 161 type, |
| 160 CreateSyncData(settings_display_name, icon_url, app_id1, app_id2)); | 162 CreateSyncData( |
| 163 settings_display_name, info_url, icon_url, app_id1, app_id2)); |
| 161 } | 164 } |
| 162 | 165 |
| 163 // Build a SyncData object to look like what Sync would deliver. | 166 // Build a SyncData object to look like what Sync would deliver. |
| 164 static SyncData CreateSyncData(const std::string& settings_display_name, | 167 static SyncData CreateSyncData(const std::string& settings_display_name, |
| 168 const std::string& info_url, |
| 165 const std::string& icon_url, | 169 const std::string& icon_url, |
| 166 const std::string& app_id1, | 170 const std::string& app_id1, |
| 167 const std::string& app_id2) { | 171 const std::string& app_id2) { |
| 168 // CreateLocalData makes a copy of this, so it can safely live on the stack. | 172 // CreateLocalData makes a copy of this, so it can safely live on the stack. |
| 169 EntitySpecifics entity_specifics; | 173 EntitySpecifics entity_specifics; |
| 170 EXPECT_FALSE(app_id1.empty()); | 174 EXPECT_FALSE(app_id1.empty()); |
| 171 | 175 |
| 172 sync_pb::SyncedNotificationAppInfoSpecifics* specifics = | 176 sync_pb::SyncedNotificationAppInfoSpecifics* specifics = |
| 173 entity_specifics.mutable_synced_notification_app_info(); | 177 entity_specifics.mutable_synced_notification_app_info(); |
| 174 | 178 |
| 175 // Add a synced_notification_app_info object. | 179 // Add a synced_notification_app_info object. |
| 176 specifics->add_synced_notification_app_info(); | 180 specifics->add_synced_notification_app_info(); |
| 177 sync_pb::SyncedNotificationAppInfo* app_info = | 181 sync_pb::SyncedNotificationAppInfo* app_info = |
| 178 specifics->mutable_synced_notification_app_info(0); | 182 specifics->mutable_synced_notification_app_info(0); |
| 179 | 183 |
| 180 // Add the key, the settings display name. | 184 // Add the key, the settings display name. |
| 181 app_info->set_settings_display_name(settings_display_name); | 185 app_info->set_settings_display_name(settings_display_name); |
| 182 | 186 |
| 187 // Add the welcome notification info URL. |
| 188 app_info->set_info_url(info_url); |
| 189 |
| 183 // Add the icon URL. | 190 // Add the icon URL. |
| 184 app_info->mutable_icon()->set_url(icon_url); | 191 app_info->mutable_icon()->set_url(icon_url); |
| 185 | 192 |
| 186 // Add the app IDs. | 193 // Add the app IDs. |
| 187 app_info->add_app_id(app_id1); | 194 app_info->add_app_id(app_id1); |
| 188 | 195 |
| 189 // Only add the second if it is non-empty | 196 // Only add the second if it is non-empty |
| 190 if (!app_id2.empty()) { | 197 if (!app_id2.empty()) { |
| 191 app_info->add_app_id(app_id2); | 198 app_info->add_app_id(app_id2); |
| 192 } | 199 } |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 // Process sync changes when there is no local data. | 242 // Process sync changes when there is no local data. |
| 236 TEST_F(SyncedNotificationAppInfoServiceTest, ProcessSyncChangesEmptyModel) { | 243 TEST_F(SyncedNotificationAppInfoServiceTest, ProcessSyncChangesEmptyModel) { |
| 237 // We initially have no data. | 244 // We initially have no data. |
| 238 SyncedNotificationAppInfoService app_info_service(profile_.get()); | 245 SyncedNotificationAppInfoService app_info_service(profile_.get()); |
| 239 app_info_service.set_avoid_bitmap_fetching_for_test(true); | 246 app_info_service.set_avoid_bitmap_fetching_for_test(true); |
| 240 | 247 |
| 241 // Set up an ADD. | 248 // Set up an ADD. |
| 242 SyncChangeList changes; | 249 SyncChangeList changes; |
| 243 changes.push_back(CreateSyncChange(SyncChange::ACTION_ADD, | 250 changes.push_back(CreateSyncChange(SyncChange::ACTION_ADD, |
| 244 kSendingService1Name, | 251 kSendingService1Name, |
| 252 kTestInfoUrl, |
| 245 kTestIconUrl, | 253 kTestIconUrl, |
| 246 kAppId1, | 254 kAppId1, |
| 247 kAppId2)); | 255 kAppId2)); |
| 248 | 256 |
| 249 // Process the changes we built. | 257 // Process the changes we built. |
| 250 app_info_service.ProcessSyncChanges(FROM_HERE, changes); | 258 app_info_service.ProcessSyncChanges(FROM_HERE, changes); |
| 251 | 259 |
| 252 // Verify sync change made it to the SyncedNotificationAppInfo list. | 260 // Verify sync change made it to the SyncedNotificationAppInfo list. |
| 253 SyncedNotificationAppInfo* app_info1 = | 261 SyncedNotificationAppInfo* app_info1 = |
| 254 app_info_service.FindSyncedNotificationAppInfoByName( | 262 app_info_service.FindSyncedNotificationAppInfoByName( |
| (...skipping 11 matching lines...) Expand all Loading... |
| 266 app_info_service.set_avoid_bitmap_fetching_for_test(true); | 274 app_info_service.set_avoid_bitmap_fetching_for_test(true); |
| 267 | 275 |
| 268 // Create some local fake data. We rely on the specific ids set up here. | 276 // Create some local fake data. We rely on the specific ids set up here. |
| 269 AddTestingAppInfosToList(&app_info_service); | 277 AddTestingAppInfosToList(&app_info_service); |
| 270 | 278 |
| 271 // Set up an UPDATE. | 279 // Set up an UPDATE. |
| 272 SyncChangeList changes; | 280 SyncChangeList changes; |
| 273 | 281 |
| 274 changes.push_back(CreateSyncChange(SyncChange::ACTION_UPDATE, | 282 changes.push_back(CreateSyncChange(SyncChange::ACTION_UPDATE, |
| 275 kSendingService1Name, | 283 kSendingService1Name, |
| 284 kTestInfoUrl, |
| 276 kTestIconUrl, | 285 kTestIconUrl, |
| 277 kAppId1, | 286 kAppId1, |
| 278 kAppId3)); | 287 kAppId3)); |
| 279 | 288 |
| 280 // Simulate incoming changed sync data at runtime. | 289 // Simulate incoming changed sync data at runtime. |
| 281 app_info_service.ProcessSyncChanges(FROM_HERE, changes); | 290 app_info_service.ProcessSyncChanges(FROM_HERE, changes); |
| 282 | 291 |
| 283 // We should find that the first item now has a different set of app ids. | 292 // We should find that the first item now has a different set of app ids. |
| 284 SyncedNotificationAppInfo* app_info1 = | 293 SyncedNotificationAppInfo* app_info1 = |
| 285 app_info_service.FindSyncedNotificationAppInfoByName( | 294 app_info_service.FindSyncedNotificationAppInfoByName( |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 365 sync_pb::SyncedNotificationAppInfo protobuf; | 374 sync_pb::SyncedNotificationAppInfo protobuf; |
| 366 FillProtobufWithTestData1(protobuf); | 375 FillProtobufWithTestData1(protobuf); |
| 367 | 376 |
| 368 scoped_ptr<SyncedNotificationAppInfo> app_info; | 377 scoped_ptr<SyncedNotificationAppInfo> app_info; |
| 369 app_info = | 378 app_info = |
| 370 app_info_service.CreateSyncedNotificationAppInfoFromProtobuf(protobuf); | 379 app_info_service.CreateSyncedNotificationAppInfoFromProtobuf(protobuf); |
| 371 | 380 |
| 372 // Ensure the app info class has the fields we expect. | 381 // Ensure the app info class has the fields we expect. |
| 373 EXPECT_EQ(std::string(kSendingService1Name), | 382 EXPECT_EQ(std::string(kSendingService1Name), |
| 374 app_info->settings_display_name()); | 383 app_info->settings_display_name()); |
| 384 EXPECT_EQ(GURL(kTestInfoUrl), app_info->welcome_link_url()); |
| 375 EXPECT_TRUE(app_info->HasAppId(kAppId1)); | 385 EXPECT_TRUE(app_info->HasAppId(kAppId1)); |
| 376 EXPECT_TRUE(app_info->HasAppId(kAppId2)); | 386 EXPECT_TRUE(app_info->HasAppId(kAppId2)); |
| 377 EXPECT_EQ(GURL(std::string(kTestIconUrl)), app_info->settings_icon_url()); | 387 EXPECT_EQ(GURL(std::string(kTestIconUrl)), app_info->settings_icon_url()); |
| 378 } | 388 } |
| 379 | 389 |
| 380 // Test our find by sending service name function. | 390 // Test our find by sending service name function. |
| 381 TEST_F(SyncedNotificationAppInfoServiceTest, | 391 TEST_F(SyncedNotificationAppInfoServiceTest, |
| 382 FindSyncedNotificationAppInfoByNameTest) { | 392 FindSyncedNotificationAppInfoByNameTest) { |
| 383 SyncedNotificationAppInfoService app_info_service(profile_.get()); | 393 SyncedNotificationAppInfoService app_info_service(profile_.get()); |
| 384 | 394 |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 455 | 465 |
| 456 std::vector<SyncedNotificationSendingServiceSettingsData> data; | 466 std::vector<SyncedNotificationSendingServiceSettingsData> data; |
| 457 data = app_info_service.GetAllSendingServiceSettingsData(); | 467 data = app_info_service.GetAllSendingServiceSettingsData(); |
| 458 | 468 |
| 459 EXPECT_EQ(static_cast<unsigned int>(2), data.size()); | 469 EXPECT_EQ(static_cast<unsigned int>(2), data.size()); |
| 460 EXPECT_EQ(kSendingService1Name, data[0].settings_display_name); | 470 EXPECT_EQ(kSendingService1Name, data[0].settings_display_name); |
| 461 EXPECT_EQ(kSendingService2Name, data[1].settings_display_name); | 471 EXPECT_EQ(kSendingService2Name, data[1].settings_display_name); |
| 462 } | 472 } |
| 463 | 473 |
| 464 } // namespace notifier | 474 } // namespace notifier |
| OLD | NEW |