Bug 914940 - Remove some enablePrivilige calls. r=jgriffin

This commit is contained in:
Martijn Wargers 2013-09-11 10:51:09 +02:00
parent dcd5e57578
commit 3c5aa5b67c
33 changed files with 48 additions and 149 deletions

View File

@ -21,10 +21,8 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=470804
Passing a null targetURL to checkLoadURIWithPrincipal shouldn't crash
**/
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
const nsIScriptSecurityManager = Components.interfaces.nsIScriptSecurityManager;
var secMan = SpecialPowers.Cc["@mozilla.org/scriptsecuritymanager;1"]
.getService(nsIScriptSecurityManager);
const nsIScriptSecurityManager = SpecialPowers.Ci.nsIScriptSecurityManager;
var secMan = SpecialPowers.Services.scriptSecurityManager;
var principal = SpecialPowers.wrap(document).nodePrincipal;
isnot(principal, undefined, "Should have a principal");
isnot(principal, null, "Should have a non-null principal");

View File

@ -30,12 +30,10 @@ function getLoadContext() {
}
function testCopyPaste (isXHTML) {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var suppressUnicodeCheckIfHidden = !!isXHTML;
var suppressHTMLCheck = !!isXHTML;
var webnav = window.QueryInterface(SpecialPowers.Ci.nsIInterfaceRequestor)
var webnav = SpecialPowers.wrap(window).QueryInterface(SpecialPowers.Ci.nsIInterfaceRequestor)
.getInterface(SpecialPowers.Ci.nsIWebNavigation)
var docShell = webnav.QueryInterface(SpecialPowers.Ci.nsIDocShell);
@ -43,8 +41,7 @@ function testCopyPaste (isXHTML) {
var documentViewer = docShell.contentViewer
.QueryInterface(SpecialPowers.Ci.nsIContentViewerEdit);
var clipboard = SpecialPowers.Cc["@mozilla.org/widget/clipboard;1"]
.getService(SpecialPowers.Ci.nsIClipboard);
var clipboard = SpecialPowers.Services.clipboard;
var textarea = SpecialPowers.wrap(document.getElementById('input'));
@ -88,14 +85,14 @@ function testCopyPaste (isXHTML) {
transferable.init(getLoadContext());
transferable.addDataFlavor(mime);
clipboard.getData(transferable, 1);
var data = {};
var data = SpecialPowers.createBlankObject();
transferable.getTransferData(mime, data, {}) ;
return data;
}
function testClipboardValue(mime, expected) {
if (suppressHTMLCheck && mime == "text/html")
return null;
var data = getClipboardData(mime);
var data = SpecialPowers.wrap(getClipboardData(mime));
is (data.value == null ? data.value :
data.value.QueryInterface(SpecialPowers.Ci.nsISupportsString).data,
expected,

View File

@ -12,11 +12,8 @@ function run() {
}
function forcegc(){
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
Components.utils.forceGC();
var wu = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsIDOMWindowUtils);
wu.garbageCollect();
SpecialPowers.forceGC();
SpecialPowers.gc();
}
</script>

View File

@ -38,8 +38,6 @@ testDoc2.appendChild(testDoc2.createElement("res"));
testDoc2.documentElement.appendChild(testDoc2.createTextNode("text"));
is(testDoc2.inputEncoding, null, "wrong encoding");
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var testData = "blahblahblahblahblahblahblaaaaaaaah. blah.";
var extensions = [".txt",".png",".jpg",".gif",".xml", "noext"];
var fileTypes = ["text/plain", "image/png", "image/jpeg", "image/gif", "text/xml", null];
@ -72,14 +70,13 @@ extensions.forEach(
testFiles.push(testFile);
var fileList = document.getElementById('fileList');
fileList.value = testFile.path;
SpecialPowers.wrap(fileList).value = testFile.path;
testDOMFiles.push(fileList.files[0]);
}
);
function createFileWithDataExt(fileData, extension) {
var dirSvc = SpecialPowers.Cc["@mozilla.org/file/directory_service;1"].getService(SpecialPowers.Ci.nsIProperties);
var testFile = dirSvc.get("ProfD", SpecialPowers.Ci.nsIFile);
var testFile = SpecialPowers.Services.dirsvc.get("ProfD", SpecialPowers.Ci.nsIFile);
testFile.append("testfile" + extension);
var outStream = SpecialPowers.Cc["@mozilla.org/network/file-output-stream;1"].createInstance(SpecialPowers.Ci.nsIFileOutputStream);
outStream.init(testFile, 0x02 | 0x08 | 0x20, 0666, 0);

View File

@ -65,8 +65,6 @@ function runNextTest() {
if (tests.length > 0) {
var test = tests.shift();
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
// Initialize state variables
testName = test[0]
currentState = 0;

View File

@ -33,10 +33,7 @@ function runTest() {
xhr.open("GET", "test_bug382871.html");
xhr.send();
xhr = null;
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsIDOMWindowUtils)
.garbageCollect();
SpecialPowers.gc();
}
SimpleTest.waitForExplicitFinish();

View File

@ -21,14 +21,11 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=403852
<pre id="test">
<script class="testbody" type="text/javascript">
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var dirSvc = SpecialPowers.Cc["@mozilla.org/file/directory_service;1"].getService(SpecialPowers.Ci.nsIProperties);
var testFile = dirSvc.get("ProfD", SpecialPowers.Ci.nsIFile);
var testFile = SpecialPowers.Services.dirsvc.get("ProfD", SpecialPowers.Ci.nsIFile);
testFile.append("prefs.js");
var fileList = document.getElementById('fileList');
fileList.value = testFile.path;
SpecialPowers.wrap(fileList).value = testFile.path;
// Make sure the file is accessible with indexed notation
var domFile = fileList.files[0];

View File

@ -21,16 +21,13 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=416383
/** Test for Bug 416383 **/
function runTest() {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var testParent = document.getElementById("test_parent");
var attrs = testParent.firstChild.attributes;
ok(attrs != null, "Element should have attributes!");
var attr = testParent.firstChild.getAttributeNode("someattr");
ok(attr.value == "foo", "The value of the attribute should be 'foo'!");
testParent.removeChild(testParent.firstChild);
window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsIDOMWindowUtils)
.garbageCollect();
SpecialPowers.gc();
ok(true, "Browser should not crash!")
}

View File

@ -23,13 +23,6 @@ SimpleTest.waitForExplicitFinish();
var img1loaded = false;
var img1errored = false;
function gc() {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsIDOMWindowUtils)
.garbageCollect();
}
// Our test image
function loadTestImage() {
var img1 = new Image();
@ -46,7 +39,7 @@ function loadTestImage() {
loadTestImage();
// Probably overkill to gc() more than once, but let's be safe
gc(); gc(); gc();
SpecialPowers.gc(); SpecialPowers.gc(); SpecialPowers.gc();
function finishTest() {
is(img1errored, true, "Image 1 should error");

View File

@ -19,13 +19,6 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=448993
/** Test for Bug 448993 **/
function gc() {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsIDOMWindowUtils)
.garbageCollect();
}
function runTest() {
var a = document.getElementById("a");
var b = document.getElementById("b");
@ -37,7 +30,7 @@ function runTest() {
r.extractContents();
var s = document.createRange();
s.setEnd(b, 0);
gc();
SpecialPowers.gc();
s.deleteContents();
ok(true, "test did not crash");
SimpleTest.finish();

View File

@ -20,14 +20,11 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=456262
/** Test for Bug 456262 **/
function runTest() {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
document.expando = document;
document.documentElement.expando = document;
document.documentElement.setAttribute("foo", "bar");
document.documentElement.getAttributeNode("foo").expando = document;
window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsIDOMWindowUtils)
.garbageCollect();
SpecialPowers.gc();
ok(document.expando, "Should have preserved the expando!");
ok(document.documentElement.expando, "Should have preserved the expando!");
ok(document.documentElement.getAttributeNode('foo').expando,

View File

@ -20,16 +20,9 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=459424
/** Test for Bug 459424 **/
SimpleTest.waitForExplicitFinish();
addLoadEvent(function() {
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
var viewer =
window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsIWebNavigation)
.QueryInterface(Components.interfaces.nsIDocShell)
.contentViewer
.QueryInterface(Components.interfaces.nsIMarkupDocumentViewer);
viewer.fullZoom = 2;
SpecialPowers.setFullZoom(window, 2);
is(true, true, "Gotta test something");
viewer.fullZoom = 1;
SpecialPowers.setFullZoom(window, 1);
SimpleTest.finish();
});
</script>

View File

@ -19,19 +19,12 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=465767
/** Test for Bug 465767 **/
function CC() {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsIDOMWindowUtils)
.garbageCollect();
}
function runTest() {
var node = document.createElement("div");
var e = null;
try {
document.implementation.createDocument("", "", null).adoptNode(node);
CC();
SpecialPowers.gc();
document.implementation.createDocument("", "", null).adoptNode(node);
} catch(ex) {
e = ex;

View File

@ -19,12 +19,10 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=592829
// If we ever change how DOMParser initilization works, just update this code
// to create a DOMParser which is not allowed to parse XUL.
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var isXUL = true;
try {
var x =
Components.classes["@mozilla.org/xmlextras/domparser;1"]
SpecialPowers.Cc
.getService(Components.interfaces.nsIDOMParser)
.parseFromString('<overlay xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"/>', "text/xml");
isXUL = x.documentElement.namespaceURI ==

View File

@ -209,10 +209,8 @@ function getFile(name) {
basePath = xhr.responseText;
}
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var fileList = document.getElementById('fileList');
fileList.value = basePath + name;
SpecialPowers.wrap(fileList).value = basePath + name;
return fileList.files[0];
}

View File

@ -90,10 +90,7 @@ function start() {
kOS = OS_WINDOWS;
// code borrowed from browser/modules/test/browser_taskbar_preview.js
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
var version = SpecialPowers.Cc['@mozilla.org/system-info;1']
.getService(SpecialPowers.Ci.nsIPropertyBag2)
.getProperty('version');
var version = SpecialPowers.Services.sysinfo.getProperty('version');
kOSVersion = parseFloat(version);
// Version 6.0 is Vista, 6.1 is 7.
} else if (navigator.platform.indexOf('Mac') == 0) {
@ -139,7 +136,6 @@ function start() {
requestLongerTimeoutLen = 6;
function getEnv(env) {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var envsvc = SpecialPowers.Cc["@mozilla.org/process/environment;1"].getService(SpecialPowers.Ci.nsIEnvironment);
var val = envsvc.get(env);
if (val == "")

View File

@ -49,8 +49,7 @@ function isRectContainedInRectFromRegion(rect, region) {
}
function paintListener(e) {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
if (isRectContainedInRectFromRegion(buttonRect(), e.clientRects)) {
if (isRectContainedInRectFromRegion(buttonRect(), SpecialPowers.wrap(e).clientRects)) {
gNeedsPaint = false;
currentSnapshot = takeSnapshot();
}

View File

@ -65,8 +65,7 @@ function isRectContainedInRectFromRegion(rect, region) {
}
function paintListener(e) {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
if (isRectContainedInRectFromRegion(buttonRect(), e.clientRects)) {
if (isRectContainedInRectFromRegion(buttonRect(), SpecialPowers.wrap(e).clientRects)) {
gNeedsPaint = false;
currentSnapshot = takeSnapshot();
}

View File

@ -52,9 +52,7 @@ function clickHandler(e) {
function doTest() {
window.addEventListener("click", clickHandler, true);
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
var utils = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor).
getInterface(Components.interfaces.nsIDOMWindowUtils);
var utils = SpecialPowers.getDOMWindowUtils(window);
utils.sendMouseEvent("mousedown", 1, 1, 0, 1, 0);
utils.sendMouseEvent("mouseup", 1, 1, 0, 1, 0);

View File

@ -151,8 +151,7 @@ function runTests() {
}
function dispatchTrusted(t, o) {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
t.dispatchEvent(new Event("testevent", o));
SpecialPowers.dispatchEvent(window, t, new Event("testevent", o));
}
function testAllListener() {

View File

@ -20,14 +20,11 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=450876
/** Test for Bug 450876 **/
function doTest() {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
is(document.activeElement, document.body, "body element should be focused");
document.getElementById('a').focus();
is(document.activeElement, document.getElementById('a'), "link should have focus");
var wu = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsIDOMWindowUtils);
is(document.hasFocus(), true, "document should be focused");
wu.sendKeyEvent('keypress', 9, 0, 0);
SpecialPowers.DOMWindowUtils.sendKeyEvent('keypress', 9, 0, 0);
is(document.activeElement, document.getElementById('a'), "body element should be focused");
is(document.hasFocus(), false, "document should not be focused");

View File

@ -23,12 +23,11 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=456273
/** Test for Bug 456273 **/
function doTest() {
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
var ev = document.createEvent('KeyEvents');
ev.initKeyEvent("keypress", true, true, null, true, false,
false, false, 0, "z".charCodeAt(0));
document.getElementById('edit456273').dispatchEvent(ev);
SpecialPowers.dispatchEvent(window, document.getElementById('edit456273'), ev);
ok(true, "PASS");
SimpleTest.finish();
}

View File

@ -21,19 +21,14 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=605242
SimpleTest.waitForExplicitFinish();
var utils = SpecialPowers.getDOMWindowUtils(window);
function sendMouseDown(el) {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var rect = el.getBoundingClientRect();
var utils = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsIDOMWindowUtils);
utils.sendMouseEvent('mousedown', rect.left + 5, rect.top + 5, 0, 1, 0);
}
function sendMouseUp(el) {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var rect = el.getBoundingClientRect();
var utils = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsIDOMWindowUtils);
utils.sendMouseEvent('mouseup', rect.left + 5, rect.top + 5, 0, 1, 0);
}

View File

@ -34,11 +34,6 @@ function invalidEventHandler(e)
function completeValidityCheck(element, alwaysValid, isBarred)
{
if (element.type == 'file') {
// Need privileges to set a filename with .value.
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
}
// Check when pattern matches.
if (element.type == 'email') {
element.pattern = ".*@bar.com";
@ -48,7 +43,7 @@ function completeValidityCheck(element, alwaysValid, isBarred)
element.value = "http://mozilla.com";
} else {
element.pattern = "foo";
element.value = "foo";
SpecialPowers.wrap(element).value = "foo";
}
checkValidPattern(element, true, isBarred);
@ -63,7 +58,7 @@ function completeValidityCheck(element, alwaysValid, isBarred)
element.value = "http://mozilla.org";
} else {
element.pattern = "foo";
element.value = "bar";
SpecialPowers.wrap(element).value = "bar";
}
if (!alwaysValid) {

View File

@ -268,10 +268,8 @@ function checkValidityStateObjectAliveWithoutElement(element)
// Then, we make sure it is removed by the garbage collector and we check the
// ValidityState default values (it should not crash).
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var v = document.createElement(element).validity;
window.QueryInterface(Components.interfaces.nsIInterfaceRequestor).
getInterface(Components.interfaces.nsIDOMWindowUtils).garbageCollect();
SpecialPowers.gc();
ok(!v.valueMissing,
"When the element is not alive, it shouldn't suffer from constraint validation");

View File

@ -77,9 +77,7 @@ function link123HrefIs(href, testNum) {
var gGen;
function visitedDependentComputedStyle(win, elem, property) {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var utils = win.QueryInterface(Components.interfaces.nsIInterfaceRequestor).
getInterface(Components.interfaces.nsIDOMWindowUtils);
var utils = SpecialPowers.getDOMWindowUtils(window);
return utils.getVisitedDependentComputedStyle(elem, "", property);
}

View File

@ -25,9 +25,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=406596
/** Test for Bug 406596 **/
function testTabbing(click, focus, selectionOffset) {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var wu = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsIDOMWindowUtils);
var wu = SpecialPowers.getDOMWindowUtils(window);
var elem = document.getElementById(click);
var rect = elem.getBoundingClientRect();

View File

@ -21,9 +21,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=421640
/** Test for Bug 421640 **/
function test(click, focus, nextFocus) {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var wu = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsIDOMWindowUtils);
var wu = SpecialPowers.getDOMWindowUtils(window);
var selection = window.getSelection();
var edit = document.getElementById("edit");

View File

@ -36,15 +36,14 @@ function runTest()
range.selectNodeContents(editor);
var prevStr = range.toString();
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
var docShell =
window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsIWebNavigation)
.QueryInterface(Components.interfaces.nsIDocShell);
var docShell = SpecialPowers.wrap(window)
.QueryInterface(SpecialPowers.Ci.nsIInterfaceRequestor)
.getInterface(SpecialPowers.Ci.nsIWebNavigation)
.QueryInterface(SpecialPowers.Ci.nsIDocShell);
var controller =
docShell.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsISelectionDisplay)
.QueryInterface(Components.interfaces.nsISelectionController);
docShell.QueryInterface(SpecialPowers.Ci.nsIInterfaceRequestor)
.getInterface(SpecialPowers.Ci.nsISelectionDisplay)
.QueryInterface(SpecialPowers.Ci.nsISelectionController);
var sel = controller.getSelection(controller.SELECTION_NORMAL);
sel.collapse(anchorInEditor, 0);
synthesizeKey('a', {});

View File

@ -51,10 +51,7 @@ function checkLinkColor(aElmId, aExpectedColor, aMessage) {
// Because link coloring is asynchronous, we wait until we get the right
// result, or we will time out (resulting in a failure).
function getColor() {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var utils = document.defaultView.
QueryInterface(Components.interfaces.nsIInterfaceRequestor).
getInterface(Components.interfaces.nsIDOMWindowUtils);
var utils = SpecialPowers.getDOMWindowUtils(window);
return utils.getVisitedDependentComputedStyle($(aElmId), "", "color");
}
while (getColor() != aExpectedColor) {

View File

@ -152,10 +152,7 @@ function clickImage(aTarget, aX, aY)
aTarget.style.left = "0";
aTarget.offsetTop;
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var wu = aTarget.ownerDocument.defaultView
.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsIDOMWindowUtils);
var wu = SpecialPowers.getDOMWindowUtils(aTarget.ownerDocument.defaultView);
wu.sendMouseEvent('mousedown', aX, aY, 0, 1, 0);
wu.sendMouseEvent('mouseup', aX, aY, 0, 0, 0);

View File

@ -20,10 +20,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=446483
/** Test for Bug 446483 **/
function gc() {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsIDOMWindowUtils)
.garbageCollect();
SpecialPowers.gc();
}
function runTest() {

View File

@ -27,10 +27,7 @@ function testViewport() {
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
/* Grab Viewport Metadata from the document header. */
var iRequester =
window.QueryInterface(Components.interfaces.nsIInterfaceRequestor);
var windowUtils =
iRequester.getInterface(Components.interfaces.nsIDOMWindowUtils);
var windowUtils = SpecialPowers.getDOMWindowUtils(window);
var vpWidth =
parseInt(windowUtils.getDocumentMetadata("viewport-width"));
var vpHeight =