diff options
Diffstat (limited to 'devtools/client/webconsole/test/browser/browser_jsterm_autocomplete_accept_no_scroll.js')
-rw-r--r-- | devtools/client/webconsole/test/browser/browser_jsterm_autocomplete_accept_no_scroll.js | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/devtools/client/webconsole/test/browser/browser_jsterm_autocomplete_accept_no_scroll.js b/devtools/client/webconsole/test/browser/browser_jsterm_autocomplete_accept_no_scroll.js new file mode 100644 index 0000000000..cfdb17d8da --- /dev/null +++ b/devtools/client/webconsole/test/browser/browser_jsterm_autocomplete_accept_no_scroll.js @@ -0,0 +1,54 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +// Test that the accepting an autocompletion does not scroll the input. + +const TEST_URI = `data:text/html;charset=utf-8,<!DOCTYPE html> + <script> + /* Create a prototype-less object so popup does not contain native + * Object prototype properties. + */ + window.foobar = Object.create(null, Object.getOwnPropertyDescriptors({ + item0: "value0", + item1: "value1", + })); + </script>`; + +add_task(async function () { + const hud = await openNewTabAndConsole(TEST_URI); + const { jsterm, ui } = hud; + const { autocompletePopup: popup } = jsterm; + + info("Insert multiple new lines so the input overflows"); + const onPopUpOpen = popup.once("popup-opened"); + const lines = "\n".repeat(200); + setInputValue(hud, lines); + + info("Fire the autocompletion popup"); + EventUtils.sendString("window.foobar."); + + await onPopUpOpen; + const scrollableEl = ui.window.document.querySelector(".CodeMirror-scroll"); + + Assert.greater(scrollableEl.scrollTop, 0, "The input overflows"); + const scrollTop = scrollableEl.scrollTop; + + info("Hit Enter to accept the autocompletion"); + const onPopupClose = popup.once("popup-closed"); + EventUtils.synthesizeKey("KEY_Enter"); + await onPopupClose; + + ok(!popup.isOpen, "popup is not open after KEY_Enter"); + is( + getInputValue(hud), + lines + "window.foobar.item0", + "completion was successful after KEY_Enter" + ); + is( + scrollableEl.scrollTop, + scrollTop, + "The scrolling position stayed the same when accepting the completion" + ); +}); |