3 Copyright (c) 2013 Samsung Electronics Co., Ltd.
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
9 http://www.apache.org/licenses/LICENSE-2.0
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.
19 Andrzej Krolikowski <a.krolikowsk@samsung.com>
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>
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
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;
48 add_result_callback(function () {
50 messageStorage.removeChangeListener(listenerId);
52 // do nothing in case removeChangeListener throw an exception
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");
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");
87 updateError = t.step_func(function (error) {
88 assert_unreached("updateMessages() error callback: name:" + error.name + ", msg:" + error.message);
91 addDraftSuccess = t.step_func(function () {
92 listenerId = messageStorage.addConversationsChangeListener(changeCallback);
94 message.subject = generateSubject();
95 messageStorage.updateMessages([message], null, updateError);
98 addDraftError = t.step_func(function (error) {
99 assert_unreached("addDraftMessage() error callback: name:" + error.name + ", msg:" + error.message);
102 serviceSuccess = t.step_func(function (service) {
103 messageService = service;
104 messageStorage = messageService.messageStorage;
106 message = createSimpleMessageTo(TEST_EMAIL_RECIPIENT_2);
107 messageStorage.addDraftMessage(message, addDraftSuccess, addDraftError);
110 serviceError = t.step_func(function (error) {
111 assert_unreached("getEmailService() error callback: name:" + error.name + ", msg:" + error.message);
114 getEmailService(t, serviceSuccess, serviceError);