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