Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / http / tests / serviceworker / serviceworker-message-event.html
blob7f9d7526c532105e7663c5512c0e3199267e80fd
1 <!DOCTYPE html>
2 <title>Service Worker: ServiceWorkerMessageEvent</title>
3 <script src="../resources/testharness.js"></script>
4 <script src="../resources/testharness-helpers.js"></script>
5 <script src="../resources/testharnessreport.js"></script>
6 <script src="resources/test-helpers.js"></script>
7 <script>
9 promise_test(function(t) {
10 var scope = 'resources/blank.html';
11 var url = 'resources/postmessage-to-client-worker.js';
12 return service_worker_unregister_and_register(t, url, scope)
13 .then(function(r) {
14 return wait_for_state(t, r.installing, 'activated');
16 .then(function() {
17 return with_iframe(scope);
19 .then(function(frame) {
20 var w = frame.contentWindow;
21 var worker = w.navigator.serviceWorker.controller;
22 // Test constructor with ServiceWorker object as source.
23 var e = new ServiceWorkerMessageEvent('eventType', {source: worker});
24 assert_equals(e.source, worker,
25 'Source should equal to the passing service worker');
26 return new Promise(function(resolve) {
27 w.navigator.serviceWorker.onmessage = t.step_func(function(e) {
28 assert_true(
29 e instanceof w.ServiceWorkerMessageEvent,
30 'Instance type should be ServiceWorkerMessageEvent');
31 assert_true(e.source instanceof w.ServiceWorker,
32 'Source type should be ServiceWorker');
33 assert_equals(e.type, 'message',
34 'Event type should be "message"');
35 assert_equals(e.source, worker,
36 'Source worker should equal to the controller');
37 resolve();
38 });
39 worker.postMessage('PING');
40 });
42 .then(function() {
43 return service_worker_unregister_and_done(t, scope);
44 });
45 }, 'Test ServiceWorkerMessageEvent type.');
47 </script>