Bug 1945965 – remove new tab April Fools logo. r=home-newtab-reviewers,reemhamz
[gecko.git] / dom / manifest / test / common.js
blob50f27c119ae36df501a13df4a6247bebfe97d939
1 /**
2 * Common infrastructure for manifest tests.
3 **/
4 "use strict";
5 const { ManifestProcessor } = SpecialPowers.ChromeUtils.importESModule(
6 "resource://gre/modules/ManifestProcessor.sys.mjs"
7 );
8 const processor = ManifestProcessor;
9 const manifestURL = new URL(document.location.origin + "/manifest.json");
10 const docURL = document.location;
11 const seperators =
12 "\u2028\u2029\u0020\u00A0\u1680\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000";
13 const lineTerminators = "\u000D\u000A\u2028\u2029";
14 const whiteSpace = `${seperators}${lineTerminators}`;
15 const typeTests = [1, null, {}, [], false];
16 const data = {
17 jsonText: "{}",
18 manifestURL,
19 docURL,
22 const validThemeColors = [
23 ["maroon", "#800000ff"],
24 ["#f00", "#ff0000ff"],
25 ["#ff0000", "#ff0000ff"],
26 ["rgb(255,0,0)", "#ff0000ff"],
27 ["rgb(255,0,0,1)", "#ff0000ff"],
28 ["rgb(255,0,0,1.0)", "#ff0000ff"],
29 ["rgb(255,0,0,100%)", "#ff0000ff"],
30 ["rgb(255 0 0)", "#ff0000ff"],
31 ["rgb(255 0 0 / 1)", "#ff0000ff"],
32 ["rgb(255 0 0 / 1.0)", "#ff0000ff"],
33 ["rgb(255 0 0 / 100%)", "#ff0000ff"],
34 ["rgb(100%, 0%, 0%)", "#ff0000ff"],
35 ["rgb(100%, 0%, 0%, 1)", "#ff0000ff"],
36 ["rgb(100%, 0%, 0%, 1.0)", "#ff0000ff"],
37 ["rgb(100%, 0%, 0%, 100%)", "#ff0000ff"],
38 ["rgb(100% 0% 0%)", "#ff0000ff"],
39 ["rgb(100% 0% 0% / 1)", "#ff0000ff"],
40 ["rgb(100%, 0%, 0%, 1.0)", "#ff0000ff"],
41 ["rgb(100%, 0%, 0%, 100%)", "#ff0000ff"],
42 ["rgb(300,0,0)", "#ff0000ff"],
43 ["rgb(300 0 0)", "#ff0000ff"],
44 ["rgb(255,-10,0)", "#ff0000ff"],
45 ["rgb(110%, 0%, 0%)", "#ff0000ff"],
46 ["rgba(255,0,0)", "#ff0000ff"],
47 ["rgba(255,0,0,1)", "#ff0000ff"],
48 ["rgba(255 0 0 / 1)", "#ff0000ff"],
49 ["rgba(100%,0%,0%,1)", "#ff0000ff"],
50 ["rgba(0,0,255,0.5)", "#0000ff80"],
51 ["rgba(100%, 50%, 0%, 0.1)", "#ff80001a"],
52 ["hsl(120, 100%, 50%)", "#00ff00ff"],
53 ["hsl(120 100% 50%)", "#00ff00ff"],
54 ["hsl(120, 100%, 50%, 1.0)", "#00ff00ff"],
55 ["hsl(120 100% 50% / 1.0)", "#00ff00ff"],
56 ["hsla(120, 100%, 50%)", "#00ff00ff"],
57 ["hsla(120 100% 50%)", "#00ff00ff"],
58 ["hsla(120, 100%, 50%, 1.0)", "#00ff00ff"],
59 ["hsla(120 100% 50% / 1.0)", "#00ff00ff"],
60 ["hsl(120deg, 100%, 50%)", "#00ff00ff"],
61 ["hsl(133.33333333grad, 100%, 50%)", "#00ff00ff"],
62 ["hsl(2.0943951024rad, 100%, 50%)", "#00ff00ff"],
63 ["hsl(0.3333333333turn, 100%, 50%)", "#00ff00ff"],
66 function setupManifest(key, value) {
67 const manifest = {};
68 manifest[key] = value;
69 data.jsonText = JSON.stringify(manifest);
72 function testValidColors(key) {
73 validThemeColors.forEach(item => {
74 const [manifest_color, parsed_color] = item;
75 setupManifest(key, manifest_color);
76 const result = processor.process(data);
78 is(
79 result[key],
80 parsed_color,
81 `Expect ${key} to be returned for ${manifest_color}`
83 });
85 // Trim tests
86 validThemeColors.forEach(item => {
87 const [manifest_color, parsed_color] = item;
88 const expandedThemeColor = `${seperators}${lineTerminators}${manifest_color}${lineTerminators}${seperators}`;
89 setupManifest(key, expandedThemeColor);
90 const result = processor.process(data);
92 is(
93 result[key],
94 parsed_color,
95 `Expect trimmed ${key} to be returned for ${manifest_color}`
97 });
100 const invalidThemeColors = [
101 "marooon",
102 "f000000",
103 "#ff00000",
104 "rgb(100, 0%, 0%)",
105 "rgb(255,0)",
106 "rbg(255,-10,0)",
107 "rgb(110, 0%, 0%)",
108 "(255,0,0) }",
109 "rgba(255)",
110 " rgb(100%,0%,0%) }",
111 "hsl(120, 100%, 50)",
112 "hsl(120, 100%, 50.0)",
113 "hsl 120, 100%, 50%",
114 "hsla{120, 100%, 50%, 1}",
117 function testInvalidColors(key) {
118 typeTests.forEach(type => {
119 setupManifest(key, type);
120 const result = processor.process(data);
123 result[key],
124 undefined,
125 `Expect non-string ${key} to be undefined: ${typeof type}.`
129 invalidThemeColors.forEach(manifest_color => {
130 setupManifest(key, manifest_color);
131 const result = processor.process(data);
134 result[key],
135 undefined,
136 `Expect ${key} to be undefined: ${manifest_color}.`