Bug 1497604 - Enable ESLint for dom/cache (automatic changes) r=Standard8,hsivonen

Differential Revision: https://phabricator.services.mozilla.com/D20943

--HG--
extra : moz-landing-system : lando
This commit is contained in:
monmanuela 2019-03-06 08:04:15 +00:00
parent 73eb7b29fb
commit df11f56d3f
33 changed files with 1325 additions and 1332 deletions

View file

@ -1,13 +1,13 @@
var name = 'pb-window-cache'; var name = "pb-window-cache";
function testMatch(browser) { function testMatch(browser) {
return ContentTask.spawn(browser, name, function(name) { return ContentTask.spawn(browser, name, function(name) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
content.caches.match('http://foo.com').then(function(response) { content.caches.match("http://foo.com").then(function(response) {
ok(false, 'caches.match() should not return success'); ok(false, "caches.match() should not return success");
reject(); reject();
}).catch(function(err) { }).catch(function(err) {
is('SecurityError', err.name, 'caches.match() should throw SecurityError'); is("SecurityError", err.name, "caches.match() should throw SecurityError");
resolve(); resolve();
}); });
}); });
@ -18,10 +18,10 @@ function testHas(browser) {
return ContentTask.spawn(browser, name, function(name) { return ContentTask.spawn(browser, name, function(name) {
return new Promise(function(resolve, reject) { return new Promise(function(resolve, reject) {
content.caches.has(name).then(function(result) { content.caches.has(name).then(function(result) {
ok(false, 'caches.has() should not return success'); ok(false, "caches.has() should not return success");
reject(); reject();
}).catch(function(err) { }).catch(function(err) {
is('SecurityError', err.name, 'caches.has() should throw SecurityError'); is("SecurityError", err.name, "caches.has() should throw SecurityError");
resolve(); resolve();
}); });
}); });
@ -32,10 +32,10 @@ function testOpen(browser) {
return ContentTask.spawn(browser, name, function(name) { return ContentTask.spawn(browser, name, function(name) {
return new Promise(function(resolve, reject) { return new Promise(function(resolve, reject) {
content.caches.open(name).then(function(c) { content.caches.open(name).then(function(c) {
ok(false, 'caches.open() should not return success'); ok(false, "caches.open() should not return success");
reject(); reject();
}).catch(function(err) { }).catch(function(err) {
is('SecurityError', err.name, 'caches.open() should throw SecurityError'); is("SecurityError", err.name, "caches.open() should throw SecurityError");
resolve(); resolve();
}); });
}); });
@ -46,10 +46,10 @@ function testDelete(browser) {
return ContentTask.spawn(browser, name, function(name) { return ContentTask.spawn(browser, name, function(name) {
return new Promise(function(resolve, reject) { return new Promise(function(resolve, reject) {
content.caches.delete(name).then(function(result) { content.caches.delete(name).then(function(result) {
ok(false, 'caches.delete() should not return success'); ok(false, "caches.delete() should not return success");
reject(); reject();
}).catch(function(err) { }).catch(function(err) {
is('SecurityError', err.name, 'caches.delete() should throw SecurityError'); is("SecurityError", err.name, "caches.delete() should throw SecurityError");
resolve(); resolve();
}); });
}); });
@ -60,10 +60,10 @@ function testKeys(browser) {
return ContentTask.spawn(browser, name, function(name) { return ContentTask.spawn(browser, name, function(name) {
return new Promise(function(resolve, reject) { return new Promise(function(resolve, reject) {
content.caches.keys().then(function(names) { content.caches.keys().then(function(names) {
ok(false, 'caches.keys() should not return success'); ok(false, "caches.keys() should not return success");
reject(); reject();
}).catch(function(err) { }).catch(function(err) {
is('SecurityError', err.name, 'caches.keys() should throw SecurityError'); is("SecurityError", err.name, "caches.keys() should throw SecurityError");
resolve(); resolve();
}); });
}); });
@ -74,20 +74,20 @@ function testOpen_worker(browser) {
return ContentTask.spawn(browser, {}, function() { return ContentTask.spawn(browser, {}, function() {
Cu.importGlobalProperties(["Blob"]); Cu.importGlobalProperties(["Blob"]);
let workerFunctionString = function () { let workerFunctionString = function() {
caches.open("pb-worker-cache").then(function(cacheObject) { caches.open("pb-worker-cache").then(function(cacheObject) {
postMessage(cacheObject.toString()); postMessage(cacheObject.toString());
}, function (reason) { }, function(reason) {
postMessage(reason.name); postMessage(reason.name);
}); });
}.toString(); }.toString();
let workerBlobURL = content.URL.createObjectURL( let workerBlobURL = content.URL.createObjectURL(
new Blob(['(', workerFunctionString, ')()'], new Blob(["(", workerFunctionString, ")()"],
{ type : 'application/javascript' })); { type: "application/javascript" }));
let worker = new content.Worker(workerBlobURL); let worker = new content.Worker(workerBlobURL);
content.URL.revokeObjectURL(workerBlobURL); content.URL.revokeObjectURL(workerBlobURL);
return new Promise(function(resolve, reject) { return new Promise(function(resolve, reject) {
worker.addEventListener("message", function (e) { worker.addEventListener("message", function(e) {
let isGood = (e.data === "SecurityError"); let isGood = (e.data === "SecurityError");
ok(isGood, "caches.open() should throw SecurityError from worker"); ok(isGood, "caches.open() should throw SecurityError from worker");
isGood ? resolve() : reject(); isGood ? resolve() : reject();
@ -99,8 +99,8 @@ function testOpen_worker(browser) {
function test() { function test() {
let privateWin, privateTab; let privateWin, privateTab;
waitForExplicitFinish(); waitForExplicitFinish();
SpecialPowers.pushPrefEnv({'set': [['dom.caches.enabled', true], SpecialPowers.pushPrefEnv({"set": [["dom.caches.enabled", true],
['dom.caches.testing.enabled', true]]} ["dom.caches.testing.enabled", true]]}
).then(() => { ).then(() => {
return BrowserTestUtils.openNewBrowserWindow({private: true}); return BrowserTestUtils.openNewBrowserWindow({private: true});
}).then(pw => { }).then(pw => {

View file

@ -23,7 +23,7 @@ function runTests(testFile, order) {
["dom.caches.testing.enabled", true], ["dom.caches.testing.enabled", true],
["dom.serviceWorkers.enabled", true], ["dom.serviceWorkers.enabled", true],
["dom.serviceWorkers.testing.enabled", true], ["dom.serviceWorkers.testing.enabled", true],
["dom.serviceWorkers.exemptFromPerDomainMax", true]] ["dom.serviceWorkers.exemptFromPerDomainMax", true]],
}); });
} }
@ -73,10 +73,10 @@ function runTests(testFile, order) {
if (event.data.context != "Window") { if (event.data.context != "Window") {
return; return;
} }
if (event.data.type == 'finish') { if (event.data.type == "finish") {
window.removeEventListener("message", onMessage); window.removeEventListener("message", onMessage);
resolve(); resolve();
} else if (event.data.type == 'status') { } else if (event.data.type == "status") {
ok(event.data.status, event.data.context + ": " + event.data.msg); ok(event.data.status, event.data.context + ": " + event.data.msg);
} }
}); });

View file

@ -2,16 +2,16 @@
<script> <script>
var context = "Window"; var context = "Window";
function ok(a, msg) { function ok(a, msg) {
parent.postMessage({type: 'status', status: !!a, parent.postMessage({type: "status", status: !!a,
msg: a + ": " + msg, context: context}, "*"); msg: a + ": " + msg, context}, "*");
} }
function is(a, b, msg) { function is(a, b, msg) {
parent.postMessage({type: 'status', status: a === b, parent.postMessage({type: "status", status: a === b,
msg: a + " === " + b + ": " + msg, context: context}, "*"); msg: a + " === " + b + ": " + msg, context}, "*");
} }
function testDone() { function testDone() {
parent.postMessage({type: 'finish', context: context}, "*"); parent.postMessage({type: "finish", context}, "*");
} }
</script> </script>

View file

@ -1,9 +1,9 @@
// Touch CacheStorage, but then idle and do nothing. // Touch CacheStorage, but then idle and do nothing.
const name = 'idle_worker_cache'; const name = "idle_worker_cache";
var cache; var cache;
self.caches.open(name).then(c => { self.caches.open(name).then(c => {
cache = c; cache = c;
return self.caches.delete(name); return self.caches.delete(name);
}).then(_ => { }).then(_ => {
postMessage('LOADED'); postMessage("LOADED");
}); });

File diff suppressed because it is too large Load diff

View file

@ -9,17 +9,17 @@ function serviceWorkerTestExec(testFile) {
registration.active; registration.active;
var iframe; var iframe;
window.addEventListener("message",function onMessage(event) { window.addEventListener("message", function onMessage(event) {
if (event.data.context != "ServiceWorker") { if (event.data.context != "ServiceWorker") {
return; return;
} }
if (event.data.type == 'finish') { if (event.data.type == "finish") {
window.removeEventListener("message", onMessage); window.removeEventListener("message", onMessage);
iframe.remove(); iframe.remove();
registration.unregister() registration.unregister()
.then(resolve) .then(resolve)
.catch(reject); .catch(reject);
} else if (event.data.type == 'status') { } else if (event.data.type == "status") {
ok(event.data.status, event.data.context + ": " + event.data.msg); ok(event.data.status, event.data.context + ": " + event.data.msg);
} }
}); });

View file

@ -1,41 +1,41 @@
var c = null var c = null;
var request = "http://example.com/hmm?q=foobar" + context; var request = "http://example.com/hmm?q=foobar" + context;
var response = new Response("This is some Response!"); var response = new Response("This is some Response!");
var name = 'snafu' + context; var name = "snafu" + context;
var foobar = 'foobar' + context; var foobar = "foobar" + context;
ok(!!caches, 'caches object should be available on global'); ok(!!caches, "caches object should be available on global");
caches.open(name).then(function(openCache) { caches.open(name).then(function(openCache) {
ok(openCache instanceof Cache, 'cache object should be resolved from caches.open'); ok(openCache instanceof Cache, "cache object should be resolved from caches.open");
return caches.has(name); return caches.has(name);
}).then(function(hasResult) { }).then(function(hasResult) {
ok(hasResult, 'caches.has() should resolve true'); ok(hasResult, "caches.has() should resolve true");
return caches.keys(); return caches.keys();
}).then(function(keys) { }).then(function(keys) {
ok(!!keys, 'caches.keys() should resolve to a truthy value'); ok(!!keys, "caches.keys() should resolve to a truthy value");
ok(keys.length >= 1, 'caches.keys() should resolve to an array of length at least 1'); ok(keys.length >= 1, "caches.keys() should resolve to an array of length at least 1");
ok(keys.includes(name), 'caches.keys() should resolve to an array containing key'); ok(keys.includes(name), "caches.keys() should resolve to an array containing key");
return caches.delete(name); return caches.delete(name);
}).then(function(deleteResult) { }).then(function(deleteResult) {
ok(deleteResult, 'caches.delete() should resolve true'); ok(deleteResult, "caches.delete() should resolve true");
return caches.has(name); return caches.has(name);
}).then(function(hasMissingCache) { }).then(function(hasMissingCache) {
ok(!hasMissingCache, 'missing key should return false from has'); ok(!hasMissingCache, "missing key should return false from has");
}).then(function() { }).then(function() {
return caches.open(name); return caches.open(name);
}).then(function(snafu) { }).then(function(snafu) {
return snafu.keys(); return snafu.keys();
}).then(function(empty) { }).then(function(empty) {
is(0, empty.length, 'cache.keys() should resolve to an array of length 0'); is(0, empty.length, "cache.keys() should resolve to an array of length 0");
}).then(function() { }).then(function() {
return caches.open(name); return caches.open(name);
}).then(function(snafu) { }).then(function(snafu) {
var req = './cachekey'; var req = "./cachekey";
var res = new Response("Hello world"); var res = new Response("Hello world");
return snafu.put('ftp://invalid', res).then(function() { return snafu.put("ftp://invalid", res).then(function() {
ok(false, 'This should fail'); ok(false, "This should fail");
}).catch(function (err) { }).catch(function(err) {
is(err.name, 'TypeError', 'put() should throw TypeError for invalid scheme'); is(err.name, "TypeError", "put() should throw TypeError for invalid scheme");
return snafu.put(req, res); return snafu.put(req, res);
}).then(function(v) { }).then(function(v) {
return snafu; return snafu;
@ -45,20 +45,20 @@ caches.open(name).then(function(openCache) {
}).then(function(args) { }).then(function(args) {
var snafu = args[0]; var snafu = args[0];
var keys = args[1]; var keys = args[1];
is(1, keys.length, 'cache.keys() should resolve to an array of length 1'); is(1, keys.length, "cache.keys() should resolve to an array of length 1");
ok(keys[0] instanceof Request, 'key should be a Request'); ok(keys[0] instanceof Request, "key should be a Request");
ok(keys[0].url.match(/cachekey$/), 'Request URL should match original'); ok(keys[0].url.match(/cachekey$/), "Request URL should match original");
return Promise.all([snafu, snafu.match(keys[0]), snafu.match('ftp://invalid')]); return Promise.all([snafu, snafu.match(keys[0]), snafu.match("ftp://invalid")]);
}).then(function(args) { }).then(function(args) {
var snafu = args[0]; var snafu = args[0];
var response = args[1]; var response = args[1];
ok(response instanceof Response, 'value should be a Response'); ok(response instanceof Response, "value should be a Response");
is(response.status, 200, 'Response status should be 200'); is(response.status, 200, "Response status should be 200");
is(undefined, args[2], 'Match with invalid scheme should resolve undefined'); is(undefined, args[2], "Match with invalid scheme should resolve undefined");
return Promise.all([snafu, snafu.put('./cachekey2', response)]); return Promise.all([snafu, snafu.put("./cachekey2", response)]);
}).then(function(args) { }).then(function(args) {
var snafu = args[0] var snafu = args[0];
return snafu.match('./cachekey2'); return snafu.match("./cachekey2");
}).then(function(response) { }).then(function(response) {
return response.text().then(function(v) { return response.text().then(function(v) {
is(v, "Hello world", "Response body should match original"); is(v, "Hello world", "Response body should match original");
@ -72,60 +72,60 @@ caches.open(name).then(function(openCache) {
c = openCache; c = openCache;
return c.put(request, response); return c.put(request, response);
}).then(function(putResponse) { }).then(function(putResponse) {
is(putResponse, undefined, 'The promise should resolve to undefined'); is(putResponse, undefined, "The promise should resolve to undefined");
return c.keys(request); return c.keys(request);
}).then(function(keys) { }).then(function(keys) {
ok(keys, 'Valid keys object expected'); ok(keys, "Valid keys object expected");
is(keys.length, 1, 'Only one key is expected'); is(keys.length, 1, "Only one key is expected");
return c.keys(); return c.keys();
}).then(function(keys) { }).then(function(keys) {
ok(keys, 'Valid keys object expected'); ok(keys, "Valid keys object expected");
is(keys.length, 1, 'Only one key is expected'); is(keys.length, 1, "Only one key is expected");
return c.matchAll(request); return c.matchAll(request);
}).then(function(matchAllResponses) { }).then(function(matchAllResponses) {
ok(matchAllResponses, 'matchAll should succeed'); ok(matchAllResponses, "matchAll should succeed");
is(matchAllResponses.length, 1, 'Only one match is expected'); is(matchAllResponses.length, 1, "Only one match is expected");
return c.match(request); return c.match(request);
}).then(function(matchResponse) { }).then(function(matchResponse) {
ok(matchResponse, 'match should succeed'); ok(matchResponse, "match should succeed");
return caches.match(request); return caches.match(request);
}).then(function(storageMatchResponse) { }).then(function(storageMatchResponse) {
ok(storageMatchResponse, 'storage match should succeed'); ok(storageMatchResponse, "storage match should succeed");
return caches.match(request, {cacheName:foobar}); return caches.match(request, {cacheName: foobar});
}).then(function(storageMatchResponse) { }).then(function(storageMatchResponse) {
ok(storageMatchResponse, 'storage match with cacheName should succeed'); ok(storageMatchResponse, "storage match with cacheName should succeed");
var request2 = new Request("http://example.com/hmm?q=snafu" + context); var request2 = new Request("http://example.com/hmm?q=snafu" + context);
return c.match(request2, {ignoreSearch:true}); return c.match(request2, {ignoreSearch: true});
}).then(function(match2Response) { }).then(function(match2Response) {
ok(match2Response, 'match should succeed'); ok(match2Response, "match should succeed");
return c.delete(request); return c.delete(request);
}).then(function(deleteResult) { }).then(function(deleteResult) {
ok(deleteResult, 'delete should succeed'); ok(deleteResult, "delete should succeed");
return c.keys(); return c.keys();
}).then(function(keys) { }).then(function(keys) {
ok(keys, 'Valid keys object expected'); ok(keys, "Valid keys object expected");
is(keys.length, 0, 'Zero keys is expected'); is(keys.length, 0, "Zero keys is expected");
return c.matchAll(request); return c.matchAll(request);
}).then(function(matchAll2Responses) { }).then(function(matchAll2Responses) {
ok(matchAll2Responses, 'matchAll should succeed'); ok(matchAll2Responses, "matchAll should succeed");
is(matchAll2Responses.length, 0, 'Zero matches is expected'); is(matchAll2Responses.length, 0, "Zero matches is expected");
return caches.has(foobar); return caches.has(foobar);
}).then(function(hasResult) { }).then(function(hasResult) {
ok(hasResult, 'has should succeed'); ok(hasResult, "has should succeed");
return caches.keys(); return caches.keys();
}).then(function(keys) { }).then(function(keys) {
ok(keys, 'Valid keys object expected'); ok(keys, "Valid keys object expected");
ok(keys.length >= 2, 'At least two keys are expected'); ok(keys.length >= 2, "At least two keys are expected");
ok(keys.includes(name), 'snafu should exist'); ok(keys.includes(name), "snafu should exist");
ok(keys.indexOf(foobar) >= keys.indexOf(name), 'foobar should come after it'); ok(keys.indexOf(foobar) >= keys.indexOf(name), "foobar should come after it");
return caches.delete(foobar); return caches.delete(foobar);
}).then(function(deleteResult) { }).then(function(deleteResult) {
ok(deleteResult, 'delete should succeed'); ok(deleteResult, "delete should succeed");
return caches.has(foobar); return caches.has(foobar);
}).then(function(hasMissingCache) { }).then(function(hasMissingCache) {
ok(!hasMissingCache, 'has should have a result'); ok(!hasMissingCache, "has should have a result");
return caches.delete(name); return caches.delete(name);
}).then(function(deleteResult) { }).then(function(deleteResult) {
ok(deleteResult, 'delete should succeed'); ok(deleteResult, "delete should succeed");
testDone(); testDone();
}) });

View file

@ -1,55 +1,55 @@
var singleUrl = './test_cache_add.js'; var singleUrl = "./test_cache_add.js";
var urlList = [ var urlList = [
'./empty.html', "./empty.html",
'./frame.html', "./frame.html",
'./test_cache.js' "./test_cache.js",
]; ];
var cache; var cache;
var name = "adder" + context; var name = "adder" + context;
caches.open(name).then(function(openCache) { caches.open(name).then(function(openCache) {
cache = openCache; cache = openCache;
return cache.add('ftp://example.com/invalid' + context); return cache.add("ftp://example.com/invalid" + context);
}).catch(function (err) { }).catch(function(err) {
is(err.name, 'TypeError', 'add() should throw TypeError for invalid scheme'); is(err.name, "TypeError", "add() should throw TypeError for invalid scheme");
return cache.addAll(['http://example.com/valid' + context, 'ftp://example.com/invalid' + context]); return cache.addAll(["http://example.com/valid" + context, "ftp://example.com/invalid" + context]);
}).catch(function (err) { }).catch(function(err) {
is(err.name, 'TypeError', 'addAll() should throw TypeError for invalid scheme'); is(err.name, "TypeError", "addAll() should throw TypeError for invalid scheme");
var promiseList = urlList.map(function(url) { var promiseList = urlList.map(function(url) {
return cache.match(url); return cache.match(url);
}); });
promiseList.push(cache.match(singleUrl)); promiseList.push(cache.match(singleUrl));
return Promise.all(promiseList); return Promise.all(promiseList);
}).then(function(resultList) { }).then(function(resultList) {
is(urlList.length + 1, resultList.length, 'Expected number of results'); is(urlList.length + 1, resultList.length, "Expected number of results");
resultList.every(function(result) { resultList.every(function(result) {
is(undefined, result, 'URLs should not already be in the cache'); is(undefined, result, "URLs should not already be in the cache");
}); });
return cache.add(singleUrl); return cache.add(singleUrl);
}).then(function(result) { }).then(function(result) {
is(undefined, result, 'Successful add() should resolve undefined'); is(undefined, result, "Successful add() should resolve undefined");
return cache.addAll(urlList); return cache.addAll(urlList);
}).then(function(result) { }).then(function(result) {
is(undefined, result, 'Successful addAll() should resolve undefined'); is(undefined, result, "Successful addAll() should resolve undefined");
var promiseList = urlList.map(function(url) { var promiseList = urlList.map(function(url) {
return cache.match(url); return cache.match(url);
}); });
promiseList.push(cache.match(singleUrl)); promiseList.push(cache.match(singleUrl));
return Promise.all(promiseList); return Promise.all(promiseList);
}).then(function(resultList) { }).then(function(resultList) {
is(urlList.length + 1, resultList.length, 'Expected number of results'); is(urlList.length + 1, resultList.length, "Expected number of results");
resultList.every(function(result) { resultList.every(function(result) {
ok(!!result, 'Responses should now be in cache for each URL.'); ok(!!result, "Responses should now be in cache for each URL.");
}); });
return cache.matchAll(); return cache.matchAll();
}).then(function(resultList) { }).then(function(resultList) {
is(urlList.length + 1, resultList.length, 'Expected number of results'); is(urlList.length + 1, resultList.length, "Expected number of results");
resultList.every(function(result) { resultList.every(function(result) {
ok(!!result, 'Responses should now be in cache for each URL.'); ok(!!result, "Responses should now be in cache for each URL.");
}); });
return caches.delete(name); return caches.delete(name);
}).then(function() { }).then(function() {
testDone(); testDone();
}).catch(function(err) { }).catch(function(err) {
ok(false, 'Caught error: ' + err); ok(false, "Caught error: " + err);
testDone(); testDone();
}); });

View file

@ -1,11 +1,11 @@
var cache = null; var cache = null;
var name = 'https_' + context; var name = "https_" + context;
var urlBase = 'https://example.com/tests/dom/cache/test/mochitest'; var urlBase = "https://example.com/tests/dom/cache/test/mochitest";
var url1 = urlBase + '/test_cache.js'; var url1 = urlBase + "/test_cache.js";
var url2 = urlBase + '/test_cache_add.js'; var url2 = urlBase + "/test_cache_add.js";
function addOpaque(cache, url) { function addOpaque(cache, url) {
return fetch(new Request(url, { mode: 'no-cors' })).then(function(response) { return fetch(new Request(url, { mode: "no-cors" })).then(function(response) {
return cache.put(url, response); return cache.put(url, response);
}); });
} }
@ -14,18 +14,18 @@ caches.open(name).then(function(c) {
cache = c; cache = c;
return Promise.all([ return Promise.all([
addOpaque(cache, url1), addOpaque(cache, url1),
addOpaque(cache, url2) addOpaque(cache, url2),
]); ]);
}).then(function() { }).then(function() {
return cache.delete(url1); return cache.delete(url1);
}).then(function(result) { }).then(function(result) {
ok(result, 'Cache entry should be deleted'); ok(result, "Cache entry should be deleted");
return cache.delete(url2); return cache.delete(url2);
}).then(function(result) { }).then(function(result) {
ok(result, 'Cache entry should be deleted'); ok(result, "Cache entry should be deleted");
cache = null; cache = null;
return caches.delete(name); return caches.delete(name);
}).then(function(result) { }).then(function(result) {
ok(result, 'Cache should be deleted'); ok(result, "Cache should be deleted");
testDone(); testDone();
}); });

View file

@ -45,7 +45,7 @@ caches.open(name).then(function(cache) {
return Promise.all( return Promise.all(
["POST", "PUT", "DELETE", "OPTIONS"] ["POST", "PUT", "DELETE", "OPTIONS"]
.map(function(method) { .map(function(method) {
var req = new Request(tests[2], {method: method}); var req = new Request(tests[2], {method});
return c.keys(req) return c.keys(req)
.then(function(keys) { .then(function(keys) {
is(keys.length, 0, "No request should be matched without ignoreMethod"); is(keys.length, 0, "No request should be matched without ignoreMethod");

View file

@ -60,7 +60,7 @@ function testRequest(request1, request2, request3, unknownRequest,
return Promise.all( return Promise.all(
["HEAD", "POST", "PUT", "DELETE", "OPTIONS"] ["HEAD", "POST", "PUT", "DELETE", "OPTIONS"]
.map(function(method) { .map(function(method) {
var r = new Request(request1, {method: method}); var r = new Request(request1, {method});
return c.add(r) return c.add(r)
.then(function() { .then(function() {
ok(false, "Promise should be rejected"); ok(false, "Promise should be rejected");
@ -86,7 +86,7 @@ function testRequest(request1, request2, request3, unknownRequest,
return Promise.all( return Promise.all(
["HEAD", "POST", "PUT", "DELETE", "OPTIONS"] ["HEAD", "POST", "PUT", "DELETE", "OPTIONS"]
.map(function(method) { .map(function(method) {
var req = new Request(request1, {method: method}); var req = new Request(request1, {method});
return c.matchAll(req) return c.matchAll(req)
.then(function(r) { .then(function(r) {
is(r.length, 0, "Searching for a request with a non-GET method should not succeed"); is(r.length, 0, "Searching for a request with a non-GET method should not succeed");
@ -109,7 +109,7 @@ function testRequest(request1, request2, request3, unknownRequest,
is(r.length, 2, "Should find 2 items"); is(r.length, 2, "Should find 2 items");
return Promise.all([ return Promise.all([
checkResponse(r[0], response1, response1Text), checkResponse(r[0], response1, response1Text),
checkResponse(r[1], response3, response3Text) checkResponse(r[1], response3, response3Text),
]); ]);
}).then(function() { }).then(function() {
return c.matchAll(request3); return c.matchAll(request3);
@ -122,15 +122,15 @@ function testRequest(request1, request2, request3, unknownRequest,
is(r.length, 2, "Should find 2 items"); is(r.length, 2, "Should find 2 items");
return Promise.all([ return Promise.all([
checkResponse(r[0], response1, response1Text), checkResponse(r[0], response1, response1Text),
checkResponse(r[1], response3, response3Text) checkResponse(r[1], response3, response3Text),
]); ]);
}).then(function() { }).then(function() {
return caches.match(request1, {cacheName: name + "mambojambo"}) return caches.match(request1, {cacheName: name + "mambojambo"})
.then(function() { .then(function() {
is(typeof r, "undefined", 'Searching in the wrong cache should resolve to undefined'); is(typeof r, "undefined", "Searching in the wrong cache should resolve to undefined");
return caches.has(name + "mambojambo"); return caches.has(name + "mambojambo");
}).then(function(hasCache) { }).then(function(hasCache) {
ok(!hasCache, 'The wrong cache should still not exist'); ok(!hasCache, "The wrong cache should still not exist");
}); });
}).then(function() { }).then(function() {
return c.matchAll(unknownRequest); return c.matchAll(unknownRequest);
@ -164,7 +164,7 @@ function testRequest(request1, request2, request3, unknownRequest,
is(r.length, 2, "Should find 2 items"); is(r.length, 2, "Should find 2 items");
return Promise.all([ return Promise.all([
checkResponse(r[0], response1, response1Text), checkResponse(r[0], response1, response1Text),
checkResponse(r[1], response3, response3Text) checkResponse(r[1], response3, response3Text),
]); ]);
}).then(function() { }).then(function() {
// Now, drop the cache, reopen and verify that we can't find the request any more. // Now, drop the cache, reopen and verify that we can't find the request any more.

View file

@ -48,7 +48,7 @@ function testRequest(request, unknownRequest, requestWithAlternateQueryString,
return Promise.all( return Promise.all(
["HEAD", "POST", "PUT", "DELETE", "OPTIONS"] ["HEAD", "POST", "PUT", "DELETE", "OPTIONS"]
.map(function(method) { .map(function(method) {
var r = new Request(request, {method: method}); var r = new Request(request, {method});
return c.add(r) return c.add(r)
.then(function() { .then(function() {
ok(false, "Promise should be rejected"); ok(false, "Promise should be rejected");
@ -72,7 +72,7 @@ function testRequest(request, unknownRequest, requestWithAlternateQueryString,
return Promise.all( return Promise.all(
["HEAD", "POST", "PUT", "DELETE", "OPTIONS"] ["HEAD", "POST", "PUT", "DELETE", "OPTIONS"]
.map(function(method) { .map(function(method) {
var req = new Request(request, {method: method}); var req = new Request(request, {method});
return c.match(req) return c.match(req)
.then(function(r) { .then(function(r) {
is(typeof r, "undefined", "Searching for a request with a non-GET method should not succeed"); is(typeof r, "undefined", "Searching for a request with a non-GET method should not succeed");
@ -102,10 +102,10 @@ function testRequest(request, unknownRequest, requestWithAlternateQueryString,
}).then(function() { }).then(function() {
return caches.match(request, {cacheName: name + "mambojambo"}) return caches.match(request, {cacheName: name + "mambojambo"})
.then(function(result) { .then(function(result) {
is(typeof r, "undefined", 'Searching in the wrong cache should resolve to undefined'); is(typeof r, "undefined", "Searching in the wrong cache should resolve to undefined");
return caches.has(name + "mambojambo"); return caches.has(name + "mambojambo");
}).then(function(hasCache) { }).then(function(hasCache) {
ok(!hasCache, 'The wrong cache should still not exist'); ok(!hasCache, "The wrong cache should still not exist");
}); });
}).then(function() { }).then(function() {
// Make sure that cacheName is ignored on Cache // Make sure that cacheName is ignored on Cache

View file

@ -50,7 +50,7 @@ function setupTestMultipleEntries(headers) {
return c.add(new Request(requestURL, {headers: h})); return c.add(new Request(requestURL, {headers: h}));
})); }));
}).then(function() { }).then(function() {
resolve({response: response, responseText: responseText, cache: cache}); resolve({response, responseText, cache});
}).catch(function(err) { }).catch(function(err) {
reject(err); reject(err);
}); });
@ -257,7 +257,7 @@ function testMultipleCacheEntries() {
]).then(function(t) { ]).then(function(t) {
test = t; test = t;
return test.cache.matchAll(); return test.cache.matchAll();
}).then(function (r) { }).then(function(r) {
is(r.length, 2, "Two cache entries should be stored in the DB"); is(r.length, 2, "Two cache entries should be stored in the DB");
// Ensure that searching without specifying an Accept-Language header fails. // Ensure that searching without specifying an Accept-Language header fails.
return test.cache.matchAll(requestURL); return test.cache.matchAll(requestURL);

View file

@ -64,7 +64,7 @@ function workerGroupUsage() {
URL.createObjectURL(new Blob(["(", workerScript.toSource(), ")()"])); URL.createObjectURL(new Blob(["(", workerScript.toSource(), ")()"]));
let worker = new Worker(url); let worker = new Worker(url);
worker.onmessage = function (e) { worker.onmessage = function(e) {
resolve(e.data, 0); resolve(e.data, 0);
}; };
}); });
@ -92,14 +92,14 @@ SpecialPowers.pushPrefEnv({
["dom.quotaManager.testing", true], ["dom.quotaManager.testing", true],
["dom.storageManager.enabled", true]], ["dom.storageManager.enabled", true]],
}, function() { }, function() {
var name = 'orphanedBodyOwner'; var name = "orphanedBodyOwner";
var cache = null; var cache = null;
var response = null; var response = null;
var initialUsage = 0; var initialUsage = 0;
var fullUsage = 0; var fullUsage = 0;
var resetUsage = 0; var resetUsage = 0;
var endUsage = 0; var endUsage = 0;
var url = 'test_cache_add.js'; var url = "test_cache_add.js";
// start from a fresh origin directory so other tests do not influence our // start from a fresh origin directory so other tests do not influence our
// results // results
@ -108,7 +108,7 @@ SpecialPowers.pushPrefEnv({
}).then(function() { }).then(function() {
return storageUsage(); return storageUsage();
}).then(function(usage) { }).then(function(usage) {
is(0, usage, 'disk usage should be zero to start'); is(0, usage, "disk usage should be zero to start");
}) })
// Initialize and populate an initial cache to get the base sqlite pages // Initialize and populate an initial cache to get the base sqlite pages
@ -122,7 +122,7 @@ SpecialPowers.pushPrefEnv({
}).then(function() { }).then(function() {
return caches.delete(name); return caches.delete(name);
}).then(function(deleted) { }).then(function(deleted) {
ok(deleted, 'cache should be deleted'); ok(deleted, "cache should be deleted");
// This is a bit superfluous, but its necessary to make sure the Cache is // This is a bit superfluous, but its necessary to make sure the Cache is
// fully deleted before we proceed. The deletion actually takes place in // fully deleted before we proceed. The deletion actually takes place in
@ -167,7 +167,7 @@ SpecialPowers.pushPrefEnv({
return storageUsage(); return storageUsage();
}).then(function(usage) { }).then(function(usage) {
fullUsage = usage; fullUsage = usage;
ok(fullUsage > initialUsage, 'disk usage should have grown'); ok(fullUsage > initialUsage, "disk usage should have grown");
}) })
// Test groupUsage() // Test groupUsage()
@ -177,7 +177,7 @@ SpecialPowers.pushPrefEnv({
return groupUsage(); return groupUsage();
}).then(function(usage) { }).then(function(usage) {
fullUsage = usage; fullUsage = usage;
ok(fullUsage > initialUsage, 'disk group usage should have grown'); ok(fullUsage > initialUsage, "disk group usage should have grown");
}) })
// Test workerGroupUsage() // Test workerGroupUsage()
@ -187,7 +187,7 @@ SpecialPowers.pushPrefEnv({
return workerGroupUsage(); return workerGroupUsage();
}).then(function(usage) { }).then(function(usage) {
fullUsage = usage; fullUsage = usage;
ok(fullUsage > initialUsage, 'disk group usage on worker should have grown'); ok(fullUsage > initialUsage, "disk group usage on worker should have grown");
}) })
// Now perform a new Cache operation that will reopen the origin. This // Now perform a new Cache operation that will reopen the origin. This
@ -195,7 +195,7 @@ SpecialPowers.pushPrefEnv({
.then(function() { .then(function() {
return caches.match(url); return caches.match(url);
}).then(function(r) { }).then(function(r) {
ok(!r, 'response should not exist in storage'); ok(!r, "response should not exist in storage");
}) })
// Finally, verify orphaned data was cleaned up by re-checking the disk // Finally, verify orphaned data was cleaned up by re-checking the disk
@ -209,21 +209,21 @@ SpecialPowers.pushPrefEnv({
endUsage = usage; endUsage = usage;
dump("### ### initial:" + initialUsage + ", full:" + fullUsage + dump("### ### initial:" + initialUsage + ", full:" + fullUsage +
", end:" + endUsage + "\n"); ", end:" + endUsage + "\n");
ok(endUsage < fullUsage, 'disk usage should have shrank'); ok(endUsage < fullUsage, "disk usage should have shrank");
is(endUsage, initialUsage, 'disk usage should return to original'); is(endUsage, initialUsage, "disk usage should return to original");
}) })
// Verify that the stale, orphaned response cannot be put back into // Verify that the stale, orphaned response cannot be put back into
// the cache. // the cache.
.then(function() { .then(function() {
ok(!response.bodyUsed, 'response body should not be considered used'); ok(!response.bodyUsed, "response body should not be considered used");
return cache.put(url, response).then(function() { return cache.put(url, response).then(function() {
ok(false, 'Should not be able to store stale orphaned body.'); ok(false, "Should not be able to store stale orphaned body.");
}).catch(function(e) { }).catch(function(e) {
is(e.name, 'TypeError', 'storing a stale orphaned body should throw TypeError'); is(e.name, "TypeError", "storing a stale orphaned body should throw TypeError");
}); });
}).then(function() { }).then(function() {
ok(response.bodyUsed, 'attempting to store response should mark body used'); ok(response.bodyUsed, "attempting to store response should mark body used");
}) })
.then(function() { .then(function() {

View file

@ -65,13 +65,13 @@ SpecialPowers.pushPrefEnv({
["dom.caches.testing.enabled", true], ["dom.caches.testing.enabled", true],
["dom.quotaManager.testing", true]], ["dom.quotaManager.testing", true]],
}, function() { }, function() {
var name = 'toBeOrphaned'; var name = "toBeOrphaned";
var cache = null; var cache = null;
var initialUsage = 0; var initialUsage = 0;
var fullUsage = 0; var fullUsage = 0;
var resetUsage = 0; var resetUsage = 0;
var endUsage = 0; var endUsage = 0;
var url = 'test_cache_add.js'; var url = "test_cache_add.js";
// start from a fresh origin directory so other tests do not influence our // start from a fresh origin directory so other tests do not influence our
// results // results
@ -80,7 +80,7 @@ SpecialPowers.pushPrefEnv({
}).then(function() { }).then(function() {
return storageUsage(); return storageUsage();
}).then(function(usage) { }).then(function(usage) {
is(0, usage, 'disk usage should be zero to start'); is(0, usage, "disk usage should be zero to start");
}) })
// Initialize and populate an initial cache to get the base sqlite pages // Initialize and populate an initial cache to get the base sqlite pages
@ -94,7 +94,7 @@ SpecialPowers.pushPrefEnv({
}).then(function() { }).then(function() {
return caches.delete(name); return caches.delete(name);
}).then(function(deleted) { }).then(function(deleted) {
ok(deleted, 'cache should be deleted'); ok(deleted, "cache should be deleted");
// This is a bit superfluous, but its necessary to make sure the Cache is // This is a bit superfluous, but its necessary to make sure the Cache is
// fully deleted before we proceed. The deletion actually takes place in // fully deleted before we proceed. The deletion actually takes place in
@ -122,7 +122,7 @@ SpecialPowers.pushPrefEnv({
}).then(function() { }).then(function() {
return caches.delete(name); return caches.delete(name);
}).then(function(deleted) { }).then(function(deleted) {
ok(deleted, 'cache should be deleted'); ok(deleted, "cache should be deleted");
}) })
// Reset the quota dir while the cache is deleted, but still referenced // Reset the quota dir while the cache is deleted, but still referenced
@ -133,7 +133,7 @@ SpecialPowers.pushPrefEnv({
return storageUsage(); return storageUsage();
}).then(function(usage) { }).then(function(usage) {
fullUsage = usage; fullUsage = usage;
ok(fullUsage > initialUsage, 'disk usage should have grown'); ok(fullUsage > initialUsage, "disk usage should have grown");
}) })
// Now perform a new Cache operation that will reopen the origin. This // Now perform a new Cache operation that will reopen the origin. This
@ -141,7 +141,7 @@ SpecialPowers.pushPrefEnv({
.then(function() { .then(function() {
return caches.has(name); return caches.has(name);
}).then(function(result) { }).then(function(result) {
ok(!result, 'cache should not exist in storage'); ok(!result, "cache should not exist in storage");
}) })
// Finally, verify orphaned data was cleaned up by re-checking the disk // Finally, verify orphaned data was cleaned up by re-checking the disk
@ -155,8 +155,8 @@ SpecialPowers.pushPrefEnv({
endUsage = usage; endUsage = usage;
dump("### ### initial:" + initialUsage + ", full:" + fullUsage + dump("### ### initial:" + initialUsage + ", full:" + fullUsage +
", end:" + endUsage + "\n"); ", end:" + endUsage + "\n");
ok(endUsage < fullUsage, 'disk usage should have shrank'); ok(endUsage < fullUsage, "disk usage should have shrank");
is(endUsage, initialUsage, 'disk usage should return to original'); is(endUsage, initialUsage, "disk usage should return to original");
SimpleTest.finish(); SimpleTest.finish();
}); });
}); });

View file

@ -87,9 +87,8 @@ SimpleTest.waitForExplicitFinish();
SpecialPowers.pushPrefEnv({ SpecialPowers.pushPrefEnv({
"set": [["dom.caches.enabled", true], "set": [["dom.caches.enabled", true],
["dom.caches.testing.enabled", true], ["dom.caches.testing.enabled", true],
["dom.quotaManager.testing", true]] ["dom.quotaManager.testing", true]],
}, async function() { }, async function() {
// This test is mainly to verify we only generate different padding size for // This test is mainly to verify we only generate different padding size for
// the opaque response which is comming from netwrok. // the opaque response which is comming from netwrok.
// Besides, this test utilizes verifyUsage() to ensure Cache Acions does // Besides, this test utilizes verifyUsage() to ensure Cache Acions does
@ -101,10 +100,10 @@ SpecialPowers.pushPrefEnv({
// Note: For the cloned and cached opaque response, the padding size shouldn't // Note: For the cloned and cached opaque response, the padding size shouldn't
// be changed. Thus, it makes the attacker harder to get the padding size. // be changed. Thus, it makes the attacker harder to get the padding size.
const name = 'cachePadding'; const name = "cachePadding";
const other_name = 'cachePaddingOther'; const other_name = "cachePaddingOther";
const cors_base = 'https://example.com/test/dom/cache/test/mochitest/'; const cors_base = "https://example.com/test/dom/cache/test/mochitest/";
const url = 'test_cache_add.js'; const url = "test_cache_add.js";
await setupTestIframe(); await setupTestIframe();

View file

@ -1,23 +1,23 @@
var url = 'test_cache.js'; var url = "test_cache.js";
var cache; var cache;
var fetchResponse; var fetchResponse;
Promise.all([fetch(url), Promise.all([fetch(url),
caches.open('putter' + context)]).then(function(results) { caches.open("putter" + context)]).then(function(results) {
fetchResponse = results[0]; fetchResponse = results[0];
cache = results[1]; cache = results[1];
return cache.put(url, fetchResponse.clone()); return cache.put(url, fetchResponse.clone());
}).then(function(result) { }).then(function(result) {
is(undefined, result, 'Successful put() should resolve undefined'); is(undefined, result, "Successful put() should resolve undefined");
return cache.match(url); return cache.match(url);
}).then(function(response) { }).then(function(response) {
ok(response, 'match() should find resppnse that was previously put()'); ok(response, "match() should find resppnse that was previously put()");
ok(response.url.endsWith(url), 'matched response should match original url'); ok(response.url.endsWith(url), "matched response should match original url");
return Promise.all([fetchResponse.text(), return Promise.all([fetchResponse.text(),
response.text()]); response.text()]);
}).then(function(results) { }).then(function(results) {
// suppress large assert spam unless it's relevent // suppress large assert spam unless it's relevent
if (results[0] !== results[1]) { if (results[0] !== results[1]) {
is(results[0], results[1], 'stored response body should match original'); is(results[0], results[1], "stored response body should match original");
} }
// Now, try to overwrite the request with a different response object. // Now, try to overwrite the request with a different response object.
@ -43,7 +43,7 @@ Promise.all([fetch(url),
// TODO: Verify that trying to store a response with an error raises a TypeError // TODO: Verify that trying to store a response with an error raises a TypeError
// when bug 1147178 is fixed. // when bug 1147178 is fixed.
return caches.delete('putter' + context); return caches.delete("putter" + context);
}).then(function(deleted) { }).then(function(deleted) {
ok(deleted, "The cache should be deleted successfully"); ok(deleted, "The cache should be deleted successfully");
testDone(); testDone();

View file

@ -1,14 +1,14 @@
let cache; let cache;
let url = 'foo.html'; let url = "foo.html";
let redirectURL = 'http://example.com/foo-bar.html'; let redirectURL = "http://example.com/foo-bar.html";
caches.open('redirect-' + context).then(c => { caches.open("redirect-" + context).then(c => {
cache = c; cache = c;
var response = Response.redirect(redirectURL); var response = Response.redirect(redirectURL);
is(response.headers.get('Location'), redirectURL); is(response.headers.get("Location"), redirectURL);
return cache.put(url, response); return cache.put(url, response);
}).then(_ => { }).then(_ => {
return cache.match(url); return cache.match(url);
}).then(response => { }).then(response => {
is(response.headers.get('Location'), redirectURL); is(response.headers.get("Location"), redirectURL);
testDone(); testDone();
}); });

View file

@ -36,8 +36,8 @@ SpecialPowers.pushPrefEnv({
["dom.caches.testing.enabled", true], ["dom.caches.testing.enabled", true],
["dom.quotaManager.testing", true]], ["dom.quotaManager.testing", true]],
}, function() { }, function() {
var name = 'foo'; var name = "foo";
var url = './test_cache_add.js'; var url = "./test_cache_add.js";
var cache; var cache;
setupTestIframe().then(function() { setupTestIframe().then(function() {
return caches.open(name); return caches.open(name);
@ -48,9 +48,9 @@ SpecialPowers.pushPrefEnv({
return resetStorage(); return resetStorage();
}).then(function() { }).then(function() {
return cache.match(url).then(function(resp) { return cache.match(url).then(function(resp) {
ok(false, 'old cache reference should not work after reset'); ok(false, "old cache reference should not work after reset");
}).catch(function(err) { }).catch(function(err) {
ok(true, 'old cache reference should not work after reset'); ok(true, "old cache reference should not work after reset");
}); });
}).then(function() { }).then(function() {
return caches.open(name); return caches.open(name);
@ -58,10 +58,10 @@ SpecialPowers.pushPrefEnv({
cache = c; cache = c;
return cache.match(url); return cache.match(url);
}).then(function(resp) { }).then(function(resp) {
ok(!!resp, 'cache should work after QM reset'); ok(!!resp, "cache should work after QM reset");
return caches.delete(name); return caches.delete(name);
}).then(function(success) { }).then(function(success) {
ok(success, 'cache should be deleted'); ok(success, "cache should be deleted");
SimpleTest.finish(); SimpleTest.finish();
}); });
}); });

View file

@ -65,7 +65,7 @@ SpecialPowers.pushPrefEnv({
["dom.caches.testing.enabled", true], ["dom.caches.testing.enabled", true],
["dom.quotaManager.testing", true]], ["dom.quotaManager.testing", true]],
}, function() { }, function() {
var name = 'foo'; var name = "foo";
var cache = null; var cache = null;
var initialUsage = 0; var initialUsage = 0;
var fullUsage = 0; var fullUsage = 0;
@ -77,7 +77,7 @@ SpecialPowers.pushPrefEnv({
}).then(function() { }).then(function() {
return storageUsage(); return storageUsage();
}).then(function(usage) { }).then(function(usage) {
is(0, usage, 'disk usage should be zero to start'); is(0, usage, "disk usage should be zero to start");
return caches.open(name); return caches.open(name);
}).then(function(c) { }).then(function(c) {
cache = c; cache = c;
@ -90,7 +90,7 @@ SpecialPowers.pushPrefEnv({
}).then(function() { }).then(function() {
return cache.keys(); return cache.keys();
}).then(function(keyList) { }).then(function(keyList) {
is(keyList.length, largeUrlList.length, 'Large URL list is stored in cache'); is(keyList.length, largeUrlList.length, "Large URL list is stored in cache");
cache = null; cache = null;
// Ensure the Cache DOM object is gone before proceeding. If its alive // Ensure the Cache DOM object is gone before proceeding. If its alive
// it will keep the related entries on-disk as well. // it will keep the related entries on-disk as well.
@ -102,10 +102,10 @@ SpecialPowers.pushPrefEnv({
return storageUsage(); return storageUsage();
}).then(function(usage) { }).then(function(usage) {
fullUsage = usage; fullUsage = usage;
ok(fullUsage > initialUsage, 'disk usage should have grown'); ok(fullUsage > initialUsage, "disk usage should have grown");
return caches.delete(name); return caches.delete(name);
}).then(function(result) { }).then(function(result) {
ok(result, 'cache should be deleted'); ok(result, "cache should be deleted");
// This is a bit superfluous, but its necessary to make sure the Cache is // This is a bit superfluous, but its necessary to make sure the Cache is
// fully deleted before we proceed. The deletion actually takes place in // fully deleted before we proceed. The deletion actually takes place in
// two async steps. We don't want to resetStorage() until the second step // two async steps. We don't want to resetStorage() until the second step
@ -113,7 +113,7 @@ SpecialPowers.pushPrefEnv({
// runnables have been flushed through the threads, etc. // runnables have been flushed through the threads, etc.
return caches.has(name); return caches.has(name);
}).then(function(result) { }).then(function(result) {
ok(!result, 'cache should not exist in storage'); ok(!result, "cache should not exist in storage");
// reset the quota manager storage to ensure the DB connection is flushed // reset the quota manager storage to ensure the DB connection is flushed
return resetStorage(); return resetStorage();
}).then(function() { }).then(function() {
@ -122,8 +122,8 @@ SpecialPowers.pushPrefEnv({
endUsage = usage; endUsage = usage;
dump("### ### initial:" + initialUsage + ", full:" + fullUsage + dump("### ### initial:" + initialUsage + ", full:" + fullUsage +
", end:" + endUsage + "\n"); ", end:" + endUsage + "\n");
ok(endUsage < (fullUsage / 2), 'disk usage should have shrank significantly'); ok(endUsage < (fullUsage / 2), "disk usage should have shrank significantly");
ok(endUsage > initialUsage, 'disk usage should not shrink back to orig size'); ok(endUsage > initialUsage, "disk usage should not shrink back to orig size");
SimpleTest.finish(); SimpleTest.finish();
}); });
}); });

View file

@ -34,8 +34,8 @@ function clearStorage() {
async function testCreateTonsOfFD() { async function testCreateTonsOfFD() {
const number_of_fd = 5120; const number_of_fd = 5120;
const name = 'cacheTonsOfFD'; const name = "cacheTonsOfFD";
const url = "foo.com" const url = "foo.com";
const body = "This is a body"; const body = "This is a body";
info("Stage A: Cached a Request/Response pairs"); info("Stage A: Cached a Request/Response pairs");
@ -54,30 +54,30 @@ async function testCreateTonsOfFD() {
try { try {
cached_response_array = await Promise.all(promise_array); cached_response_array = await Promise.all(promise_array);
} catch (e) { } catch (e) {
throw("Fail to open tons of files with error: " + e); throw ("Fail to open tons of files with error: " + e);
} }
if (cached_response_array.length != number_of_fd) { if (cached_response_array.length != number_of_fd) {
throw("Fail to cache.match the cached responses"); throw ("Fail to cache.match the cached responses");
} }
info("Stage C: Consume the cached body") info("Stage C: Consume the cached body");
for (let i = 0; i < number_of_fd; ++i) { for (let i = 0; i < number_of_fd; ++i) {
if (!cached_response_array[i]) { if (!cached_response_array[i]) {
// Reduce the checking message. // Reduce the checking message.
throw("The cached response doesn't exist"); throw ("The cached response doesn't exist");
} }
let bodyText = ""; let bodyText = "";
try { try {
bodyText = await cached_response_array[i].text(); bodyText = await cached_response_array[i].text();
} catch (e) { } catch (e) {
throw("Fail to consume the cached response's body with error: " + e); throw ("Fail to consume the cached response's body with error: " + e);
} }
if (bodyText != body) { if (bodyText != body) {
// Reduce the checking message. // Reduce the checking message.
throw("The cached body doeen't be the same as original one"); throw ("The cached body doeen't be the same as original one");
} }
} }
@ -89,7 +89,7 @@ SimpleTest.waitForExplicitFinish();
SpecialPowers.pushPrefEnv({ SpecialPowers.pushPrefEnv({
"set": [["dom.caches.enabled", true], "set": [["dom.caches.enabled", true],
["dom.caches.testing.enabled", true], ["dom.caches.testing.enabled", true],
["dom.quotaManager.testing", true]] ["dom.quotaManager.testing", true]],
}, async function() { }, async function() {
await setupTestIframe(); await setupTestIframe();

View file

@ -27,11 +27,11 @@ SpecialPowers.pushPrefEnv({
"set": [["dom.caches.enabled", true]], "set": [["dom.caches.enabled", true]],
}, function() { }, function() {
setupTestIframe().then(function() { setupTestIframe().then(function() {
return caches.open('foo'); return caches.open("foo");
}).then(function(usage) { }).then(function(usage) {
ok(false, 'caches should not be usable in untrusted http origin'); ok(false, "caches should not be usable in untrusted http origin");
}).catch(function(err) { }).catch(function(err) {
is(err.name, 'SecurityError', 'caches should reject with SecurityError'); is(err.name, "SecurityError", "caches should reject with SecurityError");
SimpleTest.finish(); SimpleTest.finish();
}); });
}); });

View file

@ -83,11 +83,11 @@ SimpleTest.waitForExplicitFinish();
SpecialPowers.pushPrefEnv({ SpecialPowers.pushPrefEnv({
"set": [["dom.caches.enabled", true], "set": [["dom.caches.enabled", true],
["dom.caches.testing.enabled", true], ["dom.caches.testing.enabled", true],
["dom.quotaManager.testing", true]] ["dom.quotaManager.testing", true]],
}, async function() { }, async function() {
const name = 'cacheUpdateUsage'; const name = "cacheUpdateUsage";
const url = 'test_cache_add.js'; const url = "test_cache_add.js";
const other_url = 'test_cache_put.js'; const other_url = "test_cache_put.js";
// This test mainly ensure DOM Cache updates its usage to QuotaManager when // This test mainly ensure DOM Cache updates its usage to QuotaManager when
// executing an operation which creates/deletes files. To do this, we verify // executing an operation which creates/deletes files. To do this, we verify
@ -108,7 +108,7 @@ SpecialPowers.pushPrefEnv({
info("Stage 2.2: Verify caches.delete."); info("Stage 2.2: Verify caches.delete.");
var deleted = await caches.delete(name); var deleted = await caches.delete(name);
ok(deleted, 'Cache storage should be deleted'); ok(deleted, "Cache storage should be deleted");
// Reference from test_cache_orphanced_body.html. It ensures that all // Reference from test_cache_orphanced_body.html. It ensures that all
// the runnables have been flushed through the threads. // the runnables have been flushed through the threads.
await caches.has(name); await caches.has(name);

View file

@ -13,10 +13,10 @@
<script class="testbody" type="text/javascript"> <script class="testbody" type="text/javascript">
function startWorker() { function startWorker() {
return new Promise(resolve => { return new Promise(resolve => {
var w = new Worker('idle_worker.js'); var w = new Worker("idle_worker.js");
w.addEventListener('message', function onMessage(evt) { w.addEventListener("message", function onMessage(evt) {
if (evt.data === 'LOADED') { if (evt.data === "LOADED") {
w.removeEventListener('message', onMessage); w.removeEventListener("message", onMessage);
resolve(w); resolve(w);
} }
}); });
@ -34,11 +34,11 @@ SimpleTest.waitForExplicitFinish();
async function test() { async function test() {
let w = await startWorker(); let w = await startWorker();
let weakWorker = SpecialPowers.Cu.getWeakReference(w); let weakWorker = SpecialPowers.Cu.getWeakReference(w);
ok(weakWorker, 'worker supports weak reference'); ok(weakWorker, "worker supports weak reference");
w = null; w = null;
await gc(); await gc();
await gc(); await gc();
ok(!weakWorker.get(), 'worker weak reference should be garbage collected'); ok(!weakWorker.get(), "worker weak reference should be garbage collected");
SimpleTest.finish(); SimpleTest.finish();
} }

View file

@ -16,26 +16,26 @@
["dom.caches.testing.enabled", true]], ["dom.caches.testing.enabled", true]],
}, function() { }, function() {
// attach to a different origin's CacheStorage // attach to a different origin's CacheStorage
var url = 'http://example.com/'; var url = "http://example.com/";
var storage = SpecialPowers.createChromeCache('content', url); var storage = SpecialPowers.createChromeCache("content", url);
// verify we can use the other origin's CacheStorage as normal // verify we can use the other origin's CacheStorage as normal
var req = new Request('http://example.com/index.html'); var req = new Request("http://example.com/index.html");
var res = new Response('hello world'); var res = new Response("hello world");
var cache; var cache;
storage.open('foo').then(function(c) { storage.open("foo").then(function(c) {
cache = c; cache = c;
ok(cache, 'storage should create cache'); ok(cache, "storage should create cache");
return cache.put(req, res.clone()); return cache.put(req, res.clone());
}).then(function() { }).then(function() {
return cache.match(req); return cache.match(req);
}).then(function(foundResponse) { }).then(function(foundResponse) {
return Promise.all([res.text(), foundResponse.text()]); return Promise.all([res.text(), foundResponse.text()]);
}).then(function(results) { }).then(function(results) {
is(results[0], results[1], 'cache should contain response'); is(results[0], results[1], "cache should contain response");
return storage.delete('foo'); return storage.delete("foo");
}).then(function(deleted) { }).then(function(deleted) {
ok(deleted, 'storage should delete cache'); ok(deleted, "storage should delete cache");
SimpleTest.finish(); SimpleTest.finish();
}); });
}); });

View file

@ -28,59 +28,54 @@
function workerTestExec(script) { function workerTestExec(script) {
return new Promise(function(resolve, reject) { return new Promise(function(resolve, reject) {
var worker = new Worker('worker_wrapper.js'); var worker = new Worker("worker_wrapper.js");
worker.onmessage = function(event) { worker.onmessage = function(event) {
is(event.data.context, "Worker", is(event.data.context, "Worker",
"Correct context for messages received on the worker"); "Correct context for messages received on the worker");
if (event.data.type == 'finish') { if (event.data.type == "finish") {
worker.terminate(); worker.terminate();
SpecialPowers.forceGC(); SpecialPowers.forceGC();
resolve(); resolve();
} else if (event.data.type == "status") {
} else if (event.data.type == 'status') {
ok(event.data.status, event.data.context + ": " + event.data.msg); ok(event.data.status, event.data.context + ": " + event.data.msg);
} else if (event.data.type == "getPrefs") {
} else if (event.data.type == 'getPrefs') {
var result = {}; var result = {};
event.data.prefs.forEach(function(pref) { event.data.prefs.forEach(function(pref) {
result[pref] = SpecialPowers.Services.prefs.getBoolPref(pref); result[pref] = SpecialPowers.Services.prefs.getBoolPref(pref);
}); });
worker.postMessage({ worker.postMessage({
type: 'returnPrefs', type: "returnPrefs",
prefs: event.data.prefs, prefs: event.data.prefs,
result: result result,
}); });
} else if (event.data.type == "getPermissions") {
} else if (event.data.type == 'getPermissions') {
var result = {}; var result = {};
event.data.permissions.forEach(function(permission) { event.data.permissions.forEach(function(permission) {
result[permission] = SpecialPowers.hasPermission(permission, window.document); result[permission] = SpecialPowers.hasPermission(permission, window.document);
}); });
worker.postMessage({ worker.postMessage({
type: 'returnPermissions', type: "returnPermissions",
permissions: event.data.permissions, permissions: event.data.permissions,
result: result result,
}); });
} else if (event.data.type == "getVersion") {
} else if (event.data.type == 'getVersion') { var result = SpecialPowers.Cc["@mozilla.org/xre/app-info;1"].getService(SpecialPowers.Ci.nsIXULAppInfo).version;
var result = SpecialPowers.Cc['@mozilla.org/xre/app-info;1'].getService(SpecialPowers.Ci.nsIXULAppInfo).version;
worker.postMessage({ worker.postMessage({
type: 'returnVersion', type: "returnVersion",
result: result result,
}); });
} else if (event.data.type == "getUserAgent") {
} else if (event.data.type == 'getUserAgent') {
worker.postMessage({ worker.postMessage({
type: 'returnUserAgent', type: "returnUserAgent",
result: navigator.userAgent result: navigator.userAgent,
}); });
} }
}
worker.onerror = function(event) {
reject('Worker had an error: ' + event.data);
}; };
worker.postMessage({ script: script }); worker.onerror = function(event) {
reject("Worker had an error: " + event.data);
};
worker.postMessage({ script });
}); });
} }

View file

@ -7,13 +7,13 @@ var client;
var context; var context;
function ok(a, msg) { function ok(a, msg) {
client.postMessage({type: 'status', status: !!a, client.postMessage({type: "status", status: !!a,
msg: a + ": " + msg, context: context}); msg: a + ": " + msg, context});
} }
function is(a, b, msg) { function is(a, b, msg) {
client.postMessage({type: 'status', status: a === b, client.postMessage({type: "status", status: a === b,
msg: a + " === " + b + ": " + msg, context: context }); msg: a + " === " + b + ": " + msg, context });
} }
function workerTestArrayEquals(a, b) { function workerTestArrayEquals(a, b) {
@ -29,83 +29,83 @@ function workerTestArrayEquals(a, b) {
} }
function testDone() { function testDone() {
client.postMessage({ type: 'finish', context: context }); client.postMessage({ type: "finish", context });
} }
function workerTestGetPrefs(prefs, cb) { function workerTestGetPrefs(prefs, cb) {
addEventListener('message', function workerTestGetPrefsCB(e) { addEventListener("message", function workerTestGetPrefsCB(e) {
if (e.data.type != 'returnPrefs' || if (e.data.type != "returnPrefs" ||
!workerTestArrayEquals(prefs, e.data.prefs)) { !workerTestArrayEquals(prefs, e.data.prefs)) {
return; return;
} }
removeEventListener('message', workerTestGetPrefsCB); removeEventListener("message", workerTestGetPrefsCB);
cb(e.data.result); cb(e.data.result);
}); });
client.postMessage({ client.postMessage({
type: 'getPrefs', type: "getPrefs",
context: context, context,
prefs: prefs prefs,
}); });
} }
function workerTestGetPermissions(permissions, cb) { function workerTestGetPermissions(permissions, cb) {
addEventListener('message', function workerTestGetPermissionsCB(e) { addEventListener("message", function workerTestGetPermissionsCB(e) {
if (e.data.type != 'returnPermissions' || if (e.data.type != "returnPermissions" ||
!workerTestArrayEquals(permissions, e.data.permissions)) { !workerTestArrayEquals(permissions, e.data.permissions)) {
return; return;
} }
removeEventListener('message', workerTestGetPermissionsCB); removeEventListener("message", workerTestGetPermissionsCB);
cb(e.data.result); cb(e.data.result);
}); });
client.postMessage({ client.postMessage({
type: 'getPermissions', type: "getPermissions",
context: context, context,
permissions: permissions permissions,
}); });
} }
function workerTestGetVersion(cb) { function workerTestGetVersion(cb) {
addEventListener('message', function workerTestGetVersionCB(e) { addEventListener("message", function workerTestGetVersionCB(e) {
if (e.data.type !== 'returnVersion') { if (e.data.type !== "returnVersion") {
return; return;
} }
removeEventListener('message', workerTestGetVersionCB); removeEventListener("message", workerTestGetVersionCB);
cb(e.data.result); cb(e.data.result);
}); });
client.postMessage({ client.postMessage({
context: context, context,
type: 'getVersion' type: "getVersion",
}); });
} }
function workerTestGetUserAgent(cb) { function workerTestGetUserAgent(cb) {
addEventListener('message', function workerTestGetUserAgentCB(e) { addEventListener("message", function workerTestGetUserAgentCB(e) {
if (e.data.type !== 'returnUserAgent') { if (e.data.type !== "returnUserAgent") {
return; return;
} }
removeEventListener('message', workerTestGetUserAgentCB); removeEventListener("message", workerTestGetUserAgentCB);
cb(e.data.result); cb(e.data.result);
}); });
client.postMessage({ client.postMessage({
context: context, context,
type: 'getUserAgent' type: "getUserAgent",
}); });
} }
var completeInstall = null; var completeInstall = null;
addEventListener('message', function workerWrapperOnMessage(e) { addEventListener("message", function workerWrapperOnMessage(e) {
removeEventListener('message', workerWrapperOnMessage); removeEventListener("message", workerWrapperOnMessage);
var data = e.data; var data = e.data;
function runScript() { function runScript() {
try { try {
importScripts(data.script); importScripts(data.script);
} catch(e) { } catch (e) {
client.postMessage({ client.postMessage({
type: 'status', type: "status",
status: false, status: false,
context: context, context,
msg: 'worker failed to import ' + data.script + "; error: " + e.message msg: "worker failed to import " + data.script + "; error: " + e.message,
}); });
} }
} }
@ -133,4 +133,4 @@ addEventListener('message', function workerWrapperOnMessage(e) {
addEventListener("install", e => { addEventListener("install", e => {
e.waitUntil(new Promise(resolve => completeInstall = resolve)); e.waitUntil(new Promise(resolve => completeInstall = resolve));
}) });

View file

@ -7,29 +7,29 @@
*/ */
// services required be initialized in order to run CacheStorage // services required be initialized in order to run CacheStorage
var ss = Cc['@mozilla.org/storage/service;1'] var ss = Cc["@mozilla.org/storage/service;1"]
.createInstance(Ci.mozIStorageService); .createInstance(Ci.mozIStorageService);
var sts = Cc['@mozilla.org/network/stream-transport-service;1'] var sts = Cc["@mozilla.org/network/stream-transport-service;1"]
.getService(Ci.nsIStreamTransportService); .getService(Ci.nsIStreamTransportService);
var hash = Cc['@mozilla.org/security/hash;1'] var hash = Cc["@mozilla.org/security/hash;1"]
.createInstance(Ci.nsICryptoHash); .createInstance(Ci.nsICryptoHash);
// Expose Cache and Fetch symbols on the global // Expose Cache and Fetch symbols on the global
Cu.importGlobalProperties(['caches', 'File', 'fetch']); Cu.importGlobalProperties(["caches", "File", "fetch"]);
// Extract a zip file into the profile // Extract a zip file into the profile
function create_test_profile(zipFileName) { function create_test_profile(zipFileName) {
do_get_profile(); do_get_profile();
var directoryService = Cc['@mozilla.org/file/directory_service;1'] var directoryService = Cc["@mozilla.org/file/directory_service;1"]
.getService(Ci.nsIProperties); .getService(Ci.nsIProperties);
var profileDir = directoryService.get('ProfD', Ci.nsIFile); var profileDir = directoryService.get("ProfD", Ci.nsIFile);
var currentDir = directoryService.get('CurWorkD', Ci.nsIFile); var currentDir = directoryService.get("CurWorkD", Ci.nsIFile);
var packageFile = currentDir.clone(); var packageFile = currentDir.clone();
packageFile.append(zipFileName); packageFile.append(zipFileName);
var zipReader = Cc['@mozilla.org/libjar/zip-reader;1'] var zipReader = Cc["@mozilla.org/libjar/zip-reader;1"]
.createInstance(Ci.nsIZipReader); .createInstance(Ci.nsIZipReader);
zipReader.open(packageFile); zipReader.open(packageFile);
@ -40,20 +40,20 @@ function create_test_profile(zipFileName) {
var zipentry = zipReader.getEntry(entryName); var zipentry = zipReader.getEntry(entryName);
var file = profileDir.clone(); var file = profileDir.clone();
entryName.split('/').forEach(function(part) { entryName.split("/").forEach(function(part) {
file.append(part); file.append(part);
}); });
if (zipentry.isDirectory) { if (zipentry.isDirectory) {
file.create(Ci.nsIFile.DIRECTORY_TYPE, parseInt('0755', 8)); file.create(Ci.nsIFile.DIRECTORY_TYPE, parseInt("0755", 8));
} else { } else {
var istream = zipReader.getInputStream(entryName); var istream = zipReader.getInputStream(entryName);
var ostream = Cc['@mozilla.org/network/file-output-stream;1'] var ostream = Cc["@mozilla.org/network/file-output-stream;1"]
.createInstance(Ci.nsIFileOutputStream); .createInstance(Ci.nsIFileOutputStream);
ostream.init(file, -1, parseInt('0644', 8), 0); ostream.init(file, -1, parseInt("0644", 8), 0);
var bostream = Cc['@mozilla.org/network/buffered-output-stream;1'] var bostream = Cc["@mozilla.org/network/buffered-output-stream;1"]
.createInstance(Ci.nsIBufferedOutputStream); .createInstance(Ci.nsIBufferedOutputStream);
bostream.init(ostream, 32 * 1024); bostream.init(ostream, 32 * 1024);
@ -67,8 +67,7 @@ function create_test_profile(zipFileName) {
zipReader.close(); zipReader.close();
} }
function getCacheDir() function getCacheDir() {
{
let dirService = Cc["@mozilla.org/file/directory_service;1"] let dirService = Cc["@mozilla.org/file/directory_service;1"]
.getService(Ci.nsIProperties); .getService(Ci.nsIProperties);

View file

@ -20,23 +20,23 @@ function enumerate_tree(entryList) {
var dirList = file.directoryEntries; var dirList = file.directoryEntries;
while (dirList.hasMoreElements()) { while (dirList.hasMoreElements()) {
var dirFile = dirList.nextFile; var dirFile = dirList.nextFile;
entryList.push({ path: path + '/' + dirFile.leafName, file: dirFile }); entryList.push({ path: path + "/" + dirFile.leafName, file: dirFile });
} }
} }
} }
} }
function zip_profile(zipFile, profileDir) { function zip_profile(zipFile, profileDir) {
var zipWriter = Cc['@mozilla.org/zipwriter;1'] var zipWriter = Cc["@mozilla.org/zipwriter;1"]
.createInstance(Ci.nsIZipWriter); .createInstance(Ci.nsIZipWriter);
zipWriter.open(zipFile, 0x04 | 0x08 | 0x20); zipWriter.open(zipFile, 0x04 | 0x08 | 0x20);
var root = profileDir.clone(); var root = profileDir.clone();
root.append('storage'); root.append("storage");
root.append('default'); root.append("default");
root.append('chrome'); root.append("chrome");
var entryList = [{path: 'storage/default/chrome', file: root}]; var entryList = [{path: "storage/default/chrome", file: root}];
enumerate_tree(entryList); enumerate_tree(entryList);
entryList.forEach(function(entry) { entryList.forEach(function(entry) {
@ -44,7 +44,7 @@ function zip_profile(zipFile, profileDir) {
zipWriter.addEntryDirectory(entry.path, entry.file.lastModifiedTime, zipWriter.addEntryDirectory(entry.path, entry.file.lastModifiedTime,
false); false);
} else { } else {
var istream = Cc['@mozilla.org/network/file-input-stream;1'] var istream = Cc["@mozilla.org/network/file-input-stream;1"]
.createInstance(Ci.nsIFileInputStream); .createInstance(Ci.nsIFileInputStream);
istream.init(entry.file, -1, -1, 0); istream.init(entry.file, -1, -1, 0);
zipWriter.addEntryStream(entry.path, entry.file.lastModifiedTime, zipWriter.addEntryStream(entry.path, entry.file.lastModifiedTime,
@ -78,21 +78,21 @@ function exactGC() {
function resetQuotaManager() { function resetQuotaManager() {
return new Promise(function(resolve) { return new Promise(function(resolve) {
var qm = Cc['@mozilla.org/dom/quota/manager;1'] var qm = Cc["@mozilla.org/dom/quota/manager;1"]
.getService(Ci.nsIQuotaManager); .getService(Ci.nsIQuotaManager);
var prefService = Cc['@mozilla.org/preferences-service;1'] var prefService = Cc["@mozilla.org/preferences-service;1"]
.getService(Ci.nsIPrefService); .getService(Ci.nsIPrefService);
// enable quota manager testing mode // enable quota manager testing mode
var pref = 'dom.quotaManager.testing'; var pref = "dom.quotaManager.testing";
prefService.getBranch(null).setBoolPref(pref, true); prefService.getBranch(null).setBoolPref(pref, true);
var request = qm.reset(); var request = qm.reset();
request.callback = resolve; request.callback = resolve;
// disable quota manager testing mode // disable quota manager testing mode
//prefService.getBranch(null).setBoolPref(pref, false); // prefService.getBranch(null).setBoolPref(pref, false);
}); });
} }
@ -100,25 +100,25 @@ function run_test() {
do_test_pending(); do_test_pending();
do_get_profile(); do_get_profile();
var directoryService = Cc['@mozilla.org/file/directory_service;1'] var directoryService = Cc["@mozilla.org/file/directory_service;1"]
.getService(Ci.nsIProperties); .getService(Ci.nsIProperties);
var profileDir = directoryService.get('ProfD', Ci.nsIFile); var profileDir = directoryService.get("ProfD", Ci.nsIFile);
var currentDir = directoryService.get('CurWorkD', Ci.nsIFile); var currentDir = directoryService.get("CurWorkD", Ci.nsIFile);
var zipFile = currentDir.clone(); var zipFile = currentDir.clone();
zipFile.append('new_profile.zip'); zipFile.append("new_profile.zip");
if (zipFile.exists()) { if (zipFile.exists()) {
zipFile.remove(false); zipFile.remove(false);
} }
ok(!zipFile.exists()); ok(!zipFile.exists());
caches.open('xpcshell-test').then(function(c) { caches.open("xpcshell-test").then(function(c) {
var request = new Request('http://example.com/index.html'); var request = new Request("http://example.com/index.html");
var response = new Response('hello world'); var response = new Response("hello world");
return c.put(request, response); return c.put(request, response);
}).then(exactGC).then(resetQuotaManager).then(function() { }).then(exactGC).then(resetQuotaManager).then(function() {
zip_profile(zipFile, profileDir); zip_profile(zipFile, profileDir);
dump('### ### created zip at: ' + zipFile.path + '\n'); dump("### ### created zip at: " + zipFile.path + "\n");
do_test_finished(); do_test_finished();
}).catch(function(e) { }).catch(function(e) {
do_test_finished(); do_test_finished();

View file

@ -42,12 +42,12 @@ async function run_test() {
// 5. Add "create_cache.js". // 5. Add "create_cache.js".
// 6. Replace the "storage.sqlite" created by FF56 (storage v2.0) with the // 6. Replace the "storage.sqlite" created by FF56 (storage v2.0) with the
// "storage.sqlite" created by FF57 (storage v2.1) // "storage.sqlite" created by FF57 (storage v2.1)
create_test_profile('bug1425146_profile.zip'); create_test_profile("bug1425146_profile.zip");
try { try {
await caches.open("test"); await caches.open("test");
ok(true, "Should not have thrown"); ok(true, "Should not have thrown");
} catch(ex) { } catch (ex) {
ok(false, "Should not have thrown"); ok(false, "Should not have thrown");
} }

View file

@ -8,42 +8,42 @@
function run_test() { function run_test() {
do_test_pending(); do_test_pending();
create_test_profile('schema_15_profile.zip'); create_test_profile("schema_15_profile.zip");
var cache; var cache;
caches.open('xpcshell-test').then(function(c) { caches.open("xpcshell-test").then(function(c) {
cache = c; cache = c;
ok(cache, 'cache exists'); ok(cache, "cache exists");
return cache.keys(); return cache.keys();
}).then(function(requestList) { }).then(function(requestList) {
ok(requestList.length > 0, 'should have at least one request in cache'); ok(requestList.length > 0, "should have at least one request in cache");
requestList.forEach(function(request) { requestList.forEach(function(request) {
ok(request, 'each request in list should be non-null'); ok(request, "each request in list should be non-null");
ok(request.redirect === 'follow', 'request.redirect should default to "follow"'); ok(request.redirect === "follow", 'request.redirect should default to "follow"');
ok(request.cache === 'default', 'request.cache should have been updated to "default"' + request.cache); ok(request.cache === "default", 'request.cache should have been updated to "default"' + request.cache);
ok(request.mode === 'navigate', 'request.mode should have been updated to "navigate"'); ok(request.mode === "navigate", 'request.mode should have been updated to "navigate"');
ok(request.referrerPolicy === 'no-referrer-when-downgrade', 'request.referrerPolicy should have been updated to "no-referrer-when-downgrade"'); ok(request.referrerPolicy === "no-referrer-when-downgrade", 'request.referrerPolicy should have been updated to "no-referrer-when-downgrade"');
}); });
return Promise.all(requestList.map(function(request) { return Promise.all(requestList.map(function(request) {
return cache.match(request); return cache.match(request);
})); }));
}).then(function(responseList) { }).then(function(responseList) {
ok(responseList.length > 0, 'should have at least one response in cache'); ok(responseList.length > 0, "should have at least one response in cache");
responseList.forEach(function(response) { responseList.forEach(function(response) {
ok(response, 'each response in list should be non-null'); ok(response, "each response in list should be non-null");
// reponse.url is a empty string in current test file. It should test for // reponse.url is a empty string in current test file. It should test for
// not being a empty string once thet test file is updated. // not being a empty string once thet test file is updated.
ok(typeof response.url === 'string', 'each response.url in list should be a string'); ok(typeof response.url === "string", "each response.url in list should be a string");
// reponse.redirected may be changed once test file is updated. It should // reponse.redirected may be changed once test file is updated. It should
// be false since current reponse.url is a empty string. // be false since current reponse.url is a empty string.
ok(response.redirected === false, 'each response.redirected in list should be false'); ok(response.redirected === false, "each response.redirected in list should be false");
Assert.equal(response.headers.get('Content-Type'), 'text/plain;charset=UTF-8', Assert.equal(response.headers.get("Content-Type"), "text/plain;charset=UTF-8",
'the response should have the correct header'); "the response should have the correct header");
}); });
}).then(function() { }).then(function() {
do_test_finished(); do_test_finished();
}).catch(function(e) { }).catch(function(e) {
ok(false, 'caught exception ' + e); ok(false, "caught exception " + e);
do_test_finished(); do_test_finished();
}); });
} }

View file

@ -10,7 +10,7 @@ function getTempPaddingFilePath() {
return temporaryPaddingFile; return temporaryPaddingFile;
} }
function createTempPaddingFile () { function createTempPaddingFile() {
let temporaryPaddingFile = getTempPaddingFilePath(); let temporaryPaddingFile = getTempPaddingFilePath();
temporaryPaddingFile.create(Ci.nsIFile.NORMAL_FILE_TYPE, parseInt("0644", 8)); temporaryPaddingFile.create(Ci.nsIFile.NORMAL_FILE_TYPE, parseInt("0644", 8));
@ -20,7 +20,7 @@ function createTempPaddingFile () {
async function run_test() { async function run_test() {
do_test_pending(); do_test_pending();
create_test_profile('schema_25_profile.zip'); create_test_profile("schema_25_profile.zip");
let cache = await caches.open("test"); let cache = await caches.open("test");
// Step 1: Verify cache.match won't fail when there is a temporary padding // Step 1: Verify cache.match won't fail when there is a temporary padding

View file

@ -10,12 +10,12 @@
async function run_test() { async function run_test() {
do_test_pending(); do_test_pending();
create_test_profile('schema_25_profile.zip'); create_test_profile("schema_25_profile.zip");
let cache = await caches.open("test"); let cache = await caches.open("test");
let response = await cache.match("https://www.mozilla.org"); let response = await cache.match("https://www.mozilla.org");
ok(!!response, "Upgrade from 25 to 26 do succeed"); ok(!!response, "Upgrade from 25 to 26 do succeed");
ok(response.type === 'opaque', "The response type does be opaque"); ok(response.type === "opaque", "The response type does be opaque");
do_test_finished(); do_test_finished();
} }