Bug 1945965 – remove new tab April Fools logo. r=home-newtab-reviewers,reemhamz
[gecko.git] / dom / manifest / test / test_ManifestProcessor_warnings.html
blob06c7d0325a88202f9665f72ca0c1180eab718f55
1 <!DOCTYPE HTML>
2 <html>
3 <!--
4 https://bugzilla.mozilla.org/show_bug.cgi?id=1086997
5 -->
6 <head>
7 <meta charset="utf-8">
8 <title>Test for Bug 1086997</title>
9 <script src="/tests/SimpleTest/SimpleTest.js"></script>
10 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
11 <script src="common.js"></script>
12 <script>
13 "use strict";
14 const options = {...data, checkConformance: true } ;
17 func: () => options.jsonText = JSON.stringify(1),
18 warn: "Manifest should be an object.",
21 func: () => options.jsonText = JSON.stringify("a string"),
22 warn: "Manifest should be an object.",
25 func: () => options.jsonText = JSON.stringify({
26 scope: "https://www.mozilla.org",
27 }),
28 warn: "The scope URL must be same origin as document.",
31 func: () => options.jsonText = JSON.stringify({
32 scope: "foo",
33 start_url: "bar",
34 }),
35 warn: "The start URL is outside the scope, so the scope is invalid.",
38 func: () => options.jsonText = JSON.stringify({
39 start_url: "https://www.mozilla.org",
40 }),
41 warn: "The start URL must be same origin as document.",
44 func: () => options.jsonText = JSON.stringify({
45 start_url: 42,
46 }),
47 warn: "Expected the manifest\u2019s start_url member to be a string.",
50 func: () => options.jsonText = JSON.stringify({
51 theme_color: "42",
52 }),
53 warn: "theme_color: 42 is not a valid CSS color.",
56 func: () => options.jsonText = JSON.stringify({
57 background_color: "42",
58 }),
59 warn: "background_color: 42 is not a valid CSS color.",
62 func: () => options.jsonText = JSON.stringify({
63 icons: [
64 { "src": "http://example.com", "sizes": "48x48"},
65 { "src": "http://:Invalid", "sizes": "48x48"},
67 }),
68 warn: "icons item at index 1 is invalid. The src member is an invalid URL http://:Invalid",
70 // testing dom.properties: ManifestImageUnusable
72 func() {
73 return (options.jsonText = JSON.stringify({
74 icons: [
75 { src: "http://example.com", purpose: "any" }, // valid
76 { src: "http://example.com", purpose: "banana" }, // generates error
78 }));
80 get warn() {
81 // Returns 2 warnings... array here is just to keep them organized
82 return [
83 "icons item at index 1 includes unsupported purpose(s): banana.",
84 "icons item at index 1 lacks a usable purpose. It will be ignored.",
85 ].join(" ");
88 // testing dom.properties: ManifestImageUnsupportedPurposes
90 func() {
91 return (options.jsonText = JSON.stringify({
92 icons: [
93 { src: "http://example.com", purpose: "any" }, // valid
94 { src: "http://example.com", purpose: "any foo bar baz bar bar baz" }, // generates error
96 }));
98 warn: "icons item at index 1 includes unsupported purpose(s): foo bar baz.",
100 // testing dom.properties: ManifestImageRepeatedPurposes
102 func() {
103 return (options.jsonText = JSON.stringify({
104 icons: [
105 { src: "http://example.com", purpose: "any" }, // valid
107 src: "http://example.com",
108 purpose: "any maskable any maskable maskable", // generates error
111 }));
113 warn: "icons item at index 1 includes repeated purpose(s): any maskable.",
115 // testing dom.properties: ManifestIdIsInvalid
117 func() {
118 return (options.jsonText = JSON.stringify({
119 id: "http://test:65536/foo",
120 }));
122 warn: "The id member did not resolve to a valid URL.",
124 // testing dom.properties ManifestIdNotSameOrigin
126 func() {
127 return (options.jsonText = JSON.stringify({
128 id: "https://other.com",
129 start_url: "/this/place"
130 }));
132 warn: "The id member must have the same origin as the start_url member.",
134 ].forEach((test) => {
135 test.func();
136 const result = processor.process(options);
137 let messages = [];
138 // Poking directly at "warn" triggers xray security wrapper.
139 for (const validationError of result.moz_validation) {
140 const { warn } = validationError;
141 messages.push(warn);
143 is(messages.join(" "), test.warn, "Check warning.");
144 options.manifestURL = manifestURL;
145 options.docURL = docURL;
148 </script>
149 </head>