1d2e3c25b2fc307d2d273839725a7eeee3a70cf0
[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     Lukasz Bardeli <l.bardeli@samsung.com>
20     Mariusz Polasinski <m.polasinski@samsung.com>
21
22 -->
23 <html lang="en">
24 <head>
25 <title>MessageStorage_email_findMessages_and_loadMessageBody</title>
26 <meta charset="utf-8"/>
27 <script type="text/javascript" src="../resources/unitcommon.js"></script>
28 <script type="text/javascript" src="support/messaging_common.js"></script>
29 </head>
30
31 <body>
32 <div id="log"></div>
33 <script type="text/javascript">
34
35 //==== TEST: MessageStorage_email_findMessages_and_loadMessageBody
36 //==== LABEL Check with optional arguments findMessages(valid_filter, valid_successCallback) id for email, load and check message body
37 //==== SPEC Tizen Web API:Communication:Messaging:MessageStorage:findMessages M
38 //==== SPEC_URL https://developer.tizen.org/help/index.jsp?topic=/org.tizen.web.device.apireference/tizen/messaging.html
39 //==== ONLOAD_DELAY 90
40 //==== TEST_CRITERIA MMINA
41 setup({timeout:180000});
42
43 var t = async_test("MessageStorage_email_findMessages", {timeout:180000});
44 t.step(function () {
45     var serviceError, serviceSuccess, messageService, messageStorage,
46         message, addDraftSuccess, addDraftError, filter, findSuccess, i, loadMessageSuccess, loadMessageError;
47
48     loadMessageSuccess = t.step_func(function (msg) {
49         assert_own_property(msg, "id", "Name id doesn't exist in provided object.");
50         assert_equals(msg.id, message.id, "Id is not equal");
51         assert_own_property(msg, "conversationId", "Name conversationId doesn't exist in provided object.");
52         assert_equals(msg.conversationId, message.conversationId, "conversationId is not equal");
53         assert_own_property(msg, "folderId", "Name folderId doesn't exist in provided object.");
54         assert_equals(msg.folderId, message.folderId, "folderId is not equal");
55         assert_own_property(msg, "type", "Name type doesn't exist in provided object.");
56         assert_equals(msg.type, message.type, "type is not equal");
57         assert_own_property(msg, "timestamp", "Name timestamp doesn't exist in provided object.");
58         assert_equals(msg.timestamp.getTime(), message.timestamp.getTime(), "timestamp is not equal");
59         assert_own_property(msg, "from", "Name from doesn't exist in provided object.");
60         assert_equals(msg.from, message.from, "from is not equal");
61         assert_own_property(msg, "to", "Name to doesn't exist in provided object.");
62         for(i = 0; i < msg.to.length; i++){
63             assert_equals(msg.to[i], message.to[i], "to is not equal");
64         }
65         assert_own_property(msg, "bcc", "Name bcc doesn't exist in provided object.");
66         for(i = 0; i < msg.bcc.length; i++){
67             assert_equals(msg.bcc[i], message.bcc[i], "bcc is not equal");
68         }
69         assert_own_property(msg, "cc", "Name cc doesn't exist in provided object.");
70         for(i = 0; i < msg.cc.length; i++){
71             assert_equals(msg.cc[i], message.cc[i], "cc is not equal");
72         }
73         assert_own_property(msg.body, "messageId", "Name body.messageId doesn't exist in provided object.");
74         assert_equals(msg.body.messageId, message.body.messageId, "body.messageId is not equal");
75         assert_own_property(msg.body, "loaded", "Name loaded doesn't exist in provided object.");
76         assert_equals(msg.body.loaded, message.body.loaded, "loaded is not equal");
77         assert_own_property(msg.body, "plainBody", "Name plainBody doesn't exist in provided object.");
78         assert_equals(msg.body.plainBody, message.body.plainBody, "plainBody is not equal");
79         assert_own_property(msg.body, "htmlBody", "Name htmlBody doesn't exist in provided object.");
80         assert_equals(msg.body.htmlBody, message.body.htmlBody, "htmlBody is not equal");
81         assert_own_property(msg.body, "inlineAttachments", "Name inlineAttachments doesn't exist in provided object.");
82         for (i = 0; i < msg.body.inlineAttachments.length; i++) {
83             assert_true(msg.body.inlineAttachments[i] instanceof tizen.MessageAttachment, "wrong attachment object");
84             assert_equals(msg.body.inlineAttachments[i].id, message.body.inlineAttachments[i].id, "attachments.id is not equal");
85             assert_equals(msg.body.inlineAttachments[i].messageId, message.body.inlineAttachments[i].messageId, "attachments.messageId is not equal");
86             assert_equals(msg.body.inlineAttachments[i].mimeType, message.body.inlineAttachments[i].mimeType, "attachments.mimeType is not equal");
87         }
88         assert_own_property(msg, "isRead", "Name isRead doesn't exist in provided object.");
89         assert_equals(msg.isRead, message.isRead, "isRead is not equal");
90         assert_own_property(msg, "hasAttachment", "Name hasAttachment doesn't exist in provided object.");
91         assert_equals(msg.hasAttachment, message.hasAttachment, "hasAttachment is not equal");
92         assert_own_property(msg, "isHighPriority", "Name isHighPriority doesn't exist in provided object.");
93         assert_equals(msg.isHighPriority, message.isHighPriority, "isHighPriority is not equal");
94         assert_own_property(msg, "subject", "Name subject doesn't exist in provided object.");
95         assert_equals(msg.subject, message.subject, "subject is not equal");
96         assert_own_property(msg, "inResponseTo", "Name inResponseTo doesn't exist in provided object.");
97         assert_equals(msg.inResponseTo, message.inResponseTo, "inResponseTo is not equal");
98         assert_own_property(msg, "messageStatus", "Name messageStatus doesn't exist in provided object.");
99         assert_equals(msg.messageStatus, message.messageStatus, "messageStatus is not equal");
100         for(i = 0; i < msg.attachments.length; i++){
101             assert_true(msg.attachments[i] instanceof tizen.MessageAttachment, "wrong attachment object");
102             assert_equals(msg.attachments[i].id, message.attachments[i].id, "attachments.id is not equal");
103             assert_equals(msg.attachments[i].messageId, message.attachments[i].messageId, "attachments.messageId is not equal");
104             assert_equals(msg.attachments[i].mimeType, message.attachments[i].mimeType, "attachments.mimeType is not equal");
105         }
106         t.done();
107     });
108
109     loadMessageError = t.step_func(function (error) {
110         assert_unreached("loadMessageError() error callback: name:" + error.name + ", msg:" + error.message);
111     });
112
113     findSuccess = t.step_func(function (msg) {
114         assert_true(msg.length === 1, "Received incorrect number of messages: " + msg.length);
115         messageService.loadMessageBody(msg[0], loadMessageSuccess, loadMessageError);
116     });
117
118     addDraftSuccess = t.step_func(function () {
119         filter = new tizen.AttributeFilter("id", "EXACTLY", message.id);
120         messageStorage.findMessages(filter, findSuccess);
121     });
122
123     addDraftError = t.step_func(function (error) {
124         assert_unreached("addDraftErrorCB() error callback: name:" + error.name + ", msg:" + error.message);
125     });
126
127     serviceSuccess = t.step_func(function (services) {
128         assert_true(services.length > 0, "No services was return");
129
130         message = new tizen.Message("messaging.email", emailMessageInitDict);
131         message.attachments = [new tizen.MessageAttachment(imagePathToSet, "image/jpeg")];
132         message.body.inlineAttachments = [new tizen.MessageAttachment(soundPathToSet, "audio/mp3")];
133
134         messageService = services[0];
135         messageStorage = messageService.messageStorage;
136         messageStorage.addDraftMessage(message, addDraftSuccess, addDraftError);
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 }, "MessageStorage_email_findMessages");
145
146 </script>
147 </body>
148 </html>