Bug 1143820 - Add tests to ensure that the URL fragments are correctly ignored by the DOM Cache API; r=bkelly

This commit is contained in:
Ehsan Akhgari 2015-03-16 15:43:09 -04:00
parent 4132833fa3
commit 0e09c7917d
2 changed files with 26 additions and 10 deletions

View File

@ -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);
@ -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");
@ -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);
@ -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) {

View File

@ -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;
@ -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");
@ -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);
@ -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) {