3 Copyright (c) 2013 Samsung Electronics Co., Ltd.
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
9 http://www.apache.org/licenses/LICENSE-2.0
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.
19 Andrzej Krolikowski <a.krolikowsk@samsung.com>
24 <title>MessageStorage_sms_addMessagesChangeListener_with_filter</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>
33 //==== TEST: MessageStorage_sms_addMessagesChangeListener_with_filter
34 //==== LABEL Check if MessageStorage.addMessagesChangeListener method works properly with filter (sms)
35 //==== SPEC Tizen Web API:Communication:Messaging:MessageStorage:addMessagesChangeListener M
36 //==== SPEC_URL https://developer.tizen.org/help/topic/org.tizen.web.device.apireference/tizen/messaging.html
37 //==== ONLOAD_DELAY 90
38 //==== TEST_CRITERIA MR MOA MAST
39 setup({timeout: 90000});
41 var t = async_test(document.title, {timeout: 90000}), serviceSuccess, serviceError, messageService, messageStorage,
42 subscriptionIdentifier, filter, endText = "ending", currentDate = new Date(),
43 matchPlainBodyToSet = currentDate.getTime().toString() + endText.toUpperCase(),
44 mismatchPlainBodyToSet = currentDate.getTime().toString(),
45 matchInitDict = smsMessageInitDict, mismatchInitDict = smsMessageInitDict,
46 matchMessage, mismatchMessage, changeCallback, addDraftError, loadSuccess, loadError;
50 add_result_callback(function () {
52 messageStorage.removeChangeListener(subscriptionIdentifier);
54 // do nothing in case removeChangeListener throw an exception
58 loadSuccess = t.step_func(function (loadedMessage) {
59 assert_equals(loadedMessage.body.plainBody, matchPlainBodyToSet, "Incorrect plainBody.");
60 assert_equals(loadedMessage.id, matchMessage.id, "Incorrect id.");
64 loadError = t.step_func(function (error) {
65 assert_unreached("loadMessageBody() error callback: name:" + error.name + ", msg:" + error.message);
70 messagesadded: t.step_func(function (addedMessages) {
71 assert_type(addedMessages, "array", "Not an array.");
72 assert_equals(addedMessages.length, 1, "Received incorrect number of messages: " + addedMessages.length);
73 assert_true(addedMessages[0] instanceof tizen.Message, "Not a message.");
74 messageService.loadMessageBody(addedMessages[0], loadSuccess, loadError);
76 messagesupdated: t.step_func(function (updatedMessages) {
77 assert_unreached("memssagesupdated callback invoked.");
79 messagesremoved: t.step_func(function (removedMessages) {
80 assert_unreached("messagesremoved callback invoked.");
84 addDraftError = t.step_func(function (error) {
85 assert_unreached("addDraftMessage() error callback: name:" + error.name + ", msg:" + error.message);
88 serviceSuccess = t.step_func(function (services) {
89 assert_true(services.length > 0, "Received empty services array");
90 messageService = services[0];
91 messageStorage = messageService.messageStorage;
93 filter = new tizen.AttributeFilter("body.plainBody", "ENDSWITH", endText);
94 subscriptionIdentifier = messageStorage.addMessagesChangeListener(changeCallback, filter);
95 assert_type(subscriptionIdentifier, "long", "Incorrect returned value.");
97 mismatchInitDict.plainBody = mismatchPlainBodyToSet;
98 mismatchMessage = new tizen.Message("messaging.sms", mismatchInitDict);
99 messageStorage.addDraftMessage(mismatchMessage, null, addDraftError);
101 matchInitDict.plainBody = matchPlainBodyToSet;
102 matchMessage = new tizen.Message("messaging.sms", matchInitDict);
103 messageStorage.addDraftMessage(matchMessage, null, addDraftError);
106 serviceError = t.step_func(function (error) {
107 assert_unreached("getMessageServices() error callback: name:" + error.name + ", msg:" + error.message);
109 tizen.messaging.getMessageServices("messaging.sms", serviceSuccess, serviceError);