Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(824)

Side by Side Diff: chrome/browser/notifications/sync_notifier/chrome_notifier_service_unittest.cc

Issue 12717010: Widen Data Pipes and newer protobufs (Closed) Base URL: http://git.chromium.org/chromium/src.git@newProtobufs
Patch Set: Synced Notifications newer protobufs - add priority enum adapter. Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <map> 5 #include <map>
6 6
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/utf_string_conversions.h"
9 #include "base/values.h"
10 #include "chrome/browser/notifications/notification.h"
8 #include "chrome/browser/notifications/notification_ui_manager.h" 11 #include "chrome/browser/notifications/notification_ui_manager.h"
9 #include "chrome/browser/notifications/sync_notifier/chrome_notifier_service.h" 12 #include "chrome/browser/notifications/sync_notifier/chrome_notifier_service.h"
10 #include "chrome/browser/notifications/sync_notifier/synced_notification.h" 13 #include "chrome/browser/notifications/sync_notifier/synced_notification.h"
11 #include "sync/api/sync_change.h" 14 #include "sync/api/sync_change.h"
12 #include "sync/api/sync_change_processor.h" 15 #include "sync/api/sync_change_processor.h"
13 #include "sync/api/sync_error_factory.h" 16 #include "sync/api/sync_error_factory.h"
14 #include "sync/api/sync_error_factory_mock.h" 17 #include "sync/api/sync_error_factory_mock.h"
15 #include "sync/protocol/sync.pb.h" 18 #include "sync/protocol/sync.pb.h"
16 #include "sync/protocol/synced_notification_specifics.pb.h" 19 #include "sync/protocol/synced_notification_specifics.pb.h"
17 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 17 matching lines...) Expand all
35 const char kAppId5[] = "fbcmoldooppoahjhfflnmljoanccek55"; 38 const char kAppId5[] = "fbcmoldooppoahjhfflnmljoanccek55";
36 const char kAppId6[] = "fbcmoldooppoahjhfflnmljoanccek66"; 39 const char kAppId6[] = "fbcmoldooppoahjhfflnmljoanccek66";
37 const char kAppId7[] = "fbcmoldooppoahjhfflnmljoanccek77"; 40 const char kAppId7[] = "fbcmoldooppoahjhfflnmljoanccek77";
38 const char kKey1[] = "foo"; 41 const char kKey1[] = "foo";
39 const char kKey2[] = "bar"; 42 const char kKey2[] = "bar";
40 const char kKey3[] = "bat"; 43 const char kKey3[] = "bat";
41 const char kKey4[] = "baz"; 44 const char kKey4[] = "baz";
42 const char kKey5[] = "foobar"; 45 const char kKey5[] = "foobar";
43 const char kKey6[] = "fu"; 46 const char kKey6[] = "fu";
44 const char kKey7[] = "meta"; 47 const char kKey7[] = "meta";
48 const char kIconUrl[] = "http://www.google.com/icon1.jpg";
49 const char kTitle1[] = "New appointment at 2:15";
50 const char kTitle2[] = "Email from Mark: Upcoming Ski trip";
51 const char kTitle3[] = "Weather alert - light rain tonight.";
52 const char kTitle4[] = "Zombie Alert on I-405";
53 const char kTitle5[] = "5-dimensional plutonian steam hockey scores";
54 const char kTitle6[] = "Conterfactuals Inc Stock report";
55 const char kTitle7[] = "Push Messaging app updated";
56 const char kText1[] = "Space Needle, 12:00 pm";
57 const char kText2[] = "Stevens Pass is our first choice.";
58 const char kText3[] = "More rain expected in the Seattle area tonight.";
59 const char kText4[] = "Traffic slowdown as motorists are hitting zombies";
60 const char kText5[] = "Neptune wins, pi to e";
61 const char kText6[] = "Beef flavored base for soups";
62 const char kText7[] = "You now have the latest version of Push Messaging App.";
63 const char kIconUrl1[] = "http://www.google.com/icon1.jpg";
64 const char kIconUrl2[] = "http://www.google.com/icon2.jpg";
65 const char kIconUrl3[] = "http://www.google.com/icon3.jpg";
66 const char kIconUrl4[] = "http://www.google.com/icon4.jpg";
67 const char kIconUrl5[] = "http://www.google.com/icon5.jpg";
68 const char kIconUrl6[] = "http://www.google.com/icon6.jpg";
69 const char kIconUrl7[] = "http://www.google.com/icon7.jpg";
70 const char kImageUrl1[] = "http://www.google.com/image1.jpg";
71 const char kImageUrl2[] = "http://www.google.com/image2.jpg";
72 const char kImageUrl3[] = "http://www.google.com/image3.jpg";
73 const char kImageUrl4[] = "http://www.google.com/image4.jpg";
74 const char kImageUrl5[] = "http://www.google.com/image5.jpg";
75 const char kImageUrl6[] = "http://www.google.com/image6.jpg";
76 const char kImageUrl7[] = "http://www.google.com/image7.jpg";
77 const char kExpectedOriginUrl[] =
78 "chrome-extension://fboilmbenheemaomgaeehigklolhkhnf/";
79 const char kDefaultDestinationTitle[] = "Open web page";
80 const char kDefaultDestinationIconUrl[] = "http://www.google.com/image4.jpg";
81 const char kDefaultDestinationUrl[] = "http://www.google.com";
82 const char kButtonOneTitle[] = "Read";
83 const char kButtonOneIconUrl[] = "http://www.google.com/image8.jpg";
84 const char kButtonOneUrl[] = "http://www.google.com/do-something1";
85 const char kButtonTwoTitle[] = "Reply";
86 const char kButtonTwoIconUrl[] = "http://www.google.com/image9.jpg";
87 const char kButtonTwoUrl[] = "http://www.google.com/do-something2";
88 const char kContainedTitle1[] = "Today's Picnic moved";
89 const char kContainedTitle2[] = "Group Run Today";
90 const char kContainedTitle3[] = "Starcraft Tonight";
91 const char kContainedMessage1[] = "Due to rain, we will be inside the cafe.";
92 const char kContainedMessage2[] = "Meet at noon in the Gym.";
93 const char kContainedMessage3[] = "Let's play starcraft tonight on the LAN.";
45 const int64 kFakeCreationTime = 42; 94 const int64 kFakeCreationTime = 42;
95 const int kProtobufPriority = static_cast<int>(
96 sync_pb::CoalescedSyncedNotification_Priority_LOW);
97 const int kNotificationPriority = static_cast<int>(
98 message_center::LOW_PRIORITY);
46 const sync_pb::CoalescedSyncedNotification_ReadState kDismissed = 99 const sync_pb::CoalescedSyncedNotification_ReadState kDismissed =
47 sync_pb::CoalescedSyncedNotification_ReadState_DISMISSED; 100 sync_pb::CoalescedSyncedNotification_ReadState_DISMISSED;
48 const sync_pb::CoalescedSyncedNotification_ReadState kUnread = 101 const sync_pb::CoalescedSyncedNotification_ReadState kUnread =
49 sync_pb::CoalescedSyncedNotification_ReadState_UNREAD; 102 sync_pb::CoalescedSyncedNotification_ReadState_UNREAD;
50 103
51 // Extract notification id from syncer::SyncData. 104 // Extract notification id from syncer::SyncData.
52 std::string GetNotificationId(const SyncData& sync_data) { 105 std::string GetNotificationId(const SyncData& sync_data) {
53 SyncedNotificationSpecifics specifics = sync_data.GetSpecifics(). 106 SyncedNotificationSpecifics specifics = sync_data.GetSpecifics().
54 synced_notification(); 107 synced_notification();
108
55 return specifics.coalesced_notification().key(); 109 return specifics.coalesced_notification().key();
56 } 110 }
57 111
58 // Stub out the NotificationUIManager for unit testing. 112 // Stub out the NotificationUIManager for unit testing.
59 class StubNotificationUIManager : public NotificationUIManager { 113 class StubNotificationUIManager : public NotificationUIManager {
60 public: 114 public:
61 StubNotificationUIManager() {} 115 StubNotificationUIManager() : notification_(GURL(), GURL(), L"", L"", NULL) {}
dcheng 2013/03/28 18:10:17 L"", L"" is not going to work on platforms where s
Pete Williamson 2013/03/28 19:59:00 Done.
62 virtual ~StubNotificationUIManager() {} 116 virtual ~StubNotificationUIManager() {}
63 117
64 // Adds a notification to be displayed. Virtual for unit test override. 118 // Adds a notification to be displayed. Virtual for unit test override.
65 virtual void Add(const Notification& notification, Profile* profile) 119 virtual void Add(const Notification& notification, Profile* profile)
66 OVERRIDE {} 120 OVERRIDE {
121 // Make a deep copy of the notification that we can inspect.
122 notification_ = notification;
123 }
67 124
68 // Returns true if any notifications match the supplied ID, either currently 125 // Returns true if any notifications match the supplied ID, either currently
69 // displayed or in the queue. 126 // displayed or in the queue.
70 virtual bool DoesIdExist(const std::string& id) OVERRIDE { 127 virtual bool DoesIdExist(const std::string& id) OVERRIDE {
71 return true; 128 return true;
72 } 129 }
73 130
74 // Removes any notifications matching the supplied ID, either currently 131 // Removes any notifications matching the supplied ID, either currently
75 // displayed or in the queue. Returns true if anything was removed. 132 // displayed or in the queue. Returns true if anything was removed.
76 virtual bool CancelById(const std::string& notification_id) OVERRIDE { 133 virtual bool CancelById(const std::string& notification_id) OVERRIDE {
77 return false; 134 return false;
78 } 135 }
79 136
80 // Removes notifications matching the |source_origin| (which could be an 137 // Removes notifications matching the |source_origin| (which could be an
81 // extension ID). Returns true if anything was removed. 138 // extension ID). Returns true if anything was removed.
82 virtual bool CancelAllBySourceOrigin(const GURL& source_origin) OVERRIDE { 139 virtual bool CancelAllBySourceOrigin(const GURL& source_origin) OVERRIDE {
83 return false; 140 return false;
84 } 141 }
85 142
86 // Removes notifications matching |profile|. Returns true if any were removed. 143 // Removes notifications matching |profile|. Returns true if any were removed.
87 virtual bool CancelAllByProfile(Profile* profile) OVERRIDE { 144 virtual bool CancelAllByProfile(Profile* profile) OVERRIDE {
88 return false; 145 return false;
89 } 146 }
90 147
91 // Cancels all pending notifications and closes anything currently showing. 148 // Cancels all pending notifications and closes anything currently showing.
92 // Used when the app is terminating. 149 // Used when the app is terminating.
93 virtual void CancelAll() OVERRIDE {} 150 virtual void CancelAll() OVERRIDE {}
94 151
152 // Test hook to get the notification so we can check it
153 const Notification& notification() { return notification_; }
dcheng 2013/03/28 18:10:17 Nit: const-ify this method.
Pete Williamson 2013/03/28 19:59:00 Done.
154
95 private: 155 private:
96 DISALLOW_COPY_AND_ASSIGN(StubNotificationUIManager); 156 DISALLOW_COPY_AND_ASSIGN(StubNotificationUIManager);
157 Notification notification_;
97 }; 158 };
98 159
99 // Dummy SyncChangeProcessor used to help review what SyncChanges are pushed 160 // Dummy SyncChangeProcessor used to help review what SyncChanges are pushed
100 // back up to Sync. 161 // back up to Sync.
101 class TestChangeProcessor : public syncer::SyncChangeProcessor { 162 class TestChangeProcessor : public syncer::SyncChangeProcessor {
102 public: 163 public:
103 TestChangeProcessor() { } 164 TestChangeProcessor() { }
104 virtual ~TestChangeProcessor() { } 165 virtual ~TestChangeProcessor() { }
105 166
106 // Store a copy of all the changes passed in so we can examine them later. 167 // Store a copy of all the changes passed in so we can examine them later.
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 234
174 TestChangeProcessor* processor() { 235 TestChangeProcessor* processor() {
175 return static_cast<TestChangeProcessor*>(sync_processor_.get()); 236 return static_cast<TestChangeProcessor*>(sync_processor_.get());
176 } 237 }
177 238
178 scoped_ptr<syncer::SyncChangeProcessor> PassProcessor() { 239 scoped_ptr<syncer::SyncChangeProcessor> PassProcessor() {
179 return sync_processor_delegate_.Pass(); 240 return sync_processor_delegate_.Pass();
180 } 241 }
181 242
182 SyncedNotification* CreateNotification( 243 SyncedNotification* CreateNotification(
183 const std::string& message, 244 const std::string& title,
245 const std::string& text,
246 const std::string& app_icon_url,
247 const std::string& image_url,
184 const std::string& app_id, 248 const std::string& app_id,
185 const std::string& key, 249 const std::string& key,
186 const std::string& external_id,
187 sync_pb::CoalescedSyncedNotification_ReadState read_state) { 250 sync_pb::CoalescedSyncedNotification_ReadState read_state) {
188 SyncData sync_data = CreateSyncData(message, app_id, key, 251 SyncData sync_data = CreateSyncData(title, text, app_icon_url, image_url,
189 external_id, read_state); 252 app_id, key, read_state);
190 // Set enough fields in sync_data, including specifics, for our tests 253 // Set enough fields in sync_data, including specifics, for our tests
191 // to pass. 254 // to pass.
192 return new SyncedNotification(sync_data); 255 return new SyncedNotification(sync_data);
193 } 256 }
194 257
195 // Helper to create syncer::SyncChange. 258 // Helper to create syncer::SyncChange.
196 static SyncChange CreateSyncChange( 259 static SyncChange CreateSyncChange(
197 SyncChange::SyncChangeType type, 260 SyncChange::SyncChangeType type,
198 SyncedNotification* notification) { 261 SyncedNotification* notification) {
199 // Take control of the notification to clean it up after we create data 262 // Take control of the notification to clean it up after we create data
200 // out of it. 263 // out of it.
201 scoped_ptr<SyncedNotification> scoped_notification(notification); 264 scoped_ptr<SyncedNotification> scoped_notification(notification);
202 return SyncChange( 265 return SyncChange(
203 FROM_HERE, 266 FROM_HERE,
204 type, 267 type,
205 ChromeNotifierService::CreateSyncDataFromNotification(*notification)); 268 ChromeNotifierService::CreateSyncDataFromNotification(*notification));
206 } 269 }
207 270
208 // Helper to create syncer::SyncData. 271 // Helper to create syncer::SyncData.
209 static SyncData CreateSyncData( 272 static SyncData CreateSyncData(
210 const std::string& message, 273 const std::string& title,
274 const std::string& text,
275 const std::string& app_icon_url,
276 const std::string& image_url,
211 const std::string& app_id, 277 const std::string& app_id,
212 const std::string& key, 278 const std::string& key,
213 const std::string& external_id, 279 const sync_pb::CoalescedSyncedNotification_ReadState read_state) {
214 sync_pb::CoalescedSyncedNotification_ReadState read_state) {
215 // CreateLocalData makes a copy of this, so this can safely live 280 // CreateLocalData makes a copy of this, so this can safely live
216 // on the stack. 281 // on the stack.
217 EntitySpecifics entity_specifics; 282 EntitySpecifics entity_specifics;
218 283
284 // Get a writeable pointer to the sync notifications specifics inside the
285 // entity specifics.
219 SyncedNotificationSpecifics* specifics = 286 SyncedNotificationSpecifics* specifics =
220 entity_specifics.mutable_synced_notification(); 287 entity_specifics.mutable_synced_notification();
221 288
222 specifics->mutable_coalesced_notification()-> 289 specifics->mutable_coalesced_notification()->
223 set_app_id(app_id); 290 set_app_id(app_id);
224 291
225 specifics->mutable_coalesced_notification()-> 292 specifics->mutable_coalesced_notification()->
226 set_key(key); 293 set_key(key);
227 294
228 specifics->mutable_coalesced_notification()-> 295 specifics->mutable_coalesced_notification()->
229 mutable_render_info()-> 296 set_priority(static_cast<sync_pb::CoalescedSyncedNotification_Priority>(
230 mutable_expanded_info()-> 297 kProtobufPriority));
231 mutable_simple_expanded_layout()-> 298
232 set_title(message); 299 // Set the title.
233 300 specifics->mutable_coalesced_notification()->
234 specifics-> 301 mutable_render_info()->
235 mutable_coalesced_notification()-> 302 mutable_expanded_info()->
303 mutable_simple_expanded_layout()->
304 set_title(title);
305
306 // Set the text.
307 specifics->mutable_coalesced_notification()->
308 mutable_render_info()->
309 mutable_expanded_info()->
310 mutable_simple_expanded_layout()->
311 set_text(text);
312
313 // Set the heading.
314 specifics->
315 mutable_coalesced_notification()->
316 mutable_render_info()->
317 mutable_collapsed_info()->
318 mutable_simple_collapsed_layout()->
319 set_heading(title);
320
321 // Add the collapsed info and set the app_icon_url on it.
322 specifics->
323 mutable_coalesced_notification()->
324 mutable_render_info()->
325 mutable_expanded_info()->
326 add_collapsed_info();
327 specifics->
328 mutable_coalesced_notification()->
329 mutable_render_info()->
330 mutable_expanded_info()->
331 mutable_collapsed_info(0)->
332 mutable_simple_collapsed_layout()->
333 mutable_app_icon()->
334 set_url(app_icon_url);
335
336 // Add the media object and set the image url on it.
337 specifics->
338 mutable_coalesced_notification()->
339 mutable_render_info()->
340 mutable_expanded_info()->
341 mutable_simple_expanded_layout()->
342 add_media();
343 specifics->
344 mutable_coalesced_notification()->
345 mutable_render_info()->
346 mutable_expanded_info()->
347 mutable_simple_expanded_layout()->
348 mutable_media(0)->
349 mutable_image()->
350 set_url(image_url);
351
352 specifics->mutable_coalesced_notification()->
236 set_creation_time_msec(kFakeCreationTime); 353 set_creation_time_msec(kFakeCreationTime);
237 354
238 specifics-> 355 specifics->mutable_coalesced_notification()->
239 mutable_coalesced_notification()->
240 add_notification();
241
242 specifics->
243 mutable_coalesced_notification()->
244 mutable_notification(0)->set_external_id(external_id);
245
246 specifics->
247 mutable_coalesced_notification()->
248 set_read_state(read_state); 356 set_read_state(read_state);
249 357
358 // Contained notification one.
359 // We re-use the collapsed info we added for the app_icon_url,
360 // so no need to create another one here.
361 specifics->mutable_coalesced_notification()->
362 mutable_render_info()->
363 mutable_expanded_info()->
364 mutable_collapsed_info(0)->
365 mutable_simple_collapsed_layout()->
366 set_heading(kContainedTitle1);
367 specifics->mutable_coalesced_notification()->
368 mutable_render_info()->
369 mutable_expanded_info()->
370 mutable_collapsed_info(0)->
371 mutable_simple_collapsed_layout()->
372 set_description(kContainedMessage1);
373
374 // Contained notification two.
375 specifics->mutable_coalesced_notification()->
376 mutable_render_info()->
377 mutable_expanded_info()->
378 add_collapsed_info();
379 specifics->mutable_coalesced_notification()->
380 mutable_render_info()->
381 mutable_expanded_info()->
382 mutable_collapsed_info(1)->
383 mutable_simple_collapsed_layout()->
384 set_heading(kContainedTitle2);
385 specifics->mutable_coalesced_notification()->
386 mutable_render_info()->
387 mutable_expanded_info()->
388 mutable_collapsed_info(1)->
389 mutable_simple_collapsed_layout()->
390 set_description(kContainedMessage2);
391
392 // Contained notification three.
393 specifics->mutable_coalesced_notification()->
394 mutable_render_info()->
395 mutable_expanded_info()->
396 add_collapsed_info();
397 specifics->mutable_coalesced_notification()->
398 mutable_render_info()->
399 mutable_expanded_info()->
400 mutable_collapsed_info(2)->
401 mutable_simple_collapsed_layout()->
402 set_heading(kContainedTitle3);
403 specifics->mutable_coalesced_notification()->
404 mutable_render_info()->
405 mutable_expanded_info()->
406 mutable_collapsed_info(2)->
407 mutable_simple_collapsed_layout()->
408 set_description(kContainedMessage3);
409
410 // Default Destination.
411 specifics->mutable_coalesced_notification()->
412 mutable_render_info()->
413 mutable_collapsed_info()->
414 mutable_default_destination()->
415 set_text(kDefaultDestinationTitle);
416 specifics->mutable_coalesced_notification()->
417 mutable_render_info()->
418 mutable_collapsed_info()->
419 mutable_default_destination()->
420 mutable_icon()->
421 set_url(kDefaultDestinationIconUrl);
422 specifics->mutable_coalesced_notification()->
423 mutable_render_info()->
424 mutable_collapsed_info()->
425 mutable_default_destination()->
426 mutable_icon()->
427 set_alt_text(kDefaultDestinationTitle);
428 specifics->mutable_coalesced_notification()->
429 mutable_render_info()->
430 mutable_collapsed_info()->
431 mutable_default_destination()->
432 set_url(kDefaultDestinationUrl);
433
434 // Buttons are represented as targets.
435
436 // Button One.
437 specifics->mutable_coalesced_notification()->
438 mutable_render_info()->
439 mutable_collapsed_info()->
440 add_target();
441 specifics->mutable_coalesced_notification()->
442 mutable_render_info()->
443 mutable_collapsed_info()->
444 mutable_target(0)->
445 mutable_action()->
446 set_text(kButtonOneTitle);
447 specifics->mutable_coalesced_notification()->
448 mutable_render_info()->
449 mutable_collapsed_info()->
450 mutable_target(0)->
451 mutable_action()->
452 mutable_icon()->
453 set_url(kButtonOneIconUrl);
454 specifics->mutable_coalesced_notification()->
455 mutable_render_info()->
456 mutable_collapsed_info()->
457 mutable_target(0)->
458 mutable_action()->
459 mutable_icon()->
460 set_alt_text(kButtonOneTitle);
461 specifics->mutable_coalesced_notification()->
462 mutable_render_info()->
463 mutable_collapsed_info()->
464 mutable_target(0)->
465 mutable_action()->
466 set_url(kButtonOneUrl);
467
468 // Button Two.
469 specifics->mutable_coalesced_notification()->
470 mutable_render_info()->
471 mutable_collapsed_info()->
472 add_target();
473 specifics->mutable_coalesced_notification()->
474 mutable_render_info()->
475 mutable_collapsed_info()->
476 mutable_target(1)->
477 mutable_action()->
478 set_text(kButtonTwoTitle);
479 specifics->mutable_coalesced_notification()->
480 mutable_render_info()->
481 mutable_collapsed_info()->
482 mutable_target(1)->
483 mutable_action()->
484 mutable_icon()->
485 set_url(kButtonTwoIconUrl);
486 specifics->mutable_coalesced_notification()->
487 mutable_render_info()->
488 mutable_collapsed_info()->
489 mutable_target(1)->
490 mutable_action()->
491 mutable_icon()->
492 set_alt_text(kButtonTwoTitle);
493 specifics->mutable_coalesced_notification()->
494 mutable_render_info()->
495 mutable_collapsed_info()->
496 mutable_target(1)->
497 mutable_action()->
498 set_url(kButtonTwoUrl);
499
250 SyncData sync_data = SyncData::CreateLocalData( 500 SyncData sync_data = SyncData::CreateLocalData(
251 "syncer::SYNCED_NOTIFICATIONS", 501 "syncer::SYNCED_NOTIFICATIONS",
252 "ChromeNotifierServiceUnitTest", 502 "ChromeNotifierServiceUnitTest",
253 entity_specifics); 503 entity_specifics);
254 504
255 return sync_data; 505 return sync_data;
256 } 506 }
257 507
258 private: 508 private:
259 scoped_ptr<syncer::SyncChangeProcessor> sync_processor_; 509 scoped_ptr<syncer::SyncChangeProcessor> sync_processor_;
260 scoped_ptr<syncer::SyncChangeProcessor> sync_processor_delegate_; 510 scoped_ptr<syncer::SyncChangeProcessor> sync_processor_delegate_;
261 511
262 DISALLOW_COPY_AND_ASSIGN(ChromeNotifierServiceTest); 512 DISALLOW_COPY_AND_ASSIGN(ChromeNotifierServiceTest);
263 }; 513 };
264 514
265 // TODO(petewil): Add more tests as I add functionalty. Tests are based on 515 // TODO(petewil): Add more tests as I add functionalty. Tests are based on
266 // chrome/browser/extensions/app_notification_manager_sync_unittest.cc 516 // chrome/browser/extensions/app_notification_manager_sync_unittest.cc
267 517
268 // Create a Notification, convert it to SyncData and convert it back. 518 // Create a Notification, convert it to SyncData and convert it back.
269 TEST_F(ChromeNotifierServiceTest, NotificationToSyncDataToNotification) { 519 TEST_F(ChromeNotifierServiceTest, NotificationToSyncDataToNotification) {
270 scoped_ptr<SyncedNotification> notification1( 520 scoped_ptr<SyncedNotification> notification1(
271 CreateNotification("1", kAppId1, kKey1, "11", kUnread)); 521 CreateNotification(kTitle1, kText1, kIconUrl1, kImageUrl1, kAppId1,
522 kKey1, kUnread));
272 SyncData sync_data = 523 SyncData sync_data =
273 ChromeNotifierService::CreateSyncDataFromNotification(*notification1); 524 ChromeNotifierService::CreateSyncDataFromNotification(*notification1);
274 scoped_ptr<SyncedNotification> notification2( 525 scoped_ptr<SyncedNotification> notification2(
275 ChromeNotifierService::CreateNotificationFromSyncData(sync_data)); 526 ChromeNotifierService::CreateNotificationFromSyncData(sync_data));
276 EXPECT_TRUE(notification2.get()); 527 EXPECT_TRUE(notification2.get());
277 EXPECT_TRUE(notification1->EqualsIgnoringReadState(*notification2)); 528 EXPECT_TRUE(notification1->EqualsIgnoringReadState(*notification2));
278 EXPECT_EQ(notification1->read_state(), notification2->read_state()); 529 EXPECT_EQ(notification1->GetReadState(), notification2->GetReadState());
279 } 530 }
280 531
281 // Model assocation: We have no local data, and no remote data. 532 // Model assocation: We have no local data, and no remote data.
282 TEST_F(ChromeNotifierServiceTest, ModelAssocBothEmpty) { 533 TEST_F(ChromeNotifierServiceTest, ModelAssocBothEmpty) {
283 StubNotificationUIManager notification_manager; 534 StubNotificationUIManager notification_manager;
284 ChromeNotifierService notifier(NULL, &notification_manager); 535 ChromeNotifierService notifier(NULL, &notification_manager);
285 536
286 notifier.MergeDataAndStartSyncing( 537 notifier.MergeDataAndStartSyncing(
287 SYNCED_NOTIFICATIONS, 538 SYNCED_NOTIFICATIONS,
288 SyncDataList(), // Empty. 539 SyncDataList(), // Empty.
(...skipping 13 matching lines...) Expand all
302 notifier.MergeDataAndStartSyncing( 553 notifier.MergeDataAndStartSyncing(
303 SYNCED_NOTIFICATIONS, 554 SYNCED_NOTIFICATIONS,
304 SyncDataList(), 555 SyncDataList(),
305 PassProcessor(), 556 PassProcessor(),
306 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); 557 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock()));
307 558
308 // Set up a bunch of ADDs. 559 // Set up a bunch of ADDs.
309 SyncChangeList changes; 560 SyncChangeList changes;
310 changes.push_back(CreateSyncChange( 561 changes.push_back(CreateSyncChange(
311 SyncChange::ACTION_ADD, CreateNotification( 562 SyncChange::ACTION_ADD, CreateNotification(
312 "1", kAppId1, kKey1, "11", kUnread))); 563 kTitle1, kText1, kIconUrl1, kImageUrl1, kAppId1, kKey1, kUnread)));
313 changes.push_back(CreateSyncChange( 564 changes.push_back(CreateSyncChange(
314 SyncChange::ACTION_ADD, CreateNotification( 565 SyncChange::ACTION_ADD, CreateNotification(
315 "2", kAppId2, kKey2, "22", kUnread))); 566 kTitle2, kText2, kIconUrl2, kImageUrl2, kAppId2, kKey2, kUnread)));
316 changes.push_back(CreateSyncChange( 567 changes.push_back(CreateSyncChange(
317 SyncChange::ACTION_ADD, CreateNotification( 568 SyncChange::ACTION_ADD, CreateNotification(
318 "3", kAppId3, kKey3, "33", kUnread))); 569 kTitle3, kText3, kIconUrl3, kImageUrl3, kAppId3, kKey3, kUnread)));
319 570
320 notifier.ProcessSyncChanges(FROM_HERE, changes); 571 notifier.ProcessSyncChanges(FROM_HERE, changes);
321 572
322 EXPECT_EQ(3U, notifier.GetAllSyncData(SYNCED_NOTIFICATIONS).size()); 573 EXPECT_EQ(3U, notifier.GetAllSyncData(SYNCED_NOTIFICATIONS).size());
323 // TODO(petewil): verify that the list entries have expected values to make 574 // TODO(petewil): verify that the list entries have expected values to make
324 // this test more robust. 575 // this test more robust.
325 } 576 }
326 577
327 // Model has some notifications, some of them are local only. Sync has some 578 // Model has some notifications, some of them are local only. Sync has some
328 // notifications. No items match up. 579 // notifications. No items match up.
329 TEST_F(ChromeNotifierServiceTest, LocalRemoteBothNonEmptyNoOverlap) { 580 TEST_F(ChromeNotifierServiceTest, LocalRemoteBothNonEmptyNoOverlap) {
330 StubNotificationUIManager notification_manager; 581 StubNotificationUIManager notification_manager;
331 ChromeNotifierService notifier(NULL, &notification_manager); 582 ChromeNotifierService notifier(NULL, &notification_manager);
332 583
333 // Create some local fake data. 584 // Create some local fake data.
334 scoped_ptr<SyncedNotification> n1(CreateNotification( 585 scoped_ptr<SyncedNotification> n1(CreateNotification(
335 "1", kAppId1, kKey1, "11", kUnread)); 586 kTitle1, kText1, kIconUrl1, kImageUrl1, kAppId1, kKey1, kUnread));
336 notifier.AddForTest(n1.Pass()); 587 notifier.AddForTest(n1.Pass());
337 scoped_ptr<SyncedNotification> n2(CreateNotification( 588 scoped_ptr<SyncedNotification> n2(CreateNotification(
338 "2", kAppId2, kKey2, "22", kUnread)); 589 kTitle2, kText2, kIconUrl2, kImageUrl2, kAppId2, kKey2, kUnread));
339 notifier.AddForTest(n2.Pass()); 590 notifier.AddForTest(n2.Pass());
340 scoped_ptr<SyncedNotification> n3(CreateNotification( 591 scoped_ptr<SyncedNotification> n3(CreateNotification(
341 "3", kAppId3, kKey3, "33", kUnread)); 592 kTitle3, kText3, kIconUrl3, kImageUrl3, kAppId3, kKey3, kUnread));
342 notifier.AddForTest(n3.Pass()); 593 notifier.AddForTest(n3.Pass());
343 594
344 // Create some remote fake data. 595 // Create some remote fake data.
345 SyncDataList initial_data; 596 SyncDataList initial_data;
346 initial_data.push_back(CreateSyncData("4", kAppId4, kKey4, 597 initial_data.push_back(CreateSyncData(kTitle4, kText4, kIconUrl4, kImageUrl4,
347 "44", kUnread)); 598 kAppId4, kKey4, kUnread));
348 initial_data.push_back(CreateSyncData("5", kAppId5, kKey5, 599 initial_data.push_back(CreateSyncData(kTitle5, kText5, kIconUrl5, kImageUrl5,
349 "55", kUnread)); 600 kAppId5, kKey5, kUnread));
350 initial_data.push_back(CreateSyncData("6", kAppId6, kKey6, 601 initial_data.push_back(CreateSyncData(kTitle6, kText6, kIconUrl6, kImageUrl6,
351 "66", kUnread)); 602 kAppId6, kKey6, kUnread));
352 initial_data.push_back(CreateSyncData("7", kAppId7, kKey7, 603 initial_data.push_back(CreateSyncData(kTitle7, kText7, kIconUrl7, kImageUrl7,
353 "77", kUnread)); 604 kAppId7, kKey7, kUnread));
354 605
355 // Merge the local and remote data. 606 // Merge the local and remote data.
356 notifier.MergeDataAndStartSyncing( 607 notifier.MergeDataAndStartSyncing(
357 SYNCED_NOTIFICATIONS, 608 SYNCED_NOTIFICATIONS,
358 initial_data, 609 initial_data,
359 PassProcessor(), 610 PassProcessor(),
360 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); 611 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock()));
361 612
362 // Ensure the local store now has all local and remote notifications. 613 // Ensure the local store now has all local and remote notifications.
363 EXPECT_EQ(7U, notifier.GetAllSyncData(SYNCED_NOTIFICATIONS).size()); 614 EXPECT_EQ(7U, notifier.GetAllSyncData(SYNCED_NOTIFICATIONS).size());
364 EXPECT_TRUE(notifier.FindNotificationById(kKey1)); 615 EXPECT_TRUE(notifier.FindNotificationByKey(kKey1));
365 EXPECT_TRUE(notifier.FindNotificationById(kKey2)); 616 EXPECT_TRUE(notifier.FindNotificationByKey(kKey2));
366 EXPECT_TRUE(notifier.FindNotificationById(kKey3)); 617 EXPECT_TRUE(notifier.FindNotificationByKey(kKey3));
367 EXPECT_TRUE(notifier.FindNotificationById(kKey4)); 618 EXPECT_TRUE(notifier.FindNotificationByKey(kKey4));
368 EXPECT_TRUE(notifier.FindNotificationById(kKey5)); 619 EXPECT_TRUE(notifier.FindNotificationByKey(kKey5));
369 EXPECT_TRUE(notifier.FindNotificationById(kKey6)); 620 EXPECT_TRUE(notifier.FindNotificationByKey(kKey6));
370 EXPECT_TRUE(notifier.FindNotificationById(kKey7)); 621 EXPECT_TRUE(notifier.FindNotificationByKey(kKey7));
371 622
372 // Test the type conversion and construction functions. 623 // Test the type conversion and construction functions.
373 for (SyncDataList::const_iterator iter = initial_data.begin(); 624 for (SyncDataList::const_iterator iter = initial_data.begin();
374 iter != initial_data.end(); ++iter) { 625 iter != initial_data.end(); ++iter) {
375 scoped_ptr<SyncedNotification> notification1( 626 scoped_ptr<SyncedNotification> notification1(
376 ChromeNotifierService::CreateNotificationFromSyncData(*iter)); 627 ChromeNotifierService::CreateNotificationFromSyncData(*iter));
377 // TODO(petewil): Revisit this when we add version info to notifications. 628 // TODO(petewil): Revisit this when we add version info to notifications.
378 const std::string& id = notification1->notification_id(); 629 const std::string& key = notification1->GetKey();
379 const SyncedNotification* notification2 = notifier.FindNotificationById(id); 630 const SyncedNotification* notification2 =
631 notifier.FindNotificationByKey(key);
380 EXPECT_TRUE(NULL != notification2); 632 EXPECT_TRUE(NULL != notification2);
381 EXPECT_TRUE(notification1->EqualsIgnoringReadState(*notification2)); 633 EXPECT_TRUE(notification1->EqualsIgnoringReadState(*notification2));
382 EXPECT_EQ(notification1->read_state(), notification2->read_state()); 634 EXPECT_EQ(notification1->GetReadState(), notification2->GetReadState());
383 } 635 }
384 EXPECT_TRUE(notifier.FindNotificationById(kKey1)); 636 EXPECT_TRUE(notifier.FindNotificationByKey(kKey1));
385 EXPECT_TRUE(notifier.FindNotificationById(kKey2)); 637 EXPECT_TRUE(notifier.FindNotificationByKey(kKey2));
386 EXPECT_TRUE(notifier.FindNotificationById(kKey3)); 638 EXPECT_TRUE(notifier.FindNotificationByKey(kKey3));
387 } 639 }
388 640
389 // Test the local store having the read bit unset, the remote store having 641 // Test the local store having the read bit unset, the remote store having
390 // it set. 642 // it set.
391 TEST_F(ChromeNotifierServiceTest, ModelAssocBothNonEmptyReadMismatch1) { 643 TEST_F(ChromeNotifierServiceTest, ModelAssocBothNonEmptyReadMismatch1) {
392 StubNotificationUIManager notification_manager; 644 StubNotificationUIManager notification_manager;
393 ChromeNotifierService notifier(NULL, &notification_manager); 645 ChromeNotifierService notifier(NULL, &notification_manager);
394 646
395 // Create some local fake data. 647 // Create some local fake data.
396 scoped_ptr<SyncedNotification> n1(CreateNotification( 648 scoped_ptr<SyncedNotification> n1(CreateNotification(
397 "1", kAppId1, kKey1, "11", kUnread)); 649 kTitle1, kText1, kIconUrl1, kImageUrl1, kAppId1, kKey1, kUnread));
398 notifier.AddForTest(n1.Pass()); 650 notifier.AddForTest(n1.Pass());
399 scoped_ptr<SyncedNotification> n2(CreateNotification( 651 scoped_ptr<SyncedNotification> n2(CreateNotification(
400 "2", kAppId2, kKey2, "22", kUnread)); 652 kTitle2, kText2, kIconUrl2, kImageUrl2, kAppId2, kKey2, kUnread));
401 notifier.AddForTest(n2.Pass()); 653 notifier.AddForTest(n2.Pass());
402 654
403 // Create some remote fake data, item 1 matches except for the read state. 655 // Create some remote fake data, item 1 matches except for the read state.
404 syncer::SyncDataList initial_data; 656 syncer::SyncDataList initial_data;
405 initial_data.push_back(CreateSyncData("1", kAppId1, kKey1, 657 initial_data.push_back(CreateSyncData(kTitle1, kText1, kIconUrl1, kImageUrl1,
406 "11", kDismissed)); 658 kAppId1, kKey1, kDismissed));
407 // Merge the local and remote data. 659 // Merge the local and remote data.
408 notifier.MergeDataAndStartSyncing( 660 notifier.MergeDataAndStartSyncing(
409 syncer::SYNCED_NOTIFICATIONS, 661 syncer::SYNCED_NOTIFICATIONS,
410 initial_data, 662 initial_data,
411 PassProcessor(), 663 PassProcessor(),
412 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); 664 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock()));
413 665
414 // Ensure the local store still has only two notifications, and the read 666 // Ensure the local store still has only two notifications, and the read
415 // state of the first is now read. 667 // state of the first is now read.
416 EXPECT_EQ(2U, notifier.GetAllSyncData(syncer::SYNCED_NOTIFICATIONS).size()); 668 EXPECT_EQ(2U, notifier.GetAllSyncData(syncer::SYNCED_NOTIFICATIONS).size());
417 SyncedNotification* notification1 = 669 SyncedNotification* notification1 =
418 notifier.FindNotificationById(kKey1); 670 notifier.FindNotificationByKey(kKey1);
419 EXPECT_FALSE(NULL == notification1); 671 EXPECT_FALSE(NULL == notification1);
420 EXPECT_EQ(SyncedNotification::kDismissed, notification1->read_state()); 672 EXPECT_EQ(kDismissed, notification1->GetReadState());
421 EXPECT_TRUE(notifier.FindNotificationById(kKey2)); 673 EXPECT_TRUE(notifier.FindNotificationByKey(kKey2));
422 EXPECT_FALSE(notifier.FindNotificationById(kKey3)); 674 EXPECT_FALSE(notifier.FindNotificationByKey(kKey3));
423 675
424 // Ensure no new data will be sent to the remote store for notification1. 676 // Ensure no new data will be sent to the remote store for notification1.
425 EXPECT_EQ(0U, processor()->change_list_size()); 677 EXPECT_EQ(0U, processor()->change_list_size());
426 EXPECT_FALSE(processor()->ContainsId(kKey1)); 678 EXPECT_FALSE(processor()->ContainsId(kKey1));
427 } 679 }
428 680
429 // Test when the local store has the read bit set, and the remote store has 681 // Test when the local store has the read bit set, and the remote store has
430 // it unset. 682 // it unset.
431 TEST_F(ChromeNotifierServiceTest, ModelAssocBothNonEmptyReadMismatch2) { 683 TEST_F(ChromeNotifierServiceTest, ModelAssocBothNonEmptyReadMismatch2) {
432 StubNotificationUIManager notification_manager; 684 StubNotificationUIManager notification_manager;
433 ChromeNotifierService notifier(NULL, &notification_manager); 685 ChromeNotifierService notifier(NULL, &notification_manager);
434 686
435 // Create some local fake data. 687 // Create some local fake data.
436 scoped_ptr<SyncedNotification> n1(CreateNotification( 688 scoped_ptr<SyncedNotification> n1(CreateNotification(
437 "1", kAppId1, kKey1, "11", kDismissed)); 689 kTitle1, kText1, kIconUrl1, kImageUrl1, kAppId1, kKey1, kDismissed));
438 notifier.AddForTest(n1.Pass()); 690 notifier.AddForTest(n1.Pass());
439 scoped_ptr<SyncedNotification> n2(CreateNotification( 691 scoped_ptr<SyncedNotification> n2(CreateNotification(
440 "2", kAppId2, kKey2, "22", kUnread)); 692 kTitle2, kText2, kIconUrl2, kImageUrl2, kAppId2, kKey2, kUnread));
441 notifier.AddForTest(n2.Pass()); 693 notifier.AddForTest(n2.Pass());
442 694
443 // Create some remote fake data, item 1 matches except for the read state. 695 // Create some remote fake data, item 1 matches except for the read state.
444 syncer::SyncDataList initial_data; 696 syncer::SyncDataList initial_data;
445 initial_data.push_back(CreateSyncData("1", kAppId1, kKey1, 697 initial_data.push_back(CreateSyncData(kTitle1, kText1, kIconUrl1, kImageUrl1,
446 "11", kUnread)); 698 kAppId1, kKey1, kUnread));
447 // Merge the local and remote data. 699 // Merge the local and remote data.
448 notifier.MergeDataAndStartSyncing( 700 notifier.MergeDataAndStartSyncing(
449 syncer::SYNCED_NOTIFICATIONS, 701 syncer::SYNCED_NOTIFICATIONS,
450 initial_data, 702 initial_data,
451 PassProcessor(), 703 PassProcessor(),
452 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); 704 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock()));
453 705
454 // Ensure the local store still has only two notifications, and the read 706 // Ensure the local store still has only two notifications, and the read
455 // state of the first is now read. 707 // state of the first is now read.
456 EXPECT_EQ(2U, notifier.GetAllSyncData(syncer::SYNCED_NOTIFICATIONS).size()); 708 EXPECT_EQ(2U, notifier.GetAllSyncData(syncer::SYNCED_NOTIFICATIONS).size());
457 SyncedNotification* notification1 = 709 SyncedNotification* notification1 =
458 notifier.FindNotificationById(kKey1); 710 notifier.FindNotificationByKey(kKey1);
459 EXPECT_FALSE(NULL == notification1); 711 EXPECT_FALSE(NULL == notification1);
460 EXPECT_EQ(SyncedNotification::kDismissed, notification1->read_state()); 712 EXPECT_EQ(kDismissed, notification1->GetReadState());
461 EXPECT_TRUE(notifier.FindNotificationById(kKey2)); 713 EXPECT_TRUE(notifier.FindNotificationByKey(kKey2));
462 EXPECT_FALSE(notifier.FindNotificationById(kKey3)); 714 EXPECT_FALSE(notifier.FindNotificationByKey(kKey3));
463 715
464 // Ensure the new data will be sent to the remote store for notification1. 716 // Ensure the new data will be sent to the remote store for notification1.
465 EXPECT_EQ(1U, processor()->change_list_size()); 717 EXPECT_EQ(1U, processor()->change_list_size());
466 EXPECT_TRUE(processor()->ContainsId(kKey1)); 718 EXPECT_TRUE(processor()->ContainsId(kKey1));
467 EXPECT_EQ(SyncChange::ACTION_UPDATE, processor()->GetChangeById( 719 EXPECT_EQ(SyncChange::ACTION_UPDATE, processor()->GetChangeById(
468 kKey1).change_type()); 720 kKey1).change_type());
469 } 721 }
470 722
471 // We have a notification in the local store, we get an updated version 723 // We have a notification in the local store, we get an updated version
472 // of the same notification remotely, it should take precedence. 724 // of the same notification remotely, it should take precedence.
473 TEST_F(ChromeNotifierServiceTest, ModelAssocBothNonEmptyWithUpdate) { 725 TEST_F(ChromeNotifierServiceTest, ModelAssocBothNonEmptyWithUpdate) {
474 StubNotificationUIManager notification_manager; 726 StubNotificationUIManager notification_manager;
475 ChromeNotifierService notifier(NULL, &notification_manager); 727 ChromeNotifierService notifier(NULL, &notification_manager);
476 728
477 // Create some local fake data. 729 // Create some local fake data.
478 scoped_ptr<SyncedNotification> n1(CreateNotification( 730 scoped_ptr<SyncedNotification> n1(CreateNotification(
479 "1", kAppId1, kKey1, "11", kDismissed)); 731 kTitle1, kText1, kIconUrl1, kImageUrl1, kAppId1, kKey1, kDismissed));
480 notifier.AddForTest(n1.Pass()); 732 notifier.AddForTest(n1.Pass());
481 733
482 // Create some remote fake data, item 1 matches the ID, but has different data 734 // Create some remote fake data, item 1 matches the ID, but has different data
483 syncer::SyncDataList initial_data; 735 syncer::SyncDataList initial_data;
484 initial_data.push_back(CreateSyncData("One", kAppId1, kKey1, 736 initial_data.push_back(CreateSyncData(kTitle2, kText2, kIconUrl2, kImageUrl2,
485 "Eleven", kUnread)); 737 kAppId1, kKey1, kUnread));
486 // Merge the local and remote data. 738 // Merge the local and remote data.
487 notifier.MergeDataAndStartSyncing( 739 notifier.MergeDataAndStartSyncing(
488 syncer::SYNCED_NOTIFICATIONS, 740 syncer::SYNCED_NOTIFICATIONS,
489 initial_data, 741 initial_data,
490 PassProcessor(), 742 PassProcessor(),
491 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); 743 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock()));
492 744
493 // Ensure the local store still has only one notification 745 // Ensure the local store still has only one notification
494 EXPECT_EQ(1U, notifier.GetAllSyncData(syncer::SYNCED_NOTIFICATIONS).size()); 746 EXPECT_EQ(1U, notifier.GetAllSyncData(syncer::SYNCED_NOTIFICATIONS).size());
495 SyncedNotification* notification1 = 747 SyncedNotification* notification1 =
496 notifier.FindNotificationById(kKey1); 748 notifier.FindNotificationByKey(kKey1);
749
497 EXPECT_FALSE(NULL == notification1); 750 EXPECT_FALSE(NULL == notification1);
498 EXPECT_EQ(SyncedNotification::kUnread, notification1->read_state()); 751 EXPECT_EQ(kUnread, notification1->GetReadState());
499 EXPECT_EQ("One", notification1->title()); 752 EXPECT_EQ(kTitle2, notification1->GetTitle());
500 EXPECT_EQ("Eleven", notification1->first_external_id());
501 753
502 // Ensure no new data will be sent to the remote store for notification1. 754 // Ensure no new data will be sent to the remote store for notification1.
503 EXPECT_EQ(0U, processor()->change_list_size()); 755 EXPECT_EQ(0U, processor()->change_list_size());
504 EXPECT_FALSE(processor()->ContainsId(kKey1)); 756 EXPECT_FALSE(processor()->ContainsId(kKey1));
505 } 757 }
506 758
759 TEST_F(ChromeNotifierServiceTest, ShowTest) {
760 StubNotificationUIManager notification_manager;
761 ChromeNotifierService notifier(NULL, &notification_manager);
762
763 // Create some remote fake data
764 syncer::SyncDataList initial_data;
765 initial_data.push_back(CreateSyncData(kTitle1, kText1, kIconUrl1, kImageUrl1,
766 kAppId1, kKey1, kUnread));
767 // Merge the local and remote data.
768 notifier.MergeDataAndStartSyncing(
769 syncer::SYNCED_NOTIFICATIONS,
770 initial_data,
771 PassProcessor(),
772 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock()));
773
774 // Check the base fields of the notification.
775 EXPECT_EQ(message_center::NOTIFICATION_TYPE_IMAGE,
776 notification_manager.notification().type());
777 EXPECT_EQ(kTitle1,
778 UTF16ToUTF8(notification_manager.notification().title()));
779 EXPECT_EQ(kText1,
780 UTF16ToUTF8(notification_manager.notification().body()));
781 EXPECT_EQ(kExpectedOriginUrl,
782 notification_manager.notification().origin_url().spec());
783 EXPECT_EQ(kIconUrl, notification_manager.notification().icon_url().spec());
784 EXPECT_EQ(kKey1,
785 UTF16ToUTF8(notification_manager.notification().replace_id()));
786 const DictionaryValue* actual_fields =
787 notification_manager.notification().optional_fields();
788
789 // Check the optional fields of the notification.
790 // Make an optional fields struct like we expect, compare it with actual.
791 DictionaryValue expected_fields;
792 expected_fields.SetDouble(message_center::kTimestampKey, kFakeCreationTime);
793 expected_fields.SetInteger(message_center::kPriorityKey,
794 kNotificationPriority);
795 expected_fields.SetString(message_center::kButtonOneTitleKey,
796 kButtonOneTitle);
797 expected_fields.SetString(message_center::kButtonOneIconUrlKey,
798 kButtonOneIconUrl);
799 expected_fields.SetString(message_center::kButtonTwoTitleKey,
800 kButtonTwoTitle);
801 expected_fields.SetString(message_center::kButtonTwoIconUrlKey,
802 kButtonTwoIconUrl);
803
804 // Fill the individual notification fields for a mutiple notification.
805 base::ListValue* items = new base::ListValue();
806 DictionaryValue* item1 = new DictionaryValue();
807 DictionaryValue* item2 = new DictionaryValue();
808 DictionaryValue* item3 = new DictionaryValue();
809 item1->SetString(message_center::kItemTitleKey,
810 UTF8ToUTF16(kContainedTitle1));
811 item1->SetString(message_center::kItemMessageKey,
812 UTF8ToUTF16(kContainedMessage1));
813 item2->SetString(message_center::kItemTitleKey,
814 UTF8ToUTF16(kContainedTitle2));
815 item2->SetString(message_center::kItemMessageKey,
816 UTF8ToUTF16(kContainedMessage2));
817 item3->SetString(message_center::kItemTitleKey,
818 UTF8ToUTF16(kContainedTitle3));
819 item3->SetString(message_center::kItemMessageKey,
820 UTF8ToUTF16(kContainedMessage3));
821 items->Append(item1);
822 items->Append(item2);
823 items->Append(item3);
824 expected_fields.Set(message_center::kItemsKey, items);
825
826 EXPECT_TRUE(expected_fields.Equals(actual_fields))
827 << "Expected: " << expected_fields
828 << ", but actual: " << *actual_fields;
829
830
831 }
832
507 // TODO(petewil): There are more tests to add, such as when we add an API 833 // TODO(petewil): There are more tests to add, such as when we add an API
508 // to allow data entry from the client, we might have a more up to date 834 // to allow data entry from the client, we might have a more up to date
509 // item on the client than the server, or we might have a merge conflict. 835 // item on the client than the server, or we might have a merge conflict.
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698