js/xpconnect/tests/unit/test_bug872772.js

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:ca342a42de96
1 const Cu = Components.utils;
2 function run_test() {
3
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 });
9
10 // Make an XHR in the content sandbox.
11 Cu.evalInSandbox('xhr = new XMLHttpRequest();', contentSB);
12
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));
22
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);
34
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