test_getWebIDLCaller.html 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <!DOCTYPE HTML>
  2. <html>
  3. <!--
  4. https://bugzilla.mozilla.org/show_bug.cgi?id=968335
  5. -->
  6. <head>
  7. <meta charset="utf-8">
  8. <title>Test for Bug 968335</title>
  9. <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  10. <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
  11. <script type="application/javascript">
  12. /** Test for Cu.getCallerPrincipal (within JS-implemented WebIDL). **/
  13. SimpleTest.waitForExplicitFinish();
  14. SpecialPowers.pushPrefEnv({set: [['dom.expose_test_interfaces', true]]}, go);
  15. function go() {
  16. var t = new TestInterfaceJS();
  17. is(t.getCallerPrincipal(), location.origin,
  18. "Cu.getCallerPrincipal works right within JS-implemented WebIDL");
  19. try {
  20. SpecialPowers.Cu.getWebIDLCallerPrincipal();
  21. ok(false, "Should have thrown");
  22. } catch (e) {
  23. ok(/NOT_AVAILABLE/.test(SpecialPowers.wrap(e)),
  24. "API should throw when invoked outside of JS-implemented WebIDL");
  25. }
  26. SimpleTest.finish();
  27. }
  28. </script>
  29. </head>
  30. <body>
  31. <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=968335">Mozilla Bug 968335</a>
  32. <p id="display"></p>
  33. <div id="content" style="display: none">
  34. </div>
  35. <pre id="test">
  36. </pre>
  37. </body>
  38. </html>