browser/base/content/test/general/browser_bug427559.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/base/content/test/general/browser_bug427559.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,40 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +
     1.8 +/*
     1.9 + * Test bug 427559 to make sure focused elements that are no longer on the page
    1.10 + * will have focus transferred to the window when changing tabs back to that
    1.11 + * tab with the now-gone element.
    1.12 + */
    1.13 +
    1.14 +// Default focus on a button and have it kill itself on blur
    1.15 +let testPage = 'data:text/html,<body><button onblur="this.parentNode.removeChild(this);"><script>document.body.firstChild.focus();</script></body>';
    1.16 +
    1.17 +function test() {
    1.18 +  waitForExplicitFinish();
    1.19 +
    1.20 +  gBrowser.selectedTab = gBrowser.addTab();
    1.21 +
    1.22 +  gBrowser.selectedBrowser.addEventListener("load", function () {
    1.23 +    gBrowser.selectedBrowser.removeEventListener("load", arguments.callee, true);
    1.24 +    setTimeout(function () {
    1.25 +      var testPageWin = content;
    1.26 +
    1.27 +      // The test page loaded, so open an empty tab, select it, then restore
    1.28 +      // the test tab. This causes the test page's focused element to be removed
    1.29 +      // from its document.
    1.30 +      gBrowser.selectedTab = gBrowser.addTab();
    1.31 +      gBrowser.removeCurrentTab();
    1.32 +
    1.33 +      // Make sure focus is given to the window because the element is now gone
    1.34 +      is(document.commandDispatcher.focusedWindow, testPageWin,
    1.35 +         "content window is focused");
    1.36 +
    1.37 +      gBrowser.removeCurrentTab();
    1.38 +      finish();
    1.39 +    }, 0);
    1.40 +  }, true);
    1.41 +
    1.42 +  content.location = testPage;
    1.43 +}

mercurial