bb8a3005d1333db14623a87e9e9b4e42ae7a3059
[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
21 -->
22 <html>
23 <head>
24 <title>MessageStorage_email_findMessages_hasAttachment_with_errorCallback</title>
25 <meta charset="utf-8"/>
26 <script type="text/javascript" src="../resources/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: MessageStorage_email_findMessages_hasAttachment_with_errorCallback
34 //==== LABEL Check with optional arguments findMessages(valid_filter, valid_successCallback, valid_errorCallback) hasAttachment for email
35 //==== SPEC Tizen Web API:Communication:Messaging:MessageStorage:findMessages 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 MOA
40 setup({timeout: 180000});
41
42 var t = async_test("MessageStorage_email_findMessages_hasAttachment_with_errorCallback", {timeout:180000}),
43     serviceSuccess, serviceError, service, message, filter, messageFound = false,
44     addDraftSuccess, addDraftError, findSuccess, findError;
45
46 t.step(function () {
47    findSuccess = t.step_func(function (messages) {
48         assert_type(messages, "array", "Not an array");
49         assert_greater_than(messages.length, 0, "Received empty messages array");
50
51         for (var i in messages) {
52             assert_true(messages[i] instanceof tizen.Message, "Not a Message");
53             assert_equals(messages[i].hasAttachment, true, "returned hasAttachment is not equal to true");
54
55             if (messages[i].id === message.id) {
56                 messageFound = true;
57             }
58         }
59
60         assert_true(messageFound, "expected message wasn't found");
61         t.done();
62     });
63
64     findError = t.step_func(function (error) {
65         assert_unreached("findMessages() error callback: name:" + error.name + ", msg:" + error.message);
66     });
67
68     addDraftSuccess = t.step_func(function () {
69         filter = new tizen.AttributeFilter("hasAttachment", "EXACTLY", true);
70         service.messageStorage.findMessages(filter, findSuccess, findError);
71     });
72
73     addDraftError = t.step_func(function (error) {
74         assert_unreached("addDraftMessage() error callback: name:" + error.name + ", msg:" + error.message);
75     });
76
77     serviceSuccess = t.step_func(function (emailService) {
78         service = emailService;
79
80         message = createSimpleMessageTo(TEST_EMAIL_RECIPIENT_2);
81         message.attachments = [new tizen.MessageAttachment(MESSAGE_ATTACHMENT_IMAGE_PATH, MESSAGE_ATTACHMENT_IMAGE_MIME_TYPE)];
82
83         assert_true(message.hasAttachment, "Attachment not found");
84
85         service.messageStorage.addDraftMessage(message, addDraftSuccess, addDraftError);
86     });
87
88     serviceError = t.step_func(function (error) {
89         assert_unreached("getEmailService() error callback: name:" + error.name + ", msg:" + error.message);
90     });
91
92     getEmailService(t, serviceSuccess, serviceError);
93 });
94
95 </script>
96 </body>
97 </html>