7dc11d31b5d13dff31b15f9842bd42cceae6fcb5
[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 lang="en">
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/index.jsp?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}), changeCallback,
42     serviceSuccess, serviceError, messageService, messageStorage,
43     currentDate = new Date(), subjectToSet = currentDate.getTime().toString(),
44     initDict = emailMessageInitDict, sendMessage,
45     sendSuccess, sendError, messageFilter,
46     findMessageSuccess, findMessageError, foundMessage, conversationFilter,
47     findConversationSuccess, findConversationError, foundConversation, listenerId,
48     removeConversationError;
49 initDict.to = [TEST_EMAIL_RECIPIENT_2];
50 initDict.cc = [TEST_EMAIL_RECIPIENT_2];
51 initDict.bcc = [TEST_EMAIL_RECIPIENT_2];
52
53 t.step(function () {
54     //cleanup after TC
55     add_result_callback(function () {
56         try {
57             messageStorage.removeChangeListener(listenerId);
58         } catch (err) {
59             // do nothing in case removeChangeListener throw an exception
60         }
61     });
62
63     changeCallback = {
64         conversationsadded: t.step_func(function (addedConversations) {
65             assert_unreached("conversationsadded invoked");
66         }),
67         conversationsupdated: t.step_func(function (updatedConversations) {
68             assert_unreached("conversationsupdated invoked");
69         }),
70         conversationsremoved: t.step_func(function (removedConversations) {
71             assert_type(removedConversations, "array", "Not an array.");
72             assert_equals(removedConversations.length, 1, "Incorrect length of conversations.");
73
74             assert_own_property(removedConversations[0], "id", "id not present.");
75             assert_own_property(removedConversations[0], "type", "type not present.");
76             assert_own_property(removedConversations[0], "timestamp", "timestamp not present.");
77             assert_own_property(removedConversations[0], "messageCount", "messageCount not present.");
78             assert_own_property(removedConversations[0], "unreadMessages", "unreadMessages not present.");
79             assert_own_property(removedConversations[0], "preview", "preview not present.");
80             assert_own_property(removedConversations[0], "subject", "subject not present.");
81             assert_own_property(removedConversations[0], "isRead", "isRead not present.");
82             assert_own_property(removedConversations[0], "from", "from not present.");
83             assert_own_property(removedConversations[0], "to", "to not present.");
84             assert_own_property(removedConversations[0], "cc", "cc not present.");
85             assert_own_property(removedConversations[0], "bcc", "bcc not present.");
86             assert_own_property(removedConversations[0], "lastMessageId", "lastMessageId not present.");
87
88             t.done();
89         })
90     };
91
92     removeConversationError = t.step_func(function (error) {
93         assert_unreached("removeConversations() error callback: name:" + error.name + ", msg:" + error.message);
94     });
95
96     findConversationSuccess = t.step_func(function (conversations) {
97         assert_equals(conversations.length, 1, "Incorrect number of found conversations");
98         foundConversation = conversations[0];
99
100         listenerId = messageStorage.addConversationsChangeListener(changeCallback);
101         messageStorage.removeConversations([foundConversation], null, removeConversationError);
102     });
103
104     findConversationError = t.step_func(function (error) {
105         assert_unreached("findConversations() error callback: name:" + error.name + ", msg:" + error.message);
106     });
107
108     findMessageSuccess = t.step_func(function (messages) {
109         assert_equals(messages.length, 1, "Incorrect number of found messages");
110         foundMessage = messages[0];
111
112         conversationFilter = new tizen.AttributeFilter("id", "EXACTLY", foundMessage.conversationId);
113         messageStorage.findConversations(conversationFilter, findConversationSuccess, findConversationError);
114     });
115
116     findMessageError = t.step_func(function (error) {
117         assert_unreached("findFolders() error callback: name:" + error.name + ", msg:" + error.message);
118     });
119
120     sendSuccess = t.step_func(function (recipients) {
121         messageFilter = new tizen.AttributeFilter("id", "EXACTLY", sendMessage.id);
122         messageStorage.findMessages(messageFilter, findMessageSuccess, findMessageError);
123     });
124
125     sendError = t.step_func(function (error) {
126         assert_unreached("sendMessage() error callback: name:" + error.name + ", msg:" + error.message);
127     });
128
129     serviceSuccess = t.step_func(function (services) {
130         assert_true(services.length > 0, "Received empty services array");
131         messageService = services[0];
132         messageStorage = messageService.messageStorage;
133
134         initDict.subject = subjectToSet;
135         sendMessage = new tizen.Message("messaging.email", initDict);
136         requestMessageSending(t, messageService, sendMessage, sendSuccess, sendError);
137     });
138
139     serviceError = t.step_func(function (error) {
140         assert_unreached("getMessageServices() error callback: name:" + error.name + ", msg:" + error.message);
141     });
142
143     tizen.messaging.getMessageServices("messaging.email", serviceSuccess, serviceError);
144 });
145
146 </script>
147 </body>
148 </html>