|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
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); |
|
10 |
|
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; |
|
15 |
|
16 // Create a new tab page. |
|
17 yield setLinks("0,1,2,3,4,5,6,7,8"); |
|
18 setPinnedLinks(""); |
|
19 |
|
20 yield addNewTabPageTab(); |
|
21 gURLBar.focus(); |
|
22 |
|
23 // Count the focus with the enabled page. |
|
24 yield countFocus(FOCUS_COUNT); |
|
25 |
|
26 // Disable page and count the focus with the disabled page. |
|
27 NewTabUtils.allPages.enabled = false; |
|
28 yield countFocus(1); |
|
29 |
|
30 Services.prefs.clearUserPref("accessibility.tabfocus"); |
|
31 NewTabUtils.allPages.enabled = true; |
|
32 } |
|
33 |
|
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(); |
|
40 |
|
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); |
|
55 |
|
56 document.commandDispatcher.advanceFocus(); |
|
57 } |