2006-09-05 21:50:54 +00:00
|
|
|
/* vim: set shiftwidth=4 tabstop=8 autoindent cindent expandtab: */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is Mozilla's layout acceptance tests.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is the Mozilla Foundation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2006
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* L. David Baron <dbaron@dbaron.org>, Mozilla Corporation (original author)
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
const CC = Components.classes;
|
|
|
|
const CI = Components.interfaces;
|
|
|
|
const CR = Components.results;
|
|
|
|
|
|
|
|
const XHTML_NS = "http://www.w3.org/1999/xhtml";
|
|
|
|
|
|
|
|
const NS_LOCAL_FILE_CONTRACTID = "@mozilla.org/file/local;1";
|
|
|
|
const IO_SERVICE_CONTRACTID = "@mozilla.org/network/io-service;1";
|
|
|
|
const NS_LOCALFILEINPUTSTREAM_CONTRACTID =
|
|
|
|
"@mozilla.org/network/file-input-stream;1";
|
|
|
|
|
2007-02-12 02:21:18 +00:00
|
|
|
const LOAD_FAILURE_TIMEOUT = 10000; // ms
|
|
|
|
|
2006-09-05 21:50:54 +00:00
|
|
|
var gBrowser;
|
|
|
|
var gCanvas;
|
|
|
|
var gURLs;
|
|
|
|
var gState;
|
|
|
|
var gPart1Key;
|
|
|
|
|
2007-02-08 19:24:43 +00:00
|
|
|
const EXPECTED_PASS = 0;
|
|
|
|
const EXPECTED_FAIL = 1;
|
|
|
|
const EXPECTED_RANDOM = 2;
|
|
|
|
|
2006-09-05 21:50:54 +00:00
|
|
|
function OnRefTestLoad()
|
|
|
|
{
|
|
|
|
gBrowser = document.getElementById("browser");
|
2007-02-12 02:21:18 +00:00
|
|
|
|
|
|
|
gBrowser.addEventListener("load", OnDocumentLoad, true);
|
2006-09-05 21:50:54 +00:00
|
|
|
|
|
|
|
gCanvas = document.createElementNS(XHTML_NS, "canvas");
|
|
|
|
var windowElem = document.documentElement;
|
|
|
|
gCanvas.setAttribute("width", windowElem.getAttribute("width"));
|
|
|
|
gCanvas.setAttribute("height", windowElem.getAttribute("height"));
|
|
|
|
|
|
|
|
try {
|
|
|
|
ReadTopManifest(window.arguments[0]);
|
2007-02-12 02:21:18 +00:00
|
|
|
StartCurrentTest();
|
2006-09-05 21:50:54 +00:00
|
|
|
} catch (ex) {
|
|
|
|
gBrowser.loadURI('data:text/plain,' + ex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function OnRefTestUnload()
|
|
|
|
{
|
2007-02-12 02:21:18 +00:00
|
|
|
gBrowser.removeEventListener("load", OnDocumentLoad, true);
|
2006-09-05 21:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function ReadTopManifest(aFileURL)
|
|
|
|
{
|
|
|
|
gURLs = new Array();
|
|
|
|
var ios = CC[IO_SERVICE_CONTRACTID].getService(CI.nsIIOService);
|
|
|
|
var url = ios.newURI(aFileURL, null, null);
|
|
|
|
if (!url || !url.schemeIs("file"))
|
|
|
|
throw "Expected a file URL for the manifest.";
|
|
|
|
ReadManifest(url);
|
|
|
|
}
|
|
|
|
|
|
|
|
function ReadManifest(aURL)
|
|
|
|
{
|
|
|
|
var ios = CC[IO_SERVICE_CONTRACTID].getService(CI.nsIIOService);
|
|
|
|
var listURL = aURL.QueryInterface(CI.nsIFileURL);
|
|
|
|
|
|
|
|
var fis = CC[NS_LOCALFILEINPUTSTREAM_CONTRACTID].
|
|
|
|
createInstance(CI.nsIFileInputStream);
|
|
|
|
fis.init(listURL.file, -1, -1, false);
|
|
|
|
var lis = fis.QueryInterface(CI.nsILineInputStream);
|
|
|
|
|
2007-02-08 19:24:43 +00:00
|
|
|
var sandbox = new Components.utils.Sandbox(aURL.spec);
|
|
|
|
for (var prop in gAutoconfVars)
|
|
|
|
sandbox[prop] = gAutoconfVars[prop];
|
|
|
|
|
2006-09-05 21:50:54 +00:00
|
|
|
var line = {value:null};
|
|
|
|
var lineNo = 0;
|
|
|
|
do {
|
|
|
|
var more = lis.readLine(line);
|
|
|
|
++lineNo;
|
|
|
|
var str = line.value;
|
|
|
|
str = /^[^#]*/.exec(str)[0]; // strip everything after "#"
|
2006-10-27 19:56:49 +00:00
|
|
|
if (!str)
|
|
|
|
continue; // entire line was a comment
|
2006-10-28 04:17:21 +00:00
|
|
|
// strip leading and trailing whitespace
|
|
|
|
str = str.replace(/^\s*/, '').replace(/\s*$/, '');
|
2006-09-05 21:50:54 +00:00
|
|
|
if (!str || str == "")
|
|
|
|
continue;
|
|
|
|
var items = str.split(/\s+/); // split on whitespace
|
|
|
|
|
2007-02-08 19:24:43 +00:00
|
|
|
var expected_status = EXPECTED_PASS;
|
|
|
|
while (items[0].match(/^(fails|random)/)) {
|
|
|
|
var item = items.shift();
|
|
|
|
var stat;
|
|
|
|
var cond;
|
|
|
|
var m = item.match(/^(fails|random)-if(\(.*\))$/);
|
|
|
|
if (m) {
|
|
|
|
stat = m[1];
|
|
|
|
// Note: m[2] contains the parentheses, and we want them.
|
|
|
|
cond = Components.utils.evalInSandbox(m[2], sandbox);
|
|
|
|
} else if (item.match(/^(fails|random)$/)) {
|
|
|
|
stat = item;
|
|
|
|
cond = true;
|
|
|
|
} else {
|
|
|
|
throw "Error in manifest file " + aURL + " line " + lineNo;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cond) {
|
|
|
|
if (stat == "fails") {
|
|
|
|
expected_status = EXPECTED_FAIL;
|
|
|
|
} else if (stat == "random") {
|
|
|
|
expected_status = EXPECTED_RANDOM;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-09-05 21:50:54 +00:00
|
|
|
if (items[0] == "include") {
|
|
|
|
if (items.length != 2)
|
|
|
|
throw "Error in manifest file " + aURL + " line " + lineNo;
|
|
|
|
ReadManifest(ios.newURI(items[1], null, listURL));
|
2007-02-08 19:24:43 +00:00
|
|
|
} else if (items[0] == "==" || items[0] == "!=") {
|
2006-09-05 21:50:54 +00:00
|
|
|
if (items.length != 3)
|
|
|
|
throw "Error in manifest file " + aURL + " line " + lineNo;
|
2007-02-08 19:24:43 +00:00
|
|
|
gURLs.push( { equal: (items[0] == "=="),
|
|
|
|
expected: expected_status,
|
2006-09-05 21:50:54 +00:00
|
|
|
url1: ios.newURI(items[1], null, listURL),
|
|
|
|
url2: ios.newURI(items[2], null, listURL)} );
|
|
|
|
} else {
|
|
|
|
throw "Error in manifest file " + aURL + " line " + lineNo;
|
|
|
|
}
|
|
|
|
} while (more);
|
|
|
|
}
|
|
|
|
|
2007-02-12 02:21:18 +00:00
|
|
|
function StartCurrentTest()
|
|
|
|
{
|
|
|
|
if (gURLs.length == 0)
|
|
|
|
DoneTests();
|
|
|
|
else
|
|
|
|
StartCurrentURI(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
function StartCurrentURI(aState)
|
2006-09-05 21:50:54 +00:00
|
|
|
{
|
2007-02-12 02:21:18 +00:00
|
|
|
gState = aState;
|
|
|
|
gBrowser.loadURI(gURLs[0]["url" + aState].spec);
|
2006-09-05 21:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function DoneTests()
|
|
|
|
{
|
2007-01-08 18:22:48 +00:00
|
|
|
goQuitApplication();
|
2006-09-05 21:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function IFrameToKey()
|
|
|
|
{
|
|
|
|
var ctx = gCanvas.getContext("2d");
|
|
|
|
/* XXX This needs to be rgb(255,255,255) because otherwise we get
|
|
|
|
* black bars at the bottom of every test that are different size
|
|
|
|
* for the first test and the rest (scrollbar-related??) */
|
|
|
|
ctx.drawWindow(gBrowser.contentWindow, 0, 0,
|
|
|
|
gCanvas.width, gCanvas.height, "rgb(255,255,255)");
|
|
|
|
return gCanvas.toDataURL();
|
|
|
|
}
|
|
|
|
|
2007-02-13 00:34:58 +00:00
|
|
|
function OnDocumentLoad(event)
|
2007-02-12 02:21:18 +00:00
|
|
|
{
|
2007-02-13 00:34:58 +00:00
|
|
|
if (event.target != gBrowser.contentDocument)
|
|
|
|
// Ignore load events for subframes.
|
|
|
|
return;
|
|
|
|
|
2007-02-13 00:03:50 +00:00
|
|
|
// Since we can't use a bubbling-phase load listener from chrome,
|
|
|
|
// this is a capturing phase listener. So do setTimeout twice, the
|
|
|
|
// first to get us after the onload has fired in the content, and
|
|
|
|
// the second to get us after any setTimeout(foo, 0) in the content.
|
|
|
|
setTimeout(setTimeout, 0, DocumentLoaded, 0);
|
2007-02-12 02:21:18 +00:00
|
|
|
}
|
|
|
|
|
2006-09-05 21:50:54 +00:00
|
|
|
function DocumentLoaded()
|
|
|
|
{
|
|
|
|
var key = IFrameToKey();
|
|
|
|
switch (gState) {
|
|
|
|
case 1:
|
|
|
|
gPart1Key = key;
|
|
|
|
|
2007-02-12 02:21:18 +00:00
|
|
|
StartCurrentURI(2);
|
2006-09-05 21:50:54 +00:00
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
var equal = (key == gPart1Key);
|
2007-01-26 06:56:58 +00:00
|
|
|
var result = "REFTEST ";
|
2006-09-05 21:50:54 +00:00
|
|
|
var test_passed = (equal == gURLs[0].equal);
|
2007-02-08 19:24:43 +00:00
|
|
|
var expected = gURLs[0].expected;
|
|
|
|
switch (expected) {
|
|
|
|
case EXPECTED_PASS:
|
|
|
|
if (!test_passed) result += "UNEXPECTED ";
|
|
|
|
break;
|
|
|
|
case EXPECTED_FAIL:
|
|
|
|
if (test_passed) result += "UNEXPECTED ";
|
|
|
|
break;
|
|
|
|
case EXPECTED_RANDOM:
|
|
|
|
result += "(RESULT EXPECTED TO BE RANDOM) "
|
|
|
|
break;
|
2006-09-05 21:50:54 +00:00
|
|
|
}
|
|
|
|
if (test_passed) {
|
|
|
|
result += "PASS: ";
|
|
|
|
} else {
|
|
|
|
result += "FAIL: ";
|
|
|
|
}
|
|
|
|
if (!gURLs[0].equal) {
|
|
|
|
result += "(!=) ";
|
|
|
|
}
|
|
|
|
result += gURLs[0].url1.spec;
|
|
|
|
dump(result + "\n");
|
2007-02-08 19:24:43 +00:00
|
|
|
if (!test_passed && expected == EXPECTED_PASS) {
|
|
|
|
dump("REFTEST IMAGE 1 (TEST): " + gPart1Key + "\n");
|
|
|
|
dump("REFTEST IMAGE 2 (REFERENCE): " + key + "\n");
|
2006-09-05 21:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gPart1Key = undefined;
|
|
|
|
gURLs.shift();
|
2007-02-12 02:21:18 +00:00
|
|
|
StartCurrentTest();
|
2006-09-05 21:50:54 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
throw "Unexpected state."
|
|
|
|
}
|
|
|
|
}
|