1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/xpconnect/tests/chrome/test_APIExposer.xul Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,51 @@ 1.4 +<?xml version="1.0"?> 1.5 +<?xml-stylesheet href="chrome://global/skin" type="text/css"?> 1.6 +<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" 1.7 + type="text/css"?> 1.8 +<!-- 1.9 +https://bugzilla.mozilla.org/show_bug.cgi?id=634156 1.10 +--> 1.11 +<window title="Testing API exposing capabilities" 1.12 + xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> 1.13 + <script type="application/javascript" 1.14 + src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> 1.15 + 1.16 + <!-- test results are displayed in the html:body --> 1.17 + <body xmlns="http://www.w3.org/1999/xhtml"> 1.18 + <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=634156" 1.19 + target="_blank">Mozilla Bug 634156</a> 1.20 + </body> 1.21 + 1.22 + <!-- test code goes here --> 1.23 + <script type="application/javascript"><![CDATA[ 1.24 + const Cu = Components.utils; 1.25 + 1.26 + var sandbox = new Cu.Sandbox("about:blank"); 1.27 + sandbox.ok = ok; 1.28 + sandbox.is = is; 1.29 + Cu.evalInSandbox("Object.defineProperty(Object.prototype, 'getProp', { get: function() { throw 'FAIL: called getter' }, set: function() { throw 'FAIL: called setter'; } })", sandbox); 1.30 + 1.31 + var obj = Cu.createObjectIn(sandbox); 1.32 + is(obj, Cu.waiveXrays(obj), "createObjectIn waives"); 1.33 + is(Object.getPrototypeOf(obj), Cu.waiveXrays(Cu.evalInSandbox("Object.prototype", sandbox)), 1.34 + "Object is a sandbox object"); 1.35 + 1.36 + function genPropDesc(value) { 1.37 + return { enumerable: true, configurable: true, writable: true, 1.38 + value: value }; 1.39 + } 1.40 + const props = { 1.41 + 'getProp': genPropDesc(function() { ok(true, "called prop that shadowed a getter"); }), 1.42 + 'argument': genPropDesc(function(arg) { is(arg, 42, "can pass arguments through"); }), 1.43 + 'returnval': genPropDesc(function() { return 42; }) 1.44 + }; 1.45 + Object.defineProperties(obj, props); 1.46 + Cu.makeObjectPropsNormal(obj); 1.47 + 1.48 + sandbox.api = obj; 1.49 + Cu.evalInSandbox("ok(Object.getPrototypeOf(api) === Object.prototype, 'we have the object we expected'); \ 1.50 + api.getProp(); api.argument(42); is(api.returnval(), 42, 'return value was correct');\ 1.51 + ok(typeof api.getProp === 'function', 'functions are functions');\ 1.52 + ok(Object.getPrototypeOf(api.getProp) === Function.prototype, 'functions come from our scope');", sandbox); 1.53 + ]]></script> 1.54 +</window>