OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2014, Google Inc. All rights reserved. | 2 * Copyright (c) 2014, Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 if (response.url().isNull()) | 69 if (response.url().isNull()) |
70 response.setURL(KURL(ParsedURLString, kResourceURL)); | 70 response.setURL(KURL(ParsedURLString, kResourceURL)); |
71 ResourcePtr<Resource> resource = | 71 ResourcePtr<Resource> resource = |
72 new Resource(ResourceRequest(response.url()), Resource::Raw); | 72 new Resource(ResourceRequest(response.url()), Resource::Raw); |
73 resource->setResponse(response); | 73 resource->setResponse(response); |
74 memoryCache()->add(resource.get()); | 74 memoryCache()->add(resource.get()); |
75 | 75 |
76 return resource; | 76 return resource; |
77 } | 77 } |
78 | 78 |
| 79 ResourcePtr<Resource> resourceFromResourceRequest(ResourceRequest request) |
| 80 { |
| 81 if (request.url().isNull()) |
| 82 request.setURL(KURL(ParsedURLString, kResourceURL)); |
| 83 ResourcePtr<Resource> resource = |
| 84 new Resource(request, Resource::Raw); |
| 85 resource->setResponse(ResourceResponse(KURL(ParsedURLString, kResourceUR
L), "text/html", 0, nullAtom, String())); |
| 86 memoryCache()->add(resource.get()); |
| 87 |
| 88 return resource; |
| 89 } |
| 90 |
79 ResourcePtr<Resource> fetch() | 91 ResourcePtr<Resource> fetch() |
80 { | 92 { |
81 FetchRequest fetchRequest(ResourceRequest(KURL(ParsedURLString, kResourc
eURL)), FetchInitiatorInfo()); | 93 FetchRequest fetchRequest(ResourceRequest(KURL(ParsedURLString, kResourc
eURL)), FetchInitiatorInfo()); |
82 return m_fetcher->fetchSynchronously(fetchRequest); | 94 return m_fetcher->fetchSynchronously(fetchRequest); |
83 } | 95 } |
84 | 96 |
85 private: | 97 private: |
86 // A simple platform that mocks out the clock, for cache freshness testing. | 98 // A simple platform that mocks out the clock, for cache freshness testing. |
87 class ProxyPlatform : public blink::Platform { | 99 class ProxyPlatform : public blink::Platform { |
88 public: | 100 public: |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 | 274 |
263 ResourcePtr<Resource> fresh200Nocache = resourceFromResourceResponse(fresh20
0NocacheResponse); | 275 ResourcePtr<Resource> fresh200Nocache = resourceFromResourceResponse(fresh20
0NocacheResponse); |
264 | 276 |
265 // Advance the clock within the freshness period of this resource before we
make a request. | 277 // Advance the clock within the freshness period of this resource before we
make a request. |
266 advanceClock(24. * 60. * 60. - 15.); | 278 advanceClock(24. * 60. * 60. - 15.); |
267 | 279 |
268 ResourcePtr<Resource> fetched = fetch(); | 280 ResourcePtr<Resource> fetched = fetch(); |
269 EXPECT_NE(fresh200Nocache, fetched); | 281 EXPECT_NE(fresh200Nocache, fetched); |
270 } | 282 } |
271 | 283 |
| 284 TEST_F(CachingCorrectnessTest, RequestWithNoCahe) |
| 285 { |
| 286 ResourceRequest noCacheRequest; |
| 287 noCacheRequest.setHTTPHeaderField("Cache-Control", "no-cache"); |
| 288 ResourcePtr<Resource> noCacheResource = resourceFromResourceRequest(noCacheR
equest); |
| 289 ResourcePtr<Resource> fetched = fetch(); |
| 290 EXPECT_NE(noCacheResource, fetched); |
| 291 } |
| 292 |
272 TEST_F(CachingCorrectnessTest, FreshButNoStore) | 293 TEST_F(CachingCorrectnessTest, FreshButNoStore) |
273 { | 294 { |
274 ResourceResponse fresh200NostoreResponse; | 295 ResourceResponse fresh200NostoreResponse; |
275 fresh200NostoreResponse.setHTTPStatusCode(200); | 296 fresh200NostoreResponse.setHTTPStatusCode(200); |
276 fresh200NostoreResponse.setHTTPHeaderField("Date", kOriginalRequestDateAsStr
ing); | 297 fresh200NostoreResponse.setHTTPHeaderField("Date", kOriginalRequestDateAsStr
ing); |
277 fresh200NostoreResponse.setHTTPHeaderField("Expires", kOneDayAfterOriginalRe
quest); | 298 fresh200NostoreResponse.setHTTPHeaderField("Expires", kOneDayAfterOriginalRe
quest); |
278 fresh200NostoreResponse.setHTTPHeaderField("Cache-Control", "no-store"); | 299 fresh200NostoreResponse.setHTTPHeaderField("Cache-Control", "no-store"); |
279 | 300 |
280 ResourcePtr<Resource> fresh200Nostore = resourceFromResourceResponse(fresh20
0NostoreResponse); | 301 ResourcePtr<Resource> fresh200Nostore = resourceFromResourceResponse(fresh20
0NostoreResponse); |
281 | 302 |
282 // Advance the clock within the freshness period of this resource before we
make a request. | 303 // Advance the clock within the freshness period of this resource before we
make a request. |
283 advanceClock(24. * 60. * 60. - 15.); | 304 advanceClock(24. * 60. * 60. - 15.); |
284 | 305 |
285 ResourcePtr<Resource> fetched = fetch(); | 306 ResourcePtr<Resource> fetched = fetch(); |
286 EXPECT_NE(fresh200Nostore, fetched); | 307 EXPECT_NE(fresh200Nostore, fetched); |
287 } | 308 } |
288 | 309 |
| 310 TEST_F(CachingCorrectnessTest, RequestWithNoStore) |
| 311 { |
| 312 ResourceRequest noStoreRequest; |
| 313 noStoreRequest.setHTTPHeaderField("Cache-Control", "no-store"); |
| 314 ResourcePtr<Resource> noStoreResource = resourceFromResourceRequest(noStoreR
equest); |
| 315 ResourcePtr<Resource> fetched = fetch(); |
| 316 EXPECT_NE(noStoreResource, fetched); |
| 317 } |
| 318 |
289 // FIXME: Determine if ignoring must-revalidate for blink is correct behaviour. | 319 // FIXME: Determine if ignoring must-revalidate for blink is correct behaviour. |
290 // See crbug.com/340088 . | 320 // See crbug.com/340088 . |
291 TEST_F(CachingCorrectnessTest, DISABLED_FreshButMustRevalidate) | 321 TEST_F(CachingCorrectnessTest, DISABLED_FreshButMustRevalidate) |
292 { | 322 { |
293 ResourceResponse fresh200MustRevalidateResponse; | 323 ResourceResponse fresh200MustRevalidateResponse; |
294 fresh200MustRevalidateResponse.setHTTPStatusCode(200); | 324 fresh200MustRevalidateResponse.setHTTPStatusCode(200); |
295 fresh200MustRevalidateResponse.setHTTPHeaderField("Date", kOriginalRequestDa
teAsString); | 325 fresh200MustRevalidateResponse.setHTTPHeaderField("Date", kOriginalRequestDa
teAsString); |
296 fresh200MustRevalidateResponse.setHTTPHeaderField("Expires", kOneDayAfterOri
ginalRequest); | 326 fresh200MustRevalidateResponse.setHTTPHeaderField("Expires", kOneDayAfterOri
ginalRequest); |
297 fresh200MustRevalidateResponse.setHTTPHeaderField("Cache-Control", "must-rev
alidate"); | 327 fresh200MustRevalidateResponse.setHTTPHeaderField("Cache-Control", "must-rev
alidate"); |
298 | 328 |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
368 firstResource->setResponse(fresh200Response); | 398 firstResource->setResponse(fresh200Response); |
369 memoryCache()->add(firstResource.get()); | 399 memoryCache()->add(firstResource.get()); |
370 | 400 |
371 advanceClock(500.); | 401 advanceClock(500.); |
372 | 402 |
373 ResourcePtr<Resource> fetched = fetch(); | 403 ResourcePtr<Resource> fetched = fetch(); |
374 EXPECT_NE(firstResource, fetched); | 404 EXPECT_NE(firstResource, fetched); |
375 } | 405 } |
376 | 406 |
377 } // namespace | 407 } // namespace |
OLD | NEW |