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 !!request_set[expected_base_url + '?iframe'], | |
nhiroki
2015/06/26 04:33:32
You might want to use 'in' operator like this:
horo
2015/06/26 04:57:25
Done.
| |
81 'The request for normal iframe should be handled by SW.'); | |
82 assert_true( | |
83 !!request_set[expected_base_url + '?iframe_fetch'], | |
84 'The fetch request from normal iframe should be handled by SW.'); | |
85 assert_true( | |
86 !!request_set[expected_base_url + '?iframe_iframe'], | |
87 'The request for normal iframe inside normal iframe should be ' + | |
88 'handled by SW.'); | |
89 assert_false( | |
90 !!request_set[expected_base_url + '?iframe_script'], | |
91 'The request for sandboxed iframe with allow-scripts flag ' + | |
92 'inside normal iframe should not be handled by SW.'); | |
93 assert_true( | |
94 !!request_set[expected_base_url + '?iframe_script-origin'], | |
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 !!request_set[expected_base_url + '?script'], | |
100 'The request for sandboxed iframe with allow-scripts flag ' + | |
101 'should not be handled by SW.'); | |
102 assert_false( | |
103 !!request_set[expected_base_url + '?script_fetch'], | |
104 'The fetch request from sandboxed iframe with allow-scripts ' + | |
105 'flag should not be handled by SW.'); | |
106 assert_false( | |
107 !!request_set[expected_base_url + '?script_iframe'], | |
108 'The request for normal iframe inside sandboxed iframe with ' + | |
109 'allow-scripts flag should not be handled by SW.'); | |
110 assert_false( | |
111 !!request_set[expected_base_url + '?script_script'], | |
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 !!request_set[expected_base_url + '?script_script-origin'], | |
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 !!request_set[expected_base_url + '?script-origin'], | |
122 'The request for sandboxed iframe with allow-scripts and ' + | |
123 'allow-same-origin flag should be handled by SW.'); | |
124 assert_true( | |
125 !!request_set[expected_base_url + '?script-origin_fetch'], | |
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 !!request_set[expected_base_url + '?script-origin_iframe'], | |
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 !!request_set[expected_base_url + '?script-origin_script'], | |
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 !!request_set[expected_base_url + '?script-origin_script-origin'], | |
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 !!client_set[expected_base_url + '?iframe'], | |
151 'The normal iframe should be controlled by SW.'); | |
152 assert_true( | |
153 !!client_set[expected_base_url + '?iframe_iframe'], | |
154 'The normal iframe inside normal iframe should be controlled ' + | |
155 'by SW.'); | |
156 assert_false( | |
157 !!client_set[expected_base_url + '?iframe_script'], | |
158 'The sandboxed iframe with allow-scripts flag inside normal ' + | |
159 'iframe should not be controlled by SW.'); | |
160 assert_true( | |
161 !!client_set[expected_base_url + '?iframe_script-origin'], | |
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 !!client_set[expected_base_url + '?script'], | |
166 'The sandboxed iframe with allow-scripts flag should not be ' + | |
167 'controlled by SW.'); | |
168 assert_false( | |
169 !!client_set[expected_base_url + '?script_iframe'], | |
170 'The normal iframe inside sandboxed iframe with allow-scripts' + | |
171 'flag should not be controlled by SW.'); | |
172 assert_false( | |
173 !!client_set[expected_base_url + '?script_script'], | |
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 !!client_set[expected_base_url + '?script_script-origin'], | |
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 !!client_set[expected_base_url + '?script-origin'], | |
183 'The sandboxed iframe with allow-scripts and allow-same-origin ' + | |
184 'flag should be controlled by SW.'); | |
185 assert_true( | |
186 !!client_set[expected_base_url + '?script-origin_iframe'], | |
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 !!client_set[expected_base_url + '?script-origin_script'], | |
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 !!client_set[expected_base_url + '?script-origin_script-origin'], | |
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 |