b958d40fb96d3d92d400bce007324af34ff34b3a
[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_sms_findMessages_plainBody_and_id_with_errorCallback</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>
28 </head>
29
30 <body>
31 <div id="log"></div>
32 <script>
33 //==== TEST: MessageStorage_sms_findMessages_plainBody_and_id_with_errorCallback
34 //==== LABEL Check if MessageStorage.findMessages method works properly with filter by plainBody and to (sms)
35 //==== PRIORITY P1
36 //==== ONLOAD_DELAY 90
37 //==== SPEC Tizen Web API:Communication:Messaging:MessageStorage:findMessages M
38 //==== SPEC_URL https://developer.tizen.org/help/topic/org.tizen.web.device.apireference/tizen/messaging.html
39 //==== TEST_CRITERIA MOA
40 setup({timeout: 90000});
41 var t = async_test(document.title, {timeout: 90000}), getMessageServicesErrorCB, getMessageServicesSuccessCB,
42     messageService, messageStorage, message, messageOne, count = 0, addDraftSuccessCB, addDraftErrorCB, filter1,
43     filter2, composite, findSuccessCB, findErrorCB, loadMessageSuccess, loadMessageError, commonPlainBody;
44 t.step(function () {
45
46     loadMessageSuccess = t.step_func(function (msg) {
47         assert_own_property(msg, "id", "Name id doesn't exist in provided object.");
48         assert_equals(msg.id, message.id, "Id is not equal");
49         assert_own_property(msg, "folderId", "Name folderId doesn't exist in provided object.");
50         assert_equals(msg.folderId, message.folderId, "folderId is not equal");
51         assert_own_property(msg, "type", "Name type doesn't exist in provided object.");
52         assert_equals(msg.type, message.type, "type is not equal");
53         assert_own_property(msg, "timestamp", "Name timestamp doesn't exist in provided object.");
54         assert_equals(msg.timestamp.getTime(), message.timestamp.getTime(), "timestamp is not equal");
55         assert_own_property(msg, "from", "Name from doesn't exist in provided object.");
56         assert_equals(msg.from, message.from, "from is not equal");
57         assert_own_property(msg, "to", "Name to doesn't exist in provided object.");
58         assert_array_equals(msg.to, message.to, "to is not equal");
59         assert_own_property(msg.body, "messageId", "Name body.messageId doesn't exist in provided object.");
60         assert_equals(msg.body.messageId, message.body.messageId, "body.messageId is not equal");
61         assert_own_property(msg.body, "loaded", "Name loaded doesn't exist in provided object.");
62         assert_equals(msg.body.loaded, message.body.loaded, "loaded is not equal");
63         assert_own_property(msg.body, "plainBody", "Name plainBody doesn't exist in provided object.");
64         assert_equals(msg.body.plainBody, message.body.plainBody, "plainBody is not equal");
65         assert_own_property(msg, "isRead", "Name isRead doesn't exist in provided object.");
66         assert_equals(msg.isRead, message.isRead, "isRead is not equal");
67         assert_own_property(msg, "inResponseTo", "Name inResponseTo doesn't exist in provided object.");
68         assert_equals(msg.inResponseTo, message.inResponseTo, "inResponseTo is not equal");
69
70         t.done();
71     });
72
73     loadMessageError = t.step_func(function (error) {
74         assert_unreached("loadMEssageError() error callback: name:" + error.name + ", msg:" + error.message);
75     });
76
77     findSuccessCB = t.step_func(function (msg) {
78         assert_equals(msg.length, 1, "No messages found");
79         assert_equals(msg[0].id, message.id, "Id is not equal");
80         messageService.loadMessageBody(msg[0], loadMessageSuccess, loadMessageError);
81     });
82
83     findErrorCB = t.step_func(function (error) {
84         assert_unreached("findMessage() error callback: name:" + error.name + ", msg:" + error.message);
85     });
86
87     addDraftSuccessCB = t.step_func(function () {
88         count++;
89         if (count === 2) {
90             filter1 = new tizen.AttributeFilter("body.plainBody", "CONTAINS", message.body.plainBody);
91             filter2 = new tizen.AttributeFilter("id", "EXACTLY", message.id);
92
93             composite = new tizen.CompositeFilter("INTERSECTION", [filter1, filter2]);
94             messageStorage.findMessages(composite, findSuccessCB, findErrorCB);
95         }
96     });
97
98     addDraftErrorCB = t.step_func(function (error) {
99         assert_unreached("addDraftErrorCB() error callback: name:" + error.name + ", msg:" + error.message);
100     });
101
102     getMessageServicesSuccessCB = t.step_func(function (services) {
103         assert_greater_than(services.length, 0, "Received empty services array");
104
105         commonPlainBody = generatePlainBody();
106
107         messageOne = new tizen.Message("messaging.sms", {
108             to: [TEST_SMS_RECIPIENT],
109             plainBody: commonPlainBody
110         });
111         messageOne.body.plainBody = "new plainBody";
112
113         message = new tizen.Message("messaging.sms", {
114             to: [TEST_SMS_RECIPIENT],
115             plainBody: commonPlainBody
116         });
117
118         messageService = services[0];
119         messageStorage = messageService.messageStorage;
120         messageStorage.addDraftMessage(messageOne, addDraftSuccessCB, addDraftErrorCB);
121         messageStorage.addDraftMessage(message, addDraftSuccessCB, addDraftErrorCB);
122     });
123
124     getMessageServicesErrorCB = t.step_func(function (error) {
125         assert_unreached("getMessageServices() error callback: name:" + error.name + ", msg:" + error.message);
126     });
127
128     tizen.messaging.getMessageServices("messaging.sms", getMessageServicesSuccessCB, getMessageServicesErrorCB);
129 });
130
131 </script>
132 </body>
133 </html>