Bug 1147699 - Part 11: Add tests for FetchEvent.request.context when intercepting iframes and frames; r=nsm

This commit is contained in:
Ehsan Akhgari 2015-03-26 15:11:29 -04:00
Родитель bb41d453ac
Коммит 3adeadabad
2 изменённых файлов: 37 добавлений и 0 удалений

Просмотреть файл

@ -40,6 +40,15 @@ self.addEventListener("fetch", function(event) {
respondToServiceWorker(event, "object");
} else if (event.request.url.indexOf("font") >= 0) {
respondToServiceWorker(event, "font");
} else if (event.request.url.indexOf("iframe") >= 0) {
if (event.request.context == "iframe") {
event.respondWith(fetch("context_test.js"));
}
} else if (event.request.url.indexOf("frame") >= 0) {
// FIXME: Bug 1148044: This should be "frame".
if (event.request.context == "iframe") {
event.respondWith(fetch("context_test.js"));
}
}
// Fail any request that we don't know about.
try {

Просмотреть файл

@ -158,6 +158,32 @@
});
}
function testIFrame() {
return new Promise(function(resolve, reject) {
var iframe = document.createElement("iframe");
iframe.src = "iframe";
document.documentElement.appendChild(iframe);
// The service worker will respond with an existing document only if the
// Request has the correct context, otherwise the Promise will get
// rejected and the test will fail.
iframe.onload = resolve;
iframe.onerror = reject;
});
}
function testFrame() {
return new Promise(function(resolve, reject) {
var frame = document.createElement("frame");
frame.src = "frame";
document.documentElement.appendChild(frame);
// The service worker will respond with an existing document only if the
// Request has the correct context, otherwise the Promise will get
// rejected and the test will fail.
frame.onload = resolve;
frame.onerror = reject;
});
}
Promise.all([
testFetch(),
testImage(),
@ -170,6 +196,8 @@
testEmbed(),
testObject(),
testFont(),
testIFrame(),
testFrame(),
])
.then(function() {
finish();