Skip to content

Commit

Permalink
Bug 1142790 - Add a test for passing Request objects to DOM cache mat…
Browse files Browse the repository at this point in the history
…chAll method;
  • Loading branch information
rmottola committed Jun 25, 2019
1 parent 5063462 commit 7629a09
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 0 deletions.
2 changes: 2 additions & 0 deletions dom/cache/test/mochitest/mochitest.ini
Expand Up @@ -9,7 +9,9 @@ support-files =
driver.js
serviceworker_driver.js
test_cache_match_request.js
test_cache_matchAll_request.js

[test_cache.html]
[test_cache_add.html]
[test_cache_match_request.html]
[test_cache_matchAll_request.html]
20 changes: 20 additions & 0 deletions dom/cache/test/mochitest/test_cache_matchAll_request.html
@@ -0,0 +1,20 @@
<!-- Any copyright is dedicated to the Public Domain.
- http://creativecommons.org/publicdomain/zero/1.0/ -->
<!DOCTYPE HTML>
<html>
<head>
<title>Validate calling matchAll with a Request object</title>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
<script type="text/javascript" src="driver.js"></script>
</head>
<body>
<iframe id="frame"></iframe>
<script class="testbody" type="text/javascript">
runTests("test_cache_matchAll_request.js")
.then(function() {
SimpleTest.finish();
});
</script>
</body>
</html>
93 changes: 93 additions & 0 deletions dom/cache/test/mochitest/test_cache_matchAll_request.js
@@ -0,0 +1,93 @@
var request1 = new Request("//mochi.test:8888/?1&" + context);
var request2 = new Request("//mochi.test:8888/?2&" + context);
var request3 = new Request("//mochi.test:8888/?3&" + context);
var response1, response3;
var c;
var response1Text, response3Text;
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.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");
is(r.statusText, response.statusText,
"Both responses should have the same status text");
return r.text().then(function(text) {
is(text, responseText, "The response body should be correct");
});
}

fetch(new Request(request1)).then(function(r) {
response1 = r;
return response1.text();
}).then(function(text) {
response1Text = text;
return fetch(new Request(request3));
}).then(function(r) {
response3 = r;
return response3.text();
}).then(function(text) {
response3Text = text;
return caches.open(name);
}).then(function(cache) {
c = cache;
return c.add(request1);
}).then(function() {
return c.add(request3);
}).then(function() {
return c.matchAll(request1);
}).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) {
is(r.length, 1, "Should only find 1 item");
return checkResponse(r[0], response3, response3Text);
}).then(function() {
return c.matchAll();
}).then(function(r) {
is(r.length, 2, "Should find 2 items");
return Promise.all([
checkResponse(r[0], response1, response1Text),
checkResponse(r[1], response3, response3Text)
]);
}).then(function() {
return c.matchAll({cacheName: name + "mambojambo"});
}).catch(function(err) {
is(err.name, "NotFoundError", "Searching in the wrong cache should not succeed");
}).then(function() {
return caches.delete(name);
}).then(function(success) {
ok(success, "We should be able to delete the cache successfully");
// Make sure that the cache is still usable after deletion.
return c.matchAll(request1);
}).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) {
is(r.length, 1, "Should only find 1 item");
return checkResponse(r[0], response3, response3Text);
}).then(function() {
return c.matchAll();
}).then(function(r) {
is(r.length, 2, "Should find 2 items");
return Promise.all([
checkResponse(r[0], response1, response1Text),
checkResponse(r[1], response3, response3Text)
]);
}).then(function() {
// Now, drop the cache, reopen and verify that we can't find the request any more.
c = null;
return caches.open(name);
}).then(function(cache) {
return cache.matchAll();
}).catch(function(err) {
is(err.name, "NotFoundError", "Searching in the cache after deletion should not succeed");
}).then(function() {
testDone();
});

0 comments on commit 7629a09

Please sign in to comment.