2012-03-29 21:08:43 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
var W3CTest = {
|
|
|
|
/**
|
|
|
|
* Dictionary mapping a test URL to either the string "all", which means that
|
|
|
|
* all tests in this file are expected to fail, or a dictionary mapping test
|
|
|
|
* names to either the boolean |true|, or the string "debug". The former
|
|
|
|
* means that this test is expected to fail in all builds, and the latter
|
|
|
|
* that it is only expected to fail in debug builds.
|
|
|
|
*/
|
2012-05-15 06:35:31 +00:00
|
|
|
"expectedFailures": {},
|
2012-03-29 21:08:43 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* List of test results, needed by TestRunner to update the UI.
|
|
|
|
*/
|
|
|
|
"tests": [],
|
|
|
|
|
2012-06-17 08:11:14 +00:00
|
|
|
/**
|
|
|
|
* Number of unlogged passes, to stop buildbot from truncating the log.
|
|
|
|
* We will print a message every MAX_COLLAPSED_MESSAGES passes.
|
|
|
|
*/
|
|
|
|
"collapsedMessages": 0,
|
|
|
|
"MAX_COLLAPSED_MESSAGES": 100,
|
|
|
|
|
2012-03-29 21:08:43 +00:00
|
|
|
/**
|
|
|
|
* Reference to the TestRunner object in the parent frame.
|
|
|
|
*/
|
|
|
|
"runner": parent === this ? null : parent.TestRunner || parent.wrappedJSObject.TestRunner,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Prefixes for the error logging. Indexed first by int(todo) and second by
|
|
|
|
* int(result).
|
|
|
|
*/
|
|
|
|
"prefixes": [
|
|
|
|
["TEST-UNEXPECTED-FAIL", "TEST-PASS"],
|
|
|
|
["TEST-KNOWN-FAIL", "TEST-UNEXPECTED-PASS"]
|
|
|
|
],
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the URL of the current test, relative to the root W3C tests
|
|
|
|
* directory. Used as a key into the expectedFailures dictionary.
|
|
|
|
*/
|
|
|
|
"getURL": function() {
|
2012-05-05 14:00:30 +00:00
|
|
|
return this.runner.currentTestURL.substring("/tests/dom/imptests/".length);
|
2012-03-29 21:08:43 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Lets the test runner know about a test result.
|
|
|
|
*/
|
|
|
|
"_log": function(test) {
|
|
|
|
var msg = this.prefixes[+test.todo][+test.result] + " | ";
|
2012-06-17 08:11:14 +00:00
|
|
|
if (this.runner.currentTestURL) {
|
2012-03-29 21:08:43 +00:00
|
|
|
msg += this.runner.currentTestURL;
|
2012-06-17 08:11:14 +00:00
|
|
|
}
|
2012-03-29 21:08:43 +00:00
|
|
|
msg += " | " + test.message;
|
|
|
|
this.runner[(test.result === !test.todo) ? "log" : "error"](msg);
|
|
|
|
},
|
|
|
|
|
2012-06-17 08:11:14 +00:00
|
|
|
/**
|
|
|
|
* Maybe logs a result, eliding up to MAX_COLLAPSED_MESSAGES consecutive
|
|
|
|
* passes.
|
|
|
|
*/
|
|
|
|
"_maybeLog": function(test) {
|
|
|
|
var success = (test.result === !test.todo);
|
|
|
|
if (success && ++this.collapsedMessages < this.MAX_COLLAPSED_MESSAGES) {
|
|
|
|
return;
|
|
|
|
}
|
2012-06-21 07:21:55 +00:00
|
|
|
if (this.collapsedMessages) {
|
|
|
|
this._log({
|
|
|
|
"result": true,
|
|
|
|
"todo": false,
|
|
|
|
"message": "Elided " + this.collapsedMessages + " passes or known failures."
|
|
|
|
});
|
|
|
|
}
|
2012-06-17 08:11:14 +00:00
|
|
|
this.collapsedMessages = 0;
|
|
|
|
this._log(test);
|
|
|
|
},
|
|
|
|
|
2012-03-29 21:08:43 +00:00
|
|
|
/**
|
|
|
|
* Reports a test result. The argument is an object with the following
|
|
|
|
* properties:
|
|
|
|
*
|
|
|
|
* o message (string): message to be reported
|
|
|
|
* o result (boolean): whether this test failed
|
|
|
|
* o todo (boolean): whether this test is expected to fail
|
|
|
|
*/
|
|
|
|
"report": function(test) {
|
|
|
|
this.tests.push(test);
|
2012-06-17 08:11:14 +00:00
|
|
|
this._maybeLog(test);
|
2012-03-29 21:08:43 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if this test is expected to fail, and false otherwise.
|
|
|
|
*/
|
2012-05-15 06:35:31 +00:00
|
|
|
"_todo": function(test) {
|
|
|
|
if (this.expectedFailures === "all") {
|
2012-03-29 21:08:43 +00:00
|
|
|
return true;
|
|
|
|
}
|
2012-05-15 06:35:31 +00:00
|
|
|
var value = this.expectedFailures[test.name];
|
2012-03-29 21:08:43 +00:00
|
|
|
return value === true || (value === "debug" && !!SpecialPowers.isDebugBuild);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Callback function for testharness.js. Called when one test in a file
|
|
|
|
* finishes.
|
|
|
|
*/
|
|
|
|
"result": function(test) {
|
|
|
|
var url = this.getURL();
|
|
|
|
this.report({
|
2012-05-09 09:46:23 +00:00
|
|
|
"message": test.name + (test.message ? "; " + test.message : ""),
|
2012-03-29 21:08:43 +00:00
|
|
|
"result": test.status === test.PASS,
|
2012-05-15 06:35:31 +00:00
|
|
|
"todo": this._todo(test)
|
2012-03-29 21:08:43 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Callback function for testharness.js. Called when the entire test file
|
|
|
|
* finishes.
|
|
|
|
*/
|
|
|
|
"finish": function(tests, status) {
|
|
|
|
var url = this.getURL();
|
|
|
|
this.report({
|
2012-05-08 06:14:40 +00:00
|
|
|
"message": "Finished test, status " + status.status,
|
2012-03-29 21:08:43 +00:00
|
|
|
"result": status.status === status.OK,
|
|
|
|
"todo":
|
|
|
|
url in this.expectedFailures &&
|
|
|
|
this.expectedFailures[url] === "error"
|
|
|
|
});
|
|
|
|
this.runner.testFinished(this.tests);
|
2012-06-17 07:51:22 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Log an unexpected failure. Intended to be used from harness code, not
|
|
|
|
* from tests.
|
|
|
|
*/
|
|
|
|
"logFailure": function(message) {
|
|
|
|
this.report({
|
|
|
|
"message": message,
|
|
|
|
"result": false,
|
|
|
|
"todo": false
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Timeout the current test. Intended to be used from harness code, not
|
|
|
|
* from tests.
|
|
|
|
*/
|
|
|
|
"timeout": function() {
|
|
|
|
timeout();
|
2012-03-29 21:08:43 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
(function() {
|
2012-06-17 07:51:22 +00:00
|
|
|
try {
|
|
|
|
if (!W3CTest.runner) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Get expected fails. If there aren't any, there will be a 404, which is
|
|
|
|
// fine. Anything else is unexpected.
|
|
|
|
var request = new XMLHttpRequest();
|
|
|
|
request.open("GET", "/tests/dom/imptests/failures/" + W3CTest.getURL() + ".json", false);
|
|
|
|
request.send();
|
|
|
|
if (request.status === 200) {
|
|
|
|
W3CTest.expectedFailures = JSON.parse(request.responseText);
|
|
|
|
} else if (request.status !== 404) {
|
|
|
|
W3CTest.logFailure("Request status was " + request.status);
|
|
|
|
}
|
2012-05-15 06:35:31 +00:00
|
|
|
|
2012-06-17 07:51:22 +00:00
|
|
|
add_result_callback(W3CTest.result.bind(W3CTest));
|
|
|
|
add_completion_callback(W3CTest.finish.bind(W3CTest));
|
|
|
|
setup({
|
|
|
|
"output": false,
|
|
|
|
"timeout": 1000000
|
|
|
|
});
|
|
|
|
} catch (e) {
|
|
|
|
W3CTest.logFailure("Unexpected exception: " + e);
|
|
|
|
}
|
2012-03-29 21:08:43 +00:00
|
|
|
})();
|