summaryrefslogtreecommitdiffstats
path: root/devtools/client/shared/remote-debugging/test
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/shared/remote-debugging/test
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/shared/remote-debugging/test')
-rw-r--r--devtools/client/shared/remote-debugging/test/xpcshell/.eslintrc.js6
-rw-r--r--devtools/client/shared/remote-debugging/test/xpcshell/test_remote_client_manager.js153
-rw-r--r--devtools/client/shared/remote-debugging/test/xpcshell/test_version_checker.js159
-rw-r--r--devtools/client/shared/remote-debugging/test/xpcshell/xpcshell-head.js10
-rw-r--r--devtools/client/shared/remote-debugging/test/xpcshell/xpcshell.ini8
5 files changed, 336 insertions, 0 deletions
diff --git a/devtools/client/shared/remote-debugging/test/xpcshell/.eslintrc.js b/devtools/client/shared/remote-debugging/test/xpcshell/.eslintrc.js
new file mode 100644
index 0000000000..86bd54c245
--- /dev/null
+++ b/devtools/client/shared/remote-debugging/test/xpcshell/.eslintrc.js
@@ -0,0 +1,6 @@
+"use strict";
+
+module.exports = {
+ // Extend from the common devtools xpcshell eslintrc config.
+ extends: "../../../../../.eslintrc.xpcshell.js",
+};
diff --git a/devtools/client/shared/remote-debugging/test/xpcshell/test_remote_client_manager.js b/devtools/client/shared/remote-debugging/test/xpcshell/test_remote_client_manager.js
new file mode 100644
index 0000000000..e66c38b67d
--- /dev/null
+++ b/devtools/client/shared/remote-debugging/test/xpcshell/test_remote_client_manager.js
@@ -0,0 +1,153 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+const {
+ remoteClientManager,
+} = require("resource://devtools/client/shared/remote-debugging/remote-client-manager.js");
+const {
+ CONNECTION_TYPES,
+} = require("resource://devtools/client/shared/remote-debugging/constants.js");
+
+add_task(async function testRemoteClientManager() {
+ for (const type of Object.values(CONNECTION_TYPES)) {
+ const fakeClient = createFakeClient();
+ const runtimeInfo = {};
+ const clientId = "clientId";
+ const remoteId = remoteClientManager.getRemoteId(clientId, type);
+
+ const connectionType =
+ remoteClientManager.getConnectionTypeByRemoteId(remoteId);
+ equal(
+ connectionType,
+ type,
+ `[${type}]: Correct connection type was returned by getConnectionTypeByRemoteId`
+ );
+
+ equal(
+ remoteClientManager.hasClient(clientId, type),
+ false,
+ `[${type}]: hasClient returns false if no client was set`
+ );
+ equal(
+ remoteClientManager.getClient(clientId, type),
+ null,
+ `[${type}]: getClient returns null if no client was set`
+ );
+ equal(
+ remoteClientManager.getClientByRemoteId(remoteId),
+ null,
+ `[${type}]: getClientByRemoteId returns null if no client was set`
+ );
+ equal(
+ remoteClientManager.getRuntimeInfoByRemoteId(remoteId),
+ null,
+ `[${type}]: getRuntimeInfoByRemoteId returns null if no client was set`
+ );
+
+ remoteClientManager.setClient(clientId, type, fakeClient, runtimeInfo);
+ equal(
+ remoteClientManager.hasClient(clientId, type),
+ true,
+ `[${type}]: hasClient returns true`
+ );
+ equal(
+ remoteClientManager.getClient(clientId, type),
+ fakeClient,
+ `[${type}]: getClient returns the correct client`
+ );
+ equal(
+ remoteClientManager.getClientByRemoteId(remoteId),
+ fakeClient,
+ `[${type}]: getClientByRemoteId returns the correct client`
+ );
+ equal(
+ remoteClientManager.getRuntimeInfoByRemoteId(remoteId),
+ runtimeInfo,
+ `[${type}]: getRuntimeInfoByRemoteId returns the correct object`
+ );
+
+ remoteClientManager.removeClient(clientId, type);
+ equal(
+ remoteClientManager.hasClient(clientId, type),
+ false,
+ `[${type}]: hasClient returns false after removing the client`
+ );
+ equal(
+ remoteClientManager.getClient(clientId, type),
+ null,
+ `[${type}]: getClient returns null after removing the client`
+ );
+ equal(
+ remoteClientManager.getClientByRemoteId(remoteId),
+ null,
+ `[${type}]: getClientByRemoteId returns null after removing the client`
+ );
+ equal(
+ remoteClientManager.getRuntimeInfoByRemoteId(),
+ null,
+ `[${type}]: getRuntimeInfoByRemoteId returns null after removing the client`
+ );
+ }
+
+ // Test various fallback scenarios for APIs relying on remoteId, when called without a
+ // remoteId, we expect to get the information for the local this-firefox runtime.
+ const { THIS_FIREFOX } = CONNECTION_TYPES;
+ const thisFirefoxClient = createFakeClient();
+ const thisFirefoxInfo = {};
+ remoteClientManager.setClient(
+ THIS_FIREFOX,
+ THIS_FIREFOX,
+ thisFirefoxClient,
+ thisFirefoxInfo
+ );
+
+ equal(
+ remoteClientManager.getClientByRemoteId(),
+ thisFirefoxClient,
+ `[fallback]: getClientByRemoteId returns this-firefox if remoteId is null`
+ );
+ equal(
+ remoteClientManager.getRuntimeInfoByRemoteId(),
+ thisFirefoxInfo,
+ `[fallback]: getRuntimeInfoByRemoteId returns this-firefox if remoteId is null`
+ );
+
+ const otherRemoteId = remoteClientManager.getRemoteId(
+ "clientId",
+ CONNECTION_TYPES.USB
+ );
+ equal(
+ remoteClientManager.getClientByRemoteId(otherRemoteId),
+ null,
+ `[fallback]: getClientByRemoteId does not fallback if remoteId is non-null`
+ );
+ equal(
+ remoteClientManager.getRuntimeInfoByRemoteId(otherRemoteId),
+ null,
+ `[fallback]: getRuntimeInfoByRemoteId does not fallback if remoteId is non-null`
+ );
+});
+
+add_task(async function testRemoteClientManagerWithUnknownType() {
+ const remoteId = remoteClientManager.getRemoteId(
+ "someClientId",
+ "NotARealType"
+ );
+ const connectionType =
+ remoteClientManager.getConnectionTypeByRemoteId(remoteId);
+ equal(
+ connectionType,
+ CONNECTION_TYPES.UNKNOWN,
+ `Connection type UNKNOWN was returned by getConnectionTypeByRemoteId`
+ );
+});
+
+function createFakeClient() {
+ const EventEmitter = require("resource://devtools/shared/event-emitter.js");
+
+ const client = {};
+ EventEmitter.decorate(client);
+ return client;
+}
diff --git a/devtools/client/shared/remote-debugging/test/xpcshell/test_version_checker.js b/devtools/client/shared/remote-debugging/test/xpcshell/test_version_checker.js
new file mode 100644
index 0000000000..92f7d54a1e
--- /dev/null
+++ b/devtools/client/shared/remote-debugging/test/xpcshell/test_version_checker.js
@@ -0,0 +1,159 @@
+/* global equal */
+
+"use strict";
+
+const {
+ _compareVersionCompatibility,
+ checkVersionCompatibility,
+ COMPATIBILITY_STATUS,
+} = require("resource://devtools/client/shared/remote-debugging/version-checker.js");
+
+const TEST_DATA = [
+ {
+ description: "same build date and same version number",
+ localBuildId: "20190131000000",
+ localVersion: "60.0",
+ runtimeBuildId: "20190131000000",
+ runtimeVersion: "60.0",
+ expected: COMPATIBILITY_STATUS.COMPATIBLE,
+ },
+ {
+ description: "same build date and older version in range (-1)",
+ localBuildId: "20190131000000",
+ localVersion: "60.0",
+ runtimeBuildId: "20190131000000",
+ runtimeVersion: "59.0",
+ expected: COMPATIBILITY_STATUS.COMPATIBLE,
+ },
+ {
+ description: "same build date and older version in range (-2)",
+ localBuildId: "20190131000000",
+ localVersion: "60.0",
+ runtimeBuildId: "20190131000000",
+ runtimeVersion: "58.0",
+ expected: COMPATIBILITY_STATUS.COMPATIBLE,
+ },
+ {
+ description: "same build date and older version in range (-2 Nightly)",
+ localBuildId: "20190131000000",
+ localVersion: "60.0",
+ runtimeBuildId: "20190131000000",
+ runtimeVersion: "58.0a1",
+ expected: COMPATIBILITY_STATUS.COMPATIBLE,
+ },
+ {
+ description: "same build date and older version out of range (-3)",
+ localBuildId: "20190131000000",
+ localVersion: "60.0",
+ runtimeBuildId: "20190131000000",
+ runtimeVersion: "57.0",
+ expected: COMPATIBILITY_STATUS.TOO_OLD,
+ },
+ {
+ description: "same build date and newer version out of range (+1)",
+ localBuildId: "20190131000000",
+ localVersion: "60.0",
+ runtimeBuildId: "20190131000000",
+ runtimeVersion: "61.0",
+ expected: COMPATIBILITY_STATUS.TOO_RECENT,
+ },
+ {
+ description: "same major version and build date in range (-10 days)",
+ localBuildId: "20190131000000",
+ localVersion: "60.0",
+ runtimeBuildId: "20190121000000",
+ runtimeVersion: "60.0",
+ expected: COMPATIBILITY_STATUS.COMPATIBLE,
+ },
+ {
+ description: "same major version and build date in range (+2 days)",
+ localBuildId: "20190131000000",
+ localVersion: "60.0",
+ runtimeBuildId: "20190202000000",
+ runtimeVersion: "60.0",
+ expected: COMPATIBILITY_STATUS.COMPATIBLE,
+ },
+ {
+ description: "same major version and build date out of range (+8 days)",
+ localBuildId: "20190131000000",
+ localVersion: "60.0",
+ runtimeBuildId: "20190208000000",
+ runtimeVersion: "60.0",
+ expected: COMPATIBILITY_STATUS.TOO_RECENT,
+ },
+ {
+ description:
+ "fennec 68 compatibility error not raised for 68 -> 68 Android",
+ localBuildId: "20190131000000",
+ localVersion: "68.0",
+ runtimeBuildId: "20190202000000",
+ runtimeVersion: "68.0",
+ runtimeOs: "Android",
+ expected: COMPATIBILITY_STATUS.COMPATIBLE,
+ },
+ {
+ description:
+ "fennec 68 compatibility error not raised for 70 -> 68 Android",
+ localBuildId: "20190131000000",
+ localVersion: "70.0",
+ runtimeBuildId: "20190202000000",
+ runtimeVersion: "68.0",
+ runtimeOs: "Android",
+ expected: COMPATIBILITY_STATUS.COMPATIBLE,
+ },
+ {
+ description: "fennec 68 compatibility error raised for 71 -> 68 Android",
+ localBuildId: "20190131000000",
+ localVersion: "71.0",
+ runtimeBuildId: "20190202000000",
+ runtimeVersion: "68.0",
+ runtimeOs: "Android",
+ expected: COMPATIBILITY_STATUS.TOO_OLD_FENNEC,
+ },
+ {
+ description:
+ "fennec 68 compatibility error not raised for 71 -> 68 non-Android",
+ localBuildId: "20190131000000",
+ localVersion: "71.0",
+ runtimeBuildId: "20190202000000",
+ runtimeVersion: "68.0",
+ runtimeOs: "NotAndroid",
+ expected: COMPATIBILITY_STATUS.TOO_OLD,
+ },
+];
+
+add_task(async function testVersionChecker() {
+ for (const testData of TEST_DATA) {
+ const localDescription = {
+ appbuildid: testData.localBuildId,
+ platformversion: testData.localVersion,
+ };
+
+ const runtimeDescription = {
+ appbuildid: testData.runtimeBuildId,
+ platformversion: testData.runtimeVersion,
+ os: testData.runtimeOs,
+ };
+
+ const report = _compareVersionCompatibility(
+ localDescription,
+ runtimeDescription
+ );
+ equal(
+ report.status,
+ testData.expected,
+ "Expected status for test: " + testData.description
+ );
+ }
+});
+
+add_task(async function testVersionCheckWithVeryOldClient() {
+ // Use an empty object as devtools client, calling any method on it will fail.
+ const emptyClient = {};
+ const report = await checkVersionCompatibility(emptyClient);
+ equal(
+ report.status,
+ COMPATIBILITY_STATUS.TOO_OLD,
+ "Report status too old if devtools client is not implementing expected interface"
+ );
+});
diff --git a/devtools/client/shared/remote-debugging/test/xpcshell/xpcshell-head.js b/devtools/client/shared/remote-debugging/test/xpcshell/xpcshell-head.js
new file mode 100644
index 0000000000..733c0400da
--- /dev/null
+++ b/devtools/client/shared/remote-debugging/test/xpcshell/xpcshell-head.js
@@ -0,0 +1,10 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+/* eslint no-unused-vars: [2, {"vars": "local"}] */
+
+const { require } = ChromeUtils.importESModule(
+ "resource://devtools/shared/loader/Loader.sys.mjs"
+);
diff --git a/devtools/client/shared/remote-debugging/test/xpcshell/xpcshell.ini b/devtools/client/shared/remote-debugging/test/xpcshell/xpcshell.ini
new file mode 100644
index 0000000000..0579b8a674
--- /dev/null
+++ b/devtools/client/shared/remote-debugging/test/xpcshell/xpcshell.ini
@@ -0,0 +1,8 @@
+[DEFAULT]
+tags = devtools
+head = xpcshell-head.js
+firefox-appdir = browser
+skip-if = toolkit == 'android'
+
+[test_remote_client_manager.js]
+[test_version_checker.js]