Bug 778420 - Initial stab at the tests. r=bholley

This commit is contained in:
William Chen 2012-08-03 22:19:54 +02:00
parent 12d0810b14
commit d1fa2a97bc
18 changed files with 74 additions and 116 deletions

View File

@ -26,6 +26,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=462856
<script class="testbody" type="text/javascript">
SimpleTest.waitForExplicitFinish();
const Cc = SpecialPowers.wrap(Components).classes;
var numFinished = 0;
@ -34,18 +35,17 @@ window.addEventListener("message", function(event) {
if (++numFinished == 3) {
// Clean up after ourself
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var pm = Components.classes["@mozilla.org/permissionmanager;1"].
var pm = Cc["@mozilla.org/permissionmanager;1"].
getService(Components.interfaces.nsIPermissionManager);
var ioService = Components.classes["@mozilla.org/network/io-service;1"]
var ioService = Cc["@mozilla.org/network/io-service;1"]
.getService(Components.interfaces.nsIIOService);
var uri1 = ioService.newURI(frames.testFrame.location, null, null);
var uri2 = ioService.newURI(frames.testFrame3.location, null, null);
var principal1 = Components.classes["@mozilla.org/scriptsecuritymanager;1"]
var principal1 = Cc["@mozilla.org/scriptsecuritymanager;1"]
.getService(Components.interfaces.nsIScriptSecurityManager)
.getNoAppCodebasePrincipal(uri1);
var principal2 = Components.classes["@mozilla.org/scriptsecuritymanager;1"]
var principal2 = Cc["@mozilla.org/scriptsecuritymanager;1"]
.getService(Components.interfaces.nsIScriptSecurityManager)
.getNoAppCodebasePrincipal(uri2);
@ -108,8 +108,7 @@ function loaded() {
// Click the notification bar's "Allow" button. This should kick
// off updates, which will eventually lead to getting messages from
// the children.
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"].
var wm = SpecialPowers.wrap(Components).classes["@mozilla.org/appshell/window-mediator;1"].
getService(Components.interfaces.nsIWindowMediator);
var win = wm.getMostRecentWindow("navigator:browser");
var notificationBox = win.gBrowser.getNotificationBox();
@ -117,7 +116,7 @@ function loaded() {
var notification = notificationBox.getNotificationWithValue("offline-app-requested-mochi.test");
notification.childNodes[0].click();
notification = notificationBox.getNotificationWithValue("offline-app-requested-example.com");
notification = SpecialPowers.wrap(notificationBox).getNotificationWithValue("offline-app-requested-example.com");
notification.childNodes[0].click();
}

View File

@ -32,9 +32,7 @@ SimpleTest.waitForExplicitFinish();
function finishTest() {
// Clean up after ourselves.
netscape.security.PrivilegeManager
.enablePrivilege("UniversalXPConnect");
var pm = Components.classes["@mozilla.org/permissionmanager;1"].
var pm = SpecialPowers.wrap(Components).classes["@mozilla.org/permissionmanager;1"].
getService(Components.interfaces.nsIPermissionManager);
var uri = Components.classes["@mozilla.org/network/io-service;1"]
@ -70,8 +68,6 @@ function handleMessageEvents(event) {
// successfully reloaded), or the string "error" appears
// in the iframe, as in the case of bug 501422.
intervalID = setInterval(function() {
netscape.security.PrivilegeManager
.enablePrivilege("UniversalXPConnect");
// Sometimes document.body may not exist, and trying to access
// it will throw an exception, so handle this case.
try {
@ -103,8 +99,7 @@ function loaded() {
// Click the notification bar's "Allow" button. This should kick
// off updates, which will eventually lead to getting messages from
// the iframe.
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"].
var wm = SpecialPowers.wrap(Components).classes["@mozilla.org/appshell/window-mediator;1"].
getService(Components.interfaces.nsIWindowMediator);
var win = wm.getMostRecentWindow("navigator:browser");
var notificationBox = win.gBrowser.getNotificationBox();

View File

@ -20,8 +20,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=589543
SimpleTest.waitForExplicitFinish();
addLoadEvent(function() {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var doc = $("testFrame").contentDocument;
var doc = SpecialPowers.wrap($("testFrame").contentDocument);
var daddy = doc.getElementById("feedSubscribeLine");
var popup = doc.getAnonymousElementByAttribute(daddy, "anonid", "handlersMenuPopup");
isnot(popup, null, "Feed preview should have a handlers popup");

View File

@ -22,14 +22,13 @@
request.send(null);
// Try reading headers in privileged context
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
is(request.getResponseHeader("Set-Cookie"), "test", "Reading Set-Cookie response header in privileged context");
is(request.getResponseHeader("Set-Cookie2"), "test2", "Reading Set-Cookie2 response header in privileged context");
is(request.getResponseHeader("X-Dummy"), "test", "Reading X-Dummy response header in privileged context");
is(SpecialPowers.wrap(request).getResponseHeader("Set-Cookie"), "test", "Reading Set-Cookie response header in privileged context");
is(SpecialPowers.wrap(request).getResponseHeader("Set-Cookie2"), "test2", "Reading Set-Cookie2 response header in privileged context");
is(SpecialPowers.wrap(request).getResponseHeader("X-Dummy"), "test", "Reading X-Dummy response header in privileged context");
ok(/\bSet-Cookie:/i.test(request.getAllResponseHeaders()), "Looking for Set-Cookie in all response headers in privileged context");
ok(/\bSet-Cookie2:/i.test(request.getAllResponseHeaders()), "Looking for Set-Cookie2 in all response headers in privileged context");
ok(/\bX-Dummy:/i.test(request.getAllResponseHeaders()), "Looking for X-Dummy in all response headers in privileged context");
ok(/\bSet-Cookie:/i.test(SpecialPowers.wrap(request).getAllResponseHeaders()), "Looking for Set-Cookie in all response headers in privileged context");
ok(/\bSet-Cookie2:/i.test(SpecialPowers.wrap(request).getAllResponseHeaders()), "Looking for Set-Cookie2 in all response headers in privileged context");
ok(/\bX-Dummy:/i.test(SpecialPowers.wrap(request).getAllResponseHeaders()), "Looking for X-Dummy in all response headers in privileged context");
// Try reading headers in unprivileged context
setTimeout(function() {

View File

@ -32,26 +32,25 @@ var input2Files =
SimpleTest.waitForExplicitFinish();
function setFileInputs () {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
f = createFileWithData(input1File.name, input1File.body);
singleFileInput.mozSetFileNameArray([f.path], 1);
SpecialPowers.wrap(singleFileInput).mozSetFileNameArray([f.path], 1);
var input2FileNames = [];
for each (file in input2Files) {
f = createFileWithData(file.name, file.body);
input2FileNames.push(f.path);
}
multiFileInput.mozSetFileNameArray(input2FileNames, input2FileNames.length);
SpecialPowers.wrap(multiFileInput).mozSetFileNameArray(input2FileNames, input2FileNames.length);
}
function createFileWithData(fileName, fileData) {
var dirSvc = Components.classes["@mozilla.org/file/directory_service;1"]
.getService(Components.interfaces.nsIProperties);
var dirSvc = SpecialPowers.wrap(Components).classes["@mozilla.org/file/directory_service;1"]
.getService(Components.interfaces.nsIProperties);
var testFile = dirSvc.get("ProfD", Components.interfaces.nsIFile);
testFile.append(fileName);
var outStream = Components.
classes["@mozilla.org/network/file-output-stream;1"].
createInstance(Components.interfaces.nsIFileOutputStream);
var outStream = SpecialPowers.wrap(Components).
classes["@mozilla.org/network/file-output-stream;1"].
createInstance(Components.interfaces.nsIFileOutputStream);
outStream.init(testFile, 0x02 | 0x08 | 0x20, // write, create, truncate
0666, 0);
outStream.write(fileData, fileData.length);

View File

@ -55,9 +55,7 @@ function checkURI(uri, name, type) {
function checkFrame(num) {
// Just snarf our data
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var outer = window.frames[num]
var outer = SpecialPowers.wrap(window.frames[num]);
name = outer.name;
is(outer.document.baseURI,

View File

@ -24,21 +24,19 @@ var frame = document.getElementById("i");
SimpleTest.waitForExplicitFinish();
addLoadEvent(function() {
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
var viewer =
frame.contentWindow
.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsIWebNavigation)
.QueryInterface(Components.interfaces.nsIDocShell)
.contentViewer
.QueryInterface(Components.interfaces.nsIMarkupDocumentViewer);
SpecialPowers.wrap(frame.contentWindow
.QueryInterface(Components.interfaces.nsIInterfaceRequestor))
.getInterface(Components.interfaces.nsIWebNavigation)
.QueryInterface(Components.interfaces.nsIDocShell)
.contentViewer
.QueryInterface(Components.interfaces.nsIMarkupDocumentViewer);
viewer.fullZoom = 1.5;
setTimeout(function() {
synthesizeMouse(frame, 30, 30, {});
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
is(viewer.fullZoom, 1.5, "Zoom in the image frame should not have been reset");
SimpleTest.finish();

View File

@ -116,9 +116,8 @@ function test5()
SimpleTest.executeSoon(function() {
// We have to focus back the originating window but we can't do that with
// .focus() or .blur() anymore.
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var fm = Components.classes["@mozilla.org/focus-manager;1"].
getService(Components.interfaces.nsIFocusManager);
var fm = SpecialPowers.wrap(Components).classes["@mozilla.org/focus-manager;1"]
.getService(Components.interfaces.nsIFocusManager);
fm.focusedWindow = window;
});
}, w, true);
@ -126,10 +125,9 @@ function test5()
function finished()
{
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefBranch)
.setBoolPref("dom.disable_window_flip", gOldPrefValue);
SpecialPowers.wrap(Components).classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefBranch)
.setBoolPref("dom.disable_window_flip", gOldPrefValue);
SimpleTest.finish();
}
@ -137,9 +135,8 @@ SimpleTest.waitForExplicitFinish();
// dom.disable_window_flip has to be set to true for this test.
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var prefs = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefBranch);
var prefs = SpecialPowers.wrap(Components).classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefBranch);
gOldPrefValue = prefs.getBoolPref("dom.disable_window_flip");
prefs.setBoolPref("dom.disable_window_flip", true);

View File

@ -153,8 +153,7 @@ function popstateExpected(msg) {
}
function getColor(elem) {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var utils = document.defaultView.
var utils = SpecialPowers.wrap(document).defaultView.
QueryInterface(Components.interfaces.nsIInterfaceRequestor).
getInterface(Components.interfaces.nsIDOMWindowUtils);
return utils.getVisitedDependentComputedStyle(elem, "", "color");
@ -162,12 +161,10 @@ function getColor(elem) {
function getSHistory(theWindow)
{
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
const Ci = Components.interfaces;
var sh = theWindow.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIWebNavigation)
.sessionHistory;
var sh = SpecialPowers.wrap(theWindow.QueryInterface(Ci.nsIInterfaceRequestor))
.getInterface(Ci.nsIWebNavigation)
.sessionHistory;
if (!sh || sh == null)
throw("Couldn't get shistory for window!");
@ -176,8 +173,6 @@ function getSHistory(theWindow)
function getSHTitle(sh, offset)
{
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
if (!offset)
offset = 0;

View File

@ -22,11 +22,10 @@ var iframe = document.getElementById("load-frame");
function enableJS() allowJS(true, iframe);
function disableJS() allowJS(false, iframe);
function allowJS(allow, frame) {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
frame.contentWindow.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsIWebNavigation)
.QueryInterface(Components.interfaces.nsIDocShell)
.allowJavascript = allow;
SpecialPowers.wrap(frame.contentWindow.QueryInterface(Components.interfaces.nsIInterfaceRequestor))
.getInterface(Components.interfaces.nsIWebNavigation)
.QueryInterface(Components.interfaces.nsIDocShell)
.allowJavascript = allow;
}
function expectJSAllowed(allowed, testCondition, callback) {
window.ICanRunMyJS = false;

View File

@ -36,10 +36,10 @@ function editDoc() {
function getSpellCheckSelection() {
var Ci = Components.interfaces;
var win = editDoc().defaultView;
var editingSession = win.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIWebNavigation)
.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIEditingSession);
var editingSession = SpecialPowers.wrap(win.QueryInterface(Ci.nsIInterfaceRequestor))
.getInterface(Ci.nsIWebNavigation)
.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIEditingSession);
var editor = editingSession.getEditorForWindow(win);
var selcon = editor.selectionController;
return selcon.getSelection(selcon.SELECTION_SPELLCHECK);
@ -51,7 +51,6 @@ function runTest() {
}
function addWords(aLimit) {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
if (aLimit == 0) {
is(isSpellingCheckOk(), true, "All misspellings accounted for.");
SimpleTest.finish();

View File

@ -20,8 +20,6 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=468353
var styleSheets = null;
function checkStylesheets() {
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
// Evidently RemoveStyleSheet is the only method in nsIEditorStyleSheets
// that would throw. RemoveOverrideStyleSheet returns NS_OK even if the
// sheet is not there
@ -43,8 +41,6 @@ function checkStylesheets() {
}
function runTest() {
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
const Ci = Components.interfaces;
const Cc = Components.classes;
@ -58,7 +54,7 @@ function runTest() {
editdoc.designMode='on';
// Hold the reference to the editor
editor = editframe.QueryInterface(Ci.nsIInterfaceRequestor)
editor = SpecialPowers.wrap(editframe.QueryInterface(Ci.nsIInterfaceRequestor))
.getInterface(Ci.nsIWebNavigation)
.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIEditingSession)
@ -77,7 +73,7 @@ function runTest() {
editdoc.body.contentEditable = true;
// Hold the reference to the editor
editor = editframe.QueryInterface(Ci.nsIInterfaceRequestor)
editor = SpecialPowers.wrap(editframe.QueryInterface(Ci.nsIInterfaceRequestor))
.getInterface(Ci.nsIWebNavigation)
.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIEditingSession)
@ -94,7 +90,7 @@ function runTest() {
editdoc.designMode = "off";
// Hold the reference to the editor
editor = editframe.QueryInterface(Ci.nsIInterfaceRequestor)
editor = SpecialPowers.wrap(editframe.QueryInterface(Ci.nsIInterfaceRequestor))
.getInterface(Ci.nsIWebNavigation)
.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIEditingSession)

View File

@ -8,8 +8,6 @@
<script class="testbody" type="application/javascript">
function runTest() {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
function verifyContent(s) {
var e = document.getElementById('i1');
var doc = e.contentDocument;
@ -27,7 +25,7 @@ function runTest() {
selection.removeAllRanges();
selection.selectAllChildren(e);
selection.collapseToEnd();
doc.execCommand("paste", false, null);
SpecialPowers.wrap(doc).execCommand("paste", false, null);
return e;
}
@ -51,7 +49,7 @@ function runTest() {
range.selectNode(doc.getElementById(target_id));
selection.addRange(range);
}
doc.execCommand("copy", false, null);
SpecialPowers.wrap(doc).execCommand("copy", false, null);
return e;
}

View File

@ -8,8 +8,6 @@
<script class="testbody" type="application/javascript">
function runTest() {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
function verifyContent(s) {
var e = document.getElementById('i1');
var doc = e.contentDocument;
@ -30,7 +28,7 @@ function runTest() {
selection.removeAllRanges();
selection.selectAllChildren(e);
selection.collapseToEnd();
doc.execCommand("paste", false, null);
SpecialPowers.wrap(doc).execCommand("paste", false, null);
return e;
}
@ -54,7 +52,7 @@ function runTest() {
range.selectNode(doc.getElementById(target_id));
selection.addRange(range);
}
doc.execCommand("copy", false, null);
SpecialPowers.wrap(doc).execCommand("copy", false, null);
return e;
}

View File

@ -563,13 +563,11 @@ function runTest(test) {
} else
elem.focus();
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var trans = Components.classes["@mozilla.org/widget/transferable;1"]
.createInstance(Components.interfaces.nsITransferable);
var trans = SpecialPowers.wrap(Components).classes["@mozilla.org/widget/transferable;1"]
.createInstance(Components.interfaces.nsITransferable);
trans.init(getLoadContext());
var data = Components.classes["@mozilla.org/supports-string;1"]
.createInstance(Components.interfaces.nsISupportsString);
var data = SpecialPowers.wrap(Components).classes["@mozilla.org/supports-string;1"]
.createInstance(Components.interfaces.nsISupportsString);
data.data = test.payload;
trans.addDataFlavor("text/html");
trans.setTransferData("text/html", data, data.data.length * 2);
@ -582,14 +580,14 @@ function runTest(test) {
getSelection().collapse(elem, 0);
win = window;
}
editor = win.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsIWebNavigation)
.QueryInterface(Components.interfaces.nsIEditorDocShell)
.editor;
editor = SpecialPowers.wrap(win).QueryInterface(Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsIWebNavigation)
.QueryInterface(Components.interfaces.nsIEditorDocShell)
.editor;
editor.pasteTransferable(trans);
} else {
var clipboard = Components.classes["@mozilla.org/widget/clipboard;1"]
.getService(Components.interfaces.nsIClipboard);
var clipboard = SpecialPowers.wrap(Components).classes["@mozilla.org/widget/clipboard;1"]
.getService(Components.interfaces.nsIClipboard);
clipboard.setData(trans, null, Components.interfaces.nsIClipboard.kGlobalClipboard);

View File

@ -7,13 +7,14 @@
<script class="testbody" type="application/javascript">
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var utils = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor).getInterface(Components.interfaces.nsIDOMWindowUtils);
var Cc = Components.classes;
var utils = SpecialPowers.wrap(window)
.QueryInterface(Components.interfaces.nsIInterfaceRequestor).getInterface(Components.interfaces.nsIDOMWindowUtils);
var Cc = SpecialPowers.wrap(Components).classes;
var Ci = Components.interfaces;
function getLoadContext() {
return window.QueryInterface(Ci.nsIInterfaceRequestor)
return SpecialPowers.wrap(window)
.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIWebNavigation)
.QueryInterface(Ci.nsILoadContext);
}
@ -29,7 +30,6 @@ function runTest() {
}
function pasteInto(trans, html, target_id) {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var e = document.getElementById('i1');
var doc = e.contentDocument;
doc.designMode = "on";
@ -53,7 +53,6 @@ function runTest() {
}
function getTransferableFromClipboard(asHTML) {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var trans = Cc["@mozilla.org/widget/transferable;1"].createInstance(Ci.nsITransferable);
trans.init(getLoadContext());
if (asHTML) {
@ -67,8 +66,6 @@ function runTest() {
}
function makeTransferable(s,asHTML,target_id) {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var e = document.getElementById('i2');
var doc = e.contentDocument;
if (asHTML) {
@ -112,7 +109,6 @@ function runTest() {
}
function copyToClipBoard(s,asHTML,target_id) {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var e = document.getElementById('i2');
var doc = e.contentDocument;
if (asHTML) {
@ -132,7 +128,7 @@ function runTest() {
range.selectNode(doc.getElementById(target_id));
selection.addRange(range);
}
doc.execCommand("copy", false, null);
SpecialPowers.wrap(doc).execCommand("copy", false, null);
return e;
}

View File

@ -22,8 +22,6 @@
SimpleTest.waitForExplicitFinish();
SimpleTest.waitForFocus(runTest);
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
function runDesignModeTest(aDoc, aFocus, aNewSource)
{
aDoc.designMode = "on";
@ -83,11 +81,9 @@ var gSetFocusToIFrame = false;
function onLoadIFrame()
{
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
var frameDoc = gIFrame.contentWindow.document;
var selCon = gIFrame.contentWindow.
var selCon = SpecialPowers.wrap(gIFrame).contentWindow.
QueryInterface(Components.interfaces.nsIInterfaceRequestor).
getInterface(Components.interfaces.nsIWebNavigation).
QueryInterface(Components.interfaces.nsIInterfaceRequestor).

View File

@ -36,9 +36,8 @@ addLoadEvent(function() {
ok(equal, "Show/hide should have no effect",
"got " + str1 + " but expected " + str2);
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
var viewer =
$("ourFrame").contentWindow
SpecialPowers.wrap($("ourFrame")).contentWindow
.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsIWebNavigation)
.QueryInterface(Components.interfaces.nsIDocShell)