Skip to content
Permalink
Browse files

Bug 1147699 - Part 12: Add a test for FetchEvent.request.context when…

… intercepting new window loads;
  • Loading branch information...
rmottola committed Jul 2, 2019
1 parent 981c934 commit cd1ce857f20d44168f60a8b228544fa3b298fd9e
@@ -49,6 +49,8 @@ self.addEventListener("fetch", function(event) {
if (event.request.context == "iframe") {
event.respondWith(fetch("context_test.js"));
}
} else if (event.request.url.indexOf("newwindow") >= 0) {
respondToServiceWorker(event, "newwindow");
}
// Fail any request that we don't know about.
try {
@@ -184,6 +184,28 @@
});
}
function testInternal() {
var isB2G = !navigator.userAgent.contains("Android") &&
/Mobile|Tablet/.test(navigator.userAgent);
if (isB2G) {
// We can't open new windows on b2g, so skip this part of the test there.
return Promise.resolve();
}
return new Promise(function(resolve, reject) {
// Test this with a new window opened through script. There are of course
// other possible ways of testing this too.
var win = window.open("newwindow", "_blank", "width=100,height=100");
navigator.serviceWorker.addEventListener("message", function onMessage(e) {
if (e.data.data == "newwindow") {
is(e.data.context, "internal", "Expected the internal context on a newly opened window");
navigator.serviceWorker.removeEventListener("message", onMessage);
win.close();
resolve();
}
}, false);
});
}
Promise.all([
testFetch(),
testImage(),
@@ -198,6 +220,7 @@
testFont(),
testIFrame(),
testFrame(),
testInternal(),
])
.then(function() {
finish();

0 comments on commit cd1ce85

Please sign in to comment.
You can’t perform that action at this time.