Bug 1147699 - Part 3: Add a test for FetchEvent.request.context when intercepting an image load; r=nsm,bzbarsky

This commit is contained in:
Ehsan Akhgari 2015-03-25 16:47:57 -04:00
parent 99c8062500
commit 6fdcabe29e
4 changed files with 21 additions and 1 deletions

View File

@ -8,6 +8,10 @@ self.addEventListener("fetch", function(event) {
var body = event.request.context == "fetch" ?
"so fetch" : "so unfetch";
event.respondWith(new Response(body));
} else if (event.request.url.indexOf("img.jpg") >= 0) {
if (event.request.context == "image") {
event.respondWith(fetch("realimg.jpg"));
}
} else {
// Fail any request that we don't know about.
event.respondWith(Promise.reject());

View File

@ -20,7 +20,22 @@
});
}
testFetch()
function testImage() {
return new Promise(function(resolve, reject) {
var img = document.createElement("img");
img.src = "img.jpg";
// The service worker will respond with an existing image only if the
// Request has the correct context, otherwise the Promise will get
// rejected and the test will fail.
img.onload = resolve;
img.onerror = reject;
});
}
Promise.all([
testFetch(),
testImage(),
])
.then(function() {
finish();
}, function(e) {

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

View File

@ -30,6 +30,7 @@ support-files =
fetch/context/register.html
fetch/context/unregister.html
fetch/context/context_test.js
fetch/context/realimg.jpg
fetch/https/index.html
fetch/https/register.html
fetch/https/unregister.html