OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <link rel="stylesheet" type="text/css" href="resources/mark-result-red.css" inte
grity="sha256-deadbeef"> |
| 3 <script src="/resources/testharness.js"></script> |
| 4 <script src="/resources/testharnessreport.js"></script> |
| 5 <body> |
| 6 <script> |
| 7 function waitForLinkElementToLoad(linkElement) { |
| 8 return new Promise(resolve => { |
| 9 (function waitAgain() { |
| 10 if (linkElement.sheet !== null) { |
| 11 resolve(); |
| 12 } else { |
| 13 setTimeout(waitAgain, 100); |
| 14 } |
| 15 })(); |
| 16 }); |
| 17 } |
| 18 |
| 19 promise_test(() => { |
| 20 let link = document.querySelector("link"); |
| 21 |
| 22 let divResult = document.createElement("div"); |
| 23 divResult.id = "result"; |
| 24 document.body.appendChild(divResult); |
| 25 |
| 26 let divResult2 = document.createElement("div"); |
| 27 divResult2.id = "result2"; |
| 28 document.body.appendChild(divResult2); |
| 29 |
| 30 return new Promise(resolve => { |
| 31 window.addEventListener("load", resolve, {once: true}); |
| 32 }) |
| 33 .then(() => { |
| 34 assert_equals(getComputedStyle(divResult).color.toString(), "rgb(0, 0, 0)",
"bad integrity CSS should not be applied"); |
| 35 |
| 36 let linkElement = document.querySelector("link"); |
| 37 linkElement.removeAttribute("integrity"); |
| 38 linkElement.href = "resources/mark-result2-blue.css"; |
| 39 return waitForLinkElementToLoad(linkElement); |
| 40 }) |
| 41 .then(() => { |
| 42 assert_equals(getComputedStyle(divResult).color.toString(), "rgb(0, 0, 0)",
"bad integrity CSS should not be applied"); |
| 43 assert_equals(getComputedStyle(divResult2).color.toString(), "rgb(0, 0, 255)
", "CSS w/o integrity check disabled should load on the link element"); |
| 44 }) |
| 45 .then(() => { |
| 46 document.body.removeChild(divResult); |
| 47 document.body.removeChild(divResult2); |
| 48 }); |
| 49 }, 'Link element should still load another CSS after SRI check failed.'); |
| 50 </script> |
OLD | NEW |