mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-07 09:54:42 +00:00
Bug 1286717 - Part 2: Add mochitests for persist/persisted functions, r=janv
This commit is contained in:
parent
c9c55c765e
commit
3ee2d007ef
@ -7,6 +7,10 @@
|
||||
with Files("**"):
|
||||
BUG_COMPONENT = ("Core", "DOM: Quota Manager")
|
||||
|
||||
MOCHITEST_MANIFESTS += ['test/mochitest.ini']
|
||||
|
||||
BROWSER_CHROME_MANIFESTS += ['test/browser.ini']
|
||||
|
||||
XPCSHELL_TESTS_MANIFESTS += [
|
||||
'test/unit/xpcshell.ini'
|
||||
]
|
||||
|
10
dom/quota/test/browser.ini
Normal file
10
dom/quota/test/browser.ini
Normal file
@ -0,0 +1,10 @@
|
||||
[DEFAULT]
|
||||
skip-if = (buildapp != "browser")
|
||||
support-files =
|
||||
head.js
|
||||
browserHelpers.js
|
||||
browser_permissionsPrompt.html
|
||||
|
||||
[browser_permissionsPromptAllow.js]
|
||||
[browser_permissionsPromptDeny.js]
|
||||
[browser_permissionsPromptUnknown.js]
|
49
dom/quota/test/browserHelpers.js
Normal file
49
dom/quota/test/browserHelpers.js
Normal file
@ -0,0 +1,49 @@
|
||||
/**
|
||||
* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/
|
||||
*/
|
||||
|
||||
var testGenerator = testSteps();
|
||||
|
||||
var testResult;
|
||||
|
||||
function clearAllDatabases(callback)
|
||||
{
|
||||
let qms = SpecialPowers.Services.qms;
|
||||
let principal = SpecialPowers.wrap(document).nodePrincipal;
|
||||
let request = qms.clearStoragesForPrincipal(principal);
|
||||
let cb = SpecialPowers.wrapCallback(callback);
|
||||
request.callback = cb;
|
||||
}
|
||||
|
||||
function runTest()
|
||||
{
|
||||
clearAllDatabases(() => {
|
||||
testGenerator.next();
|
||||
});
|
||||
}
|
||||
|
||||
function finishTestNow()
|
||||
{
|
||||
if (testGenerator) {
|
||||
testGenerator.return();
|
||||
testGenerator = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
function finishTest()
|
||||
{
|
||||
clearAllDatabases(() => {
|
||||
setTimeout(finishTestNow, 0);
|
||||
setTimeout(() => {
|
||||
window.parent.postMessage(testResult, "*");
|
||||
}, 0);
|
||||
});
|
||||
}
|
||||
|
||||
function continueToNextStep()
|
||||
{
|
||||
setTimeout(() => {
|
||||
testGenerator.next();
|
||||
}, 0);
|
||||
}
|
35
dom/quota/test/browser_permissionsPrompt.html
Normal file
35
dom/quota/test/browser_permissionsPrompt.html
Normal file
@ -0,0 +1,35 @@
|
||||
<!--
|
||||
Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/
|
||||
-->
|
||||
<html>
|
||||
<head>
|
||||
<meta charset=UTF-8>
|
||||
<title>Persistent-Storage Permission Prompt Test</title>
|
||||
|
||||
<script type="text/javascript">
|
||||
function* testSteps()
|
||||
{
|
||||
SpecialPowers.pushPrefEnv({
|
||||
"set": [["dom.storageManager.enabled", true],
|
||||
["dom.storageManager.prompt.testing", false],
|
||||
["dom.storageManager.prompt.testing.allow", false]]
|
||||
}, continueToNextStep);
|
||||
yield undefined;
|
||||
|
||||
navigator.storage.persist().then(result => {
|
||||
testGenerator.next(result);
|
||||
});
|
||||
testResult = yield undefined;
|
||||
|
||||
finishTest();
|
||||
}
|
||||
</script>
|
||||
|
||||
<script type="text/javascript" src="browserHelpers.js"></script>
|
||||
|
||||
</head>
|
||||
|
||||
<body onload="runTest();" onunload="finishTestNow();"></body>
|
||||
|
||||
</html>
|
65
dom/quota/test/browser_permissionsPromptAllow.js
Normal file
65
dom/quota/test/browser_permissionsPromptAllow.js
Normal file
@ -0,0 +1,65 @@
|
||||
/**
|
||||
* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/
|
||||
*/
|
||||
|
||||
const testPageURL =
|
||||
"https://example.com/browser/dom/quota/test/browser_permissionsPrompt.html";
|
||||
|
||||
add_task(function* testPermissionAllow() {
|
||||
removePermission(testPageURL, "persistent-storage");
|
||||
info("Creating tab");
|
||||
gBrowser.selectedTab = gBrowser.addTab();
|
||||
|
||||
info("Loading test page: " + testPageURL);
|
||||
gBrowser.selectedBrowser.loadURI(testPageURL);
|
||||
yield BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser);
|
||||
|
||||
registerPopupEventHandler("popupshowing", function () {
|
||||
ok(true, "prompt showing");
|
||||
});
|
||||
registerPopupEventHandler("popupshown", function () {
|
||||
ok(true, "prompt shown");
|
||||
triggerMainCommand(this);
|
||||
});
|
||||
registerPopupEventHandler("popuphidden", function () {
|
||||
ok(true, "prompt hidden");
|
||||
});
|
||||
|
||||
yield promiseMessage(true, gBrowser);
|
||||
|
||||
is(getPermission(testPageURL, "persistent-storage"),
|
||||
Components.interfaces.nsIPermissionManager.ALLOW_ACTION,
|
||||
"Correct permission set");
|
||||
gBrowser.removeCurrentTab();
|
||||
unregisterAllPopupEventHandlers();
|
||||
// Keep persistent-storage permission for the next test.
|
||||
});
|
||||
|
||||
add_task(function* testNoPermissionPrompt() {
|
||||
info("Creating tab");
|
||||
gBrowser.selectedTab = gBrowser.addTab();
|
||||
|
||||
info("Loading test page: " + testPageURL);
|
||||
gBrowser.selectedBrowser.loadURI(testPageURL);
|
||||
yield BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser);
|
||||
|
||||
registerPopupEventHandler("popupshowing", function () {
|
||||
ok(false, "Shouldn't show a popup this time");
|
||||
});
|
||||
registerPopupEventHandler("popupshown", function () {
|
||||
ok(false, "Shouldn't show a popup this time");
|
||||
});
|
||||
registerPopupEventHandler("popuphidden", function () {
|
||||
ok(false, "Shouldn't show a popup this time");
|
||||
});
|
||||
|
||||
yield promiseMessage(true, gBrowser);
|
||||
|
||||
is(getPermission(testPageURL, "persistent-storage"),
|
||||
Components.interfaces.nsIPermissionManager.ALLOW_ACTION,
|
||||
"Correct permission set");
|
||||
gBrowser.removeCurrentTab();
|
||||
unregisterAllPopupEventHandlers();
|
||||
removePermission(testPageURL, "persistent-storage");
|
||||
});
|
95
dom/quota/test/browser_permissionsPromptDeny.js
Normal file
95
dom/quota/test/browser_permissionsPromptDeny.js
Normal file
@ -0,0 +1,95 @@
|
||||
/**
|
||||
* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/
|
||||
*/
|
||||
|
||||
const testPageURL =
|
||||
"https://example.com/browser/dom/quota/test/browser_permissionsPrompt.html";
|
||||
|
||||
add_task(function* testPermissionDenied() {
|
||||
removePermission(testPageURL, "persistent-storage");
|
||||
info("Creating tab");
|
||||
gBrowser.selectedTab = gBrowser.addTab();
|
||||
|
||||
info("Loading test page: " + testPageURL);
|
||||
gBrowser.selectedBrowser.loadURI(testPageURL);
|
||||
yield BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser);
|
||||
|
||||
registerPopupEventHandler("popupshowing", function () {
|
||||
ok(true, "prompt showing");
|
||||
});
|
||||
registerPopupEventHandler("popupshown", function () {
|
||||
ok(true, "prompt shown");
|
||||
triggerSecondaryCommand(this);
|
||||
});
|
||||
registerPopupEventHandler("popuphidden", function () {
|
||||
ok(true, "prompt hidden");
|
||||
});
|
||||
|
||||
yield promiseMessage(false, gBrowser);
|
||||
|
||||
is(getPermission(testPageURL, "persistent-storage"),
|
||||
Components.interfaces.nsIPermissionManager.DENY_ACTION,
|
||||
"Correct permission set");
|
||||
unregisterAllPopupEventHandlers();
|
||||
gBrowser.removeCurrentTab();
|
||||
// Keep persistent-storage permission for the next test.
|
||||
});
|
||||
|
||||
add_task(function* testNoPermissionPrompt() {
|
||||
info("Creating tab");
|
||||
gBrowser.selectedTab = gBrowser.addTab();
|
||||
|
||||
info("Loading test page: " + testPageURL);
|
||||
gBrowser.selectedBrowser.loadURI(testPageURL);
|
||||
yield BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser);
|
||||
|
||||
registerPopupEventHandler("popupshowing", function () {
|
||||
ok(false, "Shouldn't show a popup this time");
|
||||
});
|
||||
registerPopupEventHandler("popupshown", function () {
|
||||
ok(false, "Shouldn't show a popup this time");
|
||||
});
|
||||
registerPopupEventHandler("popuphidden", function () {
|
||||
ok(false, "Shouldn't show a popup this time");
|
||||
});
|
||||
|
||||
yield promiseMessage(false, gBrowser);
|
||||
|
||||
is(getPermission(testPageURL, "persistent-storage"),
|
||||
Components.interfaces.nsIPermissionManager.DENY_ACTION,
|
||||
"Correct permission set");
|
||||
unregisterAllPopupEventHandlers();
|
||||
gBrowser.removeCurrentTab();
|
||||
removePermission(testPageURL, "persistent-storage");
|
||||
});
|
||||
|
||||
add_task(function* testPermissionDeniedDismiss() {
|
||||
info("Creating tab");
|
||||
gBrowser.selectedTab = gBrowser.addTab();
|
||||
|
||||
info("Loading test page: " + testPageURL);
|
||||
gBrowser.selectedBrowser.loadURI(testPageURL);
|
||||
yield BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser);
|
||||
|
||||
registerPopupEventHandler("popupshowing", function () {
|
||||
ok(true, "prompt showing");
|
||||
});
|
||||
registerPopupEventHandler("popupshown", function () {
|
||||
ok(true, "prompt shown");
|
||||
// Dismiss permission prompt.
|
||||
dismissNotification(this);
|
||||
});
|
||||
registerPopupEventHandler("popuphidden", function () {
|
||||
ok(true, "prompt hidden");
|
||||
});
|
||||
|
||||
yield promiseMessage(false, gBrowser);
|
||||
|
||||
is(getPermission(testPageURL, "persistent-storage"),
|
||||
Components.interfaces.nsIPermissionManager.DENY_ACTION,
|
||||
"Correct permission set");
|
||||
unregisterAllPopupEventHandlers();
|
||||
gBrowser.removeCurrentTab();
|
||||
removePermission(testPageURL, "persistent-storage");
|
||||
});
|
40
dom/quota/test/browser_permissionsPromptUnknown.js
Normal file
40
dom/quota/test/browser_permissionsPromptUnknown.js
Normal file
@ -0,0 +1,40 @@
|
||||
/**
|
||||
* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/
|
||||
*/
|
||||
|
||||
const testPageURL =
|
||||
"https://example.com/browser/dom/quota/test/browser_permissionsPrompt.html";
|
||||
|
||||
add_task(function* testPermissionUnknownInPrivateWindow() {
|
||||
removePermission(testPageURL, "persistent-storage");
|
||||
info("Creating private window");
|
||||
let win = yield BrowserTestUtils.openNewBrowserWindow({ private : true });
|
||||
|
||||
info("Creating private tab");
|
||||
win.gBrowser.selectedTab = win.gBrowser.addTab();
|
||||
|
||||
info("Loading test page: " + testPageURL);
|
||||
win.gBrowser.selectedBrowser.loadURI(testPageURL);
|
||||
yield BrowserTestUtils.browserLoaded(win.gBrowser.selectedBrowser);
|
||||
|
||||
registerPopupEventHandler("popupshowing", function () {
|
||||
ok(false, "Shouldn't show a popup this time");
|
||||
}, win);
|
||||
registerPopupEventHandler("popupshown", function () {
|
||||
ok(false, "Shouldn't show a popup this time");
|
||||
}, win);
|
||||
registerPopupEventHandler("popuphidden", function () {
|
||||
ok(false, "Shouldn't show a popup this time");
|
||||
}, win);
|
||||
|
||||
yield promiseMessage(false, win.gBrowser);
|
||||
|
||||
is(getPermission(testPageURL, "persistent-storage"),
|
||||
Components.interfaces.nsIPermissionManager.UNKNOWN_ACTION,
|
||||
"Correct permission set");
|
||||
unregisterAllPopupEventHandlers(win);
|
||||
win.gBrowser.removeCurrentTab();
|
||||
win.close();
|
||||
removePermission(testPageURL, "persistent-storage");
|
||||
});
|
121
dom/quota/test/head.js
Normal file
121
dom/quota/test/head.js
Normal file
@ -0,0 +1,121 @@
|
||||
/**
|
||||
* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/
|
||||
*/
|
||||
|
||||
var gActiveListeners = {};
|
||||
|
||||
// These event (un)registration handlers only work for one window, DONOT use
|
||||
// them with multiple windows.
|
||||
|
||||
function registerPopupEventHandler(eventName, callback, win)
|
||||
{
|
||||
if (!win) {
|
||||
win = window;
|
||||
}
|
||||
gActiveListeners[eventName] = function (event) {
|
||||
if (event.target != win.PopupNotifications.panel)
|
||||
return;
|
||||
win.PopupNotifications.panel.removeEventListener(
|
||||
eventName,
|
||||
gActiveListeners[eventName]);
|
||||
delete gActiveListeners[eventName];
|
||||
|
||||
callback.call(win.PopupNotifications.panel);
|
||||
}
|
||||
win.PopupNotifications.panel.addEventListener(eventName,
|
||||
gActiveListeners[eventName]);
|
||||
}
|
||||
|
||||
function unregisterAllPopupEventHandlers(win)
|
||||
{
|
||||
if (!win) {
|
||||
win = window;
|
||||
}
|
||||
for (let eventName in gActiveListeners) {
|
||||
win.PopupNotifications.panel.removeEventListener(
|
||||
eventName,
|
||||
gActiveListeners[eventName]);
|
||||
}
|
||||
gActiveListeners = {};
|
||||
}
|
||||
|
||||
function triggerMainCommand(popup, win)
|
||||
{
|
||||
if (!win) {
|
||||
win = window;
|
||||
}
|
||||
info("triggering main command");
|
||||
let notifications = popup.childNodes;
|
||||
ok(notifications.length > 0, "at least one notification displayed");
|
||||
let notification = notifications[0];
|
||||
info("triggering command: " + notification.getAttribute("buttonlabel"));
|
||||
|
||||
EventUtils.synthesizeMouseAtCenter(notification.button, {}, win);
|
||||
}
|
||||
|
||||
function triggerSecondaryCommand(popup, win)
|
||||
{
|
||||
if (!win) {
|
||||
win = window;
|
||||
}
|
||||
info("triggering secondary command");
|
||||
let notifications = popup.childNodes;
|
||||
ok(notifications.length > 0, "at least one notification displayed");
|
||||
let notification = notifications[0];
|
||||
EventUtils.synthesizeMouseAtCenter(notification.secondaryButton, {}, win);
|
||||
}
|
||||
|
||||
function dismissNotification(popup, win)
|
||||
{
|
||||
if (!win) {
|
||||
win = window;
|
||||
}
|
||||
info("dismissing notification");
|
||||
executeSoon(function () {
|
||||
EventUtils.synthesizeKey("VK_ESCAPE", {}, win);
|
||||
});
|
||||
}
|
||||
|
||||
function promiseMessage(aMessage, browser)
|
||||
{
|
||||
return ContentTask.spawn(browser.selectedBrowser, aMessage, function* (aMessage) {
|
||||
yield new Promise((resolve, reject) => {
|
||||
content.addEventListener("message", function(event) {
|
||||
is(event.data, aMessage, "received " + aMessage);
|
||||
if (event.data == aMessage)
|
||||
resolve();
|
||||
else
|
||||
reject();
|
||||
}, {once: true});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function removePermission(url, permission)
|
||||
{
|
||||
let uri = Components.classes["@mozilla.org/network/io-service;1"]
|
||||
.getService(Components.interfaces.nsIIOService)
|
||||
.newURI(url);
|
||||
let ssm = Components.classes["@mozilla.org/scriptsecuritymanager;1"]
|
||||
.getService(Ci.nsIScriptSecurityManager);
|
||||
let principal = ssm.createCodebasePrincipal(uri, {});
|
||||
|
||||
Components.classes["@mozilla.org/permissionmanager;1"]
|
||||
.getService(Components.interfaces.nsIPermissionManager)
|
||||
.removeFromPrincipal(principal, permission);
|
||||
}
|
||||
|
||||
function getPermission(url, permission)
|
||||
{
|
||||
let uri = Components.classes["@mozilla.org/network/io-service;1"]
|
||||
.getService(Components.interfaces.nsIIOService)
|
||||
.newURI(url);
|
||||
let ssm = Components.classes["@mozilla.org/scriptsecuritymanager;1"]
|
||||
.getService(Ci.nsIScriptSecurityManager);
|
||||
let principal = ssm.createCodebasePrincipal(uri, {});
|
||||
|
||||
return Components.classes["@mozilla.org/permissionmanager;1"]
|
||||
.getService(Components.interfaces.nsIPermissionManager)
|
||||
.testPermissionFromPrincipal(principal, permission);
|
||||
}
|
293
dom/quota/test/helpers.js
Normal file
293
dom/quota/test/helpers.js
Normal file
@ -0,0 +1,293 @@
|
||||
/**
|
||||
* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/
|
||||
*/
|
||||
|
||||
var testGenerator = testSteps();
|
||||
|
||||
function clearAllDatabases(callback)
|
||||
{
|
||||
let qms = SpecialPowers.Services.qms;
|
||||
let principal = SpecialPowers.wrap(document).nodePrincipal;
|
||||
let request = qms.clearStoragesForPrincipal(principal);
|
||||
let cb = SpecialPowers.wrapCallback(callback);
|
||||
request.callback = cb;
|
||||
}
|
||||
|
||||
var testHarnessGenerator = testHarnessSteps();
|
||||
testHarnessGenerator.next();
|
||||
|
||||
function* testHarnessSteps()
|
||||
{
|
||||
function nextTestHarnessStep(val)
|
||||
{
|
||||
testHarnessGenerator.next(val);
|
||||
}
|
||||
|
||||
let testScriptPath;
|
||||
let testScriptFilename;
|
||||
|
||||
let scripts = document.getElementsByTagName("script");
|
||||
for (let i = 0; i < scripts.length; i++) {
|
||||
let src = scripts[i].src;
|
||||
let match = src.match(/quota\/test\/unit\/(test_[^\/]+\.js)$/);
|
||||
if (match && match.length == 2) {
|
||||
testScriptPath = src;
|
||||
testScriptFilename = match[1];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
yield undefined;
|
||||
|
||||
info("Clearing old databases");
|
||||
|
||||
clearAllDatabases(nextTestHarnessStep);
|
||||
yield undefined;
|
||||
|
||||
info("Running" +
|
||||
(testScriptFilename ? " '" + testScriptFilename + "'" : ""));
|
||||
|
||||
if (testScriptFilename && !window.disableWorkerTest) {
|
||||
info("Running test in a worker");
|
||||
|
||||
let workerScriptBlob =
|
||||
new Blob([ "(" + workerScript.toString() + ")();" ],
|
||||
{ type: "text/javascript" });
|
||||
let workerScriptURL = URL.createObjectURL(workerScriptBlob);
|
||||
|
||||
let worker = new Worker(workerScriptURL);
|
||||
|
||||
worker.onerror = function(event) {
|
||||
ok(false, "Worker had an error: " + event.message);
|
||||
worker.terminate();
|
||||
nextTestHarnessStep();
|
||||
};
|
||||
|
||||
worker.onmessage = function(event) {
|
||||
let message = event.data;
|
||||
switch (message.op) {
|
||||
case "ok":
|
||||
ok(message.condition, message.name, message.diag);
|
||||
break;
|
||||
|
||||
case "todo":
|
||||
todo(message.condition, message.name, message.diag);
|
||||
break;
|
||||
|
||||
case "info":
|
||||
info(message.msg);
|
||||
break;
|
||||
|
||||
case "ready":
|
||||
worker.postMessage({ op: "load", files: [ testScriptPath ] });
|
||||
break;
|
||||
|
||||
case "loaded":
|
||||
worker.postMessage({ op: "start" });
|
||||
break;
|
||||
|
||||
case "done":
|
||||
ok(true, "Worker finished");
|
||||
nextTestHarnessStep();
|
||||
break;
|
||||
|
||||
case "clearAllDatabases":
|
||||
clearAllDatabases(function(){
|
||||
worker.postMessage({ op: "clearAllDatabasesDone" });
|
||||
});
|
||||
break;
|
||||
|
||||
default:
|
||||
ok(false,
|
||||
"Received a bad message from worker: " + JSON.stringify(message));
|
||||
nextTestHarnessStep();
|
||||
}
|
||||
};
|
||||
|
||||
URL.revokeObjectURL(workerScriptURL);
|
||||
|
||||
yield undefined;
|
||||
|
||||
worker.terminate();
|
||||
worker = null;
|
||||
|
||||
clearAllDatabases(nextTestHarnessStep);
|
||||
yield undefined;
|
||||
} else if (testScriptFilename) {
|
||||
todo(false,
|
||||
"Skipping test in a worker because it is explicitly disabled: " +
|
||||
disableWorkerTest);
|
||||
} else {
|
||||
todo(false,
|
||||
"Skipping test in a worker because it's not structured properly");
|
||||
}
|
||||
|
||||
info("Running test in main thread");
|
||||
|
||||
// Now run the test script in the main thread.
|
||||
testGenerator.next();
|
||||
|
||||
yield undefined;
|
||||
}
|
||||
|
||||
if (!window.runTest) {
|
||||
window.runTest = function()
|
||||
{
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
testHarnessGenerator.next();
|
||||
}
|
||||
}
|
||||
|
||||
function finishTest()
|
||||
{
|
||||
SimpleTest.executeSoon(function() {
|
||||
clearAllDatabases(function() { SimpleTest.finish(); });
|
||||
});
|
||||
}
|
||||
|
||||
function grabArgAndContinueHandler(arg)
|
||||
{
|
||||
testGenerator.next(arg);
|
||||
}
|
||||
|
||||
function continueToNextStep()
|
||||
{
|
||||
SimpleTest.executeSoon(function() {
|
||||
testGenerator.next();
|
||||
});
|
||||
}
|
||||
|
||||
function continueToNextStepSync()
|
||||
{
|
||||
testGenerator.next();
|
||||
}
|
||||
|
||||
function workerScript()
|
||||
{
|
||||
"use strict";
|
||||
|
||||
self.repr = function(_thing_) {
|
||||
if (typeof(_thing_) == "undefined") {
|
||||
return "undefined";
|
||||
}
|
||||
|
||||
let str;
|
||||
|
||||
try {
|
||||
str = _thing_ + "";
|
||||
} catch (e) {
|
||||
return "[" + typeof(_thing_) + "]";
|
||||
}
|
||||
|
||||
if (typeof(_thing_) == "function") {
|
||||
str = str.replace(/^\s+/, "");
|
||||
let idx = str.indexOf("{");
|
||||
if (idx != -1) {
|
||||
str = str.substr(0, idx) + "{...}";
|
||||
}
|
||||
}
|
||||
|
||||
return str;
|
||||
};
|
||||
|
||||
self.ok = function(_condition_, _name_, _diag_) {
|
||||
self.postMessage({ op: "ok",
|
||||
condition: !!_condition_,
|
||||
name: _name_,
|
||||
diag: _diag_ });
|
||||
};
|
||||
|
||||
self.is = function(_a_, _b_, _name_) {
|
||||
let pass = (_a_ == _b_);
|
||||
let diag = pass ? "" : "got " + repr(_a_) + ", expected " + repr(_b_);
|
||||
ok(pass, _name_, diag);
|
||||
};
|
||||
|
||||
self.isnot = function(_a_, _b_, _name_) {
|
||||
let pass = (_a_ != _b_);
|
||||
let diag = pass ? "" : "didn't expect " + repr(_a_) + ", but got it";
|
||||
ok(pass, _name_, diag);
|
||||
};
|
||||
|
||||
self.todo = function(_condition_, _name_, _diag_) {
|
||||
self.postMessage({ op: "todo",
|
||||
condition: !!_condition_,
|
||||
name: _name_,
|
||||
diag: _diag_ });
|
||||
};
|
||||
|
||||
self.info = function(_msg_) {
|
||||
self.postMessage({ op: "info", msg: _msg_ });
|
||||
};
|
||||
|
||||
self.executeSoon = function(_fun_) {
|
||||
var channel = new MessageChannel();
|
||||
channel.port1.postMessage("");
|
||||
channel.port2.onmessage = function(event) { _fun_(); };
|
||||
};
|
||||
|
||||
self.finishTest = function() {
|
||||
self.postMessage({ op: "done" });
|
||||
};
|
||||
|
||||
self.grabArgAndContinueHandler = function(_arg_) {
|
||||
testGenerator.next(_arg_);
|
||||
};
|
||||
|
||||
self.continueToNextStep = function() {
|
||||
executeSoon(function() {
|
||||
testGenerator.next();
|
||||
});
|
||||
};
|
||||
|
||||
self.continueToNextStepSync = function() {
|
||||
testGenerator.next();
|
||||
};
|
||||
|
||||
self._clearAllDatabasesCallback = undefined;
|
||||
self.clearAllDatabases = function(_callback_) {
|
||||
self._clearAllDatabasesCallback = _callback_;
|
||||
self.postMessage({ op: "clearAllDatabases" });
|
||||
}
|
||||
|
||||
self.onerror = function(_message_, _file_, _line_) {
|
||||
ok(false,
|
||||
"Worker: uncaught exception [" + _file_ + ":" + _line_ + "]: '" +
|
||||
_message_ + "'");
|
||||
self.finishTest();
|
||||
self.close();
|
||||
return true;
|
||||
};
|
||||
|
||||
self.onmessage = function(_event_) {
|
||||
let message = _event_.data;
|
||||
switch (message.op) {
|
||||
case "load":
|
||||
info("Worker: loading " + JSON.stringify(message.files));
|
||||
self.importScripts(message.files);
|
||||
self.postMessage({ op: "loaded" });
|
||||
break;
|
||||
|
||||
case "start":
|
||||
executeSoon(function() {
|
||||
info("Worker: starting tests");
|
||||
testGenerator.next();
|
||||
});
|
||||
break;
|
||||
|
||||
case "clearAllDatabasesDone":
|
||||
info("Worker: all databases are cleared");
|
||||
if (self._clearAllDatabasesCallback) {
|
||||
self._clearAllDatabasesCallback();
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new Error("Received a bad message from parent: " +
|
||||
JSON.stringify(message));
|
||||
}
|
||||
};
|
||||
|
||||
self.postMessage({ op: "ready" });
|
||||
}
|
17
dom/quota/test/mochitest.ini
Normal file
17
dom/quota/test/mochitest.ini
Normal file
@ -0,0 +1,17 @@
|
||||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
[DEFAULT]
|
||||
support-files =
|
||||
helpers.js
|
||||
unit/test_storage_manager_persist_allow.js
|
||||
unit/test_storage_manager_persist_deny.js
|
||||
unit/test_storage_manager_persisted.js
|
||||
|
||||
[test_storage_manager_persist_allow.html]
|
||||
scheme=https
|
||||
[test_storage_manager_persist_deny.html]
|
||||
scheme=https
|
||||
[test_storage_manager_persisted.html]
|
||||
scheme=https
|
19
dom/quota/test/test_storage_manager_persist_allow.html
Normal file
19
dom/quota/test/test_storage_manager_persist_allow.html
Normal file
@ -0,0 +1,19 @@
|
||||
<!--
|
||||
Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/
|
||||
-->
|
||||
<html>
|
||||
<head>
|
||||
<title>Allow Persist Prompt for StorageManager</title>
|
||||
|
||||
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||
|
||||
<script type="text/javascript" src="unit/test_storage_manager_persist_allow.js"></script>
|
||||
<script type="text/javascript" src="helpers.js"></script>
|
||||
|
||||
</head>
|
||||
|
||||
<body onload="runTest();"></body>
|
||||
|
||||
</html>
|
19
dom/quota/test/test_storage_manager_persist_deny.html
Normal file
19
dom/quota/test/test_storage_manager_persist_deny.html
Normal file
@ -0,0 +1,19 @@
|
||||
<!--
|
||||
Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/
|
||||
-->
|
||||
<html>
|
||||
<head>
|
||||
<title>Deny Persist Prompt for StorageManager</title>
|
||||
|
||||
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||
|
||||
<script type="text/javascript" src="unit/test_storage_manager_persist_deny.js"></script>
|
||||
<script type="text/javascript" src="helpers.js"></script>
|
||||
|
||||
</head>
|
||||
|
||||
<body onload="runTest();"></body>
|
||||
|
||||
</html>
|
19
dom/quota/test/test_storage_manager_persisted.html
Normal file
19
dom/quota/test/test_storage_manager_persisted.html
Normal file
@ -0,0 +1,19 @@
|
||||
<!--
|
||||
Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/
|
||||
-->
|
||||
<html>
|
||||
<head>
|
||||
<title>Storage Manager Persisted Test</title>
|
||||
|
||||
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||
|
||||
<script type="text/javascript" src="unit/test_storage_manager_persisted.js"></script>
|
||||
<script type="text/javascript" src="helpers.js"></script>
|
||||
|
||||
</head>
|
||||
|
||||
<body onload="runTest();"></body>
|
||||
|
||||
</html>
|
24
dom/quota/test/unit/test_storage_manager_persist_allow.js
Normal file
24
dom/quota/test/unit/test_storage_manager_persist_allow.js
Normal file
@ -0,0 +1,24 @@
|
||||
var disableWorkerTest = "Persist doesn't work in workers";
|
||||
var testGenerator = testSteps();
|
||||
|
||||
function* testSteps()
|
||||
{
|
||||
SpecialPowers.pushPrefEnv({
|
||||
"set": [["dom.storageManager.enabled", true],
|
||||
["dom.storageManager.prompt.testing", true],
|
||||
["dom.storageManager.prompt.testing.allow", true]]
|
||||
}, continueToNextStep);
|
||||
yield undefined;
|
||||
|
||||
navigator.storage.persist().then(grabArgAndContinueHandler);
|
||||
let persistResult = yield undefined;
|
||||
|
||||
is(persistResult, true, "Persist succeeded");
|
||||
|
||||
navigator.storage.persisted().then(grabArgAndContinueHandler);
|
||||
let persistedResult = yield undefined;
|
||||
|
||||
is(persistResult, persistedResult, "Persist/persisted results are consistent");
|
||||
|
||||
finishTest();
|
||||
}
|
24
dom/quota/test/unit/test_storage_manager_persist_deny.js
Normal file
24
dom/quota/test/unit/test_storage_manager_persist_deny.js
Normal file
@ -0,0 +1,24 @@
|
||||
var disableWorkerTest = "Persist doesn't work in workers";
|
||||
var testGenerator = testSteps();
|
||||
|
||||
function* testSteps()
|
||||
{
|
||||
SpecialPowers.pushPrefEnv({
|
||||
"set": [["dom.storageManager.enabled", true],
|
||||
["dom.storageManager.prompt.testing", true],
|
||||
["dom.storageManager.prompt.testing.allow", false]]
|
||||
}, continueToNextStep);
|
||||
yield undefined;
|
||||
|
||||
navigator.storage.persist().then(grabArgAndContinueHandler);
|
||||
let persistResult = yield undefined;
|
||||
|
||||
is(persistResult, false, "Cancel the persist prompt and resolve a promise with false");
|
||||
|
||||
navigator.storage.persisted().then(grabArgAndContinueHandler);
|
||||
let persistedResult = yield undefined;
|
||||
|
||||
is(persistResult, persistedResult, "Persist/persisted results are consistent");
|
||||
|
||||
finishTest();
|
||||
}
|
11
dom/quota/test/unit/test_storage_manager_persisted.js
Normal file
11
dom/quota/test/unit/test_storage_manager_persisted.js
Normal file
@ -0,0 +1,11 @@
|
||||
var testGenerator = testSteps();
|
||||
|
||||
function* testSteps()
|
||||
{
|
||||
navigator.storage.persisted().then(grabArgAndContinueHandler);
|
||||
let persistedResult = yield undefined;
|
||||
|
||||
is(persistedResult, false, "Persisted returns false");
|
||||
|
||||
finishTest();
|
||||
}
|
@ -5655,6 +5655,9 @@ pref("dom.storageManager.enabled", true);
|
||||
pref("dom.storageManager.enabled", false);
|
||||
#endif
|
||||
|
||||
pref("dom.storageManager.prompt.testing", false);
|
||||
pref("dom.storageManager.prompt.testing.allow", false);
|
||||
|
||||
// Enable the Storage management in about:preferences and persistent-storage permission request
|
||||
// To enable the DOM implementation, turn on "dom.storageManager.enabled"
|
||||
#ifdef NIGHTLY_BUILD
|
||||
|
Loading…
Reference in New Issue
Block a user