summaryrefslogtreecommitdiffstats
path: root/dom/bindings/test/test_bug1123516_maplikesetlikechrome.xul
blob: 4bc45cdddcde391903ccc138a13b2c1e90c3b2e4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?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 type="application/javascript" 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[

     /** Test for Bug 1123516 **/
     const Cu = Components.utils;
     function doTest() {
       var win = $("t").contentWindow;
       var sandbox = Components.utils.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 = Components.utils.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 = Components.utils.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 = Components.utils.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 {
             var e = TestInterfaceSetlikeNode.prototype.keys.call(setlike);
             ok(false, "Calling iterators via xrays should fail");
           } 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");
         } catch(e) {
           ok(false, "Shouldn't throw when working with cross-compartment maplike/setlike interfaces " + e)
         };
         SimpleTest.finish();
       });
     }

     SimpleTest.waitForExplicitFinish();
     addLoadEvent(doTest);
   ]]>
  </script>
</window>