mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-19 00:05:36 +00:00
Bug 1147699 - Part 3: Add a test for FetchEvent.request.context when intercepting an image load; r=nsm,bzbarsky
This commit is contained in:
parent
99c8062500
commit
6fdcabe29e
@ -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());
|
||||
|
@ -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) {
|
||||
|
BIN
dom/workers/test/serviceworkers/fetch/context/realimg.jpg
Normal file
BIN
dom/workers/test/serviceworkers/fetch/context/realimg.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.5 KiB |
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user