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 loadHelperScript("helper_inplace_editor.js");
9 // Test the inplace-editor stopOnX options behavior
11 add_task(async function () {
12 await addTab("data:text/html;charset=utf-8,inline editor stopOnX");
13 const { host, doc } = await createHost();
15 testStopOnReturn(doc);
17 testStopOnShiftTab(doc);
20 gBrowser.removeCurrentTab();
23 function testStopOnReturn(doc) {
24 const { span1El, span2El } = setupMarkupAndCreateInplaceEditors(doc);
26 info(`Create an editable field with "stopOnReturn" set to true`);
29 focusEditableFieldAfterApply: true,
30 focusEditableFieldContainerSelector: "main",
37 info("Activate inplace editor on first span");
41 doc.activeElement.inplaceEditor.elt.id,
43 "Visible editable field is the one associated with first span"
45 assertFocusedElementInplaceEditorInput(doc);
48 EventUtils.synthesizeKey("VK_RETURN");
53 "Using Enter did not advance the editor to the next focusable element"
56 info("Activate inplace editor on first span again");
60 doc.activeElement.inplaceEditor.elt.id,
62 "Visible editable field is the one associated with first span"
64 assertFocusedElementInplaceEditorInput(doc);
66 const isMacOS = Services.appinfo.OS === "Darwin";
67 info(`Press ${isMacOS ? "Cmd" : "Ctrl"} + Enter`);
68 EventUtils.synthesizeKey("VK_RETURN", {
69 [isMacOS ? "metaKey" : "ctrlKey"]: true,
73 doc.activeElement.inplaceEditor.elt.id,
76 isMacOS ? "Cmd" : "Ctrl"
77 } + Enter did advance the editor to the next focusable element`
81 function testStopOnTab(doc) {
82 const { span1El, span2El } = setupMarkupAndCreateInplaceEditors(doc);
84 info(`Create editable fields with "stopOnTab" set to true`);
86 focusEditableFieldAfterApply: true,
87 focusEditableFieldContainerSelector: "main",
99 info("Activate inplace editor on first span");
103 doc.activeElement.inplaceEditor.elt.id,
105 "Visible editable field is the one associated with first span"
107 assertFocusedElementInplaceEditorInput(doc);
110 EventUtils.synthesizeKey("VK_TAB");
113 doc.activeElement.id,
115 "Using Tab did not advance the editor to the next focusable element"
119 "Activate inplace editor on second span to check that Shift+Tab does work"
124 doc.activeElement.inplaceEditor.elt.id,
126 "Visible editable field is the one associated with second span"
128 assertFocusedElementInplaceEditorInput(doc);
130 info("Press Shift+Tab");
131 EventUtils.synthesizeKey("VK_TAB", {
136 doc.activeElement.inplaceEditor.elt.id,
138 `Using Shift + Tab did move the editor to the previous focusable element`
142 function testStopOnShiftTab(doc) {
143 const { span1El, span2El } = setupMarkupAndCreateInplaceEditors(doc);
144 info(`Create editable fields with "stopOnShiftTab" set to true`);
146 focusEditableFieldAfterApply: true,
147 focusEditableFieldContainerSelector: "main",
148 stopOnShiftTab: true,
159 info("Activate inplace editor on second span");
163 doc.activeElement.inplaceEditor.elt.id,
165 "Visible editable field is the one associated with second span"
167 assertFocusedElementInplaceEditorInput(doc);
169 info("Press Shift+Tab");
170 EventUtils.synthesizeKey("VK_TAB", { shiftKey: true });
173 doc.activeElement.id,
175 "Using Shift+Tab did not move the editor to the previous focusable element"
179 "Activate inplace editor on first span to check that Tab is not impacted"
184 doc.activeElement.inplaceEditor.elt.id,
186 "Visible editable field is the one associated with first span"
188 assertFocusedElementInplaceEditorInput(doc);
191 EventUtils.synthesizeKey("VK_TAB");
194 doc.activeElement.inplaceEditor.elt.id,
196 `Using Tab did move the editor to the next focusable element`
200 function setupMarkupAndCreateInplaceEditors(doc) {
201 // For some reason <button> or <input> are not rendered, so let's use divs with
202 // tabindex attribute to make them focusable.
203 doc.body.innerHTML = `
205 <span id="span-1" tabindex=0>SPAN 1</span>
206 <span id="span-2" tabindex=0>SPAN 2</span>
209 const span1El = doc.getElementById("span-1");
210 const span2El = doc.getElementById("span-2");
211 return { span1El, span2El };
214 function assertFocusedElementInplaceEditorInput(doc) {
216 doc.activeElement.matches("input.styleinspector-propertyeditor"),
217 "inplace editor input is focused"