зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1433044 P2 Update local-url-inherit-controller.https.html to test fetch() interception in local URL windows and workers. r=asuth
This commit is contained in:
Родитель
4a88dfb69d
Коммит
e9b911badc
|
@ -287941,6 +287941,11 @@
|
|||
{}
|
||||
]
|
||||
],
|
||||
"service-workers/service-worker/resources/local-url-inherit-controller-worker.js": [
|
||||
[
|
||||
{}
|
||||
]
|
||||
],
|
||||
"service-workers/service-worker/resources/malformed-worker.py": [
|
||||
[
|
||||
{}
|
||||
|
@ -580167,7 +580172,7 @@
|
|||
"testharness"
|
||||
],
|
||||
"service-workers/service-worker/local-url-inherit-controller.https.html": [
|
||||
"e29f2ffef20a9436cc721293ddcf932ca1b26bda",
|
||||
"e2e8258f24860cb93b71b4bb27f618b7740756bd",
|
||||
"testharness"
|
||||
],
|
||||
"service-workers/service-worker/mime-sniffing.https.html": [
|
||||
|
@ -580979,7 +580984,11 @@
|
|||
"support"
|
||||
],
|
||||
"service-workers/service-worker/resources/local-url-inherit-controller-frame.html": [
|
||||
"bf2722799132cf551a9d32e5593c0734b85a3c0f",
|
||||
"12822899ad84cef80d4f67cb33475a93ca1d56ed",
|
||||
"support"
|
||||
],
|
||||
"service-workers/service-worker/resources/local-url-inherit-controller-worker.js": [
|
||||
"7a74ae709c072750cf0639f78bf9a0ac4f16f50b",
|
||||
"support"
|
||||
],
|
||||
"service-workers/service-worker/resources/malformed-worker.py": [
|
||||
|
|
|
@ -8,11 +8,11 @@
|
|||
<body>
|
||||
<script>
|
||||
|
||||
const SCRIPT = 'resources/empty.js';
|
||||
const SCRIPT = 'resources/local-url-inherit-controller-worker.js';
|
||||
const SCOPE = 'resources/local-url-inherit-controller-frame.html';
|
||||
|
||||
async function doAsyncTest(t, opts) {
|
||||
let name = opts.scheme + '-' + opts.child;
|
||||
let name = `${opts.scheme}-${opts.child}-${opts.check}`;
|
||||
let scope = SCOPE + '?name=' + name;
|
||||
let reg = await service_worker_unregister_and_register(t, SCRIPT, scope);
|
||||
add_completion_callback(_ => reg.unregister());
|
||||
|
@ -23,32 +23,62 @@ async function doAsyncTest(t, opts) {
|
|||
assert_not_equals(frame.contentWindow.navigator.serviceWorker.controller, null,
|
||||
'frame should be controlled');
|
||||
|
||||
let blobController = await frame.contentWindow.checkChildController(opts);
|
||||
let result = await frame.contentWindow.checkChildController(opts);
|
||||
result = result.data;
|
||||
|
||||
let expect = opts.expect === 'inherit'
|
||||
let expect = 'unexpected';
|
||||
if (opts.check === 'controller') {
|
||||
expect = opts.expect === 'inherit'
|
||||
? frame.contentWindow.navigator.serviceWorker.controller.scriptURL
|
||||
: null;
|
||||
} else if (opts.check === 'fetch') {
|
||||
// The service worker FetchEvent handler will provide an "intercepted"
|
||||
// body. If the local URL ends up with an opaque origin and is not
|
||||
// intercepted then it will get an opaque Response. In that case it
|
||||
// should see an empty string body.
|
||||
expect = opts.expect === 'intercept' ? 'intercepted' : '';
|
||||
}
|
||||
|
||||
assert_equals(blobController, expect,
|
||||
`${opts.scheme} URL ${opts.child} should ${opts.expect} controller`);
|
||||
assert_equals(result, expect,
|
||||
`${opts.scheme} URL ${opts.child} should ${opts.expect} ${opts.check}`);
|
||||
}
|
||||
|
||||
promise_test(function(t) {
|
||||
return doAsyncTest(t, {
|
||||
scheme: 'blob',
|
||||
child: 'iframe',
|
||||
check: 'controller',
|
||||
expect: 'inherit',
|
||||
});
|
||||
}, 'Same-origin blob URL iframe should inherit service worker controller.');
|
||||
|
||||
promise_test(function(t) {
|
||||
return doAsyncTest(t, {
|
||||
scheme: 'blob',
|
||||
child: 'iframe',
|
||||
check: 'fetch',
|
||||
expect: 'intercept',
|
||||
});
|
||||
}, 'Same-origin blob URL iframe should intercept fetch().');
|
||||
|
||||
promise_test(function(t) {
|
||||
return doAsyncTest(t, {
|
||||
scheme: 'blob',
|
||||
child: 'worker',
|
||||
check: 'controller',
|
||||
expect: 'inherit',
|
||||
});
|
||||
}, 'Same-origin blob URL worker should inherit service worker controller.');
|
||||
|
||||
promise_test(function(t) {
|
||||
return doAsyncTest(t, {
|
||||
scheme: 'blob',
|
||||
child: 'worker',
|
||||
check: 'fetch',
|
||||
expect: 'intercept',
|
||||
});
|
||||
}, 'Same-origin blob URL worker should intercept fetch().');
|
||||
|
||||
promise_test(function(t) {
|
||||
// Data URLs should result in an opaque origin and should probably not
|
||||
// have access to a cross-origin service worker. See:
|
||||
|
@ -58,10 +88,20 @@ promise_test(function(t) {
|
|||
return doAsyncTest(t, {
|
||||
scheme: 'data',
|
||||
child: 'iframe',
|
||||
check: 'controller',
|
||||
expect: 'not inherit',
|
||||
});
|
||||
}, 'Data URL iframe should not inherit service worker controller.');
|
||||
|
||||
promise_test(function(t) {
|
||||
return doAsyncTest(t, {
|
||||
scheme: 'data',
|
||||
child: 'iframe',
|
||||
check: 'fetch',
|
||||
expect: 'not intercept',
|
||||
});
|
||||
}, 'Data URL iframe should not intercept fetch().');
|
||||
|
||||
promise_test(function(t) {
|
||||
// Data URLs should result in an opaque origin and should probably not
|
||||
// have access to a cross-origin service worker. See:
|
||||
|
@ -71,9 +111,19 @@ promise_test(function(t) {
|
|||
return doAsyncTest(t, {
|
||||
scheme: 'data',
|
||||
child: 'worker',
|
||||
check: 'controller',
|
||||
expect: 'not inherit',
|
||||
});
|
||||
}, 'Data URL worker should not inherit service worker controller.');
|
||||
|
||||
promise_test(function(t) {
|
||||
return doAsyncTest(t, {
|
||||
scheme: 'data',
|
||||
child: 'worker',
|
||||
check: 'fetch',
|
||||
expect: 'not intercept',
|
||||
});
|
||||
}, 'Data URL worker should not intercept fetch().');
|
||||
|
||||
</script>
|
||||
</body>
|
||||
|
|
|
@ -2,27 +2,65 @@
|
|||
<html>
|
||||
<script>
|
||||
|
||||
const frameText =
|
||||
const fetchURL = new URL('dummy.txt', window.location).href;
|
||||
|
||||
const frameControllerText =
|
||||
`<script>
|
||||
let t = navigator.serviceWorker.controller
|
||||
? navigator.serviceWorker.controller.scriptURL
|
||||
: null;
|
||||
parent.postMessage(t, "*");
|
||||
parent.postMessage({ data: t }, '*');
|
||||
</` + `script>`;
|
||||
|
||||
const workerText =
|
||||
const frameFetchText =
|
||||
`<script>
|
||||
fetch('${fetchURL}', { mode: 'no-cors' }).then(response => {
|
||||
return response.text();
|
||||
}).then(text => {
|
||||
parent.postMessage({ data: text }, '*');
|
||||
}).catch(e => {
|
||||
parent.postMessage({ data: e.message }, '*');
|
||||
});
|
||||
</` + `script>`;
|
||||
|
||||
const workerControllerText =
|
||||
`let t = navigator.serviceWorker.controller
|
||||
? navigator.serviceWorker.controller.scriptURL
|
||||
: null;
|
||||
self.postMessage(t);`;
|
||||
|
||||
const workerFetchText =
|
||||
`fetch('${fetchURL}', { mode: 'no-cors' }).then(response => {
|
||||
return response.text();
|
||||
}).then(text => {
|
||||
self.postMessage(text);
|
||||
}).catch(e => {
|
||||
self.postMessage(e.message);
|
||||
});`
|
||||
|
||||
function getChildText(opts) {
|
||||
if (opts.child === 'iframe') {
|
||||
return frameText;
|
||||
if (opts.check === 'controller') {
|
||||
return frameControllerText;
|
||||
}
|
||||
|
||||
if (opts.check === 'fetch') {
|
||||
return frameFetchText;
|
||||
}
|
||||
|
||||
throw('unexpected feature to check: ' + opts.check);
|
||||
}
|
||||
|
||||
if (opts.child === 'worker') {
|
||||
return workerText;
|
||||
if (opts.check === 'controller') {
|
||||
return workerControllerText;
|
||||
}
|
||||
|
||||
if (opts.check === 'fetch') {
|
||||
return workerFetchText;
|
||||
}
|
||||
|
||||
throw('unexpected feature to check: ' + opts.check);
|
||||
}
|
||||
|
||||
throw('unexpected child type ' + opts.child);
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
addEventListener('fetch', evt => {
|
||||
if (evt.request.url.includes('dummy')) {
|
||||
evt.respondWith(new Response('intercepted'));
|
||||
}
|
||||
});
|
Загрузка…
Ссылка в новой задаче