Sat, 03 Jan 2015 20:18:00 +0100
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.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 | // https://developer.mozilla.org/en-US/docs/DOM/SmsManager |
michael@0 | 11 | let maxCharsPerSms = 160; |
michael@0 | 12 | let maxSegments = 10; // 10 message segments concatenated into 1 multipart SMS |
michael@0 | 13 | |
michael@0 | 14 | function verifyInitialState() { |
michael@0 | 15 | log("Verifying initial state."); |
michael@0 | 16 | ok(manager instanceof MozMobileMessageManager, |
michael@0 | 17 | "manager is instance of " + manager.constructor); |
michael@0 | 18 | sendSms(); |
michael@0 | 19 | } |
michael@0 | 20 | |
michael@0 | 21 | function sendSms() { |
michael@0 | 22 | let destNumber = "5551234567"; |
michael@0 | 23 | let msgText = ""; |
michael@0 | 24 | let gotReqOnSuccess = false; |
michael@0 | 25 | let gotSmsOnSent = false; |
michael@0 | 26 | let sentSms; |
michael@0 | 27 | |
michael@0 | 28 | // Build the message text |
michael@0 | 29 | msgText = new Array((maxCharsPerSms * maxSegments) + 1).join('a'); |
michael@0 | 30 | log("Sending multipart SMS (" + msgText.length + " chars total)."); |
michael@0 | 31 | |
michael@0 | 32 | manager.onsent = function(event) { |
michael@0 | 33 | manager.onsent = null; |
michael@0 | 34 | log("Received 'onsent' event."); |
michael@0 | 35 | |
michael@0 | 36 | gotSmsOnSent = true; |
michael@0 | 37 | sentSms = event.message; |
michael@0 | 38 | ok(sentSms, "outgoing sms"); |
michael@0 | 39 | ok(sentSms.id, "sms id"); |
michael@0 | 40 | log("Sent SMS (id: " + sentSms.id + ")."); |
michael@0 | 41 | ok(sentSms.threadId, "thread id"); |
michael@0 | 42 | is(sentSms.body.length, msgText.length, "text length"); |
michael@0 | 43 | is(sentSms.body, msgText, "msg body"); |
michael@0 | 44 | is(sentSms.delivery, "sent", "delivery"); |
michael@0 | 45 | |
michael@0 | 46 | if (gotReqOnSuccess) { verifySmsExists(sentSms); } |
michael@0 | 47 | }; |
michael@0 | 48 | |
michael@0 | 49 | let requestRet = manager.send(destNumber, msgText); |
michael@0 | 50 | ok(requestRet, "smsrequest obj returned"); |
michael@0 | 51 | |
michael@0 | 52 | requestRet.onsuccess = function(event) { |
michael@0 | 53 | log("Received 'onsuccess' smsrequest event."); |
michael@0 | 54 | gotReqOnSuccess = true; |
michael@0 | 55 | if (event.target.result) { |
michael@0 | 56 | if (gotSmsOnSent) { verifySmsExists(sentSms); } |
michael@0 | 57 | } else { |
michael@0 | 58 | log("smsrequest returned false for manager.send"); |
michael@0 | 59 | ok(false, "SMS send failed"); |
michael@0 | 60 | cleanUp(); |
michael@0 | 61 | } |
michael@0 | 62 | }; |
michael@0 | 63 | |
michael@0 | 64 | requestRet.onerror = function(event) { |
michael@0 | 65 | log("Received 'onerror' smsrequest event."); |
michael@0 | 66 | ok(event.target.error, "domerror obj"); |
michael@0 | 67 | ok(false, "manager.send request returned unexpected error: " + |
michael@0 | 68 | event.target.error.name); |
michael@0 | 69 | cleanUp(); |
michael@0 | 70 | }; |
michael@0 | 71 | } |
michael@0 | 72 | |
michael@0 | 73 | function verifySmsExists(sentSms) { |
michael@0 | 74 | log("Getting SMS (id: " + sentSms.id + ")."); |
michael@0 | 75 | let requestRet = manager.getMessage(sentSms.id); |
michael@0 | 76 | ok(requestRet, "smsrequest obj returned"); |
michael@0 | 77 | |
michael@0 | 78 | requestRet.onsuccess = function(event) { |
michael@0 | 79 | log("Received 'onsuccess' smsrequest event."); |
michael@0 | 80 | ok(event.target.result, "smsrequest event.target.result"); |
michael@0 | 81 | let foundSms = event.target.result; |
michael@0 | 82 | is(foundSms.id, sentSms.id, "found SMS id matches"); |
michael@0 | 83 | is(foundSms.threadId, sentSms.threadId, "found SMS thread id matches"); |
michael@0 | 84 | is(foundSms.body.length, sentSms.body.length, "found SMS text length"); |
michael@0 | 85 | is(foundSms.body, sentSms.body, "found SMS msg text matches"); |
michael@0 | 86 | log("Got SMS (id: " + foundSms.id + ") as expected."); |
michael@0 | 87 | deleteSms(sentSms); |
michael@0 | 88 | }; |
michael@0 | 89 | |
michael@0 | 90 | requestRet.onerror = function(event) { |
michael@0 | 91 | log("Received 'onerror' smsrequest event."); |
michael@0 | 92 | ok(event.target.error, "domerror obj"); |
michael@0 | 93 | is(event.target.error.name, "NotFoundError", "error returned"); |
michael@0 | 94 | log("Could not get SMS (id: " + sentSms.id + ") but should have."); |
michael@0 | 95 | ok(false, "SMS was not found"); |
michael@0 | 96 | cleanUp(); |
michael@0 | 97 | }; |
michael@0 | 98 | } |
michael@0 | 99 | |
michael@0 | 100 | function deleteSms(smsMsgObj) { |
michael@0 | 101 | log("Deleting SMS (id: " + smsMsgObj.id + ") using smsmsg obj parameter."); |
michael@0 | 102 | let requestRet = manager.delete(smsMsgObj); |
michael@0 | 103 | ok(requestRet,"smsrequest obj returned"); |
michael@0 | 104 | |
michael@0 | 105 | requestRet.onsuccess = function(event) { |
michael@0 | 106 | log("Received 'onsuccess' smsrequest event."); |
michael@0 | 107 | if (event.target.result) { |
michael@0 | 108 | cleanUp(); |
michael@0 | 109 | } else { |
michael@0 | 110 | log("smsrequest returned false for manager.delete"); |
michael@0 | 111 | ok(false, "SMS delete failed"); |
michael@0 | 112 | cleanUp(); |
michael@0 | 113 | } |
michael@0 | 114 | }; |
michael@0 | 115 | |
michael@0 | 116 | requestRet.onerror = function(event) { |
michael@0 | 117 | log("Received 'onerror' smsrequest event."); |
michael@0 | 118 | ok(event.target.error, "domerror obj"); |
michael@0 | 119 | ok(false, "manager.delete request returned unexpected error: " + |
michael@0 | 120 | event.target.error.name); |
michael@0 | 121 | cleanUp(); |
michael@0 | 122 | }; |
michael@0 | 123 | } |
michael@0 | 124 | |
michael@0 | 125 | function cleanUp() { |
michael@0 | 126 | SpecialPowers.removePermission("sms", document); |
michael@0 | 127 | SpecialPowers.clearUserPref("dom.sms.enabled"); |
michael@0 | 128 | finish(); |
michael@0 | 129 | } |
michael@0 | 130 | |
michael@0 | 131 | // Start the test |
michael@0 | 132 | verifyInitialState(); |