summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/service-workers/service-worker/resources/local-url-inherit-controller-frame.html
diff options
context:
space:
mode:
Diffstat (limited to 'testing/web-platform/tests/service-workers/service-worker/resources/local-url-inherit-controller-frame.html')
-rw-r--r--testing/web-platform/tests/service-workers/service-worker/resources/local-url-inherit-controller-frame.html60
1 files changed, 59 insertions, 1 deletions
diff --git a/testing/web-platform/tests/service-workers/service-worker/resources/local-url-inherit-controller-frame.html b/testing/web-platform/tests/service-workers/service-worker/resources/local-url-inherit-controller-frame.html
index b1e554d220..3a5d9b51e7 100644
--- a/testing/web-platform/tests/service-workers/service-worker/resources/local-url-inherit-controller-frame.html
+++ b/testing/web-platform/tests/service-workers/service-worker/resources/local-url-inherit-controller-frame.html
@@ -42,7 +42,33 @@ const workerFetchText =
self.postMessage(text);
}).catch(e => {
self.postMessage(e.message);
-});`
+});`;
+
+const sharedWorkerControllerText =
+`const ports = [];
+self.onconnect = evt => {
+ const port = evt.ports[0];
+ ports.push(port);
+ const t = navigator.serviceWorker.controller
+ ? navigator.serviceWorker.controller.scriptURL
+ : null;
+ port.postMessage(t);
+};
+self.onerror = msg => {
+ ports.forEach(port => {port.postMessage(msg);});
+};`;
+
+const sharedWorkerFetchText =
+`self.onconnect = evt => {
+ const port = evt.ports[0];
+ fetch('${fetchURL}', { mode: 'no-cors' }).then(response => {
+ return response.text();
+ }).then(text => {
+ port.postMessage(text);
+ }).catch(e => {
+ port.postMessage(e.message);
+ });
+};`;
function getChildText(opts) {
if (opts.child === 'iframe') {
@@ -69,6 +95,18 @@ function getChildText(opts) {
throw('unexpected feature to check: ' + opts.check);
}
+ if (opts.child === 'sharedworker') {
+ if (opts.check === 'controller') {
+ return sharedWorkerControllerText;
+ }
+
+ if (opts.check === 'fetch') {
+ return sharedWorkerFetchText;
+ }
+
+ throw('unexpected feature to check: ' + opts.check);
+ }
+
throw('unexpected child type ' + opts.child);
}
@@ -98,6 +136,22 @@ function testWorkerChild(url) {
});
}
+function testSharedWorkerChild(url) {
+ let w = new SharedWorker(url);
+ return new Promise((resolve, reject) => {
+ w.port.onmessage = m => {
+ if (m.data.includes("Error")) {
+ reject(m.data);
+ return;
+ }
+ resolve(m);
+ }
+ w.onerror = evt => {
+ reject(evt.message);
+ }
+ });
+}
+
function testIframeChild(url) {
let frame = document.createElement('iframe');
frame.src = url;
@@ -115,6 +169,10 @@ function testURL(opts, url) {
return testWorkerChild(url);
}
+ if (opts.child === 'sharedworker') {
+ return testSharedWorkerChild(url);
+ }
+
if (opts.child === 'iframe') {
return testIframeChild(url);
}