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

View file

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

View file

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

View file

@ -1,9 +1,9 @@
// Touch CacheStorage, but then idle and do nothing.
const name = 'idle_worker_cache';
const name = "idle_worker_cache";
var cache;
self.caches.open(name).then(c => {
cache = c;
return self.caches.delete(name);
}).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;
var iframe;
window.addEventListener("message",function onMessage(event) {
window.addEventListener("message", function onMessage(event) {
if (event.data.context != "ServiceWorker") {
return;
}
if (event.data.type == 'finish') {
if (event.data.type == "finish") {
window.removeEventListener("message", onMessage);
iframe.remove();
registration.unregister()
.then(resolve)
.catch(reject);
} else if (event.data.type == 'status') {
} else if (event.data.type == "status") {
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 response = new Response("This is some Response!");
var name = 'snafu' + context;
var foobar = 'foobar' + context;
var name = "snafu" + 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) {
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);
}).then(function(hasResult) {
ok(hasResult, 'caches.has() should resolve true');
ok(hasResult, "caches.has() should resolve true");
return caches.keys();
}).then(function(keys) {
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.includes(name), 'caches.keys() should resolve to an array containing key');
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.includes(name), "caches.keys() should resolve to an array containing key");
return caches.delete(name);
}).then(function(deleteResult) {
ok(deleteResult, 'caches.delete() should resolve true');
ok(deleteResult, "caches.delete() should resolve true");
return caches.has(name);
}).then(function(hasMissingCache) {
ok(!hasMissingCache, 'missing key should return false from has');
ok(!hasMissingCache, "missing key should return false from has");
}).then(function() {
return caches.open(name);
}).then(function(snafu) {
return snafu.keys();
}).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() {
return caches.open(name);
}).then(function(snafu) {
var req = './cachekey';
var req = "./cachekey";
var res = new Response("Hello world");
return snafu.put('ftp://invalid', res).then(function() {
ok(false, 'This should fail');
}).catch(function (err) {
is(err.name, 'TypeError', 'put() should throw TypeError for invalid scheme');
return snafu.put("ftp://invalid", res).then(function() {
ok(false, "This should fail");
}).catch(function(err) {
is(err.name, "TypeError", "put() should throw TypeError for invalid scheme");
return snafu.put(req, res);
}).then(function(v) {
return snafu;
@ -45,20 +45,20 @@ caches.open(name).then(function(openCache) {
}).then(function(args) {
var snafu = args[0];
var keys = args[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].url.match(/cachekey$/), 'Request URL should match original');
return Promise.all([snafu, snafu.match(keys[0]), snafu.match('ftp://invalid')]);
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].url.match(/cachekey$/), "Request URL should match original");
return Promise.all([snafu, snafu.match(keys[0]), snafu.match("ftp://invalid")]);
}).then(function(args) {
var snafu = args[0];
var response = args[1];
ok(response instanceof Response, 'value should be a Response');
is(response.status, 200, 'Response status should be 200');
is(undefined, args[2], 'Match with invalid scheme should resolve undefined');
return Promise.all([snafu, snafu.put('./cachekey2', response)]);
ok(response instanceof Response, "value should be a Response");
is(response.status, 200, "Response status should be 200");
is(undefined, args[2], "Match with invalid scheme should resolve undefined");
return Promise.all([snafu, snafu.put("./cachekey2", response)]);
}).then(function(args) {
var snafu = args[0]
return snafu.match('./cachekey2');
var snafu = args[0];
return snafu.match("./cachekey2");
}).then(function(response) {
return response.text().then(function(v) {
is(v, "Hello world", "Response body should match original");
@ -72,60 +72,60 @@ caches.open(name).then(function(openCache) {
c = openCache;
return c.put(request, response);
}).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);
}).then(function(keys) {
ok(keys, 'Valid keys object expected');
is(keys.length, 1, 'Only one key is expected');
ok(keys, "Valid keys object expected");
is(keys.length, 1, "Only one key is expected");
return c.keys();
}).then(function(keys) {
ok(keys, 'Valid keys object expected');
is(keys.length, 1, 'Only one key is expected');
ok(keys, "Valid keys object expected");
is(keys.length, 1, "Only one key is expected");
return c.matchAll(request);
}).then(function(matchAllResponses) {
ok(matchAllResponses, 'matchAll should succeed');
is(matchAllResponses.length, 1, 'Only one match is expected');
ok(matchAllResponses, "matchAll should succeed");
is(matchAllResponses.length, 1, "Only one match is expected");
return c.match(request);
}).then(function(matchResponse) {
ok(matchResponse, 'match should succeed');
ok(matchResponse, "match should succeed");
return caches.match(request);
}).then(function(storageMatchResponse) {
ok(storageMatchResponse, 'storage match should succeed');
return caches.match(request, {cacheName:foobar});
ok(storageMatchResponse, "storage match should succeed");
return caches.match(request, {cacheName: foobar});
}).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);
return c.match(request2, {ignoreSearch:true});
return c.match(request2, {ignoreSearch: true});
}).then(function(match2Response) {
ok(match2Response, 'match should succeed');
ok(match2Response, "match should succeed");
return c.delete(request);
}).then(function(deleteResult) {
ok(deleteResult, 'delete should succeed');
ok(deleteResult, "delete should succeed");
return c.keys();
}).then(function(keys) {
ok(keys, 'Valid keys object expected');
is(keys.length, 0, 'Zero keys is expected');
ok(keys, "Valid keys object expected");
is(keys.length, 0, "Zero keys is expected");
return c.matchAll(request);
}).then(function(matchAll2Responses) {
ok(matchAll2Responses, 'matchAll should succeed');
is(matchAll2Responses.length, 0, 'Zero matches is expected');
ok(matchAll2Responses, "matchAll should succeed");
is(matchAll2Responses.length, 0, "Zero matches is expected");
return caches.has(foobar);
}).then(function(hasResult) {
ok(hasResult, 'has should succeed');
ok(hasResult, "has should succeed");
return caches.keys();
}).then(function(keys) {
ok(keys, 'Valid keys object expected');
ok(keys.length >= 2, 'At least two keys are expected');
ok(keys.includes(name), 'snafu should exist');
ok(keys.indexOf(foobar) >= keys.indexOf(name), 'foobar should come after it');
ok(keys, "Valid keys object expected");
ok(keys.length >= 2, "At least two keys are expected");
ok(keys.includes(name), "snafu should exist");
ok(keys.indexOf(foobar) >= keys.indexOf(name), "foobar should come after it");
return caches.delete(foobar);
}).then(function(deleteResult) {
ok(deleteResult, 'delete should succeed');
ok(deleteResult, "delete should succeed");
return caches.has(foobar);
}).then(function(hasMissingCache) {
ok(!hasMissingCache, 'has should have a result');
ok(!hasMissingCache, "has should have a result");
return caches.delete(name);
}).then(function(deleteResult) {
ok(deleteResult, 'delete should succeed');
ok(deleteResult, "delete should succeed");
testDone();
})
});

View file

@ -1,55 +1,55 @@
var singleUrl = './test_cache_add.js';
var singleUrl = "./test_cache_add.js";
var urlList = [
'./empty.html',
'./frame.html',
'./test_cache.js'
"./empty.html",
"./frame.html",
"./test_cache.js",
];
var cache;
var name = "adder" + context;
caches.open(name).then(function(openCache) {
cache = openCache;
return cache.add('ftp://example.com/invalid' + context);
}).catch(function (err) {
is(err.name, 'TypeError', 'add() should throw TypeError for invalid scheme');
return cache.addAll(['http://example.com/valid' + context, 'ftp://example.com/invalid' + context]);
}).catch(function (err) {
is(err.name, 'TypeError', 'addAll() should throw TypeError for invalid scheme');
return cache.add("ftp://example.com/invalid" + context);
}).catch(function(err) {
is(err.name, "TypeError", "add() should throw TypeError for invalid scheme");
return cache.addAll(["http://example.com/valid" + context, "ftp://example.com/invalid" + context]);
}).catch(function(err) {
is(err.name, "TypeError", "addAll() should throw TypeError for invalid scheme");
var promiseList = urlList.map(function(url) {
return cache.match(url);
});
promiseList.push(cache.match(singleUrl));
return Promise.all(promiseList);
}).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) {
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);
}).then(function(result) {
is(undefined, result, 'Successful add() should resolve undefined');
is(undefined, result, "Successful add() should resolve undefined");
return cache.addAll(urlList);
}).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) {
return cache.match(url);
});
promiseList.push(cache.match(singleUrl));
return Promise.all(promiseList);
}).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) {
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();
}).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) {
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);
}).then(function() {
testDone();
}).catch(function(err) {
ok(false, 'Caught error: ' + err);
ok(false, "Caught error: " + err);
testDone();
});

View file

@ -1,11 +1,11 @@
var cache = null;
var name = 'https_' + context;
var urlBase = 'https://example.com/tests/dom/cache/test/mochitest';
var url1 = urlBase + '/test_cache.js';
var url2 = urlBase + '/test_cache_add.js';
var name = "https_" + context;
var urlBase = "https://example.com/tests/dom/cache/test/mochitest";
var url1 = urlBase + "/test_cache.js";
var url2 = urlBase + "/test_cache_add.js";
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);
});
}
@ -14,18 +14,18 @@ caches.open(name).then(function(c) {
cache = c;
return Promise.all([
addOpaque(cache, url1),
addOpaque(cache, url2)
addOpaque(cache, url2),
]);
}).then(function() {
return cache.delete(url1);
}).then(function(result) {
ok(result, 'Cache entry should be deleted');
ok(result, "Cache entry should be deleted");
return cache.delete(url2);
}).then(function(result) {
ok(result, 'Cache entry should be deleted');
ok(result, "Cache entry should be deleted");
cache = null;
return caches.delete(name);
}).then(function(result) {
ok(result, 'Cache should be deleted');
ok(result, "Cache should be deleted");
testDone();
});

View file

@ -45,7 +45,7 @@ caches.open(name).then(function(cache) {
return Promise.all(
["POST", "PUT", "DELETE", "OPTIONS"]
.map(function(method) {
var req = new Request(tests[2], {method: method});
var req = new Request(tests[2], {method});
return c.keys(req)
.then(function(keys) {
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(
["HEAD", "POST", "PUT", "DELETE", "OPTIONS"]
.map(function(method) {
var r = new Request(request1, {method: method});
var r = new Request(request1, {method});
return c.add(r)
.then(function() {
ok(false, "Promise should be rejected");
@ -86,7 +86,7 @@ function testRequest(request1, request2, request3, unknownRequest,
return Promise.all(
["HEAD", "POST", "PUT", "DELETE", "OPTIONS"]
.map(function(method) {
var req = new Request(request1, {method: method});
var req = new Request(request1, {method});
return c.matchAll(req)
.then(function(r) {
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");
return Promise.all([
checkResponse(r[0], response1, response1Text),
checkResponse(r[1], response3, response3Text)
checkResponse(r[1], response3, response3Text),
]);
}).then(function() {
return c.matchAll(request3);
@ -122,15 +122,15 @@ function testRequest(request1, request2, request3, unknownRequest,
is(r.length, 2, "Should find 2 items");
return Promise.all([
checkResponse(r[0], response1, response1Text),
checkResponse(r[1], response3, response3Text)
checkResponse(r[1], response3, response3Text),
]);
}).then(function() {
return caches.match(request1, {cacheName: name + "mambojambo"})
.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");
}).then(function(hasCache) {
ok(!hasCache, 'The wrong cache should still not exist');
ok(!hasCache, "The wrong cache should still not exist");
});
}).then(function() {
return c.matchAll(unknownRequest);
@ -164,7 +164,7 @@ function testRequest(request1, request2, request3, unknownRequest,
is(r.length, 2, "Should find 2 items");
return Promise.all([
checkResponse(r[0], response1, response1Text),
checkResponse(r[1], response3, response3Text)
checkResponse(r[1], response3, response3Text),
]);
}).then(function() {
// 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(
["HEAD", "POST", "PUT", "DELETE", "OPTIONS"]
.map(function(method) {
var r = new Request(request, {method: method});
var r = new Request(request, {method});
return c.add(r)
.then(function() {
ok(false, "Promise should be rejected");
@ -72,7 +72,7 @@ function testRequest(request, unknownRequest, requestWithAlternateQueryString,
return Promise.all(
["HEAD", "POST", "PUT", "DELETE", "OPTIONS"]
.map(function(method) {
var req = new Request(request, {method: method});
var req = new Request(request, {method});
return c.match(req)
.then(function(r) {
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() {
return caches.match(request, {cacheName: name + "mambojambo"})
.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");
}).then(function(hasCache) {
ok(!hasCache, 'The wrong cache should still not exist');
ok(!hasCache, "The wrong cache should still not exist");
});
}).then(function() {
// 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}));
}));
}).then(function() {
resolve({response: response, responseText: responseText, cache: cache});
resolve({response, responseText, cache});
}).catch(function(err) {
reject(err);
});
@ -257,7 +257,7 @@ function testMultipleCacheEntries() {
]).then(function(t) {
test = t;
return test.cache.matchAll();
}).then(function (r) {
}).then(function(r) {
is(r.length, 2, "Two cache entries should be stored in the DB");
// Ensure that searching without specifying an Accept-Language header fails.
return test.cache.matchAll(requestURL);

View file

@ -64,7 +64,7 @@ function workerGroupUsage() {
URL.createObjectURL(new Blob(["(", workerScript.toSource(), ")()"]));
let worker = new Worker(url);
worker.onmessage = function (e) {
worker.onmessage = function(e) {
resolve(e.data, 0);
};
});
@ -92,14 +92,14 @@ SpecialPowers.pushPrefEnv({
["dom.quotaManager.testing", true],
["dom.storageManager.enabled", true]],
}, function() {
var name = 'orphanedBodyOwner';
var name = "orphanedBodyOwner";
var cache = null;
var response = null;
var initialUsage = 0;
var fullUsage = 0;
var resetUsage = 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
// results
@ -108,7 +108,7 @@ SpecialPowers.pushPrefEnv({
}).then(function() {
return storageUsage();
}).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
@ -122,7 +122,7 @@ SpecialPowers.pushPrefEnv({
}).then(function() {
return caches.delete(name);
}).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
// fully deleted before we proceed. The deletion actually takes place in
@ -167,7 +167,7 @@ SpecialPowers.pushPrefEnv({
return storageUsage();
}).then(function(usage) {
fullUsage = usage;
ok(fullUsage > initialUsage, 'disk usage should have grown');
ok(fullUsage > initialUsage, "disk usage should have grown");
})
// Test groupUsage()
@ -177,7 +177,7 @@ SpecialPowers.pushPrefEnv({
return groupUsage();
}).then(function(usage) {
fullUsage = usage;
ok(fullUsage > initialUsage, 'disk group usage should have grown');
ok(fullUsage > initialUsage, "disk group usage should have grown");
})
// Test workerGroupUsage()
@ -187,7 +187,7 @@ SpecialPowers.pushPrefEnv({
return workerGroupUsage();
}).then(function(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
@ -195,7 +195,7 @@ SpecialPowers.pushPrefEnv({
.then(function() {
return caches.match(url);
}).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
@ -209,21 +209,21 @@ SpecialPowers.pushPrefEnv({
endUsage = usage;
dump("### ### initial:" + initialUsage + ", full:" + fullUsage +
", end:" + endUsage + "\n");
ok(endUsage < fullUsage, 'disk usage should have shrank');
is(endUsage, initialUsage, 'disk usage should return to original');
ok(endUsage < fullUsage, "disk usage should have shrank");
is(endUsage, initialUsage, "disk usage should return to original");
})
// Verify that the stale, orphaned response cannot be put back into
// the cache.
.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() {
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) {
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() {
ok(response.bodyUsed, 'attempting to store response should mark body used');
ok(response.bodyUsed, "attempting to store response should mark body used");
})
.then(function() {

View file

@ -65,13 +65,13 @@ SpecialPowers.pushPrefEnv({
["dom.caches.testing.enabled", true],
["dom.quotaManager.testing", true]],
}, function() {
var name = 'toBeOrphaned';
var name = "toBeOrphaned";
var cache = null;
var initialUsage = 0;
var fullUsage = 0;
var resetUsage = 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
// results
@ -80,7 +80,7 @@ SpecialPowers.pushPrefEnv({
}).then(function() {
return storageUsage();
}).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
@ -94,7 +94,7 @@ SpecialPowers.pushPrefEnv({
}).then(function() {
return caches.delete(name);
}).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
// fully deleted before we proceed. The deletion actually takes place in
@ -122,7 +122,7 @@ SpecialPowers.pushPrefEnv({
}).then(function() {
return caches.delete(name);
}).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
@ -133,7 +133,7 @@ SpecialPowers.pushPrefEnv({
return storageUsage();
}).then(function(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
@ -141,7 +141,7 @@ SpecialPowers.pushPrefEnv({
.then(function() {
return caches.has(name);
}).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
@ -155,8 +155,8 @@ SpecialPowers.pushPrefEnv({
endUsage = usage;
dump("### ### initial:" + initialUsage + ", full:" + fullUsage +
", end:" + endUsage + "\n");
ok(endUsage < fullUsage, 'disk usage should have shrank');
is(endUsage, initialUsage, 'disk usage should return to original');
ok(endUsage < fullUsage, "disk usage should have shrank");
is(endUsage, initialUsage, "disk usage should return to original");
SimpleTest.finish();
});
});

View file

@ -87,9 +87,8 @@ SimpleTest.waitForExplicitFinish();
SpecialPowers.pushPrefEnv({
"set": [["dom.caches.enabled", true],
["dom.caches.testing.enabled", true],
["dom.quotaManager.testing", true]]
["dom.quotaManager.testing", true]],
}, async function() {
// This test is mainly to verify we only generate different padding size for
// the opaque response which is comming from netwrok.
// 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
// be changed. Thus, it makes the attacker harder to get the padding size.
const name = 'cachePadding';
const other_name = 'cachePaddingOther';
const cors_base = 'https://example.com/test/dom/cache/test/mochitest/';
const url = 'test_cache_add.js';
const name = "cachePadding";
const other_name = "cachePaddingOther";
const cors_base = "https://example.com/test/dom/cache/test/mochitest/";
const url = "test_cache_add.js";
await setupTestIframe();

View file

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

View file

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

View file

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

View file

@ -65,7 +65,7 @@ SpecialPowers.pushPrefEnv({
["dom.caches.testing.enabled", true],
["dom.quotaManager.testing", true]],
}, function() {
var name = 'foo';
var name = "foo";
var cache = null;
var initialUsage = 0;
var fullUsage = 0;
@ -77,7 +77,7 @@ SpecialPowers.pushPrefEnv({
}).then(function() {
return storageUsage();
}).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);
}).then(function(c) {
cache = c;
@ -90,7 +90,7 @@ SpecialPowers.pushPrefEnv({
}).then(function() {
return cache.keys();
}).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;
// Ensure the Cache DOM object is gone before proceeding. If its alive
// it will keep the related entries on-disk as well.
@ -102,10 +102,10 @@ SpecialPowers.pushPrefEnv({
return storageUsage();
}).then(function(usage) {
fullUsage = usage;
ok(fullUsage > initialUsage, 'disk usage should have grown');
ok(fullUsage > initialUsage, "disk usage should have grown");
return caches.delete(name);
}).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
// fully deleted before we proceed. The deletion actually takes place in
// 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.
return caches.has(name);
}).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
return resetStorage();
}).then(function() {
@ -122,8 +122,8 @@ SpecialPowers.pushPrefEnv({
endUsage = usage;
dump("### ### initial:" + initialUsage + ", full:" + fullUsage +
", end:" + endUsage + "\n");
ok(endUsage < (fullUsage / 2), 'disk usage should have shrank significantly');
ok(endUsage > initialUsage, 'disk usage should not shrink back to orig size');
ok(endUsage < (fullUsage / 2), "disk usage should have shrank significantly");
ok(endUsage > initialUsage, "disk usage should not shrink back to orig size");
SimpleTest.finish();
});
});

View file

@ -34,8 +34,8 @@ function clearStorage() {
async function testCreateTonsOfFD() {
const number_of_fd = 5120;
const name = 'cacheTonsOfFD';
const url = "foo.com"
const name = "cacheTonsOfFD";
const url = "foo.com";
const body = "This is a body";
info("Stage A: Cached a Request/Response pairs");
@ -54,30 +54,30 @@ async function testCreateTonsOfFD() {
try {
cached_response_array = await Promise.all(promise_array);
} 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) {
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) {
if (!cached_response_array[i]) {
// Reduce the checking message.
throw("The cached response doesn't exist");
throw ("The cached response doesn't exist");
}
let bodyText = "";
try {
bodyText = await cached_response_array[i].text();
} 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) {
// 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({
"set": [["dom.caches.enabled", true],
["dom.caches.testing.enabled", true],
["dom.quotaManager.testing", true]]
["dom.quotaManager.testing", true]],
}, async function() {
await setupTestIframe();

View file

@ -27,11 +27,11 @@ SpecialPowers.pushPrefEnv({
"set": [["dom.caches.enabled", true]],
}, function() {
setupTestIframe().then(function() {
return caches.open('foo');
return caches.open("foo");
}).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) {
is(err.name, 'SecurityError', 'caches should reject with SecurityError');
is(err.name, "SecurityError", "caches should reject with SecurityError");
SimpleTest.finish();
});
});

View file

@ -83,11 +83,11 @@ SimpleTest.waitForExplicitFinish();
SpecialPowers.pushPrefEnv({
"set": [["dom.caches.enabled", true],
["dom.caches.testing.enabled", true],
["dom.quotaManager.testing", true]]
["dom.quotaManager.testing", true]],
}, async function() {
const name = 'cacheUpdateUsage';
const url = 'test_cache_add.js';
const other_url = 'test_cache_put.js';
const name = "cacheUpdateUsage";
const url = "test_cache_add.js";
const other_url = "test_cache_put.js";
// This test mainly ensure DOM Cache updates its usage to QuotaManager when
// 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.");
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
// the runnables have been flushed through the threads.
await caches.has(name);

View file

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

View file

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

View file

@ -28,59 +28,54 @@
function workerTestExec(script) {
return new Promise(function(resolve, reject) {
var worker = new Worker('worker_wrapper.js');
var worker = new Worker("worker_wrapper.js");
worker.onmessage = function(event) {
is(event.data.context, "Worker",
"Correct context for messages received on the worker");
if (event.data.type == 'finish') {
if (event.data.type == "finish") {
worker.terminate();
SpecialPowers.forceGC();
resolve();
} else if (event.data.type == 'status') {
} else if (event.data.type == "status") {
ok(event.data.status, event.data.context + ": " + event.data.msg);
} else if (event.data.type == 'getPrefs') {
} else if (event.data.type == "getPrefs") {
var result = {};
event.data.prefs.forEach(function(pref) {
result[pref] = SpecialPowers.Services.prefs.getBoolPref(pref);
});
worker.postMessage({
type: 'returnPrefs',
type: "returnPrefs",
prefs: event.data.prefs,
result: result
result,
});
} else if (event.data.type == 'getPermissions') {
} else if (event.data.type == "getPermissions") {
var result = {};
event.data.permissions.forEach(function(permission) {
result[permission] = SpecialPowers.hasPermission(permission, window.document);
});
worker.postMessage({
type: 'returnPermissions',
type: "returnPermissions",
permissions: event.data.permissions,
result: result
result,
});
} else if (event.data.type == 'getVersion') {
var result = SpecialPowers.Cc['@mozilla.org/xre/app-info;1'].getService(SpecialPowers.Ci.nsIXULAppInfo).version;
} else if (event.data.type == "getVersion") {
var result = SpecialPowers.Cc["@mozilla.org/xre/app-info;1"].getService(SpecialPowers.Ci.nsIXULAppInfo).version;
worker.postMessage({
type: 'returnVersion',
result: result
type: "returnVersion",
result,
});
} else if (event.data.type == 'getUserAgent') {
} else if (event.data.type == "getUserAgent") {
worker.postMessage({
type: 'returnUserAgent',
result: navigator.userAgent
type: "returnUserAgent",
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;
function ok(a, msg) {
client.postMessage({type: 'status', status: !!a,
msg: a + ": " + msg, context: context});
client.postMessage({type: "status", status: !!a,
msg: a + ": " + msg, context});
}
function is(a, b, msg) {
client.postMessage({type: 'status', status: a === b,
msg: a + " === " + b + ": " + msg, context: context });
client.postMessage({type: "status", status: a === b,
msg: a + " === " + b + ": " + msg, context });
}
function workerTestArrayEquals(a, b) {
@ -29,83 +29,83 @@ function workerTestArrayEquals(a, b) {
}
function testDone() {
client.postMessage({ type: 'finish', context: context });
client.postMessage({ type: "finish", context });
}
function workerTestGetPrefs(prefs, cb) {
addEventListener('message', function workerTestGetPrefsCB(e) {
if (e.data.type != 'returnPrefs' ||
addEventListener("message", function workerTestGetPrefsCB(e) {
if (e.data.type != "returnPrefs" ||
!workerTestArrayEquals(prefs, e.data.prefs)) {
return;
}
removeEventListener('message', workerTestGetPrefsCB);
removeEventListener("message", workerTestGetPrefsCB);
cb(e.data.result);
});
client.postMessage({
type: 'getPrefs',
context: context,
prefs: prefs
type: "getPrefs",
context,
prefs,
});
}
function workerTestGetPermissions(permissions, cb) {
addEventListener('message', function workerTestGetPermissionsCB(e) {
if (e.data.type != 'returnPermissions' ||
addEventListener("message", function workerTestGetPermissionsCB(e) {
if (e.data.type != "returnPermissions" ||
!workerTestArrayEquals(permissions, e.data.permissions)) {
return;
}
removeEventListener('message', workerTestGetPermissionsCB);
removeEventListener("message", workerTestGetPermissionsCB);
cb(e.data.result);
});
client.postMessage({
type: 'getPermissions',
context: context,
permissions: permissions
type: "getPermissions",
context,
permissions,
});
}
function workerTestGetVersion(cb) {
addEventListener('message', function workerTestGetVersionCB(e) {
if (e.data.type !== 'returnVersion') {
addEventListener("message", function workerTestGetVersionCB(e) {
if (e.data.type !== "returnVersion") {
return;
}
removeEventListener('message', workerTestGetVersionCB);
removeEventListener("message", workerTestGetVersionCB);
cb(e.data.result);
});
client.postMessage({
context: context,
type: 'getVersion'
context,
type: "getVersion",
});
}
function workerTestGetUserAgent(cb) {
addEventListener('message', function workerTestGetUserAgentCB(e) {
if (e.data.type !== 'returnUserAgent') {
addEventListener("message", function workerTestGetUserAgentCB(e) {
if (e.data.type !== "returnUserAgent") {
return;
}
removeEventListener('message', workerTestGetUserAgentCB);
removeEventListener("message", workerTestGetUserAgentCB);
cb(e.data.result);
});
client.postMessage({
context: context,
type: 'getUserAgent'
context,
type: "getUserAgent",
});
}
var completeInstall = null;
addEventListener('message', function workerWrapperOnMessage(e) {
removeEventListener('message', workerWrapperOnMessage);
addEventListener("message", function workerWrapperOnMessage(e) {
removeEventListener("message", workerWrapperOnMessage);
var data = e.data;
function runScript() {
try {
importScripts(data.script);
} catch(e) {
} catch (e) {
client.postMessage({
type: 'status',
type: "status",
status: false,
context: context,
msg: 'worker failed to import ' + data.script + "; error: " + e.message
context,
msg: "worker failed to import " + data.script + "; error: " + e.message,
});
}
}
@ -133,4 +133,4 @@ addEventListener('message', function workerWrapperOnMessage(e) {
addEventListener("install", e => {
e.waitUntil(new Promise(resolve => completeInstall = resolve));
})
});

View file

@ -7,29 +7,29 @@
*/
// 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);
var sts = Cc['@mozilla.org/network/stream-transport-service;1']
var sts = Cc["@mozilla.org/network/stream-transport-service;1"]
.getService(Ci.nsIStreamTransportService);
var hash = Cc['@mozilla.org/security/hash;1']
var hash = Cc["@mozilla.org/security/hash;1"]
.createInstance(Ci.nsICryptoHash);
// 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
function create_test_profile(zipFileName) {
do_get_profile();
var directoryService = Cc['@mozilla.org/file/directory_service;1']
var directoryService = Cc["@mozilla.org/file/directory_service;1"]
.getService(Ci.nsIProperties);
var profileDir = directoryService.get('ProfD', Ci.nsIFile);
var currentDir = directoryService.get('CurWorkD', Ci.nsIFile);
var profileDir = directoryService.get("ProfD", Ci.nsIFile);
var currentDir = directoryService.get("CurWorkD", Ci.nsIFile);
var packageFile = currentDir.clone();
packageFile.append(zipFileName);
var zipReader = Cc['@mozilla.org/libjar/zip-reader;1']
var zipReader = Cc["@mozilla.org/libjar/zip-reader;1"]
.createInstance(Ci.nsIZipReader);
zipReader.open(packageFile);
@ -40,20 +40,20 @@ function create_test_profile(zipFileName) {
var zipentry = zipReader.getEntry(entryName);
var file = profileDir.clone();
entryName.split('/').forEach(function(part) {
entryName.split("/").forEach(function(part) {
file.append(part);
});
if (zipentry.isDirectory) {
file.create(Ci.nsIFile.DIRECTORY_TYPE, parseInt('0755', 8));
file.create(Ci.nsIFile.DIRECTORY_TYPE, parseInt("0755", 8));
} else {
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);
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);
bostream.init(ostream, 32 * 1024);
@ -67,8 +67,7 @@ function create_test_profile(zipFileName) {
zipReader.close();
}
function getCacheDir()
{
function getCacheDir() {
let dirService = Cc["@mozilla.org/file/directory_service;1"]
.getService(Ci.nsIProperties);

View file

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

View file

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

View file

@ -8,42 +8,42 @@
function run_test() {
do_test_pending();
create_test_profile('schema_15_profile.zip');
create_test_profile("schema_15_profile.zip");
var cache;
caches.open('xpcshell-test').then(function(c) {
caches.open("xpcshell-test").then(function(c) {
cache = c;
ok(cache, 'cache exists');
ok(cache, "cache exists");
return cache.keys();
}).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) {
ok(request, 'each request in list should be non-null');
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.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, "each request in list should be non-null");
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.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"');
});
return Promise.all(requestList.map(function(request) {
return cache.match(request);
}));
}).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) {
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
// 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
// be false since current reponse.url is a empty string.
ok(response.redirected === false, 'each response.redirected in list should be false');
Assert.equal(response.headers.get('Content-Type'), 'text/plain;charset=UTF-8',
'the response should have the correct header');
ok(response.redirected === false, "each response.redirected in list should be false");
Assert.equal(response.headers.get("Content-Type"), "text/plain;charset=UTF-8",
"the response should have the correct header");
});
}).then(function() {
do_test_finished();
}).catch(function(e) {
ok(false, 'caught exception ' + e);
ok(false, "caught exception " + e);
do_test_finished();
});
}

View file

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

View file

@ -10,12 +10,12 @@
async function run_test() {
do_test_pending();
create_test_profile('schema_25_profile.zip');
create_test_profile("schema_25_profile.zip");
let cache = await caches.open("test");
let response = await cache.match("https://www.mozilla.org");
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();
}