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 <map> | 5 #include <map> |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/gtest_prod_util.h" | 8 #include "base/gtest_prod_util.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
12 #include "base/values.h" | 12 #include "base/values.h" |
13 #include "chrome/browser/notifications/notification.h" | 13 #include "chrome/browser/notifications/notification.h" |
14 #include "chrome/browser/notifications/notification_test_util.h" | 14 #include "chrome/browser/notifications/notification_test_util.h" |
15 #include "chrome/browser/notifications/notification_ui_manager.h" | 15 #include "chrome/browser/notifications/notification_ui_manager.h" |
16 #include "chrome/browser/notifications/sync_notifier/chrome_notifier_service.h" | 16 #include "chrome/browser/notifications/sync_notifier/chrome_notifier_service.h" |
17 #include "chrome/browser/notifications/sync_notifier/sync_notifier_test_utils.h" | 17 #include "chrome/browser/notifications/sync_notifier/sync_notifier_test_utils.h" |
18 #include "chrome/browser/notifications/sync_notifier/synced_notification.h" | 18 #include "chrome/browser/notifications/sync_notifier/synced_notification.h" |
| 19 #include "chrome/browser/notifications/sync_notifier/synced_notification_app_inf
o.h" |
| 20 #include "chrome/browser/notifications/sync_notifier/synced_notification_app_inf
o_service.h" |
| 21 #include "chrome/browser/notifications/sync_notifier/synced_notification_app_inf
o_service_factory.h" |
19 #include "chrome/browser/prefs/browser_prefs.h" | 22 #include "chrome/browser/prefs/browser_prefs.h" |
20 #include "chrome/browser/profiles/profile.h" | 23 #include "chrome/browser/profiles/profile.h" |
21 #include "chrome/common/chrome_switches.h" | 24 #include "chrome/common/chrome_switches.h" |
22 #include "chrome/common/pref_names.h" | 25 #include "chrome/common/pref_names.h" |
23 #include "chrome/test/base/testing_pref_service_syncable.h" | 26 #include "chrome/test/base/testing_pref_service_syncable.h" |
24 #include "chrome/test/base/testing_profile.h" | 27 #include "chrome/test/base/testing_profile.h" |
25 #include "components/user_prefs/pref_registry_syncable.h" | 28 #include "components/user_prefs/pref_registry_syncable.h" |
26 #include "content/public/test/test_browser_thread_bundle.h" | 29 #include "content/public/test/test_browser_thread_bundle.h" |
27 #include "sync/api/sync_change.h" | 30 #include "sync/api/sync_change.h" |
28 #include "sync/api/sync_change_processor.h" | 31 #include "sync/api/sync_change_processor.h" |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 CommandLine::ForCurrentProcess()->AppendSwitch( | 120 CommandLine::ForCurrentProcess()->AppendSwitch( |
118 switches::kEnableSyncSyncedNotifications); | 121 switches::kEnableSyncSyncedNotifications); |
119 | 122 |
120 // Prevent test code from trying to go to the network. | 123 // Prevent test code from trying to go to the network. |
121 ChromeNotifierService::set_avoid_bitmap_fetching_for_test(true); | 124 ChromeNotifierService::set_avoid_bitmap_fetching_for_test(true); |
122 notification_manager_.reset(new StubNotificationUIManager(GURL( | 125 notification_manager_.reset(new StubNotificationUIManager(GURL( |
123 kSyncedNotificationsWelcomeOrigin))); | 126 kSyncedNotificationsWelcomeOrigin))); |
124 | 127 |
125 // Set up a profile for the unit tests to use. | 128 // Set up a profile for the unit tests to use. |
126 profile_.reset(new TestingProfile()); | 129 profile_.reset(new TestingProfile()); |
| 130 |
| 131 // Set up the testing SyncedNotificationAppInfoService with some test data. |
| 132 AddTestingAppInfos(); |
127 } | 133 } |
128 | 134 |
129 virtual void TearDown() { | 135 virtual void TearDown() { |
130 notification_manager_.reset(); | 136 notification_manager_.reset(); |
131 } | 137 } |
132 | 138 |
133 StubNotificationUIManager* notification_manager() { | 139 StubNotificationUIManager* notification_manager() { |
134 return notification_manager_.get(); | 140 return notification_manager_.get(); |
135 } | 141 } |
136 | 142 |
(...skipping 10 matching lines...) Expand all Loading... |
147 const std::string& text, | 153 const std::string& text, |
148 const std::string& app_icon_url, | 154 const std::string& app_icon_url, |
149 const std::string& image_url, | 155 const std::string& image_url, |
150 const std::string& app_id, | 156 const std::string& app_id, |
151 const std::string& key, | 157 const std::string& key, |
152 sync_pb::CoalescedSyncedNotification_ReadState read_state) { | 158 sync_pb::CoalescedSyncedNotification_ReadState read_state) { |
153 SyncData sync_data = CreateSyncData(title, text, app_icon_url, image_url, | 159 SyncData sync_data = CreateSyncData(title, text, app_icon_url, image_url, |
154 app_id, key, read_state); | 160 app_id, key, read_state); |
155 // Set enough fields in sync_data, including specifics, for our tests | 161 // Set enough fields in sync_data, including specifics, for our tests |
156 // to pass. | 162 // to pass. |
157 return new SyncedNotification(sync_data); | 163 return new SyncedNotification(sync_data, NULL, notification_manager_.get()); |
158 } | 164 } |
159 | 165 |
160 // Helper to create syncer::SyncChange. | 166 // Helper to create syncer::SyncChange. |
161 static SyncChange CreateSyncChange( | 167 static SyncChange CreateSyncChange( |
162 SyncChange::SyncChangeType type, | 168 SyncChange::SyncChangeType type, |
163 SyncedNotification* notification) { | 169 SyncedNotification* notification) { |
164 // Take control of the notification to clean it up after we create data | 170 // Take control of the notification to clean it up after we create data |
165 // out of it. | 171 // out of it. |
166 scoped_ptr<SyncedNotification> scoped_notification(notification); | 172 scoped_ptr<SyncedNotification> scoped_notification(notification); |
167 return SyncChange( | 173 return SyncChange( |
168 FROM_HERE, | 174 FROM_HERE, |
169 type, | 175 type, |
170 ChromeNotifierService::CreateSyncDataFromNotification(*notification)); | 176 ChromeNotifierService::CreateSyncDataFromNotification(*notification)); |
171 } | 177 } |
172 | 178 |
| 179 void AddTestingAppInfos() { |
| 180 // Get the SyncedNotificationAppInfoService from the browser object. |
| 181 SyncedNotificationAppInfoService* synced_notification_app_info_service = |
| 182 SyncedNotificationAppInfoServiceFactory::GetForProfile( |
| 183 profile_.get(), Profile::EXPLICIT_ACCESS); |
| 184 |
| 185 // Create a notification to add. |
| 186 // The sending_service_infos_ list will take ownership of this pointer. |
| 187 scoped_ptr<SyncedNotificationAppInfo> test_service1( |
| 188 new SyncedNotificationAppInfo(profile_.get(), |
| 189 std::string(kSendingService1Name), |
| 190 synced_notification_app_info_service)); |
| 191 |
| 192 // Add some App IDs. |
| 193 test_service1->AddAppId(kAppId1); |
| 194 test_service1->AddAppId(kAppId2); |
| 195 |
| 196 // Set this icon's GURLs. |
| 197 test_service1->SetSettingsURLs(GURL(kTestIconUrl), GURL()); |
| 198 |
| 199 // Call AddForTest. |
| 200 synced_notification_app_info_service->AddForTest(test_service1.Pass()); |
| 201 } |
| 202 |
173 protected: | 203 protected: |
174 scoped_ptr<TestingProfile> profile_; | 204 scoped_ptr<TestingProfile> profile_; |
175 | 205 |
176 private: | 206 private: |
177 scoped_ptr<syncer::SyncChangeProcessor> sync_processor_; | 207 scoped_ptr<syncer::SyncChangeProcessor> sync_processor_; |
178 scoped_ptr<syncer::SyncChangeProcessor> sync_processor_wrapper_; | 208 scoped_ptr<syncer::SyncChangeProcessor> sync_processor_wrapper_; |
179 scoped_ptr<StubNotificationUIManager> notification_manager_; | 209 scoped_ptr<StubNotificationUIManager> notification_manager_; |
180 content::TestBrowserThreadBundle thread_bundle_; | 210 content::TestBrowserThreadBundle thread_bundle_; |
181 | 211 |
182 DISALLOW_COPY_AND_ASSIGN(ChromeNotifierServiceTest); | 212 DISALLOW_COPY_AND_ASSIGN(ChromeNotifierServiceTest); |
183 }; | 213 }; |
184 | 214 |
185 // TODO(petewil): Add more tests as I add functionalty. Tests are based on | |
186 // chrome/browser/extensions/app_notification_manager_sync_unittest.cc | |
187 | |
188 // Create a Notification, convert it to SyncData and convert it back. | 215 // Create a Notification, convert it to SyncData and convert it back. |
189 TEST_F(ChromeNotifierServiceTest, NotificationToSyncDataToNotification) { | 216 TEST_F(ChromeNotifierServiceTest, NotificationToSyncDataToNotification) { |
| 217 ChromeNotifierService notifier(profile_.get(), notification_manager()); |
| 218 |
190 scoped_ptr<SyncedNotification> notification1( | 219 scoped_ptr<SyncedNotification> notification1( |
191 CreateNotification(kTitle1, kText1, kIconUrl1, kImageUrl1, kAppId1, | 220 CreateNotification(kTitle1, kText1, kIconUrl1, kImageUrl1, kAppId1, |
192 kKey1, kUnread)); | 221 kKey1, kUnread)); |
193 SyncData sync_data = | 222 SyncData sync_data = |
194 ChromeNotifierService::CreateSyncDataFromNotification(*notification1); | 223 ChromeNotifierService::CreateSyncDataFromNotification(*notification1); |
195 scoped_ptr<SyncedNotification> notification2( | 224 scoped_ptr<SyncedNotification> notification2( |
196 ChromeNotifierService::CreateNotificationFromSyncData(sync_data)); | 225 notifier.CreateNotificationFromSyncData(sync_data)); |
197 EXPECT_TRUE(notification2.get()); | 226 EXPECT_TRUE(notification2.get()); |
198 EXPECT_TRUE(notification1->EqualsIgnoringReadState(*notification2)); | 227 EXPECT_TRUE(notification1->EqualsIgnoringReadState(*notification2)); |
199 EXPECT_EQ(notification1->GetReadState(), notification2->GetReadState()); | 228 EXPECT_EQ(notification1->GetReadState(), notification2->GetReadState()); |
200 } | 229 } |
201 | 230 |
202 // Model assocation: We have no local data, and no remote data. | 231 // Model assocation: We have no local data, and no remote data. |
203 TEST_F(ChromeNotifierServiceTest, ModelAssocBothEmpty) { | 232 TEST_F(ChromeNotifierServiceTest, ModelAssocBothEmpty) { |
204 | 233 |
205 ChromeNotifierService notifier(profile_.get(), notification_manager()); | 234 ChromeNotifierService notifier(profile_.get(), notification_manager()); |
206 | 235 |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
387 EXPECT_TRUE(notifier.FindNotificationById(kKey3)); | 416 EXPECT_TRUE(notifier.FindNotificationById(kKey3)); |
388 EXPECT_TRUE(notifier.FindNotificationById(kKey4)); | 417 EXPECT_TRUE(notifier.FindNotificationById(kKey4)); |
389 EXPECT_TRUE(notifier.FindNotificationById(kKey5)); | 418 EXPECT_TRUE(notifier.FindNotificationById(kKey5)); |
390 EXPECT_TRUE(notifier.FindNotificationById(kKey6)); | 419 EXPECT_TRUE(notifier.FindNotificationById(kKey6)); |
391 EXPECT_TRUE(notifier.FindNotificationById(kKey7)); | 420 EXPECT_TRUE(notifier.FindNotificationById(kKey7)); |
392 | 421 |
393 // Test the type conversion and construction functions. | 422 // Test the type conversion and construction functions. |
394 for (SyncDataList::const_iterator iter = initial_data.begin(); | 423 for (SyncDataList::const_iterator iter = initial_data.begin(); |
395 iter != initial_data.end(); ++iter) { | 424 iter != initial_data.end(); ++iter) { |
396 scoped_ptr<SyncedNotification> notification1( | 425 scoped_ptr<SyncedNotification> notification1( |
397 ChromeNotifierService::CreateNotificationFromSyncData(*iter)); | 426 notifier.CreateNotificationFromSyncData(*iter)); |
398 // TODO(petewil): Revisit this when we add version info to notifications. | 427 // TODO(petewil): Revisit this when we add version info to notifications. |
399 const std::string& key = notification1->GetKey(); | 428 const std::string& key = notification1->GetKey(); |
400 const SyncedNotification* notification2 = | 429 const SyncedNotification* notification2 = |
401 notifier.FindNotificationById(key); | 430 notifier.FindNotificationById(key); |
402 EXPECT_TRUE(NULL != notification2); | 431 EXPECT_TRUE(NULL != notification2); |
403 EXPECT_TRUE(notification1->EqualsIgnoringReadState(*notification2)); | 432 EXPECT_TRUE(notification1->EqualsIgnoringReadState(*notification2)); |
404 EXPECT_EQ(notification1->GetReadState(), notification2->GetReadState()); | 433 EXPECT_EQ(notification1->GetReadState(), notification2->GetReadState()); |
405 } | 434 } |
406 EXPECT_TRUE(notifier.FindNotificationById(kKey1)); | 435 EXPECT_TRUE(notifier.FindNotificationById(kKey1)); |
407 EXPECT_TRUE(notifier.FindNotificationById(kKey2)); | 436 EXPECT_TRUE(notifier.FindNotificationById(kKey2)); |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
525 EXPECT_EQ(std::string(kTitle2), notification1->GetTitle()); | 554 EXPECT_EQ(std::string(kTitle2), notification1->GetTitle()); |
526 | 555 |
527 // Ensure no new data will be sent to the remote store for notification1. | 556 // Ensure no new data will be sent to the remote store for notification1. |
528 EXPECT_EQ(0U, processor()->change_list_size()); | 557 EXPECT_EQ(0U, processor()->change_list_size()); |
529 EXPECT_FALSE(processor()->ContainsId(kKey1)); | 558 EXPECT_FALSE(processor()->ContainsId(kKey1)); |
530 } | 559 } |
531 | 560 |
532 TEST_F(ChromeNotifierServiceTest, ServiceEnabledTest) { | 561 TEST_F(ChromeNotifierServiceTest, ServiceEnabledTest) { |
533 ChromeNotifierService notifier(profile_.get(), notification_manager()); | 562 ChromeNotifierService notifier(profile_.get(), notification_manager()); |
534 std::set<std::string>::iterator iter; | 563 std::set<std::string>::iterator iter; |
535 std::string first_synced_notification_service_id( | 564 std::string first_synced_notification_service_id(kSendingService1Name); |
536 kFirstSyncedNotificationServiceId); | |
537 | 565 |
538 // Create some local fake data. | 566 // Create some local fake data. |
539 scoped_ptr<SyncedNotification> n1(CreateNotification( | 567 scoped_ptr<SyncedNotification> n1(CreateNotification( |
540 kTitle1, kText1, kIconUrl1, kImageUrl1, kAppId1, kKey1, kUnread)); | 568 kTitle1, kText1, kIconUrl1, kImageUrl1, kAppId1, kKey1, kUnread)); |
541 notifier.AddForTest(n1.Pass()); | 569 notifier.AddForTest(n1.Pass()); |
542 | 570 |
543 // Enable the service and ensure the service is in the list. | 571 // Enable the service and ensure the service is in the list. |
544 // Initially the service starts in the disabled state. | 572 // Initially the service starts in the disabled state. |
545 notifier.OnSyncedNotificationServiceEnabled(kFirstSyncedNotificationServiceId, | 573 notifier.OnSyncedNotificationServiceEnabled(kSendingService1Name, true); |
546 true); | |
547 iter = find(notifier.enabled_sending_services_.begin(), | 574 iter = find(notifier.enabled_sending_services_.begin(), |
548 notifier.enabled_sending_services_.end(), | 575 notifier.enabled_sending_services_.end(), |
549 first_synced_notification_service_id); | 576 first_synced_notification_service_id); |
| 577 |
550 EXPECT_NE(notifier.enabled_sending_services_.end(), iter); | 578 EXPECT_NE(notifier.enabled_sending_services_.end(), iter); |
| 579 |
551 // TODO(petewil): Verify Display gets called too. | 580 // TODO(petewil): Verify Display gets called too. |
552 | |
553 // Disable the service and ensure it is gone from the list and the | 581 // Disable the service and ensure it is gone from the list and the |
554 // notification_manager. | 582 // notification_manager. |
555 notifier.OnSyncedNotificationServiceEnabled(kFirstSyncedNotificationServiceId, | 583 notifier.OnSyncedNotificationServiceEnabled(kSendingService1Name, false); |
556 false); | |
557 iter = find(notifier.enabled_sending_services_.begin(), | 584 iter = find(notifier.enabled_sending_services_.begin(), |
558 notifier.enabled_sending_services_.end(), | 585 notifier.enabled_sending_services_.end(), |
559 first_synced_notification_service_id); | 586 first_synced_notification_service_id); |
| 587 |
560 EXPECT_EQ(notifier.enabled_sending_services_.end(), iter); | 588 EXPECT_EQ(notifier.enabled_sending_services_.end(), iter); |
561 EXPECT_EQ(notification_manager()->dismissed_id(), std::string(kKey1)); | 589 EXPECT_EQ(notification_manager()->dismissed_id(), std::string(kKey1)); |
562 | |
563 } | 590 } |
564 | 591 |
565 // http://crbug.com/341326 | 592 // http://crbug.com/341326 |
566 #if defined(TOOLKIT_GTK) | 593 #if defined(TOOLKIT_GTK) |
567 #define MAYBE_AddNewSendingServicesTest DISABLED_AddNewSendingServicesTest | 594 #define MAYBE_AddNewSendingServicesTest DISABLED_AddNewSendingServicesTest |
568 #else | 595 #else |
569 #define MAYBE_AddNewSendingServicesTest AddNewSendingServicesTest | 596 #define MAYBE_AddNewSendingServicesTest AddNewSendingServicesTest |
570 #endif | 597 #endif |
571 TEST_F(ChromeNotifierServiceTest, MAYBE_AddNewSendingServicesTest) { | 598 TEST_F(ChromeNotifierServiceTest, MAYBE_AddNewSendingServicesTest) { |
572 // This test will see if we get a new sending service after the first | 599 // This test will see if we get a new sending service after the first |
573 // notification for that service. | 600 // notification for that service. |
574 ChromeNotifierService notifier(profile_.get(), notification_manager()); | 601 ChromeNotifierService notifier(profile_.get(), notification_manager()); |
575 notifier.set_avoid_bitmap_fetching_for_test(true); | 602 notifier.set_avoid_bitmap_fetching_for_test(true); |
576 | 603 |
577 // We initially have no data. | 604 // We initially have no data. |
578 EXPECT_EQ(0U, notifier.enabled_sending_services_.size()); | 605 EXPECT_EQ(0U, notifier.enabled_sending_services_.size()); |
579 EXPECT_EQ(0U, notifier.GetAllSyncData(SYNCED_NOTIFICATIONS).size()); | 606 EXPECT_EQ(0U, notifier.GetAllSyncData(SYNCED_NOTIFICATIONS).size()); |
580 | 607 |
581 // Set up an ADD. | 608 // Set up an ADD. |
582 SyncChangeList changes; | 609 SyncChangeList changes; |
583 changes.push_back( | 610 changes.push_back( |
584 CreateSyncChange(SyncChange::ACTION_ADD, | 611 CreateSyncChange(SyncChange::ACTION_ADD, |
585 CreateNotification(kTitle1, | 612 CreateNotification(kTitle1, |
586 kText1, | 613 kText1, |
587 kIconUrl1, | 614 kIconUrl1, |
588 kImageUrl1, | 615 kImageUrl1, |
589 kFirstSyncedNotificationServiceId, | 616 kAppId1, |
590 kKey1, | 617 kKey1, |
591 kUnread))); | 618 kUnread))); |
592 | 619 |
593 notifier.ProcessSyncChanges(FROM_HERE, changes); | 620 notifier.ProcessSyncChanges(FROM_HERE, changes); |
594 | 621 |
595 EXPECT_EQ(1U, notifier.GetAllSyncData(SYNCED_NOTIFICATIONS).size()); | 622 EXPECT_EQ(1U, notifier.GetAllSyncData(SYNCED_NOTIFICATIONS).size()); |
596 | 623 |
597 // Verify that the first synced notification service is enabled in memory. | 624 // Verify that the first synced notification service is enabled in memory. |
598 std::set<std::string>::iterator iter; | 625 std::set<std::string>::iterator iter; |
599 std::string first_notification_service_id(kFirstSyncedNotificationServiceId); | 626 std::string first_notification_service_id(kSendingService1Name); |
600 iter = find(notifier.enabled_sending_services_.begin(), | 627 iter = find(notifier.enabled_sending_services_.begin(), |
601 notifier.enabled_sending_services_.end(), | 628 notifier.enabled_sending_services_.end(), |
602 first_notification_service_id); | 629 first_notification_service_id); |
603 | 630 |
604 EXPECT_NE(notifier.enabled_sending_services_.end(), iter); | 631 EXPECT_NE(notifier.enabled_sending_services_.end(), iter); |
605 | 632 |
606 // We should have gotten the synced notification and a welcome notification. | 633 // We should have gotten the synced notification and a welcome notification. |
607 EXPECT_EQ(2U, notification_manager()->added_notifications()); | 634 EXPECT_EQ(2U, notification_manager()->added_notifications()); |
608 EXPECT_TRUE(notification_manager()->welcomed()); | 635 EXPECT_TRUE(notification_manager()->welcomed()); |
609 | 636 |
610 changes.clear(); | 637 changes.clear(); |
611 changes.push_back( | 638 changes.push_back( |
612 CreateSyncChange(SyncChange::ACTION_ADD, | 639 CreateSyncChange(SyncChange::ACTION_ADD, |
613 CreateNotification(kTitle2, | 640 CreateNotification(kTitle2, |
614 kText2, | 641 kText2, |
615 kIconUrl2, | 642 kIconUrl2, |
616 kImageUrl2, | 643 kImageUrl2, |
617 kFirstSyncedNotificationServiceId, | 644 kAppId1, |
618 kKey2, | 645 kKey2, |
619 kUnread))); | 646 kUnread))); |
620 notifier.ProcessSyncChanges(FROM_HERE, changes); | 647 notifier.ProcessSyncChanges(FROM_HERE, changes); |
621 | 648 |
622 // But adding another notification should not cause another welcome. | 649 // But adding another notification should not cause another welcome. |
623 EXPECT_EQ(3U, notification_manager()->added_notifications()); | 650 EXPECT_EQ(3U, notification_manager()->added_notifications()); |
624 } | 651 } |
625 | 652 |
626 TEST_F(ChromeNotifierServiceTest, CheckInitializedServicesTest) { | 653 TEST_F(ChromeNotifierServiceTest, CheckInitializedServicesTest) { |
627 // This test will see if we get a new sending service after the first | 654 // This test will see if we get a new sending service after the first |
628 // notification for that service. | 655 // notification for that service. |
629 ChromeNotifierService notifier(profile_.get(), notification_manager()); | 656 ChromeNotifierService notifier(profile_.get(), notification_manager()); |
630 notifier.set_avoid_bitmap_fetching_for_test(true); | 657 notifier.set_avoid_bitmap_fetching_for_test(true); |
631 | 658 |
632 // Initialize but do not enable the sending service. | 659 // Initialize but do not enable the sending service. |
633 notifier.initialized_sending_services_.insert( | 660 notifier.initialized_sending_services_.insert(kSendingService1Name); |
634 kFirstSyncedNotificationServiceId); | |
635 ASSERT_EQ(0U, notifier.enabled_sending_services_.size()); | 661 ASSERT_EQ(0U, notifier.enabled_sending_services_.size()); |
636 ASSERT_EQ(1U, notifier.initialized_sending_services_.size()); | 662 ASSERT_EQ(1U, notifier.initialized_sending_services_.size()); |
637 | 663 |
638 // We initially have no data. | 664 // We initially have no data. |
639 EXPECT_EQ(0U, notifier.enabled_sending_services_.size()); | 665 EXPECT_EQ(0U, notifier.enabled_sending_services_.size()); |
640 EXPECT_EQ(0U, notifier.GetAllSyncData(SYNCED_NOTIFICATIONS).size()); | 666 EXPECT_EQ(0U, notifier.GetAllSyncData(SYNCED_NOTIFICATIONS).size()); |
641 | 667 |
642 // Set up an ADD. | 668 // Set up an ADD. |
643 std::string first_synced_notification_service_id( | 669 std::string first_synced_notification_service_id(kSendingService1Name); |
644 kFirstSyncedNotificationServiceId); | |
645 | 670 |
646 SyncChangeList changes; | 671 SyncChangeList changes; |
647 changes.push_back( | 672 changes.push_back( |
648 CreateSyncChange(SyncChange::ACTION_ADD, | 673 CreateSyncChange(SyncChange::ACTION_ADD, |
649 CreateNotification(kTitle1, | 674 CreateNotification(kTitle1, |
650 kText1, | 675 kText1, |
651 kIconUrl1, | 676 kIconUrl1, |
652 kImageUrl1, | 677 kImageUrl1, |
653 kFirstSyncedNotificationServiceId, | 678 kAppId1, |
654 kKey1, | 679 kKey1, |
655 kUnread))); | 680 kUnread))); |
656 | 681 |
657 notifier.ProcessSyncChanges(FROM_HERE, changes); | 682 notifier.ProcessSyncChanges(FROM_HERE, changes); |
658 | 683 |
659 // Since we added to |initialized_sending_services_| before receiving the | 684 // Since we added to |initialized_sending_services_| before receiving the |
660 // synced notification, we should not have enabled this service while | 685 // synced notification, we should not have enabled this service while |
661 // processing the sync change. | 686 // processing the sync change. |
662 EXPECT_EQ(0U, notifier.enabled_sending_services_.size()); | 687 EXPECT_EQ(0U, notifier.enabled_sending_services_.size()); |
663 EXPECT_EQ(0U, notification_manager()->added_notifications()); | 688 EXPECT_EQ(0U, notification_manager()->added_notifications()); |
664 } | 689 } |
665 | 690 |
666 TEST_F(ChromeNotifierServiceTest, CheckFindAppInfo) { | 691 TEST_F(ChromeNotifierServiceTest, SetAddedAppIdsTest) { |
667 ChromeNotifierService notifier(profile_.get(), notification_manager()); | 692 ChromeNotifierService notifier(profile_.get(), notification_manager()); |
668 notifier.set_avoid_bitmap_fetching_for_test(true); | 693 notifier.set_avoid_bitmap_fetching_for_test(true); |
669 | 694 |
670 SyncedNotificationAppInfoTemp* app_info = | 695 // Add some notifications to our notification list. |
671 notifier.FindAppInfo(kFirstSyncedNotificationServiceId); | 696 scoped_ptr<SyncedNotification> n1(CreateNotification( |
672 EXPECT_TRUE(app_info != NULL); | 697 kTitle1, kText1, kIconUrl1, kImageUrl1, kAppId1, kKey1, kUnread)); |
| 698 n1->SetNotifierServiceForTest(¬ifier); |
| 699 notifier.AddForTest(n1.Pass()); |
| 700 |
| 701 EXPECT_EQ(static_cast<size_t>(0), |
| 702 notification_manager()->added_notifications()); |
| 703 |
| 704 // Call SetAddedAppIds. |
| 705 std::vector<std::string> added_app_ids; |
| 706 added_app_ids.push_back(std::string(kAppId1)); |
| 707 notifier.OnAddedAppIds(added_app_ids); |
| 708 |
| 709 // Verify the notification was added by the notification_manager. |
| 710 // We see one welcome notification and one new notification. |
| 711 EXPECT_EQ(static_cast<size_t>(2), |
| 712 notification_manager()->added_notifications()); |
673 } | 713 } |
674 | 714 |
| 715 TEST_F(ChromeNotifierServiceTest, SetRemovedAppIdsTest) { |
| 716 ChromeNotifierService notifier(profile_.get(), notification_manager()); |
| 717 notifier.set_avoid_bitmap_fetching_for_test(true); |
| 718 |
| 719 // Add some notifications to our notification list. |
| 720 scoped_ptr<SyncedNotification> n1(CreateNotification( |
| 721 kTitle1, kText1, kIconUrl1, kImageUrl1, kAppId1, kKey1, kUnread)); |
| 722 notifier.AddForTest(n1.Pass()); |
| 723 |
| 724 // Call SetRemovedAppIds. |
| 725 std::vector<std::string> removed_app_ids; |
| 726 removed_app_ids.push_back(std::string(kAppId1)); |
| 727 notifier.OnRemovedAppIds(removed_app_ids); |
| 728 |
| 729 // Verify the notification was "removed" in the notification manager. |
| 730 EXPECT_EQ(std::string(kKey1), notification_manager()->dismissed_id()); |
| 731 } |
| 732 |
| 733 // TODO(petewil): Add a test that we do *not* get a welcome dialog unless we |
| 734 // have a valid app info for the notification. |
| 735 |
675 } // namespace notifier | 736 } // namespace notifier |
OLD | NEW |