js/xpconnect/tests/mochitest/test_nac.xhtml

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/xpconnect/tests/mochitest/test_nac.xhtml	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,64 @@
     1.4 +<html xmlns="http://www.w3.org/1999/xhtml">
     1.5 +<!--
     1.6 +https://bugzilla.mozilla.org/show_bug.cgi?id=914618
     1.7 +-->
     1.8 +<head>
     1.9 +  <title>Test for Bug 914618</title>
    1.10 +  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    1.11 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
    1.12 +  <bindings xmlns="http://www.mozilla.org/xbl"
    1.13 +            xmlns:html="http://www.w3.org/1999/xhtml">
    1.14 +    <binding id="testBinding" chromeOnlyContent="true">
    1.15 +      <!-- The root of the anonymous subtree is special, and is not allowed to
    1.16 +           be adopted, among other things. Work with a child of the root. -->
    1.17 +      <content><html:div><html:span id="nac">hidden text</html:span></html:div></content>
    1.18 +      <implementation>
    1.19 +        <constructor>
    1.20 +          var win = XPCNativeWrapper.unwrap(window);
    1.21 +          var nac = document.getAnonymousNodes(this)[0].firstChild;
    1.22 +          win.is(nac.textContent, "hidden text", "XBL can see NAC");
    1.23 +          win.playWithNAC(nac);
    1.24 +        </constructor>
    1.25 +      </implementation>
    1.26 +    </binding>
    1.27 +  </bindings>
    1.28 +  <script type="application/javascript">
    1.29 +  <![CDATA[
    1.30 +
    1.31 +  /** Test for Bug 914618 **/
    1.32 +  SimpleTest.waitForExplicitFinish();
    1.33 +
    1.34 +  function checkThrows(fn) {
    1.35 +    try {
    1.36 +      fn();
    1.37 +      ok(false, "Should have thrown");
    1.38 +    } catch (e) {
    1.39 +      ok(/denied|insecure|/.test(e), "Should have thrown security error");
    1.40 +    }
    1.41 +  }
    1.42 +
    1.43 +  function playWithNAC(nac) {
    1.44 +    checkThrows(function() { nac.toString(); });
    1.45 +    checkThrows(function() { nac.textContent; });
    1.46 +    var iwin = document.getElementById('ifr').contentWindow;
    1.47 +    iwin.nac = window.nac = nac;
    1.48 +    checkThrows(new iwin.Function('nac.toString();'));
    1.49 +    checkThrows(new iwin.Function('nac.textContent;'));
    1.50 +
    1.51 +    SimpleTest.finish();
    1.52 +  }
    1.53 +
    1.54 +  ]]>
    1.55 +</script>
    1.56 +</head>
    1.57 +<body>
    1.58 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=914618">Mozilla Bug 914618</a>
    1.59 +<p id="display"></p>
    1.60 +<div id="content" style="display: none">
    1.61 +</div>
    1.62 +<div id="bindingSink" style="-moz-binding: url(#testBinding);"></div>
    1.63 +<iframe id="ifr"></iframe>
    1.64 +<pre id="test">
    1.65 +</pre>
    1.66 +</body>
    1.67 +</html>

mercurial