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>
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
)
14 return wait_for_state(t
, r
.installing
, 'activated');
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
) {
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');
39 worker
.postMessage('PING');
43 return service_worker_unregister_and_done(t
, scope
);
45 }, 'Test ServiceWorkerMessageEvent type.');