summaryrefslogtreecommitdiffstats
path: root/dom/bindings/test/test_bug1123516_maplikesetlikechrome.xhtml
diff options
context:
space:
mode:
Diffstat (limited to 'dom/bindings/test/test_bug1123516_maplikesetlikechrome.xhtml')
-rw-r--r--dom/bindings/test/test_bug1123516_maplikesetlikechrome.xhtml70
1 files changed, 70 insertions, 0 deletions
diff --git a/dom/bindings/test/test_bug1123516_maplikesetlikechrome.xhtml b/dom/bindings/test/test_bug1123516_maplikesetlikechrome.xhtml
new file mode 100644
index 0000000000..724c40cbd3
--- /dev/null
+++ b/dom/bindings/test/test_bug1123516_maplikesetlikechrome.xhtml
@@ -0,0 +1,70 @@
+<?xml version="1.0"?>
+<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
+<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=1123516
+-->
+<window title="Mozilla Bug 1123516"
+ xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
+ <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
+ <iframe id="t"></iframe>
+
+ <!-- test results are displayed in the html:body -->
+ <body xmlns="http://www.w3.org/1999/xhtml">
+ <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1123516"
+ target="_blank">Mozilla Bug 1123516</a>
+ </body>
+
+ <!-- test code goes here -->
+ <script type="application/javascript">
+ <![CDATA[
+ /* global TestInterfaceSetlikeNode */
+
+ /** Test for Bug 1123516 **/
+ function doTest() {
+ var win = $("t").contentWindow;
+ var sandbox = Cu.Sandbox(win, { sandboxPrototype: win });
+ is(sandbox._content, undefined, "_content does nothing over Xray");
+ // Test cross-compartment usage of maplike/setlike WebIDL structures.
+ SpecialPowers.pushPrefEnv({set: [['dom.expose_test_interfaces', true]]}, function() {
+ try {
+ var maplike = Cu.evalInSandbox("var m = new TestInterfaceMaplike(); m;", sandbox);
+ maplike.set("test2", 2);
+ is(maplike.get("test2"), 2, "Should be able to create and use maplike/setlike across compartments");
+ var test = Cu.evalInSandbox("m.get('test2');", sandbox);
+ is(test, 2, "Maplike/setlike should still work in original compartment");
+ is(maplike.size, 1, "Testing size retrieval across compartments");
+ } catch(e) {
+ ok(false, "Shouldn't throw when working with cross-compartment maplike/setlike interfaces " + e)
+ };
+ try {
+ var setlike = Cu.evalInSandbox("var m = new TestInterfaceSetlikeNode(); m.add(document.documentElement); m;", sandbox);
+ is(TestInterfaceSetlikeNode.prototype.has.call(setlike, win.document.documentElement), true,
+ "Cross-compartment unwrapping/comparison has works");
+ // TODO: Should throw until iterators are handled by Xrays, Bug 1023984
+ try {
+ TestInterfaceSetlikeNode.prototype.keys.call(setlike);
+ ok(false, "Calling iterators via xrays should fail");
+ /* eslint-disable-next-line no-shadow */
+ } catch(e) {
+ ok(true, "Calling iterators via xrays should fail");
+ }
+
+ setlike.forEach((v,k,t) => { is(v, win.document.documentElement, "Cross-compartment forEach works"); });
+ TestInterfaceSetlikeNode.prototype.forEach.call(setlike,
+ (v,k,t) => { is(v, win.document.documentElement, "Cross-compartment forEach works"); });
+ is(TestInterfaceSetlikeNode.prototype.delete.call(setlike, win.document.documentElement), true,
+ "Cross-compartment unwrapping/comparison delete works");
+ /* eslint-disable-next-line no-shadow */
+ } catch(e) {
+ ok(false, "Shouldn't throw when working with cross-compartment maplike/setlike interfaces " + e)
+ };
+ SimpleTest.finish();
+ });
+ }
+
+ SimpleTest.waitForExplicitFinish();
+ addLoadEvent(doTest);
+ ]]>
+ </script>
+</window>