Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Commit

Permalink
Merge pull request #204 from gnaneswar/Bug-1062879_msg_mark_status
Browse files Browse the repository at this point in the history
Bug 1062879 - Develop more semi-auto tests for the SMS WebAPI.
  • Loading branch information
Jonathan Griffin committed Sep 9, 2014
2 parents 85ff2bb + 4c2a4d5 commit d364552
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 2 deletions.
1 change: 1 addition & 0 deletions webapi_tests/mobile_message/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@
from webapi_tests.mobile_message.test_sms_outgoing import TestSmsOutgoing
from webapi_tests.mobile_message.test_mms_incoming import TestMmsIncoming
from webapi_tests.mobile_message.test_mms_incoming_delete import TestMmsIncomingDelete
from webapi_tests.mobile_message.test_sms_incoming_read_status import TestSmsIncomingReadStatus
41 changes: 39 additions & 2 deletions webapi_tests/mobile_message/mobile_message_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,13 +183,11 @@ def send_msg(self, destination, body, msg_type="SMS"):
window.wrappedJSObject.rcvd_req_success = true;
} else {
log("request returned false for manager.send");
cleanUp();
}
};
requestRet.onerror = function() {
log("Failed to send message, received error: %s" % requestRet.error.name);
cleanUp();
};
marionetteScriptFinished(1);
""", script_args=[msg_type, destination, body], special_powers=True)
Expand Down Expand Up @@ -263,3 +261,42 @@ def user_guided_outgoing_msg(self, msg_type="SMS"):
self.confirm('Sent %s with text "%s" does this text match what was received on the target phone?' % (msg_type, self.out_msg['body']))
finally:
self.remove_sending_listeners()

def mark_message_status(self, msg_id, is_read=False):
self.marionette.execute_async_script("""
var msg_id = arguments[0];
var is_read = arguments[1];
var requestRet = null;
var mm = window.navigator.mozMobileMessage;
// Bug 952875
mm.getThreads();
requestRet = mm.markMessageRead(msg_id, is_read);
window.wrappedJSObject.rcvd_req_success_read = false;
window.wrappedJSObject.rcvd_req_success_unread = false;
requestRet.onsuccess = function(event) {
log("Received 'onsuccess' event.");
if (event.target.result) {
window.wrappedJSObject.rcvd_req_success_read = true;
} else {
window.wrappedJSObject.rcvd_req_success_unread = true;
log("request returned false for manager.markMessageRead");
}
}
requestRet.onerror = function() {
log("Failed to mark message read status, received error: %s" % requestRet.error.name);
};
marionetteScriptFinished(1);
""", script_args=[msg_id, is_read], special_powers=True)

wait = Wait(self.marionette, timeout=15, interval=0.5)
try:
if is_read is True:
wait.until(lambda m: self.marionette.execute_script("return window.wrappedJSObject.rcvd_req_success_read"))
else:
wait.until(lambda m: self.marionette.execute_script("return window.wrappedJSObject.rcvd_req_success_unread"))
except errors.TimeoutException:
# msg read status wasn't marked
self.fail("Failed to update the read status of message.")
56 changes: 56 additions & 0 deletions webapi_tests/mobile_message/test_sms_incoming_read_status.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.


from webapi_tests.semiauto import TestCase
from webapi_tests.mobile_message import MobileMessageTestCommon


class TestSmsIncomingReadStatus(TestCase, MobileMessageTestCommon):
"""
This is a test for the `WebSMS API`_ which will:
- Verify that an SMS can be received (sent by the test user)
- Confirm that the associated mozMobileMessage received event is triggered
- Mark the received message status as unread using API and verify read attribute
- Mark the received message status as read using API and verify read attribute
.. _`WebSMS API`: https://developer.mozilla.org/en-US/docs/Web/API/WebSMS_API
"""

def setUp(self):
super(TestSmsIncomingReadStatus, self).setUp()
self.wait_for_obj("window.navigator.mozMobileMessage")

def tearDown(self):
super(TestSmsIncomingReadStatus, self).tearDown()

def test_sms_incoming_read_status(self):
# have user send sms to the Firefox OS device
self.msg_type = "SMS"
self.user_guided_incoming_msg()

# verify message contents
self.assertTrue(len(self.in_msg['body']) > 0,
"Received message has no message body (was text included in the sent message?)")
self.confirm('Received SMS with text "%s" does this text match what was sent to the Firefox OS phone?' % self.in_msg['body'])

self.assertEqual(self.in_msg['type'], 'sms',
"Received SMS MozSmsMessage.type should be 'sms'")
self.assertGreater(self.in_msg['id'], 0,
"Received SMS MozSmsMessage.id should be > 0")
self.assertEqual(self.in_msg['delivery'], 'received',
"Received SMS MozSmsMessage.delivery should be 'received'")

# mark received message status as unread and verify
self.mark_message_status(self.in_msg['id'], is_read=False)
sms = self.get_message(self.in_msg['id'])
self.assertTrue(sms['read'] is False,
"Received SMS MozSmsMessage.read field should be False")

# mark received message status as read and verify
self.mark_message_status(self.in_msg['id'], is_read=True)
sms = self.get_message(self.in_msg['id'])
self.assertTrue(sms['read'] is True,
"Received SMS MozSmsMessage.read field should be True")

0 comments on commit d364552

Please sign in to comment.