test_ManifestProcessor_id.html (3069B)
1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=1731940 5 --> 6 <head> 7 <meta charset="utf-8"> 8 <title>Test for Bug 1731940 - implement id member</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 /** 14 * Manifest id member 15 * https://w3c.github.io/manifest/#id-member 16 */ 17 for (const type of typeTests) { 18 data.jsonText = JSON.stringify({ 19 id: type, 20 }); 21 const result = processor.process(data); 22 is( 23 result.id.toString(), 24 result.start_url.toString(), 25 `Expect non-string id to fall back to start_url: ${typeof type}.` 26 ); 27 } 28 29 // Invalid URLs 30 const invalidURLs = [ 31 "https://foo:65536", 32 "https://foo\u0000/", 33 "//invalid:65555", 34 "file:///passwords", 35 "about:blank", 36 "data:text/html,<html><script>alert('lol')<\/script></html>", 37 ]; 38 39 for (const url of invalidURLs) { 40 data.jsonText = JSON.stringify({ 41 id: url, 42 }); 43 const result = processor.process(data); 44 is( 45 result.id.toString(), 46 result.start_url.toString(), 47 "Expect invalid id URL to fall back to start_url." 48 ); 49 } 50 51 // Not same origin 52 data.jsonText = JSON.stringify({ 53 id: "http://not-same-origin", 54 }); 55 var result = processor.process(data); 56 is( 57 result.id.toString(), 58 result.start_url, 59 "Expect different origin id to fall back to start_url." 60 ); 61 62 // Empty string test 63 data.jsonText = JSON.stringify({ 64 id: "", 65 }); 66 result = processor.process(data); 67 is( 68 result.id.toString(), 69 result.start_url.toString(), 70 `Expect empty string for id to use start_url.` 71 ); 72 73 // Resolve URLs relative to the start_url's origin 74 const URLs = [ 75 "path", 76 "/path", 77 "../../path", 78 "./path", 79 `${whiteSpace}path${whiteSpace}`, 80 `${whiteSpace}/path`, 81 `${whiteSpace}../../path`, 82 `${whiteSpace}./path`, 83 ]; 84 85 for (const url of URLs) { 86 data.jsonText = JSON.stringify({ 87 id: url, 88 start_url: "/path/some.html", 89 }); 90 result = processor.process(data); 91 const baseOrigin = new URL(result.start_url.toString()).origin; 92 const expectedUrl = new URL(url, baseOrigin).toString(); 93 is( 94 result.id.toString(), 95 expectedUrl, 96 "Expected id to be resolved relative to start_url's origin." 97 ); 98 } 99 100 // Handles unicode encoded URLs 101 const specialCases = [ 102 ["😀", "%F0%9F%98%80"], 103 [ 104 "this/is/ok?query_is_ok=😀#keep_hash", 105 "this/is/ok?query_is_ok=%F0%9F%98%80#keep_hash", 106 ], 107 ]; 108 for (const [id, expected] of specialCases) { 109 data.jsonText = JSON.stringify({ 110 id, 111 start_url: "/my-app/", 112 }); 113 result = processor.process(data); 114 const baseOrigin = new URL(result.start_url.toString()).origin; 115 const expectedUrl = new URL(expected, baseOrigin).toString(); 116 is( 117 result.id.toString(), 118 expectedUrl, 119 `Expect id to be encoded/decoded per URL spec.` 120 ); 121 } 122 </script> 123 </head>