Resolve Service Worker redirects based on the response

We currently resolve Service-Worker-forwarded location headers using the
request. While this matches Firefox, this does not match the spec or
Safari's behavior. Instead, the spec says to resolve the location header
based on the response's URL.

This comes up if the FetchEvent was for /, but the Service Worker
responded with ev.respondWith(fetch("/foo/", {redirect: "manual"})). In
that case, a Location: bar.html header would result in /bar.html by our
version and /foo/bar.html by the spec's version.

Align with the spec. This makes the redirect go where it would have gone
under {redirect: "follow"}. This has two platform-visible behavior
changes:

- First, cases like the above will result in a different URL.

- Second, script-constructed Response objects do not have a URL list. If
  the URLs are absolute, this works fine. If they are relative, those
  fetches will now result in a network error. Note Response.redirect()
  internally constructs absolute URLs, so those continue to work. This
  only affects ev.respondWith(new Response(... location: "bar.html"}})).

Both of these changes match Safari.

Note that, as of writing, the Fetch spec describes this behavior in
terms of a location URL property on the response object. This would
require computing the location URL earlier and preserving it across many
layers, including persisting in CacheStorage. See
https://chromium-review.googlesource.com/c/chromium/src/+/2648648.

Instead, this CL uses the equivalent formulation in
https://github.com/whatwg/fetch/pull/1149. See also discussion in
https://github.com/whatwg/fetch/issues/1146.

Bug: 1170379
Change-Id: Ibb6b12566244fd259029e67787dd7f08edeece9d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2665871
Reviewed-by: Makoto Shimazu <shimazu@chromium.org>
Reviewed-by: Kinuko Yasuda <kinuko@chromium.org>
Reviewed-by: Ben Kelly <wanderview@chromium.org>
Commit-Queue: David Benjamin <davidben@chromium.org>
Cr-Commit-Position: refs/heads/master@{#850874}
5 files changed
tree: 0b7d0c78b75f16bcc34d40c128cbbdfab4da68a9
  1. .github/
  2. .well-known/
  3. accelerometer/
  4. accname/
  5. acid/
  6. ambient-light/
  7. animation-worklet/
  8. annotation-model/
  9. annotation-protocol/
  10. annotation-vocab/
  11. apng/
  12. appmanifest/
  13. audio-output/
  14. background-fetch/
  15. BackgroundSync/
  16. badging/
  17. battery-status/
  18. beacon/
  19. bluetooth/
  20. clear-site-data/
  21. client-hints/
  22. clipboard-apis/
  23. common/
  24. compat/
  25. compression/
  26. conformance-checkers/
  27. console/
  28. contacts/
  29. content-dpr/
  30. content-index/
  31. content-security-policy/
  32. contenteditable/
  33. cookie-store/
  34. cookies/
  35. core-aam/
  36. cors/
  37. cors-rfc1918/
  38. credential-management/
  39. css/
  40. custom-elements/
  41. custom-state-pseudo-class/
  42. delegated-ink/
  43. density-size-correction/
  44. deprecation-reporting/
  45. device-memory/
  46. docs/
  47. document-policy/
  48. dom/
  49. domparsing/
  50. domxpath/
  51. dpub-aam/
  52. dpub-aria/
  53. editing/
  54. element-timing/
  55. encoding/
  56. encoding-detection/
  57. encrypted-media/
  58. entries-api/
  59. event-timing/
  60. eventsource/
  61. feature-policy/
  62. fetch/
  63. file-system-access/
  64. FileAPI/
  65. focus/
  66. font-access/
  67. fonts/
  68. forced-colors-mode/
  69. fullscreen/
  70. gamepad/
  71. generic-sensor/
  72. geolocation-API/
  73. geolocation-sensor/
  74. graphics-aam/
  75. gyroscope/
  76. hr-time/
  77. html/
  78. html-longdesc/
  79. html-media-capture/
  80. idle-detection/
  81. imagebitmap-renderingcontext/
  82. images/
  83. import-maps/
  84. IndexedDB/
  85. inert/
  86. infrastructure/
  87. input-device-capabilities/
  88. input-events/
  89. installedapp/
  90. interfaces/
  91. intersection-observer/
  92. intervention-reporting/
  93. is-input-pending/
  94. js/
  95. js-self-profiling/
  96. keyboard-lock/
  97. keyboard-map/
  98. largest-contentful-paint/
  99. layout-instability/
  100. lifecycle/
  101. loading/
  102. longtask-timing/
  103. magnetometer/
  104. mathml/
  105. measure-memory/
  106. media/
  107. media-capabilities/
  108. media-feeds/
  109. media-playback-quality/
  110. media-source/
  111. mediacapture-depth/
  112. mediacapture-fromelement/
  113. mediacapture-image/
  114. mediacapture-record/
  115. mediacapture-streams/
  116. mediasession/
  117. merchant-validation/
  118. mimesniff/
  119. mixed-content/
  120. mst-content-hint/
  121. native-io/
  122. navigation-timing/
  123. netinfo/
  124. network-error-logging/
  125. notifications/
  126. old-tests/
  127. orientation-event/
  128. orientation-sensor/
  129. origin-policy/
  130. page-lifecycle/
  131. page-visibility/
  132. paint-timing/
  133. payment-handler/
  134. payment-method-basic-card/
  135. payment-method-id/
  136. payment-request/
  137. performance-timeline/
  138. periodic-background-sync/
  139. permissions/
  140. permissions-policy/
  141. permissions-request/
  142. permissions-revoke/
  143. picture-in-picture/
  144. pointerevents/
  145. pointerlock/
  146. portals/
  147. preload/
  148. presentation-api/
  149. priority-hints/
  150. proximity/
  151. push-api/
  152. quirks/
  153. raw-sockets/
  154. referrer-policy/
  155. remote-playback/
  156. reporting/
  157. requestidlecallback/
  158. resize-observer/
  159. resource-timing/
  160. resources/
  161. sanitizer-api/
  162. savedata/
  163. screen-capture/
  164. screen-orientation/
  165. screen-wake-lock/
  166. screen_enumeration/
  167. scroll-animations/
  168. scroll-to-text-fragment/
  169. secure-contexts/
  170. secure-payment-confirmation/
  171. selection/
  172. serial/
  173. server-timing/
  174. service-workers/
  175. shadow-dom/
  176. shape-detection/
  177. signed-exchange/
  178. speech-api/
  179. storage/
  180. storage-access-api/
  181. streams/
  182. subresource-integrity/
  183. svg/
  184. svg-aam/
  185. timing-entrytypes-registry/
  186. tools/
  187. touch-events/
  188. trust-tokens/
  189. trusted-types/
  190. ua-client-hints/
  191. uievents/
  192. upgrade-insecure-requests/
  193. url/
  194. urlpattern/
  195. user-timing/
  196. vibration/
  197. video-rvfc/
  198. visual-viewport/
  199. wai-aria/
  200. wasm/
  201. web-animations/
  202. web-bundle/
  203. web-locks/
  204. web-nfc/
  205. web-otp/
  206. web-share/
  207. webaudio/
  208. webauthn/
  209. webcodecs/
  210. WebCryptoAPI/
  211. webdriver/
  212. webgl/
  213. webgpu/
  214. webhid/
  215. WebIDL/
  216. webmessaging/
  217. webmidi/
  218. webrtc/
  219. webrtc-extensions/
  220. webrtc-identity/
  221. webrtc-insertable-streams/
  222. webrtc-priority/
  223. webrtc-stats/
  224. webrtc-svc/
  225. websockets/
  226. webstorage/
  227. webtransport/
  228. webusb/
  229. webvr/
  230. webvtt/
  231. webxr/
  232. window-segments/
  233. workers/
  234. worklets/
  235. x-frame-options/
  236. xhr/
  237. xslt/
  238. .azure-pipelines.yml
  239. .codecov.yml
  240. .gitattributes
  241. .gitignore
  242. .mailmap
  243. .pyup.yml
  244. .taskcluster.yml
  245. __init__.py
  246. CODE_OF_CONDUCT.md
  247. CODEOWNERS
  248. CONTRIBUTING.md
  249. LICENSE.md
  250. lint.ignore
  251. README.md
  252. testharness_runner.html
  253. update-built-tests.sh
  254. wpt
  255. wpt.py
README.md

The web-platform-tests Project

Taskcluster CI Status documentation manifest Python 3

The web-platform-tests Project is a cross-browser test suite for the Web-platform stack. Writing tests in a way that allows them to be run in all browsers gives browser projects confidence that they are shipping software that is compatible with other implementations, and that later implementations will be compatible with their implementations. This in turn gives Web authors/developers confidence that they can actually rely on the Web platform to deliver on the promise of working across browsers and devices without needing extra layers of abstraction to paper over the gaps left by specification editors and implementors.

The most important sources of information and activity are:

  • github.com/web-platform-tests/wpt: the canonical location of the project's source code revision history and the discussion forum for changes to the code
  • web-platform-tests.org: the documentation website; details how to set up the project, how to write tests, how to give and receive peer review, how to serve as an administrator, and more
  • wpt.live: a public deployment of the test suite, allowing anyone to run the tests by visiting from an Internet-enabled browser of their choice
  • wpt.fyi: an archive of test results collected from an array of web browsers on a regular basis
  • Real-time chat room: the IRC chat room named #testing on irc.w3.org; includes participants located around the world, but busiest during the European working day; all discussion is archived here
  • Mailing list: a public and low-traffic discussion list
  • RFCs: a repo for requesting comments on substantial changes that would impact other stakeholders or users; people who work on WPT infra are encouraged to watch the repo.

If you'd like clarification about anything, don't hesitate to ask in the chat room or on the mailing list.

Setting Up the Repo

Clone or otherwise get https://github.com/web-platform-tests/wpt.

Note: because of the frequent creation and deletion of branches in this repo, it is recommended to “prune” stale branches when fetching updates, i.e. use git pull --prune (or git fetch -p && git merge).

Running the Tests

See the documentation website and in particular the system setup for running tests locally.

Command Line Tools

The wpt command provides a frontend to a variety of tools for working with and running web-platform-tests. Some of the most useful commands are:

  • wpt serve - For starting the wpt http server
  • wpt run - For running tests in a browser
  • wpt lint - For running the lint against all tests
  • wpt manifest - For updating or generating a MANIFEST.json test manifest
  • wpt install - For installing the latest release of a browser or webdriver server on the local machine.
  • wpt serve-wave - For starting the wpt http server and the WAVE test runner. For more details on how to use the WAVE test runner see the documentation.

Windows Notes

On Windows wpt commands must be prefixed with python or the path to the python binary (if python is not in your %PATH%).

python wpt [command]

Alternatively, you may also use Bash on Ubuntu on Windows in the Windows 10 Anniversary Update build, then access your windows partition from there to launch wpt commands.

Please make sure git and your text editor do not automatically convert line endings, as it will cause lint errors. For git, please set git config core.autocrlf false in your working tree.

Publication

The master branch is automatically synced to http://w3c-test.org/.

Pull requests are automatically mirrored except those that modify sensitive resources (such as .py). The latter require someone with merge access to comment with “LGTM” or “w3c-test:mirror” to indicate the pull request has been checked.

Contributing

Save the Web, Write Some Tests!

Absolutely everyone is welcome to contribute to test development. No test is too small or too simple, especially if it corresponds to something for which you've noted an interoperability bug in a browser.

The way to contribute is just as usual:

  • Fork this repository (and make sure you're still relatively in sync with it if you forked a while ago).
  • Create a branch for your changes: git checkout -b topic.
  • Make your changes.
  • Run ./wpt lint as described above.
  • Commit locally and push that to your repo.
  • Create a pull request based on the above.

Issues with web-platform-tests

If you spot an issue with a test and are not comfortable providing a pull request per above to fix it, please file a new issue. Thank you!