summaryrefslogtreecommitdiffstats
path: root/dom/manifest/test/test_ImageObjectProcessor_purpose.html
blob: 386c4566d4f0876e9b99c0cf2ff5ffd4e53ff68e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
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>