ff5537e5ac56928d693cdf1ba261212b427bf875
[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_conversationsremoved_withoutfilter</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_conversationsremoved_withoutfilter
34 //==== LABEL Check if callback is called and if its arguments have proper type - MessageConversationsChangeCallback, conversationsremoved, sms
35 //==== SPEC Tizen Web API:Communication:Messaging:MessageConversationsChangeCallback:conversationsremoved 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_conversationsremoved_withoutfilter", {timeout: 90000}), changeCallback,
41     serviceSuccess, serviceError, service, message,
42     removeAllSuccess, sendSuccess, sendError, conversationChangeCB,
43     removeConversationError, removedConversationId;
44
45 t.step(function () {
46     add_result_callback(function (res) {
47         try {
48             service.messageStorage.removeChangeListener(watcherId);
49         } catch (err) {
50             // do nothing in case removeChangeListener throw an exception
51         }
52     });
53
54     removeConversationError = t.step_func(function (error) {
55         assert_unreached("removeConversations() error callback: name:" + error.name + ", msg:" + error.message);
56     });
57
58     conversationChangeCB = {
59         conversationsadded : t.step_func(function (conversations) {
60             assert_type(conversations, "array", "conversations");
61             assert_greater_than(conversations.length, 0, "Received empty conversations array");
62             for (var i in conversations) {
63                 if (conversations[i].id === message.conversationId) {
64                     removedConversationId = conversations[i].id;
65                     service.messageStorage.removeConversations([conversations[i]], null, removeConversationError);
66                     break;
67                 }
68             }
69         }),
70         conversationsremoved : t.step_func(function (conversations) {
71             assert_type(conversations, "array", "conversations");
72             assert_greater_than(conversations.length, 0, "Received empty conversations array");
73             t.done();
74         })
75     };
76
77     sendError = t.step_func(function (error) {
78         assert_unreached("sendMessage() error callback: name:" + error.name + ", msg:" + error.message);
79     });
80
81     removeAllSuccess = t.step_func(function () {
82         watcherId = service.messageStorage.addConversationsChangeListener(conversationChangeCB);
83
84         message = new tizen.Message("messaging.sms", smsMessageInitDict);
85         service.sendMessage(message, null, sendError);
86     });
87
88     serviceSuccess = t.step_func(function (services) {
89         assert_greater_than(services.length, 0, "Received empty services array");
90         service = services[0];
91         removeAllMessages(t, service, removeAllSuccess);
92     });
93
94     serviceError = t.step_func(function (error) {
95         assert_unreached("getMessageServices() error callback: name:" + error.name + ", msg:" + error.message);
96     });
97
98     tizen.messaging.getMessageServices("messaging.sms", serviceSuccess, serviceError);
99 });
100 </script>
101 </body>
102 </html>