test_bug1123516_maplikesetlikechrome.xhtml (3413B)
1 <?xml version="1.0"?> 2 <?xml-stylesheet type="text/css" href="chrome://global/skin"?> 3 <?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?> 4 <!-- 5 https://bugzilla.mozilla.org/show_bug.cgi?id=1123516 6 --> 7 <window title="Mozilla Bug 1123516" 8 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> 9 <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> 10 <iframe id="t"></iframe> 11 12 <!-- test results are displayed in the html:body --> 13 <body xmlns="http://www.w3.org/1999/xhtml"> 14 <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1123516" 15 target="_blank">Mozilla Bug 1123516</a> 16 </body> 17 18 <!-- test code goes here --> 19 <script type="application/javascript"> 20 <![CDATA[ 21 /* global TestInterfaceSetlikeNode */ 22 23 /** Test for Bug 1123516 */ 24 function doTest() { 25 var win = $("t").contentWindow; 26 var sandbox = Cu.Sandbox(win, { sandboxPrototype: win }); 27 is(sandbox._content, undefined, "_content does nothing over Xray"); 28 // Test cross-compartment usage of maplike/setlike WebIDL structures. 29 SpecialPowers.pushPrefEnv({set: [['dom.expose_test_interfaces', true]]}, function() { 30 try { 31 var maplike = Cu.evalInSandbox("var m = new TestInterfaceMaplike(); m;", sandbox); 32 maplike.set("test2", 2); 33 is(maplike.get("test2"), 2, "Should be able to create and use maplike/setlike across compartments"); 34 var test = Cu.evalInSandbox("m.get('test2');", sandbox); 35 is(test, 2, "Maplike/setlike should still work in original compartment"); 36 is(maplike.size, 1, "Testing size retrieval across compartments"); 37 } catch(e) { 38 ok(false, "Shouldn't throw when working with cross-compartment maplike/setlike interfaces " + e) 39 }; 40 try { 41 var setlike = Cu.evalInSandbox("var m = new TestInterfaceSetlikeNode(); m.add(document.documentElement); m;", sandbox); 42 is(TestInterfaceSetlikeNode.prototype.has.call(setlike, win.document.documentElement), true, 43 "Cross-compartment unwrapping/comparison has works"); 44 // TODO: Should throw until iterators are handled by Xrays, Bug 1023984 45 try { 46 TestInterfaceSetlikeNode.prototype.keys.call(setlike); 47 ok(false, "Calling iterators via xrays should fail"); 48 /* eslint-disable-next-line no-shadow */ 49 } catch(e) { 50 ok(true, "Calling iterators via xrays should fail"); 51 } 52 53 setlike.forEach((v) => { is(v, win.document.documentElement, "Cross-compartment forEach works"); }); 54 TestInterfaceSetlikeNode.prototype.forEach.call(setlike, 55 (v) => { is(v, win.document.documentElement, "Cross-compartment forEach works"); }); 56 is(TestInterfaceSetlikeNode.prototype.delete.call(setlike, win.document.documentElement), true, 57 "Cross-compartment unwrapping/comparison delete works"); 58 /* eslint-disable-next-line no-shadow */ 59 } catch(e) { 60 ok(false, "Shouldn't throw when working with cross-compartment maplike/setlike interfaces " + e) 61 }; 62 SimpleTest.finish(); 63 }); 64 } 65 66 SimpleTest.waitForExplicitFinish(); 67 addLoadEvent(doTest); 68 ]]> 69 </script> 70 </window>