test_allowMedia.html 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <!DOCTYPE HTML>
  2. <html>
  3. <!--
  4. https://bugzilla.mozilla.org/show_bug.cgi?id=759964
  5. -->
  6. <head>
  7. <meta charset="utf-8">
  8. <title>Test for Bug 759964</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 Bug 759964 **/
  13. SimpleTest.waitForExplicitFinish();
  14. addLoadEvent(runNextTest);
  15. var SJS = "http://mochi.test:8888/tests/dom/html/test/allowMedia.sjs";
  16. var TEST_PAGE = "data:text/html,<audio src='" + SJS + "?audio'></audio>";
  17. var Ci = Components.interfaces;
  18. function runNextTest() {
  19. var test = tests.shift();
  20. if (!test) {
  21. SimpleTest.finish();
  22. return;
  23. }
  24. test();
  25. }
  26. var tests = [
  27. // Set allowMedia = false, load a page with <audio>, verify the <audio>
  28. // doesn't load its source.
  29. function basic() {
  30. var iframe = insertIframe();
  31. SpecialPowers.allowMedia(iframe.contentWindow, false);
  32. loadIframe(iframe, TEST_PAGE, function () {
  33. verifyPass();
  34. iframe.remove();
  35. runNextTest();
  36. });
  37. },
  38. // Set allowMedia = false on parent docshell, load a page with <audio> in a
  39. // child iframe, verify the <audio> doesn't load its source.
  40. function inherit() {
  41. SpecialPowers.allowMedia(window, false);
  42. var iframe = insertIframe();
  43. loadIframe(iframe, TEST_PAGE, function () {
  44. verifyPass();
  45. iframe.remove();
  46. SpecialPowers.allowMedia(window, true);
  47. runNextTest();
  48. });
  49. },
  50. // In a display:none iframe, set allowMedia = false, load a page with <audio>,
  51. // verify the <audio> doesn't load its source.
  52. function displayNone() {
  53. var iframe = insertIframe();
  54. iframe.style.display = "none";
  55. SpecialPowers.allowMedia(iframe.contentWindow, false);
  56. loadIframe(iframe, TEST_PAGE, function () {
  57. verifyPass();
  58. iframe.remove();
  59. runNextTest();
  60. });
  61. },
  62. ];
  63. function insertIframe() {
  64. var iframe = document.createElement("iframe");
  65. document.body.appendChild(iframe);
  66. return iframe;
  67. }
  68. function loadIframe(iframe, url, onDone) {
  69. iframe.setAttribute("src", url);
  70. iframe.addEventListener("load", onDone);
  71. }
  72. function verifyPass() {
  73. var xhr = new XMLHttpRequest();
  74. xhr.open("GET", SJS, false);
  75. xhr.send();
  76. is(xhr.responseText, "PASS", "<audio> source should not have been loaded.");
  77. }
  78. </script>
  79. </head>
  80. <body>
  81. <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=759964">Mozilla Bug 759964</a>
  82. <p id="display">
  83. </p>
  84. </body>
  85. </html>