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/application/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/application/test/xpcshell')
7 files changed, 389 insertions, 0 deletions
diff --git a/devtools/client/application/test/xpcshell/.eslintrc.js b/devtools/client/application/test/xpcshell/.eslintrc.js new file mode 100644 index 0000000000..8611c174f5 --- /dev/null +++ b/devtools/client/application/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/application/test/xpcshell/test_manifest_reducer.js b/devtools/client/application/test/xpcshell/test_manifest_reducer.js new file mode 100644 index 0000000000..2e91b57442 --- /dev/null +++ b/devtools/client/application/test/xpcshell/test_manifest_reducer.js @@ -0,0 +1,201 @@ +/* Any copyright is dedicated to the Public Domain. +http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +const { + FETCH_MANIFEST_FAILURE, + FETCH_MANIFEST_START, + FETCH_MANIFEST_SUCCESS, + RESET_MANIFEST, + MANIFEST_MEMBER_VALUE_TYPES, +} = require("resource://devtools/client/application/src/constants.js"); + +const { ICON, COLOR, STRING, URL } = MANIFEST_MEMBER_VALUE_TYPES; + +const { + manifestReducer, + ManifestState, +} = require("resource://devtools/client/application/src/reducers/manifest-state.js"); + +const MANIFEST_PROCESSING = [ + // empty manifest + { + source: {}, + processed: {}, + }, + // manifest with just one member + { + source: { name: "Foo" }, + processed: { + identity: [{ key: "name", value: "Foo", type: STRING }], + }, + }, + // manifest with two members from the same category + { + source: { + short_name: "Short Foo", + name: "Long Foo", + }, + processed: { + identity: [ + { key: "short_name", value: "Short Foo", type: STRING }, + { key: "name", value: "Long Foo", type: STRING }, + ], + }, + }, + // manifest with members from two different categories + { + source: { + name: "Foo", + background_color: "#FF0000", + start_url: "https://example.com/?q=foo", + scope: "https://example.com", + }, + processed: { + identity: [{ key: "name", value: "Foo", type: STRING }], + presentation: [ + { key: "background_color", value: "#FF0000", type: COLOR }, + { key: "start_url", value: "https://example.com/?q=foo", type: URL }, + { key: "scope", value: "https://example.com", type: URL }, + ], + }, + }, + // manifest with icons + { + source: { + icons: [ + { + src: "something.png", + type: "image/png", + sizes: ["16x16", "32x32"], + purpose: ["any"], + }, + { + src: "another.svg", + type: "image/svg", + sizes: ["any"], + purpose: ["any maskable"], + }, + { + src: "something.png", + type: undefined, + sizes: undefined, + purpose: ["any"], + }, + ], + }, + processed: { + icons: [ + { + key: { sizes: "16x16 32x32", contentType: "image/png" }, + value: { src: "something.png", purpose: "any" }, + type: ICON, + }, + { + key: { sizes: "any", contentType: "image/svg" }, + value: { src: "another.svg", purpose: "any maskable" }, + type: ICON, + }, + { + key: { sizes: undefined, contentType: undefined }, + value: { src: "something.png", purpose: "any" }, + type: ICON, + }, + ], + }, + }, + // manifest with issues + { + source: { + moz_validation: [ + { warn: "A warning" }, + { error: "An error", type: "json" }, + ], + }, + processed: { + validation: [ + { level: "warning", message: "A warning", type: null }, + { level: "error", message: "An error", type: "json" }, + ], + }, + }, + // manifest with URL + { + source: { + moz_manifest_url: "https://example.com/manifest.json", + }, + processed: { + url: "https://example.com/manifest.json", + }, + }, +]; + +add_task(async function () { + info("Test manifest reducer: FETCH_MANIFEST_START action"); + + const state = ManifestState(); + const action = { type: FETCH_MANIFEST_START }; + const newState = manifestReducer(state, action); + + equal(newState.isLoading, true, "Loading flag is true"); +}); + +add_task(async function () { + info("Test manifest reducer: FETCH_MANIFEST_FAILURE action"); + + const state = Object.assign(ManifestState(), { isLoading: true }); + const action = { type: FETCH_MANIFEST_FAILURE, error: "some error" }; + const newState = manifestReducer(state, action); + + equal(newState.errorMessage, "some error", "Error message is as expected"); + equal(newState.isLoading, false, "Loading flag is false"); + equal(newState.manifest, null, "Manifest is null"); +}); + +add_task(async function () { + info("Test manifest reducer: FETCH_MANIFEST_SUCCESS action"); + + // test manifest processing + MANIFEST_PROCESSING.forEach(({ source, processed }) => { + test_manifest_processing(source, processed); + }); +}); + +add_task(async function () { + info("Test manifest reducer: RESET_MANIFEST action"); + + const state = Object.assign(ManifestState(), { + isLoading: true, + manifest: { identity: [{ key: "name", value: "Foo" }] }, + errorMessage: "some error", + }); + const action = { type: RESET_MANIFEST }; + const newState = manifestReducer(state, action); + + deepEqual(newState, ManifestState(), "Manifest has been reset to defaults"); +}); + +function test_manifest_processing(source, processed) { + const state = ManifestState(); + state.isLoading = true; + + const action = { type: FETCH_MANIFEST_SUCCESS, manifest: source }; + const newState = manifestReducer(state, action); + + // merge the expected processed manifst with some default values + const expected = Object.assign( + { + icons: [], + identity: [], + presentation: [], + url: undefined, + validation: [], + }, + processed + ); + + deepEqual(newState.manifest, expected, "Processed manifest as expected"); + equal(newState.errorMessage, "", "Error message is empty"); + equal(newState.isLoading, false, "Loading flag is false"); +} diff --git a/devtools/client/application/test/xpcshell/test_page_reducer.js b/devtools/client/application/test/xpcshell/test_page_reducer.js new file mode 100644 index 0000000000..9aecfc67bb --- /dev/null +++ b/devtools/client/application/test/xpcshell/test_page_reducer.js @@ -0,0 +1,22 @@ +/* Any copyright is dedicated to the Public Domain. +http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +const { + updateDomain, +} = require("resource://devtools/client/application/src/actions/page.js"); + +const { + pageReducer, + PageState, +} = require("resource://devtools/client/application/src/reducers/page-state.js"); + +add_task(async function () { + info("Test page reducer: UPDATE_DOMAIN action"); + const state = PageState(); + const action = updateDomain("https://example.com/foo/#bar"); + + const newState = pageReducer(state, action); + equal(newState.domain, "example.com"); +}); diff --git a/devtools/client/application/test/xpcshell/test_ui_reducer.js b/devtools/client/application/test/xpcshell/test_ui_reducer.js new file mode 100644 index 0000000000..22c1844238 --- /dev/null +++ b/devtools/client/application/test/xpcshell/test_ui_reducer.js @@ -0,0 +1,22 @@ +/* Any copyright is dedicated to the Public Domain. +http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +const { + updateSelectedPage, +} = require("resource://devtools/client/application/src/actions/ui.js"); + +const { + uiReducer, + UiState, +} = require("resource://devtools/client/application/src/reducers/ui-state.js"); + +add_task(async function () { + info("Test ui reducer: UPDATE_SELECTED_PAGE action"); + const state = UiState(); + const action = updateSelectedPage("foo"); + + const newState = uiReducer(state, action); + equal(newState.selectedPage, "foo"); +}); diff --git a/devtools/client/application/test/xpcshell/test_workers_reducer.js b/devtools/client/application/test/xpcshell/test_workers_reducer.js new file mode 100644 index 0000000000..a662c313df --- /dev/null +++ b/devtools/client/application/test/xpcshell/test_workers_reducer.js @@ -0,0 +1,115 @@ +/* Any copyright is dedicated to the Public Domain. +http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +const { + updateCanDebugWorkers, + updateWorkers, +} = require("resource://devtools/client/application/src/actions/workers.js"); + +const { + START_WORKER, + UNREGISTER_WORKER, +} = require("resource://devtools/client/application/src/constants.js"); + +const { + workersReducer, + WorkersState, +} = require("resource://devtools/client/application/src/reducers/workers-state.js"); + +add_task(async function () { + info("Test workers reducer: UPDATE_CAN_DEBUG_WORKERS action"); + + function testUpdateCanDebugWorkers(flagValue) { + const state = WorkersState(); + const action = updateCanDebugWorkers(flagValue); + const newState = workersReducer(state, action); + equal( + newState.canDebugWorkers, + flagValue, + "canDebugWorkers contains the expected value" + ); + } + + testUpdateCanDebugWorkers(false); + testUpdateCanDebugWorkers(true); +}); + +add_task(async function () { + info("Test workers reducer: UPDATE_WORKERS action"); + const state = WorkersState(); + + const rawData = [ + { + registration: { + scope: "lorem-ipsum", + lastUpdateTime: 42, + id: "r1", + }, + workers: [ + { + id: "w1", + state: Ci.nsIServiceWorkerInfo.STATE_ACTIVATED, + url: "https://example.com/w1.js", + workerDescriptorFront: { foo: "bar" }, + stateText: "activated", + }, + { + id: "w2", + state: Ci.nsIServiceWorkerInfo.STATE_INSTALLED, + url: "https://example.com/w2.js", + workerDescriptorFront: undefined, + stateText: "installed", + }, + ], + }, + ]; + + const expectedData = [ + { + id: "r1", + lastUpdateTime: 42, + registrationFront: rawData[0].registration, + scope: "lorem-ipsum", + workers: [ + { + id: "w1", + url: "https://example.com/w1.js", + workerDescriptorFront: rawData[0].workers[0].workerDescriptorFront, + registrationFront: rawData[0].registration, + state: Ci.nsIServiceWorkerInfo.STATE_ACTIVATED, + stateText: "activated", + }, + { + id: "w2", + url: "https://example.com/w2.js", + workerDescriptorFront: undefined, + registrationFront: rawData[0].registration, + state: Ci.nsIServiceWorkerInfo.STATE_INSTALLED, + stateText: "installed", + }, + ], + }, + ]; + + const action = updateWorkers(rawData); + const newState = workersReducer(state, action); + deepEqual(newState.list, expectedData, "workers contains the expected list"); +}); + +add_task(async function () { + info("Test workers reducer: START_WORKER action"); + const state = WorkersState(); + const action = { type: START_WORKER }; + const newState = workersReducer(state, action); + deepEqual(state, newState, "workers state stays the same"); +}); + +add_task(async function () { + info("Test workers reducer: UNREGISTER_WORKER action"); + const state = WorkersState(); + const action = { type: UNREGISTER_WORKER }; + const newState = workersReducer(state, action); + deepEqual(state, newState, "workers state stays the same"); +}); diff --git a/devtools/client/application/test/xpcshell/xpcshell-head.js b/devtools/client/application/test/xpcshell/xpcshell-head.js new file mode 100644 index 0000000000..733c0400da --- /dev/null +++ b/devtools/client/application/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/application/test/xpcshell/xpcshell.toml b/devtools/client/application/test/xpcshell/xpcshell.toml new file mode 100644 index 0000000000..1cf00f01c1 --- /dev/null +++ b/devtools/client/application/test/xpcshell/xpcshell.toml @@ -0,0 +1,13 @@ +[DEFAULT] +tags = "devtools" +head = "xpcshell-head.js" +firefox-appdir = "browser" +skip-if = ["os == 'android'"] + +["test_manifest_reducer.js"] + +["test_page_reducer.js"] + +["test_ui_reducer.js"] + +["test_workers_reducer.js"] |