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.

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

mercurial