test_cache_overwrite.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. var requestURL = "//mochi.test:8888/tests/dom/cache/test/mochitest/mirror.sjs?" + context;
  2. var response;
  3. var c;
  4. var responseText;
  5. var name = "match-mirror" + context;
  6. function checkResponse(r) {
  7. ok(r !== response, "The objects should not be the same");
  8. is(r.url, response.url.replace("#fragment", ""),
  9. "The URLs should be the same");
  10. is(r.status, response.status, "The status codes should be the same");
  11. is(r.type, response.type, "The response types should be the same");
  12. is(r.ok, response.ok, "Both responses should have succeeded");
  13. is(r.statusText, response.statusText,
  14. "Both responses should have the same status text");
  15. is(r.headers.get("Mirrored"), response.headers.get("Mirrored"),
  16. "Both responses should have the same Mirrored header");
  17. return r.text().then(function(text) {
  18. is(text, responseText, "The response body should be correct");
  19. });
  20. }
  21. fetch(new Request(requestURL, {headers: {"Mirror": "bar"}})).then(function(r) {
  22. is(r.headers.get("Mirrored"), "bar", "The server should give back the correct header");
  23. response = r;
  24. return response.text();
  25. }).then(function(text) {
  26. responseText = text;
  27. return caches.open(name);
  28. }).then(function(cache) {
  29. c = cache;
  30. return c.add(new Request(requestURL, {headers: {"Mirror": "foo"}}));
  31. }).then(function() {
  32. // Overwrite the request, to replace the entry stored in response_headers
  33. // with a different value.
  34. return c.add(new Request(requestURL, {headers: {"Mirror": "bar"}}));
  35. }).then(function() {
  36. return c.matchAll();
  37. }).then(function(r) {
  38. is(r.length, 1, "Only one request should be in the cache");
  39. return checkResponse(r[0]);
  40. }).then(function() {
  41. return caches.delete(name);
  42. }).then(function(deleted) {
  43. ok(deleted, "The cache should be deleted successfully");
  44. testDone();
  45. });