mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 877478 - Fix tests that depend on creating verboten instances in content. r=mrbkap
XPConnect generally throws when trying to create instances of non-DOM objects in content. Due to some bugs this has historically worked in certain cases, but we're fixing those now. So we need to fix the tests that do this sort of thing.
This commit is contained in:
parent
8860c38ac0
commit
03e356bde0
@ -23,9 +23,9 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=470804
|
||||
|
||||
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
|
||||
const nsIScriptSecurityManager = Components.interfaces.nsIScriptSecurityManager;
|
||||
var secMan = Components.classes["@mozilla.org/scriptsecuritymanager;1"]
|
||||
var secMan = SpecialPowers.Cc["@mozilla.org/scriptsecuritymanager;1"]
|
||||
.getService(nsIScriptSecurityManager);
|
||||
var principal = SpecialPowers.getNodePrincipal(document);
|
||||
var principal = SpecialPowers.wrap(document).nodePrincipal;
|
||||
isnot(principal, undefined, "Should have a principal");
|
||||
isnot(principal, null, "Should have a non-null principal");
|
||||
is(secMan.isSystemPrincipal(principal), false,
|
||||
|
@ -29,12 +29,11 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=353334
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
|
||||
function doPrincipalTest(id) {
|
||||
var doc = $(id).contentDocument;
|
||||
var doc = SpecialPowers.wrap($(id).contentDocument);
|
||||
|
||||
isnot(SpecialPowers.getNodePrincipal(doc), undefined, "Should have a principal");
|
||||
isnot(SpecialPowers.getNodePrincipal(doc), null, "Should have a non-null principal");
|
||||
is(SpecialPowers.getNodePrincipal(doc),
|
||||
SpecialPowers.getNodePrincipal(document),
|
||||
isnot(doc.nodePrincipal, undefined, "Should have a principal");
|
||||
isnot(doc.nodePrincipal, null, "Should have a non-null principal");
|
||||
is(doc.nodePrincipal.origin, SpecialPowers.wrap(document).nodePrincipal.origin,
|
||||
"Wrong principal for document in node with id='" + id + "'");
|
||||
}
|
||||
|
||||
@ -44,8 +43,7 @@ function doContentTest(id) {
|
||||
}
|
||||
|
||||
function checkPrincipal() {
|
||||
is(SpecialPowers.getNodePrincipal(document) instanceof SpecialPowers.Ci.nsIPrincipal,
|
||||
true,
|
||||
ok(SpecialPowers.call_Instanceof(SpecialPowers.wrap(document).nodePrincipal, SpecialPowers.Ci.nsIPrincipal),
|
||||
"Should be a principal");
|
||||
}
|
||||
|
||||
|
@ -115,19 +115,19 @@ function runTests() {
|
||||
l2 = document.getElementById("testlevel2");
|
||||
l3 = document.getElementById("testlevel3");
|
||||
var textnode = l3.firstChild;
|
||||
var chain = SpecialPowers.unwrap(els.getEventTargetChainFor(textnode, {}));
|
||||
var chain = els.getEventTargetChainFor(textnode, {});
|
||||
ok(chain.length > 3, "Too short event target chain.");
|
||||
is(chain[0], textnode, "Wrong chain item (1)");
|
||||
is(chain[1], l3, "Wrong chain item (2)");
|
||||
is(chain[2], l2, "Wrong chain item (3)");
|
||||
is(chain[3], root, "Wrong chain item (4)");
|
||||
ok(SpecialPowers.compare(chain[0], textnode), "Wrong chain item (1)");
|
||||
ok(SpecialPowers.compare(chain[1], l3), "Wrong chain item (2)");
|
||||
ok(SpecialPowers.compare(chain[2], l2), "Wrong chain item (3)");
|
||||
ok(SpecialPowers.compare(chain[3], root), "Wrong chain item (4)");
|
||||
|
||||
var hasDocumentInChain = false;
|
||||
var hasWindowInChain = false;
|
||||
for (var i = 0; i < chain.length; ++i) {
|
||||
if (chain[i] == document) {
|
||||
if (SpecialPowers.compare(chain[i], document)) {
|
||||
hasDocumentInChain = true;
|
||||
} else if (chain[i] == window) {
|
||||
} else if (SpecialPowers.compare(chain[i], window)) {
|
||||
hasWindowInChain = true;
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ browserElementTestHelpers.addPermission();
|
||||
var iframe;
|
||||
|
||||
function runTest() {
|
||||
var principal = SpecialPowers.wrap(SpecialPowers.getNodePrincipal(document));
|
||||
var principal = SpecialPowers.wrap(document).nodePrincipal;
|
||||
SpecialPowers.addPermission("browser", true, { url: SpecialPowers.wrap(principal.URI).spec,
|
||||
appId: principal.appId,
|
||||
isInBrowserElement: true });
|
||||
@ -74,7 +74,7 @@ function finish() {
|
||||
// the /next/ test to fail!
|
||||
iframe.removeEventListener('mozbrowsershowmodalprompt', checkMessage);
|
||||
|
||||
var principal = SpecialPowers.wrap(SpecialPowers.getNodePrincipal(document));
|
||||
var principal = SpecialPowers.wrap(document).nodePrincipal;
|
||||
SpecialPowers.removePermission("browser", { url: SpecialPowers.wrap(principal.URI).spec,
|
||||
appId: principal.appId,
|
||||
isInBrowserElement: true });
|
||||
|
@ -11,7 +11,7 @@ browserElementTestHelpers.setEnabledPref(true);
|
||||
browserElementTestHelpers.addPermission();
|
||||
|
||||
function runTest() {
|
||||
var principal = SpecialPowers.wrap(SpecialPowers.getNodePrincipal(document));
|
||||
var principal = SpecialPowers.wrap(document).nodePrincipal;
|
||||
SpecialPowers.addPermission("browser", true, { url: SpecialPowers.wrap(principal.URI).spec,
|
||||
appId: principal.appId,
|
||||
isInBrowserElement: true });
|
||||
@ -55,7 +55,7 @@ function runTest() {
|
||||
}
|
||||
|
||||
function finish() {
|
||||
var principal = SpecialPowers.wrap(SpecialPowers.getNodePrincipal(document));
|
||||
var principal = SpecialPowers.wrap(document).nodePrincipal;
|
||||
SpecialPowers.removePermission("browser", { url: SpecialPowers.wrap(principal.URI).spec,
|
||||
appId: principal.appId,
|
||||
isInBrowserElement: true });
|
||||
|
@ -21,13 +21,13 @@ browserElementTestHelpers.enableProcessPriorityManager();
|
||||
SpecialPowers.addPermission("embed-apps", true, document);
|
||||
|
||||
// Give our origin permission to open browsers, and remove it when the test is complete.
|
||||
var principal = SpecialPowers.wrap(SpecialPowers.getNodePrincipal(document));
|
||||
var principal = SpecialPowers.wrap(document).nodePrincipal;
|
||||
SpecialPowers.addPermission("browser", true, { url: SpecialPowers.wrap(principal.URI).spec,
|
||||
appId: principal.appId,
|
||||
isInBrowserElement: true });
|
||||
|
||||
addEventListener('unload', function() {
|
||||
var principal = SpecialPowers.wrap(SpecialPowers.getNodePrincipal(document));
|
||||
var principal = SpecialPowers.wrap(document).nodePrincipal;
|
||||
SpecialPowers.removePermission("browser", { url: SpecialPowers.wrap(principal.URI).spec,
|
||||
appId: principal.appId,
|
||||
isInBrowserElement: true });
|
||||
|
@ -20,13 +20,13 @@ browserElementTestHelpers.addPermission();
|
||||
browserElementTestHelpers.enableProcessPriorityManager();
|
||||
|
||||
// Give our origin permission to open browsers, and remove it when the test is complete.
|
||||
var principal = SpecialPowers.wrap(SpecialPowers.getNodePrincipal(document));
|
||||
var principal = SpecialPowers.wrap(document).nodePrincipal;
|
||||
SpecialPowers.addPermission("browser", true, { url: SpecialPowers.wrap(principal.URI).spec,
|
||||
appId: principal.appId,
|
||||
isInBrowserElement: true });
|
||||
|
||||
addEventListener('unload', function() {
|
||||
var principal = SpecialPowers.wrap(SpecialPowers.getNodePrincipal(document));
|
||||
var principal = SpecialPowers.wrap(document).nodePrincipal;
|
||||
SpecialPowers.removePermission("browser", { url: SpecialPowers.wrap(principal.URI).spec,
|
||||
appId: principal.appId,
|
||||
isInBrowserElement: true });
|
||||
|
@ -176,14 +176,18 @@ function getUsage(usageHandler)
|
||||
let quotaManager = comp.classes["@mozilla.org/dom/quota/manager;1"]
|
||||
.getService(comp.interfaces.nsIQuotaManager);
|
||||
|
||||
let uri = SpecialPowers.getDocumentURIObject(window.document);
|
||||
let callback = {
|
||||
onUsageResult: function(uri, usage, fileUsage) {
|
||||
usageHandler(usage, fileUsage);
|
||||
}
|
||||
};
|
||||
// We need to pass a JS callback to getUsageForURI. However, that callback
|
||||
// takes an XPCOM URI object, which will cause us to throw when we wrap it
|
||||
// for the content compartment. So we need to define the function in a
|
||||
// privileged scope, which we do using a sandbox.
|
||||
var sysPrin = SpecialPowers.Services.scriptSecurityManager.getSystemPrincipal();
|
||||
var sb = new SpecialPowers.Cu.Sandbox(sysPrin);
|
||||
sb.usageHandler = usageHandler;
|
||||
var cb = SpecialPowers.Cu.evalInSandbox((function(uri, usage, fileUsage) {
|
||||
usageHandler(usage, fileUsage); }).toSource(), sb);
|
||||
|
||||
quotaManager.getUsageForURI(uri, callback);
|
||||
let uri = SpecialPowers.wrap(window).document.documentURIObject;
|
||||
quotaManager.getUsageForURI(uri, cb);
|
||||
}
|
||||
|
||||
function scheduleGC()
|
||||
|
@ -49,17 +49,27 @@ function clearAllDatabases(callback) {
|
||||
comp.classes["@mozilla.org/dom/quota/manager;1"]
|
||||
.getService(comp.interfaces.nsIQuotaManager);
|
||||
|
||||
let uri = SpecialPowers.getDocumentURIObject(document);
|
||||
let uri = SpecialPowers.wrap(document).documentURIObject;
|
||||
|
||||
quotaManager.clearStoragesForURI(uri);
|
||||
quotaManager.getUsageForURI(uri, function(uri, usage, fileUsage) {
|
||||
// We need to pass a JS callback to getUsageForURI. However, that callback
|
||||
// takes an XPCOM URI object, which will cause us to throw when we wrap it
|
||||
// for the content compartment. So we need to define the function in a
|
||||
// privileged scope, which we do using a sandbox.
|
||||
var sysPrin = SpecialPowers.Services.scriptSecurityManager.getSystemPrincipal();
|
||||
var sb = new SpecialPowers.Cu.Sandbox(sysPrin);
|
||||
sb.ok = ok;
|
||||
sb.runCallback = runCallback;
|
||||
var cb = SpecialPowers.Cu.evalInSandbox((function(uri, usage, fileUsage) {
|
||||
if (usage) {
|
||||
ok(false,
|
||||
"getUsageForURI returned non-zero usage after clearing all " +
|
||||
"storages!");
|
||||
}
|
||||
runCallback();
|
||||
});
|
||||
}).toSource(), sb);
|
||||
|
||||
quotaManager.clearStoragesForURI(uri);
|
||||
quotaManager.getUsageForURI(uri, cb);
|
||||
}
|
||||
|
||||
if (!window.runTest) {
|
||||
|
@ -62,7 +62,7 @@ function do_test() {
|
||||
|
||||
try {
|
||||
var res = utils.getBindingURLs(docElement);
|
||||
is(SpecialPowers.unwrap(res) instanceof SpecialPowers.Ci["nsIArray"], true, "getBindingURLs result type");
|
||||
ok(SpecialPowers.call_Instanceof(res, SpecialPowers.Ci["nsIArray"]), "getBindingURLs result type");
|
||||
is(res.length, 0, "getBindingURLs array length");
|
||||
}
|
||||
catch(e) { ok(false, "got an unexpected exception:" + e); }
|
||||
|
@ -55,7 +55,7 @@ function starttest(){
|
||||
ok(app != null, "Got an app ");
|
||||
|
||||
var origin = app.origin
|
||||
var nodePrincipal = SpecialPowers.getNodePrincipal(document);
|
||||
var nodePrincipal = SpecialPowers.wrap(document).nodePrincipal;
|
||||
var appPrincipal = createPrincipal(manifest, true);
|
||||
var noappPrincipal = createPrincipal(origin, false);
|
||||
|
||||
|
@ -1269,18 +1269,6 @@ SpecialPowersAPI.prototype = {
|
||||
addCategoryEntry(category, entry, value, persists, replace);
|
||||
},
|
||||
|
||||
getNodePrincipal: function(aNode) {
|
||||
return aNode.nodePrincipal;
|
||||
},
|
||||
|
||||
getNodeBaseURIObject: function(aNode) {
|
||||
return aNode.baseURIObject;
|
||||
},
|
||||
|
||||
getDocumentURIObject: function(aDocument) {
|
||||
return aDocument.documentURIObject;
|
||||
},
|
||||
|
||||
copyString: function(str, doc) {
|
||||
Components.classes["@mozilla.org/widget/clipboardhelper;1"].
|
||||
getService(Components.interfaces.nsIClipboardHelper).
|
||||
|
Loading…
Reference in New Issue
Block a user