summaryrefslogtreecommitdiffstats
path: root/js/xpconnect/tests/mochitest/test_nac.xhtml
blob: 0f18fe48986e3b190b5517c99f01f088e8798693 (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
<html xmlns="http://www.w3.org/1999/xhtml">
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=914618
-->
<head>
  <title>Test for Bug 914618</title>
  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
  <bindings xmlns="http://www.mozilla.org/xbl"
            xmlns:html="http://www.w3.org/1999/xhtml">
    <binding id="testBinding" chromeOnlyContent="true">
      <!-- The root of the anonymous subtree is special, and is not allowed to
           be adopted, among other things. Work with a child of the root. -->
      <content><html:div><html:span id="nac">hidden text</html:span></html:div></content>
      <implementation>
        <constructor>
          var win = XPCNativeWrapper.unwrap(window);
          var nac = document.getAnonymousNodes(this)[0].firstChild;
          win.is(nac.textContent, "hidden text", "XBL can see NAC");
          win.playWithNAC(nac);
        </constructor>
      </implementation>
    </binding>
  </bindings>
  <script type="application/javascript">
  <![CDATA[

  /** Test for Bug 914618 **/
  SimpleTest.waitForExplicitFinish();

  function checkThrows(fn) {
    try {
      fn();
      ok(false, "Should have thrown");
    } catch (e) {
      ok(/denied|insecure|/.test(e), "Should have thrown security error");
    }
  }

  function playWithNAC(nac) {
    checkThrows(function() { nac.toString(); });
    checkThrows(function() { nac.textContent; });
    var iwin = document.getElementById('ifr').contentWindow;
    iwin.nac = window.nac = nac;
    checkThrows(new iwin.Function('nac.toString();'));
    checkThrows(new iwin.Function('nac.textContent;'));

    SimpleTest.finish();
  }

  ]]>
</script>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=914618">Mozilla Bug 914618</a>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<div id="bindingSink" style="-moz-binding: url(#testBinding);"></div>
<iframe id="ifr"></iframe>
<pre id="test">
</pre>
</body>
</html>