dom/telephony/test/marionette/test_dsds_default_service_id.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 MARIONETTE_CONTEXT = "chrome";
michael@0 6
michael@0 7 Cu.import("resource://gre/modules/Promise.jsm");
michael@0 8
michael@0 9 const TELEPHONY_PROVIDER_CONTRACTID =
michael@0 10 "@mozilla.org/telephony/telephonyprovider;1";
michael@0 11
michael@0 12 const PREF_RIL_NUM_RADIO_INTERFACES = "ril.numRadioInterfaces";
michael@0 13 const PREF_DEFAULT_SERVICE_ID = "dom.telephony.defaultServiceId";
michael@0 14
michael@0 15 function setPrefAndVerify(prefKey, setVal, service, attrName, expectedVal, deferred) {
michael@0 16 log(" Set '" + prefKey + "' to " + setVal);
michael@0 17 Services.prefs.setIntPref(prefKey, setVal);
michael@0 18 let prefVal = Services.prefs.getIntPref(prefKey);
michael@0 19 is(prefVal, setVal, "'" + prefKey + "' set to " + setVal);
michael@0 20
michael@0 21 window.setTimeout(function() {
michael@0 22 let defaultVal = service[attrName];
michael@0 23 is(defaultVal, expectedVal, attrName);
michael@0 24
michael@0 25 deferred.resolve(service);
michael@0 26 }, 0);
michael@0 27 }
michael@0 28
michael@0 29 function getNumRadioInterfaces() {
michael@0 30 let deferred = Promise.defer();
michael@0 31
michael@0 32 window.setTimeout(function() {
michael@0 33 let numRil = Services.prefs.getIntPref(PREF_RIL_NUM_RADIO_INTERFACES);
michael@0 34 log("numRil = " + numRil);
michael@0 35
michael@0 36 deferred.resolve(numRil);
michael@0 37 }, 0);
michael@0 38
michael@0 39 return deferred.promise;
michael@0 40 }
michael@0 41
michael@0 42 function getService(contractId, ifaceName) {
michael@0 43 let deferred = Promise.defer();
michael@0 44
michael@0 45 window.setTimeout(function() {
michael@0 46 log("Getting service for " + ifaceName);
michael@0 47 let service = Cc[contractId].getService(Ci[ifaceName]);
michael@0 48 ok(service, "service.constructor is " + service.constructor);
michael@0 49
michael@0 50 deferred.resolve(service);
michael@0 51 }, 0);
michael@0 52
michael@0 53 return deferred.promise;
michael@0 54 }
michael@0 55
michael@0 56 function checkInitialEquality(attrName, prefKey, service) {
michael@0 57 let deferred = Promise.defer();
michael@0 58
michael@0 59 log(" Checking initial value for '" + prefKey + "'");
michael@0 60 let origPrefVal = Services.prefs.getIntPref(prefKey);
michael@0 61 ok(isFinite(origPrefVal), "default '" + prefKey + "' value");
michael@0 62
michael@0 63 window.setTimeout(function() {
michael@0 64 let defaultVal = service[attrName];
michael@0 65 is(defaultVal, origPrefVal, attrName);
michael@0 66
michael@0 67 deferred.resolve(service);
michael@0 68 }, 0);
michael@0 69
michael@0 70 return deferred.promise;
michael@0 71 }
michael@0 72
michael@0 73 function checkSetToNegtiveValue(attrName, prefKey, service) {
michael@0 74 let deferred = Promise.defer();
michael@0 75
michael@0 76 // Set to -1 and verify defaultVal == 0.
michael@0 77 setPrefAndVerify(prefKey, -1, service, attrName, 0, deferred);
michael@0 78
michael@0 79 return deferred.promise;
michael@0 80 }
michael@0 81
michael@0 82 function checkSetToOverflowedValue(attrName, prefKey, numRil, service) {
michael@0 83 let deferred = Promise.defer();
michael@0 84
michael@0 85 // Set to larger-equal than numRil and verify defaultVal == 0.
michael@0 86 setPrefAndVerify(prefKey, numRil, service, attrName, 0, deferred);
michael@0 87
michael@0 88 return deferred.promise;
michael@0 89 }
michael@0 90
michael@0 91 function checkValueChange(attrName, prefKey, numRil, service) {
michael@0 92 let deferred = Promise.defer();
michael@0 93
michael@0 94 if (numRil > 1) {
michael@0 95 // Set to (numRil - 1) and verify defaultVal equals.
michael@0 96 setPrefAndVerify(prefKey, numRil - 1, service, attrName, numRil - 1, deferred);
michael@0 97 } else {
michael@0 98 window.setTimeout(function() {
michael@0 99 deferred.resolve(service);
michael@0 100 }, 0);
michael@0 101 }
michael@0 102
michael@0 103 return deferred.promise;
michael@0 104 }
michael@0 105
michael@0 106 function verify(contractId, ifaceName, attrName, prefKey, numRil) {
michael@0 107 let deferred = Promise.defer();
michael@0 108
michael@0 109 getService(contractId, ifaceName)
michael@0 110 .then(checkInitialEquality.bind(null, attrName, prefKey))
michael@0 111 .then(checkSetToNegtiveValue.bind(null, attrName, prefKey))
michael@0 112 .then(checkSetToOverflowedValue.bind(null, attrName, prefKey, numRil))
michael@0 113 .then(checkValueChange.bind(null, attrName, prefKey, numRil))
michael@0 114 .then(function() {
michael@0 115 // Reset.
michael@0 116 Services.prefs.clearUserPref(prefKey);
michael@0 117
michael@0 118 deferred.resolve(numRil);
michael@0 119 });
michael@0 120
michael@0 121 return deferred.promise;
michael@0 122 }
michael@0 123
michael@0 124 getNumRadioInterfaces()
michael@0 125 .then(verify.bind(null, TELEPHONY_PROVIDER_CONTRACTID, "nsITelephonyProvider",
michael@0 126 "defaultServiceId", PREF_DEFAULT_SERVICE_ID))
michael@0 127 .then(finish);

mercurial