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_sms_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_sms_updateMessages_without_errorCallback
34 //==== LABEL Check if MessageStorage.updateMessages method works properly without errorCallback argument (sms)
36 //==== SPEC Tizen Web API:Communication:Messaging:MessageStorage:updateMessages M
37 //==== SPEC_URL https://developer.tizen.org/help/topic/org.tizen.web.device.apireference/tizen/messaging.html
38 //==== ONLOAD_DELAY 90
39 //==== TEST_CRITERIA MR MOA MAST
40 setup({timeout: 90000});
42 var t = async_test(document.title, {timeout: 90000}), serviceSuccess, serviceError, messageService, messageStorage,
43 currentDate = new Date(), plainBodyToSet = currentDate.getTime().toString(), mutableMessage, constMessage,
44 smsMessageInitDict = { to: [TEST_SMS_RECIPIENT], plainBody: generatePlainBody() },
45 initDictForMutableMessage = smsMessageInitDict, initDictForConstMessage = smsMessageInitDict,
46 plainBodyToSetForMutableMessage = plainBodyToSet + "_mutable", plainBodyToSetForConstMessage = plainBodyToSet + "_const",
47 addDraftSuccess, addDraftError, addDraftSuccessCounter = 0,
48 returnedValue = null, updateSuccess, mutableMessagefilter, constMessagefilter, findMutableMessagesSuccess,
49 findMutableMessagesError, foundMutableMessage, mutable = "MUTABLE", findConstMessagesSuccess, findConstMessagesError,
50 foundConstMessage, consts = "CONST", loadMutableSuccess, loadMutableError, loadConstSuccess, loadConstError,
51 testMessage, testMessageCounter = 0;
54 testMessage = t.step_func(function (messageToTest, originalMessage, type) {
55 assert_equals(messageToTest.id, originalMessage.id, type + " id attribute.");
56 assert_equals(messageToTest.folderId, originalMessage.folderId, type + " folderId attribute.");
57 assert_equals(messageToTest.type, originalMessage.type, type + " type attribute.");
59 assert_equals(messageToTest.from, originalMessage.from, type + " from attribute.");
60 assert_array_equals(messageToTest.to, originalMessage.to, type + " to attribute.");
62 assert_equals(messageToTest.body.messageId, originalMessage.body.messageId, type + " body.messageId attribute.");
63 assert_equals(messageToTest.body.messageId, originalMessage.id, type + " body.messageId attribute (with message.id).");
64 assert_equals(messageToTest.body.loaded, originalMessage.body.loaded, type + " body.loaded attribute.");
65 assert_equals(messageToTest.body.plainBody, originalMessage.body.plainBody, type + " body.plainBody attribute.");
67 assert_equals(messageToTest.isRead, originalMessage.isRead, type + " isRead attribute.");
68 assert_equals(messageToTest.messageStatus, originalMessage.messageStatus, type + " messageStatus attribute.");
69 assert_equals(messageToTest.inResponseTo, originalMessage.inResponseTo, type + " inResponseTo attribute.");
70 if (messageToTest.timestamp !== null && originalMessage.timestamp !== null) {
71 assert_equals(messageToTest.timestamp.getTime(), originalMessage.timestamp.getTime(), type + " timestamp attribute.");
73 assert_equals(messageToTest.timestamp, originalMessage.timestamp, type + " timestamp attribute.");
77 if (testMessageCounter === 2) {
82 loadMutableSuccess = t.step_func(function (loadedMutableMessage) {
83 testMessage(loadedMutableMessage, mutableMessage, mutable);
86 loadMutableError = t.step_func(function (error) {
87 assert_unreached("loadMessageBody() error callback: name:" + error.name + ", msg:" + error.message);
90 loadConstSuccess = t.step_func(function (loadedConstMessage) {
91 testMessage(loadedConstMessage, constMessage, consts);
94 loadConstError = t.step_func(function (error) {
95 assert_unreached("loadMessageBody() error callback: name:" + error.name + ", msg:" + error.message);
98 findMutableMessagesSuccess = t.step_func(function (mutableMessages) {
99 assert_equals(mutableMessages.length, 1, "incorrect number of messages.");
100 foundMutableMessage = mutableMessages[0];
101 if (foundMutableMessage.body.loaded) {
102 testMessage(foundMutableMessage, mutableMessage, mutable);
104 messageService.loadMessageBody(foundMutableMessage, loadMutableSuccess, loadMutableError);
108 findMutableMessagesError = t.step_func(function (error) {
109 assert_unreached("findMessages() error callback: name:" + error.name + ", msg:" + error.message);
112 findConstMessagesSuccess = t.step_func(function (constMessages) {
113 assert_equals(constMessages.length, 1, "incorrect number of messages.");
114 foundConstMessage = constMessages[0];
115 if (foundConstMessage.body.loaded) {
116 testMessage(foundConstMessage, constMessage, consts);
118 messageService.loadMessageBody(foundConstMessage, loadConstSuccess, loadConstError);
122 findConstMessagesError = t.step_func(function (error) {
123 assert_unreached("findMessages() error callback: name:" + error.name + ", msg:" + error.message);
127 updateSuccess = t.step_func(function () {
128 assert_equals(returnedValue, undefined, "Incorrect returned value from updateMessages");
129 mutableMessagefilter = new tizen.AttributeFilter("id", "EXACTLY", mutableMessage.id);
130 messageStorage.findMessages(mutableMessagefilter, findMutableMessagesSuccess, findMutableMessagesError);
132 constMessagefilter = new tizen.AttributeFilter("id", "EXACTLY", constMessage.id);
133 messageStorage.findMessages(constMessagefilter, findConstMessagesSuccess, findConstMessagesError);
136 addDraftSuccess = t.step_func(function () {
137 addDraftSuccessCounter++;
138 if (addDraftSuccessCounter === 2) {
139 mutableMessage.to = [TEST_SMS_RECIPIENT_2];
140 mutableMessage.body.plainBody = "new mutableMessage.plainBody";
141 mutableMessage.isRead = true;
142 returnedValue = messageStorage.updateMessages([mutableMessage, constMessage], updateSuccess);
146 addDraftError = t.step_func(function (error) {
147 assert_unreached("addDraftMessage() error callback: name:" + error.name + ", msg:" + error.message);
150 serviceSuccess = t.step_func(function (services) {
151 assert_greater_than(services.length, 0, "Received empty services array");
153 messageService = services[0];
154 messageStorage = messageService.messageStorage;
156 initDictForMutableMessage.plainBody = plainBodyToSetForMutableMessage;
157 mutableMessage = new tizen.Message("messaging.sms", initDictForMutableMessage);
158 messageStorage.addDraftMessage(mutableMessage, addDraftSuccess, addDraftError);
160 initDictForConstMessage.plainBody = plainBodyToSetForConstMessage;
161 constMessage = new tizen.Message("messaging.sms", initDictForConstMessage);
162 messageStorage.addDraftMessage(constMessage, addDraftSuccess, addDraftError);
165 serviceError = t.step_func(function (error) {
166 assert_unreached("getMessageServices() error callback: name:" + error.name + ", msg:" + error.message);
168 tizen.messaging.getMessageServices("messaging.sms", serviceSuccess, serviceError);