test_nac.xhtml 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <html xmlns="http://www.w3.org/1999/xhtml">
  2. <!--
  3. https://bugzilla.mozilla.org/show_bug.cgi?id=914618
  4. -->
  5. <head>
  6. <title>Test for Bug 914618</title>
  7. <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  8. <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
  9. <bindings xmlns="http://www.mozilla.org/xbl"
  10. xmlns:html="http://www.w3.org/1999/xhtml">
  11. <binding id="testBinding" chromeOnlyContent="true">
  12. <!-- The root of the anonymous subtree is special, and is not allowed to
  13. be adopted, among other things. Work with a child of the root. -->
  14. <content><html:div><html:span id="nac">hidden text</html:span></html:div></content>
  15. <implementation>
  16. <constructor>
  17. var win = XPCNativeWrapper.unwrap(window);
  18. var nac = document.getAnonymousNodes(this)[0].firstChild;
  19. win.is(nac.textContent, "hidden text", "XBL can see NAC");
  20. win.playWithNAC(nac);
  21. </constructor>
  22. </implementation>
  23. </binding>
  24. </bindings>
  25. <script type="application/javascript">
  26. <![CDATA[
  27. /** Test for Bug 914618 **/
  28. SimpleTest.waitForExplicitFinish();
  29. function checkThrows(fn) {
  30. try {
  31. fn();
  32. ok(false, "Should have thrown");
  33. } catch (e) {
  34. ok(/denied|insecure|/.test(e), "Should have thrown security error");
  35. }
  36. }
  37. function playWithNAC(nac) {
  38. checkThrows(function() { nac.toString(); });
  39. checkThrows(function() { nac.textContent; });
  40. var iwin = document.getElementById('ifr').contentWindow;
  41. iwin.nac = window.nac = nac;
  42. checkThrows(new iwin.Function('nac.toString();'));
  43. checkThrows(new iwin.Function('nac.textContent;'));
  44. SimpleTest.finish();
  45. }
  46. ]]>
  47. </script>
  48. </head>
  49. <body>
  50. <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=914618">Mozilla Bug 914618</a>
  51. <p id="display"></p>
  52. <div id="content" style="display: none">
  53. </div>
  54. <div id="bindingSink" style="-moz-binding: url(#testBinding);"></div>
  55. <iframe id="ifr"></iframe>
  56. <pre id="test">
  57. </pre>
  58. </body>
  59. </html>