browser_inplace-editor_autocomplete_01.js (2242B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 /* import-globals-from helper_inplace_editor.js */ 4 5 "use strict"; 6 7 const AutocompletePopup = require("resource://devtools/client/shared/autocomplete-popup.js"); 8 const { 9 InplaceEditor, 10 } = require("resource://devtools/client/shared/inplace-editor.js"); 11 loadHelperScript("helper_inplace_editor.js"); 12 13 // Test the inplace-editor autocomplete popup for CSS properties suggestions. 14 // Using a mocked list of CSS properties to avoid test failures linked to 15 // engine changes (new property, removed property, ...). 16 17 // format : 18 // [ 19 // what key to press, 20 // expected input box value after keypress, 21 // selected suggestion index (-1 if popup is hidden), 22 // number of suggestions in the popup (0 if popup is hidden), 23 // ] 24 const testData = [ 25 ["b", "border", 1, 3], 26 ["VK_DOWN", "box-sizing", 2, 3], 27 ["VK_DOWN", "background", 0, 3], 28 ["VK_DOWN", "border", 1, 3], 29 ["VK_BACK_SPACE", "b", -1, 0], 30 ["VK_BACK_SPACE", "", -1, 0], 31 ["VK_DOWN", "background", 0, 6], 32 ["VK_LEFT", "background", -1, 0], 33 ]; 34 35 const mockValues = { 36 background: [], 37 border: [], 38 "box-sizing": [], 39 color: [], 40 display: [], 41 visibility: [], 42 }; 43 44 add_task(async function () { 45 await addTab( 46 "data:text/html;charset=utf-8," + "inplace editor CSS property autocomplete" 47 ); 48 const { host, doc } = await createHost(); 49 50 const popup = new AutocompletePopup(doc, { autoSelect: true }); 51 await new Promise(resolve => { 52 createInplaceEditorAndClick( 53 { 54 start: runPropertyAutocompletionTest, 55 contentType: InplaceEditor.CONTENT_TYPES.CSS_PROPERTY, 56 done: resolve, 57 popup, 58 cssProperties: { 59 getNames: () => Object.keys(mockValues), 60 getValues: propertyName => mockValues[propertyName] || [], 61 }, 62 }, 63 doc 64 ); 65 }); 66 67 popup.destroy(); 68 host.destroy(); 69 gBrowser.removeCurrentTab(); 70 }); 71 72 const runPropertyAutocompletionTest = async function (editor) { 73 info("Starting to test for css property completion"); 74 for (const data of testData) { 75 await testCompletion(data, editor); 76 } 77 78 EventUtils.synthesizeKey("VK_RETURN", {}, editor.input.defaultView); 79 };