9a104bf8ebc9df6adb1c8c26a14d9606855e564d
[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_email_conversationsremoved</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_email_conversationsremoved
34 //==== LABEL Check if callback is called and if its arguments have proper type - MessageConversationsChangeCallback, conversationsremoved, email
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 180
38 //==== TIMEOUT 180
39 //==== TEST_CRITERIA CBOA CBT
40 setup({ timeout: 180000 });
41 var t = async_test("MessageConversationsChangeCallback_email_conversationsremoved", {timeout: 180000}),
42     serviceSuccess, serviceError, service, message, addDraftSuccess, addDraftError,
43     conversationFilter, findConversationSuccess, findConversationError, foundConversation, removeConversationError,
44     changeCallback, listenerId;
45
46 t.step(function () {
47     //cleanup after TC
48     add_result_callback(function () {
49         try {
50             service.messageStorage.removeChangeListener(listenerId);
51         } catch (err) {
52             // do nothing in case removeChangeListener throw an exception
53         }
54     });
55
56     changeCallback = {
57         conversationsremoved: t.step_func(function (removedConversations) {
58             assert_type(removedConversations, "array", "Not an array.");
59             assert_equals(removedConversations.length, 1, "Incorrect length of conversations.");
60             assert_equals(removedConversations[0].id, foundConversation.id, "Incorrect id of removed conversation.");
61
62             assert_own_property(removedConversations[0], "id", "id not present.");
63             assert_own_property(removedConversations[0], "type", "type not present.");
64             assert_own_property(removedConversations[0], "timestamp", "timestamp not present.");
65             assert_own_property(removedConversations[0], "messageCount", "messageCount not present.");
66             assert_own_property(removedConversations[0], "unreadMessages", "unreadMessages not present.");
67             assert_own_property(removedConversations[0], "preview", "preview not present.");
68             assert_own_property(removedConversations[0], "subject", "subject not present.");
69             assert_own_property(removedConversations[0], "isRead", "isRead not present.");
70             assert_own_property(removedConversations[0], "from", "from not present.");
71             assert_own_property(removedConversations[0], "to", "to not present.");
72             assert_own_property(removedConversations[0], "cc", "cc not present.");
73             assert_own_property(removedConversations[0], "bcc", "bcc not present.");
74             assert_own_property(removedConversations[0], "lastMessageId", "lastMessageId not present.");
75
76             t.done();
77         })
78     };
79
80     removeConversationError = t.step_func(function (error) {
81         assert_unreached("removeConversations() error callback: name:" + error.name + ", msg:" + error.message);
82     });
83
84     findConversationSuccess = t.step_func(function (conversations) {
85         assert_equals(conversations.length, 1, "Incorrect number of found conversations");
86         foundConversation = conversations[0];
87
88         listenerId = service.messageStorage.addConversationsChangeListener(changeCallback);
89         service.messageStorage.removeConversations([foundConversation], null, removeConversationError);
90     });
91
92     findConversationError = t.step_func(function (error) {
93         assert_unreached("findConversations() error callback: name:" + error.name + ", msg:" + error.message);
94     });
95
96     addDraftSuccess = t.step_func(function (recipients) {
97         conversationFilter = new tizen.AttributeFilter("id", "EXACTLY", message.conversationId);
98         service.messageStorage.findConversations(conversationFilter, findConversationSuccess, findConversationError);
99     });
100
101     addDraftError = t.step_func(function (error) {
102         assert_unreached("addDraftMessage() error callback: name:" + error.name + ", msg:" + error.message);
103     });
104
105     serviceSuccess = t.step_func(function (emailService) {
106         service = emailService;
107
108         message = createSimpleMessageTo(TEST_EMAIL_RECIPIENT_2);
109
110         service.messageStorage.addDraftMessage(message, addDraftSuccess, addDraftError);
111     });
112
113     serviceError = t.step_func(function (error) {
114         assert_unreached("getEmailService() error callback: name:" + error.name + ", msg:" + error.message);
115     });
116
117     getEmailService(t, serviceSuccess, serviceError);
118 });
119
120 </script>
121 </body>
122 </html>