test_iframe_sandbox_popups.html 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <!DOCTYPE HTML>
  2. <html>
  3. <!--
  4. https://bugzilla.mozilla.org/show_bug.cgi?id=766282
  5. implement allow-popups directive for iframe sandbox
  6. -->
  7. <head>
  8. <meta charset="utf-8">
  9. <title>Tests for Bug 766282</title>
  10. <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  11. <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
  12. <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
  13. </head>
  14. <script type="application/javascript">
  15. SimpleTest.waitForExplicitFinish();
  16. // a postMessage handler that is used by sandboxed iframes without
  17. // 'allow-same-origin' to communicate pass/fail back to this main page.
  18. // it expects to be called with an object like {ok: true/false, desc:
  19. // <description of the test> which it then forwards to ok()
  20. window.addEventListener("message", receiveMessage, false);
  21. function receiveMessage(event)
  22. {
  23. ok_wrapper(event.data.ok, event.data.desc);
  24. }
  25. var completedTests = 0;
  26. var passedTests = 0;
  27. function ok_wrapper(result, desc) {
  28. ok(result, desc);
  29. completedTests++;
  30. if (result) {
  31. passedTests++;
  32. }
  33. if (completedTests == 3) {
  34. is(passedTests, completedTests, "There are " + completedTests + " popups tests that should pass");
  35. SimpleTest.finish();
  36. }
  37. }
  38. function doTest() {
  39. // passes if good
  40. // 1) Test that a sandboxed iframe with "allow-popups" can open a new window using the target.attribute.
  41. // This is done via file_iframe_sandbox_h_if1.html which is sandboxed with "allow-popups allow-scripts allow-same-origin".
  42. // The window it attempts to open calls window.opener.ok(true, ...) and file_iframe_h_if1.html has an ok()
  43. // function that calls window.parent.ok_wrapper.
  44. // passes if good
  45. // 2) Test that a sandboxed iframe with "allow-popups" can open a new window using window.open.
  46. // This is done via file_iframe_sandbox_h_if1.html which is sandboxed with "allow-popups allow-scripts allow-same-origin".
  47. // The window it attempts to open calls window.opener.ok(true, ...) and file_iframe_h_if1.html has an ok()
  48. // function that calls window.parent.ok_wrapper.
  49. // passes if good, fails if bad
  50. // 3) Test that a sandboxed iframe with "allow-popups" can open a new window using the target.attribute
  51. // for a non-existing browsing context (BC766282).
  52. // This is done via file_iframe_sandbox_h_if1.html which is sandboxed with "allow-popups allow-scripts allow-same-origin".
  53. // The window it attempts to open calls window.opener.ok(true, ...) and file_iframe_h_if1.html has an ok()
  54. // function that calls window.parent.ok_wrapper.
  55. }
  56. addLoadEvent(doTest);
  57. </script>
  58. <body>
  59. <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=766282">Mozilla Bug 766282</a> - implement allow-popups directive for iframe sandbox
  60. <p id="display"></p>
  61. <div id="content">
  62. <iframe sandbox="allow-popups allow-same-origin allow-scripts" id="if1" src="file_iframe_sandbox_h_if1.html" height="10" width="10"></iframe>
  63. </div>
  64. </body>
  65. </html>