1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/xpconnect/tests/unit/test_bug872772.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,43 @@ 1.4 +const Cu = Components.utils; 1.5 +function run_test() { 1.6 + 1.7 + // Make a content sandbox with an Xrayable object. 1.8 + // NB: We use an nsEP here so that we can have access to Components, but still 1.9 + // have Xray behavior from this scope. 1.10 + var contentSB = new Cu.Sandbox(['http://www.google.com'], 1.11 + { wantGlobalProperties: ["XMLHttpRequest"], wantComponents: true }); 1.12 + 1.13 + // Make an XHR in the content sandbox. 1.14 + Cu.evalInSandbox('xhr = new XMLHttpRequest();', contentSB); 1.15 + 1.16 + // Make sure that waivers can be set as Xray expandos. 1.17 + var xhr = contentSB.xhr; 1.18 + do_check_true(Cu.isXrayWrapper(xhr)); 1.19 + xhr.unwaivedExpando = xhr; 1.20 + do_check_true(Cu.isXrayWrapper(xhr.unwaivedExpando)); 1.21 + var waived = xhr.wrappedJSObject; 1.22 + do_check_true(!Cu.isXrayWrapper(waived)); 1.23 + xhr.waivedExpando = waived; 1.24 + do_check_true(!Cu.isXrayWrapper(xhr.waivedExpando)); 1.25 + 1.26 + // Try the same thing for getters/setters, even though that's kind of 1.27 + // contrived. 1.28 + Cu.evalInSandbox('function f() {}', contentSB); 1.29 + var f = contentSB.f; 1.30 + var fWaiver = Cu.waiveXrays(f); 1.31 + do_check_true(f != fWaiver); 1.32 + do_check_true(Cu.unwaiveXrays(fWaiver) === f); 1.33 + Object.defineProperty(xhr, 'waivedAccessors', {get: fWaiver, set: fWaiver}); 1.34 + var desc = Object.getOwnPropertyDescriptor(xhr, 'waivedAccessors'); 1.35 + do_check_true(desc.get === fWaiver); 1.36 + do_check_true(desc.set === fWaiver); 1.37 + 1.38 + // Make sure we correctly handle same-compartment security wrappers. 1.39 + var unwaivedC = contentSB.Components; 1.40 + do_check_true(Cu.isXrayWrapper(unwaivedC)); 1.41 + var waivedC = unwaivedC.wrappedJSObject; 1.42 + do_check_true(waivedC && unwaivedC && (waivedC != unwaivedC)); 1.43 + xhr.waivedC = waivedC; 1.44 + do_check_true(xhr.waivedC === waivedC); 1.45 + do_check_true(Cu.unwaiveXrays(xhr.waivedC) === unwaivedC); 1.46 +}