32bd76ac3ae9e282b1b39be83edb8f21c6e2a47d
[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>MessageService_email_loadMessageAttachment_without_errorCallback</title>
25 <meta charset="utf-8"/>
26 <script src="../resources/unitcommon.js"></script>
27 <script src="support/messaging_common.js"></script>
28 </head>
29
30 <body>
31 <div id="log"></div>
32 <script>
33 //==== TEST: MessageService_email_loadMessageAttachment_without_errorCallback
34 //==== LABEL Check MessageService.loadMessageAttachment method with non-optional arguments (email)
35 //==== SPEC Tizen Web API:Communication:Messaging:MessageService:loadMessageAttachment 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 MR MMINA MAST
40 setup({timeout: 180000});
41
42 var t = async_test("MessageService_email_loadMessageAttachment_without_errorCallback", {timeout: 180000}),
43     service, inboxFolder, serviceSuccess, serviceError, sendSuccess, sendError,
44     message, attachment, syncSuccess, syncError, returnedValue, findSuccess, findError, foundMessage,
45     loadAttachmentSuccess, loadBodySuccess, loadBodyError, loadMessage, folderSuccess, folderError;
46
47 t.step(function () {
48     loadAttachmentSuccess = t.step_func(function (f_attachment) {
49         assert_equals(returnedValue, undefined, "Incorrect returned value from loadMessageAttachment");
50         assert_true(f_attachment instanceof tizen.MessageAttachment, "Not a tizen.MessageAttachment.");
51
52         assert_type(f_attachment.id, "string", "attachment.id incorrect type.");
53         assert_not_equals(f_attachment.id, "", "attachment.id is empty.");
54
55         assert_type(f_attachment.messageId, "string", "attachment.messageId incorrect type.");
56         assert_equals(f_attachment.messageId, foundMessage.attachments[0].messageId, "attachment.messageId");
57
58         assert_equals(f_attachment.mimeType, attachment.mimeType, "attachment.mimeType");
59
60         assert_type(f_attachment.filePath, "string", "attachment.filePath incorrect type.");
61         assert_not_equals(f_attachment.filePath, "", "attachment.filePath is empty.");
62         t.done();
63     });
64
65     loadBodySuccess = t.step_func(function (message) {
66         loadMessage = message;
67         assert_equals(loadMessage.attachments.length, 1, "Incorrect number of found attachments");
68         returnedValue = service.loadMessageAttachment(loadMessage.attachments[0], loadAttachmentSuccess);
69     });
70
71     loadBodyError = t.step_func(function (error) {
72         assert_unreached("loadMessageBody() error callback: name:" + error.name + ", msg:" + error.message);
73     });
74
75     findSuccess = t.step_func(function (messages) {
76         assert_inbox_message_equals(t, messages, message, inboxFolder);
77
78         foundMessage = messages[0];
79
80         if (foundMessage.attachments.length === 0) {
81             service.loadMessageBody(foundMessage, loadBodySuccess, loadBodyError);
82         } else {
83             returnedValue = service.loadMessageAttachment(foundMessage.attachments[0], loadAttachmentSuccess);
84         }
85     });
86
87     findError = t.step_func(function (error) {
88         assert_unreached("findMessages() error callback: name:" + error.name + ", msg:" + error.message);
89     });
90
91     folderSuccess = t.step_func(function (folders) {
92         inboxFolder = getInboxFolder(t, folders);
93         findMessages(t, service, inboxFolder, message.subject, findSuccess, findError);
94     });
95
96     folderError = t.step_func(function (error) {
97         assert_unreached("findFolders() error callback: name:" + error.name + ", msg:" + error.message);
98     });
99
100     syncSuccess = t.step_func(function () {
101         findFolders(t, service, folderSuccess, folderError);
102     });
103
104     syncError = t.step_func(function (error) {
105         assert_unreached("sync() error callback: name:" + error.name + ", msg:" + error.message);
106     });
107
108     sendSuccess = t.step_func(function () {
109         sync(t, service, syncSuccess, syncError);
110     });
111
112     sendError = t.step_func(function (error) {
113         assert_unreached("sendMessage() error callback: name:" + error.name + ", msg:" + error.message);
114     });
115
116     serviceSuccess = t.step_func(function (emailService) {
117         service = emailService;
118
119         message = createSimpleMessageTo(TEST_EMAIL_RECIPIENT_1);
120         attachment = new tizen.MessageAttachment(MESSAGE_ATTACHMENT_IMAGE_PATH, "image/jpg");
121         message.attachments = [attachment];
122
123         sendMessage(t, service, message, sendSuccess, sendError);
124     });
125
126     serviceError = t.step_func(function (error) {
127         assert_unreached("getEmailService() error callback: name:" + error.name + ", msg:" + error.message);
128     });
129
130     getEmailService(t, serviceSuccess, serviceError); 
131 });
132 </script>
133 </body>
134 </html>