1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/notifications/sync_notifier/sync_notifier_test_utils.h"
6
7 // Test data for App Info structures.
8 const char kSendingService1Name[] = "TestService1";
9 const char kSendingService2Name[] = "TestService2";
10 const char kSendingService3Name[] = "TestService3";
11 const char kTestInfoUrl[] = "https://www.google.com/info.html";
12 const char kTestIconUrl[] = "https://www.google.com/someicon.png";
13
14 // Fake data for creating a SyncData object to use in creating a
15 // SyncedNotification.
16 const char kAppId1[] = "fboilmbenheemaomgaeehigklolhkhnf";
17 const char kAppId2[] = "fbcmoldooppoahjhfflnmljoanccekpf";
18 const char kAppId3[] = "fbcmoldooppoahjhfflnmljoanccek33";
19 const char kAppId4[] = "fbcmoldooppoahjhfflnmljoanccek44";
20 const char kAppId5[] = "fbcmoldooppoahjhfflnmljoanccek55";
21 const char kAppId6[] = "fbcmoldooppoahjhfflnmljoanccek66";
22 const char kAppId7[] = "fbcmoldooppoahjhfflnmljoanccek77";
23 const char kKey1[] = "foo";
24 const char kKey2[] = "bar";
25 const char kKey3[] = "bat";
26 const char kKey4[] = "baz";
27 const char kKey5[] = "foobar";
28 const char kKey6[] = "fu";
29 const char kKey7[] = "meta";
30 const char kIconUrl1[] = "http://www.google.com/icon1.jpg";
31 const char kIconUrl2[] = "http://www.google.com/icon2.jpg";
32 const char kIconUrl3[] = "http://www.google.com/icon3.jpg";
33 const char kIconUrl4[] = "http://www.google.com/icon4.jpg";
34 const char kIconUrl5[] = "http://www.google.com/icon5.jpg";
35 const char kIconUrl6[] = "http://www.google.com/icon6.jpg";
36 const char kIconUrl7[] = "http://www.google.com/icon7.jpg";
37 const char kTitle1[] = "New appointment at 2:15";
38 const char kTitle2[] = "Email from Mark: Upcoming Ski trip";
39 const char kTitle3[] = "Weather alert - light rain tonight.";
40 const char kTitle4[] = "Zombie Alert on I-405";
41 const char kTitle5[] = "5-dimensional plutonian steam hockey scores";
42 const char kTitle6[] = "Conterfactuals Inc Stock report";
43 const char kTitle7[] = "Push Messaging app updated";
44 const char kText1[] = "Space Needle, 12:00 pm";
45 const char kText2[] = "Stevens Pass is our first choice.";
46 const char kText3[] = "More rain expected in the Seattle area tonight.";
47 const char kText4[] = "Traffic slowdown as motorists are hitting zombies";
48 const char kText5[] = "Neptune wins, pi to e";
49 const char kText6[] = "Beef flavored base for soups";
50 const char kText7[] = "You now have the latest version of Push Messaging App.";
51 const char kText1And1[] = "Space Needle, 12:00 pm\nSpace Needle, 12:00 pm";
52 const char kImageUrl1[] = "http://www.google.com/image1.jpg";
53 const char kImageUrl2[] = "http://www.google.com/image2.jpg";
54 const char kImageUrl3[] = "http://www.google.com/image3.jpg";
55 const char kImageUrl4[] = "http://www.google.com/image4.jpg";
56 const char kImageUrl5[] = "http://www.google.com/image5.jpg";
57 const char kImageUrl6[] = "http://www.google.com/image6.jpg";
58 const char kImageUrl7[] = "http://www.google.com/image7.jpg";
59 const char kExpectedOriginUrl[] =
60 "synced-notification://fboilmbenheemaomgaeehigklolhkhnf";
61 const char kDefaultDestinationTitle[] = "Open web page";
62 const char kDefaultDestinationIconUrl[] = "http://www.google.com/image4.jpg";
63 const char kDefaultDestinationUrl[] = "chrome://flags";
64 const char kButtonOneTitle[] = "Read";
65 const char kButtonOneIconUrl[] = "http://www.google.com/image8.jpg";
66 const char kButtonOneUrl[] = "chrome://sync";
67 const char kButtonTwoTitle[] = "Reply";
68 const char kButtonTwoIconUrl[] = "http://www.google.com/image9.jpg";
69 const char kButtonTwoUrl[] = "chrome://about";
70 const char kContainedTitle1[] = "Today's Picnic moved";
71 const char kContainedTitle2[] = "Group Run Today";
72 const char kContainedTitle3[] = "Starcraft Tonight";
73 const char kContainedMessage1[] = "Due to rain, we will be inside the cafe.";
74 const char kContainedMessage2[] = "Meet at noon in the Gym.";
75 const char kContainedMessage3[] = "Let's play starcraft tonight on the LAN.";
76
CreateSyncData(const std::string & title,const std::string & text,const std::string & app_icon_url,const std::string & image_url,const std::string & app_id,const std::string & key,const sync_pb::CoalescedSyncedNotification_ReadState read_state)77 syncer::SyncData CreateSyncData(
78 const std::string& title,
79 const std::string& text,
80 const std::string& app_icon_url,
81 const std::string& image_url,
82 const std::string& app_id,
83 const std::string& key,
84 const sync_pb::CoalescedSyncedNotification_ReadState read_state) {
85 // CreateLocalData makes a copy of this, so this can safely live
86 // on the stack.
87 sync_pb::EntitySpecifics entity_specifics;
88
89 // Get a writeable pointer to the sync notifications specifics inside the
90 // entity specifics.
91 sync_pb::SyncedNotificationSpecifics* specifics =
92 entity_specifics.mutable_synced_notification();
93
94 // Get pointers to sub structures.
95 sync_pb::CoalescedSyncedNotification* coalesced_notification =
96 specifics->mutable_coalesced_notification();
97 sync_pb::SyncedNotificationRenderInfo* render_info =
98 coalesced_notification->mutable_render_info();
99 sync_pb::ExpandedInfo* expanded_info =
100 render_info->mutable_expanded_info();
101 sync_pb::SimpleExpandedLayout* simple_expanded_layout =
102 expanded_info->mutable_simple_expanded_layout();
103 sync_pb::CollapsedInfo* collapsed_info =
104 render_info->mutable_collapsed_info();
105 sync_pb::SimpleCollapsedLayout* simple_collapsed_layout =
106 collapsed_info->mutable_simple_collapsed_layout();
107 sync_pb::SyncedNotificationDestination* default_destination =
108 collapsed_info->mutable_default_destination();
109
110 coalesced_notification->set_app_id(app_id);
111
112 coalesced_notification->set_key(key);
113
114 coalesced_notification->
115 set_priority(static_cast<sync_pb::CoalescedSyncedNotification_Priority>(
116 kProtobufPriority));
117
118 // Set the title.
119 simple_expanded_layout->set_title(title);
120 simple_collapsed_layout->set_heading(title);
121
122 // Set the text.
123 simple_expanded_layout->set_text(text);
124 simple_collapsed_layout->set_description(text);
125 simple_collapsed_layout->set_annotation(text);
126
127 // Set the heading.
128 simple_collapsed_layout->set_heading(title);
129
130 // Add the collapsed info and set the app_icon_url on it.
131 simple_collapsed_layout->
132 mutable_app_icon()->
133 set_url(app_icon_url);
134
135 // Add the media object and set the image url on it.
136 simple_collapsed_layout->add_media();
137 simple_collapsed_layout->
138 mutable_media(0)->
139 mutable_image()->
140 set_url(image_url);
141
142 coalesced_notification->set_creation_time_msec(kFakeCreationTime);
143
144 coalesced_notification->set_read_state(read_state);
145
146 // Contained notification one.
147 expanded_info->add_collapsed_info();
148 sync_pb::SimpleCollapsedLayout* notification_layout1 =
149 expanded_info->
150 mutable_collapsed_info(0)->
151 mutable_simple_collapsed_layout();
152 notification_layout1->set_heading(kContainedTitle1);
153 notification_layout1->set_description(kContainedMessage1);
154
155 // Contained notification two.
156 expanded_info->add_collapsed_info();
157 sync_pb::SimpleCollapsedLayout* notification_layout2 =
158 expanded_info->
159 mutable_collapsed_info(1)->
160 mutable_simple_collapsed_layout();
161 notification_layout2->set_heading(kContainedTitle2);
162 notification_layout2->set_description(kContainedMessage2);
163
164 // Contained notification three.
165 expanded_info->add_collapsed_info();
166 sync_pb::SimpleCollapsedLayout* notification_layout3 =
167 expanded_info->
168 mutable_collapsed_info(2)->
169 mutable_simple_collapsed_layout();
170 notification_layout3->set_heading(kContainedTitle3);
171 notification_layout3->set_description(kContainedMessage3);
172
173 // Default Destination.
174 default_destination->set_text(kDefaultDestinationTitle);
175 default_destination->mutable_icon()->set_url(kDefaultDestinationIconUrl);
176 default_destination->mutable_icon()->set_alt_text(kDefaultDestinationTitle);
177 default_destination->set_url(kDefaultDestinationUrl);
178
179 // Buttons are represented as targets.
180
181 // Button One.
182 collapsed_info->add_target();
183 sync_pb::SyncedNotificationAction* action1 =
184 collapsed_info->mutable_target(0)->mutable_action();
185 action1->set_text(kButtonOneTitle);
186 action1->mutable_icon()->set_url(kButtonOneIconUrl);
187 action1->mutable_icon()->set_alt_text(kButtonOneTitle);
188 action1->set_url(kButtonOneUrl);
189
190 // Button Two.
191 collapsed_info->add_target();
192 sync_pb::SyncedNotificationAction* action2 =
193 collapsed_info->mutable_target(1)->mutable_action();
194 action2->set_text(kButtonOneTitle);
195 action2->mutable_icon()->set_url(kButtonTwoIconUrl);
196 action2->mutable_icon()->set_alt_text(kButtonTwoTitle);
197 action2->set_url(kButtonTwoUrl);
198
199 syncer::SyncData sync_data = syncer::SyncData::CreateLocalData(
200 "syncer::SYNCED_NOTIFICATIONS",
201 "ChromeNotifierServiceUnitTest",
202 entity_specifics);
203
204 return sync_data;
205 }
206
207 namespace notifier {
208
StubSyncedNotificationAppInfoService(Profile * profile)209 StubSyncedNotificationAppInfoService::StubSyncedNotificationAppInfoService(
210 Profile* profile) : SyncedNotificationAppInfoService(profile) {
211 on_bitmap_fetches_done_called_ = false;
212 }
213
~StubSyncedNotificationAppInfoService()214 StubSyncedNotificationAppInfoService::~StubSyncedNotificationAppInfoService() {
215 }
216
217 syncer::SyncMergeResult
MergeDataAndStartSyncing(syncer::ModelType type,const syncer::SyncDataList & initial_sync_data,scoped_ptr<syncer::SyncChangeProcessor> sync_processor,scoped_ptr<syncer::SyncErrorFactory> error_handler)218 StubSyncedNotificationAppInfoService::MergeDataAndStartSyncing(
219 syncer::ModelType type,
220 const syncer::SyncDataList& initial_sync_data,
221 scoped_ptr<syncer::SyncChangeProcessor> sync_processor,
222 scoped_ptr<syncer::SyncErrorFactory> error_handler) {
223 return syncer::SyncMergeResult(syncer::SYNCED_NOTIFICATION_APP_INFO);
224 }
225
ProcessSyncChanges(const tracked_objects::Location & from_here,const syncer::SyncChangeList & change_list)226 syncer::SyncError StubSyncedNotificationAppInfoService::ProcessSyncChanges(
227 const tracked_objects::Location& from_here,
228 const syncer::SyncChangeList& change_list) {
229 return syncer::SyncError();
230 }
231
GetAllSyncData(syncer::ModelType type) const232 syncer::SyncDataList StubSyncedNotificationAppInfoService::GetAllSyncData(
233 syncer::ModelType type) const {
234 return syncer::SyncDataList();
235 }
236
OnBitmapFetchesDone(std::vector<std::string> added_app_ids,std::vector<std::string> removed_app_ids)237 void StubSyncedNotificationAppInfoService::OnBitmapFetchesDone(
238 std::vector<std::string> added_app_ids,
239 std::vector<std::string> removed_app_ids) {
240 added_app_ids_ = added_app_ids;
241 removed_app_ids_ = removed_app_ids;
242 on_bitmap_fetches_done_called_ = true;
243 }
244
245 scoped_ptr<SyncedNotificationAppInfo>
246 StubSyncedNotificationAppInfoService::
CreateSyncedNotificationAppInfoFromProtobuf(const sync_pb::SyncedNotificationAppInfo & app_info)247 CreateSyncedNotificationAppInfoFromProtobuf(
248 const sync_pb::SyncedNotificationAppInfo& app_info) {
249 return scoped_ptr<SyncedNotificationAppInfo>();
250 }
251
252 SyncedNotificationAppInfo*
FindSyncedNotificationAppInfoByName(const std::string & name)253 StubSyncedNotificationAppInfoService::FindSyncedNotificationAppInfoByName(
254 const std::string& name) {
255 return NULL;
256 }
257
258 SyncedNotificationAppInfo*
FindSyncedNotificationAppInfoByAppId(const std::string & app_id)259 StubSyncedNotificationAppInfoService::FindSyncedNotificationAppInfoByAppId(
260 const std::string& app_id) {
261 return NULL;
262 }
263
264 std::string
FindSendingServiceNameFromAppId(const std::string app_id)265 StubSyncedNotificationAppInfoService::FindSendingServiceNameFromAppId(
266 const std::string app_id) {
267 return std::string();
268 }
269 std::vector<SyncedNotificationSendingServiceSettingsData>
GetAllSendingServiceSettingsData()270 StubSyncedNotificationAppInfoService::GetAllSendingServiceSettingsData() {
271 std::vector<SyncedNotificationSendingServiceSettingsData> empty;
272 return empty;
273 }
274
275
276 // Probe functions to return data.
added_app_ids()277 std::vector<std::string> StubSyncedNotificationAppInfoService::added_app_ids() {
278 return added_app_ids_;
279 }
280
281 std::vector<std::string>
removed_app_ids()282 StubSyncedNotificationAppInfoService::removed_app_ids() {
283 return removed_app_ids_;
284 }
on_bitmap_fetches_done_called()285 bool StubSyncedNotificationAppInfoService::on_bitmap_fetches_done_called() {
286 return on_bitmap_fetches_done_called_;
287 }
288
289 } // namespace notifier
290