From 932865b78c77621ff462676a693ce5b6e85e207b Mon Sep 17 00:00:00 2001 From: Marco Castelluccio Date: Thu, 3 Oct 2019 21:52:23 +0000 Subject: [PATCH] Bug 1523562 [wpt PR 15047] - Reland add tentative WPT tests for stale while revalidate handling., a=testonly Automatic update from web-platform-tests Reland add tentative WPT tests for stale while revalidate handling. Add test to ensure that handling the fetch doesn't trigger stale while revalidate loading. Add test to ensure that scripts and css loaded trigger a stale while revalidate cache hit. The PR for the spec changes is here: https://github.com/whatwg/fetch/pull/853 This reland removes the resource timing and moves to css (instead of images) which were both unreliable. BUG=348877 Change-Id: Ibabd8d3fd0295bedc8259594fc926da6ab5cfc43 Reviewed-on: https://chromium-review.googlesource.com/c/1434776 Commit-Queue: Dave Tapuska Reviewed-by: Ben Kelly Cr-Commit-Position: refs/heads/master{#626264} -- wpt-commits: f8a34bc8fa3a9451717c974108d677e319243ded wpt-pr: 15047 UltraBlame original commit: 53cc2cd5c20c298cc1d7b855d0053fe58856bc10 --- .../fetch.tentative.html | 171 +++++++ .../fetch/stale-while-revalidate/stale-css.py | 192 ++++++++ .../stale-css.tentative.html | 427 ++++++++++++++++ .../stale-while-revalidate/stale-image.py | 279 +++++++++++ .../stale-image.tentative.html | 460 ++++++++++++++++++ .../stale-while-revalidate/stale-script.py | 218 +++++++++ .../stale-script.tentative.html | 423 ++++++++++++++++ 7 files changed, 2170 insertions(+) create mode 100644 testing/web-platform/tests/fetch/stale-while-revalidate/fetch.tentative.html create mode 100644 testing/web-platform/tests/fetch/stale-while-revalidate/stale-css.py create mode 100644 testing/web-platform/tests/fetch/stale-while-revalidate/stale-css.tentative.html create mode 100644 testing/web-platform/tests/fetch/stale-while-revalidate/stale-image.py create mode 100644 testing/web-platform/tests/fetch/stale-while-revalidate/stale-image.tentative.html create mode 100644 testing/web-platform/tests/fetch/stale-while-revalidate/stale-script.py create mode 100644 testing/web-platform/tests/fetch/stale-while-revalidate/stale-script.tentative.html diff --git a/testing/web-platform/tests/fetch/stale-while-revalidate/fetch.tentative.html b/testing/web-platform/tests/fetch/stale-while-revalidate/fetch.tentative.html new file mode 100644 index 0000000000000..01ea704bf449d --- /dev/null +++ b/testing/web-platform/tests/fetch/stale-while-revalidate/fetch.tentative.html @@ -0,0 +1,171 @@ +< +! +DOCTYPE +html +> +< +! +- +- +- +Tentative +test +against +: +https +: +/ +/ +github +. +com +/ +whatwg +/ +fetch +/ +pull +/ +853 +- +- +> +< +meta +charset += +" +utf +- +8 +" +> +< +title +> +Tests +Stale +While +Revalidate +is +not +executed +for +fetch +API +< +/ +title +> +< +script +src += +" +/ +resources +/ +testharness +. +js +" +> +< +/ +script +> +< +script +src += +" +/ +resources +/ +testharnessreport +. +js +" +> +< +/ +script +> +< +script +> +promise_test +( +async +( +test +) += +> +{ +const +response += +await +fetch +( +stale +- +script +. +py +) +; +const +response2 += +await +fetch +( +stale +- +script +. +py +) +; +assert_not_equals +( +response +. +headers +. +get +( +' +Token +' +) +response2 +. +headers +. +get +( +' +Token +' +) +) +; +} +' +Second +fetch +does +not +return +same +response +' +) +; +< +/ +script +> diff --git a/testing/web-platform/tests/fetch/stale-while-revalidate/stale-css.py b/testing/web-platform/tests/fetch/stale-while-revalidate/stale-css.py new file mode 100644 index 0000000000000..b416e5fc5f270 --- /dev/null +++ b/testing/web-platform/tests/fetch/stale-while-revalidate/stale-css.py @@ -0,0 +1,192 @@ +def +main +( +request +response +) +: + +cookie += +request +. +cookies +. +first +( +" +Count +" +None +) + +count += +0 + +if +cookie +! += +None +: + +count += +int +( +cookie +. +value +) + +if +request +. +GET +. +first +( +" +query +" +None +) +! += +None +: + +headers += +[ +( +" +Count +" +count +) +] + +content += +" +" + +return +200 +headers +content + +else +: + +count += +count ++ +1 + +content += +" +body +{ +background +: +rgb +( +0 +128 +0 +) +; +} +" + +if +count +> +1 +: + +content += +" +body +{ +background +: +rgb +( +255 +0 +0 +) +; +} +" + +headers += +[ +( +" +Content +- +Type +" +" +text +/ +css +" +) + +( +" +Set +- +Cookie +" +" +Count += +{ +} +" +. +format +( +count +) +) + +( +" +Cache +- +Control +" +" +private +max +- +age += +0 +stale +- +while +- +revalidate += +10 +" +) +] + +return +200 +headers +content diff --git a/testing/web-platform/tests/fetch/stale-while-revalidate/stale-css.tentative.html b/testing/web-platform/tests/fetch/stale-while-revalidate/stale-css.tentative.html new file mode 100644 index 0000000000000..35ec82ff335e6 --- /dev/null +++ b/testing/web-platform/tests/fetch/stale-while-revalidate/stale-css.tentative.html @@ -0,0 +1,427 @@ +< +! +DOCTYPE +html +> +< +! +- +- +- +Tentative +test +against +: +https +: +/ +/ +github +. +com +/ +whatwg +/ +fetch +/ +pull +/ +853 +- +- +> +< +meta +charset += +" +utf +- +8 +" +> +< +title +> +Tests +Stale +While +Revalidate +works +for +css +< +/ +title +> +< +script +src += +" +/ +resources +/ +testharness +. +js +" +> +< +/ +script +> +< +script +src += +" +/ +resources +/ +testharnessreport +. +js +" +> +< +/ +script +> +< +body +> +< +script +> +async_test +( +t += +> +{ +window +. +onload += +t +. +step_func +( +( +) += +> +{ +step_timeout +( +( +) += +> +{ +assert_equals +( +window +. +getComputedStyle +( +document +. +body +) +. +getPropertyValue +( +' +background +- +color +' +) +" +rgb +( +0 +128 +0 +) +" +) +; +var +link2 += +document +. +createElement +( +" +link +" +) +; +link2 +. +onload += +t +. +step_func +( +( +) += +> +{ +assert_equals +( +window +. +getComputedStyle +( +document +. +body +) +. +getPropertyValue +( +' +background +- +color +' +) +" +rgb +( +0 +128 +0 +) +" +) +; +var +checkResult += +( +) += +> +{ +/ +/ +We +poll +because +we +don +' +t +know +when +the +revalidation +will +occur +. +fetch +( +" +stale +- +css +. +py +? +query +" +) +. +then +( +t +. +step_func +( +( +response +) += +> +{ +var +count += +response +. +headers +. +get +( +" +Count +" +) +; +if +( +count += += +' +2 +' +) +{ +t +. +done +( +) +; +} +else +{ +t +. +step_timeout +( +checkResult +25 +) +; +} +} +) +) +; +} +; +t +. +step_timeout +( +checkResult +25 +) +; +} +) +; +link2 +. +rel += +" +stylesheet +" +; +link2 +. +type += +" +text +/ +css +" +; +link2 +. +href += +" +stale +- +css +. +py +" +; +document +. +body +. +appendChild +( +link2 +) +; +} +0 +) +; +} +) +; +} +' +Cache +returns +stale +resource +' +) +; +var +link += +document +. +createElement +( +" +link +" +) +; +link +. +rel += +" +stylesheet +" +; +link +. +type += +" +text +/ +css +" +; +link +. +href += +" +stale +- +css +. +py +" +; +document +. +body +. +appendChild +( +link +) +; +< +/ +script +> +< +/ +body +> diff --git a/testing/web-platform/tests/fetch/stale-while-revalidate/stale-image.py b/testing/web-platform/tests/fetch/stale-while-revalidate/stale-image.py new file mode 100644 index 0000000000000..2934a01f8964a --- /dev/null +++ b/testing/web-platform/tests/fetch/stale-while-revalidate/stale-image.py @@ -0,0 +1,279 @@ +import +os +. +path +def +main +( +request +response +) +: + +cookie += +request +. +cookies +. +first +( +" +Count +" +None +) + +count += +0 + +if +cookie +! += +None +: + +count += +int +( +cookie +. +value +) + +if +request +. +GET +. +first +( +" +query +" +None +) +! += +None +: + +headers += +[ +( +" +Count +" +count +) +] + +content += +" +" + +return +200 +headers +content + +else +: + +count += +count ++ +1 + +filename += +" +green +- +16x16 +. +png +" + +if +cookie +> +1 +: + +filename += +" +green +- +256x256 +. +png +" + +path += +os +. +path +. +join +( +os +. +path +. +dirname +( +__file__ +) +" +. +. +/ +. +. +/ +images +" +filename +) + +body += +open +( +path +" +rb +" +) +. +read +( +) + +response +. +add_required_headers += +False + +response +. +writer +. +write_status +( +200 +) + +response +. +writer +. +write_header +( +" +content +- +length +" +len +( +body +) +) + +response +. +writer +. +write_header +( +" +Cache +- +Control +" +" +private +max +- +age += +0 +stale +- +while +- +revalidate += +10 +" +) + +response +. +writer +. +write_header +( +" +content +- +type +" +" +image +/ +png +" +) + +response +. +writer +. +write_header +( +" +Set +- +Cookie +" +" +Count += +{ +} +" +. +format +( +count +) +) + +response +. +writer +. +end_headers +( +) + +response +. +writer +. +write +( +body +) diff --git a/testing/web-platform/tests/fetch/stale-while-revalidate/stale-image.tentative.html b/testing/web-platform/tests/fetch/stale-while-revalidate/stale-image.tentative.html new file mode 100644 index 0000000000000..b3fd7af40f565 --- /dev/null +++ b/testing/web-platform/tests/fetch/stale-while-revalidate/stale-image.tentative.html @@ -0,0 +1,460 @@ +< +! +DOCTYPE +html +> +< +! +- +- +- +Tentative +test +against +: +https +: +/ +/ +github +. +com +/ +whatwg +/ +fetch +/ +pull +/ +853 +- +- +> +< +meta +charset += +" +utf +- +8 +" +> +< +title +> +Tests +Stale +While +Revalidate +works +for +images +< +/ +title +> +< +script +src += +" +/ +resources +/ +testharness +. +js +" +> +< +/ +script +> +< +script +src += +" +/ +resources +/ +testharnessreport +. +js +" +> +< +/ +script +> +< +body +> +< +! +- +- +Use +a +child +document +to +load +the +second +stale +image +into +because +an +image +loaded +into +the +same +document +will +skip +cache +- +control +headers +. +See +: +https +: +/ +/ +html +. +spec +. +whatwg +. +org +/ +# +the +- +list +- +of +- +available +- +images +- +- +> +< +iframe +id += +" +child +" +srcdoc += +" +" +> +< +/ +iframe +> +< +script +> +async_test +( +t += +> +{ +window +. +onload += +t +. +step_func +( +( +) += +> +{ +step_timeout +( +( +) += +> +{ +assert_equals +( +document +. +getElementById +( +" +firstimage +" +) +. +width +16 +" +Width +is +16 +" +) +; +var +childDocument += +document +. +getElementById +( +' +child +' +) +. +contentDocument +; +var +img2 += +childDocument +. +createElement +( +" +img +" +) +; +img2 +. +onload += +t +. +step_func +( +( +) += +> +{ +assert_equals +( +img2 +. +width +16 +" +image +dimension +" +) +; +var +checkResult += +( +) += +> +{ +/ +/ +We +poll +because +we +don +' +t +know +when +the +revalidation +will +occur +. +fetch +( +" +stale +- +image +. +py +? +query +" +) +. +then +( +t +. +step_func +( +( +response +) += +> +{ +var +count += +response +. +headers +. +get +( +" +Count +" +) +; +if +( +count += += +' +2 +' +) +{ +t +. +done +( +) +; +} +else +{ +t +. +step_timeout +( +checkResult +25 +) +; +} +} +) +) +; +} +; +t +. +step_timeout +( +checkResult +25 +) +; +} +) +; +img2 +. +src += +" +stale +- +image +. +py +" +; +childDocument +. +body +. +appendChild +( +img2 +) +; +} +0 +) +; +} +) +; +} +' +Cache +returns +stale +resource +' +) +; +var +img += +document +. +createElement +( +" +img +" +) +; +img +. +src += +" +stale +- +image +. +py +" +; +img +. +id += +" +firstimage +" +; +document +. +body +. +appendChild +( +img +) +; +< +/ +script +> +< +/ +body +> diff --git a/testing/web-platform/tests/fetch/stale-while-revalidate/stale-script.py b/testing/web-platform/tests/fetch/stale-while-revalidate/stale-script.py new file mode 100644 index 0000000000000..4b801ee603b92 --- /dev/null +++ b/testing/web-platform/tests/fetch/stale-while-revalidate/stale-script.py @@ -0,0 +1,218 @@ +import +random +string +datetime +def +token +( +) +: + +letters += +string +. +ascii_lowercase + +return +' +' +. +join +( +random +. +choice +( +letters +) +for +i +in +range +( +20 +) +) +def +main +( +request +response +) +: + +cookie += +request +. +cookies +. +first +( +" +Count +" +None +) + +count += +0 + +if +cookie +! += +None +: + +count += +int +( +cookie +. +value +) + +if +request +. +GET +. +first +( +" +query +" +None +) +! += +None +: + +headers += +[ +( +" +Count +" +count +) +] + +content += +" +" + +return +200 +headers +content + +else +: + +count += +count ++ +1 + +unique_id += +token +( +) + +headers += +[ +( +" +Content +- +Type +" +" +text +/ +javascript +" +) + +( +" +Cache +- +Control +" +" +private +max +- +age += +0 +stale +- +while +- +revalidate += +10 +" +) + +( +" +Set +- +Cookie +" +" +Count += +{ +} +" +. +format +( +count +) +) + +( +" +Token +" +unique_id +) +] + +content += +" +report +( +' +{ +} +' +) +" +. +format +( +unique_id +) + +return +200 +headers +content diff --git a/testing/web-platform/tests/fetch/stale-while-revalidate/stale-script.tentative.html b/testing/web-platform/tests/fetch/stale-while-revalidate/stale-script.tentative.html new file mode 100644 index 0000000000000..c189453952d04 --- /dev/null +++ b/testing/web-platform/tests/fetch/stale-while-revalidate/stale-script.tentative.html @@ -0,0 +1,423 @@ +< +! +DOCTYPE +html +> +< +! +- +- +- +Tentative +test +against +: +https +: +/ +/ +github +. +com +/ +whatwg +/ +fetch +/ +pull +/ +853 +- +- +> +< +meta +charset += +" +utf +- +8 +" +> +< +title +> +Tests +Stale +While +Revalidate +works +for +scripts +< +/ +title +> +< +script +src += +" +/ +resources +/ +testharness +. +js +" +> +< +/ +script +> +< +script +src += +" +/ +resources +/ +testharnessreport +. +js +" +> +< +/ +script +> +< +body +> +< +script +> +var +last_modified +; +var +last_modified_count += +0 +; +/ +/ +The +script +will +call +report +via +a +uniquely +generated +ID +on +the +subresource +. +/ +/ +If +it +is +a +cache +hit +the +ID +will +be +the +same +and +the +test +will +pass +. +function +report +( +mod +) +{ +if +( +! +last_modified +) +{ +last_modified += +mod +; +last_modified_count += +1 +; +} +else +if +( +last_modified += += +mod +) +{ +last_modified_count ++ ++ +; +} +} +async_test +( +t += +> +{ +window +. +onload += +t +. +step_func +( +( +) += +> +{ +step_timeout +( +( +) += +> +{ +var +script += +document +. +createElement +( +" +script +" +) +; +script +. +src += +" +stale +- +script +. +py +" +; +document +. +body +. +appendChild +( +script +) +; +script +. +onload += +t +. +step_func +( +( +) += +> +{ +assert_equals +( +last_modified_count +2 +" +last +modified +" +) +; +var +checkResult += +( +) += +> +{ +/ +/ +We +poll +because +we +don +' +t +know +when +the +revalidation +will +occur +. +fetch +( +" +stale +- +script +. +py +? +query +" +) +. +then +( +t +. +step_func +( +( +response +) += +> +{ +var +count += +response +. +headers +. +get +( +" +Count +" +) +; +if +( +count += += +' +2 +' +) +{ +t +. +done +( +) +; +} +else +{ +t +. +step_timeout +( +checkResult +25 +) +; +} +} +) +) +; +} +; +t +. +step_timeout +( +checkResult +25 +) +; +} +) +; +} +0 +) +; +} +) +; +} +' +Cache +returns +stale +resource +' +) +; +var +script += +document +. +createElement +( +" +script +" +) +; +script +. +src += +" +stale +- +script +. +py +" +; +document +. +body +. +appendChild +( +script +) +; +< +/ +script +> +< +/ +body +>