summaryrefslogtreecommitdiffstats
path: root/devtools/client/jsonview/test/browser_jsonview_url_linkification.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /devtools/client/jsonview/test/browser_jsonview_url_linkification.js
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'devtools/client/jsonview/test/browser_jsonview_url_linkification.js')
-rw-r--r--devtools/client/jsonview/test/browser_jsonview_url_linkification.js88
1 files changed, 88 insertions, 0 deletions
diff --git a/devtools/client/jsonview/test/browser_jsonview_url_linkification.js b/devtools/client/jsonview/test/browser_jsonview_url_linkification.js
new file mode 100644
index 0000000000..19d1f27f0c
--- /dev/null
+++ b/devtools/client/jsonview/test/browser_jsonview_url_linkification.js
@@ -0,0 +1,88 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+const { ELLIPSIS } = require("resource://devtools/shared/l10n.js");
+
+add_task(async function () {
+ info("Test short URL linkification JSON started");
+
+ const url = "https://example.com/";
+ const tab = await addJsonViewTab(
+ "data:application/json," + JSON.stringify([url])
+ );
+ await testLinkNavigation({ browser: tab.linkedBrowser, url });
+
+ info("Switch back to the JSONViewer");
+ await BrowserTestUtils.switchTab(gBrowser, tab);
+
+ await testLinkNavigation({
+ browser: tab.linkedBrowser,
+ url,
+ clickLabel: true,
+ });
+});
+
+add_task(async function () {
+ info("Test long URL linkification JSON started");
+
+ const url = "https://example.com/" + "a".repeat(100);
+ const tab = await addJsonViewTab(
+ "data:application/json," + JSON.stringify([url])
+ );
+
+ await testLinkNavigation({ browser: tab.linkedBrowser, url });
+
+ info("Switch back to the JSONViewer");
+ await BrowserTestUtils.switchTab(gBrowser, tab);
+
+ await testLinkNavigation({
+ browser: tab.linkedBrowser,
+ url,
+ urlText: url.slice(0, 24) + ELLIPSIS + url.slice(-24),
+ clickLabel: true,
+ });
+});
+
+/**
+ * Assert that the expected link is displayed and that clicking on it navigates to the
+ * expected url.
+ *
+ * @param {Object} option object containing:
+ * - browser (mandatory): the browser the tab will be opened in.
+ * - url (mandatory): The url we should navigate to.
+ * - urlText: The expected displayed text of the url.
+ * Falls back to `url` if not filled
+ * - clickLabel: Should we click the label before doing assertions.
+ */
+async function testLinkNavigation({
+ browser,
+ url,
+ urlText,
+ clickLabel = false,
+}) {
+ const onTabLoaded = BrowserTestUtils.waitForNewTab(gBrowser, url);
+
+ SpecialPowers.spawn(browser, [[urlText || url, url, clickLabel]], args => {
+ const [expectedURLText, expectedURL, shouldClickLabel] = args;
+ const { document } = content;
+
+ if (shouldClickLabel === true) {
+ document.querySelector(".jsonPanelBox .treeTable .treeLabel").click();
+ }
+
+ const link = document.querySelector(
+ ".jsonPanelBox .treeTable .treeValueCell a"
+ );
+ is(link.textContent, expectedURLText, "The expected URL is displayed.");
+ is(link.href, expectedURL, "The URL was linkified.");
+
+ link.click();
+ });
+
+ const newTab = await onTabLoaded;
+ // We only need to check that newTab is truthy since
+ // BrowserTestUtils.waitForNewTab checks the URL.
+ ok(newTab, "The expected tab was opened.");
+}