Bug 1392391 - [reftest] Factor out code for creating nsIUri objects to isolated function, r=jmaher

This is a simple refactor of manifest.jsm.

We'd like to access the test objects from the parsed manifest in python. This
will allow us implement things like runByManifest (to improve intermittent
stability), share the chunking logic used by other harnesses, and much more.

To do this, we need to JSON serialize all of the test objects and dump them
to a file. The python side can then load the file, make modifications, and
send it back to the JS side to run.

The problem is that we turn the test urls into nsIURI objects as soon as they
are parsed, which isn't JSON serializable. This commit is a simple refactor to
delay this from happening. Instead, we will create the urls in reftest.jsm,
after the modified test objects have been loaded from python. This step will
be implemented by the next commit.

MozReview-Commit-ID: 6ijOqhNaig

--HG--
extra : rebase_source : fbfa259121a8d79bfc44695397d0d1ce08123558
This commit is contained in:
Andrew Halberstadt 2018-02-01 16:22:55 -05:00
Родитель 41c896bd5d
Коммит d75648cfac
1 изменённых файлов: 40 добавлений и 71 удалений

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

@ -296,25 +296,15 @@ function ReadManifest(aURL, aFilter)
CI.nsIScriptSecurityManager.DISALLOW_SCRIPT);
ReadManifest(incURI, aFilter);
}
} else if (items[0] == TYPE_LOAD) {
} else if (items[0] == TYPE_LOAD || items[0] == TYPE_SCRIPT) {
if (items.length != 2)
throw "Error in manifest file " + aURL.spec + " line " + lineNo + ": incorrect number of arguments to load";
if (expected_status != EXPECTED_PASS &&
expected_status != EXPECTED_DEATH)
throw "Error in manifest file " + aURL.spec + " line " + lineNo + ": incorrect number of arguments to " + items[0];
if (items[0] == TYPE_LOAD && expected_status != EXPECTED_PASS && expected_status != EXPECTED_DEATH)
throw "Error in manifest file " + aURL.spec + " line " + lineNo + ": incorrect known failure type for load test";
var [testURI] = runHttp
? ServeFiles(principal, httpDepth,
listURL, [items[1]])
: [g.ioService.newURI(items[1], null, listURL)];
var prettyPath = runHttp
? g.ioService.newURI(items[1], null, listURL).spec
: testURI.spec;
secMan.checkLoadURIWithPrincipal(principal, testURI,
CI.nsIScriptSecurityManager.DISALLOW_SCRIPT);
AddTestItem({ type: TYPE_LOAD,
expected: expected_status,
manifest: aURL.spec,
allowSilentFail: allow_silent_fail,
prettyPath: prettyPath,
minAsserts: minAsserts,
maxAsserts: maxAsserts,
needsFocus: needs_focus,
@ -325,36 +315,9 @@ function ReadManifest(aURL, aFilter)
fuzzyMaxDelta: fuzzy_delta.max,
fuzzyMinPixels: fuzzy_pixels.min,
fuzzyMaxPixels: fuzzy_pixels.max,
url1: testURI,
url2: null,
chaosMode: chaosMode }, aFilter);
} else if (items[0] == TYPE_SCRIPT) {
if (items.length != 2)
throw "Error in manifest file " + aURL.spec + " line " + lineNo + ": incorrect number of arguments to script";
var [testURI] = runHttp
? ServeFiles(principal, httpDepth,
listURL, [items[1]])
: [g.ioService.newURI(items[1], null, listURL)];
var prettyPath = runHttp
? g.ioService.newURI(items[1], null, listURL).spec
: testURI.spec;
secMan.checkLoadURIWithPrincipal(principal, testURI,
CI.nsIScriptSecurityManager.DISALLOW_SCRIPT);
AddTestItem({ type: TYPE_SCRIPT,
expected: expected_status,
allowSilentFail: allow_silent_fail,
prettyPath: prettyPath,
minAsserts: minAsserts,
maxAsserts: maxAsserts,
needsFocus: needs_focus,
slow: slow,
prefSettings1: testPrefSettings,
prefSettings2: refPrefSettings,
fuzzyMinDelta: fuzzy_delta.min,
fuzzyMaxDelta: fuzzy_delta.max,
fuzzyMinPixels: fuzzy_pixels.min,
fuzzyMaxPixels: fuzzy_pixels.max,
url1: testURI,
runHttp: runHttp,
httpDepth: httpDepth,
url1: items[1],
url2: null,
chaosMode: chaosMode }, aFilter);
} else if (items[0] == TYPE_REFTEST_EQUAL || items[0] == TYPE_REFTEST_NOTEQUAL || items[0] == TYPE_PRINT) {
@ -367,22 +330,9 @@ function ReadManifest(aURL, aFilter)
throw "Error in manifest file " + aURL.spec + " line " + lineNo + ": minimum fuzz must be zero for tests of type " + items[0];
}
var [testURI, refURI] = runHttp
? ServeFiles(principal, httpDepth,
listURL, [items[1], items[2]])
: [g.ioService.newURI(items[1], null, listURL),
g.ioService.newURI(items[2], null, listURL)];
var prettyPath = runHttp
? g.ioService.newURI(items[1], null, listURL).spec
: testURI.spec;
secMan.checkLoadURIWithPrincipal(principal, testURI,
CI.nsIScriptSecurityManager.DISALLOW_SCRIPT);
secMan.checkLoadURIWithPrincipal(principal, refURI,
CI.nsIScriptSecurityManager.DISALLOW_SCRIPT);
var type = items[0];
if (g.compareStyloToGecko || g.compareRetainedDisplayLists) {
type = TYPE_REFTEST_EQUAL;
refURI = testURI;
// We expect twice as many assertion failures when running in
// styloVsGecko mode because we run each test twice: once in
@ -402,8 +352,8 @@ function ReadManifest(aURL, aFilter)
AddTestItem({ type: type,
expected: expected_status,
manifest: aURL.spec,
allowSilentFail: allow_silent_fail,
prettyPath: prettyPath,
minAsserts: minAsserts,
maxAsserts: maxAsserts,
needsFocus: needs_focus,
@ -414,8 +364,10 @@ function ReadManifest(aURL, aFilter)
fuzzyMaxDelta: fuzzy_delta.max,
fuzzyMinPixels: fuzzy_pixels.min,
fuzzyMaxPixels: fuzzy_pixels.max,
url1: testURI,
url2: refURI,
runHttp: runHttp,
httpDepth: httpDepth,
url1: items[1],
url2: items[2],
chaosMode: chaosMode }, aFilter);
} else {
throw "Error in manifest file " + aURL.spec + " line " + lineNo + ": unknown test type " + items[0];
@ -692,7 +644,7 @@ function ExtractRange(matches, startIndex, defaultMin = 0) {
};
}
function ServeFiles(manifestPrincipal, depth, aURL, files) {
function ServeTestBase(aURL, depth) {
var listURL = aURL.QueryInterface(CI.nsIFileURL);
var directory = listURL.file.parent;
@ -717,27 +669,45 @@ function ServeFiles(manifestPrincipal, depth, aURL, files) {
// Give the testbase URI access to XUL and XBL
Services.perms.add(testbase, "allowXULXBL", Services.perms.ALLOW_ACTION);
return testbase;
}
function CreateUrls(test) {
let secMan = CC[NS_SCRIPTSECURITYMANAGER_CONTRACTID]
.getService(CI.nsIScriptSecurityManager);
let manifestURL = g.ioService.newURI(test.manifest);
let principal = secMan.createCodebasePrincipal(manifestURL, {});
let testbase = manifestURL;
if (test.runHttp)
testbase = ServeTestBase(manifestURL, test.httpDepth)
function FileToURI(file)
{
// Only serve relative URIs via the HTTP server, not absolute
// ones like about:blank.
if (file === null)
return file;
var testURI = g.ioService.newURI(file, null, testbase);
// XXX necessary? manifestURL guaranteed to be file, others always HTTP
secMan.checkLoadURIWithPrincipal(manifestPrincipal, testURI,
secMan.checkLoadURIWithPrincipal(principal, testURI,
CI.nsIScriptSecurityManager.DISALLOW_SCRIPT);
return testURI;
}
return files.map(FileToURI);
let files = [test.url1, test.url2];
[test.url1, test.url2] = files.map(FileToURI);
if (test.url2 && g.compareStyloToGecko)
test.url2 = test.url1;
return test;
}
function AddTestItem(aTest, aFilter) {
if (!aFilter)
aFilter = [null, [], false];
aTest = CreateUrls(aTest);
var globalFilter = aFilter[0];
var manifestFilter = aFilter[1];
var invertManifest = aFilter[2];
@ -753,9 +723,8 @@ function AddTestItem(aTest, aFilter) {
return;
if (aTest.url2 !== null)
aTest.identifier = [aTest.prettyPath, aTest.type, aTest.url2.spec];
aTest.identifier = [aTest.url1.spec, aTest.type, aTest.url2.spec];
else
aTest.identifier = aTest.prettyPath;
aTest.identifier = aTest.url1.spec;
g.urls.push(aTest);
}