diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /devtools/client/aboutdebugging/test/xpcshell | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'devtools/client/aboutdebugging/test/xpcshell')
5 files changed, 255 insertions, 0 deletions
diff --git a/devtools/client/aboutdebugging/test/xpcshell/.eslintrc.js b/devtools/client/aboutdebugging/test/xpcshell/.eslintrc.js new file mode 100644 index 0000000000..8611c174f5 --- /dev/null +++ b/devtools/client/aboutdebugging/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/aboutdebugging/test/xpcshell/test_extensions_path.js b/devtools/client/aboutdebugging/test/xpcshell/test_extensions_path.js new file mode 100644 index 0000000000..1ec9f0d7c2 --- /dev/null +++ b/devtools/client/aboutdebugging/test/xpcshell/test_extensions_path.js @@ -0,0 +1,27 @@ +/* global equal */ + +"use strict"; + +const { + parseFileUri, +} = require("resource://devtools/client/aboutdebugging/src/modules/extensions-helper.js"); + +add_task(async function testParseFileUri() { + equal( + parseFileUri("file:///home/me/my-extension/"), + "/home/me/my-extension/", + "UNIX paths are supported" + ); + + equal( + parseFileUri("file:///C:/Documents/my-extension/"), + "C:/Documents/my-extension/", + "Windows paths are supported" + ); + + equal( + parseFileUri("file://home/Documents/my-extension/"), + "home/Documents/my-extension/", + "Windows network paths are supported" + ); +}); diff --git a/devtools/client/aboutdebugging/test/xpcshell/test_runtime_default_preferences.js b/devtools/client/aboutdebugging/test/xpcshell/test_runtime_default_preferences.js new file mode 100644 index 0000000000..637e42e078 --- /dev/null +++ b/devtools/client/aboutdebugging/test/xpcshell/test_runtime_default_preferences.js @@ -0,0 +1,203 @@ +"use strict"; + +const { sinon } = ChromeUtils.importESModule( + "resource://testing-common/Sinon.sys.mjs" +); +const { + setDefaultPreferencesIfNeeded, + PREFERENCE_TYPES, +} = require("resource://devtools/client/aboutdebugging/src/modules/runtime-default-preferences.js"); + +const CHAR_PREF = "some.char.pref"; +const BOOL_PREF = "some.bool.pref"; +const INT_PREF = "some.int.pref"; + +const TEST_PREFERENCES = [ + { + prefName: BOOL_PREF, + defaultValue: false, + trait: "boolPrefTrait", + type: PREFERENCE_TYPES.BOOL, + }, + { + prefName: CHAR_PREF, + defaultValue: "", + trait: "charPrefTrait", + type: PREFERENCE_TYPES.CHAR, + }, + { + prefName: INT_PREF, + defaultValue: 1, + trait: "intPrefTrait", + type: PREFERENCE_TYPES.INT, + }, +]; + +add_task(async function test_with_traits() { + // Create a front that indicates that the preferences should be safe to query. + // We should not perform any additional call to the preferences front. + const preferencesFront = { + getTraits: () => ({ + boolPrefTrait: true, + charPrefTrait: true, + intPrefTrait: true, + }), + + setBoolPref: sinon.spy(), + getBoolPref: sinon.spy(), + setCharPref: sinon.spy(), + getCharPref: sinon.spy(), + setIntPref: sinon.spy(), + getIntPref: sinon.spy(), + }; + + const clientWrapper = createClientWrapper(preferencesFront); + await setDefaultPreferencesIfNeeded(clientWrapper, TEST_PREFERENCES); + + // Check get/setBoolPref spies + ok(preferencesFront.getBoolPref.notCalled, "getBoolPref was not called"); + ok(preferencesFront.setBoolPref.notCalled, "setBoolPref was not called"); + + // Check get/setCharPref spies + ok(preferencesFront.getCharPref.notCalled, "getCharPref was not called"); + ok(preferencesFront.setCharPref.notCalled, "setCharPref was not called"); + + // Check get/setIntPref spies + ok(preferencesFront.getIntPref.notCalled, "getIntPref was not called"); + ok(preferencesFront.setIntPref.notCalled, "setIntPref was not called"); +}); + +add_task(async function test_without_traits_no_error() { + // Create a front that indicates that the preferences are missing, but which + // doesn't fail when getting the preferences. This will typically happen when + // the user managed to set the preference on the remote runtime. + // We should not erase user values, so we should not call the set*Pref APIs. + const preferencesFront = { + getTraits: () => ({ + boolPrefTrait: false, + charPrefTrait: false, + intPrefTrait: false, + }), + + setBoolPref: sinon.spy(), + getBoolPref: sinon.spy(), + setCharPref: sinon.spy(), + getCharPref: sinon.spy(), + setIntPref: sinon.spy(), + getIntPref: sinon.spy(), + }; + + const clientWrapper = createClientWrapper(preferencesFront); + await setDefaultPreferencesIfNeeded(clientWrapper, TEST_PREFERENCES); + + // Check get/setBoolPref spies + ok( + preferencesFront.getBoolPref.calledWith(BOOL_PREF), + "getBoolPref was called with the proper preference name" + ); + ok(preferencesFront.getBoolPref.calledOnce, "getBoolPref was called once"); + ok(preferencesFront.setBoolPref.notCalled, "setBoolPref was not called"); + + // Check get/setCharPref spies + ok( + preferencesFront.getCharPref.calledWith(CHAR_PREF), + "getCharPref was called with the proper preference name" + ); + ok(preferencesFront.getCharPref.calledOnce, "getCharPref was called once"); + ok(preferencesFront.setCharPref.notCalled, "setCharPref was not called"); + + // Check get/setIntPref spies + ok( + preferencesFront.getIntPref.calledWith(INT_PREF), + "getIntPref was called with the proper preference name" + ); + ok(preferencesFront.getIntPref.calledOnce, "getIntPref was called once"); + ok(preferencesFront.setIntPref.notCalled, "setIntPref was not called"); +}); + +add_task(async function test_without_traits_with_error() { + // Create a front that indicates that the preferences are missing, and which + // will also throw when attempting to get said preferences. + // This should lead to create default values for the preferences. + const preferencesFront = { + getTraits: () => ({ + boolPrefTrait: false, + charPrefTrait: false, + intPrefTrait: false, + }), + + setBoolPref: sinon.spy(), + getBoolPref: sinon.spy(pref => { + if (pref === BOOL_PREF) { + throw new Error("Invalid preference"); + } + }), + setCharPref: sinon.spy(), + getCharPref: sinon.spy(pref => { + if (pref === CHAR_PREF) { + throw new Error("Invalid preference"); + } + }), + setIntPref: sinon.spy(), + getIntPref: sinon.spy(pref => { + if (pref === INT_PREF) { + throw new Error("Invalid preference"); + } + }), + }; + + const clientWrapper = createClientWrapper(preferencesFront); + await setDefaultPreferencesIfNeeded(clientWrapper, TEST_PREFERENCES); + + // Check get/setBoolPref spies + ok(preferencesFront.getBoolPref.calledOnce, "getBoolPref was called once"); + ok(preferencesFront.getBoolPref.threw(), "getBoolPref threw"); + ok( + preferencesFront.getBoolPref.calledWith(BOOL_PREF), + "getBoolPref was called with the proper preference name" + ); + + ok(preferencesFront.setBoolPref.calledOnce, "setBoolPref was called once"); + ok( + preferencesFront.setBoolPref.calledWith(BOOL_PREF, false), + "setBoolPref was called with the proper preference name and value" + ); + + // Check get/setCharPref spies + ok(preferencesFront.getCharPref.calledOnce, "getCharPref was called once"); + ok(preferencesFront.getCharPref.threw(), "getCharPref threw"); + ok( + preferencesFront.getCharPref.calledWith(CHAR_PREF), + "getCharPref was called with the proper preference name" + ); + + ok(preferencesFront.setCharPref.calledOnce, "setCharPref was called once"); + ok( + preferencesFront.setCharPref.calledWith(CHAR_PREF, ""), + "setCharPref was called with the proper preference name and value" + ); + + // Check get/setIntPref spies + ok(preferencesFront.getIntPref.calledOnce, "getIntPref was called once"); + ok(preferencesFront.getIntPref.threw(), "getIntPref threw"); + ok( + preferencesFront.getIntPref.calledWith(INT_PREF), + "getIntPref was called with the proper preference name" + ); + + ok(preferencesFront.setIntPref.calledOnce, "setIntPref was called once"); + ok( + preferencesFront.setIntPref.calledWith(INT_PREF, 1), + "setIntPref was called with the proper preference name and value" + ); +}); + +function createClientWrapper(preferencesFront) { + const clientWrapper = { + getFront: name => { + return preferencesFront; + }, + }; + + return clientWrapper; +} diff --git a/devtools/client/aboutdebugging/test/xpcshell/xpcshell-head.js b/devtools/client/aboutdebugging/test/xpcshell/xpcshell-head.js new file mode 100644 index 0000000000..733c0400da --- /dev/null +++ b/devtools/client/aboutdebugging/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/aboutdebugging/test/xpcshell/xpcshell.toml b/devtools/client/aboutdebugging/test/xpcshell/xpcshell.toml new file mode 100644 index 0000000000..7444308fe4 --- /dev/null +++ b/devtools/client/aboutdebugging/test/xpcshell/xpcshell.toml @@ -0,0 +1,9 @@ +[DEFAULT] +tags = "devtools" +head = "xpcshell-head.js" +firefox-appdir = "browser" +skip-if = ["os == 'android'"] + +["test_extensions_path.js"] + +["test_runtime_default_preferences.js"] |