a932b1a20783da9dc88d64e38b0ff351a92f6f7b
[test/tct/web/api.git] /
1 <!DOCTYPE html>
2 <!--
3 Copyright (c) 2012 Intel Corporation.
4
5 Redistribution and use in source and binary forms, with or without modification,
6 are permitted provided that the following conditions are met:
7
8 * Redistributions of works must retain the original copyright notice, this list
9   of conditions and the following disclaimer.
10 * Redistributions in binary form must reproduce the original copyright notice,
11   this list of conditions and the following disclaimer in the documentation
12   and/or other materials provided with the distribution.
13 * Neither the name of Intel Corporation nor the names of its contributors
14   may be used to endorse or promote products derived from this work without
15   specific prior written permission.
16
17 THIS SOFTWARE IS PROVIDED BY INTEL CORPORATION "AS IS"
18 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 ARE DISCLAIMED. IN NO EVENT SHALL INTEL CORPORATION BE LIABLE FOR ANY DIRECT,
21 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
22 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
24 OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
25 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
26 EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28 Authors:
29         Li, Li <li.l.li@intel.com>
30         Zoe, Zou <zoex.zou@intel.com>
31         Ma, YueX <yuex.ma@intel.com>
32
33 -->
34
35 <html>
36 <head>
37 <title>MessagesChangeCallback_messagesupdated_withfilter</title>
38 <script type="text/javascript" src="support/unitcommon.js"></script>
39 <script type="text/javascript" src="support/messaging_common.js"></script>
40 </head>
41 <body>
42 <div id="log"></div>
43 <script type="text/javascript">
44 //==== TEST: MessagesChangeCallback_messagesupdated_withfilter
45 //==== LABEL Check if MessagesChangeCallback's messagesupdated callback works properly (listener added with filter)
46 //==== PRIORITY P1
47 //==== ONLOAD_DELAY 90
48 //==== SPEC Tizen Web API:Communication:Messaging:MessagesChangeCallback:messagesupdated M
49 //==== SPEC_URL https://developer.tizen.org/help/topic/org.tizen.web.device.apireference/tizen/messaging.html
50 //==== TEST_CRITERIA CBOA
51 setup({timeout: 90000});
52
53 var t = async_test(document.title, {timeout: 90000}),
54         serviceError, serviceSuccess, sendSuccess, sendError, findfilter, msg, listener, updateError,
55         findSuccess, findError, service, listenerfilter, listenerId;
56
57 t.step(function () {
58
59     add_result_callback(function (res) {
60         try {
61             service.messageStorage.removeChangeListener(listenerId);
62         } catch (err) {
63             // do nothing in case removeChangeListener throw an exception
64         }
65     });
66
67     listener = {
68         messagesadded: t.step_func(function (messages) {
69             assert_unreached("Should not enter messagesadded: " + messages.length);
70         }),
71         messagesupdated: t.step_func(function (messages) {
72             assert_greater_than(messages.length, 0, "Received empty messages array in messagesupdated");
73
74             t.done();
75         }),
76         messagesremoved: t.step_func(function (messages) {
77             assert_unreached("Should not enter messagesremoved: " + messages.length);
78         })
79     };
80
81     updateError = t.step_func(function (error) {
82         assert_unreached("updateMessages() error callback: name:" + error.name + ", msg:" + error.message);
83     });
84
85     findSuccess = t.step_func(function (messages) {
86         assert_greater_than(messages.length, 0, "Received empty messages array after findMessages()");
87         messages[0].isRead = !messages[0].isRead;
88         service.messageStorage.updateMessages(messages, null, updateError);
89     });
90
91     findError = t.step_func(function (error) {
92         assert_unreached("findMessages() error callback: name:" + error.name + ", msg:" + error.message);
93     });
94
95     sendSuccess = t.step_func(function () {
96         listenerfilter = new tizen.AttributeFilter("type", "EXACTLY", "messaging.sms");
97         listenerId = service.messageStorage.addMessagesChangeListener(listener, listenerfilter);
98         findfilter = new tizen.AttributeFilter("to", "CONTAINS", TEST_SMS_RECIPIENT_2);
99         service.messageStorage.findMessages(findfilter, findSuccess, findError);
100     });
101
102     sendError = t.step_func(function (error) {
103         assert_unreached("sendMessage() error callback: name:" + error.name + ", msg:" + error.message);
104     });
105
106     serviceSuccess = t.step_func(function (services) {
107         assert_greater_than(services.length, 0, "Received empty services array");
108         service = services[0];
109         msg = new tizen.Message("messaging.sms",
110                 { plainBody: "test.", to: [ TEST_SMS_RECIPIENT_2 ] });
111
112         sendMessage(t, service, msg, sendSuccess, sendError);
113     });
114
115     serviceError = t.step_func(function (error) {
116         assert_unreached("getMessageServices() error callback: name:" + error.name + ", msg:" + error.message);
117     });
118
119     tizen.messaging.getMessageServices("messaging.sms", serviceSuccess, serviceError);
120 });
121
122 </script>
123 </body>
124 </html>