-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement ServiceWorkerContainer.onmessageerror.
This patch implements ServiceWorkerContainer.onmessageerror and writes WPT test for it. chromestatus: https://chromestatus.com/feature/5699031592337408 Bug: 926102 Change-Id: I60e73dcb69de4a2876cc966dfa1809a30510b5f2 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1864409 Reviewed-by: Kent Tamura <tkent@chromium.org> Reviewed-by: Matt Falkenhagen <falken@chromium.org> Commit-Queue: Wei4 Wang <wei4.wang@intel.com> Cr-Commit-Position: refs/heads/master@{#718507}
- Loading branch information
1 parent
ff1ea7c
commit c2ddea9
Showing
6 changed files
with
137 additions
and
0 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
...e/safe-passing-of-structured-data/shared-array-buffers/resources/serviceworker-success.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
"use strict"; | ||
self.importScripts("/resources/testharness.js"); | ||
|
||
let state = "start in worker"; | ||
|
||
self.onmessage = e => { | ||
if (e.data === "start in window") { | ||
assert_equals(state, "start in worker"); | ||
e.source.postMessage(state); | ||
state = "waiting for message from the window"; | ||
} else if (e.data === "we are expecting a messageerror due to the worker sending us a SAB") { | ||
assert_equals(state, "waiting for message from the window"); | ||
e.source.postMessage(new SharedArrayBuffer()); | ||
state = "done in worker"; | ||
} else { | ||
e.source.postMessage(`worker onmessage was reached when in state "${state}" and data ${e.data}`); | ||
} | ||
}; |
1 change: 1 addition & 0 deletions
1
...assing-of-structured-data/shared-array-buffers/resources/serviceworker-success.js.headers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Cross-Origin-Embedder-Policy: require-corp |
48 changes: 48 additions & 0 deletions
48
...e-passing-of-structured-data/shared-array-buffers/window-serviceworker-success.https.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<!DOCTYPE html> | ||
<meta charset="utf-8"> | ||
<title>Test ServiceWorkerContainer.onmessageerror using SharedArrayBuffer</title> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script src="/service-workers/service-worker/resources/test-helpers.sub.js"></script> | ||
|
||
<script> | ||
"use strict"; | ||
promise_test(t => { | ||
const scope = "resources/blank.html"; | ||
return service_worker_unregister_and_register(t, "resources/serviceworker-success.js", scope) | ||
.then(reg => { | ||
t.add_cleanup(() => service_worker_unregister(t, scope)); | ||
return wait_for_state(t, reg.installing, "activated"); | ||
}) | ||
.then(() => with_iframe(scope)) | ||
.then(iframe => { | ||
t.add_cleanup(() => iframe.remove()); | ||
const sw = iframe.contentWindow.navigator.serviceWorker; | ||
let state = "start in window"; | ||
|
||
return new Promise(resolve => { | ||
sw.onmessage = t.step_func(e => { | ||
if (e.data === "start in worker") { | ||
assert_equals(state, "start in window"); | ||
state = "we are expecting a messageerror due to the worker sending us a SAB"; | ||
sw.controller.postMessage(state); | ||
} else { | ||
assert_unreached("Got an unexpected message from the service worker: " + e.data); | ||
} | ||
}); | ||
|
||
sw.onmessageerror = t.step_func(e => { | ||
assert_equals(state, "we are expecting a messageerror due to the worker sending us a SAB"); | ||
assert_equals(e.data, null, "data"); | ||
assert_equals(e.origin, self.origin, "origin"); | ||
assert_not_equals(e.source, null, "source"); | ||
assert_equals(e.ports.length, 0, "ports length"); | ||
state = "done in window"; | ||
resolve(); | ||
}); | ||
|
||
sw.controller.postMessage(state); | ||
}); | ||
}); | ||
}); | ||
</script> |
2 changes: 2 additions & 0 deletions
2
...g-of-structured-data/shared-array-buffers/window-serviceworker-success.https.html.headers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Cross-Origin-Opener-Policy: same-origin | ||
Cross-Origin-Embedder-Policy: require-corp |
19 changes: 19 additions & 0 deletions
19
wasm/serialization/module/resources/serviceworker-success.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
"use strict"; | ||
self.importScripts("/resources/testharness.js"); | ||
self.importScripts("./create-empty-wasm-module.js"); | ||
|
||
let state = "start in worker"; | ||
|
||
self.onmessage = e => { | ||
if (e.data === "start in window") { | ||
assert_equals(state, "start in worker"); | ||
e.source.postMessage(state); | ||
state = "waiting for message from the window"; | ||
} else if (e.data === "we are expecting a messageerror due to the worker sending us a WebAssembly.Module") { | ||
assert_equals(state, "waiting for message from the window"); | ||
e.source.postMessage(createEmptyWasmModule()); | ||
state = "done in worker"; | ||
} else { | ||
e.source.postMessage(`worker onmessage was reached when in state "${state}" and data ${e.data}`); | ||
} | ||
}; |
49 changes: 49 additions & 0 deletions
49
wasm/serialization/module/window-serviceworker-success.https.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<!DOCTYPE html> | ||
<meta charset="utf-8"> | ||
<title>Test ServiceWorkerContainer.onmessageerror using WebAssembly.Module</title> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script src="/service-workers/service-worker/resources/test-helpers.sub.js"></script> | ||
<script src="./resources/create-empty-wasm-module.js"></script> | ||
|
||
<script> | ||
"use strict"; | ||
promise_test(t => { | ||
const scope = "resources/blank.html"; | ||
return service_worker_unregister_and_register(t, "resources/serviceworker-success.js", scope) | ||
.then(reg => { | ||
t.add_cleanup(() => service_worker_unregister(t, scope)); | ||
return wait_for_state(t, reg.installing, "activated"); | ||
}) | ||
.then(() => with_iframe(scope)) | ||
.then(iframe => { | ||
t.add_cleanup(() => iframe.remove()); | ||
const sw = iframe.contentWindow.navigator.serviceWorker; | ||
let state = "start in window"; | ||
|
||
return new Promise(resolve => { | ||
sw.onmessage = t.step_func(e => { | ||
if (e.data === "start in worker") { | ||
assert_equals(state, "start in window"); | ||
state = "we are expecting a messageerror due to the worker sending us a WebAssembly.Module"; | ||
sw.controller.postMessage(state); | ||
} else { | ||
assert_unreached("Got an unexpected message from the service worker: " + e.data); | ||
} | ||
}); | ||
|
||
sw.onmessageerror = t.step_func(e => { | ||
assert_equals(state, "we are expecting a messageerror due to the worker sending us a WebAssembly.Module"); | ||
assert_equals(e.data, null, "data"); | ||
assert_equals(e.origin, self.origin, "origin"); | ||
assert_not_equals(e.source, null, "source"); | ||
assert_equals(e.ports.length, 0, "ports length"); | ||
state = "done in window"; | ||
resolve(); | ||
}); | ||
|
||
sw.controller.postMessage(state); | ||
}); | ||
}); | ||
}); | ||
</script> |