dom/devicestorage/test/devicestorage_common.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.

     1 /**
     2  * Any copyright is dedicated to the Public Domain.
     3  * http://creativecommons.org/publicdomain/zero/1.0/
     4  */
     6 var oldVal = false;
     8 Object.defineProperty(Array.prototype, "remove", {
     9   enumerable: false,
    10   configurable: false,
    11   writable: false,
    12   value: function(from, to) {
    13     // Array Remove - By John Resig (MIT Licensed)
    14     var rest = this.slice((to || from) + 1 || this.length);
    15     this.length = from < 0 ? this.length + from : from;
    16     return this.push.apply(this, rest);
    17   }
    18 });
    20 function devicestorage_setup() {
    22   // ensure that the directory we are writing into is empty
    23   try {
    24     const Cc = SpecialPowers.Cc;
    25     const Ci = SpecialPowers.Ci;
    26     var directoryService = Cc["@mozilla.org/file/directory_service;1"].getService(Ci.nsIProperties);
    27     var f = directoryService.get("TmpD", Ci.nsIFile);
    28     f.appendRelativePath("device-storage-testing");
    29     f.remove(true);
    30   } catch(e) {}
    32   SimpleTest.waitForExplicitFinish();
    33   if (SpecialPowers.isMainProcess()) {
    34     try {
    35       oldVal = SpecialPowers.getBoolPref("device.storage.enabled");
    36     } catch(e) {}
    37     SpecialPowers.setBoolPref("device.storage.enabled", true);
    38     SpecialPowers.setBoolPref("device.storage.testing", true);
    39     SpecialPowers.setBoolPref("device.storage.prompt.testing", true);
    40   }
    41 }
    43 function devicestorage_cleanup() {
    44   if (SpecialPowers.isMainProcess()) {
    45     SpecialPowers.setBoolPref("device.storage.enabled", oldVal);
    46     SpecialPowers.setBoolPref("device.storage.testing", false);
    47     SpecialPowers.setBoolPref("device.storage.prompt.testing", false);
    48   }
    49   SimpleTest.finish();
    50 }
    52 function getRandomBuffer() {
    53   var size = 1024;
    54   var buffer = new ArrayBuffer(size);
    55   var view = new Uint8Array(buffer);
    56   for (var i = 0; i < size; i++) {
    57     view[i] = parseInt(Math.random() * 255);
    58   }
    59   return buffer;
    60 }
    62 function createRandomBlob(mime) {
    63   return blob = new Blob([getRandomBuffer()], {type: mime});
    64 }
    66 function randomFilename(l) {
    67   var set = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZ";
    68   var result = "";
    69   for (var i=0; i<l; i++) {
    70     var r = Math.floor(set.length * Math.random());
    71     result += set.substring(r, r + 1);
    72   }
    73   return result;
    74 }
    76 function reportErrorAndQuit(e) {
    77   ok(false, "handleError was called : " + e.target.error.name);
    78   devicestorage_cleanup();
    79 }

mercurial