summaryrefslogtreecommitdiffstats
path: root/dom/manifest/test/test_ImageObjectProcessor_purpose.html
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 /dom/manifest/test/test_ImageObjectProcessor_purpose.html
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/manifest/test/test_ImageObjectProcessor_purpose.html')
-rw-r--r--dom/manifest/test/test_ImageObjectProcessor_purpose.html120
1 files changed, 120 insertions, 0 deletions
diff --git a/dom/manifest/test/test_ImageObjectProcessor_purpose.html b/dom/manifest/test/test_ImageObjectProcessor_purpose.html
new file mode 100644
index 0000000000..386c4566d4
--- /dev/null
+++ b/dom/manifest/test/test_ImageObjectProcessor_purpose.html
@@ -0,0 +1,120 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=
+-->
+<head>
+ <meta charset="utf-8">
+ <title>Test for Bug </title>
+ <script src="/tests/SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" href="/tests/SimpleTest/test.css"/>
+ <script src="common.js"></script>
+ <script>
+ /**
+ * Image object's purpose member
+ * https://w3c.github.io/manifest/#purpose-member
+ **/
+
+ "use strict";
+ const testManifest = {
+ icons: [{
+ src: "test",
+ }],
+ };
+
+ const invalidPurposeTypes = [
+ [],
+ 123,
+ {},
+ null,
+ ]
+
+ invalidPurposeTypes.forEach(invalidType => {
+ const expected = `Invalid types get treated as 'any'.`;
+ testManifest.icons[0].purpose = invalidType;
+ data.jsonText = JSON.stringify(testManifest);
+ const result = processor.process(data);
+ is(result.icons.length, 1, expected);
+ is(result.icons[0].purpose.length, 1, expected);
+ is(result.icons[0].purpose[0], "any", expected);
+ });
+
+ const invalidPurposes = [
+ "not-known-test-purpose",
+ "invalid-purpose invalid-purpose",
+ "no-purpose invalid-purpose some-other-non-valid-purpose",
+ ];
+
+ invalidPurposes.forEach(invalidPurpose => {
+ const expected = `Expect invalid purposes to invalidate the icon.`;
+ testManifest.icons[0].purpose = invalidPurpose;
+ data.jsonText = JSON.stringify(testManifest);
+ const result = processor.process(data);
+ is(result.icons.length, 0, expected);
+ });
+
+ const mixedMaskableAndInvalidPurposes = [
+ "not-known-test-purpose maskable",
+ "maskable invalid-purpose invalid-purpose",
+ "no-purpose invalid-purpose maskable some-other-non-valid-purpose",
+ ];
+
+ mixedMaskableAndInvalidPurposes.forEach(mixedPurpose => {
+ const expected = `Expect on 'maskable' to remain.`;
+ testManifest.icons[0].purpose = mixedPurpose;
+ data.jsonText = JSON.stringify(testManifest);
+ const result = processor.process(data);
+ is(result.icons.length, 1, expected);
+ is(result.icons[0].purpose.join(), "maskable", expected);
+ });
+
+ const mixedMonochromeAndInvalidPurposes = [
+ "not-known-test-purpose monochrome",
+ "monochrome invalid-purpose invalid-purpose",
+ "no-purpose invalid-purpose monochrome some-other-non-valid-purpose",
+ ];
+
+ mixedMonochromeAndInvalidPurposes.forEach(mixedPurpose => {
+ const expected = `Expect on 'monochrome' to remain.`;
+ testManifest.icons[0].purpose = mixedPurpose;
+ data.jsonText = JSON.stringify(testManifest);
+ const result = processor.process(data);
+ is(result.icons.length, 1, expected);
+ is(result.icons[0].purpose.join(), "monochrome", expected);
+ });
+
+ const validPurposes = [
+ "maskable",
+ "monochrome",
+ "any",
+ "any maskable",
+ "maskable any",
+ "any monochrome",
+ "monochrome any",
+ "maskable monochrome any",
+ "monochrome maskable"
+ ];
+
+ validPurposes.forEach(purpose => {
+ testManifest.icons[0].purpose = purpose;
+ data.jsonText = JSON.stringify(testManifest);
+ var manifest = processor.process(data);
+ is(manifest.icons[0].purpose.join(" "), purpose, `Expected "${purpose}" as purpose.`);
+ });
+
+ const validWhiteSpace = [
+ "",
+ whiteSpace, // defined in common.js
+ `${whiteSpace}any`,
+ `any${whiteSpace}`,
+ `${whiteSpace}any${whiteSpace}`,
+ ];
+
+ validWhiteSpace.forEach(purpose => {
+ testManifest.icons[0].purpose = purpose;
+ data.jsonText = JSON.stringify(testManifest);
+ var manifest = processor.process(data);
+ is(manifest.icons[0].purpose.join(), "any");
+ });
+ </script>
+</head>