2 Any copyright is dedicated to the Public Domain.
3 http://creativecommons.org/publicdomain/zero/1.0/
10 <script type=
"text/javascript">
11 function ok(exp
, msg
) {
17 function is(actual
, expected
, msg
) {
18 if (actual
!== expected
) {
19 throw('got "' + actual
+ '", but expected "' + expected
+ '" - ' + msg
);
24 window
.dispatchEvent(new Event("cached-failure", { bubbles
: true, detail
: err
}));
27 function getUncontrolledClients(sw
) {
28 return new Promise(function(resolve
, reject
) {
29 navigator
.serviceWorker
.addEventListener('message', function onMsg(evt
) {
30 if (evt
.data
.type
=== 'CLIENTS') {
31 navigator
.serviceWorker
.removeEventListener('message', onMsg
);
32 resolve(evt
.data
.detail
);
35 sw
.postMessage({ type
: 'GET_UNCONTROLLED_CLIENTS' })
39 addEventListener('load', function(event
) {
40 if (!navigator
.serviceWorker
.controller
) {
41 fail(window
.location
.href
+ ' is not controlled!');
45 getUncontrolledClients(navigator
.serviceWorker
.controller
)
46 .then(function(clientList
) {
47 is(clientList
.length
, 1, 'should only have one client');
48 is(clientList
[0].url
, window
.location
.href
,
49 'client url should match current window');
50 is(clientList
[0].frameType
, 'top-level',
51 'client should be a top-level window');
52 window
.dispatchEvent(new Event('cached-load', { bubbles
: true }));
54 .catch(function(err
) {