Skip to content

Commit

Permalink
Bug 861674 - Change some content mochitests from enablePrivilege to u…
Browse files Browse the repository at this point in the history
…se SpecialPowers. r=jgriffin
  • Loading branch information
mwargers committed Apr 15, 2013
1 parent ef862b3 commit 01ffcc1
Show file tree
Hide file tree
Showing 12 changed files with 39 additions and 119 deletions.
8 changes: 2 additions & 6 deletions content/base/test/test_bug466409.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,8 @@

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;
}

Expand Down
15 changes: 3 additions & 12 deletions content/events/test/bug299673.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ var popup;

function OpenWindow()
{
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
log({},">>> OpenWindow");
popup = window.open("","Test");

Expand Down Expand Up @@ -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");
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
}
}
11 changes: 2 additions & 9 deletions content/events/test/test_bug226361.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
13 changes: 3 additions & 10 deletions content/events/test/test_bug238987.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,10 @@
// 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);
}
}

Expand Down Expand Up @@ -105,9 +100,7 @@
}

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);
Expand Down
14 changes: 3 additions & 11 deletions content/events/test/test_bug409604.html
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,10 @@

// 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);
}
}

Expand Down Expand Up @@ -134,10 +129,7 @@
}

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);
Expand Down
9 changes: 2 additions & 7 deletions content/events/test/test_bug457672.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,10 @@
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);
}
}

Expand Down
17 changes: 4 additions & 13 deletions content/events/test/test_bug563329.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,7 @@

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");

Expand All @@ -69,26 +66,20 @@
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) {}

Expand Down
25 changes: 8 additions & 17 deletions content/events/test/test_bug574663.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
winUtils.advanceTimeAndRefresh(1000);

function nextTest() {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
if (!outstandingTests.length) {
winUtils.restoreNormalRefresh();
win.close();
Expand All @@ -74,7 +73,6 @@
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
Expand Down Expand Up @@ -102,27 +100,20 @@

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 () {
Expand Down
22 changes: 6 additions & 16 deletions content/events/test/test_bug607464.html
Original file line number Diff line number Diff line change
Expand Up @@ -72,29 +72,19 @@

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 () {
Expand Down
6 changes: 1 addition & 5 deletions content/events/test/test_clickevent_on_input.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,8 @@

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;
}
Expand Down
10 changes: 3 additions & 7 deletions content/html/content/test/test_bug583533.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@

/** 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");
Expand All @@ -32,9 +30,7 @@
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;
Expand Down
8 changes: 2 additions & 6 deletions content/html/document/test/test_bug369370.html
Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,12 @@
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
Expand Down

0 comments on commit 01ffcc1

Please sign in to comment.