Skip to content

Commit

Permalink
WPT: Tentative test HTTP cache vs credentials.
Browse files Browse the repository at this point in the history
Add a test. Check whether the HTTP cache discriminate the credentialled
requests from the anonymous ones.

The expectations used are the ones from the specification. That's also
Firefox's behavior.
Chrome fails the test. Safari fail similarly + do not support
SharedWorker.
At some point, we would like to make Chrome to converge with the spec,
or update with the specification.

whatwg/fetch issue:
whatwg/fetch#307
whatwg/fetch#1253

Design doc:
https://docs.google.com/document/d/1lvbiy4n-GM5I56Ncw304sgvY5Td32R6KHitjRXvkZ6U/edit#

Test results:
https://github.com/web-platform-tests/wpt/pull/29867/checks?check_run_id=3279839968
```
┌────────────────────────────────────────────┬───────┬───────┬────────┐
│Test                                        │ Chrome│ Safari│ Firefox│
├────────────────────────────────────────────┼───────┼───────┼────────┤
│credentials.tentative.any.html              │ 1/3   │ 1/3   │ 3/3    │
├────────────────────────────────────────────┼───────┼───────┼────────┤
│credentials.tentative.any.serviceworker.html│ 1/3   │ 1/3   │ 3/3    │
├────────────────────────────────────────────┼───────┼───────┼────────┤
│credentials.tentative.any.sharedworker.html │ 1/3   │ 0/3   │ 3/3    │
├────────────────────────────────────────────┼───────┼───────┼────────┤
│credentials.tentative.any.worker.html       │ 1/3   │ 1/3   │ 3/3    │
└────────────────────────────────────────────┴───────┴───────┴────────┘
```

Bug: 1221529
Change-Id: I0537108f473f37f42eef7b4fa1079cd88d987b62
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3066251
Reviewed-by: Maksim Orlovich <[email protected]>
Commit-Queue: Arthur Sonzogni <[email protected]>
Cr-Commit-Position: refs/heads/master@{#909780}
  • Loading branch information
ArthurSonzogni authored and chromium-wpt-export-bot committed Aug 9, 2021
1 parent 4324d7a commit 7d35724
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions fetch/http-cache/credentials.tentative.any.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// META: global=window,worker
// META: title=HTTP Cache - Content
// META: timeout=long
// META: script=/common/utils.js
// META: script=http-cache.js

// This is a tentative test.
// Firefox behavior is used as expectations.
//
// whatwg/fetch issue:
// https://github.com/whatwg/fetch/issues/1253
//
// Chrome design doc:
// https://docs.google.com/document/d/1lvbiy4n-GM5I56Ncw304sgvY5Td32R6KHitjRXvkZ6U/edit#

const request_cacheable = {
request_headers: [],
response_headers: [
['Cache-Control', 'max-age=3600'],
],
// TODO(arthursonzogni): The behavior is tested only for same-origin requests.
// It must behave similarly for cross-site and cross-origin requests. The
// problems is the http-cache.js infrastructure returns the
// "Server-Request-Count" as HTTP response headers, which aren't readable for
// CORS requests.
base_url: location.href.replace(/\/[^\/]*$/, '/'),
};

const request_credentialled = { ...request_cacheable, credentials: 'include', };
const request_anonymous = { ...request_cacheable, credentials: 'omit', };

const responseIndex = count => {
return {
expected_response_headers: [
['Server-Request-Count', count.toString()],
],
}
};

var tests = [
{
name: 'same-origin: 2xAnonymous, 2xCredentialled, 1xAnonymous',
requests: [
{ ...request_anonymous , ...responseIndex(1)} ,
{ ...request_anonymous , ...responseIndex(1)} ,
{ ...request_credentialled , ...responseIndex(2)} ,
{ ...request_credentialled , ...responseIndex(2)} ,
{ ...request_anonymous , ...responseIndex(1)} ,
]
},
{
name: 'same-origin: 2xCredentialled, 2xAnonymous, 1xCredentialled',
requests: [
{ ...request_credentialled , ...responseIndex(1)} ,
{ ...request_credentialled , ...responseIndex(1)} ,
{ ...request_anonymous , ...responseIndex(2)} ,
{ ...request_anonymous , ...responseIndex(2)} ,
{ ...request_credentialled , ...responseIndex(1)} ,
]
},
];
run_tests(tests);

0 comments on commit 7d35724

Please sign in to comment.