Bug 1884032 [wpt PR 44942] - [css-color] add missing colorscheme-aware tests, a=testonly
[gecko.git] / dom / serviceworkers / test / browser_cached_force_refresh.html
bloba0223d26b8727b58e35d2313ce74661c2ec11ed1
1 <!--
2 Any copyright is dedicated to the Public Domain.
3 http://creativecommons.org/publicdomain/zero/1.0/
4 -->
5 <!DOCTYPE HTML>
6 <html>
7 <head>
8 </head>
9 <body>
10 <script type="text/javascript">
11 function ok(exp, msg) {
12 if (!exp) {
13 throw(msg);
17 function is(actual, expected, msg) {
18 if (actual !== expected) {
19 throw('got "' + actual + '", but expected "' + expected + '" - ' + msg);
23 function fail(err) {
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);
34 });
35 sw.postMessage({ type: 'GET_UNCONTROLLED_CLIENTS' })
36 });
39 addEventListener('load', function(event) {
40 if (!navigator.serviceWorker.controller) {
41 fail(window.location.href + ' is not controlled!');
42 return;
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) {
55 fail(err);
56 });
57 });
58 </script>
59 </body>
60 </html>