browser/base/content/test/newtab/browser_newtab_focus.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* Any copyright is dedicated to the Public Domain.
     2    http://creativecommons.org/publicdomain/zero/1.0/ */
     4 /*
     5  * These tests make sure that focusing the 'New Tage Page' works as expected.
     6  */
     7 function runTests() {
     8   // Handle the OSX full keyboard access setting
     9   Services.prefs.setIntPref("accessibility.tabfocus", 7);
    11   // Focus count in new tab page.
    12   // 30 = 9 * 3 + 3 = 9 sites, each with link, pin and remove buttons; search
    13   // bar; search button; and toggle button.
    14   let FOCUS_COUNT = 30;
    16   // Create a new tab page.
    17   yield setLinks("0,1,2,3,4,5,6,7,8");
    18   setPinnedLinks("");
    20   yield addNewTabPageTab();
    21   gURLBar.focus();
    23   // Count the focus with the enabled page.
    24   yield countFocus(FOCUS_COUNT);
    26   // Disable page and count the focus with the disabled page.
    27   NewTabUtils.allPages.enabled = false;
    28   yield countFocus(1);
    30   Services.prefs.clearUserPref("accessibility.tabfocus");
    31   NewTabUtils.allPages.enabled = true;
    32 }
    34 /**
    35  * Focus the urlbar and count how many focus stops to return again to the urlbar.
    36  */
    37 function countFocus(aExpectedCount) {
    38   let focusCount = 0;
    39   let contentDoc = getContentDocument();
    41   window.addEventListener("focus", function onFocus() {
    42     let focusedElement = document.commandDispatcher.focusedElement;
    43     if (focusedElement && focusedElement.classList.contains("urlbar-input")) {
    44       window.removeEventListener("focus", onFocus, true);
    45       is(focusCount, aExpectedCount, "Validate focus count in the new tab page.");
    46       executeSoon(TestRunner.next);
    47     } else {
    48       if (focusedElement && focusedElement.ownerDocument == contentDoc &&
    49           focusedElement instanceof HTMLElement) {
    50         focusCount++;
    51       }
    52       document.commandDispatcher.advanceFocus();
    53     }
    54   }, true);
    56   document.commandDispatcher.advanceFocus();
    57 }

mercurial