1dd8de87397397bf0abe2276e643885d3429d57f
[test/tct/web/api.git] /
1 <!DOCTYPE html>
2 <!--
3 Copyright (c) 2013 Samsung Electronics Co., Ltd.
4
5 Licensed under the Apache License, Version 2.0 (the License);
6 you may not use this file except in compliance with the License.
7 You may obtain a copy of the License at
8
9     http://www.apache.org/licenses/LICENSE-2.0
10
11 Unless required by applicable law or agreed to in writing, software
12 distributed under the License is distributed on an "AS IS" BASIS,
13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 See the License for the specific language governing permissions and
15 limitations under the License.
16
17
18 Authors:
19         Andrzej Krolikowski <a.krolikowsk@samsung.com>
20
21 -->
22 <html>
23 <head>
24 <title>MessageStorage_mms_updateMessages_without_errorCallback</title>
25 <meta charset="utf-8"/>
26 <script type="text/javascript" src="../resources/unitcommon.js"></script>
27 <script type="text/javascript" src="support/messaging_common.js"></script>
28 </head>
29
30 <body>
31 <div id="log"></div>
32 <script>
33 //==== TEST: MessageStorage_mms_updateMessages_without_errorCallback
34 //==== LABEL Check if method updateMessages of MessageStorage (MMS) works properly - without errorCallback.
35 //==== SPEC Tizen Web API:Communication:Messaging:MessageStorage:updateMessages M
36 //==== SPEC_URL https://developer.tizen.org/help/topic/org.tizen.web.device.apireference/tizen/messaging.html
37 //==== ONLOAD_DELAY 90
38 //==== TEST_CRITERIA MR MOA MAST
39 setup({timeout: 90000});
40
41 var t = async_test("MessageStorage_mms_updateMessages_without_errorCallback", {timeout:90000});
42 t.step(function () {
43     var serviceSuccess, serviceError, messageService, messageStorage,
44         currentDate = new Date(), plainBodyToSet = currentDate.getTime().toString(),
45         mutableMessage, constMessage,
46         initDictForMutableMessage = mmsMessageInitDict, initDictForConstMessage = mmsMessageInitDict,
47         plainBodyToSetForMutableMesage = plainBodyToSet + "_mutable", plainBodyToSetForConstMessage = plainBodyToSet + "_const",
48
49         addDraftSuccess, addDraftError, addDraftSuccessCounter = 0, returnedValue,
50         updateSuccess, mutableMessagefilter, constMessagefilter,
51         findMutableMessagesSuccess, findMutableMessagesError, foundMutableMessage, mutable = "MUTABLE",
52         findConstMessagesSuccess, findConstMessagesError, foundConstMessage, consts = "CONST",
53         loadMutableSuccess, loadMutableError,
54         loadConstSuccess, loadConstError,
55         loadMutableAttachmentSuccess, loadMutableAttachmentError,
56         loadConstAttachmentSuccess, loadConstAttachmentError,
57         testMessage, testAttachment, testAttachmentCounter = 0;
58
59     testAttachment = t.step_func(function (attachment, type) {
60         var j, foundAttachmenentCounter = 0;
61         if (type === mutable) {
62             for (j = 0; j < mutableMessage.attachments.length; j++) {
63                 if (attachment.id === mutableMessage.attachments[j].id) {
64                     assert_equals(attachment.id, mutableMessage.attachments[j].id, type + " attachment.id");
65                     assert_equals(attachment.messageId, mutableMessage.attachments[j].messageId, type + " attachment.messageId");
66                     assert_equals(attachment.messageId, mutableMessage.id, type + " attachment.messageId (with message.id)");
67                     assert_equals(attachment.mimeType, mutableMessage.attachments[j].mimeType, type + " attachment.mimeType");
68                     assert_type(attachment.filePath, "string",  type + " attachment.filePath is not a string");
69                     assert_not_equals(attachment.filePath, "", type + " attachment.filePath is empty");
70                     foundAttachmenentCounter++;
71                 }
72             }
73             assert_equals(foundAttachmenentCounter, 1, type + " incorrect number of found attachement = " + foundAttachmenentCounter);
74         } else if (type === consts) {
75             for (j = 0; j < constMessage.attachments.length; j++) {
76                 if (attachment.id === constMessage.attachments[j].id) {
77                     assert_equals(attachment.id, constMessage.attachments[j].id, type + " attachment.id");
78                     assert_equals(attachment.messageId, constMessage.attachments[j].messageId, type + " attachment.messageId");
79                     assert_equals(attachment.messageId, constMessage.id, type + " attachment.messageId - (with message.id)");
80                     assert_equals(attachment.mimeType, constMessage.attachments[j].mimeType, type + " attachment.mimeType");
81                     assert_type(attachment.filePath, "string",  type + " attachment.filePath is not a string");
82                     assert_not_equals(attachment.filePath, "", type + " attachment.filePath is empty");
83                     foundAttachmenentCounter++;
84                 }
85             }
86             assert_equals(foundAttachmenentCounter, 1, type + " incorrect number of found attachement = " + foundAttachmenentCounter);
87         } else {
88             assert_unreached("FIX your test - unknown type = " + type);
89         }
90
91         testAttachmentCounter++;
92         if (testAttachmentCounter === mutableMessage.attachments.length + constMessage.attachments.length) {
93             t.done();
94         }
95     });
96
97     loadMutableAttachmentSuccess = t.step_func(function (attachment) {
98         testAttachment(attachment, mutable);
99     });
100
101     loadMutableAttachmentError = t.step_func(function (error) {
102         assert_unreached("loadMessageAttachment() error callback: name:" + error.name + ", msg:" + error.message);
103     });
104
105     loadConstAttachmentSuccess = t.step_func(function (attachment) {
106         testAttachment(attachment, consts);
107     });
108
109     loadConstAttachmentError = t.step_func(function (error) {
110         assert_unreached("loadMessageAttachment() error callback: name:" + error.name + ", msg:" + error.message);
111     });
112
113     testMessage = t.step_func(function (messageToTest, originalMessage, type) {
114         var i;
115         assert_equals(messageToTest.id, originalMessage.id, type + " id attribute.");
116         assert_equals(messageToTest.folderId, originalMessage.folderId, type + " folderId attribute.");
117         assert_equals(messageToTest.type, originalMessage.type, type + " type attribute.");
118
119         assert_equals(messageToTest.from, originalMessage.from, type + " from attribute.");
120         assert_array_equals(messageToTest.to, originalMessage.to, type + " to attribute.");
121
122         assert_equals(messageToTest.body.messageId, originalMessage.body.messageId, type + " body.messageId attribute.");
123         assert_equals(messageToTest.body.messageId, originalMessage.id, type + " body.messageId attribute (with message.id).");
124         assert_equals(messageToTest.body.loaded, originalMessage.body.loaded, type + " body.loaded attribute.");
125         assert_equals(messageToTest.body.plainBody, originalMessage.body.plainBody, type + " body.plainBody attribute.");
126
127         assert_equals(messageToTest.isRead, originalMessage.isRead, type + " isRead attribute.");
128         assert_equals(messageToTest.hasAttachment, originalMessage.hasAttachment, type + " hasAttachment attribute.");
129         assert_equals(messageToTest.subject, originalMessage.subject, type + " subject attribute.");
130         assert_equals(messageToTest.messageStatus, originalMessage.messageStatus, type + " messageStatus attribute.");
131         assert_equals(messageToTest.inResponseTo, originalMessage.inResponseTo, type + " inResponseTo attribute.");
132         if (messageToTest.timestamp !== null && originalMessage.timestamp !== null) {
133             assert_equals(messageToTest.timestamp.getTime(), originalMessage.timestamp.getTime(), type + " timestamp attribute.");
134         } else {
135             assert_equals(messageToTest.timestamp, originalMessage.timestamp, type + " timestamp attribute.");
136         }
137
138         assert_equals(messageToTest.attachments.length, originalMessage.attachments.length, type + " incorrect length of attachments");
139         for (i = 0; i < messageToTest.attachments.length; i++) {
140             if (type === mutable) {
141                 messageService.loadMessageAttachment(messageToTest.attachments[i], loadMutableAttachmentSuccess, loadMutableAttachmentError);
142             } else if (type === consts) {
143                 messageService.loadMessageAttachment(messageToTest.attachments[i], loadConstAttachmentSuccess, loadConstAttachmentError);
144             } else {
145                 assert_unreached("FIX your test - unknown type = " + type);
146             }
147         }
148     });
149
150     loadMutableSuccess = t.step_func(function (loadedMutableMessage) {
151         testMessage(loadedMutableMessage, mutableMessage, mutable);
152     });
153
154     loadMutableError = t.step_func(function (error) {
155         assert_unreached("loadMessageBody() error callback: name:" + error.name + ", msg:" + error.message);
156     });
157
158     loadConstSuccess = t.step_func(function (loadedConstMessage) {
159         testMessage(loadedConstMessage, constMessage, consts);
160     });
161
162     loadConstError = t.step_func(function (error) {
163         assert_unreached("loadMessageBody() error callback: name:" + error.name + ", msg:" + error.message);
164     });
165
166     findMutableMessagesSuccess = t.step_func(function (mutableMessages) {
167         assert_equals(mutableMessages.length, 1, "incorrect number of messages.");
168         foundMutableMessage = mutableMessages[0];
169         if (foundMutableMessage.body.loaded) {
170             testMessage(foundMutableMessage, mutableMessage, mutable);
171         } else {
172             messageService.loadMessageBody(foundMutableMessage, loadMutableSuccess, loadMutableError);
173         }
174     });
175
176     findMutableMessagesError = t.step_func(function (error) {
177         assert_unreached("findMessages() error callback: name:" + error.name + ", msg:" + error.message);
178     });
179
180     findConstMessagesSuccess = t.step_func(function (constMessages) {
181         assert_equals(constMessages.length, 1, "incorrect number of messages.");
182         foundConstMessage = constMessages[0];
183         if (foundConstMessage.body.loaded) {
184             testMessage(foundConstMessage, constMessage, consts);
185         } else {
186             messageService.loadMessageBody(foundConstMessage, loadConstSuccess, loadConstError);
187         }
188     });
189
190     findConstMessagesError = t.step_func(function (error) {
191         assert_unreached("findMessages() error callback: name:" + error.name + ", msg:" + error.message);
192     });
193
194
195     updateSuccess = t.step_func(function () {
196         assert_equals(returnedValue, undefined, "Incorrect returned value from updateMessages");
197
198         mutableMessagefilter = new tizen.AttributeFilter("id", "EXACTLY", mutableMessage.id);
199         messageStorage.findMessages(mutableMessagefilter, findMutableMessagesSuccess, findMutableMessagesError);
200
201         constMessagefilter = new tizen.AttributeFilter("id", "EXACTLY", constMessage.id);
202         messageStorage.findMessages(constMessagefilter, findConstMessagesSuccess, findConstMessagesError);
203     });
204
205     addDraftSuccess = t.step_func(function () {
206         addDraftSuccessCounter++;
207         if (addDraftSuccessCounter === 2) {
208             mutableMessage.to = [TEST_SMS_RECIPIENT_2];
209             mutableMessage.body.plainBody = "new mutableMessage.plainBody";
210             mutableMessage.isRead = true;
211             mutableMessage.subject = "new mutableMessage.subject";
212             mutableMessage.attachments = [new tizen.MessageAttachment(soundPathToSet, "audio/mp3"),
213                 new tizen.MessageAttachment(imagePathToSet, "image/jpeg")];
214
215             returnedValue = messageStorage.updateMessages([mutableMessage, constMessage], updateSuccess);
216         }
217     });
218
219     addDraftError = t.step_func(function (error) {
220         assert_unreached("addDraftMessage() error callback: name:" + error.name + ", msg:" + error.message);
221     });
222
223     serviceSuccess = t.step_func(function (services) {
224         assert_true(services.length > 0, "Received empty services array");
225         messageService = services[0];
226         messageStorage = messageService.messageStorage;
227
228         initDictForMutableMessage.plainBody = plainBodyToSetForMutableMesage;
229         mutableMessage = new tizen.Message("messaging.mms", initDictForMutableMessage);
230         messageStorage.addDraftMessage(mutableMessage, addDraftSuccess, addDraftError);
231
232         initDictForConstMessage.plainBody = plainBodyToSetForConstMessage;
233         constMessage = new tizen.Message("messaging.mms", initDictForConstMessage);
234         constMessage.attachments = [new tizen.MessageAttachment(soundPathToSet, "audio/mp3"),
235             new tizen.MessageAttachment(soundPathToSet, "audio/mp3"), new tizen.MessageAttachment(imagePathToSet, "image/jpeg")];
236         messageStorage.addDraftMessage(constMessage, addDraftSuccess, addDraftError);
237     });
238
239     serviceError = t.step_func(function (error) {
240         assert_unreached("getMessageServices() error callback: name:" + error.name + ", msg:" + error.message);
241     });
242     tizen.messaging.getMessageServices("messaging.mms", serviceSuccess, serviceError);
243 });
244
245 </script>
246 </body>
247 </html>