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 09:22:09 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
commit43a97878ce14b72f0981164f87f2e35e14151312 (patch)
tree620249daf56c0258faa40cbdcf9cfba06de2a846 /devtools/client/jsonview/test/browser_jsonview_url_linkification.js
parentInitial commit. (diff)
downloadfirefox-upstream.tar.xz
firefox-upstream.zip
Adding upstream version 110.0.1.upstream/110.0.1upstream
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..9cba254398
--- /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.");
+}