Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(168)

Side by Side Diff: LayoutTests/http/tests/security/subresourceIntegrity/subresource-integrity-fetch.html

Issue 1279163005: Initial Fetch integration for Subresource Integrity (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Fix test expectations Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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, expectedValue) {
11 this.pass = pass;
12 this.name = name;
13 this.src = src;
14 this.integrity = integrity;
15 this.expectedValue = expectedValue;
16 }
17 SRITest.prototype.execute = function() {
18 var pass = this.pass;
19 var src = this.src;
20 var integrity = this.integrity;
21 var expectedValue = this.expectedValue;
22 var options = {};
23 if (integrity !== '') {
24 options.integrity = integrity;
25 }
26 promise_test(function() {
27 return fetch(src, options)
28 .then(function(response) {
29 assert_true(pass, "Response should resolve");
30
31 if (expectedValue) {
32 return response.text().then(function(actualValue) {
33 assert_equals(actualValue, expectedValue, "Value consume d must match hashed value.");
34 });
35 }
36 }, function() {
37 assert_false(pass, "Response should be rejected");
38 })
39 }, this.name);
40 }
41
42 new SRITest(true, 'No integrity', 'call-success.js', '', 'success();\n').execute ();
43 new SRITest(true, 'Good integrity', 'call-success.js', 'sha256-B0/62fJSJFrdjEFR9 ba04m/D+LHQ+zG6PGcaR0Trpxg=', 'success();\n').execute();
44 new SRITest(false, 'Bad integrity', 'call-success.js', 'sha256-deadbeef').execut e();
45 new SRITest(false, 'Bad integrity and an img', '/resources/square100.png', 'sha2 56-B0/62fJSJFrdjEFR9ba04m/D+LHQ+zG6PGcaR0Trpxg=').execute();
46 new SRITest(true, 'Good integrity and an img', '/resources/square100.png', 'sha2 56-xZjdcorjj+TiKGteFFcrNbdqrDns2iVURBpGpAwp12k=').execute();
47 </script>
48 </body>
49 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698