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 */
7 const AutocompletePopup = require("resource://devtools/client/shared/autocomplete-popup.js");
10 } = require("resource://devtools/client/shared/inplace-editor.js");
11 loadHelperScript("helper_inplace_editor.js");
14 CHROME_URL_ROOT + "doc_inplace-editor_autocomplete_offset.xhtml";
16 // Test the inplace-editor autocomplete popup is aligned with the completed query.
17 // Which means when completing "style=display:flex; color:" the popup will aim to be
18 // aligned with the ":" next to "color".
23 // expected input box value after keypress,
24 // selected suggestion index (-1 if popup is hidden),
25 // number of suggestions in the popup (0 if popup is hidden),
28 // ["checkPopupOffset"]
29 // to measure and test the autocomplete popup left offset.
31 ["VK_RIGHT", "style=", -1, 0],
32 ["d", "style=display", 1, 2],
34 ["VK_RIGHT", "style=display", -1, 0],
35 [":", "style=display:block", 0, 3],
37 ["f", "style=display:flex", -1, 0],
38 ["VK_RIGHT", "style=display:flex", -1, 0],
39 [";", "style=display:flex;", -1, 0],
40 ["c", "style=display:flex;color", 1, 2],
42 ["VK_RIGHT", "style=display:flex;color", -1, 0],
43 [":", "style=display:flex;color:blue", 0, 2],
49 color: ["blue", "red"],
51 display: ["block", "flex", "none"],
54 add_task(async function () {
56 "data:text/html;charset=utf-8,inplace editor CSS value autocomplete"
58 const { host, doc } = await createHost("bottom", TEST_URI);
60 const popup = new AutocompletePopup(doc, { autoSelect: true });
62 info("Create a CSS_MIXED type autocomplete");
63 await new Promise(resolve => {
64 createInplaceEditorAndClick(
67 start: runAutocompletionTest,
68 contentType: InplaceEditor.CONTENT_TYPES.CSS_MIXED,
72 getNames: () => Object.keys(mockValues),
73 getValues: propertyName => mockValues[propertyName] || [],
82 gBrowser.removeCurrentTab();
85 const runAutocompletionTest = async function (editor) {
86 info("Starting autocomplete test for inplace-editor popup offset");
87 let previousOffset = -1;
88 for (const data of testData) {
89 if (data[0] === "checkPopupOffset") {
90 info("Check the popup offset has been modified");
91 // We are not testing hard coded offset values here, which could be fragile. We only
92 // want to ensure the popup tries to match the position of the query in the editor
94 const offset = getPopupOffset(editor);
98 "New popup offset is greater than the previous one"
100 previousOffset = offset;
102 await testCompletion(data, editor);
106 EventUtils.synthesizeKey("VK_RETURN", {}, editor.input.defaultView);
110 * Get the autocomplete panel left offset, relative to the provided input's left offset.
112 function getPopupOffset({ popup, input }) {
113 const popupQuads = popup._panel.getBoxQuads({ relativeTo: input });
114 return popupQuads[0].getBounds().left;