summaryrefslogtreecommitdiffstats
path: root/test/wpt/tests/fetch/http-cache/freshness.any.js
blob: 6b97c8244f647c9dcbb95ccd2a9e06796e70444a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
// META: global=window,worker
// META: title=HTTP Cache - Freshness
// META: timeout=long
// META: script=/common/utils.js
// META: script=/common/get-host-info.sub.js
// META: script=http-cache.js

var tests = [
  // response directives
  {
    name: "HTTP cache reuses a response with a future Expires",
    requests: [
      {
        response_headers: [
          ["Expires", (30 * 24 * 60 * 60)]
        ]
      },
      {
        expected_type: "cached"
      }
    ]
  },
  {
    name: "HTTP cache does not reuse a response with a past Expires",
    requests: [
      {
        response_headers: [
          ["Expires", (-30 * 24 * 60 * 60)]
        ]
      },
      {
        expected_type: "not_cached"
      }
    ]
  },
  {
    name: "HTTP cache does not reuse a response with a present Expires",
    requests: [
      {
        response_headers: [
          ["Expires", 0]
        ]
      },
      {
        expected_type: "not_cached"
      }
    ]
  },
  {
    name: "HTTP cache does not reuse a response with an invalid Expires",
    requests: [
      {
        response_headers: [
          ["Expires", "0"]
        ]
      },
      {
        expected_type: "not_cached"
      }
    ]
  },
  {
    name: "HTTP cache reuses a response with positive Cache-Control: max-age",
    requests: [
      {
        response_headers: [
          ["Cache-Control", "max-age=3600"]
        ]
      },
      {
        expected_type: "cached"
      }
    ]
  },
  {
    name: "HTTP cache does not reuse a response with Cache-Control: max-age=0",
    requests: [
      {
        response_headers: [
          ["Cache-Control", "max-age=0"]
        ]
      },
      {
        expected_type: "not_cached"
      }
    ]
  },
  {
    name: "HTTP cache reuses a response with positive Cache-Control: max-age and a past Expires",
    requests: [
      {
        response_headers: [
          ["Cache-Control", "max-age=3600"],
          ["Expires", -10000]
        ]
      },
      {
        expected_type: "cached"
      }
    ]
  },
  {
    name: "HTTP cache reuses a response with positive Cache-Control: max-age and an invalid Expires",
    requests: [
      {
        response_headers: [
          ["Cache-Control", "max-age=3600"],
          ["Expires", "0"]
        ]
      },
      {
        expected_type: "cached"
      }
    ]
  },
  {
    name: "HTTP cache does not reuse a response with Cache-Control: max-age=0 and a future Expires",
    requests: [
      {
        response_headers: [
          ["Cache-Control", "max-age=0"],
          ["Expires", 10000]
        ]
      },
      {
        expected_type: "not_cached"
      }
    ]
  },
  {
    name: "HTTP cache does not prefer Cache-Control: s-maxage over Cache-Control: max-age",
    requests: [
      {
        response_headers: [
          ["Cache-Control", "max-age=1, s-maxage=3600"]
        ],
        pause_after: true,
      },
      {
        expected_type: "not_cached"
      }
    ]
  },
  {
    name: "HTTP cache does not reuse a response when the Age header is greater than its freshness lifetime",
    requests: [
      {
        response_headers: [
          ["Cache-Control", "max-age=3600"],
          ["Age", "12000"]
        ],
      },
      {
        expected_type: "not_cached"
      }
    ]
  },
  {
    name: "HTTP cache does not store a response with Cache-Control: no-store",
    requests: [
      {
        response_headers: [
          ["Cache-Control", "no-store"]
        ]
      },
      {
        expected_type: "not_cached"
      }
    ]
  },
  {
    name: "HTTP cache does not store a response with Cache-Control: no-store, even with max-age and Expires",
    requests: [
      {
        response_headers: [
          ["Cache-Control", "max-age=10000, no-store"],
          ["Expires", 10000]
        ]
      },
      {
        expected_type: "not_cached"
      }
    ]
  },
  {
    name: "HTTP cache stores a response with Cache-Control: no-cache, but revalidates upon use",
    requests: [
      {
        response_headers: [
          ["Cache-Control", "no-cache"],
          ["ETag", "abcd"]
        ]
      },
      {
        expected_type: "etag_validated"
      }
    ]
  },
  {
    name: "HTTP cache stores a response with Cache-Control: no-cache, but revalidates upon use, even with max-age and Expires",
    requests: [
      {
        response_headers: [
          ["Cache-Control", "max-age=10000, no-cache"],
          ["Expires", 10000],
          ["ETag", "abcd"]
        ]
      },
      {
        expected_type: "etag_validated"
      }
    ]
  },
];
run_tests(tests);