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 int64 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, base::Time::FromInternalValue(time), |
| 149 guid, extension_id, title, body); |
147 if (!link_url.empty()) | 150 if (!link_url.empty()) |
148 notif->set_link_url(GURL(link_url)); | 151 notif->set_link_url(GURL(link_url)); |
149 if (!link_text.empty()) | 152 if (!link_text.empty()) |
150 notif->set_link_text(link_text); | 153 notif->set_link_text(link_text); |
151 return notif; | 154 return notif; |
152 } | 155 } |
153 | 156 |
154 static SyncData CreateSyncData(int suffix) { | 157 static SyncData CreateSyncData(int suffix) { |
155 scoped_ptr<AppNotification> notif(CreateNotification(suffix)); | 158 scoped_ptr<AppNotification> notif(CreateNotification(suffix)); |
156 return AppNotificationManager::CreateSyncDataFromNotification(*notif); | 159 return AppNotificationManager::CreateSyncDataFromNotification(*notif); |
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
405 // should be returned. | 408 // should be returned. |
406 TEST_F(AppNotificationManagerSyncTest, ModelAssocBothNonEmptyTitleMismatch) { | 409 TEST_F(AppNotificationManagerSyncTest, ModelAssocBothNonEmptyTitleMismatch) { |
407 AppNotification* n1 = CreateNotification(1); | 410 AppNotification* n1 = CreateNotification(1); |
408 model()->Add(n1); | 411 model()->Add(n1); |
409 AppNotification* n2 = CreateNotification(true, 2); | 412 AppNotification* n2 = CreateNotification(true, 2); |
410 model()->Add(n2); | 413 model()->Add(n2); |
411 | 414 |
412 SyncDataList initial_data; | 415 SyncDataList initial_data; |
413 initial_data.push_back(CreateSyncData(1)); | 416 initial_data.push_back(CreateSyncData(1)); |
414 scoped_ptr<AppNotification> n1_a(CreateNotification( | 417 scoped_ptr<AppNotification> n1_a(CreateNotification( |
415 n1->is_local(), n1->guid(), n1->extension_id(), | 418 n1->is_local(), n1->creation_time().ToInternalValue(), |
| 419 n1->guid(), n1->extension_id(), |
416 n1->title() + "_changed", // different title | 420 n1->title() + "_changed", // different title |
417 n1->body(), n1->link_url().spec(), n1->link_text())); | 421 n1->body(), n1->link_url().spec(), n1->link_text())); |
418 initial_data.push_back( | 422 initial_data.push_back( |
419 AppNotificationManager::CreateSyncDataFromNotification(*n1_a)); | 423 AppNotificationManager::CreateSyncDataFromNotification(*n1_a)); |
420 | 424 |
421 SyncError sync_error = model()->MergeDataAndStartSyncing( | 425 SyncError sync_error = model()->MergeDataAndStartSyncing( |
422 syncable::APP_NOTIFICATIONS, | 426 syncable::APP_NOTIFICATIONS, |
423 initial_data, | 427 initial_data, |
424 processor()); | 428 processor()); |
425 | 429 |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
493 changes.push_back(CreateSyncChange(SyncChange::ACTION_DELETE, n1->Copy())); | 497 changes.push_back(CreateSyncChange(SyncChange::ACTION_DELETE, n1->Copy())); |
494 changes.push_back(CreateSyncChange( | 498 changes.push_back(CreateSyncChange( |
495 SyncChange::ACTION_ADD, CreateNotification(4))); | 499 SyncChange::ACTION_ADD, CreateNotification(4))); |
496 | 500 |
497 model()->ProcessSyncChanges(FROM_HERE, changes); | 501 model()->ProcessSyncChanges(FROM_HERE, changes); |
498 | 502 |
499 EXPECT_EQ(3U, model()->GetAllSyncData(syncable::APP_NOTIFICATIONS).size()); | 503 EXPECT_EQ(3U, model()->GetAllSyncData(syncable::APP_NOTIFICATIONS).size()); |
500 EXPECT_EQ(2, processor()->change_list_size()); | 504 EXPECT_EQ(2, processor()->change_list_size()); |
501 } | 505 } |
502 | 506 |
| 507 // Process over 15 changes changes when model is not empty. |
| 508 TEST_F(AppNotificationManagerSyncTest, ProcessSyncChangesEmptyModelWithMax) { |
| 509 const std::string& ext_id = "e1"; |
| 510 model()->MergeDataAndStartSyncing( |
| 511 syncable::APP_NOTIFICATIONS, |
| 512 SyncDataList(), |
| 513 processor()); |
| 514 for (unsigned int i = 0; |
| 515 i < AppNotificationManager::kMaxNotificationPerApp * 2; i++) { |
| 516 SyncChangeList changes; |
| 517 changes.push_back(CreateSyncChange( |
| 518 SyncChange::ACTION_ADD, CreateNotification(false, i, ext_id))); |
| 519 model()->ProcessSyncChanges(FROM_HERE, changes); |
| 520 if (i < AppNotificationManager::kMaxNotificationPerApp) { |
| 521 EXPECT_EQ(i + 1, |
| 522 model()->GetAllSyncData(syncable::APP_NOTIFICATIONS).size()); |
| 523 } else { |
| 524 EXPECT_EQ(AppNotificationManager::kMaxNotificationPerApp, |
| 525 model()->GetAllSyncData(syncable::APP_NOTIFICATIONS).size()); |
| 526 for (unsigned int j = i; j > i - 5; j--) { |
| 527 EXPECT_EQ( |
| 528 AppNotificationManager::kMaxNotificationPerApp, |
| 529 model()->GetAllSyncData(syncable::APP_NOTIFICATIONS).size()); |
| 530 } |
| 531 } |
| 532 } |
| 533 } |
| 534 |
503 // Process sync changes should return error if model association is not done. | 535 // Process sync changes should return error if model association is not done. |
504 TEST_F(AppNotificationManagerSyncTest, | 536 TEST_F(AppNotificationManagerSyncTest, |
505 ProcessSyncChangesErrorModelAssocNotDone) { | 537 ProcessSyncChangesErrorModelAssocNotDone) { |
506 SyncChangeList changes; | 538 SyncChangeList changes; |
507 | 539 |
508 SyncError sync_error = model()->ProcessSyncChanges(FROM_HERE, changes); | 540 SyncError sync_error = model()->ProcessSyncChanges(FROM_HERE, changes); |
509 EXPECT_TRUE(sync_error.IsSet()); | 541 EXPECT_TRUE(sync_error.IsSet()); |
510 EXPECT_EQ(syncable::APP_NOTIFICATIONS, sync_error.type()); | 542 EXPECT_EQ(syncable::APP_NOTIFICATIONS, sync_error.type()); |
511 EXPECT_EQ(0, processor()->change_list_size()); | 543 EXPECT_EQ(0, processor()->change_list_size()); |
512 } | 544 } |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
577 | 609 |
578 EXPECT_EQ(3, processor()->change_list_size()); | 610 EXPECT_EQ(3, processor()->change_list_size()); |
579 EXPECT_TRUE(processor()->ContainsGuid(n1->guid())); | 611 EXPECT_TRUE(processor()->ContainsGuid(n1->guid())); |
580 SyncChange c1 = processor()->GetChangeByGuid(n1->guid()); | 612 SyncChange c1 = processor()->GetChangeByGuid(n1->guid()); |
581 AssertSyncChange(c1, SyncChange::ACTION_DELETE, *n1); | 613 AssertSyncChange(c1, SyncChange::ACTION_DELETE, *n1); |
582 SyncChange c2 = processor()->GetChangeByGuid(n2->guid()); | 614 SyncChange c2 = processor()->GetChangeByGuid(n2->guid()); |
583 AssertSyncChange(c2, SyncChange::ACTION_DELETE, *n2); | 615 AssertSyncChange(c2, SyncChange::ACTION_DELETE, *n2); |
584 SyncChange c3 = processor()->GetChangeByGuid(n3->guid()); | 616 SyncChange c3 = processor()->GetChangeByGuid(n3->guid()); |
585 AssertSyncChange(c3, SyncChange::ACTION_DELETE, *n3); | 617 AssertSyncChange(c3, SyncChange::ACTION_DELETE, *n3); |
586 } | 618 } |
OLD | NEW |