Bug 1187335 - P5 - Adding new tests for SRI and enabling test for Request's integrity attribute in wpt. r=bkelly.

This commit is contained in:
Tom Tung 2016-09-07 10:38:59 +08:00
parent a167b66e90
commit 8b51370a4d
12 changed files with 63 additions and 59 deletions

View File

@ -16009,6 +16009,10 @@
"path": "fetch/api/basic/accept-header.html",
"url": "/fetch/api/basic/accept-header.html"
},
{
"path": "fetch/api/basic/integrity-sharedworker.html",
"url": "/fetch/api/basic/integrity-sharedworker.html"
},
{
"path": "fetch/api/basic/integrity-worker.html",
"url": "/fetch/api/basic/integrity-worker.html"

View File

@ -1,14 +0,0 @@
[integrity-worker.html]
type: testharness
[Invalid integrity]
expected: FAIL
[Multiple integrities: invalid stronger than valid]
expected: FAIL
[Multiple integrities: both are invalid]
expected: FAIL
[CORS invalid integrity]
expected: FAIL

View File

@ -1,14 +0,0 @@
[integrity.html]
type: testharness
[Invalid integrity]
expected: FAIL
[Multiple integrities: invalid stronger than valid]
expected: FAIL
[Multiple integrities: both are invalid]
expected: FAIL
[CORS invalid integrity]
expected: FAIL

View File

@ -1,5 +0,0 @@
[request-clone.sub.html]
type: testharness
[Check cloning a request]
expected: FAIL

View File

@ -3,6 +3,3 @@
[RequestInit's window is not null]
expected: FAIL
[RequestInit's mode is no-cors and integrity is not empty]
expected: FAIL

View File

@ -6,15 +6,9 @@
[Request interface: attribute destination]
expected: FAIL
[Request interface: attribute integrity]
expected: FAIL
[Request interface: new Request("") must inherit property "type" with the proper type (3)]
expected: FAIL
[Request interface: new Request("") must inherit property "destination" with the proper type (4)]
expected: FAIL
[Request interface: new Request("") must inherit property "integrity" with the proper type (11)]
expected: FAIL

View File

@ -1,8 +0,0 @@
[request-init-001.sub.html]
type: testharness
[Check integrity init value of and associated getter]
expected: FAIL
[Check integrity init value of AZERTYUIOP1234567890 and associated getter]
expected: FAIL

View File

@ -1,11 +1,5 @@
[request-init-003.sub.html]
type: testharness
[Check request values when initialized from Request]
expected: FAIL
[Check request values when initialized from Request and init values]
expected: FAIL
[Check request values when initialized from url string]
expected: FAIL

View File

@ -6,6 +6,3 @@
[Check destination attribute]
expected: FAIL
[Check integrity attribute]
expected: FAIL

View File

@ -0,0 +1,15 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Fetch in sharedworker: integrity handling</title>
<meta name="help" href="https://fetch.spec.whatwg.org/#main-fetch">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<script>
fetch_tests_from_worker(new SharedWorker("integrity.js?pipe=sub"));
</script>
</body>
</html>

View File

@ -533,5 +533,44 @@ async_test(function(t) {
.catch(unreached_rejection(t));
}, 'Service Worker should intercept EventSource');
async_test(function(t) {
var scope = 'resources/simple.html?integrity';
var frame;
var integrity_metadata = 'gs0nqru8KbsrIt5YToQqS9fYao4GQJXtcId610g7cCU=';
service_worker_unregister_and_register(t, worker, scope)
.then(function(reg) {
return wait_for_state(t, reg.installing, 'activated');
})
.then(function() { return with_iframe(scope); })
.then(function(f) {
frame = f;
// A request has associated integrity metadata (a string).
// Unless stated otherwise, it is the empty string.
assert_equals(
frame.contentDocument.body.textContent, '');
return new Promise(function(resolve, reject) {
return frame.contentWindow.fetch(scope,
{'integrity': integrity_metadata})
.then(function(response) {
return response.text();
})
.then(function(response_text) {
// Should get the same integrity metadata.
assert_equals(response_text, integrity_metadata,
'Service Worker should respond to fetch with the correct integrity');
})
.then(resolve())
.catch(reject());
});
})
.then(function() {
frame.remove();
return service_worker_unregister_and_done(t, scope);
})
.catch(unreached_rejection(t));
}, 'Service Worker responds to fetch event with the correct integrity_metadata');
</script>
</body>

View File

@ -111,6 +111,10 @@ function handleEventSource(event) {
));
}
function handleIntegrity(event) {
event.respondWith(new Response(event.request.integrity));
}
self.addEventListener('fetch', function(event) {
var url = event.request.url;
var handlers = [
@ -129,6 +133,7 @@ self.addEventListener('fetch', function(event) {
{ pattern: '?fragment-check', fn: handleFragmentCheck },
{ pattern: '?cache', fn: handleCache },
{ pattern: '?eventsource', fn: handleEventSource },
{ pattern: '?integrity', fn: handleIntegrity },
];
var handler = null;