dom/tests/mochitest/bugs/test_bug369306.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/tests/mochitest/bugs/test_bug369306.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,137 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<!--
     1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=369306
     1.8 +-->
     1.9 +<head>
    1.10 +  <title>Test for Bug 369306</title>
    1.11 +  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    1.12 +  <script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
    1.13 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
    1.14 +</head>
    1.15 +<body>
    1.16 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=369306">Mozilla Bug 369306</a>
    1.17 +<p id="display"></p>
    1.18 +<div id='content'>
    1.19 +</div>
    1.20 +<pre id="test">
    1.21 +<script type="application/javascript">
    1.22 +
    1.23 +/** Test for Bug 369306 **/
    1.24 +
    1.25 +var originatingWindow = self;
    1.26 +
    1.27 +function focusShouldNotChange(aAction, nextTest)
    1.28 +{
    1.29 +  var w = window.open('about:blank', '', 'foo');
    1.30 +  var fail = false;
    1.31 +
    1.32 +  SimpleTest.waitForFocus(function () {
    1.33 +    function failHandler() { fail = true; }
    1.34 +
    1.35 +    originatingWindow.addEventListener("focus", failHandler, false);
    1.36 +    w.addEventListener("blur", failHandler, false);
    1.37 +
    1.38 +    aAction(w);
    1.39 +
    1.40 +    SimpleTest.executeSoon(function () {
    1.41 +      originatingWindow.removeEventListener("focus", failHandler, false);
    1.42 +      w.removeEventListener("blur", failHandler, false);
    1.43 +
    1.44 +      ok(!fail, "The focus should not have been changed!");
    1.45 +
    1.46 +      // Cleaning and running next test.
    1.47 +      w.close();
    1.48 +      SimpleTest.waitForFocus(nextTest, originatingWindow);
    1.49 +    });
    1.50 +  }, w, true);
    1.51 +}
    1.52 +
    1.53 +function focusShouldNotChange2(aURL, nextTest)
    1.54 +{
    1.55 +  var w = window.open(aURL, '', 'foo');
    1.56 +  var fail = false;
    1.57 +
    1.58 +  SimpleTest.waitForFocus(function () {
    1.59 +    function failHandler() { fail = true; }
    1.60 +
    1.61 +    originatingWindow.addEventListener("focus", failHandler, false);
    1.62 +    w.addEventListener("blur", failHandler, false);
    1.63 +
    1.64 +    /**
    1.65 +     * NOTE: This setTimeout can cause a random green.
    1.66 +     * onload handler + executeSoon doesn't work too so we have to use setTimeout.
    1.67 +     * The check may be call before w script being executed but that would make
    1.68 +     * this check green even if it should be orange.
    1.69 +     */
    1.70 +    setTimeout(function () {
    1.71 +      originatingWindow.removeEventListener("focus", failHandler, false);
    1.72 +      w.removeEventListener("blur", failHandler, false);
    1.73 +
    1.74 +      ok(!fail, "The focus should not have been changed with URL=" + aURL);
    1.75 +
    1.76 +      // Cleaning and running next test.
    1.77 +      w.close();
    1.78 +      SimpleTest.waitForFocus(nextTest, originatingWindow);
    1.79 +    }, 1000);
    1.80 +  }, w);
    1.81 +}
    1.82 +
    1.83 +function test1()
    1.84 +{
    1.85 +  focusShouldNotChange(function (aW) { aW.blur(); }, test2);
    1.86 +}
    1.87 +
    1.88 +function test2()
    1.89 +{
    1.90 +  focusShouldNotChange(function () { originatingWindow.focus(); }, test3);
    1.91 +}
    1.92 +
    1.93 +function test3()
    1.94 +{
    1.95 +  focusShouldNotChange2("data:text/html,\<script>opener.focus();\<\/script>", test4);
    1.96 +}
    1.97 +
    1.98 +function test4()
    1.99 +{
   1.100 +  focusShouldNotChange2("data:text/html,\<script>blur();\<\/script>", test5);
   1.101 +}
   1.102 +
   1.103 +function test5()
   1.104 +{
   1.105 +  var w = window.open('about:blank', '', 'foo');
   1.106 +
   1.107 +  SimpleTest.waitForFocus(function () {
   1.108 +    SimpleTest.waitForFocus(function () {
   1.109 +      SimpleTest.waitForFocus(function () {
   1.110 +        ok(true, "The last opened window should be able to get focus");
   1.111 +        w.close();
   1.112 +        SimpleTest.executeSoon(SimpleTest.finish);
   1.113 +      }, w, true);
   1.114 +
   1.115 +      w.focus();
   1.116 +    }, originatingWindow);
   1.117 +
   1.118 +    SimpleTest.executeSoon(function() {
   1.119 +      // We have to focus back the originating window but we can't do that with
   1.120 +      // .focus() or .blur() anymore.
   1.121 +      SpecialPowers.focus(window);
   1.122 +    });
   1.123 +  }, w, true);
   1.124 +}
   1.125 +
   1.126 +SimpleTest.waitForExplicitFinish();
   1.127 +
   1.128 +
   1.129 +function startTest() {
   1.130 +  // dom.disable_window_flip has to be set to true for this test.
   1.131 +  SpecialPowers.pushPrefEnv({"set": [["dom.disable_window_flip", true]]}, test1);
   1.132 +}
   1.133 +
   1.134 +// startTest is going to call the next tests.
   1.135 +SimpleTest.waitForFocus(startTest);
   1.136 +
   1.137 +</script>
   1.138 +</pre>
   1.139 +</body>
   1.140 +</html>

mercurial