Bug 861674 - Change some content mochitests from enablePrivilege to use SpecialPowers. r=jgriffin

This commit is contained in:
Martijn Wargers 2013-04-15 19:50:45 +02:00
parent ef862b3016
commit 01ffcc1bab
12 changed files with 39 additions and 119 deletions

View File

@ -21,12 +21,8 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=466409
function setUniversalDetector(detector)
{
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var pref = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefBranch);
var olddetector = pref.getCharPref("intl.charset.detector");
pref.setCharPref("intl.charset.detector", detector);
var olddetector = SpecialPowers.getCharPref("intl.charset.detector");
SpecialPowers.setCharPref("intl.charset.detector", detector);
return olddetector;
}

View File

@ -2,7 +2,6 @@ var popup;
function OpenWindow()
{
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
log({},">>> OpenWindow");
popup = window.open("","Test");
@ -50,7 +49,6 @@ document.onblur=function (event) { log(event,"top-doc") };
document.onchange=function (event) { log(event,"top-doc") };
function doTest1_rest2(expectedEventLog,focusAfterCloseId) {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
try {
is(document.activeElement, document.getElementById(focusAfterCloseId), "wrong element is focused after popup was closed");
is(result, expectedEventLog, "unexpected events");
@ -62,7 +60,6 @@ function doTest1_rest2(expectedEventLog,focusAfterCloseId) {
}
}
function doTest1_rest1(expectedEventLog,focusAfterCloseId) {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
try {
synthesizeKey("V", {}, popup);
synthesizeKey("A", {}, popup);
@ -82,13 +79,10 @@ function doTest1_rest1(expectedEventLog,focusAfterCloseId) {
}
function doTest1(expectedEventLog,focusAfterCloseId) {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
try {
var select1 = document.getElementById('Select1');
select1.focus();
is(document.activeElement, select1, "select element should be focused");
var wu = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsIDOMWindowUtils);
synthesizeKey("VK_DOWN",{});
synthesizeKey("VK_TAB", {});
SimpleTest.waitForFocus(function () { doTest1_rest1(expectedEventLog,focusAfterCloseId); }, popup);
@ -101,18 +95,15 @@ function doTest1(expectedEventLog,focusAfterCloseId) {
}
function setPrefAndDoTest(expectedEventLog,focusAfterCloseId,prefValue) {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var prefs = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefBranch);
var origPrefValue = prefs.getIntPref("browser.link.open_newwindow");
var origPrefValue = SpecialPowers.getIntPref("browser.link.open_newwindow");
var select1 = document.getElementById('Select1');
select1.blur();
result = "";
log({},"Test with browser.link.open_newwindow = "+prefValue);
try {
prefs.setIntPref("browser.link.open_newwindow", prefValue);
SpecialPowers.setIntPref("browser.link.open_newwindow", prefValue);
doTest1(expectedEventLog,focusAfterCloseId);
} finally {
prefs.setIntPref("browser.link.open_newwindow", origPrefValue);
SpecialPowers.setIntPref("browser.link.open_newwindow", origPrefValue);
}
}

View File

@ -30,17 +30,10 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=226361
// accessibility.tabfocus must be set to value 7 before running test also
// on a mac.
function setOrRestoreTabFocus(newValue) {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
const prefSvcContractID = "@mozilla.org/preferences-service;1";
const prefSvcIID = Components.interfaces.nsIPrefService;
var prefs = Components.classes[prefSvcContractID].getService(prefSvcIID)
.getBranch("accessibility.");
if (!newValue) {
if (prefs.prefHasUserValue("tabfocus")) {
prefs.clearUserPref("tabfocus");
}
SpecialPowers.clearUserPref("accessibility.tabfocus");
} else {
prefs.setIntPref("tabfocus", newValue);
SpecialPowers.setIntPref("accessibility.tabfocus", newValue);
}
}

View File

@ -34,15 +34,10 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=238987
// accessibility.tabfocus must be set to value 7 before running test also
// on a mac.
function setOrRestoreTabFocus(newValue) {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
const prefSvcContractID = "@mozilla.org/preferences-service;1";
const prefSvcIID = Components.interfaces.nsIPrefService;
var prefs = Components.classes[prefSvcContractID].getService(prefSvcIID)
.getBranch("accessibility.");
if (!newValue) {
prefs.clearUserPref("tabfocus");
SpecialPowers.clearUserPref("accessibility.tabfocus");
} else {
prefs.setIntPref("tabfocus", newValue);
SpecialPowers.setIntPref("accessibility.tabfocus", newValue);
}
}
@ -105,9 +100,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=238987
}
function tab() {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var utils = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor).
getInterface(Components.interfaces.nsIDOMWindowUtils);
var utils = SpecialPowers.DOMWindowUtils;
// Send tab key events.
var key = Components.interfaces.nsIDOMKeyEvent.DOM_VK_TAB;
utils.sendKeyEvent("keydown", key, 0, modifier);

View File

@ -92,15 +92,10 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=409604
// ui.key.contentAccess must be set to value 5 before running the test.
function setOrRestoreContentAccess(newValue) {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
const prefSvcContractID = "@mozilla.org/preferences-service;1";
const prefSvcIID = Components.interfaces.nsIPrefService;
var prefs = Components.classes[prefSvcContractID].getService(prefSvcIID)
.getBranch("ui.key.");
if (!newValue) {
prefs.clearUserPref("contentAccess");
SpecialPowers.clearUserPref("ui.key.contentAccess");
} else {
prefs.setIntPref("contentAccess", newValue);
SpecialPowers.setIntPref("ui.key.contentAccess", newValue);
}
}
@ -134,10 +129,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=409604
}
function pressAccessKey(key) {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
// Send key events.
var utils = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor).
getInterface(Components.interfaces.nsIDOMWindowUtils);
var utils = SpecialPowers.DOMWindowUtils;
utils.sendKeyEvent("keydown", key, key, modifier);
utils.sendKeyEvent("keypress", key, key, modifier);
utils.sendKeyEvent("keyup", key, key, modifier);

View File

@ -24,15 +24,10 @@ SimpleTest.expectAssertions(1);
var windowBlurCount = 0;
function setUserPref(reset) {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
const prefSvcContractID = "@mozilla.org/preferences-service;1";
const prefSvcIID = Components.interfaces.nsIPrefService;
var prefs = Components.classes[prefSvcContractID].getService(prefSvcIID)
.getBranch("browser.link.");
if (reset) {
prefs.clearUserPref("open_newwindow");
SpecialPowers.clearUserPref("browser.link.open_newwindow");
} else {
prefs.setIntPref("open_newwindow", 3);
SpecialPowers.setIntPref("browser.link.open_newwindow", 3);
}
}

View File

@ -39,10 +39,7 @@ function getTests() {
function doTest() {
// Enable context menus
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var prefs = Components.classes["@mozilla.org/preferences-service;1"].
getService(Components.interfaces.nsIPrefBranch);
prefs.setBoolPref("ui.click_hold_context_menus", true);
SpecialPowers.setBoolPref("ui.click_hold_context_menus", true);
target = document.getElementById("testTarget");
@ -69,26 +66,20 @@ function doCheckDuration() {
var duration = 50;
// Change click hold delay
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var prefs = Components.classes["@mozilla.org/preferences-service;1"].
getService(Components.interfaces.nsIPrefBranch);
prefs.setIntPref("ui.click_hold_context_menus.delay", duration);
SpecialPowers.setIntPref("ui.click_hold_context_menus.delay", duration);
synthesizeMouse(target, 0, 0, {type: "mousedown"});
}
function finishTest() {
synthesizeKey("VK_ESCAPE", {}, window);
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var prefs = Components.classes["@mozilla.org/preferences-service;1"].
getService(Components.interfaces.nsIPrefBranch);
try {
prefs.clearUserPref("ui.click_hold_context_menus");
SpecialPowers.clearUserPref("ui.click_hold_context_menus");
}
catch(e) {}
try {
prefs.clearUserPref("ui.click_hold_context_menus.delay");
SpecialPowers.clearUserPref("ui.click_hold_context_menus.delay");
}
catch(e) {}

View File

@ -57,7 +57,6 @@ function runTest() {
winUtils.advanceTimeAndRefresh(1000);
function nextTest() {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
if (!outstandingTests.length) {
winUtils.restoreNormalRefresh();
win.close();
@ -74,7 +73,6 @@ function runTest() {
winUtils.advanceTimeAndRefresh(1000); // force scrolling to happen
setTimeout(function () {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
if (!ctrlKey) {
let postfix = isMomentum ? ", even after releasing the touchpad" : "";
// Normal scroll: scroll
@ -102,27 +100,20 @@ function runTest() {
function initPrefs()
{
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var prefSvc = Components.classes["@mozilla.org/preferences-service;1"].
getService(Components.interfaces.nsIPrefBranch);
prefSvc.setBoolPref("general.smoothScroll", false);
SpecialPowers.setBoolPref("general.smoothScroll", false);
// Disables the app level scroll acceleration
prefSvc.setIntPref("mousewheel.acceleration.start", -1);
prefSvc.setBoolPref("mousewheel.system_scroll_override_on_root_content.enabled", false);
SpecialPowers.setIntPref("mousewheel.acceleration.start", -1);
SpecialPowers.setBoolPref("mousewheel.system_scroll_override_on_root_content.enabled", false);
// Enable zooming for ctrl-scrolling
prefSvc.setIntPref("mousewheel.with_control.action", 3);
SpecialPowers.setIntPref("mousewheel.with_control.action", 3);
}
function clearPrefs()
{
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var prefSvc = Components.classes["@mozilla.org/preferences-service;1"].
getService(Components.interfaces.nsIPrefBranch);
prefSvc.clearUserPref("general.smoothScroll");
prefSvc.clearUserPref("mousewheel.acceleration.start");
prefSvc.clearUserPref("mousewheel.system_scroll_override_on_root_content.enabled");
prefSvc.clearUserPref("mousewheel.with_control.action");
SpecialPowers.clearUserPref("general.smoothScroll");
SpecialPowers.clearUserPref("mousewheel.acceleration.start");
SpecialPowers.clearUserPref("mousewheel.system_scroll_override_on_root_content.enabled");
SpecialPowers.clearUserPref("mousewheel.with_control.action");
}
window.onload = function () {

View File

@ -72,29 +72,19 @@ function runTest() {
function initPrefs()
{
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var prefSvc = Components.classes["@mozilla.org/preferences-service;1"].
getService(Components.interfaces.nsIPrefBranch);
// Disables the app level scroll acceleration
prefSvc.setIntPref("mousewheel.acceleration.start", -1);
prefSvc.setBoolPref("mousewheel.system_scroll_override_on_root_content.enabled", false);
SpecialPowers.setIntPref("mousewheel.acceleration.start", -1);
SpecialPowers.setBoolPref("mousewheel.system_scroll_override_on_root_content.enabled", false);
// Enables smooth scrolling
prefSvc.setBoolPref("general.smoothScroll", true);
SpecialPowers.setBoolPref("general.smoothScroll", true);
}
function clearPrefs()
{
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var prefSvc = Components.classes["@mozilla.org/preferences-service;1"].
getService(Components.interfaces.nsIPrefBranch);
if (prefSvc.prefHasUserValue("mousewheel.acceleration.start"))
prefSvc.clearUserPref("mousewheel.acceleration.start");
if (prefSvc.prefHasUserValue("mousewheel.system_scroll_override_on_root_content.enabled"))
prefSvc.clearUserPref("mousewheel.system_scroll_override_on_root_content.enabled");
if (prefSvc.prefHasUserValue("general.smoothScroll"))
prefSvc.clearUserPref("general.smoothScroll");
SpecialPowers.clearUserPref("mousewheel.acceleration.start");
SpecialPowers.clearUserPref("mousewheel.system_scroll_override_on_root_content.enabled");
SpecialPowers.clearUserPref("general.smoothScroll");
}
window.onload = function () {

View File

@ -42,12 +42,8 @@ function runTests()
function isEnabledMiddleClickPaste()
{
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
var prefs = Components.classes["@mozilla.org/preferences-service;1"].
getService(Components.interfaces.nsIPrefBranch);
try {
return prefs.getBoolPref("middlemouse.paste");
return SpecialPowers.getBoolPref("middlemouse.paste");
} catch (e) {
return false;
}

View File

@ -20,10 +20,8 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=583533
/** Test for Bug 583533 **/
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var sbs = Components.classes["@mozilla.org/intl/stringbundle;1"].
getService(Components.interfaces.nsIStringBundleService);
var sbs = SpecialPowers.Cc['@mozilla.org/intl/stringbundle;1'].
getService(SpecialPowers.Ci.nsIStringBundleService);
var bundle = sbs.createBundle("chrome://global-platform/locale/platformKeys.properties");
var shiftText = bundle.GetStringFromName("VK_SHIFT");
@ -32,9 +30,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=583533
var metaText = bundle.GetStringFromName("VK_META");
var separatorText = bundle.GetStringFromName("MODIFIER_SEPARATOR");
var modifier = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefBranch)
.getIntPref("ui.key.contentAccess");
var modifier = SpecialPowers.getIntPref("ui.key.contentAccess");
var isShift;
var isAlt;

View File

@ -89,16 +89,12 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=369370
is(kidDoc.body.scrollTop, 0, "Checking scrollTop");
kidWin.close();
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
prefs.clearUserPref("browser.enable_automatic_image_resizing");
SpecialPowers.clearUserPref("browser.enable_automatic_image_resizing");
SimpleTest.finish();
}
SimpleTest.waitForExplicitFinish();
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
var prefs = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefBranch);
prefs.setBoolPref("browser.enable_automatic_image_resizing", true);
SpecialPowers.setBoolPref("browser.enable_automatic_image_resizing", true);
var kidWin = window.open("bug369370-popup.png", "bug369370", "width=400,height=300");
var kidDoc; // will init onload