js/xpconnect/tests/chrome/test_bug760109.xul

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 <?xml version="1.0"?>
     2 <?xml-stylesheet type="text/css" href="chrome://global/skin"?>
     3 <?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
     4 <!--
     5 https://bugzilla.mozilla.org/show_bug.cgi?id=760109
     6 -->
     7 <window title="Mozilla Bug 760109"
     8         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
     9   <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
    11   <!-- test results are displayed in the html:body -->
    12   <body xmlns="http://www.w3.org/1999/xhtml">
    13   <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=760109"
    14      target="_blank">Mozilla Bug 760109</a>
    15   </body>
    17   <!-- test code goes here -->
    18   <script type="application/javascript">
    19   <![CDATA[
    21   /** Test for COW prototype remapping.**/
    23   // This gets decompiled and run inside the sandbox.
    24   function sandboxCode() {
    26     // Check that COWs for objects with standard prototypes use the standard
    27     // prototype in the home compartment.
    28     ok(Object.getPrototypeOf(chromeArray) === Array.prototype,
    29        "Array prototype remapped properly");
    30     var protoProto = Object.getPrototypeOf(Object.getPrototypeOf(chromeObject));
    31     ok(protoProto === Object.prototype,
    32        "Object prototype remapped properly");
    34     // Check |constructor|.
    35     // Note that the 'constructor' property of the underlying chrome object
    36     // will be resolved on SomeConstructor.prototype, which has an empty
    37     // __exposedProps__. This means that we shouldn't remap the property, even
    38     // though we'd also be able to find it on Object.prototype. Some recent
    39     // refactoring has made it possible to do the right thing here.
    40     is(typeof chromeObject.constructor, "undefined", "Object constructor does what we expect");
    41     ok(chromeArray.constructor === Array, "Array constructor remapped properly");
    43     // We should be able to .forEach on the Array.
    44     var concat = '';
    45     chromeArray.forEach(function(val) { concat += val; });
    46     is(concat, 'abz', "Should be able to .forEach COW-ed Array");
    48     // Try other Array operations.
    49     is(chromeArray.indexOf('b'), 1, "indexOf works correctly");
    50     is(chromeArray.join(''), concat, "join works correctly");
    51     is(chromeArray.slice(1).join(''), 'bz', "slice works correctly");
    52     is(chromeArray.length, 3, "Able to check array length");
    54     // Try some operations that modify the array.
    55     is(chromeArray.pop(), 'z', "Able to call pop");
    56     is(chromeArray.push('z'), 3, "Able to call push");
    57     chromeArray.reverse();
    58     is(chromeArray.join(''), 'zba', "Able to call reverse");
    59     chromeArray.sort();
    60     is(chromeArray.join(''), 'abz', "Able to call sort");
    62     // Make sure we can see the data on the typed array
    63     is(chromeTypedArray.length, 3, "Able to check typed array length");
    64     is(chromeTypedArray[0], 10, "Able to access typed array data");
    66     // We should be able to .hasOwnProperty on the Object, and have
    67     // it filter the objects we can see.
    68     ok(chromeObject.hasOwnProperty('foo'), "Should see r property");
    69     ok(!chromeObject.hasOwnProperty('bar'), "Shouldn't see non-exposed property");
    70     ok(chromeObject.hasOwnProperty('baz'), "Should see rw property");
    71   }
    73   // We use a constructor to create the test object so that there's an
    74   // intermediate object on the prototype chain between the instance and the
    75   // standard prototype.
    76   function SomeConstructor() {
    77     this.foo = 2;
    78     this.bar = 3;
    79     this.baz = 4;
    80     this.__exposedProps__ = {foo: 'r', baz: 'rw'};
    81   }
    82   SomeConstructor.prototype.__exposedProps__ = {};
    84   const Cu = Components.utils;
    85   var sb = new Cu.Sandbox('http://www.example.org');
    86   sb.chromeArray = ['a', 'b', 'z'];
    87   sb.chromeArray.__exposedProps__ = {};
    88   sb.chromeTypedArray = new Uint8Array([10, 20, 30]);
    89   sb.chromeObject = new SomeConstructor();
    90   sb.ok = ok;
    91   sb.is = is;
    92   Cu.evalInSandbox('(' + sandboxCode.toSource() + ')();', sb);
    94   ]]>
    95   </script>
    96 </window>

mercurial