| 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/gtest_prod_util.h" | 7 #include "base/gtest_prod_util.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 11 #include "base/values.h" | 11 #include "base/values.h" |
| 12 #include "chrome/browser/notifications/notification.h" | 12 #include "chrome/browser/notifications/notification.h" |
| 13 #include "chrome/browser/notifications/notification_test_util.h" | 13 #include "chrome/browser/notifications/notification_test_util.h" |
| 14 #include "chrome/browser/notifications/notification_ui_manager.h" | 14 #include "chrome/browser/notifications/notification_ui_manager.h" |
| 15 #include "chrome/browser/notifications/sync_notifier/chrome_notifier_service.h" | 15 #include "chrome/browser/notifications/sync_notifier/chrome_notifier_service.h" |
| 16 #include "chrome/browser/notifications/sync_notifier/sync_notifier_test_utils.h" | 16 #include "chrome/browser/notifications/sync_notifier/sync_notifier_test_utils.h" |
| 17 #include "chrome/browser/notifications/sync_notifier/synced_notification.h" | 17 #include "chrome/browser/notifications/sync_notifier/synced_notification.h" |
| 18 #include "chrome/browser/prefs/browser_prefs.h" | 18 #include "chrome/browser/prefs/browser_prefs.h" |
| 19 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
| 20 #include "chrome/common/pref_names.h" | 20 #include "chrome/common/pref_names.h" |
| 21 #include "chrome/test/base/testing_pref_service_syncable.h" | 21 #include "chrome/test/base/testing_pref_service_syncable.h" |
| 22 #include "chrome/test/base/testing_profile.h" | 22 #include "chrome/test/base/testing_profile.h" |
| 23 #include "components/user_prefs/pref_registry_syncable.h" | 23 #include "components/user_prefs/pref_registry_syncable.h" |
| 24 #include "content/public/test/test_browser_thread_bundle.h" | 24 #include "content/public/test/test_browser_thread_bundle.h" |
| 25 #include "sync/api/sync_change.h" | 25 #include "sync/api/sync_change.h" |
| 26 #include "sync/api/sync_change_processor.h" | 26 #include "sync/api/sync_change_processor.h" |
| 27 #include "sync/api/sync_change_processor_delegator.h" |
| 27 #include "sync/api/sync_error_factory.h" | 28 #include "sync/api/sync_error_factory.h" |
| 28 #include "sync/api/sync_error_factory_mock.h" | 29 #include "sync/api/sync_error_factory_mock.h" |
| 29 #include "testing/gtest/include/gtest/gtest.h" | 30 #include "testing/gtest/include/gtest/gtest.h" |
| 30 #include "ui/message_center/message_center_util.h" | 31 #include "ui/message_center/message_center_util.h" |
| 31 | 32 |
| 32 using sync_pb::SyncedNotificationSpecifics; | 33 using sync_pb::SyncedNotificationSpecifics; |
| 33 using sync_pb::EntitySpecifics; | 34 using sync_pb::EntitySpecifics; |
| 34 using syncer::SyncData; | 35 using syncer::SyncData; |
| 35 using syncer::SyncChange; | 36 using syncer::SyncChange; |
| 36 using syncer::SyncChangeList; | 37 using syncer::SyncChangeList; |
| 38 using syncer::SyncChangeProcessorDelegator; |
| 37 using syncer::SyncDataList; | 39 using syncer::SyncDataList; |
| 38 using syncer::SYNCED_NOTIFICATIONS; | 40 using syncer::SYNCED_NOTIFICATIONS; |
| 39 using notifier::SyncedNotification; | 41 using notifier::SyncedNotification; |
| 40 using notifier::ChromeNotifierService; | 42 using notifier::ChromeNotifierService; |
| 41 | 43 |
| 42 namespace { | 44 namespace { |
| 43 | 45 |
| 44 // Extract notification id from syncer::SyncData. | 46 // Extract notification id from syncer::SyncData. |
| 45 std::string GetNotificationId(const SyncData& sync_data) { | 47 std::string GetNotificationId(const SyncData& sync_data) { |
| 46 SyncedNotificationSpecifics specifics = sync_data.GetSpecifics(). | 48 SyncedNotificationSpecifics specifics = sync_data.GetSpecifics(). |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 return change_map_[id]; | 92 return change_map_[id]; |
| 91 } | 93 } |
| 92 | 94 |
| 93 private: | 95 private: |
| 94 // Track the changes received in ProcessSyncChanges. | 96 // Track the changes received in ProcessSyncChanges. |
| 95 std::map<std::string, SyncChange> change_map_; | 97 std::map<std::string, SyncChange> change_map_; |
| 96 | 98 |
| 97 DISALLOW_COPY_AND_ASSIGN(TestChangeProcessor); | 99 DISALLOW_COPY_AND_ASSIGN(TestChangeProcessor); |
| 98 }; | 100 }; |
| 99 | 101 |
| 100 class SyncChangeProcessorDelegate : public syncer::SyncChangeProcessor { | |
| 101 public: | |
| 102 explicit SyncChangeProcessorDelegate(SyncChangeProcessor* recipient) | |
| 103 : recipient_(recipient) { | |
| 104 EXPECT_TRUE(recipient_); | |
| 105 } | |
| 106 virtual ~SyncChangeProcessorDelegate() {} | |
| 107 | |
| 108 // syncer::SyncChangeProcessor implementation. | |
| 109 virtual syncer::SyncError ProcessSyncChanges( | |
| 110 const tracked_objects::Location& from_here, | |
| 111 const SyncChangeList& change_list) OVERRIDE { | |
| 112 return recipient_->ProcessSyncChanges(from_here, change_list); | |
| 113 } | |
| 114 | |
| 115 virtual syncer::SyncDataList GetAllSyncData(syncer::ModelType type) const | |
| 116 OVERRIDE { | |
| 117 return recipient_->GetAllSyncData(type); | |
| 118 } | |
| 119 | |
| 120 private: | |
| 121 // The recipient of all sync changes. | |
| 122 SyncChangeProcessor* recipient_; | |
| 123 | |
| 124 DISALLOW_COPY_AND_ASSIGN(SyncChangeProcessorDelegate); | |
| 125 }; | |
| 126 | |
| 127 class ChromeNotifierServiceTest : public testing::Test { | 102 class ChromeNotifierServiceTest : public testing::Test { |
| 128 public: | 103 public: |
| 129 ChromeNotifierServiceTest() | 104 ChromeNotifierServiceTest() |
| 130 : sync_processor_(new TestChangeProcessor), | 105 : sync_processor_(new TestChangeProcessor), |
| 131 sync_processor_delegate_(new SyncChangeProcessorDelegate( | 106 sync_processor_delegate_(new SyncChangeProcessorDelegator( |
| 132 sync_processor_.get())) {} | 107 sync_processor_.get())) {} |
| 133 virtual ~ChromeNotifierServiceTest() {} | 108 virtual ~ChromeNotifierServiceTest() {} |
| 134 | 109 |
| 135 // Methods from testing::Test. | 110 // Methods from testing::Test. |
| 136 virtual void SetUp() { | 111 virtual void SetUp() { |
| 137 // Prevent test code from trying to go to the network. | 112 // Prevent test code from trying to go to the network. |
| 138 ChromeNotifierService::set_avoid_bitmap_fetching_for_test(true); | 113 ChromeNotifierService::set_avoid_bitmap_fetching_for_test(true); |
| 139 notification_manager_.reset(new StubNotificationUIManager(GURL( | 114 notification_manager_.reset(new StubNotificationUIManager(GURL( |
| 140 kSyncedNotificationsWelcomeOrigin))); | 115 kSyncedNotificationsWelcomeOrigin))); |
| 141 | 116 |
| (...skipping 535 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 677 TEST_F(ChromeNotifierServiceTest, CheckFindAppInfo) { | 652 TEST_F(ChromeNotifierServiceTest, CheckFindAppInfo) { |
| 678 ChromeNotifierService notifier(profile_.get(), notification_manager()); | 653 ChromeNotifierService notifier(profile_.get(), notification_manager()); |
| 679 notifier.set_avoid_bitmap_fetching_for_test(true); | 654 notifier.set_avoid_bitmap_fetching_for_test(true); |
| 680 | 655 |
| 681 SyncedNotificationAppInfo* app_info = | 656 SyncedNotificationAppInfo* app_info = |
| 682 notifier.FindAppInfo(kFirstSyncedNotificationServiceId); | 657 notifier.FindAppInfo(kFirstSyncedNotificationServiceId); |
| 683 EXPECT_TRUE(app_info != NULL); | 658 EXPECT_TRUE(app_info != NULL); |
| 684 } | 659 } |
| 685 | 660 |
| 686 } // namespace notifier | 661 } // namespace notifier |
| OLD | NEW |