48cad485cdf929bd6c6ec7fba97f521df9b54416
[test/tct/web/api.git] /
1 <!DOCTYPE html>
2 <!--
3 Copyright (c) 2013 Samsung Electronics Co., Ltd.
4
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
8
9     http://www.apache.org/licenses/LICENSE-2.0
10
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.
16
17
18 Authors:
19         Andrzej Krolikowski <a.krolikowsk@samsung.com>
20
21 -->
22 <html>
23 <head>
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>
28 </head>
29
30 <body>
31 <div id="log"></div>
32 <script>
33 //==== TEST: MessageStorage_sms_updateMessages_without_errorCallback
34 //==== LABEL Check if MessageStorage.updateMessages method works properly without errorCallback argument (sms)
35 //==== PRIORITY P1
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});
41
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;
52 t.step(function () {
53
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.");
58
59         assert_equals(messageToTest.from, originalMessage.from, type + " from attribute.");
60         assert_array_equals(messageToTest.to, originalMessage.to, type + " to attribute.");
61
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.");
66
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.");
72         } else {
73             assert_equals(messageToTest.timestamp, originalMessage.timestamp, type + " timestamp attribute.");
74         }
75
76         testMessageCounter++;
77         if (testMessageCounter === 2) {
78             t.done();
79         }
80     });
81
82     loadMutableSuccess = t.step_func(function (loadedMutableMessage) {
83         testMessage(loadedMutableMessage, mutableMessage, mutable);
84     });
85
86     loadMutableError = t.step_func(function (error) {
87         assert_unreached("loadMessageBody() error callback: name:" + error.name + ", msg:" + error.message);
88     });
89
90     loadConstSuccess = t.step_func(function (loadedConstMessage) {
91         testMessage(loadedConstMessage, constMessage, consts);
92     });
93
94     loadConstError = t.step_func(function (error) {
95         assert_unreached("loadMessageBody() error callback: name:" + error.name + ", msg:" + error.message);
96     });
97
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);
103         } else {
104             messageService.loadMessageBody(foundMutableMessage, loadMutableSuccess, loadMutableError);
105         }
106     });
107
108     findMutableMessagesError = t.step_func(function (error) {
109         assert_unreached("findMessages() error callback: name:" + error.name + ", msg:" + error.message);
110     });
111
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);
117         } else {
118             messageService.loadMessageBody(foundConstMessage, loadConstSuccess, loadConstError);
119         }
120     });
121
122     findConstMessagesError = t.step_func(function (error) {
123         assert_unreached("findMessages() error callback: name:" + error.name + ", msg:" + error.message);
124     });
125
126
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);
131
132         constMessagefilter = new tizen.AttributeFilter("id", "EXACTLY", constMessage.id);
133         messageStorage.findMessages(constMessagefilter, findConstMessagesSuccess, findConstMessagesError);
134     });
135
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);
143         }
144     });
145
146     addDraftError = t.step_func(function (error) {
147         assert_unreached("addDraftMessage() error callback: name:" + error.name + ", msg:" + error.message);
148     });
149
150     serviceSuccess = t.step_func(function (services) {
151         assert_greater_than(services.length, 0, "Received empty services array");
152
153         messageService = services[0];
154         messageStorage = messageService.messageStorage;
155
156         initDictForMutableMessage.plainBody = plainBodyToSetForMutableMessage;
157         mutableMessage = new tizen.Message("messaging.sms", initDictForMutableMessage);
158         messageStorage.addDraftMessage(mutableMessage, addDraftSuccess, addDraftError);
159
160         initDictForConstMessage.plainBody = plainBodyToSetForConstMessage;
161         constMessage = new tizen.Message("messaging.sms", initDictForConstMessage);
162         messageStorage.addDraftMessage(constMessage, addDraftSuccess, addDraftError);
163     });
164
165     serviceError = t.step_func(function (error) {
166         assert_unreached("getMessageServices() error callback: name:" + error.name + ", msg:" + error.message);
167     });
168     tizen.messaging.getMessageServices("messaging.sms", serviceSuccess, serviceError);
169 });
170
171 </script>
172 </body>
173 </html>