7f83fb374280df897f14e2cd34bf0bbcbeab5f43
[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>MessageConversationsChangeCallback_sms_conversationsupdated</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: MessageConversationsChangeCallback_sms_conversationsupdated
34 //==== LABEL Check if callback is called and if its arguments have proper type - MessageConversationsChangeCallback, conversationsupdated, sms
35 //==== SPEC Tizen Web API:Communication:Messaging:MessageConversationsChangeCallback:conversationsupdated 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 CBOA
39 setup({ timeout: 90000 });
40 var t = async_test("MessageConversationsChangeCallback_sms_conversationsupdated", {timeout: 90000}), changeCallback,
41     serviceSuccess, serviceError, messageService, messageStorage, listenerId,
42     initDict = smsMessageInitDict, addDraftMessage1st, addDraftMessage2nd,
43     addSuccess1st, addError1st, addError2nd, timestampBeforeChange;
44
45 t.step(function () {
46     //cleanup after TC
47     add_result_callback(function () {
48         try {
49             messageStorage.removeChangeListener(listenerId);
50         } catch (err) {
51             // do nothing in case removeChangeListener throw an exception
52         }
53     });
54
55     changeCallback = {
56         conversationsadded: t.step_func(function (addedConversations) {
57             assert_unreached("conversationsadded invoked");
58         }),
59         conversationsupdated: t.step_func(function (updatedConversations) {
60             assert_equals(updatedConversations.length, 1, "Incorrect length of conversations.");
61             check_readonly(updatedConversations[0], "id", updatedConversations[0].id, "string", "dummyValue");
62             check_readonly(updatedConversations[0], "type", "messaging.sms", "string", "dummyValue");
63             assert_true(updatedConversations[0].timestamp instanceof Date, "Not a date");
64             timestampBeforeChange = updatedConversations[0].timestamp.getTime();
65             updatedConversations[0].timestamp = new Date();
66             assert_equals(updatedConversations[0].timestamp.getTime(), timestampBeforeChange, "timestamp modified");
67             check_readonly(updatedConversations[0], "messageCount", updatedConversations[0].messageCount, "number", 123);
68             check_readonly(updatedConversations[0], "unreadMessages", updatedConversations[0].unreadMessages, "number", 123);
69             check_readonly(updatedConversations[0], "preview", updatedConversations[0].preview, "string", "dummyValue");
70             check_readonly(updatedConversations[0], "isRead", updatedConversations[0].isRead, "boolean", "dummyValue");
71             check_readonly(updatedConversations[0], "lastMessageId", updatedConversations[0].lastMessageId, "string", "dummyValue");
72             t.done();
73         }),
74         conversationsremoved: t.step_func(function (removedConversations) {
75             assert_unreached("conversationsremoved invoked");
76         })
77     };
78
79     addError2nd = t.step_func(function (error) {
80         assert_unreached("addDraftMessage() error callback: name:" + error.name + ", msg:" + error.message);
81     });
82
83     addSuccess1st = t.step_func(function () {
84         listenerId = messageStorage.addConversationsChangeListener(changeCallback);
85
86         addDraftMessage2nd = new tizen.Message("messaging.sms", initDict);
87         messageService.messageStorage.addDraftMessage(addDraftMessage2nd, function (){}, addError2nd);
88     });
89
90     addError1st = t.step_func(function (error) {
91         assert_unreached("addDraftMessage() error callback: name:" + error.name + ", msg:" + error.message);
92     });
93
94     serviceSuccess = t.step_func(function (services) {
95         assert_greater_than(services.length, 0, "Received empty services array");
96         messageService = services[0];
97         messageStorage = messageService.messageStorage;
98
99         addDraftMessage1st = new tizen.Message("messaging.sms", initDict);
100         messageService.messageStorage.addDraftMessage(addDraftMessage1st, addSuccess1st, addError1st);
101     });
102
103     serviceError = t.step_func(function (error) {
104         assert_unreached("getMessageServices() error callback: name:" + error.name + ", msg:" + error.message);
105     });
106
107     tizen.messaging.getMessageServices("messaging.sms", serviceSuccess, serviceError);
108 });
109
110 </script>
111 </body>
112 </html>