style-src-hash-blocked.html (1492B)
1 <!doctype html> 2 <html> 3 <head> 4 <meta http-equiv="Content-Security-Policy" content="style-src 5 'sha256-7kQ1KhZCpEzWtsa0RSpbIL7FU3kPNhE3IJMaNeTclMU='"> 6 <script src="/resources/testharness.js"></script> 7 <script src="/resources/testharnessreport.js"></script> 8 9 <script> 10 var t1 = async_test("Should load the style with a correct hash"); 11 var t2 = async_test("Should not load style that does not match hash"); 12 var t_spv = async_test("Should fire a securitypolicyviolation event"); 13 14 document.addEventListener("securitypolicyviolation", t_spv.step_func_done(function(e) { 15 assert_equals("style-src-elem", e.violatedDirective); 16 })); 17 </script> 18 19 <style>#content1 { margin-left: 2px; }</style> 20 <style>#content2 { margin-left: 2px; }</style> 21 </head> 22 <body> 23 <div id='log'></div> 24 25 <div id="content1">Lorem ipsum</div> 26 <div id="content2">Lorem ipsum</div> 27 28 <script> 29 function make_assert(contentId, assertTrue) { 30 var contentEl = document.getElementById(contentId); 31 var marginLeftVal = getComputedStyle(contentEl).getPropertyValue('margin-left'); 32 if (assertTrue) assert_equals(marginLeftVal, "2px"); 33 else assert_not_equals(marginLeftVal, "2px"); 34 } 35 36 t1.step(function() { 37 make_assert("content1", true); 38 t1.done(); 39 }); 40 41 t2.step(function() { 42 make_assert("content2", false); 43 t2.done(); 44 }); 45 46 </script> 47 </body> 48 </html>