browser_styleeditor_sv_keynav.js (2458B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 "use strict"; 4 5 // Test that the style sheet list can be navigated with keyboard. 6 7 const TESTCASE_URI = TEST_BASE_HTTP + "four.html"; 8 9 add_task(async function () { 10 const { panel, ui } = await openStyleEditorForURL(TESTCASE_URI); 11 12 info("Waiting for source editor to load."); 13 await ui.editors[0].getSourceEditor(); 14 15 const onEditorSelected = new Promise(resolve => { 16 const off = ui.on("editor-selected", editor => { 17 if (editor == ui.editors[2]) { 18 resolve(); 19 off(); 20 } 21 }); 22 }); 23 24 info("Testing keyboard navigation on the sheet list."); 25 testKeyboardNavigation(ui.editors[0], panel); 26 27 info("Waiting for editor #2 to be selected due to keyboard navigation."); 28 await onEditorSelected; 29 ok(ui.editors[2].sourceEditor.hasFocus(), "Editor #2 has focus."); 30 }); 31 32 function getStylesheetNameLinkFor(editor) { 33 return editor.summary.querySelector(".stylesheet-name"); 34 } 35 36 function testKeyboardNavigation(editor, panel) { 37 const panelWindow = panel.panelWindow; 38 const ui = panel.UI; 39 waitForFocus(function () { 40 const summary = editor.summary; 41 EventUtils.synthesizeMouseAtCenter(summary, {}, panelWindow); 42 43 let item = getStylesheetNameLinkFor(ui.editors[0]); 44 is( 45 panelWindow.document.activeElement, 46 item, 47 "editor 0 item is the active element" 48 ); 49 50 EventUtils.synthesizeKey("VK_DOWN", {}, panelWindow); 51 item = getStylesheetNameLinkFor(ui.editors[1]); 52 is( 53 panelWindow.document.activeElement, 54 item, 55 "editor 1 item is the active element" 56 ); 57 58 EventUtils.synthesizeKey("VK_HOME", {}, panelWindow); 59 item = getStylesheetNameLinkFor(ui.editors[0]); 60 is( 61 panelWindow.document.activeElement, 62 item, 63 "fist editor item is the active element" 64 ); 65 66 EventUtils.synthesizeKey("VK_END", {}, panelWindow); 67 item = getStylesheetNameLinkFor(ui.editors[3]); 68 is( 69 panelWindow.document.activeElement, 70 item, 71 "last editor item is the active element" 72 ); 73 74 EventUtils.synthesizeKey("VK_UP", {}, panelWindow); 75 item = getStylesheetNameLinkFor(ui.editors[2]); 76 is( 77 panelWindow.document.activeElement, 78 item, 79 "editor 2 item is the active element" 80 ); 81 82 EventUtils.synthesizeKey("VK_RETURN", {}, panelWindow); 83 // this will attach and give focus editor 2 84 }, panelWindow); 85 }