diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /toolkit/modules/tests/browser/browser_BrowserUtils.js | |
parent | Initial commit. (diff) | |
download | firefox-esr-upstream.tar.xz firefox-esr-upstream.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'toolkit/modules/tests/browser/browser_BrowserUtils.js')
-rw-r--r-- | toolkit/modules/tests/browser/browser_BrowserUtils.js | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/toolkit/modules/tests/browser/browser_BrowserUtils.js b/toolkit/modules/tests/browser/browser_BrowserUtils.js new file mode 100644 index 0000000000..da28c07b69 --- /dev/null +++ b/toolkit/modules/tests/browser/browser_BrowserUtils.js @@ -0,0 +1,50 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +add_task(async function test_getSelectionDetails_input() { + // Mostly a regression test for bug 1420560 + const url = kFixtureBaseURL + "file_getSelectionDetails_inputs.html"; + await BrowserTestUtils.withNewTab({ gBrowser, url }, async browser => { + await SpecialPowers.spawn(browser, [], () => { + function checkSelection({ id, text, linkURL }) { + const { SelectionUtils } = ChromeUtils.importESModule( + "resource://gre/modules/SelectionUtils.sys.mjs" + ); + content.document.getElementById(id).select(); + // It seems that when running as a test, the previous line will set + // the both the window's selection and the input's selection to contain + // the input's text. Outside of tests, only the input's selection seems + // to be updated, so we explicitly clear the window's selection to + // ensure we're doing the right thing in the case that only the input's + // selection is present. + content.getSelection().removeAllRanges(); + let info = SelectionUtils.getSelectionDetails(content); + Assert.equal(text, info.text); + Assert.ok(!info.collapsed); + Assert.equal(linkURL, info.linkURL); + } + + checkSelection({ + id: "url-no-scheme", + text: "test.example.com", + linkURL: "http://test.example.com/", + }); + checkSelection({ + id: "url-with-scheme", + text: "https://test.example.com", + linkURL: "https://test.example.com/", + }); + checkSelection({ + id: "not-url", + text: "foo. bar", + linkURL: null, + }); + checkSelection({ + id: "not-url-number", + text: "3.5", + linkURL: null, + }); + }); + }); +}); |