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/prefs/browser_prefs.h" | 19 #include "chrome/browser/prefs/browser_prefs.h" |
20 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
21 #include "chrome/common/chrome_switches.h" | 21 #include "chrome/common/chrome_switches.h" |
22 #include "chrome/common/pref_names.h" | 22 #include "chrome/common/pref_names.h" |
23 #include "chrome/test/base/testing_pref_service_syncable.h" | 23 #include "chrome/test/base/testing_pref_service_syncable.h" |
24 #include "chrome/test/base/testing_profile.h" | 24 #include "chrome/test/base/testing_profile.h" |
25 #include "components/user_prefs/pref_registry_syncable.h" | 25 #include "components/user_prefs/pref_registry_syncable.h" |
26 #include "content/public/test/test_browser_thread_bundle.h" | 26 #include "content/public/test/test_browser_thread_bundle.h" |
27 #include "sync/api/sync_change.h" | 27 #include "sync/api/sync_change.h" |
28 #include "sync/api/sync_change_processor.h" | 28 #include "sync/api/sync_change_processor.h" |
| 29 #include "sync/api/sync_change_processor_wrapper_for_test.h" |
29 #include "sync/api/sync_error_factory.h" | 30 #include "sync/api/sync_error_factory.h" |
30 #include "sync/api/sync_error_factory_mock.h" | 31 #include "sync/api/sync_error_factory_mock.h" |
31 #include "testing/gtest/include/gtest/gtest.h" | 32 #include "testing/gtest/include/gtest/gtest.h" |
32 #include "ui/message_center/message_center_util.h" | 33 #include "ui/message_center/message_center_util.h" |
33 | 34 |
34 using sync_pb::SyncedNotificationSpecifics; | 35 using sync_pb::SyncedNotificationSpecifics; |
35 using sync_pb::EntitySpecifics; | 36 using sync_pb::EntitySpecifics; |
36 using syncer::SyncData; | 37 using syncer::SyncData; |
37 using syncer::SyncChange; | 38 using syncer::SyncChange; |
38 using syncer::SyncChangeList; | 39 using syncer::SyncChangeList; |
| 40 using syncer::SyncChangeProcessorWrapperForTest; |
39 using syncer::SyncDataList; | 41 using syncer::SyncDataList; |
40 using syncer::SYNCED_NOTIFICATIONS; | 42 using syncer::SYNCED_NOTIFICATIONS; |
41 using notifier::SyncedNotification; | 43 using notifier::SyncedNotification; |
42 using notifier::ChromeNotifierService; | 44 using notifier::ChromeNotifierService; |
43 | 45 |
44 namespace { | 46 namespace { |
45 | 47 |
46 // Extract notification id from syncer::SyncData. | 48 // Extract notification id from syncer::SyncData. |
47 std::string GetNotificationId(const SyncData& sync_data) { | 49 std::string GetNotificationId(const SyncData& sync_data) { |
48 SyncedNotificationSpecifics specifics = sync_data.GetSpecifics(). | 50 SyncedNotificationSpecifics specifics = sync_data.GetSpecifics(). |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 return change_map_[id]; | 94 return change_map_[id]; |
93 } | 95 } |
94 | 96 |
95 private: | 97 private: |
96 // Track the changes received in ProcessSyncChanges. | 98 // Track the changes received in ProcessSyncChanges. |
97 std::map<std::string, SyncChange> change_map_; | 99 std::map<std::string, SyncChange> change_map_; |
98 | 100 |
99 DISALLOW_COPY_AND_ASSIGN(TestChangeProcessor); | 101 DISALLOW_COPY_AND_ASSIGN(TestChangeProcessor); |
100 }; | 102 }; |
101 | 103 |
102 class SyncChangeProcessorDelegate : public syncer::SyncChangeProcessor { | |
103 public: | |
104 explicit SyncChangeProcessorDelegate(SyncChangeProcessor* recipient) | |
105 : recipient_(recipient) { | |
106 EXPECT_TRUE(recipient_); | |
107 } | |
108 virtual ~SyncChangeProcessorDelegate() {} | |
109 | |
110 // syncer::SyncChangeProcessor implementation. | |
111 virtual syncer::SyncError ProcessSyncChanges( | |
112 const tracked_objects::Location& from_here, | |
113 const SyncChangeList& change_list) OVERRIDE { | |
114 return recipient_->ProcessSyncChanges(from_here, change_list); | |
115 } | |
116 | |
117 virtual syncer::SyncDataList GetAllSyncData(syncer::ModelType type) const | |
118 OVERRIDE { | |
119 return recipient_->GetAllSyncData(type); | |
120 } | |
121 | |
122 private: | |
123 // The recipient of all sync changes. | |
124 SyncChangeProcessor* recipient_; | |
125 | |
126 DISALLOW_COPY_AND_ASSIGN(SyncChangeProcessorDelegate); | |
127 }; | |
128 | |
129 class ChromeNotifierServiceTest : public testing::Test { | 104 class ChromeNotifierServiceTest : public testing::Test { |
130 public: | 105 public: |
131 ChromeNotifierServiceTest() | 106 ChromeNotifierServiceTest() |
132 : sync_processor_(new TestChangeProcessor), | 107 : sync_processor_(new TestChangeProcessor), |
133 sync_processor_delegate_(new SyncChangeProcessorDelegate( | 108 sync_processor_wrapper_( |
134 sync_processor_.get())) {} | 109 new SyncChangeProcessorWrapperForTest(sync_processor_.get())) {} |
135 virtual ~ChromeNotifierServiceTest() {} | 110 virtual ~ChromeNotifierServiceTest() {} |
136 | 111 |
137 // Methods from testing::Test. | 112 // Methods from testing::Test. |
138 virtual void SetUp() { | 113 virtual void SetUp() { |
139 // These tests rely on synced notifications being active. Some testers | 114 // These tests rely on synced notifications being active. Some testers |
140 // report the channel as STABLE so we need to manually enable it. | 115 // report the channel as STABLE so we need to manually enable it. |
141 // See crbug.com/338426 for details. | 116 // See crbug.com/338426 for details. |
142 CommandLine::ForCurrentProcess()->AppendSwitch( | 117 CommandLine::ForCurrentProcess()->AppendSwitch( |
143 switches::kEnableSyncSyncedNotifications); | 118 switches::kEnableSyncSyncedNotifications); |
144 | 119 |
(...skipping 12 matching lines...) Expand all Loading... |
157 | 132 |
158 StubNotificationUIManager* notification_manager() { | 133 StubNotificationUIManager* notification_manager() { |
159 return notification_manager_.get(); | 134 return notification_manager_.get(); |
160 } | 135 } |
161 | 136 |
162 TestChangeProcessor* processor() { | 137 TestChangeProcessor* processor() { |
163 return static_cast<TestChangeProcessor*>(sync_processor_.get()); | 138 return static_cast<TestChangeProcessor*>(sync_processor_.get()); |
164 } | 139 } |
165 | 140 |
166 scoped_ptr<syncer::SyncChangeProcessor> PassProcessor() { | 141 scoped_ptr<syncer::SyncChangeProcessor> PassProcessor() { |
167 return sync_processor_delegate_.Pass(); | 142 return sync_processor_wrapper_.Pass(); |
168 } | 143 } |
169 | 144 |
170 SyncedNotification* CreateNotification( | 145 SyncedNotification* CreateNotification( |
171 const std::string& title, | 146 const std::string& title, |
172 const std::string& text, | 147 const std::string& text, |
173 const std::string& app_icon_url, | 148 const std::string& app_icon_url, |
174 const std::string& image_url, | 149 const std::string& image_url, |
175 const std::string& app_id, | 150 const std::string& app_id, |
176 const std::string& key, | 151 const std::string& key, |
177 sync_pb::CoalescedSyncedNotification_ReadState read_state) { | 152 sync_pb::CoalescedSyncedNotification_ReadState read_state) { |
(...skipping 15 matching lines...) Expand all Loading... |
193 FROM_HERE, | 168 FROM_HERE, |
194 type, | 169 type, |
195 ChromeNotifierService::CreateSyncDataFromNotification(*notification)); | 170 ChromeNotifierService::CreateSyncDataFromNotification(*notification)); |
196 } | 171 } |
197 | 172 |
198 protected: | 173 protected: |
199 scoped_ptr<TestingProfile> profile_; | 174 scoped_ptr<TestingProfile> profile_; |
200 | 175 |
201 private: | 176 private: |
202 scoped_ptr<syncer::SyncChangeProcessor> sync_processor_; | 177 scoped_ptr<syncer::SyncChangeProcessor> sync_processor_; |
203 scoped_ptr<syncer::SyncChangeProcessor> sync_processor_delegate_; | 178 scoped_ptr<syncer::SyncChangeProcessor> sync_processor_wrapper_; |
204 scoped_ptr<StubNotificationUIManager> notification_manager_; | 179 scoped_ptr<StubNotificationUIManager> notification_manager_; |
205 content::TestBrowserThreadBundle thread_bundle_; | 180 content::TestBrowserThreadBundle thread_bundle_; |
206 | 181 |
207 DISALLOW_COPY_AND_ASSIGN(ChromeNotifierServiceTest); | 182 DISALLOW_COPY_AND_ASSIGN(ChromeNotifierServiceTest); |
208 }; | 183 }; |
209 | 184 |
210 // TODO(petewil): Add more tests as I add functionalty. Tests are based on | 185 // TODO(petewil): Add more tests as I add functionalty. Tests are based on |
211 // chrome/browser/extensions/app_notification_manager_sync_unittest.cc | 186 // chrome/browser/extensions/app_notification_manager_sync_unittest.cc |
212 | 187 |
213 // Create a Notification, convert it to SyncData and convert it back. | 188 // Create a Notification, convert it to SyncData and convert it back. |
(...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
691 TEST_F(ChromeNotifierServiceTest, CheckFindAppInfo) { | 666 TEST_F(ChromeNotifierServiceTest, CheckFindAppInfo) { |
692 ChromeNotifierService notifier(profile_.get(), notification_manager()); | 667 ChromeNotifierService notifier(profile_.get(), notification_manager()); |
693 notifier.set_avoid_bitmap_fetching_for_test(true); | 668 notifier.set_avoid_bitmap_fetching_for_test(true); |
694 | 669 |
695 SyncedNotificationAppInfo* app_info = | 670 SyncedNotificationAppInfo* app_info = |
696 notifier.FindAppInfo(kFirstSyncedNotificationServiceId); | 671 notifier.FindAppInfo(kFirstSyncedNotificationServiceId); |
697 EXPECT_TRUE(app_info != NULL); | 672 EXPECT_TRUE(app_info != NULL); |
698 } | 673 } |
699 | 674 |
700 } // namespace notifier | 675 } // namespace notifier |
OLD | NEW |