browser_rules_completion-shortcut.js (2194B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 // Tests the shortcut key for the suggest completion popup. 7 8 const TEST_URI = "<h1 style='colo: lim'>Header</h1>"; 9 const TEST_SHORTCUTS = [ 10 { 11 key: " ", 12 modifiers: { ctrlKey: true }, 13 }, 14 { 15 key: "VK_DOWN", 16 modifiers: {}, 17 }, 18 ]; 19 20 add_task(async function () { 21 for (const shortcut of TEST_SHORTCUTS) { 22 info( 23 "Start to test for the shortcut " + 24 `key: "${shortcut.key}" modifiers: ${Object.keys(shortcut.modifiers)}` 25 ); 26 27 const tab = await addTab( 28 "data:text/html;charset=utf-8," + encodeURIComponent(TEST_URI) 29 ); 30 const { inspector, view } = await openRuleView(); 31 32 info("Selecting the test node"); 33 await selectNode("h1", inspector); 34 35 const prop = getTextProperty(view, 0, { colo: "lim" }); 36 37 info("Test with css property name field"); 38 const nameEditor = await focusEditableField(view, prop.editor.nameSpan); 39 await testCompletion(shortcut, view, nameEditor, "color"); 40 41 info("Test with css property value field"); 42 const valueEditor = inplaceEditor(view.styleDocument.activeElement); 43 await testCompletion(shortcut, view, valueEditor, "lime"); 44 45 await removeTab(tab); 46 } 47 }); 48 49 async function testCompletion(shortcut, view, editor, expectedValue) { 50 const spanEl = editor.elt; 51 52 info("Move cursor to the end"); 53 EventUtils.synthesizeKey("VK_RIGHT", {}, view.styleWindow); 54 await waitUntil( 55 () => editor.input.selectionStart === editor.input.selectionEnd 56 ); 57 58 info("Check whether the popup opens after sending the shortcut key"); 59 const onPopupOpened = once(view.popup, "popup-opened"); 60 EventUtils.synthesizeKey(shortcut.key, shortcut.modifiers, view.styleWindow); 61 await onPopupOpened; 62 ok(view.popup.isOpen, "The popup opened correctly"); 63 64 info("Commit the suggestion"); 65 const onChanged = view.once("ruleview-changed"); 66 const onPopupClosed = once(view.popup, "popup-closed"); 67 EventUtils.synthesizeKey("VK_TAB", {}, view.styleWindow); 68 await Promise.all([onChanged, onPopupClosed]); 69 is(spanEl.textContent, expectedValue, "The value is set correctly"); 70 }