Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(188)

Unified Diff: LayoutTests/http/tests/serviceworker/postmessage-to-client.html

Issue 264233003: Add blink-side binding code and tests for ServiceWorker -> Document postMessage (3/3) (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: remove local test remnant Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: LayoutTests/http/tests/serviceworker/postmessage-to-client.html
diff --git a/LayoutTests/http/tests/serviceworker/current-on-load.html b/LayoutTests/http/tests/serviceworker/postmessage-to-client.html
similarity index 57%
copy from LayoutTests/http/tests/serviceworker/current-on-load.html
copy to LayoutTests/http/tests/serviceworker/postmessage-to-client.html
index 5c43c4d47d9ff8db6634e418f5e483b59380dfbd..01a63a2d13913e67bc2c92c392a2202a72db35b9 100644
--- a/LayoutTests/http/tests/serviceworker/current-on-load.html
+++ b/LayoutTests/http/tests/serviceworker/postmessage-to-client.html
@@ -1,21 +1,20 @@
<!DOCTYPE html>
-<title>Service Worker: Current on load</title>
+<title>Service Worker: postMessage to Client</title>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<script src="resources/test-helpers.js"></script>
-<body>
<script>
-var t = async_test('current is set for a controlled document');
+var t = async_test('postMessage from ServiceWorker to Client');
t.step(function() {
var scope = 'resources/blank.html'
navigator.serviceWorker.unregister(scope).then(
- doTest,
+ doRegister,
unreached_rejection(t, 'Unregister should not fail')
);
- function doTest() {
+ function doRegister() {
navigator.serviceWorker.register(
- 'resources/worker-no-op.js', {scope: scope}
+ 'resources/postmessage-to-client-worker.js', {scope: scope}
).then(
onRegister,
unreached_rejection(t, 'Registration should succeed, but failed')
@@ -32,11 +31,22 @@ t.step(function() {
function onActive() {
with_iframe(scope, t.step_func(function(frame) {
var w = frame.contentWindow;
- assert_true(w.navigator.serviceWorker.current instanceof w.ServiceWorker,
- 'current should be a ServiceWorker object');
- t.done();
+ w.onmessage = t.step_func(onMessage);
+ w.navigator.serviceWorker.current.postMessage('ping');
}));
}
+
+ var result = [];
+ var expected = ['Sending message via clients'];
+
+ function onMessage(e) {
+ var message = e.data;
+ if (message === 'quit') {
+ assert_array_equals(result, expected, 'Worker should post back expected messages.');
+ t.done();
+ } else {
+ result.push(message);
+ }
+ }
});
</script>
-</body>

Powered by Google App Engine
This is Rietveld 408576698