Bug 376489 - Serve reftests from a web server so as not to depend on external resources, if the reftest is marked as needing HTTP; also picks up support for HTTP header and status modification in reftest files. r=dbaron

This commit is contained in:
jwalden@mit.edu 2007-07-18 14:32:50 -07:00
Родитель 190d5a54d9
Коммит 13955bbb15
10 изменённых файлов: 139 добавлений и 23 удалений

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

@ -5,8 +5,6 @@
<title>&lt;object&gt;: 404 data with type</title>
</head>
<body>
<p><!-- XXX
- This should really be on a server run locally
--><object type="text/html" data="http://www.mozilla.org/this_does_not_exist">PASS</object></p>
<p><object type="text/html" data="extra/404.html">PASS</object></p>
</body>
</html>

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

@ -5,8 +5,6 @@
<title>&lt;object&gt;: 404 data</title>
</head>
<body>
<p><!-- XXX
- This should really be on a server run locally
--><object data="http://www.mozilla.org/this_does_not_exist.html">PASS</object></p>
<p><object data="extra/404.html">PASS</object></p>
</body>
</html>

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

@ -0,0 +1,9 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<title>404 Not Found</title>
</head>
<body>
<p>This is a 404 page.</p>
</body>
</html>

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

@ -0,0 +1 @@
HTTP 404 Not Found

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

@ -1,6 +1,6 @@
== no-attrs.html no-attrs-ref.html
== 404-data.html 404-data-ref.html
== 404-data-with-type.html 404-data-with-type-ref.html
HTTP == 404-data.html 404-data-ref.html
HTTP == 404-data-with-type.html 404-data-with-type-ref.html
== page-as-data.html page-as-data-ref.html
== page-as-data-with-type.html page-as-data-with-type-ref.html
== connection-refused.html connection-refused-ref.html
@ -9,7 +9,14 @@
== image-no-useful-extension-typesniff.html image-no-useful-extension-typesniff-ref.html
== image-no-useful-extension-with-type.html image-no-useful-extension-with-type-ref.html
#
# XXX missing tests 011-015 from http://biesi.damowmow.com/object/ here; need
# This test must be run on an HTTP server because it relies on the HTTP
# Content-Type overriding the type specified by the attribute on the object,
# but when run from a local file the type attribute will override the
# content-sniffed assumed type (text/html based entirely on the extension).
#
HTTP == type-overridden-by-server.html type-overridden-by-server-ref.html
#
# XXX missing tests 012-015 from http://biesi.damowmow.com/object/ here; need
# a controllable HTTP server (or preferably one run on the test machine)
# to add them
#

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

@ -0,0 +1,10 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<!-- http://biesi.damowmow.com/object/011.html -->
<html lang="en">
<head>
<title>&lt;object&gt;: Server override of type (PNG vs HTML)</title>
</head>
<body>
<p><iframe style="border: 0px" src="extra/pass.html"></iframe></p>
</body>
</html>

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

@ -0,0 +1,10 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<!-- http://biesi.damowmow.com/object/011.html -->
<html lang="en">
<head>
<title>&lt;object&gt;: Server override of type (PNG vs HTML)</title>
</head>
<body>
<p><object type="image/png" data="extra/pass.html">FAIL</object></p>
</body>
</html>

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

@ -43,7 +43,7 @@ comments) must be one of the following:
2. A test item
<failure-type>* <type> <url> <url_ref>
<failure-type>* [<http>] <type> <url> <url_ref>
where
@ -78,17 +78,45 @@ comments) must be one of the following:
fails-if(MOZ_WIDGET_TOOLKIT=="cocoa") ...
fails-if(MOZ_WIDGET_TOOLKIT=="gtk2") ...
b. <type> is one of the following:
b. <http>, if present, is the string "HTTP" (sans quotes), indicating that
the test should be run over an HTTP server because it requires certain
HTTP headers or a particular HTTP status. (Don't use this if your test
doesn't require this functionality, because it unnecessarily slows down
the test.)
HTTP tests have the restriction that any resource an HTTP test accesses
must be accessed using a relative URL, and the test and the resource must
be within the directory containing the reftest manifest that describes
the test (or within a descendant directory).
To modify the HTTP status or headers of a resource named FOO, create a
sibling file named FOO^headers^ with the following contents:
[<http-status>]
<http-header>*
<http-status> A line of the form "HTTP ###[ <description>]", where
### indicates the desired HTTP status and <description>
indicates a desired HTTP status description, if any.
If this line is omitted, the default is "HTTP 200 OK".
<http-header> A line in standard HTTP header line format, i.e.
"Field-Name: field-value". You may not repeat the use
of a Field-Name and must coalesce such headers together,
and each header must be specified on a single line, but
otherwise the format exactly matches that from HTTP
itself.
c. <type> is one of the following:
== The test passes if the images of the two renderings are the
SAME.
!= The test passes if the images of the two renderings are
DIFFERENT.
c. <url> is either a relative file path or an absolute URL for the
d. <url> is either a relative file path or an absolute URL for the
test page
d. <url_ref> is either a relative file path or an absolute URL for
e. <url_ref> is either a relative file path or an absolute URL for
the reference page
The only difference between <url> and <url_ref> is that results of

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

@ -1,3 +1,4 @@
/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- /
/* vim: set shiftwidth=4 tabstop=8 autoindent cindent expandtab: */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
@ -56,12 +57,18 @@ var gURLs;
var gState;
var gPart1Key;
var gFailureTimeout;
var gServer;
var gCount = 0;
var gIOService;
const EXPECTED_PASS = 0;
const EXPECTED_FAIL = 1;
const EXPECTED_RANDOM = 2;
const EXPECTED_DEATH = 3; // test must be skipped to avoid e.g. crash/hang
const HTTP_SERVER_PORT = 4444;
function OnRefTestLoad()
{
gBrowser = document.getElementById("browser");
@ -73,8 +80,12 @@ function OnRefTestLoad()
gCanvas.setAttribute("width", windowElem.getAttribute("width"));
gCanvas.setAttribute("height", windowElem.getAttribute("height"));
gIOService = CC[IO_SERVICE_CONTRACTID].getService(CI.nsIIOService);
try {
ReadTopManifest(window.arguments[0]);
if (gServer)
gServer.start(HTTP_SERVER_PORT);
StartCurrentTest();
} catch (ex) {
gBrowser.loadURI('data:text/plain,' + ex);
@ -89,8 +100,7 @@ function OnRefTestUnload()
function ReadTopManifest(aFileURL)
{
gURLs = new Array();
var ios = CC[IO_SERVICE_CONTRACTID].getService(CI.nsIIOService);
var url = ios.newURI(aFileURL, null, null);
var url = gIOService.newURI(aFileURL, null, null);
if (!url || !url.schemeIs("file"))
throw "Expected a file URL for the manifest.";
ReadManifest(url);
@ -98,7 +108,6 @@ function ReadTopManifest(aFileURL)
function ReadManifest(aURL)
{
var ios = CC[IO_SERVICE_CONTRACTID].getService(CI.nsIIOService);
var listURL = aURL.QueryInterface(CI.nsIFileURL);
var secMan = CC[NS_SCRIPTSECURITYMANAGER_CONTRACTID]
@ -156,32 +165,72 @@ function ReadManifest(aURL)
}
}
var runHttp = items[0] == "HTTP";
if (runHttp)
items.shift();
if (items[0] == "include") {
if (items.length != 2)
if (items.length != 2 || runHttp)
throw "Error in manifest file " + aURL.spec + " line " + lineNo;
var incURI = ios.newURI(items[1], null, listURL);
var incURI = gIOService.newURI(items[1], null, listURL);
secMan.checkLoadURI(aURL, incURI,
CI.nsIScriptSecurityManager.DISALLOW_SCRIPT);
ReadManifest(incURI);
} else if (items[0] == "==" || items[0] == "!=") {
if (items.length != 3)
throw "Error in manifest file " + aURL.spec + " line " + lineNo;
var testURI = ios.newURI(items[1], null, listURL);
var refURI = ios.newURI(items[2], null, listURL);
var [testURI, refURI] = runHttp
? ServeFiles(aURL,
listURL.file.parent, items[1], items[2])
: [gIOService.newURI(items[1], null, listURL),
gIOService.newURI(items[2], null, listURL)];
var prettyPath = runHttp
? gIOService.newURI(items[1], null, listURL).spec
: testURI.spec;
secMan.checkLoadURI(aURL, testURI,
CI.nsIScriptSecurityManager.DISALLOW_SCRIPT);
secMan.checkLoadURI(aURL, refURI,
CI.nsIScriptSecurityManager.DISALLOW_SCRIPT);
gURLs.push( { equal: (items[0] == "=="),
expected: expected_status,
prettyPath: prettyPath,
url1: testURI,
url2: refURI} );
url2: refURI } );
} else {
throw "Error in manifest file " + aURL.spec + " line " + lineNo;
}
} while (more);
}
function ServeFiles(manifestURL, directory, file1, file2)
{
if (!gServer)
gServer = CC["@mozilla.org/server/jshttp;1"].
createInstance(CI.nsIHttpServer);
gCount++;
var path = "/" + gCount + "/";
gServer.registerDirectory(path, directory);
var testURI = gIOService.newURI("http://localhost:" + HTTP_SERVER_PORT +
path + file1,
null, null);
var refURI = gIOService.newURI("http://localhost:" + HTTP_SERVER_PORT +
path + file2,
null, null);
var secMan = CC[NS_SCRIPTSECURITYMANAGER_CONTRACTID]
.getService(CI.nsIScriptSecurityManager);
// XXX necessary? manifestURL guaranteed to be file, others always HTTP
secMan.checkLoadURI(manifestURL, testURI,
CI.nsIScriptSecurityManager.DISALLOW_SCRIPT);
secMan.checkLoadURI(manifestURL, refURI,
CI.nsIScriptSecurityManager.DISALLOW_SCRIPT);
return [testURI, refURI];
}
function StartCurrentTest()
{
// make sure we don't run tests that are expected to kill the browser
@ -206,6 +255,8 @@ function StartCurrentURI(aState)
function DoneTests()
{
if (gServer)
gServer.stop();
goQuitApplication();
}
@ -318,7 +369,7 @@ function DocumentLoaded()
if (!gURLs[0].equal) {
result += "(!=) ";
}
result += gURLs[0].url1.spec; // the URL being tested
result += gURLs[0].prettyPath; // the URL being tested
dump(result + "\n");
if (!test_passed && expected == EXPECTED_PASS) {
dump("REFTEST IMAGE 1 (TEST): " + gPart1Key + "\n");
@ -330,7 +381,7 @@ function DocumentLoaded()
StartCurrentTest();
break;
default:
throw "Unexpected state."
throw "Unexpected state.";
}
}

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

@ -45,6 +45,10 @@ include $(DEPTH)/config/autoconf.mk
MODULE = test_necko
EXTRA_COMPONENTS = \
httpd.js \
$(NULL)
XPIDLSRCS = \
nsIHttpServer.idl \
$(NULL)