e31fb0aad78e2c2937f93c89f13e7588c8b5cb45
[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="../resources/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 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});
40
41 var t = async_test("MessageStorage_sms_updateMessages_without_errorCallback", {timeout:90000});
42 t.step(function () {
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",
48
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;
56
57
58
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.");
63
64         assert_equals(messageToTest.from, originalMessage.from, type + " from attribute.");
65         assert_array_equals(messageToTest.to, originalMessage.to, type + " to attribute.");
66
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.");
71
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.");
77         } else {
78             assert_equals(messageToTest.timestamp, originalMessage.timestamp, type + " timestamp attribute.");
79         }
80
81         testMessageCounter++;
82         if (testMessageCounter === 2) {
83             t.done();
84         }
85     });
86
87     loadMutableSuccess = t.step_func(function (loadedMutableMessage) {
88         testMessage(loadedMutableMessage, mutableMessage, mutable);
89     });
90
91     loadMutableError = t.step_func(function (error) {
92         assert_unreached("loadMessageBody() error callback: name:" + error.name + ", msg:" + error.message);
93     });
94
95     loadConstSuccess = t.step_func(function (loadedConstMessage) {
96         testMessage(loadedConstMessage, constMessage, consts);
97     });
98
99     loadConstError = t.step_func(function (error) {
100         assert_unreached("loadMessageBody() error callback: name:" + error.name + ", msg:" + error.message);
101     });
102
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);
108         } else {
109             messageService.loadMessageBody(foundMutableMessage, loadMutableSuccess, loadMutableError);
110         }
111     });
112
113     findMutableMessagesError = t.step_func(function (error) {
114         assert_unreached("findMessages() error callback: name:" + error.name + ", msg:" + error.message);
115     });
116
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);
122         } else {
123             messageService.loadMessageBody(foundConstMessage, loadConstSuccess, loadConstError);
124         }
125     });
126
127     findConstMessagesError = t.step_func(function (error) {
128         assert_unreached("findMessages() error callback: name:" + error.name + ", msg:" + error.message);
129     });
130
131
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);
136
137         constMessagefilter = new tizen.AttributeFilter("id", "EXACTLY", constMessage.id);
138         messageStorage.findMessages(constMessagefilter, findConstMessagesSuccess, findConstMessagesError);
139     });
140
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);
148         }
149     });
150
151     addDraftError = t.step_func(function (error) {
152         assert_unreached("addDraftMessage() error callback: name:" + error.name + ", msg:" + error.message);
153     });
154
155     serviceSuccess = t.step_func(function (services) {
156         assert_greater_than(services.length, 0, "Received empty services array");
157
158         messageService = services[0];
159         messageStorage = messageService.messageStorage;
160
161         initDictForMutableMessage.plainBody = plainBodyToSetForMutableMessage;
162         mutableMessage = new tizen.Message("messaging.sms", initDictForMutableMessage);
163         messageStorage.addDraftMessage(mutableMessage, addDraftSuccess, addDraftError);
164
165         initDictForConstMessage.plainBody = plainBodyToSetForConstMessage;
166         constMessage = new tizen.Message("messaging.sms", initDictForConstMessage);
167         messageStorage.addDraftMessage(constMessage, addDraftSuccess, addDraftError);
168     });
169
170     serviceError = t.step_func(function (error) {
171         assert_unreached("getMessageServices() error callback: name:" + error.name + ", msg:" + error.message);
172     });
173     tizen.messaging.getMessageServices("messaging.sms", serviceSuccess, serviceError);
174 });
175
176 </script>
177 </body>
178 </html>