2e1343d5cc8e46ae8ac9b36f7f23107bf65c79be
[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_conversationsupdated</title>
25 <meta charset="utf-8"/>
26 <script type="text/javascript" src="support/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_conversationsupdated
34 //==== LABEL Check if callback is called and if its arguments have proper type - MessageConversationsChangeCallback, conversationsupdated, email
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 180
38 //==== TIMEOUT 180
39 //==== TEST_CRITERIA CBT CBOA
40 setup({timeout: 180000});
41 var t = async_test(document.title, {timeout: 180000}),
42     serviceSuccess, serviceError, messageService, messageStorage, message, i,
43     addDraftSuccess, addDraftError, updateError, oldTimestamp, changeCallback, listenerId;
44
45 t.step(function () {
46
47     //cleanup after TC
48     add_result_callback(function () {
49         try {
50             messageStorage.removeChangeListener(listenerId);
51         } catch (err) {
52             // do nothing in case removeChangeListener throw an exception
53         }
54     });
55
56     changeCallback = {
57         conversationsupdated: t.step_func(function (updatedConversations) {
58             assert_type(updatedConversations, "array", "Not an array");
59             assert_greater_than(updatedConversations.length, 0, "Received empty conversations array");
60
61             for (i = 0; i < updatedConversations.length; i++) {
62                 if (updatedConversations[i].id === message.conversationId) {
63                     check_readonly(updatedConversations[i], "id", updatedConversations[i].id, "string", "dummyValue");
64                     check_readonly(updatedConversations[i], "type", "messaging.email", "string", "dummyValue");
65                     assert_true(updatedConversations[i].timestamp instanceof Date, "Not a date");
66                     oldTimestamp = updatedConversations[i].timestamp;
67                     updatedConversations[i].timestamp = new Date();
68                     assert_equals(updatedConversations[i].timestamp.getTime(), oldTimestamp.getTime(), "timestamp modified");
69                     check_readonly(updatedConversations[i], "messageCount", updatedConversations[i].messageCount, "number", 123);
70                     check_readonly(updatedConversations[i], "unreadMessages", updatedConversations[i].unreadMessages, "number", 123);
71                     check_readonly(updatedConversations[i], "preview", updatedConversations[i].preview, "string", "dummyValue");
72                     check_readonly(updatedConversations[i], "subject", message.subject, "string", "dummyValue");
73                     check_readonly(updatedConversations[i], "isRead", updatedConversations[i].isRead, "boolean", "dummyValue");
74                     check_readonly(updatedConversations[i], "from", TEST_EMAIL_RECIPIENT_1, "string", "dummyValue");
75                     assert_array_equals(updatedConversations[i].to, message.to, "to incorrect");
76                     assert_array_equals(updatedConversations[i].cc, message.cc, "cc incorrect");
77                     assert_array_equals(updatedConversations[i].bcc, message.bcc, "bcc incorrect");
78                     check_readonly(updatedConversations[i], "lastMessageId", message.id, "string", "dummyValue");
79
80                     t.done();
81                     break;
82                 }
83             }
84         })
85     };
86
87     updateError = t.step_func(function (error) {
88         assert_unreached("updateMessages() error callback: name:" + error.name + ", msg:" + error.message);
89     });
90
91     addDraftSuccess = t.step_func(function () {
92         listenerId = messageStorage.addConversationsChangeListener(changeCallback);
93
94         message.subject = generateSubject();
95         messageStorage.updateMessages([message], null, updateError);
96     });
97
98     addDraftError = t.step_func(function (error) {
99         assert_unreached("addDraftMessage() error callback: name:" + error.name + ", msg:" + error.message);
100     });
101
102     serviceSuccess = t.step_func(function (service) {
103         messageService = service;
104         messageStorage = messageService.messageStorage;
105
106         message = createSimpleMessageTo(TEST_EMAIL_RECIPIENT_2);
107         messageStorage.addDraftMessage(message, addDraftSuccess, addDraftError);
108     });
109
110     serviceError = t.step_func(function (error) {
111         assert_unreached("getEmailService() error callback: name:" + error.name + ", msg:" + error.message);
112     });
113
114     getEmailService(t, serviceSuccess, serviceError);
115 });
116
117 </script>
118 </body>
119 </html>