From 9e9aa468cf45ccaf618a5cb6e5a145a4a696d0fc Mon Sep 17 00:00:00 2001 From: Marco Castelluccio Date: Wed, 10 Mar 2021 18:28:32 +0000 Subject: [PATCH] Bug 1688827 [wpt PR 27325] - Test cases where request body gets used before network fallback, a=testonly Automatic update from web-platform-tests Test cases where request body gets used before network fallback (#27325) Tests for whatwg/fetch#1144 and w3c/ServiceWorker#1563. Co-authored-by: Yutaka Hirano Co-authored-by: Anne van Kesteren -- wpt-commits: c30545df6a50c61f3673ed952c78c0a607100d45 wpt-pr: 27325 UltraBlame original commit: 02b382fb279e8edb2435787d95fd519f036320b3 --- .../service-worker/fetch-event.https.html | 4447 ++++++++++++----- .../resources/fetch-event-test-worker.js | 78 + 2 files changed, 3263 insertions(+), 1262 deletions(-) diff --git a/testing/web-platform/tests/service-workers/service-worker/fetch-event.https.html b/testing/web-platform/tests/service-workers/service-worker/fetch-event.https.html index 661e3a8d7385c..383e15a1fafe3 100644 --- a/testing/web-platform/tests/service-workers/service-worker/fetch-event.https.html +++ b/testing/web-platform/tests/service-workers/service-worker/fetch-event.https.html @@ -3979,35 +3979,99 @@ Test that the -service -worker -can -read -FetchEvent -# +request body -when -it is -a -blob -. +sent +to +network +upon +network +fallback / / -It -responds -with -request +for +a +ReadableStream body -it -read . promise_test ( +async +t += +> +{ +const +rs += +new +ReadableStream +( +{ +start +( +c +) +{ +c +. +enqueue +( +' +i +a +' +) +; +c +. +enqueue +( +' +m +the +request +' +) +; +t +. +step_timeout +( t +. +step_func +( +( +) = > { +c +. +enqueue +( +' +body +' +) +; +c +. +close +( +) +; +} +10 +) +) +; +} +} +) +; / / Set @@ -4051,9 +4115,6 @@ ' resources / -simple -. -html ? ignore - @@ -4063,27 +4124,19 @@ - body - -blob +fallback +- +string ' ; -let +const frame -; -return += +await with_iframe ( page_url ) -. -then -( -f -= -> -{ -frame -= -f ; t . @@ -4103,49 +4156,57 @@ } ) ; +/ +/ +Add +" +? +ignore +" +so +the +service +worker +falls +back +to +echo +- +content +. +py +. const -blob +echo_url = -new -Blob -( -[ -' -it -\ -' -s -me -the -blob -' ' +/ +fetch +/ +api +/ +resources +/ +echo +- +content +. +py +? +ignore ' -' -and -more -blob -! -' -] -) ; -return +const +response += +await frame . contentWindow . fetch ( -' -simple -. -html -? -request -- -body -' +echo_url { method : @@ -4154,64 +4215,57 @@ ' body : -blob +rs } ) ; -} -) -. -then -( -response +const +text = -> -{ -return +await response . text ( ) ; -} -) -. -then -( -response_text -= -> -{ assert_equals ( -response_text +text +' +i +am +the +request +body ' -it -\ ' -s -me the -blob -and -more -blob -! +network +fallback +request +should +include +the +request +body ' ) ; } -) -; -} ' FetchEvent # body is a -blob +ReadableStream +and +is +passed +to +network +fallback ' ) ; @@ -4229,15 +4283,27 @@ upon network fallback +even +when / / -for -a -blob +the +request +body +is +used +in +the +service +worker +for +a +string body . promise_test ( +async t = > @@ -4285,9 +4351,6 @@ ' resources / -simple -. -html ? ignore - @@ -4299,27 +4362,17 @@ - fallback - -blob +string ' ; -let +const frame -; -return += +await with_iframe ( page_url ) -. -then -( -f -= -> -{ -frame -= -f ; t . @@ -4339,38 +4392,15 @@ } ) ; -const -blob -= -new -Blob -( -[ -' -it -\ -' -s -me -the -blob -' -' -' -' -and -more -blob -! -' -] -) -; / / Add " ? +use +- +and +- ignore " so @@ -4403,10 +4433,17 @@ . py ? +use +- +and +- ignore ' ; -return +const +response += +await frame . contentWindow @@ -4422,50 +4459,35 @@ ' body : -blob +' +i +am +the +request +body +' } ) ; -} -) -. -then -( -response +const +text = -> -{ -return +await response . text ( ) ; -} -) -. -then -( -response_text -= -> -{ assert_equals ( -response_text -' -it -\ +text ' -s -me +i +am the -blob -and -more -blob -! +request +body ' ' the @@ -4481,18 +4503,15 @@ ) ; } -) -; -} ' FetchEvent # body is a -blob +string +used and -is passed to network @@ -4500,141 +4519,156 @@ ' ) ; +/ +/ +When +the +streaming +body +is +used +in +the +service +worker +network +fallback +/ +/ +fails +. promise_test ( async -( t -) = > { const -page_url +rs = -' -resources -/ -simple +new +ReadableStream +( +{ +start +( +c +) +{ +c . -html -? -keepalive +enqueue +( +' +i +a ' +) ; -const -frame -= -await -with_iframe +c +. +enqueue ( -page_url +' +m +the +request +' ) ; t . -add_cleanup +step_timeout +( +t +. +step_func ( ( ) = > { -frame +c . -remove -( -) -; -} -) -; -assert_equals +enqueue ( -frame -. -contentDocument -. -body -. -textContent ' -false +body ' ) ; -const -response -= -await -frame -. -contentWindow +c . -fetch +close ( -page_url -{ -keepalive -: -true -} ) ; -const -text -= -await -response -. -text -( +} +10 ) -; -assert_equals -( -text -' -true -' ) ; } -' -Service -Worker -responds -to -fetch -event -with -the -correct -keepalive -value -' +} ) ; -promise_test -( -async -( -t -) -= -> -{ +/ +/ +Set +page_url +to +" +? +ignore +" +so +the +service +worker +falls +back +to +network +/ +/ +for +the +main +resource +request +and +add +a +suffix +to +avoid +colliding +/ +/ +with +other +tests +. const page_url = ' resources / -simple -. -html ? -isReloadNavigation +ignore +- +for +- +request +- +body +- +fallback +- +string ' ; const @@ -4664,116 +4698,169 @@ } ) ; -assert_equals -( -frame -. -contentDocument -. -body -. -textContent -' -method -= -GET -isReloadNavigation +const +echo_url = -false ' -) -; -await -new -Promise -( -( -resolve -) -= -> -{ -frame +/ +fetch +/ +api +/ +resources +/ +echo +- +content . -addEventListener -( -' -load +py +? +use +- +and +- +ignore ' -resolve -) ; +await +promise_rejects_js +( +t +TypeError frame . contentWindow . -location -. -reload -( -) -; -} -) -; -assert_equals +fetch ( -frame -. -contentDocument -. -body -. -textContent -' +echo_url +{ method -= -GET -isReloadNavigation -= -true +: +' +POST ' +body +: +rs +} ) ; } ' FetchEvent # -request -. -isReloadNavigation +body is -true -( -location -. -reload -( -) -) +a +ReadableStream +used +and +passed +to +network +fallback ' ) ; +/ +/ +Test +that +the +request +body +is +sent +to +network +upon +network +fallback +even +when +/ +/ +the +request +body +is +used +by +clone +( +) +in +the +service +worker +for +a +string +body +. promise_test ( async -( t -) = > { +/ +/ +Set +page_url +to +" +? +ignore +" +so +the +service +worker +falls +back +to +network +/ +/ +for +the +main +resource +request +and +add +a +suffix +to +avoid +colliding +/ +/ +with +other +tests +. const page_url = ' resources / -simple -. -html ? -isReloadNavigation +ignore +- +for +- +request +- +body +- +fallback +- +string ' ; const @@ -4803,7 +4890,1829 @@ } ) ; -assert_equals +/ +/ +Add +" +? +clone +- +and +- +ignore +" +so +the +service +worker +falls +back +to +/ +/ +echo +- +content +. +py +. +const +echo_url += +' +/ +fetch +/ +api +/ +resources +/ +echo +- +content +. +py +? +clone +- +and +- +ignore +' +; +const +response += +await +frame +. +contentWindow +. +fetch +( +echo_url +{ +method +: +' +POST +' +body +: +' +i +am +the +request +body +' +} +) +; +const +text += +await +response +. +text +( +) +; +assert_equals +( +text +' +i +am +the +request +body +' +' +the +network +fallback +request +should +include +the +request +body +' +) +; +} +' +FetchEvent +# +body +is +a +string +cloned +and +passed +to +network +fallback +' +) +; +/ +/ +When +the +streaming +body +is +used +by +clone +( +) +in +the +service +worker +network +/ +/ +fallback +fails +. +promise_test +( +async +t += +> +{ +const +rs += +new +ReadableStream +( +{ +start +( +c +) +{ +c +. +enqueue +( +' +i +a +' +) +; +c +. +enqueue +( +' +m +the +request +' +) +; +t +. +step_timeout +( +t +. +step_func +( +( +) += +> +{ +c +. +enqueue +( +' +body +' +) +; +c +. +close +( +) +; +} +10 +) +) +; +} +} +) +; +/ +/ +Set +page_url +to +" +? +ignore +" +so +the +service +worker +falls +back +to +network +/ +/ +for +the +main +resource +request +and +add +a +suffix +to +avoid +colliding +/ +/ +with +other +tests +. +const +page_url += +' +resources +/ +? +ignore +- +for +- +request +- +body +- +fallback +- +string +' +; +const +frame += +await +with_iframe +( +page_url +) +; +t +. +add_cleanup +( +( +) += +> +{ +frame +. +remove +( +) +; +} +) +; +/ +/ +Add +" +? +clone +- +and +- +ignore +" +so +the +service +worker +falls +back +to +/ +/ +echo +- +content +. +py +. +const +echo_url += +' +/ +fetch +/ +api +/ +resources +/ +echo +- +content +. +py +? +clone +- +and +- +ignore +' +; +const +response += +await +frame +. +contentWindow +. +fetch +( +echo_url +{ +method +: +' +POST +' +body +: +' +i +am +the +request +body +' +} +) +; +const +text += +await +response +. +text +( +) +; +assert_equals +( +text +' +i +am +the +request +body +' +' +the +network +fallback +request +should +include +the +request +body +' +) +; +} +' +FetchEvent +# +body +is +a +ReadableStream +cloned +and +passed +to +network +fallback +' +) +; +/ +/ +Test +that +the +service +worker +can +read +FetchEvent +# +body +when +it +is +a +blob +. +/ +/ +It +responds +with +request +body +it +read +. +promise_test +( +t += +> +{ +/ +/ +Set +page_url +to +" +? +ignore +" +so +the +service +worker +falls +back +to +network +/ +/ +for +the +main +resource +request +and +add +a +suffix +to +avoid +colliding +/ +/ +with +other +tests +. +const +page_url += +' +resources +/ +simple +. +html +? +ignore +- +for +- +request +- +body +- +blob +' +; +let +frame +; +return +with_iframe +( +page_url +) +. +then +( +f += +> +{ +frame += +f +; +t +. +add_cleanup +( +( +) += +> +{ +frame +. +remove +( +) +; +} +) +; +const +blob += +new +Blob +( +[ +' +it +\ +' +s +me +the +blob +' +' +' +' +and +more +blob +! +' +] +) +; +return +frame +. +contentWindow +. +fetch +( +' +simple +. +html +? +request +- +body +' +{ +method +: +' +POST +' +body +: +blob +} +) +; +} +) +. +then +( +response += +> +{ +return +response +. +text +( +) +; +} +) +. +then +( +response_text += +> +{ +assert_equals +( +response_text +' +it +\ +' +s +me +the +blob +and +more +blob +! +' +) +; +} +) +; +} +' +FetchEvent +# +body +is +a +blob +' +) +; +/ +/ +Test +that +the +request +body +is +sent +to +network +upon +network +fallback +/ +/ +for +a +blob +body +. +promise_test +( +t += +> +{ +/ +/ +Set +page_url +to +" +? +ignore +" +so +the +service +worker +falls +back +to +network +/ +/ +for +the +main +resource +request +and +add +a +suffix +to +avoid +colliding +/ +/ +with +other +tests +. +const +page_url += +' +resources +/ +simple +. +html +? +ignore +- +for +- +request +- +body +- +fallback +- +blob +' +; +let +frame +; +return +with_iframe +( +page_url +) +. +then +( +f += +> +{ +frame += +f +; +t +. +add_cleanup +( +( +) += +> +{ +frame +. +remove +( +) +; +} +) +; +const +blob += +new +Blob +( +[ +' +it +\ +' +s +me +the +blob +' +' +' +' +and +more +blob +! +' +] +) +; +/ +/ +Add +" +? +ignore +" +so +the +service +worker +falls +back +to +echo +- +content +. +py +. +const +echo_url += +' +/ +fetch +/ +api +/ +resources +/ +echo +- +content +. +py +? +ignore +' +; +return +frame +. +contentWindow +. +fetch +( +echo_url +{ +method +: +' +POST +' +body +: +blob +} +) +; +} +) +. +then +( +response += +> +{ +return +response +. +text +( +) +; +} +) +. +then +( +response_text += +> +{ +assert_equals +( +response_text +' +it +\ +' +s +me +the +blob +and +more +blob +! +' +' +the +network +fallback +request +should +include +the +request +body +' +) +; +} +) +; +} +' +FetchEvent +# +body +is +a +blob +and +is +passed +to +network +fallback +' +) +; +promise_test +( +async +( +t +) += +> +{ +const +page_url += +' +resources +/ +simple +. +html +? +keepalive +' +; +const +frame += +await +with_iframe +( +page_url +) +; +t +. +add_cleanup +( +( +) += +> +{ +frame +. +remove +( +) +; +} +) +; +assert_equals +( +frame +. +contentDocument +. +body +. +textContent +' +false +' +) +; +const +response += +await +frame +. +contentWindow +. +fetch +( +page_url +{ +keepalive +: +true +} +) +; +const +text += +await +response +. +text +( +) +; +assert_equals +( +text +' +true +' +) +; +} +' +Service +Worker +responds +to +fetch +event +with +the +correct +keepalive +value +' +) +; +promise_test +( +async +( +t +) += +> +{ +const +page_url += +' +resources +/ +simple +. +html +? +isReloadNavigation +' +; +const +frame += +await +with_iframe +( +page_url +) +; +t +. +add_cleanup +( +( +) += +> +{ +frame +. +remove +( +) +; +} +) +; +assert_equals +( +frame +. +contentDocument +. +body +. +textContent +' +method += +GET +isReloadNavigation += +false +' +) +; +await +new +Promise +( +( +resolve +) += +> +{ +frame +. +addEventListener +( +' +load +' +resolve +) +; +frame +. +contentWindow +. +location +. +reload +( +) +; +} +) +; +assert_equals +( +frame +. +contentDocument +. +body +. +textContent +' +method += +GET +isReloadNavigation += +true +' +) +; +} +' +FetchEvent +# +request +. +isReloadNavigation +is +true +( +location +. +reload +( +) +) +' +) +; +promise_test +( +async +( +t +) += +> +{ +const +page_url += +' +resources +/ +simple +. +html +? +isReloadNavigation +' +; +const +frame += +await +with_iframe +( +page_url +) +; +t +. +add_cleanup +( +( +) += +> +{ +frame +. +remove +( +) +; +} +) +; +assert_equals +( +frame +. +contentDocument +. +body +. +textContent +' +method += +GET +isReloadNavigation += +false +' +) +; +await +new +Promise +( +( +resolve +) += +> +{ +frame +. +addEventListener +( +' +load +' +resolve +) +; +frame +. +contentWindow +. +history +. +go +( +0 +) +; +} +) +; +assert_equals +( +frame +. +contentDocument +. +body +. +textContent +' +method += +GET +isReloadNavigation += +true +' +) +; +} +' +FetchEvent +# +request +. +isReloadNavigation +is +true +( +history +. +go +( +0 +) +) +' +) +; +promise_test +( +async +( +t +) += +> +{ +const +page_url += +' +resources +/ +simple +. +html +? +isReloadNavigation +' +; +const +frame += +await +with_iframe +( +page_url +) +; +t +. +add_cleanup +( +( +) += +> +{ +frame +. +remove +( +) +; +} +) +; +assert_equals +( +frame +. +contentDocument +. +body +. +textContent +' +method += +GET +isReloadNavigation += +false +' +) +; +await +new +Promise +( +( +resolve +) += +> +{ +frame +. +addEventListener +( +' +load +' +resolve +) +; +const +form += +frame +. +contentDocument +. +createElement +( +' +form +' +) +; +form +. +method += +' +POST +' +; +form +. +name += +' +form +' +; +form +. +action += +new +Request +( +page_url +) +. +url +; +frame +. +contentDocument +. +body +. +appendChild +( +form +) +; +form +. +submit +( +) +; +} +) +; +assert_equals +( +frame +. +contentDocument +. +body +. +textContent +' +method += +POST +isReloadNavigation += +false +' +) +; +await +new +Promise +( +( +resolve +) += +> +{ +frame +. +addEventListener +( +' +load +' +resolve +) +; +frame +. +contentWindow +. +location +. +reload +( +) +; +} +) +; +assert_equals +( +frame +. +contentDocument +. +body +. +textContent +' +method += +POST +isReloadNavigation += +true +' +) +; +} +' +FetchEvent +# +request +. +isReloadNavigation +is +true +( +POST ++ +location +. +reload +( +) +) +' +) +; +promise_test +( +async +( +t +) += +> +{ +const +page_url += +' +resources +/ +simple +. +html +? +isReloadNavigation +' +; +const +anotherUrl += +new +Request +( +' +resources +/ +simple +. +html +' +) +. +url +; +let +frame += +await +with_iframe +( +page_url +) +; +t +. +add_cleanup +( +( +) += +> +{ +frame +. +remove +( +) +; +} +) +; +assert_equals +( +frame +. +contentDocument +. +body +. +textContent +' +method += +GET +isReloadNavigation += +false +' +) +; +/ +/ +Use +step_timeout +( +0 +) +to +ensure +the +history +entry +is +created +for +Blink +/ +/ +and +WebKit +. +See +https +: +/ +/ +bugs +. +webkit +. +org +/ +show_bug +. +cgi +? +id += +42861 +. +await +wait +( +0 +) +; +await +new +Promise +( +( +resolve +) += +> +{ +frame +. +addEventListener +( +' +load +' +resolve +) +; +frame +. +src += +anotherUrl +; +} +) +; +assert_equals +( +frame +. +contentDocument +. +body +. +textContent +" +Here +' +s +a +simple +html +file +. +\ +n +" +) +; +await +new +Promise +( +( +resolve +) += +> +{ +frame +. +addEventListener +( +' +load +' +resolve +) +; +frame +. +contentWindow +. +history +. +go +( +- +1 +) +; +} +) +; +assert_equals ( frame . @@ -4875,6 +6784,63 @@ ' ) ; +await +new +Promise +( +( +resolve +) += +> +{ +frame +. +addEventListener +( +' +load +' +resolve +) +; +frame +. +contentWindow +. +history +. +go +( +1 +) +; +} +) +; +assert_equals +( +frame +. +contentDocument +. +body +. +textContent +" +Here +' +s +a +simple +html +file +. +\ +n +" +) +; } ' FetchEvent @@ -4885,12 +6851,9 @@ is true ( +with history -. -go -( -0 -) +traversal ) ' ) @@ -4914,8 +6877,27 @@ . html ? -isReloadNavigation +isHistoryNavigation +' +; +const +anotherUrl += +new +Request +( +' +resources +/ +simple +. +html +? +ignore ' +) +. +url ; const frame @@ -4957,12 +6939,58 @@ method = GET -isReloadNavigation +isHistoryNavigation = false ' ) ; +/ +/ +Use +step_timeout +( +0 +) +to +ensure +the +history +entry +is +created +for +Blink +/ +/ +and +WebKit +. +See +https +: +/ +/ +bugs +. +webkit +. +org +/ +show_bug +. +cgi +? +id += +42861 +. +await +wait +( +0 +) +; await new Promise @@ -4983,64 +7011,11 @@ resolve ) ; -const -form -= frame . -contentDocument -. -createElement -( -' -form -' -) -; -form -. -method -= -' -POST -' -; -form -. -name -= -' -form -' -; -form -. -action +src = -new -Request -( -page_url -) -. -url -; -frame -. -contentDocument -. -body -. -appendChild -( -form -) -; -form -. -submit -( -) +anotherUrl ; } ) @@ -5054,14 +7029,18 @@ body . textContent +" +Here ' -method -= -POST -isReloadNavigation -= -false -' +s +a +simple +html +file +. +\ +n +" ) ; await @@ -5088,10 +7067,12 @@ . contentWindow . -location +history . -reload +go ( +- +1 ) ; } @@ -5109,8 +7090,8 @@ ' method = -POST -isReloadNavigation +GET +isHistoryNavigation = true ' @@ -5122,16 +7103,17 @@ # request . -isReloadNavigation +isHistoryNavigation is true -( -POST -+ -location +( +with +history . -reload +go ( +- +1 ) ) ' @@ -5156,7 +7138,7 @@ . html ? -isReloadNavigation +isHistoryNavigation ' ; const @@ -5171,18 +7153,20 @@ simple . html +? +ignore ' ) . url ; -let +const frame = await with_iframe ( -page_url +anotherUrl ) ; t @@ -5212,14 +7196,18 @@ body . textContent +" +Here ' -method -= -GET -isReloadNavigation -= -false -' +s +a +simple +html +file +. +\ +n +" ) ; / @@ -5292,7 +7280,7 @@ . src = -anotherUrl +page_url ; } ) @@ -5306,18 +7294,14 @@ body . textContent -" -Here ' -s -a -simple -html -file -. -\ -n -" +method += +GET +isHistoryNavigation += +false +' ) ; await @@ -5355,25 +7339,6 @@ } ) ; -assert_equals -( -frame -. -contentDocument -. -body -. -textContent -' -method -= -GET -isReloadNavigation -= -false -' -) -; await new Promise @@ -5402,7 +7367,7 @@ . go ( -0 +1 ) ; } @@ -5421,82 +7386,29 @@ method = GET -isReloadNavigation +isHistoryNavigation = true ' ) ; -await -new -Promise -( -( -resolve -) -= -> -{ -frame -. -addEventListener -( -' -load -' -resolve -) -; -frame -. -contentWindow -. -history -. -go -( -1 -) -; -} -) -; -assert_equals -( -frame -. -contentDocument -. -body -. -textContent -" -Here -' -s -a -simple -html -file -. -\ -n -" -) -; } ' FetchEvent # request . -isReloadNavigation +isHistoryNavigation is true ( with history -traversal +. +go +( +1 +) ) ' ) @@ -5548,7 +7460,7 @@ await with_iframe ( -page_url +anotherUrl ) ; t @@ -5578,6 +7490,104 @@ body . textContent +" +Here +' +s +a +simple +html +file +. +\ +n +" +) +; +/ +/ +Use +step_timeout +( +0 +) +to +ensure +the +history +entry +is +created +for +Blink +/ +/ +and +WebKit +. +See +https +: +/ +/ +bugs +. +webkit +. +org +/ +show_bug +. +cgi +? +id += +42861 +. +await +wait +( +0 +) +; +await +new +Promise +( +( +resolve +) += +> +{ +frame +. +addEventListener +( +' +load +' +resolve +) +; +frame +. +src += +page_url +; +} +) +; +assert_equals +( +frame +. +contentDocument +. +body +. +textContent ' method = @@ -5588,50 +7598,39 @@ ' ) ; -/ -/ -Use -step_timeout -( -0 -) -to -ensure -the -history -entry -is -created -for -Blink -/ -/ -and -WebKit -. -See -https -: -/ -/ -bugs -. -webkit +await +new +Promise +( +( +resolve +) += +> +{ +frame +. +addEventListener +( +' +load +' +resolve +) +; +frame . -org -/ -show_bug +contentWindow . -cgi -? -id -= -42861 +history . -await -wait +go ( -0 +- +1 +) +; +} ) ; await @@ -5656,9 +7655,14 @@ ; frame . -src -= -anotherUrl +contentWindow +. +history +. +go +( +1 +) ; } ) @@ -5672,18 +7676,14 @@ body . textContent -" -Here ' -s -a -simple -html -file -. -\ -n -" +method += +GET +isHistoryNavigation += +true +' ) ; await @@ -5714,8 +7714,7 @@ . go ( -- -1 +0 ) ; } @@ -5736,7 +7735,7 @@ GET isHistoryNavigation = -true +false ' ) ; @@ -5748,15 +7747,14 @@ . isHistoryNavigation is -true +false ( with history . go ( -- -1 +0 ) ) ' @@ -6035,6 +8033,58 @@ ' ) ; +await +new +Promise +( +( +resolve +) += +> +{ +frame +. +addEventListener +( +' +load +' +resolve +) +; +frame +. +contentWindow +. +location +. +reload +( +) +; +} +) +; +assert_equals +( +frame +. +contentDocument +. +body +. +textContent +' +method += +GET +isHistoryNavigation += +false +' +) +; } ' FetchEvent @@ -6043,15 +8093,12 @@ . isHistoryNavigation is -true +false ( with -history +location . -go -( -1 -) +reload ) ' ) @@ -6098,12 +8145,31 @@ url ; const +oneAnotherUrl += +new +Request +( +' +resources +/ +simple +. +html +? +ignore2 +' +) +. +url +; +const frame = await with_iframe ( -anotherUrl +page_url ) ; t @@ -6133,18 +8199,14 @@ body . textContent -" -Here ' -s -a -simple -html -file -. -\ -n -" +method += +GET +isHistoryNavigation += +false +' ) ; / @@ -6217,7 +8279,7 @@ . src = -page_url +anotherUrl ; } ) @@ -6231,49 +8293,24 @@ body . textContent +" +Here ' -method -= -GET -isHistoryNavigation -= -false -' -) -; -await -new -Promise -( -( -resolve -) -= -> -{ -frame +s +a +simple +html +file . -addEventListener -( -' -load -' -resolve +\ +n +" ) ; -frame -. -contentWindow -. -history -. -go +await +wait ( -- -1 -) -; -} +0 ) ; await @@ -6298,14 +8335,9 @@ ; frame . -contentWindow -. -history -. -go -( -1 -) +src += +oneAnotherUrl ; } ) @@ -6319,14 +8351,18 @@ body . textContent +" +Here ' -method -= -GET -isHistoryNavigation -= -true -' +s +a +simple +html +file +. +\ +n +" ) ; await @@ -6357,7 +8393,8 @@ . go ( -0 +- +2 ) ; } @@ -6378,7 +8415,7 @@ GET isHistoryNavigation = -false +true ' ) ; @@ -6390,14 +8427,15 @@ . isHistoryNavigation is -false +true ( with history . go ( -0 +- +2 ) ) ' @@ -6445,6 +8483,25 @@ url ; const +oneAnotherUrl += +new +Request +( +' +resources +/ +simple +. +html +? +ignore2 +' +) +. +url +; +const frame = await @@ -6564,7 +8621,7 @@ . src = -page_url +oneAnotherUrl ; } ) @@ -6578,14 +8635,24 @@ body . textContent +" +Here ' -method -= -GET -isHistoryNavigation -= -false -' +s +a +simple +html +file +. +\ +n +" +) +; +await +wait +( +0 ) ; await @@ -6610,19 +8677,32 @@ ; frame . -contentWindow -. -history -. -go -( -- -1 -) +src += +page_url ; } ) ; +assert_equals +( +frame +. +contentDocument +. +body +. +textContent +' +method += +GET +isHistoryNavigation += +false +' +) +; await new Promise @@ -6651,31 +8731,13 @@ . go ( -1 +- +2 ) ; } ) ; -assert_equals -( -frame -. -contentDocument -. -body -. -textContent -' -method -= -GET -isHistoryNavigation -= -true -' -) -; await new Promise @@ -6700,10 +8762,11 @@ . contentWindow . -location +history . -reload +go ( +2 ) ; } @@ -6724,7 +8787,7 @@ GET isHistoryNavigation = -false +true ' ) ; @@ -6736,12 +8799,15 @@ . isHistoryNavigation is -false +true ( with -location +history . -reload +go +( +2 +) ) ' ) @@ -6788,45 +8854,127 @@ url ; const -oneAnotherUrl +frame = -new -Request +await +with_iframe ( -' -resources -/ -simple +page_url +) +; +t . -html -? -ignore2 +add_cleanup +( +( +) += +> +{ +frame +. +remove +( +) +; +} +) +; +assert_equals +( +frame +. +contentDocument +. +body +. +textContent +' +method += +GET +isHistoryNavigation += +false ' ) +; +await +new +Promise +( +( +resolve +) += +> +{ +frame . -url +addEventListener +( +' +load +' +resolve +) ; const +form += frame +. +contentDocument +. +createElement +( +' +form +' +) +; +form +. +method = -await -with_iframe +' +POST +' +; +form +. +name += +' +form +' +; +form +. +action += +new +Request ( page_url ) +. +url ; -t +frame . -add_cleanup -( +contentDocument +. +body +. +appendChild ( +form ) -= -> -{ -frame +; +form . -remove +submit ( ) ; @@ -6845,7 +8993,7 @@ ' method = -GET +POST isHistoryNavigation = false @@ -6978,58 +9126,6 @@ ; frame . -src -= -oneAnotherUrl -; -} -) -; -assert_equals -( -frame -. -contentDocument -. -body -. -textContent -" -Here -' -s -a -simple -html -file -. -\ -n -" -) -; -await -new -Promise -( -( -resolve -) -= -> -{ -frame -. -addEventListener -( -' -load -' -resolve -) -; -frame -. contentWindow . history @@ -7037,7 +9133,7 @@ go ( - -2 +1 ) ; } @@ -7055,7 +9151,7 @@ ' method = -GET +POST isHistoryNavigation = true @@ -7072,24 +9168,42 @@ is true ( -with +POST ++ history . go ( - -2 +1 ) ) ' ) ; +/ +/ +When +service +worker +responds +with +a +Response +no +XHR +upload +progress +/ +/ +events +are +delivered +. promise_test ( async -( t -) = > { @@ -7103,46 +9217,16 @@ . html ? -isHistoryNavigation -' -; -const -anotherUrl -= -new -Request -( -' -resources -/ -simple -. -html -? ignore +- +for +- +request +- +body +- +string ' -) -. -url -; -const -oneAnotherUrl -= -new -Request -( -' -resources -/ -simple -. -html -? -ignore2 -' -) -. -url ; const frame @@ -7150,7 +9234,7 @@ await with_iframe ( -anotherUrl +page_url ) ; t @@ -7171,214 +9255,161 @@ } ) ; -assert_equals -( -frame -. -contentDocument -. -body -. -textContent -" -Here -' -s -a -simple -html -file -. -\ -n -" -) -; -/ -/ -Use -step_timeout -( -0 -) -to -ensure -the -history -entry -is -created -for -Blink -/ -/ -and -WebKit -. -See -https -: -/ -/ -bugs -. -webkit -. -org -/ -show_bug -. -cgi -? -id +const +xhr = -42861 -. -await -wait -( -0 -) -; -await new -Promise -( -( -resolve -) -= -> -{ frame . -addEventListener +contentWindow +. +XMLHttpRequest ( -' -load -' -resolve ) ; -frame +xhr . -src -= -oneAnotherUrl -; -} -) -; -assert_equals +open ( -frame -. -contentDocument -. -body -. -textContent -" -Here ' -s -a -simple -html -file -. -\ -n -" -) -; -await -wait -( -0 +POST +' +' +simple +. +html +? +request +- +body +' ) ; -await -new -Promise +xhr +. +upload +. +addEventListener ( +' +progress +' +t +. +unreached_func ( -resolve +' +progress +' ) -= -> -{ -frame +) +; +xhr +. +upload . addEventListener ( ' -load +error ' -resolve -) -; -frame +t . -src -= -page_url -; -} +unreached_func +( +' +error +' +) ) ; -assert_equals -( -frame +xhr . -contentDocument +upload . -body +addEventListener +( +' +abort +' +t . -textContent +unreached_func +( ' -method -= -GET -isHistoryNavigation -= -false +abort ' ) +) ; -await -new -Promise +xhr +. +upload +. +addEventListener ( +' +timeout +' +t +. +unreached_func ( -resolve +' +timeout +' ) -= -> -{ -frame +) +; +xhr +. +upload . addEventListener ( ' load ' -resolve +t +. +unreached_func +( +' +load +' +) ) ; -frame +xhr . -contentWindow +upload . -history +addEventListener +( +' +loadend +' +t . -go +unreached_func ( -- -2 +' +loadend +' +) ) ; -} +xhr +. +send +( +' +i +am +the +request +body +' ) ; await @@ -7390,8 +9421,7 @@ ) = > -{ -frame +xhr . addEventListener ( @@ -7400,67 +9430,40 @@ ' resolve ) -; -frame -. -contentWindow -. -history -. -go -( -2 ) ; } -) -; -assert_equals -( -frame -. -contentDocument -. -body -. -textContent ' -method -= -GET -isHistoryNavigation -= -true +XHR +upload +progress +events +for +response +coming +from +SW ' ) ; -} -' -FetchEvent -# -request -. -isHistoryNavigation -is -true -( -with -history +/ +/ +Upload +progress +events +should +be +delivered +for +the +network +fallback +case . -go -( -2 -) -) -' -) -; promise_test ( async -( t -) = > { @@ -7474,27 +9477,16 @@ . html ? -isHistoryNavigation -' -; -const -anotherUrl -= -new -Request -( -' -resources -/ -simple -. -html -? ignore +- +for +- +request +- +body +- +string ' -) -. -url ; const frame @@ -7523,228 +9515,180 @@ } ) ; -assert_equals -( +let +progress += +false +; +let +load += +false +; +let +loadend += +false +; +const +xhr += +new frame . -contentDocument +contentWindow . -body +XMLHttpRequest +( +) +; +xhr . -textContent +open +( ' -method -= -GET -isHistoryNavigation -= -false +POST +' +' +/ +fetch +/ +api +/ +resources +/ +echo +- +content +. +py +? +ignore ' ) ; -await -new -Promise +xhr +. +upload +. +addEventListener ( +' +progress +' ( -resolve ) = > -{ -frame +progress += +true +) +; +xhr +. +upload . addEventListener ( ' -load +error ' -resolve -) -; -const -form -= -frame -. -contentDocument +t . -createElement +unreached_func ( ' -form +error ' ) +) ; -form +xhr . -method -= -' -POST -' -; -form +upload . -name -= +addEventListener +( ' -form +abort ' -; -form +t . -action -= -new -Request +unreached_func ( -page_url +' +abort +' +) ) -. -url ; -frame -. -contentDocument +xhr . -body +upload . -appendChild +addEventListener ( -form -) -; -form +' +timeout +' +t . -submit +unreached_func ( +' +timeout +' ) -; -} ) ; -assert_equals -( -frame -. -contentDocument +xhr . -body +upload . -textContent +addEventListener +( ' -method -= -POST -isHistoryNavigation -= -false +load ' -) -; -/ -/ -Use -step_timeout ( -0 ) -to -ensure -the -history -entry -is -created -for -Blink -/ -/ -and -WebKit -. -See -https -: -/ -/ -bugs -. -webkit -. -org -/ -show_bug -. -cgi -? -id = -42861 -. -await -wait -( -0 +> +load += +true ) ; -await -new -Promise -( -( -resolve -) -= -> -{ -frame +xhr +. +upload . addEventListener ( ' -load +loadend ' -resolve +( ) -; -frame -. -src = -anotherUrl -; -} +> +loadend += +true ) ; -assert_equals -( -frame -. -contentDocument +xhr . +send +( +' +i +am +the +request body -. -textContent -" -Here ' -s -a -simple -html -file -. -\ -n -" -) -; -await -wait -( -0 ) ; await @@ -7756,8 +9700,7 @@ ) = > -{ -frame +xhr . addEventListener ( @@ -7766,61 +9709,41 @@ ' resolve ) +) ; -frame -. -contentWindow -. -history -. -go +assert_true ( -- -1 +progress +' +progress +' ) ; -} +assert_true +( +load +' +load +' ) ; -assert_equals +assert_true ( -frame -. -contentDocument -. -body -. -textContent +loadend ' -method -= -POST -isHistoryNavigation -= -true +loadend ' ) ; } ' -FetchEvent -# -request -. -isHistoryNavigation -is -true -( -POST -+ -history -. -go -( -- -1 -) -) +XHR +upload +progress +events +for +network +fallback ' ) ; diff --git a/testing/web-platform/tests/service-workers/service-worker/resources/fetch-event-test-worker.js b/testing/web-platform/tests/service-workers/service-worker/resources/fetch-event-test-worker.js index f8895978a509d..3adbc25fae318 100644 --- a/testing/web-platform/tests/service-workers/service-worker/resources/fetch-event-test-worker.js +++ b/testing/web-platform/tests/service-workers/service-worker/resources/fetch-event-test-worker.js @@ -986,6 +986,54 @@ body ) ; } +function +handleUseAndIgnore +( +event +) +{ +const +request += +event +. +request +; +request +. +text +( +) +; +return +; +} +function +handleCloneAndIgnore +( +event +) +{ +const +request += +event +. +request +; +request +. +clone +( +) +. +text +( +) +; +return +; +} self . addEventListener @@ -1269,6 +1317,36 @@ fn : handleIsHistoryNavigation } +{ +pattern +: +' +? +use +- +and +- +ignore +' +fn +: +handleUseAndIgnore +} +{ +pattern +: +' +? +clone +- +and +- +ignore +' +fn +: +handleCloneAndIgnore +} ] ; var