Bug 1142333 - Add a test for passing Request objects to DOM cache match methods; r=bkelly

This commit is contained in:
Ehsan Akhgari 2015-03-11 19:45:30 -04:00
Родитель c27c8bdddb
Коммит 43c73c2bcf
3 изменённых файлов: 84 добавлений и 0 удалений

2
dom/cache/test/mochitest/mochitest.ini поставляемый
Просмотреть файл

@ -8,6 +8,8 @@ support-files =
message_receiver.html
driver.js
serviceworker_driver.js
test_cache_match_request.js
[test_cache.html]
[test_cache_add.html]
[test_cache_match_request.html]

20
dom/cache/test/mochitest/test_cache_match_request.html поставляемый Normal file
Просмотреть файл

@ -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 match 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_match_request.js")
.then(function() {
SimpleTest.finish();
});
</script>
</body>
</html>

62
dom/cache/test/mochitest/test_cache_match_request.js поставляемый Normal file
Просмотреть файл

@ -0,0 +1,62 @@
var request = new Request("//mochi.test:8888/");
var response;
var c;
var responseText;
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.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(request)).then(function(r) {
response = r;
return response.text();
}).then(function(text) {
responseText = text;
return caches.open("match-request");
}).then(function(cache) {
c = cache;
return c.add(request);
}).then(function() {
return c.match(request);
}).then(function(r) {
return checkResponse(r);
}).then(function() {
return caches.match(request);
}).then(function(r) {
return checkResponse(r);
}).then(function() {
return caches.match(request, {cacheName: "match-request"});
}).then(function(r) {
return checkResponse(r);
}).then(function() {
return caches.match(request, {cacheName: "foobar"});
}).catch(function(err) {
is(err.name, "NotFoundError", "Searching in the wrong cache should not succeed");
}).then(function() {
return caches.delete("match-request");
}).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.match(request);
}).then(function(r) {
return checkResponse(r);
}).then(function() {
// Now, drop the cache, reopen and verify that we can't find the request any more.
c = null;
return caches.open("match-request");
}).then(function(cache) {
return cache.match(request);
}).catch(function(err) {
is(err.name, "NotFoundError", "Searching in the cache after deletion should not succeed");
}).then(function() {
testDone();
});