dom/mobilemessage/tests/marionette/test_getmessage_notfound.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* Any copyright is dedicated to the Public Domain.
michael@0 2 * http://creativecommons.org/publicdomain/zero/1.0/ */
michael@0 3
michael@0 4 MARIONETTE_TIMEOUT = 60000;
michael@0 5
michael@0 6 SpecialPowers.setBoolPref("dom.sms.enabled", true);
michael@0 7 SpecialPowers.addPermission("sms", true, document);
michael@0 8
michael@0 9 let manager = window.navigator.mozMobileMessage;
michael@0 10 let myNumber = "15555215554";
michael@0 11 let inText = "Incoming SMS message. Mozilla Firefox OS!";
michael@0 12 let remoteNumber = "5559997777";
michael@0 13 let inSmsId = 0;
michael@0 14
michael@0 15 function verifyInitialState() {
michael@0 16 log("Verifying initial state.");
michael@0 17 ok(manager instanceof MozMobileMessageManager,
michael@0 18 "manager is instance of " + manager.constructor);
michael@0 19 simulateIncomingSms();
michael@0 20 }
michael@0 21
michael@0 22 function simulateIncomingSms() {
michael@0 23 log("Simulating incoming SMS.");
michael@0 24
michael@0 25 manager.onreceived = function onreceived(event) {
michael@0 26 log("Received 'onreceived' event.");
michael@0 27 let incomingSms = event.message;
michael@0 28 ok(incomingSms, "incoming sms");
michael@0 29 ok(incomingSms.id, "sms id");
michael@0 30 inSmsId = incomingSms.id;
michael@0 31 log("Received SMS (id: " + inSmsId + ").");
michael@0 32 is(incomingSms.body, inText, "msg body");
michael@0 33 is(incomingSms.delivery, "received", "delivery");
michael@0 34 getNonExistentMsg();
michael@0 35 };
michael@0 36 // Simulate incoming sms sent from remoteNumber to our emulator
michael@0 37 runEmulatorCmd("sms send " + remoteNumber + " " + inText, function(result) {
michael@0 38 is(result[0], "OK", "emulator output");
michael@0 39 });
michael@0 40 }
michael@0 41
michael@0 42 function getNonExistentMsg() {
michael@0 43 let msgIdNoExist = inSmsId + 1;
michael@0 44 log("Attempting to get non-existent message (id: " + msgIdNoExist + ").");
michael@0 45 let requestRet = manager.getMessage(msgIdNoExist);
michael@0 46 ok(requestRet, "smsrequest obj returned");
michael@0 47
michael@0 48 requestRet.onsuccess = function(event) {
michael@0 49 log("Received 'onsuccess' smsrequest event.");
michael@0 50 ok(event.target.result, "smsrequest event.target.result");
michael@0 51 let foundSms = event.target.result;
michael@0 52 log("Got SMS (id: " + foundSms.id + ") but should not have.");
michael@0 53 ok(false, "Smsrequest successful when tried to get non-existent sms");
michael@0 54 getMsgInvalidId();
michael@0 55 };
michael@0 56
michael@0 57 requestRet.onerror = function(event) {
michael@0 58 log("Received 'onerror' smsrequest event.");
michael@0 59 ok(event.target.error, "domerror obj");
michael@0 60 is(event.target.error.name, "NotFoundError", "error returned");
michael@0 61 log("Could not get SMS (id: " + msgIdNoExist + ") as expected.");
michael@0 62 getMsgInvalidId();
michael@0 63 };
michael@0 64 }
michael@0 65
michael@0 66 function getMsgInvalidId() {
michael@0 67 invalidId = -1;
michael@0 68 log("Attempting to get sms with invalid id (id: " + invalidId + ").");
michael@0 69 let requestRet = manager.getMessage(invalidId);
michael@0 70 ok(requestRet, "smsrequest obj returned");
michael@0 71
michael@0 72 requestRet.onsuccess = function(event) {
michael@0 73 log("Received 'onsuccess' smsrequest event.");
michael@0 74 ok(event.target.result, "smsrequest event.target.result");
michael@0 75 let foundSms = event.target.result;
michael@0 76 log("Got SMS (id: " + foundSms.id + ") but should not have.");
michael@0 77 ok(false, "Smsrequest successful when tried to get message with " +
michael@0 78 "invalid id (id: " + invalidId + ").");
michael@0 79 deleteMsg();
michael@0 80 };
michael@0 81
michael@0 82 requestRet.onerror = function(event) {
michael@0 83 log("Received 'onerror' smsrequest event.");
michael@0 84 ok(event.target.error, "domerror obj");
michael@0 85 is(event.target.error.name, "NotFoundError", "error returned");
michael@0 86 log("Could not get SMS (id: -1) as expected.");
michael@0 87 deleteMsg();
michael@0 88 };
michael@0 89 }
michael@0 90
michael@0 91 function deleteMsg() {
michael@0 92 log("Deleting SMS (id: " + inSmsId + ").");
michael@0 93 let requestRet = manager.delete(inSmsId);
michael@0 94 ok(requestRet,"smsrequest obj returned");
michael@0 95
michael@0 96 requestRet.onsuccess = function(event) {
michael@0 97 log("Received 'onsuccess' smsrequest event.");
michael@0 98 if(event.target.result){
michael@0 99 cleanUp();
michael@0 100 }
michael@0 101 };
michael@0 102
michael@0 103 requestRet.onerror = function(event) {
michael@0 104 log("Received 'onerror' smsrequest event.");
michael@0 105 ok(event.target.error, "domerror obj");
michael@0 106 ok(false, "manager.delete request returned unexpected error: "
michael@0 107 + event.target.error.name );
michael@0 108 cleanUp();
michael@0 109 };
michael@0 110 }
michael@0 111
michael@0 112 function cleanUp() {
michael@0 113 manager.onreceived = null;
michael@0 114 SpecialPowers.removePermission("sms", document);
michael@0 115 SpecialPowers.setBoolPref("dom.sms.enabled", false);
michael@0 116 finish();
michael@0 117 }
michael@0 118
michael@0 119 // Start the test
michael@0 120 verifyInitialState();

mercurial