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