Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 556acff

Browse files
committedOct 4, 2019
Bug 1570776 [wpt PR 17554] - Add ability for service worker to filter out frozen windows., a=testonly
Automatic update from web-platform-tests Add ability for service worker to filter out frozen windows. Add code to support handling of frozen clients. Frozen clients do not run their event loop, so postMessage to them just causes problems. To allow service workers to continue working with frozen windows we expose includeFrozen in the matchAll and the frozen attribute on the Client. If a service worker calls focus on a client it will unfreeze the window when it is moved to have focus. This feature is currently marked as experimental and an intent to ship will be sent. This is specified in https://wicg.github.io/page-lifecycle/ and w3c/ServiceWorker#1442 BUG=957597 Change-Id: I6abe1882e88c65dac99250db5bb7fa8d3a4b2b1d Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1677065 Commit-Queue: Ken Buchanan <kenrbchromium.org> Reviewed-by: Ken Buchanan <kenrbchromium.org> Reviewed-by: Matt Falkenhagen <falkenchromium.org> Cr-Commit-Position: refs/heads/master{#689558} -- wpt-commits: 3d052c54485970c1673500c1ba7d52182adf6f4f wpt-pr: 17554 UltraBlame original commit: d34dc9e00ee2c4ca00e2b78bdad1f7c51f68ba3e
1 parent 535aef7 commit 556acff

File tree

3 files changed

+1081
-0
lines changed

3 files changed

+1081
-0
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,914 @@
1+
<
2+
!
3+
DOCTYPE
4+
html
5+
>
6+
<
7+
title
8+
>
9+
Service
10+
Worker
11+
:
12+
Clients
13+
.
14+
matchAll
15+
<
16+
/
17+
title
18+
>
19+
<
20+
script
21+
src
22+
=
23+
"
24+
/
25+
resources
26+
/
27+
testharness
28+
.
29+
js
30+
"
31+
>
32+
<
33+
/
34+
script
35+
>
36+
<
37+
script
38+
src
39+
=
40+
"
41+
/
42+
resources
43+
/
44+
testharnessreport
45+
.
46+
js
47+
"
48+
>
49+
<
50+
/
51+
script
52+
>
53+
<
54+
script
55+
src
56+
=
57+
"
58+
resources
59+
/
60+
test
61+
-
62+
helpers
63+
.
64+
sub
65+
.
66+
js
67+
"
68+
>
69+
<
70+
/
71+
script
72+
>
73+
<
74+
script
75+
>
76+
var
77+
scope
78+
=
79+
'
80+
resources
81+
/
82+
clients
83+
-
84+
frame
85+
-
86+
freeze
87+
.
88+
html
89+
'
90+
;
91+
var
92+
windows
93+
=
94+
[
95+
]
96+
;
97+
var
98+
expected_window_1
99+
=
100+
{
101+
visibilityState
102+
:
103+
'
104+
visible
105+
'
106+
focused
107+
:
108+
false
109+
lifecycleState
110+
:
111+
"
112+
frozen
113+
"
114+
url
115+
:
116+
new
117+
URL
118+
(
119+
scope
120+
+
121+
'
122+
#
123+
1
124+
'
125+
location
126+
)
127+
.
128+
toString
129+
(
130+
)
131+
type
132+
:
133+
'
134+
window
135+
'
136+
frameType
137+
:
138+
'
139+
top
140+
-
141+
level
142+
'
143+
}
144+
;
145+
var
146+
expected_window_2
147+
=
148+
{
149+
visibilityState
150+
:
151+
'
152+
visible
153+
'
154+
focused
155+
:
156+
false
157+
lifecycleState
158+
:
159+
"
160+
active
161+
"
162+
url
163+
:
164+
new
165+
URL
166+
(
167+
scope
168+
+
169+
'
170+
#
171+
2
172+
'
173+
location
174+
)
175+
.
176+
toString
177+
(
178+
)
179+
type
180+
:
181+
'
182+
window
183+
'
184+
frameType
185+
:
186+
'
187+
top
188+
-
189+
level
190+
'
191+
}
192+
;
193+
function
194+
with_window
195+
(
196+
url
197+
name
198+
)
199+
{
200+
return
201+
new
202+
Promise
203+
(
204+
function
205+
(
206+
resolve
207+
)
208+
{
209+
var
210+
child
211+
=
212+
window
213+
.
214+
open
215+
(
216+
url
217+
name
218+
)
219+
;
220+
window
221+
.
222+
onmessage
223+
=
224+
(
225+
)
226+
=
227+
>
228+
{
229+
resolve
230+
(
231+
child
232+
)
233+
}
234+
;
235+
}
236+
)
237+
;
238+
}
239+
promise_test
240+
(
241+
function
242+
(
243+
t
244+
)
245+
{
246+
return
247+
service_worker_unregister_and_register
248+
(
249+
t
250+
'
251+
resources
252+
/
253+
clients
254+
-
255+
matchall
256+
-
257+
worker
258+
.
259+
js
260+
'
261+
scope
262+
)
263+
.
264+
then
265+
(
266+
function
267+
(
268+
registration
269+
)
270+
{
271+
t
272+
.
273+
add_cleanup
274+
(
275+
function
276+
(
277+
)
278+
{
279+
return
280+
service_worker_unregister
281+
(
282+
t
283+
scope
284+
)
285+
;
286+
}
287+
)
288+
;
289+
return
290+
wait_for_state
291+
(
292+
t
293+
registration
294+
.
295+
installing
296+
'
297+
activated
298+
'
299+
)
300+
;
301+
}
302+
)
303+
.
304+
then
305+
(
306+
function
307+
(
308+
)
309+
{
310+
return
311+
with_window
312+
(
313+
scope
314+
+
315+
'
316+
#
317+
1
318+
'
319+
'
320+
Child
321+
1
322+
'
323+
)
324+
;
325+
}
326+
)
327+
.
328+
then
329+
(
330+
function
331+
(
332+
window1
333+
)
334+
{
335+
windows
336+
.
337+
push
338+
(
339+
window1
340+
)
341+
;
342+
return
343+
with_window
344+
(
345+
scope
346+
+
347+
'
348+
#
349+
2
350+
'
351+
'
352+
Child
353+
2
354+
'
355+
)
356+
;
357+
}
358+
)
359+
.
360+
then
361+
(
362+
function
363+
(
364+
window2
365+
)
366+
{
367+
windows
368+
.
369+
push
370+
(
371+
window2
372+
)
373+
;
374+
return
375+
new
376+
Promise
377+
(
378+
function
379+
(
380+
resolve
381+
)
382+
{
383+
window
384+
.
385+
onmessage
386+
=
387+
resolve
388+
;
389+
windows
390+
[
391+
0
392+
]
393+
.
394+
postMessage
395+
(
396+
'
397+
freeze
398+
'
399+
)
400+
;
401+
}
402+
)
403+
;
404+
}
405+
)
406+
.
407+
then
408+
(
409+
function
410+
(
411+
)
412+
{
413+
var
414+
channel
415+
=
416+
new
417+
MessageChannel
418+
(
419+
)
420+
;
421+
return
422+
new
423+
Promise
424+
(
425+
function
426+
(
427+
resolve
428+
)
429+
{
430+
channel
431+
.
432+
port1
433+
.
434+
onmessage
435+
=
436+
resolve
437+
;
438+
windows
439+
[
440+
1
441+
]
442+
.
443+
navigator
444+
.
445+
serviceWorker
446+
.
447+
controller
448+
.
449+
postMessage
450+
(
451+
{
452+
port
453+
:
454+
channel
455+
.
456+
port2
457+
includeLifecycleState
458+
:
459+
true
460+
}
461+
[
462+
channel
463+
.
464+
port2
465+
]
466+
)
467+
;
468+
}
469+
)
470+
;
471+
}
472+
)
473+
.
474+
then
475+
(
476+
function
477+
(
478+
e
479+
)
480+
{
481+
assert_equals
482+
(
483+
e
484+
.
485+
data
486+
.
487+
length
488+
1
489+
)
490+
;
491+
assert_object_equals
492+
(
493+
e
494+
.
495+
data
496+
[
497+
0
498+
]
499+
expected_window_2
500+
)
501+
;
502+
}
503+
)
504+
.
505+
then
506+
(
507+
function
508+
(
509+
)
510+
{
511+
var
512+
channel
513+
=
514+
new
515+
MessageChannel
516+
(
517+
)
518+
;
519+
return
520+
new
521+
Promise
522+
(
523+
function
524+
(
525+
resolve
526+
)
527+
{
528+
channel
529+
.
530+
port1
531+
.
532+
onmessage
533+
=
534+
resolve
535+
;
536+
windows
537+
[
538+
1
539+
]
540+
.
541+
navigator
542+
.
543+
serviceWorker
544+
.
545+
controller
546+
.
547+
postMessage
548+
(
549+
{
550+
port
551+
:
552+
channel
553+
.
554+
port2
555+
options
556+
:
557+
{
558+
lifecycleState
559+
:
560+
"
561+
all
562+
"
563+
}
564+
includeLifecycleState
565+
:
566+
true
567+
}
568+
[
569+
channel
570+
.
571+
port2
572+
]
573+
)
574+
;
575+
}
576+
)
577+
;
578+
}
579+
)
580+
.
581+
then
582+
(
583+
function
584+
(
585+
e
586+
)
587+
{
588+
assert_equals
589+
(
590+
e
591+
.
592+
data
593+
.
594+
length
595+
2
596+
)
597+
;
598+
/
599+
/
600+
No
601+
specific
602+
order
603+
is
604+
required
605+
so
606+
support
607+
inversion
608+
.
609+
if
610+
(
611+
e
612+
.
613+
data
614+
[
615+
0
616+
]
617+
[
618+
3
619+
]
620+
=
621+
=
622+
new
623+
URL
624+
(
625+
scope
626+
+
627+
'
628+
#
629+
2
630+
'
631+
location
632+
)
633+
)
634+
{
635+
assert_object_equals
636+
(
637+
e
638+
.
639+
data
640+
[
641+
0
642+
]
643+
expected_window_2
644+
)
645+
;
646+
assert_object_equals
647+
(
648+
e
649+
.
650+
data
651+
[
652+
1
653+
]
654+
expected_window_1
655+
)
656+
;
657+
}
658+
else
659+
{
660+
assert_object_equals
661+
(
662+
e
663+
.
664+
data
665+
[
666+
0
667+
]
668+
expected_window_1
669+
)
670+
;
671+
assert_object_equals
672+
(
673+
e
674+
.
675+
data
676+
[
677+
1
678+
]
679+
expected_window_2
680+
)
681+
;
682+
}
683+
}
684+
)
685+
.
686+
then
687+
(
688+
function
689+
(
690+
)
691+
{
692+
var
693+
channel
694+
=
695+
new
696+
MessageChannel
697+
(
698+
)
699+
;
700+
return
701+
new
702+
Promise
703+
(
704+
function
705+
(
706+
resolve
707+
)
708+
{
709+
channel
710+
.
711+
port1
712+
.
713+
onmessage
714+
=
715+
resolve
716+
;
717+
windows
718+
[
719+
1
720+
]
721+
.
722+
navigator
723+
.
724+
serviceWorker
725+
.
726+
controller
727+
.
728+
postMessage
729+
(
730+
{
731+
port
732+
:
733+
channel
734+
.
735+
port2
736+
options
737+
:
738+
{
739+
lifecycleState
740+
:
741+
"
742+
frozen
743+
"
744+
}
745+
includeLifecycleState
746+
:
747+
true
748+
}
749+
[
750+
channel
751+
.
752+
port2
753+
]
754+
)
755+
;
756+
}
757+
)
758+
;
759+
}
760+
)
761+
.
762+
then
763+
(
764+
function
765+
(
766+
e
767+
)
768+
{
769+
assert_equals
770+
(
771+
e
772+
.
773+
data
774+
.
775+
length
776+
1
777+
)
778+
;
779+
assert_object_equals
780+
(
781+
e
782+
.
783+
data
784+
[
785+
0
786+
]
787+
expected_window_1
788+
)
789+
;
790+
}
791+
)
792+
.
793+
then
794+
(
795+
function
796+
(
797+
)
798+
{
799+
var
800+
channel
801+
=
802+
new
803+
MessageChannel
804+
(
805+
)
806+
;
807+
return
808+
new
809+
Promise
810+
(
811+
function
812+
(
813+
resolve
814+
)
815+
{
816+
channel
817+
.
818+
port1
819+
.
820+
onmessage
821+
=
822+
resolve
823+
;
824+
windows
825+
[
826+
1
827+
]
828+
.
829+
navigator
830+
.
831+
serviceWorker
832+
.
833+
controller
834+
.
835+
postMessage
836+
(
837+
{
838+
port
839+
:
840+
channel
841+
.
842+
port2
843+
options
844+
:
845+
{
846+
lifecycleState
847+
:
848+
"
849+
active
850+
"
851+
}
852+
includeLifecycleState
853+
:
854+
true
855+
}
856+
[
857+
channel
858+
.
859+
port2
860+
]
861+
)
862+
;
863+
}
864+
)
865+
;
866+
}
867+
)
868+
.
869+
then
870+
(
871+
function
872+
(
873+
e
874+
)
875+
{
876+
assert_equals
877+
(
878+
e
879+
.
880+
data
881+
.
882+
length
883+
1
884+
)
885+
;
886+
assert_object_equals
887+
(
888+
e
889+
.
890+
data
891+
[
892+
0
893+
]
894+
expected_window_2
895+
)
896+
;
897+
}
898+
)
899+
;
900+
}
901+
'
902+
Test
903+
Clients
904+
.
905+
matchAll
906+
(
907+
)
908+
'
909+
)
910+
;
911+
<
912+
/
913+
script
914+
>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
<
2+
!
3+
DOCTYPE
4+
html
5+
>
6+
<
7+
script
8+
src
9+
=
10+
"
11+
/
12+
resources
13+
/
14+
testdriver
15+
.
16+
js
17+
"
18+
>
19+
<
20+
/
21+
script
22+
>
23+
<
24+
script
25+
src
26+
=
27+
"
28+
/
29+
resources
30+
/
31+
testdriver
32+
-
33+
vendor
34+
.
35+
js
36+
"
37+
>
38+
<
39+
/
40+
script
41+
>
42+
<
43+
script
44+
>
45+
document
46+
.
47+
addEventListener
48+
(
49+
'
50+
freeze
51+
'
52+
(
53+
)
54+
=
55+
>
56+
{
57+
opener
58+
.
59+
postMessage
60+
(
61+
'
62+
frozen
63+
'
64+
"
65+
*
66+
"
67+
)
68+
;
69+
}
70+
)
71+
;
72+
window
73+
.
74+
onmessage
75+
=
76+
(
77+
e
78+
)
79+
=
80+
>
81+
{
82+
if
83+
(
84+
e
85+
.
86+
data
87+
=
88+
=
89+
'
90+
freeze
91+
'
92+
)
93+
{
94+
test_driver
95+
.
96+
freeze
97+
(
98+
)
99+
;
100+
}
101+
}
102+
;
103+
opener
104+
.
105+
postMessage
106+
(
107+
'
108+
loaded
109+
'
110+
'
111+
*
112+
'
113+
)
114+
;
115+
<
116+
/
117+
script
118+
>

‎testing/web-platform/tests/service-workers/service-worker/resources/clients-matchall-worker.js

+49
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,54 @@ level
146146
'
147147
;
148148
}
149+
if
150+
(
151+
e
152+
.
153+
data
154+
.
155+
includeLifecycleState
156+
)
157+
{
158+
message
159+
.
160+
push
161+
(
162+
{
163+
visibilityState
164+
:
165+
client
166+
.
167+
visibilityState
168+
focused
169+
:
170+
client
171+
.
172+
focused
173+
url
174+
:
175+
client
176+
.
177+
url
178+
lifecycleState
179+
:
180+
client
181+
.
182+
lifecycleState
183+
type
184+
:
185+
client
186+
.
187+
type
188+
frameType
189+
:
190+
frame_type
191+
}
192+
)
193+
;
194+
}
195+
else
196+
{
149197
message
150198
.
151199
push
@@ -168,6 +216,7 @@ frame_type
168216
)
169217
;
170218
}
219+
}
171220
)
172221
;
173222
/

0 commit comments

Comments
 (0)
Please sign in to comment.