| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/string_number_conversions.h" | 7 #include "base/string_number_conversions.h" |
| 8 #include "chrome/browser/extensions/app_notification.h" | 8 #include "chrome/browser/extensions/app_notification.h" |
| 9 #include "chrome/browser/extensions/app_notification_manager.h" | 9 #include "chrome/browser/extensions/app_notification_manager.h" |
| 10 #include "chrome/browser/sync/protocol/app_notification_specifics.pb.h" | 10 #include "chrome/browser/sync/protocol/app_notification_specifics.pb.h" |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 AppNotificationManager* model() { return model_.get(); } | 105 AppNotificationManager* model() { return model_.get(); } |
| 106 TestChangeProcessor* processor() { return &processor_; } | 106 TestChangeProcessor* processor() { return &processor_; } |
| 107 | 107 |
| 108 // Creates a notification whose properties are set from the given integer. | 108 // Creates a notification whose properties are set from the given integer. |
| 109 static AppNotification* CreateNotification(int suffix) { | 109 static AppNotification* CreateNotification(int suffix) { |
| 110 return CreateNotification(false, suffix); | 110 return CreateNotification(false, suffix); |
| 111 } | 111 } |
| 112 static AppNotification* CreateNotification(bool is_local, int suffix) { | 112 static AppNotification* CreateNotification(bool is_local, int suffix) { |
| 113 std::string s = base::IntToString(suffix); | 113 std::string s = base::IntToString(suffix); |
| 114 return CreateNotification( | 114 return CreateNotification( |
| 115 is_local, "guid" + s, "ext" + s, "text" + s, "body" + s, | 115 is_local, suffix, "guid" + s, "ext" + s, "text" + s, "body" + s, |
| 116 "http://www.url" + s + ".com", "link text " + s); | 116 "http://www.url" + s + ".com", "link text " + s); |
| 117 } | 117 } |
| 118 static AppNotification* CreateNotification( | 118 static AppNotification* CreateNotification( |
| 119 bool is_local, int suffix, const std::string& extension_id) { | 119 bool is_local, int suffix, const std::string& extension_id) { |
| 120 std::string s = base::IntToString(suffix); | 120 std::string s = base::IntToString(suffix); |
| 121 return CreateNotification( | 121 return CreateNotification( |
| 122 is_local, "guid" + s, extension_id, "text" + s, "body" + s, | 122 is_local, suffix, "guid" + s, extension_id, "text" + s, "body" + s, |
| 123 "http://www.url" + s + ".com", "link text " + s); | 123 "http://www.url" + s + ".com", "link text " + s); |
| 124 } | 124 } |
| 125 | 125 |
| 126 // Creates a notification whose properties are set from the given integer | 126 // Creates a notification whose properties are set from the given integer |
| 127 // but does not set link url and link text. | 127 // but does not set link url and link text. |
| 128 static AppNotification* CreateNotificationNoLink(int suffix) { | 128 static AppNotification* CreateNotificationNoLink(int suffix) { |
| 129 return CreateNotificationNoLink(false, suffix); | 129 return CreateNotificationNoLink(false, suffix); |
| 130 } | 130 } |
| 131 static AppNotification* CreateNotificationNoLink(bool is_local, int suffix) { | 131 static AppNotification* CreateNotificationNoLink(bool is_local, int suffix) { |
| 132 std::string s = base::IntToString(suffix); | 132 std::string s = base::IntToString(suffix); |
| 133 return CreateNotification( | 133 return CreateNotification( |
| 134 is_local, "guid" + s, "ext" + s, "text" + s, "body" + s, "", ""); | 134 is_local, suffix, |
| 135 "guid" + s, "ext" + s, "text" + s, "body" + s, "", ""); |
| 135 } | 136 } |
| 136 | 137 |
| 137 // link_url and link_text are only set if the passed in values are not empty. | 138 // link_url and link_text are only set if the passed in values are not empty. |
| 138 static AppNotification* CreateNotification(bool is_local, | 139 static AppNotification* CreateNotification(bool is_local, |
| 140 double time, |
| 139 const std::string& guid, | 141 const std::string& guid, |
| 140 const std::string& extension_id, | 142 const std::string& extension_id, |
| 141 const std::string& title, | 143 const std::string& title, |
| 142 const std::string& body, | 144 const std::string& body, |
| 143 const std::string& link_url, | 145 const std::string& link_url, |
| 144 const std::string& link_text) { | 146 const std::string& link_text) { |
| 145 AppNotification* notif = new AppNotification( | 147 AppNotification* notif = new AppNotification( |
| 146 is_local, guid, extension_id, title, body); | 148 is_local, time, guid, extension_id, title, body); |
| 147 if (!link_url.empty()) | 149 if (!link_url.empty()) |
| 148 notif->set_link_url(GURL(link_url)); | 150 notif->set_link_url(GURL(link_url)); |
| 149 if (!link_text.empty()) | 151 if (!link_text.empty()) |
| 150 notif->set_link_text(link_text); | 152 notif->set_link_text(link_text); |
| 151 return notif; | 153 return notif; |
| 152 } | 154 } |
| 153 | 155 |
| 154 static SyncData CreateSyncData(int suffix) { | 156 static SyncData CreateSyncData(int suffix) { |
| 155 scoped_ptr<AppNotification> notif(CreateNotification(suffix)); | 157 scoped_ptr<AppNotification> notif(CreateNotification(suffix)); |
| 156 return AppNotificationManager::CreateSyncDataFromNotification(*notif); | 158 return AppNotificationManager::CreateSyncDataFromNotification(*notif); |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 405 // should be returned. | 407 // should be returned. |
| 406 TEST_F(AppNotificationManagerSyncTest, ModelAssocBothNonEmptyTitleMismatch) { | 408 TEST_F(AppNotificationManagerSyncTest, ModelAssocBothNonEmptyTitleMismatch) { |
| 407 AppNotification* n1 = CreateNotification(1); | 409 AppNotification* n1 = CreateNotification(1); |
| 408 model()->Add(n1); | 410 model()->Add(n1); |
| 409 AppNotification* n2 = CreateNotification(true, 2); | 411 AppNotification* n2 = CreateNotification(true, 2); |
| 410 model()->Add(n2); | 412 model()->Add(n2); |
| 411 | 413 |
| 412 SyncDataList initial_data; | 414 SyncDataList initial_data; |
| 413 initial_data.push_back(CreateSyncData(1)); | 415 initial_data.push_back(CreateSyncData(1)); |
| 414 scoped_ptr<AppNotification> n1_a(CreateNotification( | 416 scoped_ptr<AppNotification> n1_a(CreateNotification( |
| 415 n1->is_local(), n1->guid(), n1->extension_id(), | 417 n1->is_local(), n1->creation_timestamp_ms(), |
| 418 n1->guid(), n1->extension_id(), |
| 416 n1->title() + "_changed", // different title | 419 n1->title() + "_changed", // different title |
| 417 n1->body(), n1->link_url().spec(), n1->link_text())); | 420 n1->body(), n1->link_url().spec(), n1->link_text())); |
| 418 initial_data.push_back( | 421 initial_data.push_back( |
| 419 AppNotificationManager::CreateSyncDataFromNotification(*n1_a)); | 422 AppNotificationManager::CreateSyncDataFromNotification(*n1_a)); |
| 420 | 423 |
| 421 SyncError sync_error = model()->MergeDataAndStartSyncing( | 424 SyncError sync_error = model()->MergeDataAndStartSyncing( |
| 422 syncable::APP_NOTIFICATIONS, | 425 syncable::APP_NOTIFICATIONS, |
| 423 initial_data, | 426 initial_data, |
| 424 processor()); | 427 processor()); |
| 425 | 428 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 493 changes.push_back(CreateSyncChange(SyncChange::ACTION_DELETE, n1->Copy())); | 496 changes.push_back(CreateSyncChange(SyncChange::ACTION_DELETE, n1->Copy())); |
| 494 changes.push_back(CreateSyncChange( | 497 changes.push_back(CreateSyncChange( |
| 495 SyncChange::ACTION_ADD, CreateNotification(4))); | 498 SyncChange::ACTION_ADD, CreateNotification(4))); |
| 496 | 499 |
| 497 model()->ProcessSyncChanges(FROM_HERE, changes); | 500 model()->ProcessSyncChanges(FROM_HERE, changes); |
| 498 | 501 |
| 499 EXPECT_EQ(3U, model()->GetAllSyncData(syncable::APP_NOTIFICATIONS).size()); | 502 EXPECT_EQ(3U, model()->GetAllSyncData(syncable::APP_NOTIFICATIONS).size()); |
| 500 EXPECT_EQ(2, processor()->change_list_size()); | 503 EXPECT_EQ(2, processor()->change_list_size()); |
| 501 } | 504 } |
| 502 | 505 |
| 506 // Process over 15 changes changes when model is not empty. |
| 507 TEST_F(AppNotificationManagerSyncTest, ProcessSyncChangesEmptyModelWithMax) { |
| 508 const std::string& ext_id = "e1"; |
| 509 model()->MergeDataAndStartSyncing( |
| 510 syncable::APP_NOTIFICATIONS, |
| 511 SyncDataList(), |
| 512 processor()); |
| 513 for (unsigned int i = 0; |
| 514 i < notification_manager_constants::kMaxNotificationPerApp * 2; i++) { |
| 515 SyncChangeList changes; |
| 516 changes.push_back(CreateSyncChange( |
| 517 SyncChange::ACTION_ADD, CreateNotification(false, i, ext_id))); |
| 518 model()->ProcessSyncChanges(FROM_HERE, changes); |
| 519 if (i < notification_manager_constants::kMaxNotificationPerApp) { |
| 520 EXPECT_EQ(i + 1, |
| 521 model()->GetAllSyncData(syncable::APP_NOTIFICATIONS).size()); |
| 522 } else { |
| 523 EXPECT_EQ(notification_manager_constants::kMaxNotificationPerApp, |
| 524 model()->GetAllSyncData(syncable::APP_NOTIFICATIONS).size()); |
| 525 } |
| 526 } |
| 527 } |
| 528 |
| 503 // Process sync changes should return error if model association is not done. | 529 // Process sync changes should return error if model association is not done. |
| 504 TEST_F(AppNotificationManagerSyncTest, | 530 TEST_F(AppNotificationManagerSyncTest, |
| 505 ProcessSyncChangesErrorModelAssocNotDone) { | 531 ProcessSyncChangesErrorModelAssocNotDone) { |
| 506 SyncChangeList changes; | 532 SyncChangeList changes; |
| 507 | 533 |
| 508 SyncError sync_error = model()->ProcessSyncChanges(FROM_HERE, changes); | 534 SyncError sync_error = model()->ProcessSyncChanges(FROM_HERE, changes); |
| 509 EXPECT_TRUE(sync_error.IsSet()); | 535 EXPECT_TRUE(sync_error.IsSet()); |
| 510 EXPECT_EQ(syncable::APP_NOTIFICATIONS, sync_error.type()); | 536 EXPECT_EQ(syncable::APP_NOTIFICATIONS, sync_error.type()); |
| 511 EXPECT_EQ(0, processor()->change_list_size()); | 537 EXPECT_EQ(0, processor()->change_list_size()); |
| 512 } | 538 } |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 577 | 603 |
| 578 EXPECT_EQ(3, processor()->change_list_size()); | 604 EXPECT_EQ(3, processor()->change_list_size()); |
| 579 EXPECT_TRUE(processor()->ContainsGuid(n1->guid())); | 605 EXPECT_TRUE(processor()->ContainsGuid(n1->guid())); |
| 580 SyncChange c1 = processor()->GetChangeByGuid(n1->guid()); | 606 SyncChange c1 = processor()->GetChangeByGuid(n1->guid()); |
| 581 AssertSyncChange(c1, SyncChange::ACTION_DELETE, *n1); | 607 AssertSyncChange(c1, SyncChange::ACTION_DELETE, *n1); |
| 582 SyncChange c2 = processor()->GetChangeByGuid(n2->guid()); | 608 SyncChange c2 = processor()->GetChangeByGuid(n2->guid()); |
| 583 AssertSyncChange(c2, SyncChange::ACTION_DELETE, *n2); | 609 AssertSyncChange(c2, SyncChange::ACTION_DELETE, *n2); |
| 584 SyncChange c3 = processor()->GetChangeByGuid(n3->guid()); | 610 SyncChange c3 = processor()->GetChangeByGuid(n3->guid()); |
| 585 AssertSyncChange(c3, SyncChange::ACTION_DELETE, *n3); | 611 AssertSyncChange(c3, SyncChange::ACTION_DELETE, *n3); |
| 586 } | 612 } |
| OLD | NEW |