dom/mobilemessage/tests/marionette/test_mark_msg_read_error.js

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

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.addPermission("sms", true, document);
michael@0 7 SpecialPowers.setBoolPref("dom.sms.enabled", true);
michael@0 8
michael@0 9 let manager = window.navigator.mozMobileMessage;
michael@0 10 let smsId;
michael@0 11
michael@0 12 function verifyInitialState() {
michael@0 13 log("Verifying initial state.");
michael@0 14 ok(manager instanceof MozMobileMessageManager,
michael@0 15 "manager is instance of " + manager.constructor);
michael@0 16 simulateIncomingSms();
michael@0 17 }
michael@0 18
michael@0 19 function simulateIncomingSms() {
michael@0 20 let text = "Incoming SMS courtesy of Firefox OS";
michael@0 21 let remoteNumber = "5557779999";
michael@0 22
michael@0 23 log("Simulating incoming SMS.");
michael@0 24
michael@0 25 // Simulate incoming SMS sent from remoteNumber to our emulator
michael@0 26 rcvdEmulatorCallback = false;
michael@0 27 runEmulatorCmd("sms send " + remoteNumber + " " + text, function(result) {
michael@0 28 is(result[0], "OK", "emulator callback");
michael@0 29 rcvdEmulatorCallback = true;
michael@0 30 });
michael@0 31 }
michael@0 32
michael@0 33 // Callback for incoming SMS
michael@0 34 manager.onreceived = function onreceived(event) {
michael@0 35 log("Received 'onreceived' sms event.");
michael@0 36 let incomingSms = event.message;
michael@0 37 log("Received SMS (id: " + incomingSms.id + ").");
michael@0 38 is(incomingSms.read, false, "incoming message read");
michael@0 39 smsId = incomingSms.id;
michael@0 40
michael@0 41 // Wait for emulator to catch up before continuing
michael@0 42 waitFor(test1, function() {
michael@0 43 return(rcvdEmulatorCallback);
michael@0 44 });
michael@0 45 };
michael@0 46
michael@0 47 function markMsgError(invalidId, readBool, nextFunction) {
michael@0 48 let requestRet = manager.markMessageRead(invalidId, readBool);
michael@0 49 ok(requestRet, "smsrequest obj returned");
michael@0 50
michael@0 51 requestRet.onsuccess = function(event) {
michael@0 52 log("Received 'onsuccess' smsrequest event, but expected error.");
michael@0 53 ok(false, "Smsrequest should have returned error but did not");
michael@0 54 nextFunction();
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 nextFunction();
michael@0 62 };
michael@0 63 }
michael@0 64
michael@0 65 function test1() {
michael@0 66 // Mark message read for a message that doesn't exist, expect error
michael@0 67 let msgIdNoExist = smsId + 1;
michael@0 68 log("Attempting to mark non-existent sms (id: " + msgIdNoExist
michael@0 69 + ") read, expect error.");
michael@0 70 markMsgError(msgIdNoExist, true, test2);
michael@0 71 }
michael@0 72
michael@0 73 function test2() {
michael@0 74 // Mark message read using invalid SMS id, expect error
michael@0 75 invalidId = -1;
michael@0 76 log("Attempting to mark sms unread using an invalid id (id: " + invalidId
michael@0 77 + "), expect error.");
michael@0 78 markMsgError(invalidId, false, deleteMsg);
michael@0 79 }
michael@0 80
michael@0 81 function deleteMsg() {
michael@0 82 log("Deleting SMS (id: " + smsId + ").");
michael@0 83 let request = manager.delete(smsId);
michael@0 84 ok(request instanceof DOMRequest,
michael@0 85 "request is instanceof " + request.constructor);
michael@0 86
michael@0 87 request.onsuccess = function(event) {
michael@0 88 log("Received 'onsuccess' smsrequest event.");
michael@0 89 if (event.target.result) {
michael@0 90 // Message deleted
michael@0 91 cleanUp();
michael@0 92 } else {
michael@0 93 log("SMS delete failed.");
michael@0 94 ok(false,"manager.delete request returned false");
michael@0 95 cleanUp();
michael@0 96 }
michael@0 97 };
michael@0 98
michael@0 99 request.onerror = function(event) {
michael@0 100 log("Received 'onerror' smsrequest event.");
michael@0 101 ok(event.target.error, "domerror obj");
michael@0 102 ok(false, "manager.delete request returned unexpected error: "
michael@0 103 + event.target.error.name );
michael@0 104 cleanUp();
michael@0 105 };
michael@0 106 }
michael@0 107
michael@0 108 function cleanUp() {
michael@0 109 manager.onreceived = null;
michael@0 110 SpecialPowers.removePermission("sms", document);
michael@0 111 SpecialPowers.clearUserPref("dom.sms.enabled");
michael@0 112 finish();
michael@0 113 }
michael@0 114
michael@0 115 // Start the test
michael@0 116 verifyInitialState();

mercurial