OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <title>ServiceWorker FetchEvent for sandboxed iframe.</title> |
| 3 <script src="../../resources/testharness.js"></script> |
| 4 <script src="../../resources/testharnessreport.js"></script> |
| 5 <script src="../resources/test-helpers.js"></script> |
| 6 <body> |
| 7 <script> |
| 8 var lastCallbackId = 0; |
| 9 var callbacks = {}; |
| 10 function postMassageAndWaitResult(frame) { |
| 11 return new Promise(function(resolve) { |
| 12 var id = ++lastCallbackId; |
| 13 callbacks[id] = resolve; |
| 14 frame.contentWindow.postMessage({id:id}, '*'); |
| 15 }); |
| 16 } |
| 17 |
| 18 window.onmessage = function (e) { |
| 19 message = e.data; |
| 20 var id = message['id']; |
| 21 var calback = callbacks[id]; |
| 22 delete callbacks[id]; |
| 23 calback(message['result']); |
| 24 }; |
| 25 |
| 26 promise_test(function(t) { |
| 27 var SCOPE = 'resources/sandboxed-iframe-fetch-event-iframe.html'; |
| 28 var SCRIPT = 'resources/sandboxed-iframe-fetch-event-worker.js'; |
| 29 var frames = []; |
| 30 var worker; |
| 31 return service_worker_unregister_and_register(t, SCRIPT, SCOPE) |
| 32 .then(function(registration) { |
| 33 worker = registration.installing; |
| 34 return wait_for_state(t, registration.installing, 'activated'); |
| 35 }) |
| 36 .then(function() { |
| 37 return with_iframe(SCOPE + '?iframe'); |
| 38 }) |
| 39 .then(function(frame) { |
| 40 frames.push(frame); |
| 41 return postMassageAndWaitResult(frame); |
| 42 }) |
| 43 .then(function(result) { |
| 44 assert_equals(result, 'done'); |
| 45 return with_sandboxed_iframe(SCOPE + '?script', 'allow-scripts'); |
| 46 }) |
| 47 .then(function(frame) { |
| 48 frames.push(frame); |
| 49 return postMassageAndWaitResult(frame); |
| 50 }) |
| 51 .then(function(result) { |
| 52 assert_equals(result, 'done'); |
| 53 return with_sandboxed_iframe(SCOPE + '?script-origin', |
| 54 'allow-scripts allow-same-origin'); |
| 55 }) |
| 56 .then(function(frame) { |
| 57 frames.push(frame); |
| 58 return postMassageAndWaitResult(frame); |
| 59 }) |
| 60 .then(function(result) { |
| 61 assert_equals(result, 'done'); |
| 62 return new Promise(function(resolve) { |
| 63 var channel = new MessageChannel(); |
| 64 channel.port1.onmessage = function(msg) { |
| 65 resolve(msg); |
| 66 }; |
| 67 worker.postMessage({port: channel.port2}, [channel.port2]); |
| 68 }); |
| 69 }) |
| 70 .then(function(msg) { |
| 71 for (var frame of frames) { |
| 72 frame.remove(); |
| 73 } |
| 74 var expected_base_url = new URL(SCOPE, location.href).href; |
| 75 var request_set = {}; |
| 76 for (var request of msg.data.requests) { |
| 77 request_set[request] = true; |
| 78 } |
| 79 assert_true( |
| 80 expected_base_url + '?iframe' in request_set, |
| 81 'The request for normal iframe should be handled by SW.'); |
| 82 assert_true( |
| 83 expected_base_url + '?iframe_fetch' in request_set, |
| 84 'The fetch request from normal iframe should be handled by SW.'); |
| 85 assert_true( |
| 86 expected_base_url + '?iframe_iframe' in request_set, |
| 87 'The request for normal iframe inside normal iframe should be ' + |
| 88 'handled by SW.'); |
| 89 assert_false( |
| 90 expected_base_url + '?iframe_script' in request_set, |
| 91 'The request for sandboxed iframe with allow-scripts flag ' + |
| 92 'inside normal iframe should not be handled by SW.'); |
| 93 assert_true( |
| 94 expected_base_url + '?iframe_script-origin' in request_set, |
| 95 'The request for sandboxed iframe with allow-scripts and ' + |
| 96 'allow-same-origin flag inside normal iframe should be handled ' + |
| 97 'by SW.'); |
| 98 assert_false( |
| 99 expected_base_url + '?script' in request_set, |
| 100 'The request for sandboxed iframe with allow-scripts flag ' + |
| 101 'should not be handled by SW.'); |
| 102 assert_false( |
| 103 expected_base_url + '?script_fetch' in request_set, |
| 104 'The fetch request from sandboxed iframe with allow-scripts ' + |
| 105 'flag should not be handled by SW.'); |
| 106 assert_false( |
| 107 expected_base_url + '?script_iframe' in request_set, |
| 108 'The request for normal iframe inside sandboxed iframe with ' + |
| 109 'allow-scripts flag should not be handled by SW.'); |
| 110 assert_false( |
| 111 expected_base_url + '?script_script' in request_set, |
| 112 'The request for sandboxed iframe with allow-scripts flag ' + |
| 113 'inside sandboxed iframe with allow-scripts flag should not be ' + |
| 114 'handled by SW.'); |
| 115 assert_false( |
| 116 expected_base_url + '?script_script-origin' in request_set, |
| 117 'The request for sandboxed iframe with allow-scripts and ' + |
| 118 'allow-same-origin flag inside sandboxed iframe with ' + |
| 119 'allow-scripts flag should not be handled by SW.'); |
| 120 assert_true( |
| 121 expected_base_url + '?script-origin' in request_set, |
| 122 'The request for sandboxed iframe with allow-scripts and ' + |
| 123 'allow-same-origin flag should be handled by SW.'); |
| 124 assert_true( |
| 125 expected_base_url + '?script-origin_fetch' in request_set, |
| 126 'The fetch request from sandboxed iframe with allow-scripts ' + |
| 127 'and allow-same-origin flag should be handled by SW.'); |
| 128 assert_true( |
| 129 expected_base_url + '?script-origin_iframe' in request_set, |
| 130 'The request for normal iframe inside sandboxed iframe with ' + |
| 131 'allow-scripts and allow-same-origin flag should be handled by' + |
| 132 'SW.'); |
| 133 assert_false( |
| 134 expected_base_url + '?script-origin_script' in request_set, |
| 135 'The request for sandboxed iframe with allow-scripts flag ' + |
| 136 'inside sandboxed iframe with allow-scripts and ' + |
| 137 'allow-same-origin flag should be handled by SW.'); |
| 138 assert_true( |
| 139 expected_base_url + '?script-origin_script-origin' in request_set, |
| 140 'The request for sandboxed iframe with allow-scripts and' + |
| 141 'allow-same-origin flag inside sandboxed iframe with ' + |
| 142 'allow-scripts and allow-same-origin flag should be handled by' + |
| 143 'SW.'); |
| 144 |
| 145 var client_set = {}; |
| 146 for (var client of msg.data.clients) { |
| 147 client_set[client] = true; |
| 148 } |
| 149 assert_true( |
| 150 expected_base_url + '?iframe' in client_set, |
| 151 'The normal iframe should be controlled by SW.'); |
| 152 assert_true( |
| 153 expected_base_url + '?iframe_iframe' in client_set, |
| 154 'The normal iframe inside normal iframe should be controlled ' + |
| 155 'by SW.'); |
| 156 assert_false( |
| 157 expected_base_url + '?iframe_script' in client_set, |
| 158 'The sandboxed iframe with allow-scripts flag inside normal ' + |
| 159 'iframe should not be controlled by SW.'); |
| 160 assert_true( |
| 161 expected_base_url + '?iframe_script-origin' in client_set, |
| 162 'The sandboxed iframe with allow-scripts and allow-same-origin' + |
| 163 'flag inside normal iframe should be controlled by SW.'); |
| 164 assert_false( |
| 165 expected_base_url + '?script' in client_set, |
| 166 'The sandboxed iframe with allow-scripts flag should not be ' + |
| 167 'controlled by SW.'); |
| 168 assert_false( |
| 169 expected_base_url + '?script_iframe' in client_set, |
| 170 'The normal iframe inside sandboxed iframe with allow-scripts' + |
| 171 'flag should not be controlled by SW.'); |
| 172 assert_false( |
| 173 expected_base_url + '?script_script' in client_set, |
| 174 'The sandboxed iframe with allow-scripts flag inside sandboxed ' + |
| 175 'iframe with allow-scripts flag should not be controlled by SW.'); |
| 176 assert_false( |
| 177 expected_base_url + '?script_script-origin' in client_set, |
| 178 'The sandboxed iframe with allow-scripts and allow-same-origin ' + |
| 179 'flag inside sandboxed iframe with allow-scripts flag should ' + |
| 180 'not be controlled by SW.'); |
| 181 assert_true( |
| 182 expected_base_url + '?script-origin' in client_set, |
| 183 'The sandboxed iframe with allow-scripts and allow-same-origin ' + |
| 184 'flag should be controlled by SW.'); |
| 185 assert_true( |
| 186 expected_base_url + '?script-origin_iframe' in client_set, |
| 187 'The normal iframe inside sandboxed iframe with allow-scripts ' + |
| 188 'and allow-same-origin flag should be controlled by SW.'); |
| 189 assert_false( |
| 190 expected_base_url + '?script-origin_script' in client_set, |
| 191 'The sandboxed iframe with allow-scripts flag inside sandboxed ' + |
| 192 'iframe with allow-scripts and allow-same-origin flag should ' + |
| 193 'be controlled by SW.'); |
| 194 assert_true( |
| 195 expected_base_url + '?script-origin_script-origin' in client_set, |
| 196 'The sandboxed iframe with allow-scripts and allow-same-origin ' + |
| 197 'flag inside sandboxed iframe with allow-scripts and ' + |
| 198 'allow-same-origin flag should be controlled by SW.'); |
| 199 return service_worker_unregister_and_done(t, SCOPE); |
| 200 }); |
| 201 }, 'ServiceWorker FetchEvent for sandboxed iframe.'); |
| 202 </script> |
| 203 </body> |
OLD | NEW |