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="support/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 MessageStorage.updateMessages method works properly without errorCallback argument (email)
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 180
39 //==== TEST_CRITERIA MR MOA MAST
40 setup({timeout: 180000});
42 var t = async_test(document.title, {timeout: 180000});
44 var serviceSuccess, serviceError, service,
45 mutableMessage, constMessage,
46 plainBodyToSetForMutableMesage = MESSAGE_BODY_PLAIN + "_mutable",
47 plainBodyToSetForConstMessage = MESSAGE_BODY_PLAIN + "_const",
48 addDraftSuccess, addDraftError, addDraftSuccessCounter = 0, returnedValue = null,
49 updateSuccess, mutableMessagefilter, constMessagefilter,
50 findMutableMessagesSuccess, findMutableMessagesError, foundMutableMessage, mutable = "MUTABLE",
51 findConstMessagesSuccess, findConstMessagesError, foundConstMessage, consts = "CONST",
52 loadMutableSuccess, loadMutableError,
53 loadConstSuccess, loadConstError,
54 loadMutableAttachmentSuccess, loadMutableAttachmentError,
55 loadConstAttachmentSuccess, loadConstAttachmentError,
56 testMessage, testAttachment, testAttachmentCounter = 0;
58 testAttachment = t.step_func(function (attachment, type) {
59 var j, foundAttachmenentCounter = 0;
60 if (type === mutable) {
61 for (j = 0; j < mutableMessage.attachments.length; j++) {
62 if (attachment.id === mutableMessage.attachments[j].id) {
63 assert_equals(attachment.id, mutableMessage.attachments[j].id, type + " attachment.id");
64 assert_equals(attachment.messageId, mutableMessage.attachments[j].messageId, type + " attachment.messageId");
65 assert_equals(attachment.messageId, mutableMessage.id, type + " attachment.messageId (with message.id)");
66 assert_equals(attachment.mimeType, mutableMessage.attachments[j].mimeType, type + " attachment.mimeType");
67 assert_type(attachment.filePath, "string", type + " attachment.filePath is not a string");
68 assert_not_equals(attachment.filePath, "", type + " attachment.filePath is empty");
69 foundAttachmenentCounter++;
72 assert_equals(foundAttachmenentCounter, 1, type + " incorrect number of found attachement = " + foundAttachmenentCounter);
73 } else if (type === consts) {
74 for (j = 0; j < constMessage.attachments.length; j++) {
75 if (attachment.id === constMessage.attachments[j].id) {
76 assert_equals(attachment.id, constMessage.attachments[j].id, type + " attachment.id");
77 assert_equals(attachment.messageId, constMessage.attachments[j].messageId, type + " attachment.messageId");
78 assert_equals(attachment.messageId, constMessage.id, type + " attachment.messageId - (with message.id)");
79 assert_equals(attachment.mimeType, constMessage.attachments[j].mimeType, type + " attachment.mimeType");
80 assert_type(attachment.filePath, "string", type + " attachment.filePath is not a string");
81 assert_not_equals(attachment.filePath, "", type + " attachment.filePath is empty");
82 foundAttachmenentCounter++;
85 assert_equals(foundAttachmenentCounter, 1, type + " incorrect number of found attachement = " + foundAttachmenentCounter);
87 assert_unreached("FIX your test - unknown type = " + type);
90 testAttachmentCounter++;
91 if (testAttachmentCounter === mutableMessage.attachments.length + constMessage.attachments.length) {
96 loadMutableAttachmentSuccess = t.step_func(function (attachment) {
97 testAttachment(attachment, mutable);
100 loadMutableAttachmentError = t.step_func(function (error) {
101 assert_unreached("loadMessageAttachment() error callback: name:" + error.name + ", msg:" + error.message);
104 loadConstAttachmentSuccess = t.step_func(function (attachment) {
105 testAttachment(attachment, consts);
108 loadConstAttachmentError = t.step_func(function (error) {
109 assert_unreached("loadMessageAttachment() error callback: name:" + error.name + ", msg:" + error.message);
112 testMessage = t.step_func(function (messageToTest, originalMessage, type) {
114 assert_equals(messageToTest.id, originalMessage.id, type + " id attribute.");
115 assert_equals(messageToTest.folderId, originalMessage.folderId, type + " folderId attribute.");
116 assert_equals(messageToTest.type, originalMessage.type, type + " type attribute.");
118 assert_equals(messageToTest.from, originalMessage.from, type + " from attribute.");
119 assert_array_equals(messageToTest.to, originalMessage.to, type + " to attribute.");
120 assert_array_equals(messageToTest.cc, originalMessage.cc, type + " cc attribute.");
121 assert_array_equals(messageToTest.bcc, originalMessage.bcc, type + " bcc attribute.");
123 assert_equals(messageToTest.body.messageId, originalMessage.body.messageId, type + " body.messageId attribute.");
124 assert_equals(messageToTest.body.messageId, originalMessage.id, type + " body.messageId attribute (with message.id).");
125 assert_equals(messageToTest.body.loaded, originalMessage.body.loaded, type + " body.loaded attribute.");
126 assert_equals(messageToTest.body.plainBody, originalMessage.body.plainBody, type + " body.plainBody attribute.");
127 assert_equals(messageToTest.body.htmlBody, originalMessage.body.htmlBody, type + " body.htmlBody attribute.");
129 assert_equals(messageToTest.body.inlineAttachments.length, originalMessage.body.inlineAttachments.length, type + " incorrect length of inlineAttachments");
130 for (i = 0; i < originalMessage.body.inlineAttachments.length; i++) {
131 assert_equals(messageToTest.body.inlineAttachments[i].id, originalMessage.body.inlineAttachments[i].id, type + " message.body.inlineAttachments[" + i + "].id");
132 assert_equals(messageToTest.body.inlineAttachments[i].messageId, originalMessage.body.inlineAttachments[i].messageId, type + " message.body.inlineAttachments[" + i + "].messageId");
133 assert_equals(messageToTest.body.inlineAttachments[i].messageId, originalMessage.id, type + " message.body.inlineAttachments[" + i + "].messageId - (with message.id)");
134 assert_equals(messageToTest.body.inlineAttachments[i].mimeType, originalMessage.body.inlineAttachments[i].mimeType, type + " message.body.inlineAttachments[" + i + "].mimeType");
135 assert_type(messageToTest.body.inlineAttachments[i].filePath, "string", type + " attachment.filePath is not a string");
136 assert_not_equals(messageToTest.body.inlineAttachments[i].filePath, "", type + " attachment.filePath is empty");
139 assert_equals(messageToTest.isRead, originalMessage.isRead, type + " isRead attribute.");
140 assert_equals(messageToTest.hasAttachment, originalMessage.hasAttachment, type + " hasAttachment attribute.");
141 assert_equals(messageToTest.isHighPriority, originalMessage.isHighPriority, type + " isHighPriority attribute.");
142 assert_equals(messageToTest.subject, originalMessage.subject, type + " subject attribute.");
143 assert_equals(messageToTest.messageStatus, originalMessage.messageStatus, type + " messageStatus attribute.");
144 assert_equals(messageToTest.inResponseTo, originalMessage.inResponseTo, type + " inResponseTo attribute.");
145 if (messageToTest.timestamp !== null && originalMessage.timestamp !== null) {
146 assert_equals(messageToTest.timestamp.getTime(), originalMessage.timestamp.getTime(), type + " timestamp attribute.");
148 assert_equals(messageToTest.timestamp, originalMessage.timestamp, type + " timestamp attribute.");
150 assert_equals(messageToTest.conversationId, originalMessage.conversationId, type + " conversationId attribute.");
152 assert_equals(messageToTest.attachments.length, originalMessage.attachments.length, type + " incorrect length of attachments");
153 for (i = 0; i < messageToTest.attachments.length; i++) {
154 if (type === mutable) {
155 service.loadMessageAttachment(messageToTest.attachments[i], loadMutableAttachmentSuccess, loadMutableAttachmentError);
156 } else if (type === consts) {
157 service.loadMessageAttachment(messageToTest.attachments[i], loadConstAttachmentSuccess, loadConstAttachmentError);
159 assert_unreached("FIX your test - unknown type = " + type);
164 loadMutableSuccess = t.step_func(function (loadedMutableMessage) {
165 testMessage(loadedMutableMessage, mutableMessage, mutable);
168 loadMutableError = t.step_func(function (error) {
169 assert_unreached("loadMessageBody() error callback: name:" + error.name + ", msg:" + error.message);
172 loadConstSuccess = t.step_func(function (loadedConstMessage) {
173 testMessage(loadedConstMessage, constMessage, consts);
176 loadConstError = t.step_func(function (error) {
177 assert_unreached("loadMessageBody() error callback: name:" + error.name + ", msg:" + error.message);
180 findMutableMessagesSuccess = t.step_func(function (mutableMessages) {
181 assert_draft_message_equals(t, mutableMessages, mutableMessage);
182 foundMutableMessage = mutableMessages[0];
183 if (foundMutableMessage.body.loaded) {
184 testMessage(foundMutableMessage, mutableMessage, mutable);
186 service.loadMessageBody(foundMutableMessage, loadMutableSuccess, loadMutableError);
190 findMutableMessagesError = t.step_func(function (error) {
191 assert_unreached("findMessages() error callback: name:" + error.name + ", msg:" + error.message);
194 findConstMessagesSuccess = t.step_func(function (constMessages) {
195 assert_draft_message_equals(t, constMessages, constMessage);
197 foundConstMessage = constMessages[0];
198 if (foundConstMessage.body.loaded) {
199 testMessage(foundConstMessage, constMessage, consts);
201 service.loadMessageBody(foundConstMessage, loadConstSuccess, loadConstError);
205 findConstMessagesError = t.step_func(function (error) {
206 assert_unreached("findMessages() error callback: name:" + error.name + ", msg:" + error.message);
210 updateSuccess = t.step_func(function () {
211 assert_equals(returnedValue, undefined, "Incorrect returned value from updateMessages");
212 mutableMessagefilter = new tizen.AttributeFilter("id", "EXACTLY", mutableMessage.id);
213 service.messageStorage.findMessages(mutableMessagefilter, findMutableMessagesSuccess, findMutableMessagesError);
215 constMessagefilter = new tizen.AttributeFilter("id", "EXACTLY", constMessage.id);
216 service.messageStorage.findMessages(constMessagefilter, findConstMessagesSuccess, findConstMessagesError);
219 addDraftSuccess = t.step_func(function () {
220 addDraftSuccessCounter++;
221 if (addDraftSuccessCounter === 2) {
222 mutableMessage.isRead = true;
223 mutableMessage.isHighPriority = true;
224 mutableMessage.subject = "new mutableMessage.subject";
225 returnedValue = service.messageStorage.updateMessages([mutableMessage, constMessage], updateSuccess);
229 addDraftError = t.step_func(function (error) {
230 assert_unreached("addDraftMessage() error callback: name:" + error.name + ", msg:" + error.message);
233 serviceSuccess = t.step_func(function (emailService) {
234 service = emailService;
236 mutableMessage = new tizen.Message("messaging.email", {
237 subject: generateSubject(),
238 to: [TEST_EMAIL_RECIPIENT_2],
239 plainBody: plainBodyToSetForMutableMesage,
240 htmlBody: MESSAGE_BODY_HTML,
241 isHighPriority: false
244 service.messageStorage.addDraftMessage(mutableMessage, addDraftSuccess, addDraftError);
246 constMessage = new tizen.Message("messaging.email", {
247 subject: generateSubject(),
248 to: [TEST_EMAIL_RECIPIENT_2],
249 plainBody: plainBodyToSetForConstMessage,
250 htmlBody: MESSAGE_BODY_HTML,
251 isHighPriority: false
254 constMessage.attachments = [
255 new tizen.MessageAttachment(MESSAGE_ATTACHMENT_SOUND_PATH, MESSAGE_ATTACHMENT_SOUND_MIME_TYPE),
256 new tizen.MessageAttachment(MESSAGE_ATTACHMENT_IMAGE_PATH, MESSAGE_ATTACHMENT_IMAGE_MIME_TYPE)
259 service.messageStorage.addDraftMessage(constMessage, addDraftSuccess, addDraftError);
262 serviceError = t.step_func(function (error) {
263 assert_unreached("getEmailService() error callback: name:" + error.name + ", msg:" + error.message);
266 getEmailService(t, serviceSuccess, serviceError);