dom/tests/mochitest/bugs/test_bug369306.html

branch
TOR_BUG_9701
changeset 8
97036ab72558
equal deleted inserted replaced
-1:000000000000 0:bec7a7afcb92
1 <!DOCTYPE HTML>
2 <html>
3 <!--
4 https://bugzilla.mozilla.org/show_bug.cgi?id=369306
5 -->
6 <head>
7 <title>Test for Bug 369306</title>
8 <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
9 <script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
10 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
11 </head>
12 <body>
13 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=369306">Mozilla Bug 369306</a>
14 <p id="display"></p>
15 <div id='content'>
16 </div>
17 <pre id="test">
18 <script type="application/javascript">
19
20 /** Test for Bug 369306 **/
21
22 var originatingWindow = self;
23
24 function focusShouldNotChange(aAction, nextTest)
25 {
26 var w = window.open('about:blank', '', 'foo');
27 var fail = false;
28
29 SimpleTest.waitForFocus(function () {
30 function failHandler() { fail = true; }
31
32 originatingWindow.addEventListener("focus", failHandler, false);
33 w.addEventListener("blur", failHandler, false);
34
35 aAction(w);
36
37 SimpleTest.executeSoon(function () {
38 originatingWindow.removeEventListener("focus", failHandler, false);
39 w.removeEventListener("blur", failHandler, false);
40
41 ok(!fail, "The focus should not have been changed!");
42
43 // Cleaning and running next test.
44 w.close();
45 SimpleTest.waitForFocus(nextTest, originatingWindow);
46 });
47 }, w, true);
48 }
49
50 function focusShouldNotChange2(aURL, nextTest)
51 {
52 var w = window.open(aURL, '', 'foo');
53 var fail = false;
54
55 SimpleTest.waitForFocus(function () {
56 function failHandler() { fail = true; }
57
58 originatingWindow.addEventListener("focus", failHandler, false);
59 w.addEventListener("blur", failHandler, false);
60
61 /**
62 * NOTE: This setTimeout can cause a random green.
63 * onload handler + executeSoon doesn't work too so we have to use setTimeout.
64 * The check may be call before w script being executed but that would make
65 * this check green even if it should be orange.
66 */
67 setTimeout(function () {
68 originatingWindow.removeEventListener("focus", failHandler, false);
69 w.removeEventListener("blur", failHandler, false);
70
71 ok(!fail, "The focus should not have been changed with URL=" + aURL);
72
73 // Cleaning and running next test.
74 w.close();
75 SimpleTest.waitForFocus(nextTest, originatingWindow);
76 }, 1000);
77 }, w);
78 }
79
80 function test1()
81 {
82 focusShouldNotChange(function (aW) { aW.blur(); }, test2);
83 }
84
85 function test2()
86 {
87 focusShouldNotChange(function () { originatingWindow.focus(); }, test3);
88 }
89
90 function test3()
91 {
92 focusShouldNotChange2("data:text/html,\<script>opener.focus();\<\/script>", test4);
93 }
94
95 function test4()
96 {
97 focusShouldNotChange2("data:text/html,\<script>blur();\<\/script>", test5);
98 }
99
100 function test5()
101 {
102 var w = window.open('about:blank', '', 'foo');
103
104 SimpleTest.waitForFocus(function () {
105 SimpleTest.waitForFocus(function () {
106 SimpleTest.waitForFocus(function () {
107 ok(true, "The last opened window should be able to get focus");
108 w.close();
109 SimpleTest.executeSoon(SimpleTest.finish);
110 }, w, true);
111
112 w.focus();
113 }, originatingWindow);
114
115 SimpleTest.executeSoon(function() {
116 // We have to focus back the originating window but we can't do that with
117 // .focus() or .blur() anymore.
118 SpecialPowers.focus(window);
119 });
120 }, w, true);
121 }
122
123 SimpleTest.waitForExplicitFinish();
124
125
126 function startTest() {
127 // dom.disable_window_flip has to be set to true for this test.
128 SpecialPowers.pushPrefEnv({"set": [["dom.disable_window_flip", true]]}, test1);
129 }
130
131 // startTest is going to call the next tests.
132 SimpleTest.waitForFocus(startTest);
133
134 </script>
135 </pre>
136 </body>
137 </html>

mercurial