michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: /* michael@0: * These tests make sure that focusing the 'New Tage Page' works as expected. michael@0: */ michael@0: function runTests() { michael@0: // Handle the OSX full keyboard access setting michael@0: Services.prefs.setIntPref("accessibility.tabfocus", 7); michael@0: michael@0: // Focus count in new tab page. michael@0: // 30 = 9 * 3 + 3 = 9 sites, each with link, pin and remove buttons; search michael@0: // bar; search button; and toggle button. michael@0: let FOCUS_COUNT = 30; michael@0: michael@0: // Create a new tab page. michael@0: yield setLinks("0,1,2,3,4,5,6,7,8"); michael@0: setPinnedLinks(""); michael@0: michael@0: yield addNewTabPageTab(); michael@0: gURLBar.focus(); michael@0: michael@0: // Count the focus with the enabled page. michael@0: yield countFocus(FOCUS_COUNT); michael@0: michael@0: // Disable page and count the focus with the disabled page. michael@0: NewTabUtils.allPages.enabled = false; michael@0: yield countFocus(1); michael@0: michael@0: Services.prefs.clearUserPref("accessibility.tabfocus"); michael@0: NewTabUtils.allPages.enabled = true; michael@0: } michael@0: michael@0: /** michael@0: * Focus the urlbar and count how many focus stops to return again to the urlbar. michael@0: */ michael@0: function countFocus(aExpectedCount) { michael@0: let focusCount = 0; michael@0: let contentDoc = getContentDocument(); michael@0: michael@0: window.addEventListener("focus", function onFocus() { michael@0: let focusedElement = document.commandDispatcher.focusedElement; michael@0: if (focusedElement && focusedElement.classList.contains("urlbar-input")) { michael@0: window.removeEventListener("focus", onFocus, true); michael@0: is(focusCount, aExpectedCount, "Validate focus count in the new tab page."); michael@0: executeSoon(TestRunner.next); michael@0: } else { michael@0: if (focusedElement && focusedElement.ownerDocument == contentDoc && michael@0: focusedElement instanceof HTMLElement) { michael@0: focusCount++; michael@0: } michael@0: document.commandDispatcher.advanceFocus(); michael@0: } michael@0: }, true); michael@0: michael@0: document.commandDispatcher.advanceFocus(); michael@0: }