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_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>
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});
41 var t = async_test("MessageStorage_mms_updateMessages_without_errorCallback", {timeout:90000});
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",
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;
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++;
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++;
86 assert_equals(foundAttachmenentCounter, 1, type + " incorrect number of found attachement = " + foundAttachmenentCounter);
88 assert_unreached("FIX your test - unknown type = " + type);
91 testAttachmentCounter++;
92 if (testAttachmentCounter === mutableMessage.attachments.length + constMessage.attachments.length) {
97 loadMutableAttachmentSuccess = t.step_func(function (attachment) {
98 testAttachment(attachment, mutable);
101 loadMutableAttachmentError = t.step_func(function (error) {
102 assert_unreached("loadMessageAttachment() error callback: name:" + error.name + ", msg:" + error.message);
105 loadConstAttachmentSuccess = t.step_func(function (attachment) {
106 testAttachment(attachment, consts);
109 loadConstAttachmentError = t.step_func(function (error) {
110 assert_unreached("loadMessageAttachment() error callback: name:" + error.name + ", msg:" + error.message);
113 testMessage = t.step_func(function (messageToTest, originalMessage, type) {
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.");
119 assert_equals(messageToTest.from, originalMessage.from, type + " from attribute.");
120 assert_array_equals(messageToTest.to, originalMessage.to, type + " to attribute.");
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.");
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.");
135 assert_equals(messageToTest.timestamp, originalMessage.timestamp, type + " timestamp attribute.");
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);
145 assert_unreached("FIX your test - unknown type = " + type);
150 loadMutableSuccess = t.step_func(function (loadedMutableMessage) {
151 testMessage(loadedMutableMessage, mutableMessage, mutable);
154 loadMutableError = t.step_func(function (error) {
155 assert_unreached("loadMessageBody() error callback: name:" + error.name + ", msg:" + error.message);
158 loadConstSuccess = t.step_func(function (loadedConstMessage) {
159 testMessage(loadedConstMessage, constMessage, consts);
162 loadConstError = t.step_func(function (error) {
163 assert_unreached("loadMessageBody() error callback: name:" + error.name + ", msg:" + error.message);
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);
172 messageService.loadMessageBody(foundMutableMessage, loadMutableSuccess, loadMutableError);
176 findMutableMessagesError = t.step_func(function (error) {
177 assert_unreached("findMessages() error callback: name:" + error.name + ", msg:" + error.message);
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);
186 messageService.loadMessageBody(foundConstMessage, loadConstSuccess, loadConstError);
190 findConstMessagesError = t.step_func(function (error) {
191 assert_unreached("findMessages() error callback: name:" + error.name + ", msg:" + error.message);
195 updateSuccess = t.step_func(function () {
196 assert_equals(returnedValue, undefined, "Incorrect returned value from updateMessages");
198 mutableMessagefilter = new tizen.AttributeFilter("id", "EXACTLY", mutableMessage.id);
199 messageStorage.findMessages(mutableMessagefilter, findMutableMessagesSuccess, findMutableMessagesError);
201 constMessagefilter = new tizen.AttributeFilter("id", "EXACTLY", constMessage.id);
202 messageStorage.findMessages(constMessagefilter, findConstMessagesSuccess, findConstMessagesError);
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")];
215 returnedValue = messageStorage.updateMessages([mutableMessage, constMessage], updateSuccess);
219 addDraftError = t.step_func(function (error) {
220 assert_unreached("addDraftMessage() error callback: name:" + error.name + ", msg:" + error.message);
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;
228 initDictForMutableMessage.plainBody = plainBodyToSetForMutableMesage;
229 mutableMessage = new tizen.Message("messaging.mms", initDictForMutableMessage);
230 messageStorage.addDraftMessage(mutableMessage, addDraftSuccess, addDraftError);
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);
239 serviceError = t.step_func(function (error) {
240 assert_unreached("getMessageServices() error callback: name:" + error.name + ", msg:" + error.message);
242 tizen.messaging.getMessageServices("messaging.mms", serviceSuccess, serviceError);