Skip to content

Commit

Permalink
Bug 1147699 - Part 5: Add a test for FetchEvent.request.context when …
Browse files Browse the repository at this point in the history
…intercepting an audio element load;
  • Loading branch information
rmottola committed Jul 2, 2019
1 parent c7f4a27 commit 40dfbeb
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 0 deletions.
4 changes: 4 additions & 0 deletions dom/workers/test/serviceworkers/fetch/context/context_test.js
Expand Up @@ -16,6 +16,10 @@ self.addEventListener("fetch", function(event) {
if (event.request.context == "imageset") {
event.respondWith(fetch("realimg.jpg"));
}
} else if (event.request.url.indexOf("audio.ogg") >= 0) {
if (event.request.context == "audio") {
event.respondWith(fetch("realaudio.ogg"));
}
}
// Fail any request that we don't know about.
try {
Expand Down
14 changes: 14 additions & 0 deletions dom/workers/test/serviceworkers/fetch/context/index.html
Expand Up @@ -58,11 +58,25 @@
});
}

function testAudio() {
return new Promise(function(resolve, reject) {
var audio = document.createElement("audio");
audio.src = "audio.ogg";
audio.preload = "metadata";
// The service worker will respond with an existing audio only if the
// Request has the correct context, otherwise the Promise will get
// rejected and the test will fail.
audio.onloadedmetadata = resolve;
audio.onerror = reject;
});
}

Promise.all([
testFetch(),
testImage(),
testImageSrcSet(),
testPicture(),
testAudio(),
])
.then(function() {
finish();
Expand Down
Empty file.
1 change: 1 addition & 0 deletions dom/workers/test/serviceworkers/mochitest.ini
Expand Up @@ -31,6 +31,7 @@ support-files =
fetch/context/unregister.html
fetch/context/context_test.js
fetch/context/realimg.jpg
fetch/context/realaudio.ogg
fetch/https/index.html
fetch/https/register.html
fetch/https/unregister.html
Expand Down

0 comments on commit 40dfbeb

Please sign in to comment.