Source code
Revision control
Copy as Markdown
Other Tools
Test Info: Warnings
- This test runs only with pattern: os != 'android'
- Manifest: browser/components/aiwindow/models/tests/xpcshell/xpcshell.toml
/* Any copyright is dedicated to the Public Domain.
"use strict";
const { AITab } = ChromeUtils.importESModule(
"moz-src:///browser/components/aiwindow/models/aitab/AITab.sys.mjs"
);
const { buildViewerURL, getViewerBaseURL } = AITab;
const VIEWER_PREF = "browser.smartwindow.aitab.viewerURL";
registerCleanupFunction(() => Services.prefs.clearUserPref(VIEWER_PREF));
add_task(function test_buildViewerURL_puts_config_in_hash() {
const surface = {
components: [{ id: "root", component: "Page", children: [] }],
dataModel: {},
};
const parsed = new URL(url);
Assert.equal(parsed.pathname, "/app", "path is unchanged");
Assert.equal(parsed.search, "", "config is NOT in the query string");
Assert.deepEqual(
JSON.parse(decodeURIComponent(parsed.hash.slice(1))),
surface,
"the surface round-trips through the URL hash fragment"
);
});
add_task(function test_buildViewerURL_strips_existing_hash() {
components: [],
});
Assert.ok(!url.includes("#stale"), "an existing hash on the base is dropped");
});
add_task(function test_getViewerBaseURL_requires_https() {
Services.prefs.clearUserPref(VIEWER_PREF);
Assert.equal(getViewerBaseURL(), null, "empty pref yields null");
Assert.equal(getViewerBaseURL(), null, "non-https pref yields null");
Services.prefs.setStringPref(VIEWER_PREF, "not a url");
Assert.equal(getViewerBaseURL(), null, "unparseable pref yields null");
Assert.equal(
getViewerBaseURL(),
"an https pref is returned with any hash stripped"
);
});