OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <html> |
| 3 <head> |
| 4 <title>Tests integrity enforcement on fetch()</title> |
| 5 <script src="/resources/testharness.js"></script> |
| 6 <script src="/resources/testharnessreport.js"></script> |
| 7 </head> |
| 8 <body> |
| 9 <script> |
| 10 var SRITest = function(pass, name, src, integrity) { |
| 11 this.pass = pass; |
| 12 this.name = name; |
| 13 this.src = src; |
| 14 this.integrity = integrity; |
| 15 } |
| 16 SRITest.prototype.execute = function() { |
| 17 var test = async_test(this.name); |
| 18 var pass = this.pass; |
| 19 var integrity = this.integrity; |
| 20 var options = {}; |
| 21 if (integrity !== '') { |
| 22 options.integrity = integrity; |
| 23 } |
| 24 fetch(this.src, options) |
| 25 .then(test.step_func(function(response) { |
| 26 if (pass) { |
| 27 test.done(); |
| 28 } else { |
| 29 assert_unreached("Response on bad fetch."); |
| 30 } |
| 31 })) |
| 32 .catch(test.step_func(function(error) { |
| 33 if (pass) { |
| 34 assert_unreached("Network error on good fetch."); |
| 35 } else { |
| 36 test.done(); |
| 37 } |
| 38 })); |
| 39 } |
| 40 |
| 41 new SRITest(true, 'No integrity', 'call-success.js', '').execute(); |
| 42 new SRITest(true, 'Good integrity', 'call-success.js', 'sha256-B0/62fJSJFrdjEFR9
ba04m/D+LHQ+zG6PGcaR0Trpxg=').execute(); |
| 43 new SRITest(false, 'Bad integrity', 'call-success.js', 'sha256-deadbeef').execut
e(); |
| 44 </script> |
| 45 </body> |
| 46 </html> |
OLD | NEW |