Convert use of preferences API in style system mochitests to SpecialPowers. (Bug 653461, patch 1) r=bzbarsky

This commit is contained in:
L. David Baron 2011-04-30 15:16:18 -07:00
Родитель 878db847e2
Коммит 1f7739e466
5 изменённых файлов: 14 добавлений и 51 удалений

Просмотреть файл

@ -28,21 +28,14 @@
SimpleTest.waitForExplicitFinish();
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var prefService = Components.classes["@mozilla.org/preferences-service;1"].
getService(Components.interfaces.nsIPrefService);
var fontSizeBranch = prefService.getBranch("font.size.");
function get_pref(pref)
{
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
return fontSizeBranch.getIntPref(pref);
return SpecialPowers.getIntPref("font.size." + pref);
}
function set_pref(pref, val)
{
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
fontSizeBranch.setIntPref(pref, val);
SpecialPowers.setIntPref("font.size." + pref, val);
}
var cs1 = getComputedStyle(document.getElementById("one"), "");

Просмотреть файл

@ -57,54 +57,42 @@ function fs(idx) {
return getComputedStyle(elts[idx], "").marginBottom;
}
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
var CC = Components.classes;
var CI = Components.interfaces;
var prefs =
CC["@mozilla.org/preferences-service;1"].getService(CI.nsIPrefBranch);
prefs.clearUserPref('font.minimum-size.x-western');
SpecialPowers.clearUserPref('font.minimum-size.x-western');
// preference change is async (although one setTimeout might be enough?)
setTimeout(setTimeout, 0, step1, 0);
function step1() {
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
is(fs(0), "0px", "at min font size 0, 0px should compute to 0px");
is(fs(1), "4px", "at min font size 0, 4px should compute to 4px");
is(fs(2), "12px", "at min font size 0, 12px should compute to 12px");
is(fs(3), "28px", "at min font size 0, 28px should compute to 28px");
prefs.setIntPref('font.minimum-size.x-western', 7);
SpecialPowers.setIntPref('font.minimum-size.x-western', 7);
// preference change is async (although one setTimeout might be enough?)
setTimeout(setTimeout, 0, step2, 0);
}
function step2() {
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
is(fs(0), "0px", "at min font size 7, 0px should compute to 0px");
is(fs(1), "7px", "at min font size 7, 4px should compute to 7px");
is(fs(2), "12px", "at min font size 7, 12px should compute to 12px");
is(fs(3), "28px", "at min font size 7, 28px should compute to 28px");
prefs.setIntPref('font.minimum-size.x-western', 18);
SpecialPowers.setIntPref('font.minimum-size.x-western', 18);
// preference change is async (although one setTimeout might be enough?)
setTimeout(setTimeout, 0, step3, 0);
}
function step3() {
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
is(fs(0), "0px", "at min font size 18, 0px should compute to 0px");
is(fs(1), "18px", "at min font size 18, 4px should compute to 18px");
is(fs(2), "18px", "at min font size 18, 12px should compute to 18px");
is(fs(3), "28px", "at min font size 18, 28px should compute to 28px");
prefs.clearUserPref('font.minimum-size.x-western');
SpecialPowers.clearUserPref('font.minimum-size.x-western');
SimpleTest.finish();
}

Просмотреть файл

@ -43,21 +43,14 @@
SimpleTest.waitForExplicitFinish();
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var prefService = Components.classes["@mozilla.org/preferences-service;1"].
getService(Components.interfaces.nsIPrefService);
var dispBranch = prefService.getBranch("browser.display.");
function get_pref()
{
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
return dispBranch.getBoolPref("use_document_colors");
return SpecialPowers.getBoolPref("browser.display.use_document_colors");
}
function set_pref(val)
{
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
dispBranch.setBoolPref("use_document_colors", val);
SpecialPowers.setBoolPref("browser.display.use_document_colors", val);
}
var cs1 = getComputedStyle(document.getElementById("one"), "");

Просмотреть файл

@ -21,11 +21,7 @@
<pre id="test">
<script class="testbody" type="text/javascript">
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var prefService = Components.classes["@mozilla.org/preferences-service;1"].
getService(Components.interfaces.nsIPrefService);
var branch = prefService.getBranch("layout.");
var oldDPI = branch.getIntPref("css.dpi");
var oldDPI = SpecialPowers.getIntPref("layout.css.dpi");
var dpi = oldDPI;
function check(id, val) {
@ -46,7 +42,7 @@ function checkPixelRelativeUnits() {
checkPixelRelativeUnits();
branch.setIntPref("css.dpi", dpi = 96);
SpecialPowers.setIntPref("layout.css.dpi", dpi = 96);
var mozmm = document.getElementById("mozmm");
var mozmmSize = mozmm.getBoundingClientRect().width;
@ -55,7 +51,7 @@ is(Math.round(mozmmSize), Math.round(mozmm.getBoundingClientRect().height),
checkPixelRelativeUnits();
branch.setIntPref("css.dpi", dpi = 192);
SpecialPowers.setIntPref("layout.css.dpi", dpi = 192);
// At 192 dpi, a one-inch box should be twice the number of device pixels,
// and since we haven't changed the device-pixels-per-CSS-pixel ratio, the
@ -63,7 +59,7 @@ branch.setIntPref("css.dpi", dpi = 192);
check("mozmm", mozmmSize*2);
checkPixelRelativeUnits();
branch.setIntPref("css.dpi", oldDPI);
SpecialPowers.setIntPref("layout.css.dpi", oldDPI);
</script>
</pre>

Просмотреть файл

@ -32,21 +32,14 @@ function reinsert_node(e) {
par.insertBefore(e, sib);
}
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var prefService = Components.classes["@mozilla.org/preferences-service;1"].
getService(Components.interfaces.nsIPrefService);
var dispBranch = prefService.getBranch("layout.css.");
function get_pref()
{
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
return dispBranch.getBoolPref("visited_links_enabled");
return SpecialPowers.getBoolPref("layout.css.visited_links_enabled");
}
function set_pref(val)
{
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
dispBranch.setBoolPref("visited_links_enabled", val);
SpecialPowers.setBoolPref("layout.css.visited_links_enabled", val);
}
function snapshotsEqual(snap1, snap2)