js/xpconnect/tests/unit/test_bug872772.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 const Cu = Components.utils;
     2 function run_test() {
     4   // Make a content sandbox with an Xrayable object.
     5   // NB: We use an nsEP here so that we can have access to Components, but still
     6   // have Xray behavior from this scope.
     7   var contentSB = new Cu.Sandbox(['http://www.google.com'],
     8                                  { wantGlobalProperties: ["XMLHttpRequest"], wantComponents: true });
    10   // Make an XHR in the content sandbox.
    11   Cu.evalInSandbox('xhr = new XMLHttpRequest();', contentSB);
    13   // Make sure that waivers can be set as Xray expandos.
    14   var xhr = contentSB.xhr;
    15   do_check_true(Cu.isXrayWrapper(xhr));
    16   xhr.unwaivedExpando = xhr;
    17   do_check_true(Cu.isXrayWrapper(xhr.unwaivedExpando));
    18   var waived = xhr.wrappedJSObject;
    19   do_check_true(!Cu.isXrayWrapper(waived));
    20   xhr.waivedExpando = waived;
    21   do_check_true(!Cu.isXrayWrapper(xhr.waivedExpando));
    23   // Try the same thing for getters/setters, even though that's kind of
    24   // contrived.
    25   Cu.evalInSandbox('function f() {}', contentSB);
    26   var f = contentSB.f;
    27   var fWaiver = Cu.waiveXrays(f);
    28   do_check_true(f != fWaiver);
    29   do_check_true(Cu.unwaiveXrays(fWaiver) === f);
    30   Object.defineProperty(xhr, 'waivedAccessors', {get: fWaiver, set: fWaiver});
    31   var desc = Object.getOwnPropertyDescriptor(xhr, 'waivedAccessors');
    32   do_check_true(desc.get === fWaiver);
    33   do_check_true(desc.set === fWaiver);
    35   // Make sure we correctly handle same-compartment security wrappers.
    36   var unwaivedC = contentSB.Components;
    37   do_check_true(Cu.isXrayWrapper(unwaivedC));
    38   var waivedC = unwaivedC.wrappedJSObject;
    39   do_check_true(waivedC && unwaivedC && (waivedC != unwaivedC));
    40   xhr.waivedC = waivedC;
    41   do_check_true(xhr.waivedC === waivedC);
    42   do_check_true(Cu.unwaiveXrays(xhr.waivedC) === unwaivedC);
    43 }

mercurial