a7745566cc458f8358ee81cb2856024e2e59d0cc
[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 lang="en">
23 <head>
24 <title>MessageStorage_email_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_email_updateMessages_without_errorCallback
34 //==== LABEL Check if method updateMessages of MessageStorage (email) works properly - without errorCallback
35 //==== SPEC Tizen Web API:Communication:Messaging:MessageStorage:updateMessages M
36 //==== SPEC_URL https://developer.tizen.org/help/index.jsp?topic=/org.tizen.web.device.apireference/tizen/messaging.html
37 //==== ONLOAD_DELAY 180
38 //==== TIMEOUT 180
39 //==== TEST_CRITERIA MR MOA MAST
40 setup({timeout: 180000});
41
42 var t = async_test("MessageStorage_email_updateMessages_without_errorCallback", {timeout:180000});
43 t.step(function () {
44     var serviceSuccess, serviceError, messageService, messageStorage,
45         currentDate = new Date(), plainBodyToSet = currentDate.getTime().toString(),
46         mutableMessage, constMessage,
47         initDictForMutableMessage = emailMessageInitDict, initDictForConstMessage = emailMessageInitDict,
48         plainBodyToSetForMutableMesage = plainBodyToSet + "_mutable", plainBodyToSetForConstMessage = plainBodyToSet + "_const",
49
50         addDraftSuccess, addDraftError, addDraftSuccessCounter = 0, returnedValue,
51         updateSuccess, mutableMessagefilter, constMessagefilter,
52         findMutableMessagesSuccess, findMutableMessagesError, foundMutableMessage, mutable = "MUTABLE",
53         findConstMessagesSuccess, findConstMessagesError, foundConstMessage, consts = "CONST",
54         loadMutableSuccess, loadMutableError,
55         loadConstSuccess, loadConstError,
56         loadMutableAttachmentSuccess, loadMutableAttachmentError,
57         loadConstAttachmentSuccess, loadConstAttachmentError,
58         testMessage, testAttachment, testAttachmentCounter = 0;
59
60     testAttachment = t.step_func(function (attachment, type) {
61         var j, foundAttachmenentCounter = 0;
62         if (type === mutable) {
63             for (j = 0; j < mutableMessage.attachments.length; j++) {
64                 if (attachment.id === mutableMessage.attachments[j].id) {
65                     assert_equals(attachment.id, mutableMessage.attachments[j].id, type + " attachment.id");
66                     assert_equals(attachment.messageId, mutableMessage.attachments[j].messageId, type + " attachment.messageId");
67                     assert_equals(attachment.messageId, mutableMessage.id, type + " attachment.messageId (with message.id)");
68                     assert_equals(attachment.mimeType, mutableMessage.attachments[j].mimeType, type + " attachment.mimeType");
69                     assert_type(attachment.filePath, "string",  type + " attachment.filePath is not a string");
70                     assert_not_equals(attachment.filePath, "", type + " attachment.filePath is empty");
71                     foundAttachmenentCounter++;
72                 }
73             }
74             assert_equals(foundAttachmenentCounter, 1, type + " incorrect number of found attachement = " + foundAttachmenentCounter);
75         } else if (type === consts) {
76             for (j = 0; j < constMessage.attachments.length; j++) {
77                 if (attachment.id === constMessage.attachments[j].id) {
78                     assert_equals(attachment.id, constMessage.attachments[j].id, type + " attachment.id");
79                     assert_equals(attachment.messageId, constMessage.attachments[j].messageId, type + " attachment.messageId");
80                     assert_equals(attachment.messageId, constMessage.id, type + " attachment.messageId - (with message.id)");
81                     assert_equals(attachment.mimeType, constMessage.attachments[j].mimeType, type + " attachment.mimeType");
82                     assert_type(attachment.filePath, "string",  type + " attachment.filePath is not a string");
83                     assert_not_equals(attachment.filePath, "", type + " attachment.filePath is empty");
84                     foundAttachmenentCounter++;
85                 }
86             }
87             assert_equals(foundAttachmenentCounter, 1, type + " incorrect number of found attachement = " + foundAttachmenentCounter);
88         } else {
89             assert_unreached("FIX your test - unknown type = " + type);
90         }
91
92         testAttachmentCounter++;
93         if (testAttachmentCounter === mutableMessage.attachments.length + constMessage.attachments.length) {
94             t.done();
95         }
96     });
97
98     loadMutableAttachmentSuccess = t.step_func(function (attachment) {
99         testAttachment(attachment, mutable);
100     });
101
102     loadMutableAttachmentError = t.step_func(function (error) {
103         assert_unreached("loadMessageAttachment() error callback: name:" + error.name + ", msg:" + error.message);
104     });
105
106     loadConstAttachmentSuccess = t.step_func(function (attachment) {
107          testAttachment(attachment, consts);
108     });
109
110     loadConstAttachmentError = t.step_func(function (error) {
111         assert_unreached("loadMessageAttachment() error callback: name:" + error.name + ", msg:" + error.message);
112     });
113
114     testMessage = t.step_func(function (messageToTest, originalMessage, type) {
115         var i;
116         assert_equals(messageToTest.id, originalMessage.id, type + " id attribute.");
117         assert_equals(messageToTest.folderId, originalMessage.folderId, type + " folderId attribute.");
118         assert_equals(messageToTest.type, originalMessage.type, type + " type attribute.");
119
120         assert_equals(messageToTest.from, originalMessage.from, type + " from attribute.");
121         assert_array_equals(messageToTest.to, originalMessage.to, type + " to attribute.");
122         assert_array_equals(messageToTest.cc, originalMessage.cc, type + " cc attribute.");
123         assert_array_equals(messageToTest.bcc, originalMessage.bcc, type + " bcc attribute.");
124
125         assert_equals(messageToTest.body.messageId, originalMessage.body.messageId, type + " body.messageId attribute.");
126         assert_equals(messageToTest.body.messageId, originalMessage.id, type + " body.messageId attribute (with message.id).");
127         assert_equals(messageToTest.body.loaded, originalMessage.body.loaded, type + " body.loaded attribute.");
128         assert_equals(messageToTest.body.plainBody, originalMessage.body.plainBody, type + " body.plainBody attribute.");
129         assert_equals(messageToTest.body.htmlBody, originalMessage.body.htmlBody, type + " body.htmlBody attribute.");
130
131         assert_equals(messageToTest.body.inlineAttachments.length, originalMessage.body.inlineAttachments.length, type + " incorrect length of inlineAttachments");
132         for (i = 0; i < originalMessage.body.inlineAttachments.length; i++) {
133             assert_equals(messageToTest.body.inlineAttachments[i].id, originalMessage.body.inlineAttachments[i].id, type + " message.body.inlineAttachments[" + i + "].id");
134             assert_equals(messageToTest.body.inlineAttachments[i].messageId, originalMessage.body.inlineAttachments[i].messageId, type + " message.body.inlineAttachments[" + i + "].messageId");
135             assert_equals(messageToTest.body.inlineAttachments[i].messageId, originalMessage.id, type + " message.body.inlineAttachments[" + i + "].messageId - (with message.id)");
136             assert_equals(messageToTest.body.inlineAttachments[i].mimeType, originalMessage.body.inlineAttachments[i].mimeType, type + " message.body.inlineAttachments[" + i + "].mimeType");
137             assert_type(messageToTest.body.inlineAttachments[i].filePath, "string",  type + " attachment.filePath is not a string");
138             assert_not_equals(messageToTest.body.inlineAttachments[i].filePath, "", type + " attachment.filePath is empty");
139         }
140
141         assert_equals(messageToTest.isRead, originalMessage.isRead, type + " isRead attribute.");
142         assert_equals(messageToTest.hasAttachment, originalMessage.hasAttachment, type + " hasAttachment attribute.");
143         assert_equals(messageToTest.isHighPriority, originalMessage.isHighPriority, type + " isHighPriority attribute.");
144         assert_equals(messageToTest.subject, originalMessage.subject, type + " subject attribute.");
145         assert_equals(messageToTest.messageStatus, originalMessage.messageStatus, type + " messageStatus attribute.");
146         assert_equals(messageToTest.inResponseTo, originalMessage.inResponseTo, type + " inResponseTo attribute.");
147         if (messageToTest.timestamp !== null && originalMessage.timestamp !== null) {
148             assert_equals(messageToTest.timestamp.getTime(), originalMessage.timestamp.getTime(), type + " timestamp attribute.");
149         } else {
150             assert_equals(messageToTest.timestamp, originalMessage.timestamp, type + " timestamp attribute.");
151         }
152         assert_equals(messageToTest.conversationId, originalMessage.conversationId, type + "  conversationId attribute.");
153
154         assert_equals(messageToTest.attachments.length, originalMessage.attachments.length, type + " incorrect length of attachments");
155         for (i = 0; i < messageToTest.attachments.length; i++) {
156             if (type === mutable) {
157                 messageService.loadMessageAttachment(messageToTest.attachments[i], loadMutableAttachmentSuccess, loadMutableAttachmentError);
158             } else if (type === consts) {
159                 messageService.loadMessageAttachment(messageToTest.attachments[i], loadConstAttachmentSuccess, loadConstAttachmentError);
160             } else {
161                 assert_unreached("FIX your test - unknown type = " + type);
162             }
163         }
164     });
165
166     loadMutableSuccess = t.step_func(function (loadedMutableMessage) {
167         testMessage(loadedMutableMessage, mutableMessage, mutable);
168     });
169
170     loadMutableError = t.step_func(function (error) {
171         assert_unreached("loadMessageBody() error callback: name:" + error.name + ", msg:" + error.message);
172     });
173
174     loadConstSuccess = t.step_func(function (loadedConstMessage) {
175         testMessage(loadedConstMessage, constMessage, consts);
176     });
177
178     loadConstError = t.step_func(function (error) {
179         assert_unreached("loadMessageBody() error callback: name:" + error.name + ", msg:" + error.message);
180     });
181
182     findMutableMessagesSuccess = t.step_func(function (mutableMessages) {
183         assert_equals(mutableMessages.length, 1, "incorrect number of messages.");
184         foundMutableMessage = mutableMessages[0];
185         if (foundMutableMessage.body.loaded) {
186             testMessage(foundMutableMessage, mutableMessage, mutable);
187         } else {
188             messageService.loadMessageBody(foundMutableMessage, loadMutableSuccess, loadMutableError);
189         }
190     });
191
192     findMutableMessagesError = t.step_func(function (error) {
193         assert_unreached("findMessages() error callback: name:" + error.name + ", msg:" + error.message);
194     });
195
196     findConstMessagesSuccess = t.step_func(function (constMessages) {
197         assert_equals(constMessages.length, 1, "incorrect number of messages.");
198         foundConstMessage = constMessages[0];
199         if (foundConstMessage.body.loaded) {
200             testMessage(foundConstMessage, constMessage, consts);
201         } else {
202             messageService.loadMessageBody(foundConstMessage, loadConstSuccess, loadConstError);
203         }
204     });
205
206     findConstMessagesError = t.step_func(function (error) {
207         assert_unreached("findMessages() error callback: name:" + error.name + ", msg:" + error.message);
208     });
209
210
211     updateSuccess = t.step_func(function () {
212         assert_equals(returnedValue, undefined, "Incorrect returned value from updateMessages");
213         mutableMessagefilter = new tizen.AttributeFilter("id", "EXACTLY", mutableMessage.id);
214         messageStorage.findMessages(mutableMessagefilter, findMutableMessagesSuccess, findMutableMessagesError);
215
216         constMessagefilter = new tizen.AttributeFilter("id", "EXACTLY", constMessage.id);
217         messageStorage.findMessages(constMessagefilter, findConstMessagesSuccess, findConstMessagesError);
218     });
219
220     addDraftSuccess = t.step_func(function () {
221         addDraftSuccessCounter++;
222         if (addDraftSuccessCounter === 2) {
223             mutableMessage.isRead = true;
224             mutableMessage.isHighPriority = true;
225             mutableMessage.subject = "new mutableMessage.subject";
226             returnedValue = messageStorage.updateMessages([mutableMessage, constMessage], updateSuccess);
227         }
228     });
229
230     addDraftError = t.step_func(function (error) {
231         assert_unreached("addDraftMessage() error callback: name:" + error.name + ", msg:" + error.message);
232     });
233
234     serviceSuccess = t.step_func(function (services) {
235         assert_true(services.length > 0, "Received empty services array");
236         messageService = services[0];
237         messageStorage = messageService.messageStorage;
238
239         initDictForMutableMessage.plainBody = plainBodyToSetForMutableMesage;
240         mutableMessage = new tizen.Message("messaging.email", initDictForMutableMessage);
241         messageStorage.addDraftMessage(mutableMessage, addDraftSuccess, addDraftError);
242
243         initDictForConstMessage.plainBody = plainBodyToSetForConstMessage;
244         constMessage = new tizen.Message("messaging.email", initDictForConstMessage);
245         constMessage.attachments = [new tizen.MessageAttachment(soundPathToSet, "audio/mp3"), new tizen.MessageAttachment(soundPathToSet, "audio/mp3"), new tizen.MessageAttachment(imagePathToSet, "image/jpg")];
246         messageStorage.addDraftMessage(constMessage, addDraftSuccess, addDraftError);
247     });
248
249     serviceError = t.step_func(function (error) {
250         assert_unreached("getMessageServices() error callback: name:" + error.name + ", msg:" + error.message);
251     });
252     tizen.messaging.getMessageServices("messaging.email", serviceSuccess, serviceError);
253 });
254
255
256 </script>
257 </body>
258 </html>