Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / LayoutTests / http / tests / local / serviceworker / resources / fetch-request-body-file-iframe.html
1 <script>
2 var port = undefined;
3 var scope = 'fetch-request-body-file-test';
4 var script = 'fetch-request-body-file-worker.js';
5
6 window.addEventListener('message', function(evt) {
7     port = evt.ports[0];
8     start();
9   }, false);
10
11 function wait_for_update(registration) {
12   return new Promise(function(resolve) {
13       registration.addEventListener('updatefound', function() {
14           resolve(registration.installing);
15         });
16     });
17 }
18
19 function wait_for_activated(worker) {
20   return new Promise(function(resolve) {
21       worker.addEventListener('statechange', function() {
22           if (worker.state == 'activated') {
23             resolve(worker);
24           }
25         });
26     });
27 }
28
29 function start() {
30   if (location.search == '?register') {
31     navigator.serviceWorker.register(script, {scope: scope})
32       .then(function(registration) {
33           return registration.unregister();
34         })
35       .then(function() {
36           return navigator.serviceWorker.register(script, {scope: scope});
37         })
38       .then(wait_for_update)
39       .then(wait_for_activated)
40       .then(function(worker) {
41           port.postMessage({msg: 'registered'});
42         });
43   } else if (location.search == '?unregister') {
44     navigator.serviceWorker.register(script, {scope: scope})
45       .then(function(registration) {
46           return registration.unregister();
47         })
48       .then(function() {
49           port.postMessage({msg: 'unregistered'});
50         });
51   }
52 }
53 </script>