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>
8 var lastCallbackId
= 0;
10 function postMassageAndWaitResult(frame
) {
11 return new Promise(function(resolve
) {
12 var id
= ++lastCallbackId
;
13 callbacks
[id
] = resolve
;
14 frame
.contentWindow
.postMessage({id
:id
}, '*');
18 window
.onmessage = function (e
) {
20 var id
= message
['id'];
21 var calback
= callbacks
[id
];
23 calback(message
['result']);
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';
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');
37 return with_iframe(SCOPE
+ '?iframe');
39 .then(function(frame
) {
41 return postMassageAndWaitResult(frame
);
43 .then(function(result
) {
44 assert_equals(result
, 'done');
45 return with_sandboxed_iframe(SCOPE
+ '?script', 'allow-scripts');
47 .then(function(frame
) {
49 return postMassageAndWaitResult(frame
);
51 .then(function(result
) {
52 assert_equals(result
, 'done');
53 return with_sandboxed_iframe(SCOPE
+ '?script-origin',
54 'allow-scripts allow-same-origin');
56 .then(function(frame
) {
58 return postMassageAndWaitResult(frame
);
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
) {
67 worker
.postMessage({port
: channel
.port2
}, [channel
.port2
]);
71 for (var frame
of frames
) {
74 var expected_base_url
= new URL(SCOPE
, location
.href
).href
;
76 for (var request
of msg
.data
.requests
) {
77 request_set
[request
] = true;
80 expected_base_url
+ '?iframe' in request_set
,
81 'The request for normal iframe should be handled by SW.');
83 expected_base_url
+ '?iframe_fetch' in request_set
,
84 'The fetch request from normal iframe should be handled by SW.');
86 expected_base_url
+ '?iframe_iframe' in request_set
,
87 'The request for normal iframe inside normal iframe should be ' +
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.');
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 ' +
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.');
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.');
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.');
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 ' +
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.');
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.');
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.');
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' +
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.');
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' +
146 for (var client
of msg
.data
.clients
) {
147 client_set
[client
] = true;
150 expected_base_url
+ '?iframe' in client_set
,
151 'The normal iframe should be controlled by SW.');
153 expected_base_url
+ '?iframe_iframe' in client_set
,
154 'The normal iframe inside normal iframe should be controlled ' +
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.');
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.');
165 expected_base_url
+ '?script' in client_set
,
166 'The sandboxed iframe with allow-scripts flag should not be ' +
167 'controlled by SW.');
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.');
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.');
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.');
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.');
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.');
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.');
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
);
201 }, 'ServiceWorker FetchEvent for sandboxed iframe.');