зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1147699 - Part 8: Add a test for FetchEvent.request.context when intercepting a CSP report; r=nsm
This commit is contained in:
Родитель
a0ac39a25e
Коммит
3ccccb6763
|
@ -1,7 +1,8 @@
|
|||
self.addEventListener("fetch", function(event) {
|
||||
if (event.request.url.indexOf("index.html") >= 0 ||
|
||||
event.request.url.indexOf("register.html") >= 0 ||
|
||||
event.request.url.indexOf("unregister.html") >= 0) {
|
||||
event.request.url.indexOf("unregister.html") >= 0 ||
|
||||
event.request.url.indexOf("csp-violate.sjs") >= 0) {
|
||||
// Handle pass-through requests
|
||||
event.respondWith(fetch(event.request));
|
||||
} else if (event.request.url.indexOf("fetch.txt") >= 0) {
|
||||
|
@ -31,6 +32,14 @@ self.addEventListener("fetch", function(event) {
|
|||
} else {
|
||||
event.respondWith(fetch(event.request));
|
||||
}
|
||||
} else if (event.request.url.indexOf("csp-report.sjs") >= 0) {
|
||||
event.respondWith(clients.matchAll()
|
||||
.then(function(clients) {
|
||||
clients.forEach(function(c) {
|
||||
c.postMessage({data: "csp-report", context: event.request.context});
|
||||
});
|
||||
return new Response("ack");
|
||||
}));
|
||||
}
|
||||
// Fail any request that we don't know about.
|
||||
try {
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
function handleRequest(request, response)
|
||||
{
|
||||
response.setHeader("Content-Security-Policy", "default-src 'none'; report-uri /tests/dom/workers/test/serviceworkers/fetch/context/csp-report.sjs", false);
|
||||
response.setHeader("Content-Type", "text/html", false);
|
||||
response.write("<link rel=stylesheet href=style.css>");
|
||||
}
|
|
@ -95,6 +95,21 @@
|
|||
});
|
||||
}
|
||||
|
||||
function testCSPReport() {
|
||||
return new Promise(function(resolve, reject) {
|
||||
var iframe = document.createElement("iframe");
|
||||
iframe.src = "csp-violate.sjs";
|
||||
document.documentElement.appendChild(iframe);
|
||||
navigator.serviceWorker.addEventListener("message", function onMessage(e) {
|
||||
if (e.data.data == "csp-report") {
|
||||
is(e.data.context, "cspreport", "Expected the cspreport context on a CSP violation report");
|
||||
navigator.serviceWorker.removeEventListener("message", onMessage);
|
||||
resolve();
|
||||
}
|
||||
}, false);
|
||||
});
|
||||
}
|
||||
|
||||
Promise.all([
|
||||
testFetch(),
|
||||
testImage(),
|
||||
|
@ -103,6 +118,7 @@
|
|||
testAudio(),
|
||||
testVideo(),
|
||||
testBeacon(),
|
||||
testCSPReport(),
|
||||
])
|
||||
.then(function() {
|
||||
finish();
|
||||
|
|
|
@ -33,6 +33,7 @@ support-files =
|
|||
fetch/context/realimg.jpg
|
||||
fetch/context/realaudio.ogg
|
||||
fetch/context/beacon.sjs
|
||||
fetch/context/csp-violate.sjs
|
||||
fetch/https/index.html
|
||||
fetch/https/register.html
|
||||
fetch/https/unregister.html
|
||||
|
|
Загрузка…
Ссылка в новой задаче