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 Lukasz Bardeli <l.bardeli@samsung.com>
20 Mariusz Polasinski <m.polasinski@samsung.com>
25 <title>MessageStorage_email_findMessages_and_loadMessageBody</title>
26 <meta charset="utf-8"/>
27 <script type="text/javascript" src="support/unitcommon.js"></script>
28 <script type="text/javascript" src="support/messaging_common.js"></script>
33 <script type="text/javascript">
35 //==== TEST: MessageStorage_email_findMessages_and_loadMessageBody
36 //==== LABEL Check if MessageStorage.findMessages and MessageStorage.loadMessageBody methods work properly
38 //==== SPEC Tizen Web API:Communication:Messaging:MessageStorage:findMessages M
39 //==== SPEC_URL https://developer.tizen.org/help/topic/org.tizen.web.device.apireference/tizen/messaging.html
40 //==== ONLOAD_DELAY 300
42 //==== TEST_CRITERIA MMINA
43 setup({timeout: 90000});
45 var t = async_test(document.title, {timeout: 90000}),
46 serviceSuccess, serviceError, service, message, addDraftSuccess, addDraftError,
47 filter, findSuccess, i, loadMessageSuccess, loadMessageError;
50 loadMessageSuccess = t.step_func(function (msg) {
51 assert_own_property(msg, "id", "Name id doesn't exist in provided object.");
52 assert_equals(msg.id, message.id, "Id is not equal");
53 assert_own_property(msg, "conversationId", "Name conversationId doesn't exist in provided object.");
54 assert_equals(msg.conversationId, message.conversationId, "conversationId is not equal");
55 assert_own_property(msg, "folderId", "Name folderId doesn't exist in provided object.");
56 assert_equals(msg.folderId, message.folderId, "folderId is not equal");
57 assert_own_property(msg, "type", "Name type doesn't exist in provided object.");
58 assert_equals(msg.type, message.type, "type is not equal");
59 assert_own_property(msg, "timestamp", "Name timestamp doesn't exist in provided object.");
60 assert_equals(msg.timestamp.getTime(), message.timestamp.getTime(), "timestamp is not equal");
61 assert_own_property(msg, "from", "Name from doesn't exist in provided object.");
62 assert_equals(msg.from, message.from, "from is not equal");
63 assert_own_property(msg, "to", "Name to doesn't exist in provided object.");
64 assert_array_equals(msg.to, message.to, "to is not equal");
65 assert_array_equals(msg.cc, message.cc, "to is not equal");
66 assert_array_equals(msg.bcc, message.bcc, "to is not equal");
67 assert_own_property(msg.body, "messageId", "Name body.messageId doesn't exist in provided object.");
68 assert_equals(msg.body.messageId, message.body.messageId, "body.messageId is not equal");
69 assert_own_property(msg.body, "loaded", "Name loaded doesn't exist in provided object.");
70 assert_equals(msg.body.loaded, message.body.loaded, "loaded is not equal");
71 assert_own_property(msg.body, "plainBody", "Name plainBody doesn't exist in provided object.");
72 assert_equals(msg.body.plainBody, message.body.plainBody, "plainBody is not equal");
73 assert_own_property(msg.body, "htmlBody", "Name htmlBody doesn't exist in provided object.");
74 assert_equals(msg.body.htmlBody, message.body.htmlBody, "htmlBody is not equal");
75 assert_own_property(msg.body, "inlineAttachments", "Name inlineAttachments doesn't exist in provided object.");
76 for (i = 0; i < msg.body.inlineAttachments.length; i++) {
77 assert_true(msg.body.inlineAttachments[i] instanceof tizen.MessageAttachment, "wrong attachment object");
78 assert_equals(msg.body.inlineAttachments[i].id, message.body.inlineAttachments[i].id, "attachments.id is not equal");
79 assert_equals(msg.body.inlineAttachments[i].messageId, message.body.inlineAttachments[i].messageId, "attachments.messageId is not equal");
80 assert_equals(msg.body.inlineAttachments[i].mimeType, message.body.inlineAttachments[i].mimeType, "attachments.mimeType is not equal");
82 assert_own_property(msg, "isRead", "Name isRead doesn't exist in provided object.");
83 assert_equals(msg.isRead, message.isRead, "isRead is not equal");
84 assert_own_property(msg, "hasAttachment", "Name hasAttachment doesn't exist in provided object.");
85 assert_equals(msg.hasAttachment, message.hasAttachment, "hasAttachment is not equal");
86 assert_own_property(msg, "isHighPriority", "Name isHighPriority doesn't exist in provided object.");
87 assert_equals(msg.isHighPriority, message.isHighPriority, "isHighPriority is not equal");
88 assert_own_property(msg, "subject", "Name subject doesn't exist in provided object.");
89 assert_equals(msg.subject, message.subject, "subject is not equal");
90 assert_own_property(msg, "inResponseTo", "Name inResponseTo doesn't exist in provided object.");
91 assert_equals(msg.inResponseTo, message.inResponseTo, "inResponseTo is not equal");
92 assert_own_property(msg, "messageStatus", "Name messageStatus doesn't exist in provided object.");
93 assert_equals(msg.messageStatus, message.messageStatus, "messageStatus is not equal");
94 for(i = 0; i < msg.attachments.length; i++){
95 assert_true(msg.attachments[i] instanceof tizen.MessageAttachment, "wrong attachment object");
96 assert_equals(msg.attachments[i].id, message.attachments[i].id, "attachments.id is not equal");
97 assert_equals(msg.attachments[i].messageId, message.attachments[i].messageId, "attachments.messageId is not equal");
98 assert_equals(msg.attachments[i].mimeType, message.attachments[i].mimeType, "attachments.mimeType is not equal");
103 loadMessageError = t.step_func(function (error) {
104 assert_unreached("loadMessageError() error callback: name:" + error.name + ", msg:" + error.message);
107 findSuccess = t.step_func(function (messages) {
108 assert_draft_message_equals(t, messages, message);
109 service.loadMessageBody(messages[0], loadMessageSuccess, loadMessageError);
112 addDraftSuccess = t.step_func(function () {
113 filter = new tizen.AttributeFilter("id", "EXACTLY", message.id);
114 service.messageStorage.findMessages(filter, findSuccess);
117 addDraftError = t.step_func(function (error) {
118 assert_unreached("addDraftErrorCB() error callback: name:" + error.name + ", msg:" + error.message);
121 serviceSuccess = t.step_func(function (emailService) {
122 service = emailService;
124 message = new tizen.Message("messaging.email", {
125 subject: generateSubject(),
126 to: [TEST_EMAIL_RECIPIENT_2],
127 cc: [TEST_EMAIL_RECIPIENT_1],
128 bcc: [TEST_EMAIL_RECIPIENT_1],
129 plainBody: MESSAGE_BODY_PLAIN,
130 htmlBody: MESSAGE_BODY_HTML,
131 isHighPriority: false
134 message.attachments = [
135 new tizen.MessageAttachment(TEST_DIR + "webapi-tizen-messaging-test_image.jpg", MESSAGE_ATTACHMENT_IMAGE_MIME_TYPE)
138 message.body.inlineAttachments = [
139 new tizen.MessageAttachment(TEST_DIR + "webapi-tizen-messaging-test_noise.mp3", MESSAGE_ATTACHMENT_SOUND_MIME_TYPE)
142 service.messageStorage.addDraftMessage(message, addDraftSuccess, addDraftError);
145 serviceError = t.step_func(function (error) {
146 assert_unreached("getMessageServices() error callback: name:" + error.name + ", msg:" + error.message);
149 getEmailService(t, serviceSuccess, serviceError);
150 }, "MessageStorage_email_findMessages");