Skip to content

Commit

Permalink
Fetch: HTTP cache tests
Browse files Browse the repository at this point in the history
Related Fetch change: whatwg/fetch#496.
  • Loading branch information
mnot authored and annevk committed Mar 23, 2017
1 parent 63d40d1 commit 13062c6
Show file tree
Hide file tree
Showing 12 changed files with 1,720 additions and 0 deletions.
1 change: 1 addition & 0 deletions fetch/OWNERS
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@jdm
@youennf
@annevk
@mnot
124 changes: 124 additions & 0 deletions fetch/http-cache/304-update.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>HTTP Cache - 304 Updates</title>
<meta name="help" href="https://fetch.spec.whatwg.org/#request">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/common/utils.js"></script>
<script src="/common/get-host-info.sub.js"></script>
<script src="http-cache.js"></script>
</head>
<body>
<script>
var tests = [
{
name: 'HTTP cache updates returned headers from a Last-Modified 304.',
requests: [
{
response_headers: [
["Expires", http_date(-5000)],
["Last-Modified", http_date(-3000)],
["Test-Header", "A"]
]
},
{
response_headers: [
["Expires", http_date(-3000)],
["Last-Modified", http_date(-3000)],
["Test-Header", "B"]
],
expected_type: "lm_validated",
expected_response_headers: [
["Test-Header", "B"]
]
}
]
},
{
name: 'HTTP cache updates stored headers from a Last-Modified 304.',
requests: [
{
response_headers: [
["Expires", http_date(-5000)],
["Last-Modified", http_date(-3000)],
["Test-Header", "A"]
]
},
{
response_headers: [
["Expires", http_date(3000)],
["Last-Modified", http_date(-3000)],
["Test-Header", "B"]
],
expected_type: "lm_validated",
expected_response_headers: [
["Test-Header", "B"]
]
},
{
expected_type: "cached",
expected_response_headers: [
["Test-Header", "B"]
]
}
]
},
{
name: 'HTTP cache updates returned headers from a ETag 304.',
requests: [
{
response_headers: [
["Expires", http_date(-5000)],
["ETag", "ABC"],
["Test-Header", "A"]
]
},
{
response_headers: [
["Expires", http_date(-3000)],
["ETag", "ABC"],
["Test-Header", "B"]
],
expected_type: "etag_validated",
expected_response_headers: [
["Test-Header", "B"]
]
}
]
},
{
name: 'HTTP cache updates stored headers from a ETag 304.',
requests: [
{
response_headers: [
["Expires", http_date(-5000)],
["ETag", "DEF"],
["Test-Header", "A"]
]
},
{
response_headers: [
["Expires", http_date(3000)],
["ETag", "DEF"],
["Test-Header", "B"]
],
expected_type: "etag_validated",
expected_response_headers: [
["Test-Header", "B"]
]
},
{
expected_type: "cached",
expected_response_headers: [
["Test-Header", "B"]
]
}
]
},
];
run_tests(tests);
</script>
</body>
</html>
24 changes: 24 additions & 0 deletions fetch/http-cache/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
## HTTP Caching Tests

These tests cover HTTP-specified behaviours for caches, primarily from
[RFC7234](http://httpwg.org/specs/rfc7234.html), but as seen through the
lens of Fetch.

A few notes:

* By its nature, caching is optional; some tests expecting a response to be
cached might fail because the client chose not to cache it, or chose to
race the cache with a network request.

* Likewise, some tests might fail because there is a separate document-level
cache that's ill-defined; see [this
issue](https://github.com/whatwg/fetch/issues/354).

* [Partial content tests](partial.html) (a.k.a. Range requests) are not specified
in Fetch; tests are included here for interest only.

* Some browser caches will behave differently when reloading /
shift-reloading, despite the `cache mode` staying the same.

* At the moment, Edge doesn't appear to using HTTP caching in conjunction
with Fetch at all.
212 changes: 212 additions & 0 deletions fetch/http-cache/cc-request.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,212 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>HTTP Cache - Cache-Control Request Directives</title>
<meta name="help" href="https://fetch.spec.whatwg.org/#request">
<meta name="timeout" content="long">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/common/utils.js"></script>
<script src="/common/get-host-info.sub.js"></script>
<script src="http-cache.js"></script>
</head>
<body>
<script>
var tests = [
{
name: "HTTP cache doesn't use aged but fresh response when request contains Cache-Control: max-age=0.",
requests: [
{
template: "fresh",
pause_after: true
},
{
request_headers: [
["Cache-Control", "max-age=0"]
],
expected_type: "not_cached",
}
]
},
{
name: "HTTP cache doesn't use aged but fresh response when request contains Cache-Control: max-age=1.",
requests: [
{
template: "fresh",
pause_after: true
},
{
request_headers: [
["Cache-Control", "max-age=1"]
],
expected_type: "not_cached",
}
]
},
{
name: "HTTP cache doesn't use fresh response with Age header when request contains Cache-Control: max-age that is greater than remaining freshness.",
requests: [
{
response_headers: [
["Cache-Control", "max-age=3600"],
["Age", "1800"]
]
},
{
request_headers: [
["Cache-Control", "max-age=600"]
],
expected_type: "not_cached",
}
]
},
{
name: "HTTP cache does use aged stale response when request contains Cache-Control: max-stale that permits its use.",
requests: [
{
response_headers: [
["Cache-Control", "max-age=1"]
],
pause_after: true
},
{
request_headers: [
["Cache-Control", "max-stale=1000"]
],
expected_type: "cached",
}
]
},
{
name: "HTTP cache does reuse stale response with Age header when request contains Cache-Control: max-stale that permits its use.",
requests: [
{
response_headers: [
["Cache-Control", "max-age=1500"],
["Age", "2000"]
]
},
{
request_headers: [
["Cache-Control", "max-stale=1000"]
],
expected_type: "cached",
}
]
},
{
name: "HTTP cache doesn't reuse fresh response when request contains Cache-Control: min-fresh that wants it fresher.",
requests: [
{
response_headers: [
["Cache-Control", "max-age=1500"]
]
},
{
request_headers: [
["Cache-Control", "min-fresh=2000"]
],
expected_type: "not_cached",
}
]
},
{
name: "HTTP cache doesn't reuse fresh response with Age header when request contains Cache-Control: min-fresh that wants it fresher.",
requests: [
{
response_headers: [
["Cache-Control", "max-age=1500"],
["Age", "1000"]
]
},
{
request_headers: [
["Cache-Control", "min-fresh=1000"]
],
expected_type: "not_cached",
}
]
},
{
name: "HTTP cache doesn't reuse fresh response when request contains Cache-Control: no-cache.",
requests: [
{
response_headers: [
["Cache-Control", "max-age=3600"],
]
},
{
request_headers: [
["Cache-Control", "no-cache"]
],
expected_type: "not_cached",
}
]
},
{
name: "HTTP cache validates fresh response with Last-Modified when request contains Cache-Control: no-cache.",
requests: [
{
response_headers: [
["Cache-Control", "max-age=3600"],
["Last-Modified", http_date(-10000)]
]
},
{
request_headers: [
["Cache-Control", "no-cache"]
],
expected_type: "lm_validate",
}
]
},
{
name: "HTTP cache validates fresh response with ETag when request contains Cache-Control: no-cache.",
requests: [
{
response_headers: [
["Cache-Control", "max-age=3600"],
["ETag", http_content("abc")]
]
},
{
request_headers: [
["Cache-Control", "no-cache"]
],
expected_type: "etag_validate",
}
]
},
{
name: "HTTP cache doesn't reuse fresh response when request contains Cache-Control: no-store.",
requests: [
{
response_headers: [
["Cache-Control", "max-age=3600"],
]
},
{
request_headers: [
["Cache-Control", "no-store"]
],
expected_type: "not_cached",
}
]
},
{
name: 'HTTP cache generates 504 status code when nothing is in cache and request contains Cache-Control: only-if-cached.',
requests: [
{
request_headers: [
["Cache-Control", "only-if-cached"]
],
expected_status: 504
}
]
}
];
run_tests(tests);
</script>
</body>
</html>
Loading

0 comments on commit 13062c6

Please sign in to comment.