Bug 1839170 - Refactor Snap pulling, Add Firefox Snap Core22 and GNOME 42 SDK symbols...
[gecko.git] / dom / system / tests / test_bug1197901.html
blob7e1866ffa333e4142901c79266a7678fe4936456
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 src="/tests/SimpleTest/SimpleTest.js"></script>
10 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
11 <script type="application/javascript">
13 /** Test for Bug 1197901 **/
14 SimpleTest.requestFlakyTimeout("requestFlakyTimeout is silly");
15 SimpleTest.waitForExplicitFinish();
16 window.onload = function() {
17 SimpleTest.waitForFocus(function() {
18 SpecialPowers.pushPrefEnv({"set": [["device.sensors.test.events", true]]},
19 doTest);
20 }, window);
23 function doTest() {
24 window.onmessage = function(event) {
25 ok(event.data.result, event.data.message);
28 // Only same-origin iframe should get the events.
29 var xo = document.getElementById("cross-origin");
30 xo.contentWindow.postMessage(
31 { command: "addEventListener",
32 expected: false,
33 message: "Cross-origin iframe shouldn't get the sensor events."},
34 "*");
36 var so = document.getElementById("same-origin");
37 so.contentWindow.postMessage(
38 { command: "addEventListener",
39 expected: true,
40 message: "Same-origin iframe should get the sensor events." },
41 "*");
43 // We need a timeout here to check that something does not happen.
44 setTimeout(function() {
45 so.remove();
46 xo.remove();
47 doWindowTest();
48 }, 500);
51 function doWindowTest() {
52 var win = window.open("file_bug1197901.html", "w1", "height=100,width=100");
53 win.onload = function() {
54 win.focus();
55 SimpleTest.waitForFocus(function() {
56 var win2 = window.open("file_bug1197901.html", "w2", "height=100,width=100,left=100");
57 win2.onload = function() {
58 win2.focus();
59 SimpleTest.waitForFocus(function() {
60 // Only focused window should get the events.
61 win.postMessage(
62 { command: "addEventListener",
63 expected: false,
64 message: "Only focused window should get the sensor events." },
65 "*");
66 win2.postMessage(
67 { command: "addEventListener",
68 expected: true,
69 message: "Focused window should get the sensor events." },
70 "*");
71 setTimeout(function() {
72 window.onmessage = null;
73 win.close();
74 win2.close();
75 SimpleTest.finish();
76 }, 500);
77 }, win2);
79 }, win);
83 </script>
84 </head>
85 <body>
86 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=">Mozilla Bug </a>
87 <p id="display"></p>
88 <div id="content" style="display: none">
90 </div>
91 <pre id="test">
92 </pre>
93 <iframe src="file_bug1197901.html" id="same-origin"></iframe>
94 <iframe src="http://example.com/tests/dom/system/tests/file_bug1197901.html" id="cross-origin"></iframe>
95 </body>
96 </html>