test_bug1197901.html 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <!DOCTYPE HTML>
  2. <html>
  3. <!--
  4. https://bugzilla.mozilla.org/show_bug.cgi?id=1197901
  5. -->
  6. <head>
  7. <meta charset="utf-8">
  8. <title>Test for Bug 1197901</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 1197901 **/
  13. SimpleTest.requestFlakyTimeout("requestFlakyTimeout is silly");
  14. SimpleTest.waitForExplicitFinish();
  15. window.onload = function() {
  16. SimpleTest.waitForFocus(function() {
  17. SpecialPowers.pushPrefEnv({"set": [['device.sensors.test.events', true]]},
  18. doTest);
  19. }, window);
  20. }
  21. function doTest() {
  22. window.onmessage = function(event) {
  23. ok(event.data.result, event.data.message);
  24. }
  25. // Only same-origin iframe should get the events.
  26. var xo = document.getElementById("cross-origin");
  27. xo.contentWindow.postMessage(
  28. { command: "addEventListener",
  29. expected: false,
  30. message: "Cross-origin iframe shouldn't get the sensor events."},
  31. "*");
  32. var so = document.getElementById("same-origin");
  33. so.contentWindow.postMessage(
  34. { command: "addEventListener",
  35. expected: true,
  36. message: "Same-origin iframe should get the sensor events." },
  37. "*");
  38. // We need a timeout here to check that something does not happen.
  39. setTimeout(function() {
  40. so.parentNode.removeChild(so);
  41. xo.parentNode.removeChild(xo);
  42. doWindowTest();
  43. }, 500);
  44. }
  45. function doWindowTest() {
  46. var win = window.open("file_bug1197901.html", "w1", "height=100,width=100");
  47. win.onload = function() {
  48. win.focus();
  49. SimpleTest.waitForFocus(function() {
  50. var win2 = window.open("file_bug1197901.html", "w2", "height=100,width=100,left=100");
  51. win2.onload = function() {
  52. win2.focus();
  53. SimpleTest.waitForFocus(function() {
  54. // Only focused window should get the events.
  55. win.postMessage(
  56. { command: "addEventListener",
  57. expected: false,
  58. message: "Only focused window should get the sensor events." },
  59. "*");
  60. win2.postMessage(
  61. { command: "addEventListener",
  62. expected: true,
  63. message: "Focused window should get the sensor events." },
  64. "*");
  65. setTimeout(function() {
  66. window.onmessage = null;
  67. win.close();
  68. win2.close();
  69. SimpleTest.finish();
  70. }, 500);
  71. }, win2);
  72. }
  73. }, win);
  74. }
  75. }
  76. </script>
  77. </head>
  78. <body>
  79. <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=">Mozilla Bug </a>
  80. <p id="display"></p>
  81. <div id="content" style="display: none">
  82. </div>
  83. <pre id="test">
  84. </pre>
  85. <iframe src="file_bug1197901.html" id="same-origin"></iframe>
  86. <iframe src="http://example.com/tests/dom/system/tests/file_bug1197901.html" id="cross-origin"></iframe>
  87. </body>
  88. </html>