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

Unified Diff: third_party/WebKit/LayoutTests/imported/wpt/service-workers/service-worker/postmessage.https.html

Issue 2415873002: Import w3c tests for the service workers (Closed)
Patch Set: Rebase Created 4 years, 2 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: third_party/WebKit/LayoutTests/imported/wpt/service-workers/service-worker/postmessage.https.html
diff --git a/third_party/WebKit/LayoutTests/imported/wpt/service-workers/service-worker/postmessage.https.html b/third_party/WebKit/LayoutTests/imported/wpt/service-workers/service-worker/postmessage.https.html
new file mode 100644
index 0000000000000000000000000000000000000000..a6f66517910eefd54abc722c7cf16a7d6f3794ac
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/imported/wpt/service-workers/service-worker/postmessage.https.html
@@ -0,0 +1,60 @@
+<!DOCTYPE html>
+<title>Service Worker: postMessage</title>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="resources/test-helpers.sub.js"></script>
+<script>
+async_test(function(t) {
+ var scope = 'resources/blank.html';
+ var registration;
+ var worker;
+ service_worker_unregister_and_register(
+ t, 'resources/postmessage-worker.js', scope)
+ .then(function(r) {
+ registration = r;
+ worker = registration.installing;
+ var messageChannel = new MessageChannel();
+ messageChannel.port1.onmessage = t.step_func(onMessage);
+ worker.postMessage({port: messageChannel.port2},
+ [messageChannel.port2]);
+ worker.postMessage({value: 1});
+ worker.postMessage({value: 2});
+ worker.postMessage({done: true});
+ })
+ .catch(unreached_rejection(t));
+
+ var result = [];
+ var expected = [
+ 'Acking value: 1',
+ 'Acking value: 2',
+ ];
+
+ function onMessage(e) {
+ var message = e.data;
+ if (message === 'quit') {
+ assert_array_equals(result, expected,
+ 'Worker should post back expected values.');
+ postMessageToRedundantWorker();
+ } else {
+ result.push(message);
+ }
+ };
+
+ function postMessageToRedundantWorker() {
+ registration.unregister(scope)
+ .then(function() {
+ return wait_for_state(t, worker, 'redundant');
+ })
+ .then(function() {
+ assert_equals(worker.state, 'redundant');
+ assert_throws(
+ {name:'InvalidStateError'},
+ function() { worker.postMessage(''); },
+ 'Calling postMessage on a redundant ServiceWorker should ' +
+ 'throw InvalidStateError.');
+ t.done();
+ })
+ .catch(unreached_rejection(t));
+ }
+ }, 'postMessage to a ServiceWorker (and back via MessagePort)');
+</script>

Powered by Google App Engine
This is Rietveld 408576698