From 26a029d407be480d791972afb5975cf62c9360a6 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 02:47:55 +0200 Subject: Adding upstream version 124.0.1. Signed-off-by: Daniel Baumann --- remote/shared/test/xpcshell/head.js | 3 + remote/shared/test/xpcshell/test_AppInfo.js | 53 ++ .../test/xpcshell/test_ChallengeHeaderParser.js | 140 ++++ remote/shared/test/xpcshell/test_DOM.js | 479 +++++++++++ remote/shared/test/xpcshell/test_Format.js | 108 +++ remote/shared/test/xpcshell/test_Navigate.js | 879 +++++++++++++++++++++ remote/shared/test/xpcshell/test_Realm.js | 116 +++ .../test/xpcshell/test_RecommendedPreferences.js | 118 +++ remote/shared/test/xpcshell/test_Stack.js | 120 +++ remote/shared/test/xpcshell/test_Sync.js | 436 ++++++++++ remote/shared/test/xpcshell/test_TabManager.js | 56 ++ remote/shared/test/xpcshell/test_UUID.js | 21 + remote/shared/test/xpcshell/xpcshell.toml | 24 + 13 files changed, 2553 insertions(+) create mode 100644 remote/shared/test/xpcshell/head.js create mode 100644 remote/shared/test/xpcshell/test_AppInfo.js create mode 100644 remote/shared/test/xpcshell/test_ChallengeHeaderParser.js create mode 100644 remote/shared/test/xpcshell/test_DOM.js create mode 100644 remote/shared/test/xpcshell/test_Format.js create mode 100644 remote/shared/test/xpcshell/test_Navigate.js create mode 100644 remote/shared/test/xpcshell/test_Realm.js create mode 100644 remote/shared/test/xpcshell/test_RecommendedPreferences.js create mode 100644 remote/shared/test/xpcshell/test_Stack.js create mode 100644 remote/shared/test/xpcshell/test_Sync.js create mode 100644 remote/shared/test/xpcshell/test_TabManager.js create mode 100644 remote/shared/test/xpcshell/test_UUID.js create mode 100644 remote/shared/test/xpcshell/xpcshell.toml (limited to 'remote/shared/test/xpcshell') diff --git a/remote/shared/test/xpcshell/head.js b/remote/shared/test/xpcshell/head.js new file mode 100644 index 0000000000..2e7cf578d3 --- /dev/null +++ b/remote/shared/test/xpcshell/head.js @@ -0,0 +1,3 @@ +const SVG_NS = "http://www.w3.org/2000/svg"; +const XHTML_NS = "http://www.w3.org/1999/xhtml"; +const XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"; diff --git a/remote/shared/test/xpcshell/test_AppInfo.js b/remote/shared/test/xpcshell/test_AppInfo.js new file mode 100644 index 0000000000..9149564aa1 --- /dev/null +++ b/remote/shared/test/xpcshell/test_AppInfo.js @@ -0,0 +1,53 @@ +/* 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/. */ + +"use strict"; + +const { AppConstants } = ChromeUtils.importESModule( + "resource://gre/modules/AppConstants.sys.mjs" +); + +const { AppInfo, getTimeoutMultiplier } = ChromeUtils.importESModule( + "chrome://remote/content/shared/AppInfo.sys.mjs" +); + +// Minimal xpcshell tests for AppInfo; Services.appinfo.* is not available + +add_task(function test_custom_properties() { + const properties = [ + // platforms + "isAndroid", + "isLinux", + "isMac", + "isWindows", + // applications + "isFirefox", + "isThunderbird", + ]; + + for (const prop of properties) { + equal( + typeof AppInfo[prop], + "boolean", + `Custom property ${prop} has expected type` + ); + } +}); + +add_task(function test_getTimeoutMultiplier() { + const message = "Timeout multiplier has expected value"; + const timeoutMultiplier = getTimeoutMultiplier(); + + if ( + AppConstants.DEBUG || + AppConstants.MOZ_CODE_COVERAGE || + AppConstants.ASAN + ) { + equal(timeoutMultiplier, 4, message); + } else if (AppConstants.TSAN) { + equal(timeoutMultiplier, 8, message); + } else { + equal(timeoutMultiplier, 1, message); + } +}); diff --git a/remote/shared/test/xpcshell/test_ChallengeHeaderParser.js b/remote/shared/test/xpcshell/test_ChallengeHeaderParser.js new file mode 100644 index 0000000000..fa624e9c20 --- /dev/null +++ b/remote/shared/test/xpcshell/test_ChallengeHeaderParser.js @@ -0,0 +1,140 @@ +/* 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/. */ + +const { parseChallengeHeader } = ChromeUtils.importESModule( + "chrome://remote/content/shared/ChallengeHeaderParser.sys.mjs" +); + +add_task(async function test_single_scheme() { + const TEST_HEADERS = [ + { + // double quotes + header: 'Basic realm="test"', + params: [{ name: "realm", value: "test" }], + }, + { + // single quote + header: "Basic realm='test'", + params: [{ name: "realm", value: "test" }], + }, + { + // multiline + header: `Basic + realm='test'`, + params: [{ name: "realm", value: "test" }], + }, + { + // with additional parameter. + header: 'Basic realm="test", charset="UTF-8"', + params: [ + { name: "realm", value: "test" }, + { name: "charset", value: "UTF-8" }, + ], + }, + ]; + for (const { header, params } of TEST_HEADERS) { + const challenges = parseChallengeHeader(header); + equal(challenges.length, 1); + equal(challenges[0].scheme, "Basic"); + deepEqual(challenges[0].params, params); + } +}); + +add_task(async function test_realmless_scheme() { + const TEST_HEADERS = [ + { + // no parameter + header: "Custom", + params: [], + }, + { + // one non-realm parameter + header: "Custom charset='UTF-8'", + params: [{ name: "charset", value: "UTF-8" }], + }, + ]; + + for (const { header, params } of TEST_HEADERS) { + const challenges = parseChallengeHeader(header); + equal(challenges.length, 1); + equal(challenges[0].scheme, "Custom"); + deepEqual(challenges[0].params, params); + } +}); + +add_task(async function test_multiple_schemes() { + const TEST_HEADERS = [ + { + header: 'Scheme1 realm="foo", Scheme2 realm="bar"', + params: [ + [{ name: "realm", value: "foo" }], + [{ name: "realm", value: "bar" }], + ], + }, + { + header: 'Scheme1 realm="foo", charset="UTF-8", Scheme2 realm="bar"', + params: [ + [ + { name: "realm", value: "foo" }, + { name: "charset", value: "UTF-8" }, + ], + [{ name: "realm", value: "bar" }], + ], + }, + { + header: `Scheme1 realm="foo", + charset="UTF-8", + Scheme2 realm="bar"`, + params: [ + [ + { name: "realm", value: "foo" }, + { name: "charset", value: "UTF-8" }, + ], + [{ name: "realm", value: "bar" }], + ], + }, + ]; + for (const { header, params } of TEST_HEADERS) { + const challenges = parseChallengeHeader(header); + equal(challenges.length, 2); + equal(challenges[0].scheme, "Scheme1"); + deepEqual(challenges[0].params, params[0]); + equal(challenges[1].scheme, "Scheme2"); + deepEqual(challenges[1].params, params[1]); + } +}); + +add_task(async function test_digest_scheme() { + const header = `Digest + realm="http-auth@example.org", + qop="auth, auth-int", + algorithm=SHA-256, + nonce="7ypf/xlj9XXwfDPEoM4URrv/xwf94BcCAzFZH4GiTo0v", + opaque="FQhe/qaU925kfnzjCev0ciny7QMkPqMAFRtzCUYo5tdS"`; + + const challenges = parseChallengeHeader(header); + equal(challenges.length, 1); + equal(challenges[0].scheme, "Digest"); + + // Note: we are not doing a deepEqual check here, because one of the params + // actually contains a `,` inside quotes for its value, which will not be + // handled properly by the current ChallengeHeaderParser. See Bug 1857847. + const realmParam = challenges[0].params.find(param => param.name === "realm"); + ok(realmParam); + equal(realmParam.value, "http-auth@example.org"); + + // Once Bug 1857847 is addressed, this should start failing and can be + // switched to deepEqual. + notDeepEqual( + challenges[0].params, + [ + { name: "realm", value: "http-auth@example.org" }, + { name: "qop", value: "auth, auth-int" }, + { name: "algorithm", value: "SHA-256" }, + { name: "nonce", value: "7ypf/xlj9XXwfDPEoM4URrv/xwf94BcCAzFZH4GiTo0v" }, + { name: "opaque", value: "FQhe/qaU925kfnzjCev0ciny7QMkPqMAFRtzCUYo5tdS" }, + ], + "notDeepEqual should be changed to deepEqual when Bug 1857847 is fixed" + ); +}); diff --git a/remote/shared/test/xpcshell/test_DOM.js b/remote/shared/test/xpcshell/test_DOM.js new file mode 100644 index 0000000000..19844659b9 --- /dev/null +++ b/remote/shared/test/xpcshell/test_DOM.js @@ -0,0 +1,479 @@ +/* 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/. */ + +const { dom } = ChromeUtils.importESModule( + "chrome://remote/content/shared/DOM.sys.mjs" +); +const { NodeCache } = ChromeUtils.importESModule( + "chrome://remote/content/shared/webdriver/NodeCache.sys.mjs" +); + +class MockElement { + constructor(tagName, attrs = {}) { + this.tagName = tagName; + this.localName = tagName; + + this.isConnected = false; + this.ownerGlobal = { + document: { + isActive() { + return true; + }, + }, + }; + + for (let attr in attrs) { + this[attr] = attrs[attr]; + } + } + + get nodeType() { + return 1; + } + + get ELEMENT_NODE() { + return 1; + } + + // this is a severely limited CSS selector + // that only supports lists of tag names + matches(selector) { + let tags = selector.split(","); + return tags.includes(this.localName); + } +} + +class MockXULElement extends MockElement { + constructor(tagName, attrs = {}) { + super(tagName, attrs); + this.namespaceURI = XUL_NS; + + if (typeof this.ownerDocument == "undefined") { + this.ownerDocument = {}; + } + if (typeof this.ownerDocument.documentElement == "undefined") { + this.ownerDocument.documentElement = { namespaceURI: XUL_NS }; + } + } +} + +const xulEl = new MockXULElement("text"); + +const domElInPrivilegedDocument = new MockElement("input", { + nodePrincipal: { isSystemPrincipal: true }, +}); +const xulElInPrivilegedDocument = new MockXULElement("text", { + nodePrincipal: { isSystemPrincipal: true }, +}); + +function setupTest() { + const browser = Services.appShell.createWindowlessBrowser(false); + + browser.document.body.innerHTML = ` +
+ + + + +
+ `; + + const divEl = browser.document.querySelector("div"); + const svgEl = browser.document.querySelector("svg"); + const textareaEl = browser.document.querySelector("textarea"); + const videoEl = browser.document.querySelector("video"); + + const iframeEl = browser.document.querySelector("iframe"); + const childEl = iframeEl.contentDocument.createElement("div"); + iframeEl.contentDocument.body.appendChild(childEl); + + const shadowRoot = videoEl.openOrClosedShadowRoot; + + return { + browser, + nodeCache: new NodeCache(), + childEl, + divEl, + iframeEl, + shadowRoot, + svgEl, + textareaEl, + videoEl, + }; +} + +add_task(function test_findClosest() { + const { divEl, videoEl } = setupTest(); + + equal(dom.findClosest(divEl, "foo"), null); + equal(dom.findClosest(videoEl, "div"), divEl); +}); + +add_task(function test_isSelected() { + const { browser, divEl } = setupTest(); + + const checkbox = browser.document.createElement("input"); + checkbox.setAttribute("type", "checkbox"); + + ok(!dom.isSelected(checkbox)); + checkbox.checked = true; + ok(dom.isSelected(checkbox)); + + // selected is not a property of + checkbox.selected = true; + checkbox.checked = false; + ok(!dom.isSelected(checkbox)); + + const option = browser.document.createElement("option"); + + ok(!dom.isSelected(option)); + option.selected = true; + ok(dom.isSelected(option)); + + // checked is not a property of