450b016b78f3f49e9a045e4d36bc36e4dfbadd5a
[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_withoutfilter</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_withoutfilter
45 //==== LABEL Check if MessagesChangeCallback's messagesupdated callback works properly (listener added without filter)
46 //==== PRIORITY P1
47 //==== SPEC Tizen Web API:Communication:Messaging:MessagesChangeCallback:messagesupdated M
48 //==== SPEC_URL https://developer.tizen.org/help/topic/org.tizen.web.device.apireference/tizen/messaging.html
49 //==== ONLOAD_DELAY 90
50 //==== TEST_CRITERIA CBOA
51 setup({timeout: 90000});
52
53 var t = async_test(document.title, {timeout: 90000}), i,
54         serviceError, serviceSuccess, sendSuccess, sendError, findfilter, msg, listener, updateError,
55         findSuccess, findError, service, 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         messagesupdated: t.step_func(function (updatedMessages) {
69             assert_type(updatedMessages, "array", "Not an array.");
70             assert_greater_than(updatedMessages.length, 0, "Received empty messages array");
71             for (i = 0; i < updatedMessages.length; i++) {
72                 assert_true(updatedMessages[i] instanceof tizen.Message, "Not a message.");
73                 if (updatedMessages[i].id === msg.id) {
74                     t.done();
75                     break;
76                 }
77             }
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, "No messages found.");
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         listenerId = service.messageStorage.addMessagesChangeListener(listener);
97         findfilter = new tizen.AttributeFilter("to", "CONTAINS", TEST_SMS_RECIPIENT_2);
98         service.messageStorage.findMessages(findfilter, findSuccess, findError);
99     });
100
101     sendError = t.step_func(function (error) {
102         assert_unreached("sendMessage() error callback: name:" + error.name + ", msg:" + error.message);
103     });
104
105     serviceSuccess = t.step_func(function (services) {
106         assert_greater_than(services.length, 0, "Received empty services array");
107         service = services[0];
108         msg = new tizen.Message("messaging.sms",
109                 { plainBody: "test.", to: [ TEST_SMS_RECIPIENT_2] });
110
111         sendMessage(t, service, msg, sendSuccess, sendError);
112     });
113
114     serviceError = t.step_func(function (error) {
115         assert_unreached("getMessageServices() error callback: name:" + error.name + ", msg:" + error.message);
116     });
117
118     tizen.messaging.getMessageServices("messaging.sms", serviceSuccess, serviceError);
119 });
120
121 </script>
122 </body>
123 </html>