Bug 788967 - Add a default-preferences statement for reftest manifests. r=dbaron

This commit is contained in:
Cameron McCormack 2012-11-28 10:06:33 +11:00
parent 6fa243632b
commit aca7de9ff8
6 changed files with 111 additions and 23 deletions

View File

@ -0,0 +1,6 @@
# test default-preferences on include commands
# In default-preferences-tests.list, the default-preferences line in effect
# before the include statement sets different font sizes for the test and
# reference files. Those default preferences should not inherit into this file.
== font-default.html font-default.html

View File

@ -0,0 +1,28 @@
# test default-preferences
# test default-preferences with a pref()
default-preferences pref(font.size.variable.x-western,24)
!= font-default.html font-size-16.html
== font-default.html font-size-24.html
# test that a default preference can be overridden
pref(font.size.variable.x-western,16) == font-default.html font-size-16.html
pref(font.size.variable.x-western,16) != font-default.html font-size-24.html
# test that default preferences are kept when other test-specific preferences are set
pref(font.size.variable.zh-HK,36) != font-default.html font-size-16.html
pref(font.size.variable.zh-HK,36) == font-default.html font-size-24.html
# test default-preferences with test-pref() and ref-pref()
default-preferences test-pref(font.size.variable.x-western,16) ref-pref(font.size.variable.x-western,24)
!= font-default.html font-default.html
== font-default.html font-size-16.html
== font-size-24.html font-default.html
# test that default-preferences does not apply to include commands
include default-preferences-include.list
# test resetting default-preferences
default-preferences
== font-default.html font-default.html

View File

@ -65,6 +65,9 @@ include scripttests.list
# test url-prefix
include urlprefixtests.list
# test default-preferences
include default-preferences-tests.list
# test that all corners are visible
!= corners-1.html corners-1-ref.html
!= corners-2.html corners-2-ref.html

View File

@ -290,6 +290,28 @@ must be one of the following:
a manifest, it is legal to use it anywhere in a manifest. Subsequent uses
of url-prefix overwrite any existing values.
4. Specification of default preferences
default-preferences <preference>*
where <preference> is defined above.
The <preference> settings will be used for all following test items in the
manifest.
If a test item includes its own preference settings, then they will override
any settings for preferences of the same names that are set using
default-preferences, just as later items within a line override earlier ones.
A default-preferences line with no <preference> settings following it will
reset the set of default preferences to be empty.
As with url-prefix, default-preferences will often be used at the start of a
manifest file so that it applies to all test items, but it is legal for
default-preferences to appear anywhere in the manifest. A subsequent
default-preferences will reset any previous default preference values and
overwrite them with the specified <preference> values.
This test manifest format could be used by other harnesses, such as ones
that do not depend on XUL, or even ones testing other layout engines.

View File

@ -41,6 +41,8 @@ def parseManifest(manifest, dirs):
if items[0] == "url-prefix":
urlprefix = items[1]
continue
elif items[0] == "default-preferences":
continue
elif items[0] == "include":
parseManifest(os.path.join(manifestdir, items[1]), dirs)
continue

View File

@ -130,6 +130,7 @@ const PREF_INTEGER = 2;
var gPrefsToRestore = [];
const gProtocolRE = /^\w+:/;
const gPrefItemRE = /^(|test-|ref-)pref\((.+?),(.*)\)$/;
var HTTP_SERVER_PORT = 4444;
const HTTP_SERVER_PORTS_TO_TRY = 50;
@ -654,6 +655,32 @@ function BuildConditionSandbox(aURL) {
return sandbox;
}
function AddPrefSettings(aWhere, aPrefName, aPrefValExpression, aSandbox, aTestPrefSettings, aRefPrefSettings)
{
var prefVal = Components.utils.evalInSandbox("(" + aPrefValExpression + ")", aSandbox);
var prefType;
var valType = typeof(prefVal);
if (valType == "boolean") {
prefType = PREF_BOOLEAN;
} else if (valType == "string") {
prefType = PREF_STRING;
} else if (valType == "number" && (parseInt(prefVal) == prefVal)) {
prefType = PREF_INTEGER;
} else {
return false;
}
var setting = { name: aPrefName,
type: prefType,
value: prefVal };
if (aWhere != "ref-") {
aTestPrefSettings.push(setting);
}
if (aWhere != "test-") {
aRefPrefSettings.push(setting);
}
return true;
}
function ReadTopManifest(aFileURL)
{
gURLs = new Array();
@ -693,6 +720,7 @@ function ReadManifest(aURL, inherited_status)
var sandbox = BuildConditionSandbox(aURL);
var lineNo = 0;
var urlprefix = "";
var defaultTestPrefSettings = [], defaultRefPrefSettings = [];
for each (var str in lines) {
++lineNo;
if (str.charAt(0) == "#")
@ -713,13 +741,31 @@ function ReadManifest(aURL, inherited_status)
continue;
}
if (items[0] == "default-preferences") {
var m;
var item;
defaultTestPrefSettings = [];
defaultRefPrefSettings = [];
items.shift();
while ((item = items.shift())) {
if (!(m = item.match(gPrefItemRE))) {
throw "Unexpected item in default-preferences list in manifest file " + aURL.spec + " line " + lineNo;
}
if (!AddPrefSettings(m[1], m[2], m[3], sandbox, defaultTestPrefSettings, defaultRefPrefSettings)) {
throw "Error in pref value in manifest file " + aURL.spec + " line " + lineNo;
}
}
continue;
}
var expected_status = EXPECTED_PASS;
var allow_silent_fail = false;
var minAsserts = 0;
var maxAsserts = 0;
var needs_focus = false;
var slow = false;
var testPrefSettings = [], refPrefSettings = [];
var testPrefSettings = defaultTestPrefSettings.concat();
var refPrefSettings = defaultRefPrefSettings.concat();
var fuzzy_max_delta = 2;
var fuzzy_max_pixels = 1;
@ -785,31 +831,11 @@ function ReadManifest(aURL, inherited_status)
} else if (item == "silentfail") {
cond = false;
allow_silent_fail = true;
} else if ((m = item.match(/^(|test-|ref-)pref\((.+?),(.*)\)$/))) {
} else if ((m = item.match(gPrefItemRE))) {
cond = false;
var where = m[1];
var prefName = m[2];
var prefVal = Components.utils.evalInSandbox("(" + m[3] + ")", sandbox);
var prefType;
var valType = typeof(prefVal);
if (valType == "boolean") {
prefType = PREF_BOOLEAN;
} else if (valType == "string") {
prefType = PREF_STRING;
} else if (valType == "number" && (parseInt(prefVal) == prefVal)) {
prefType = PREF_INTEGER;
} else {
if (!AddPrefSettings(m[1], m[2], m[3], sandbox, testPrefSettings, refPrefSettings)) {
throw "Error in pref value in manifest file " + aURL.spec + " line " + lineNo;
}
var setting = { name: prefName,
type: prefType,
value: prefVal };
if (where != "ref-") {
testPrefSettings.push(setting);
}
if (where != "test-") {
refPrefSettings.push(setting);
}
} else if ((m = item.match(/^fuzzy\((\d+),(\d+)\)$/))) {
cond = false;
expected_status = EXPECTED_FUZZY;
@ -1674,6 +1700,7 @@ function RestoreChangedPreferences()
if (gPrefsToRestore.length > 0) {
var prefs = Components.classes["@mozilla.org/preferences-service;1"].
getService(Components.interfaces.nsIPrefBranch);
gPrefsToRestore.reverse();
gPrefsToRestore.forEach(function(ps) {
var value = ps.value;
if (ps.type == PREF_BOOLEAN) {