3 Copyright (c) 2013 Samsung Electronics Co., Ltd.
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
9 http://www.apache.org/licenses/LICENSE-2.0
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.
19 Andrzej Krolikowski <a.krolikowsk@samsung.com>
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>
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
39 //==== TEST_CRITERIA MR MOA MAST
40 setup({timeout: 180000});
42 var t = async_test("MessageStorage_email_updateMessages_without_errorCallback", {timeout:180000});
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",
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;
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++;
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++;
87 assert_equals(foundAttachmenentCounter, 1, type + " incorrect number of found attachement = " + foundAttachmenentCounter);
89 assert_unreached("FIX your test - unknown type = " + type);
92 testAttachmentCounter++;
93 if (testAttachmentCounter === mutableMessage.attachments.length + constMessage.attachments.length) {
98 loadMutableAttachmentSuccess = t.step_func(function (attachment) {
99 testAttachment(attachment, mutable);
102 loadMutableAttachmentError = t.step_func(function (error) {
103 assert_unreached("loadMessageAttachment() error callback: name:" + error.name + ", msg:" + error.message);
106 loadConstAttachmentSuccess = t.step_func(function (attachment) {
107 testAttachment(attachment, consts);
110 loadConstAttachmentError = t.step_func(function (error) {
111 assert_unreached("loadMessageAttachment() error callback: name:" + error.name + ", msg:" + error.message);
114 testMessage = t.step_func(function (messageToTest, originalMessage, type) {
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.");
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.");
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.");
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");
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.");
150 assert_equals(messageToTest.timestamp, originalMessage.timestamp, type + " timestamp attribute.");
152 assert_equals(messageToTest.conversationId, originalMessage.conversationId, type + " conversationId attribute.");
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);
161 assert_unreached("FIX your test - unknown type = " + type);
166 loadMutableSuccess = t.step_func(function (loadedMutableMessage) {
167 testMessage(loadedMutableMessage, mutableMessage, mutable);
170 loadMutableError = t.step_func(function (error) {
171 assert_unreached("loadMessageBody() error callback: name:" + error.name + ", msg:" + error.message);
174 loadConstSuccess = t.step_func(function (loadedConstMessage) {
175 testMessage(loadedConstMessage, constMessage, consts);
178 loadConstError = t.step_func(function (error) {
179 assert_unreached("loadMessageBody() error callback: name:" + error.name + ", msg:" + error.message);
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);
188 messageService.loadMessageBody(foundMutableMessage, loadMutableSuccess, loadMutableError);
192 findMutableMessagesError = t.step_func(function (error) {
193 assert_unreached("findMessages() error callback: name:" + error.name + ", msg:" + error.message);
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);
202 messageService.loadMessageBody(foundConstMessage, loadConstSuccess, loadConstError);
206 findConstMessagesError = t.step_func(function (error) {
207 assert_unreached("findMessages() error callback: name:" + error.name + ", msg:" + error.message);
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);
216 constMessagefilter = new tizen.AttributeFilter("id", "EXACTLY", constMessage.id);
217 messageStorage.findMessages(constMessagefilter, findConstMessagesSuccess, findConstMessagesError);
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);
230 addDraftError = t.step_func(function (error) {
231 assert_unreached("addDraftMessage() error callback: name:" + error.name + ", msg:" + error.message);
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;
239 initDictForMutableMessage.plainBody = plainBodyToSetForMutableMesage;
240 mutableMessage = new tizen.Message("messaging.email", initDictForMutableMessage);
241 messageStorage.addDraftMessage(mutableMessage, addDraftSuccess, addDraftError);
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);
249 serviceError = t.step_func(function (error) {
250 assert_unreached("getMessageServices() error callback: name:" + error.name + ", msg:" + error.message);
252 tizen.messaging.getMessageServices("messaging.email", serviceSuccess, serviceError);