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="../resources/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 method updateMessages of MessageStorage (SMS) 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_sms_updateMessages_without_errorCallback", {timeout:90000});
43 var serviceSuccess, serviceError, messageService, messageStorage,
44 currentDate = new Date(), plainBodyToSet = currentDate.getTime().toString(),
45 mutableMessage, constMessage,
46 initDictForMutableMessage = smsMessageInitDict, initDictForConstMessage = smsMessageInitDict,
47 plainBodyToSetForMutableMessage = 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 testMessage, testMessageCounter = 0;
59 testMessage = t.step_func(function (messageToTest, originalMessage, type) {
60 assert_equals(messageToTest.id, originalMessage.id, type + " id attribute.");
61 assert_equals(messageToTest.folderId, originalMessage.folderId, type + " folderId attribute.");
62 assert_equals(messageToTest.type, originalMessage.type, type + " type attribute.");
64 assert_equals(messageToTest.from, originalMessage.from, type + " from attribute.");
65 assert_array_equals(messageToTest.to, originalMessage.to, type + " to attribute.");
67 assert_equals(messageToTest.body.messageId, originalMessage.body.messageId, type + " body.messageId attribute.");
68 assert_equals(messageToTest.body.messageId, originalMessage.id, type + " body.messageId attribute (with message.id).");
69 assert_equals(messageToTest.body.loaded, originalMessage.body.loaded, type + " body.loaded attribute.");
70 assert_equals(messageToTest.body.plainBody, originalMessage.body.plainBody, type + " body.plainBody attribute.");
72 assert_equals(messageToTest.isRead, originalMessage.isRead, type + " isRead attribute.");
73 assert_equals(messageToTest.messageStatus, originalMessage.messageStatus, type + " messageStatus attribute.");
74 assert_equals(messageToTest.inResponseTo, originalMessage.inResponseTo, type + " inResponseTo attribute.");
75 if (messageToTest.timestamp !== null && originalMessage.timestamp !== null) {
76 assert_equals(messageToTest.timestamp.getTime(), originalMessage.timestamp.getTime(), type + " timestamp attribute.");
78 assert_equals(messageToTest.timestamp, originalMessage.timestamp, type + " timestamp attribute.");
82 if (testMessageCounter === 2) {
87 loadMutableSuccess = t.step_func(function (loadedMutableMessage) {
88 testMessage(loadedMutableMessage, mutableMessage, mutable);
91 loadMutableError = t.step_func(function (error) {
92 assert_unreached("loadMessageBody() error callback: name:" + error.name + ", msg:" + error.message);
95 loadConstSuccess = t.step_func(function (loadedConstMessage) {
96 testMessage(loadedConstMessage, constMessage, consts);
99 loadConstError = t.step_func(function (error) {
100 assert_unreached("loadMessageBody() error callback: name:" + error.name + ", msg:" + error.message);
103 findMutableMessagesSuccess = t.step_func(function (mutableMessages) {
104 assert_equals(mutableMessages.length, 1, "incorrect number of messages.");
105 foundMutableMessage = mutableMessages[0];
106 if (foundMutableMessage.body.loaded) {
107 testMessage(foundMutableMessage, mutableMessage, mutable);
109 messageService.loadMessageBody(foundMutableMessage, loadMutableSuccess, loadMutableError);
113 findMutableMessagesError = t.step_func(function (error) {
114 assert_unreached("findMessages() error callback: name:" + error.name + ", msg:" + error.message);
117 findConstMessagesSuccess = t.step_func(function (constMessages) {
118 assert_equals(constMessages.length, 1, "incorrect number of messages.");
119 foundConstMessage = constMessages[0];
120 if (foundConstMessage.body.loaded) {
121 testMessage(foundConstMessage, constMessage, consts);
123 messageService.loadMessageBody(foundConstMessage, loadConstSuccess, loadConstError);
127 findConstMessagesError = t.step_func(function (error) {
128 assert_unreached("findMessages() error callback: name:" + error.name + ", msg:" + error.message);
132 updateSuccess = t.step_func(function () {
133 assert_equals(returnedValue, undefined, "Incorrect returned value from updateMessages");
134 mutableMessagefilter = new tizen.AttributeFilter("id", "EXACTLY", mutableMessage.id);
135 messageStorage.findMessages(mutableMessagefilter, findMutableMessagesSuccess, findMutableMessagesError);
137 constMessagefilter = new tizen.AttributeFilter("id", "EXACTLY", constMessage.id);
138 messageStorage.findMessages(constMessagefilter, findConstMessagesSuccess, findConstMessagesError);
141 addDraftSuccess = t.step_func(function () {
142 addDraftSuccessCounter++;
143 if (addDraftSuccessCounter === 2) {
144 mutableMessage.to = [TEST_SMS_RECIPIENT_2];
145 mutableMessage.body.plainBody = "new mutableMessage.plainBody";
146 mutableMessage.isRead = true;
147 returnedValue = messageStorage.updateMessages([mutableMessage, constMessage], updateSuccess);
151 addDraftError = t.step_func(function (error) {
152 assert_unreached("addDraftMessage() error callback: name:" + error.name + ", msg:" + error.message);
155 serviceSuccess = t.step_func(function (services) {
156 assert_greater_than(services.length, 0, "Received empty services array");
158 messageService = services[0];
159 messageStorage = messageService.messageStorage;
161 initDictForMutableMessage.plainBody = plainBodyToSetForMutableMessage;
162 mutableMessage = new tizen.Message("messaging.sms", initDictForMutableMessage);
163 messageStorage.addDraftMessage(mutableMessage, addDraftSuccess, addDraftError);
165 initDictForConstMessage.plainBody = plainBodyToSetForConstMessage;
166 constMessage = new tizen.Message("messaging.sms", initDictForConstMessage);
167 messageStorage.addDraftMessage(constMessage, addDraftSuccess, addDraftError);
170 serviceError = t.step_func(function (error) {
171 assert_unreached("getMessageServices() error callback: name:" + error.name + ", msg:" + error.message);
173 tizen.messaging.getMessageServices("messaging.sms", serviceSuccess, serviceError);