summaryrefslogtreecommitdiffstats
path: root/devtools/client/application/test/xpcshell
diff options
context:
space:
mode:
Diffstat (limited to 'devtools/client/application/test/xpcshell')
-rw-r--r--devtools/client/application/test/xpcshell/.eslintrc.js6
-rw-r--r--devtools/client/application/test/xpcshell/test_manifest_reducer.js201
-rw-r--r--devtools/client/application/test/xpcshell/test_page_reducer.js22
-rw-r--r--devtools/client/application/test/xpcshell/test_ui_reducer.js22
-rw-r--r--devtools/client/application/test/xpcshell/test_workers_reducer.js117
-rw-r--r--devtools/client/application/test/xpcshell/xpcshell-head.js8
-rw-r--r--devtools/client/application/test/xpcshell/xpcshell.ini10
7 files changed, 386 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..7dcc919f0f
--- /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("devtools/client/application/src/constants.js");
+
+const { ICON, COLOR, STRING, URL } = MANIFEST_MEMBER_VALUE_TYPES;
+
+const {
+ manifestReducer,
+ ManifestState,
+} = require("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..eada876d5b
--- /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("devtools/client/application/src/actions/page.js");
+
+const {
+ pageReducer,
+ PageState,
+} = require("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..2388093192
--- /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("devtools/client/application/src/actions/ui.js");
+
+const {
+ uiReducer,
+ UiState,
+} = require("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..33b8376f04
--- /dev/null
+++ b/devtools/client/application/test/xpcshell/test_workers_reducer.js
@@ -0,0 +1,117 @@
+/* Any copyright is dedicated to the Public Domain.
+http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+const { Ci } = require("chrome");
+
+const {
+ updateCanDebugWorkers,
+ updateWorkers,
+} = require("devtools/client/application/src/actions/workers.js");
+
+const {
+ START_WORKER,
+ UNREGISTER_WORKER,
+} = require("devtools/client/application/src/constants.js");
+
+const {
+ workersReducer,
+ WorkersState,
+} = require("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..93a0b0881f
--- /dev/null
+++ b/devtools/client/application/test/xpcshell/xpcshell-head.js
@@ -0,0 +1,8 @@
+/* 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.import("resource://devtools/shared/Loader.jsm");
diff --git a/devtools/client/application/test/xpcshell/xpcshell.ini b/devtools/client/application/test/xpcshell/xpcshell.ini
new file mode 100644
index 0000000000..824750f9f5
--- /dev/null
+++ b/devtools/client/application/test/xpcshell/xpcshell.ini
@@ -0,0 +1,10 @@
+[DEFAULT]
+tags = devtools
+head = xpcshell-head.js
+firefox-appdir = browser
+skip-if = toolkit == 'android'
+
+[test_manifest_reducer.js]
+[test_page_reducer.js]
+[test_ui_reducer.js]
+[test_workers_reducer.js]