js/xpconnect/tests/unit/test_bug809652.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 /* This Source Code Form is subject to the terms of the Mozilla Public
     2  * License, v. 2.0. If a copy of the MPL was not distributed with this
     3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     5 /* See https://bugzilla.mozilla.org/show_bug.cgi?id=813901 */
     7 const Cu = Components.utils;
     8 const TypedArrays = [ Int8Array, Uint8Array, Int16Array, Uint16Array,
     9                       Int32Array, Uint32Array, Float32Array, Float64Array,
    10                       Uint8ClampedArray ];
    12 // Make sure that the correct nativecall-y stuff is denied on security wrappers.
    14 function run_test() {
    16   var sb = new Cu.Sandbox('http://www.example.org');
    17   sb.obj = {foo: 2};
    19   /* Set up some typed arrays. */
    20   sb.ab = new ArrayBuffer(8);
    21   for (var i = 0; i < 8; ++i)
    22     new Uint8Array(sb.ab)[i] = i * 10;
    23   sb.ta = [];
    24   TypedArrays.forEach(function(f) sb.ta.push(new f(sb.ab)));
    25   sb.dv = new DataView(sb.ab);
    27   /* Things that should throw. */
    28   checkThrows("Object.prototype.__lookupSetter__('__proto__').call(obj, {});", sb);
    29   sb.re = /f/;
    30   checkThrows("RegExp.prototype.exec.call(re, 'abcdefg').index", sb);
    31   sb.d = new Date();
    32   checkThrows("Date.prototype.setYear.call(d, 2011)", sb);
    33   sb.m = new Map();
    34   checkThrows("(new Map()).clear.call(m)", sb);
    35   checkThrows("ArrayBuffer.prototype.__lookupGetter__('byteLength').call(ab);", sb);
    36   checkThrows("ArrayBuffer.prototype.slice.call(ab, 0);", sb);
    37   checkThrows("DataView.prototype.getInt8.call(dv, 0);", sb);
    39   /* Now that Date is on Xrays, these should all throw. */
    40   checkThrows("Date.prototype.getYear.call(d)", sb);
    41   checkThrows("Date.prototype.valueOf.call(d)", sb);
    42   checkThrows("d.valueOf()", sb);
    43   checkThrows("Date.prototype.toString.call(d)", sb);
    44   checkThrows("d.toString()", sb);
    46   /* Typed arrays. */
    47   function testForTypedArray(t) {
    48     sb.curr = t;
    49     do_check_eq(Cu.evalInSandbox("this[curr.constructor.name].prototype.subarray.call(curr, 0)[0]", sb), t[0]);
    50     do_check_eq(Cu.evalInSandbox("(new this[curr.constructor.name]).__lookupGetter__('length').call(curr)", sb), t.length);
    51     do_check_eq(Cu.evalInSandbox("(new this[curr.constructor.name]).__lookupGetter__('buffer').call(curr)", sb), sb.ab);
    52     do_check_eq(Cu.evalInSandbox("(new this[curr.constructor.name]).__lookupGetter__('byteOffset').call(curr)", sb), t.byteOffset);
    53     do_check_eq(Cu.evalInSandbox("(new this[curr.constructor.name]).__lookupGetter__('byteLength').call(curr)", sb), t.byteLength);
    54   }
    55   sb.ta.forEach(testForTypedArray);
    56 }
    58 function checkThrows(expression, sb) {
    59   var result = Cu.evalInSandbox('(function() { try { ' + expression + '; return "allowed"; } catch (e) { return e.toString(); }})();', sb);
    60   dump('result: ' + result + '\n\n\n');
    61   do_check_true(!!/denied/.exec(result));
    62 }

mercurial