Skip to content

Commit

Permalink
Bug 1143820 - Add tests to ensure that the URL fragments are correctl…
Browse files Browse the repository at this point in the history
…y ignored by the DOM Cache API;
  • Loading branch information
rmottola committed Jun 25, 2019
1 parent 5731649 commit 81c4bea
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
19 changes: 14 additions & 5 deletions dom/cache/test/mochitest/test_cache_matchAll_request.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var request1 = new Request("//mochi.test:8888/?1&" + context);
var request1 = new Request("//mochi.test:8888/?1&" + context + "#fragment");
var request2 = new Request("//mochi.test:8888/?2&" + context);
var request3 = new Request("//mochi.test:8888/?3&" + context);
var unknownRequest = new Request("//mochi.test:8888/non/existing/path?" + context);
Expand All @@ -9,7 +9,8 @@ var name = "matchAll-request" + context;

function checkResponse(r, response, responseText) {
ok(r !== response, "The objects should not be the same");
is(r.url, response.url, "The URLs should be the same");
is(r.url, response.url.replace("#fragment", ""),
"The URLs should be the same");
is(r.status, response.status, "The status codes should be the same");
is(r.type, response.type, "The response types should be the same");
is(r.ok, response.ok, "Both responses should have succeeded");
Expand All @@ -31,16 +32,19 @@ fetch(new Request(request1)).then(function(r) {
return response3.text();
}).then(function(text) {
response3Text = text;
return testRequest(request1, request2, request3, unknownRequest);
return testRequest(request1, request2, request3, unknownRequest,
request1.url.replace("#fragment", "#other"));
}).then(function() {
return testRequest(request1.url, request2.url, request3.url,
unknownRequest.url);
unknownRequest.url,
request1.url.replace("#fragment", "#other"));
}).then(function() {
testDone();
});

// The request arguments can either be a URL string, or a Request object.
function testRequest(request1, request2, request3, unknownRequest) {
function testRequest(request1, request2, request3, unknownRequest,
requestWithDifferentFragment) {
return caches.open(name).then(function(cache) {
c = cache;
return c.add(request1);
Expand All @@ -64,6 +68,11 @@ function testRequest(request1, request2, request3, unknownRequest) {
}).then(function(r) {
is(r.length, 1, "Should only find 1 item");
return checkResponse(r[0], response1, response1Text);
}).then(function() {
return c.matchAll(requestWithDifferentFragment);
}).then(function(r) {
is(r.length, 1, "Should only find 1 item");
return checkResponse(r[0], response1, response1Text);
}).then(function() {
return c.matchAll(request3);
}).then(function(r) {
Expand Down
17 changes: 12 additions & 5 deletions dom/cache/test/mochitest/test_cache_match_request.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var request = new Request("//mochi.test:8888/?" + context);
var request = new Request("//mochi.test:8888/?" + context + "#fragment");
var unknownRequest = new Request("//mochi.test:8888/non/existing/path?" + context);
var response;
var c;
Expand All @@ -7,7 +7,8 @@ var name = "match-request" + context;

function checkResponse(r) {
ok(r !== response, "The objects should not be the same");
is(r.url, response.url, "The URLs should be the same");
is(r.url, response.url.replace("#fragment", ""),
"The URLs should be the same");
is(r.status, response.status, "The status codes should be the same");
is(r.type, response.type, "The response types should be the same");
is(r.ok, response.ok, "Both responses should have succeeded");
Expand All @@ -23,15 +24,17 @@ fetch(new Request(request)).then(function(r) {
return response.text();
}).then(function(text) {
responseText = text;
return testRequest(request, unknownRequest);
return testRequest(request, unknownRequest,
request.url.replace("#fragment", "#other"));
}).then(function() {
return testRequest(request.url, unknownRequest.url);
return testRequest(request.url, unknownRequest.url,
request.url.replace("#fragment", "#other"));
}).then(function() {
testDone();
});

// The request argument can either be a URL string, or a Request object.
function testRequest(request, unknownRequest) {
function testRequest(request, unknownRequest, requestWithDifferentFragment) {
return caches.open(name).then(function(cache) {
c = cache;
return c.add(request);
Expand All @@ -56,6 +59,10 @@ function testRequest(request, unknownRequest) {
return caches.match(request);
}).then(function(r) {
return checkResponse(r);
}).then(function() {
return caches.match(requestWithDifferentFragment);
}).then(function(r) {
return checkResponse(r);
}).then(function() {
return caches.match(request, {cacheName: name});
}).then(function(r) {
Expand Down

0 comments on commit 81c4bea

Please sign in to comment.