Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Side by Side Diff: third_party/WebKit/LayoutTests/imported/wpt/service-workers/service-worker/resources/fetch-mixed-content-iframe.html

Issue 2415873002: Import w3c tests for the service workers (Closed)
Patch Set: Rebase Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 <!DOCTYPE html> 1 <!DOCTYPE html>
2 <script src="../../resources/get-host-info.js?pipe=sub"></script> 2 <script src="../resources/get-host-info.sub.js"></script>
3 <script src="test-helpers.js"></script> 3 <script src="test-helpers.sub.js?pipe=sub"></script>
4 <script> 4 <script>
5 var params = get_query_params(location.href); 5 var params = get_query_params(location.href);
6 var SCOPE = 'fetch-mixed-content-iframe-inscope-to-' + params['target'] + '.html '; 6 var SCOPE = 'fetch-mixed-content-iframe-inscope-to-' + params['target'] + '.html ';
7 var URL = 'fetch-rewrite-worker.js'; 7 var URL = 'fetch-rewrite-worker.js';
8 var host_info = get_host_info(); 8 var host_info = get_host_info();
9 9
10 window.addEventListener('message', on_message, false); 10 window.addEventListener('message', on_message, false);
11 11
12 navigator.serviceWorker.getRegistration(SCOPE) 12 navigator.serviceWorker.getRegistration(SCOPE)
13 .then(function(registration) { 13 .then(function(registration) {
14 if (registration) 14 if (registration)
15 return registration.unregister(); 15 return registration.unregister();
16 }) 16 })
17 .then(function() { 17 .then(function() {
18 return navigator.serviceWorker.register(URL, {scope: SCOPE}); 18 return navigator.serviceWorker.register(URL, {scope: SCOPE});
19 }) 19 })
20 .then(function(registration) { 20 .then(function(registration) {
21 return new Promise(function(resolve) { 21 return new Promise(function(resolve) {
22 registration.addEventListener('updatefound', function() { 22 registration.addEventListener('updatefound', function() {
23 resolve(registration.installing); 23 resolve(registration.installing);
24 }); 24 });
25 }); 25 });
26 }) 26 })
27 .then(function(worker) { 27 .then(function(worker) {
28 worker.addEventListener('statechange', on_state_change); 28 worker.addEventListener('statechange', on_state_change);
29 }) 29 })
30 .catch(function(reason) { 30 .catch(function(reason) {
31 window.parent.postMessage({results: 'FAILURE: ' + reason.message}, 31 window.parent.postMessage({results: 'FAILURE: ' + reason.message},
32 host_info['HTTP_ORIGIN']); 32 host_info['HTTPS_ORIGIN']);
33 }); 33 });
34 34
35 function on_state_change(event) { 35 function on_state_change(event) {
36 if (event.target.state != 'activated') 36 if (event.target.state != 'activated')
37 return; 37 return;
38 var frame = document.createElement('iframe'); 38 var frame = document.createElement('iframe');
39 frame.src = SCOPE; 39 frame.src = SCOPE;
40 document.body.appendChild(frame); 40 document.body.appendChild(frame);
41 } 41 }
42 42
43 function on_message(e) { 43 function on_message(e) {
44 navigator.serviceWorker.getRegistration(SCOPE) 44 navigator.serviceWorker.getRegistration(SCOPE)
45 .then(function(registration) { 45 .then(function(registration) {
46 if (registration) 46 if (registration)
47 return registration.unregister(); 47 return registration.unregister();
48 }) 48 })
49 .then(function() { 49 .then(function() {
50 window.parent.postMessage(e.data, host_info['HTTP_ORIGIN']); 50 window.parent.postMessage(e.data, host_info['HTTPS_ORIGIN']);
51 }) 51 })
52 .catch(function(reason) { 52 .catch(function(reason) {
53 window.parent.postMessage({results: 'FAILURE: ' + reason.message}, 53 window.parent.postMessage({results: 'FAILURE: ' + reason.message},
54 host_info['HTTP_ORIGIN']); 54 host_info['HTTPS_ORIGIN']);
55 }); 55 });
56 } 56 }
57 57
58 function get_query_params(url) { 58 function get_query_params(url) {
59 var search = (new URL(url)).search; 59 var search = (new URL(url)).search;
60 if (!search) { 60 if (!search) {
61 return {}; 61 return {};
62 } 62 }
63 var ret = {}; 63 var ret = {};
64 var params = search.substring(1).split('&'); 64 var params = search.substring(1).split('&');
65 params.forEach(function(param) { 65 params.forEach(function(param) {
66 var element = param.split('='); 66 var element = param.split('=');
67 ret[decodeURIComponent(element[0])] = decodeURIComponent(element[1]); 67 ret[decodeURIComponent(element[0])] = decodeURIComponent(element[1]);
68 }); 68 });
69 return ret; 69 return ret;
70 } 70 }
71 </script> 71 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698