2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
* ***** 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.org code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Mozilla Foundation.
|
|
|
|
*
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2007
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Robert Sayre <sayrer@gmail.com>
|
|
|
|
*
|
|
|
|
* 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 *****/
|
|
|
|
|
2009-08-15 01:30:23 -07:00
|
|
|
/**
|
|
|
|
* Runs html5lib-formatted test cases in the browser. Requires SimpleTest.
|
2007-03-22 10:30:00 -07:00
|
|
|
*
|
2009-08-15 01:30:23 -07:00
|
|
|
* Define an array named parserDatFiles before loading this script,
|
|
|
|
* and it will load each of those dat files into an array, then run
|
|
|
|
* the test parser on each and run the tests by assigning the input
|
|
|
|
* data to an iframe's url.
|
2007-03-22 10:30:00 -07:00
|
|
|
*
|
2009-08-15 01:30:23 -07:00
|
|
|
* Your test document should have an element with id "display" and
|
|
|
|
* an iframe with id "testframe".
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
|
|
|
|
2009-08-15 01:30:23 -07:00
|
|
|
function writeErrorSummary(input, expected, got, isTodo) {
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!isTodo) {
|
|
|
|
appendChildNodes($("display"), H2("Unexpected Failure:"));
|
|
|
|
}
|
|
|
|
appendChildNodes(
|
|
|
|
$("display"), BR(),
|
2009-08-15 01:30:23 -07:00
|
|
|
SPAN("Matched: "), "" + (expected == got),
|
|
|
|
P("Input: " + input),
|
|
|
|
PRE("Expected:\n|" + expected +"|", "\n-\n",
|
|
|
|
"Output:\n|" + got + "|\n\n"),
|
2007-03-22 10:30:00 -07:00
|
|
|
HR()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2009-08-13 00:48:13 -07:00
|
|
|
/**
|
2009-08-15 01:30:23 -07:00
|
|
|
* Control will bounce back and forth between nextTest() and the
|
|
|
|
* event handler returned by makeTestChecker() until the 'testcases'
|
|
|
|
* iterator is spent.
|
2009-08-13 00:48:13 -07:00
|
|
|
*/
|
2009-08-15 01:30:23 -07:00
|
|
|
function makeTestChecker(input, expected, errors) {
|
|
|
|
return function (e) {
|
|
|
|
var domAsString = docToTestOutput(e.target.contentDocument);
|
|
|
|
// It's possible we need to reorder attributes to get these to match
|
2007-03-22 10:30:00 -07:00
|
|
|
if (expected == domAsString) {
|
|
|
|
is(domAsString, expected, "HTML5 expected success. " + new Date());
|
|
|
|
} else {
|
2009-08-15 01:30:23 -07:00
|
|
|
var reorderedDOM = reorderToMatchExpected(domAsString, expected);
|
|
|
|
if (html5Exceptions[input]) {
|
|
|
|
todo(reorderedDOM == expected, "HTML5 expected failure. " + new Date());
|
|
|
|
writeErrorSummary(input, expected, reorderedDOM, true);
|
2007-03-22 10:30:00 -07:00
|
|
|
} else {
|
2009-08-15 01:30:23 -07:00
|
|
|
if (reorderedDOM != expected) {
|
|
|
|
is(reorderedDOM, expected, "HTML5 unexpected failure. " + input + " " + new Date());
|
|
|
|
writeErrorSummary(input, expected, reorderedDOM, false);
|
2007-03-22 10:30:00 -07:00
|
|
|
} else {
|
2009-08-15 01:30:23 -07:00
|
|
|
is(reorderedDOM, expected, "HTML5 expected success. " + new Date());
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-08-15 01:30:23 -07:00
|
|
|
nextTest(e.target);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2009-08-15 01:30:23 -07:00
|
|
|
var testcases;
|
|
|
|
function nextTest(testframe) {
|
|
|
|
var test = 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
try {
|
2009-08-15 01:30:23 -07:00
|
|
|
var [input, output, errors] = testcases.next();
|
2009-08-13 00:48:13 -07:00
|
|
|
dataURL = "data:text/html;base64," + btoa(input);
|
2009-08-15 01:30:23 -07:00
|
|
|
testframe.onload = makeTestChecker(input, output, errors);
|
2007-03-22 10:30:00 -07:00
|
|
|
testframe.src = dataURL;
|
|
|
|
} catch (err if err instanceof StopIteration) {
|
2010-03-08 14:40:53 -08:00
|
|
|
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
|
|
|
prefService.setBoolPref("html5.enable", origPref);
|
2009-08-15 01:30:23 -07:00
|
|
|
SimpleTest.finish();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-15 01:30:23 -07:00
|
|
|
var framesLoaded = [];
|
|
|
|
function frameLoaded(e) {
|
|
|
|
framesLoaded.push(e.target);
|
|
|
|
if (framesLoaded.length == parserDatFiles.length) {
|
|
|
|
var tests = [scrapeText(ifr.contentDocument)
|
|
|
|
for each (ifr in framesLoaded)];
|
|
|
|
testcases = test_parser(tests);
|
|
|
|
nextTest($("testframe"));
|
2009-08-14 15:02:39 -07:00
|
|
|
|
2009-08-15 01:30:23 -07:00
|
|
|
//SimpleTest.finish();
|
2009-08-14 15:02:39 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-08-15 01:30:23 -07:00
|
|
|
* Create an iframe for each dat file
|
2009-08-14 15:02:39 -07:00
|
|
|
*/
|
2009-08-15 01:30:23 -07:00
|
|
|
function makeIFrames() {
|
|
|
|
for each (var filename in parserDatFiles) {
|
|
|
|
var datFrame = document.createElement("iframe");
|
|
|
|
datFrame.onload = frameLoaded;
|
|
|
|
datFrame.src = filename;
|
|
|
|
$("display").appendChild(datFrame);
|
2009-08-14 15:02:39 -07:00
|
|
|
}
|
|
|
|
appendChildNodes($("display"), BR(), "Results: ", HR());
|
|
|
|
}
|
|
|
|
|
2010-03-08 14:40:53 -08:00
|
|
|
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
|
|
|
var prefService = Components.classes["@mozilla.org/preferences-service;1"]
|
|
|
|
.getService(Components.interfaces.nsIPrefBranch)
|
|
|
|
.QueryInterface(Components.interfaces.nsIPrefService);
|
|
|
|
var origPref = prefService.getBoolPref("html5.enable");
|
|
|
|
prefService.setBoolPref("html5.enable", true);
|
2009-08-15 01:30:23 -07:00
|
|
|
addLoadEvent(makeIFrames);
|
|
|
|
SimpleTest.waitForExplicitFinish();
|