test_ManifestProcessor_warnings.html (4374B)
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 } ; 15 [ 16 { 17 func: () => options.jsonText = JSON.stringify(1), 18 warn: "Manifest should be an object.", 19 }, 20 { 21 func: () => options.jsonText = JSON.stringify("a string"), 22 warn: "Manifest should be an object.", 23 }, 24 { 25 func: () => options.jsonText = JSON.stringify({ 26 scope: "https://www.mozilla.org", 27 }), 28 warn: "The scope URL must be same origin as document.", 29 }, 30 { 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.", 36 }, 37 { 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.", 42 }, 43 { 44 func: () => options.jsonText = JSON.stringify({ 45 start_url: 42, 46 }), 47 warn: "Expected the manifest\u2019s start_url member to be a string.", 48 }, 49 { 50 func: () => options.jsonText = JSON.stringify({ 51 theme_color: "42", 52 }), 53 warn: "theme_color: 42 is not a valid CSS color.", 54 }, 55 { 56 func: () => options.jsonText = JSON.stringify({ 57 background_color: "42", 58 }), 59 warn: "background_color: 42 is not a valid CSS color.", 60 }, 61 { 62 func: () => options.jsonText = JSON.stringify({ 63 icons: [ 64 { "src": "http://example.com", "sizes": "48x48"}, 65 { "src": "http://:Invalid", "sizes": "48x48"}, 66 ], 67 }), 68 warn: "icons item at index 1 is invalid. The src member is an invalid URL http://:Invalid", 69 }, 70 // testing dom.properties: ManifestImageUnusable 71 { 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 77 ], 78 })); 79 }, 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(" "); 86 }, 87 }, 88 // testing dom.properties: ManifestImageUnsupportedPurposes 89 { 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 95 ], 96 })); 97 }, 98 warn: "icons item at index 1 includes unsupported purpose(s): foo bar baz.", 99 }, 100 // testing dom.properties: ManifestImageRepeatedPurposes 101 { 102 func() { 103 return (options.jsonText = JSON.stringify({ 104 icons: [ 105 { src: "http://example.com", purpose: "any" }, // valid 106 { 107 src: "http://example.com", 108 purpose: "any maskable any maskable maskable", // generates error 109 }, 110 ], 111 })); 112 }, 113 warn: "icons item at index 1 includes repeated purpose(s): any maskable.", 114 }, 115 // testing dom.properties: ManifestIdIsInvalid 116 { 117 func() { 118 return (options.jsonText = JSON.stringify({ 119 id: "http://test:65536/foo", 120 })); 121 }, 122 warn: "The id member did not resolve to a valid URL.", 123 }, 124 // testing dom.properties ManifestIdNotSameOrigin 125 { 126 func() { 127 return (options.jsonText = JSON.stringify({ 128 id: "https://other.com", 129 start_url: "/this/place" 130 })); 131 }, 132 warn: "The id member must have the same origin as the start_url member.", 133 } 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); 142 } 143 is(messages.join(" "), test.warn, "Check warning."); 144 options.manifestURL = manifestURL; 145 options.docURL = docURL; 146 }); 147 148 </script> 149 </head>