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");
10 const START_TEXT = "Start text";
12 "I am a long text and I will not fit in a 300px container. " +
13 "I expect the inplace editor to wrap over more than two lines.";
15 // Test the inplace-editor behavior with a maxWidth configuration option
18 add_task(async function () {
19 await addTab("data:text/html;charset=utf-8,inplace editor max width tests");
20 const { host, doc } = await createHost();
22 info("Testing the maxWidth option in pixels, to precisely check the size");
23 await new Promise(resolve => {
24 createInplaceEditorAndClick(
37 gBrowser.removeCurrentTab();
40 const testMaxWidth = async function (editor) {
41 is(editor.input.value, START_TEXT, "Span text content should be used");
43 editor.input.offsetWidth,
45 "Input width should be strictly smaller than MAX_WIDTH"
47 is(getLines(editor.input), 1, "Input should display 1 line of text");
49 info("Check a text is on several lines if it does not fit MAX_WIDTH");
50 for (const key of LONG_TEXT) {
51 EventUtils.sendChar(key);
52 checkScrollbars(editor.input);
55 is(editor.input.value, LONG_TEXT, "Long text should be the input value");
57 editor.input.offsetWidth,
59 "Input width should be the same as MAX_WIDTH"
61 is(getLines(editor.input), 3, "Input should display 3 lines of text");
62 checkScrollbars(editor.input);
64 info("Delete all characters on line 3.");
65 while (getLines(editor.input) === 3) {
66 EventUtils.sendKey("BACK_SPACE");
67 checkScrollbars(editor.input);
71 editor.input.offsetWidth,
73 "Input width should be the same as MAX_WIDTH"
75 is(getLines(editor.input), 2, "Input should display 2 lines of text");
76 checkScrollbars(editor.input);
78 info("Delete all characters on line 2.");
79 while (getLines(editor.input) === 2) {
80 EventUtils.sendKey("BACK_SPACE");
81 checkScrollbars(editor.input);
84 is(getLines(editor.input), 1, "Input should display 1 line of text");
85 checkScrollbars(editor.input);
87 info("Delete all characters.");
88 while (editor.input.value !== "") {
89 EventUtils.sendKey("BACK_SPACE");
90 checkScrollbars(editor.input);
94 editor.input.offsetWidth,
96 "Input width should again be strictly smaller than MAX_WIDTH"
99 editor.input.offsetWidth,
101 "Even with no content, the input has a non-zero width"
103 is(getLines(editor.input), 1, "Input should display 1 line of text");
104 checkScrollbars(editor.input);
106 info("Leave the inplace-editor");
107 EventUtils.sendKey("RETURN");
111 * Retrieve the current number of lines displayed in the provided textarea.
113 * @param {DOMNode} textarea
114 * @return {Number} the number of lines
116 function getLines(textarea) {
117 const win = textarea.ownerDocument.defaultView;
118 const style = win.getComputedStyle(textarea);
119 return Math.floor(textarea.clientHeight / parseFloat(style.fontSize));
123 * Verify that the provided textarea has no vertical or horizontal scrollbar.
125 * @param {DOMNode} textarea
127 function checkScrollbars(textarea) {
129 textarea.scrollHeight,
130 textarea.clientHeight,
131 "Textarea should never have vertical scrollbars"
134 textarea.scrollWidth,
135 textarea.clientWidth,
136 "Textarea should never have horizontal scrollbars"