mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-01-24 05:44:10 +00:00
Bug 648367 - Add run_next_test to head.js. r=ted
This commit is contained in:
parent
4bfc8d1dde
commit
1d43d57f19
@ -539,7 +539,7 @@ function test_readInputStreamToString_too_many_bytes()
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//// Test Runner
|
||||
|
||||
let tests = [
|
||||
[
|
||||
test_async_write_file,
|
||||
test_async_write_file_deferred,
|
||||
test_async_write_file_safe,
|
||||
@ -565,32 +565,11 @@ let tests = [
|
||||
test_readInputStreamToString_no_bytes_arg,
|
||||
test_readInputStreamToString_blocking_stream,
|
||||
test_readInputStreamToString_too_many_bytes,
|
||||
];
|
||||
].forEach(add_test);
|
||||
let index = 0;
|
||||
|
||||
function run_next_test()
|
||||
{
|
||||
if (index < tests.length) {
|
||||
do_test_pending();
|
||||
|
||||
// Asynchronous test exceptions do not kill the test...
|
||||
do_execute_soon(function() {
|
||||
try {
|
||||
print("Running the next test: " + tests[index].name);
|
||||
tests[index++]();
|
||||
}
|
||||
catch (e) {
|
||||
do_throw(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
do_test_finished();
|
||||
}
|
||||
|
||||
function run_test()
|
||||
{
|
||||
do_test_pending();
|
||||
run_next_test();
|
||||
}
|
||||
|
||||
|
@ -19,10 +19,6 @@ var urls = [
|
||||
["DATA:TEXT/PLAIN;BASE64,Zm9 vI%20GJ%0Dhc%0Ag==", "text/plain", "foo bar"]
|
||||
];
|
||||
|
||||
function run_next_test() {
|
||||
test_array[test_index++]();
|
||||
}
|
||||
|
||||
function run_test() {
|
||||
dump("*** run_test\n");
|
||||
|
||||
|
@ -7,18 +7,13 @@ const PR_RDONLY = 0x1; // see prio.h
|
||||
|
||||
const special_type = "application/x-our-special-type";
|
||||
|
||||
var test_index = 0;
|
||||
var test_array = [
|
||||
[
|
||||
test_read_file,
|
||||
test_read_dir_1,
|
||||
test_read_dir_2,
|
||||
test_upload_file,
|
||||
do_test_finished
|
||||
];
|
||||
|
||||
function run_next_test() {
|
||||
test_array[test_index++]();
|
||||
}
|
||||
].forEach(add_test);
|
||||
|
||||
function getFile(key) {
|
||||
var dirSvc = Components.classes["@mozilla.org/file/directory_service;1"]
|
||||
@ -228,6 +223,5 @@ function test_upload_file() {
|
||||
}
|
||||
|
||||
function run_test() {
|
||||
do_test_pending();
|
||||
run_next_test();
|
||||
}
|
||||
|
@ -9,15 +9,14 @@ const NS_ERROR_ALREADY_OPENED = 0x804b0049;
|
||||
var chan = null;
|
||||
var httpserv = null;
|
||||
|
||||
var test_index = 0;
|
||||
var test_array = [
|
||||
[
|
||||
test_data_channel,
|
||||
test_http_channel,
|
||||
test_file_channel,
|
||||
// Commented by default as it relies on external ressources
|
||||
//test_ftp_channel,
|
||||
end
|
||||
];
|
||||
].forEach(add_test);
|
||||
|
||||
// Utility functions
|
||||
|
||||
@ -87,10 +86,6 @@ function after_channel_closed() {
|
||||
run_next_test();
|
||||
}
|
||||
|
||||
function run_next_test() {
|
||||
test_array[test_index++]();
|
||||
}
|
||||
|
||||
function test_channel(createChanClosure) {
|
||||
// First, synchronous reopening test
|
||||
chan = createChanClosure();
|
||||
@ -140,6 +135,5 @@ function run_test() {
|
||||
httpserv = new nsHttpServer();
|
||||
httpserv.start(4444);
|
||||
|
||||
do_test_pending();
|
||||
run_next_test();
|
||||
}
|
||||
|
@ -307,7 +307,6 @@ function test_double_asyncClose_throws()
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//// Test Runner
|
||||
|
||||
let tests =
|
||||
[
|
||||
test_create_and_add,
|
||||
test_transaction_created,
|
||||
@ -315,36 +314,10 @@ let tests =
|
||||
test_asyncClose_does_not_complete_before_statements,
|
||||
test_asyncClose_does_not_throw_no_callback,
|
||||
test_double_asyncClose_throws,
|
||||
];
|
||||
let index = 0;
|
||||
|
||||
function run_next_test()
|
||||
{
|
||||
function _run_next_test() {
|
||||
if (index < tests.length) {
|
||||
do_test_pending();
|
||||
print("Running the next test: " + tests[index].name);
|
||||
|
||||
// Asynchronous tests means that exceptions don't kill the test.
|
||||
try {
|
||||
tests[index++]();
|
||||
}
|
||||
catch (e) {
|
||||
do_throw(e);
|
||||
}
|
||||
}
|
||||
|
||||
do_test_finished();
|
||||
}
|
||||
|
||||
// For saner stacks, we execute this code RSN.
|
||||
do_execute_soon(_run_next_test);
|
||||
}
|
||||
].forEach(add_test);
|
||||
|
||||
function run_test()
|
||||
{
|
||||
cleanup();
|
||||
|
||||
do_test_pending();
|
||||
run_next_test();
|
||||
}
|
||||
|
@ -112,27 +112,12 @@ function test_delete_removes_data()
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//// Test Runner
|
||||
|
||||
var tests =
|
||||
[
|
||||
test_delete_removes_data,
|
||||
];
|
||||
let index = 0;
|
||||
|
||||
function run_next_test()
|
||||
{
|
||||
if (index < tests.length) {
|
||||
do_test_pending();
|
||||
print("Running the next test: " + tests[index].name);
|
||||
tests[index++]();
|
||||
}
|
||||
|
||||
do_test_finished();
|
||||
}
|
||||
].forEach(add_test);
|
||||
|
||||
function run_test()
|
||||
{
|
||||
cleanup();
|
||||
|
||||
do_test_pending();
|
||||
run_next_test();
|
||||
}
|
||||
|
@ -497,7 +497,7 @@ function test_getInterface()
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//// Test Runner
|
||||
|
||||
var tests = [
|
||||
[
|
||||
test_connectionReady_open,
|
||||
test_connectionReady_closed,
|
||||
test_databaseFile,
|
||||
@ -526,36 +526,9 @@ var tests = [
|
||||
test_clone_copies_functions,
|
||||
test_clone_copies_overridden_functions,
|
||||
test_getInterface,
|
||||
];
|
||||
let index = 0;
|
||||
|
||||
function run_next_test()
|
||||
{
|
||||
function _run_next_test() {
|
||||
if (index < tests.length) {
|
||||
do_test_pending();
|
||||
print("Running the next test: " + tests[index].name);
|
||||
|
||||
// Asynchronous tests means that exceptions don't kill the test.
|
||||
try {
|
||||
tests[index++]();
|
||||
}
|
||||
catch (e) {
|
||||
do_throw(e);
|
||||
}
|
||||
}
|
||||
|
||||
do_test_finished();
|
||||
}
|
||||
|
||||
// For saner stacks, we execute this code RSN.
|
||||
do_execute_soon(_run_next_test);
|
||||
}
|
||||
].forEach(add_test);
|
||||
|
||||
function run_test()
|
||||
{
|
||||
cleanup();
|
||||
|
||||
do_test_pending();
|
||||
run_next_test();
|
||||
}
|
||||
|
@ -829,3 +829,54 @@ function run_test_in_child(testFile, optionalCallback)
|
||||
callback);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add a test function to the list of tests that are to be run asynchronously.
|
||||
*
|
||||
* Each test function must call run_next_test() when it's done. Test files
|
||||
* should call run_next_test() in their run_test function to execute all
|
||||
* async tests.
|
||||
*
|
||||
* @return the test function that was passed in.
|
||||
*/
|
||||
let gTests = [];
|
||||
function add_test(func) {
|
||||
gTests.push(func);
|
||||
return func;
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs the next test function from the list of async tests.
|
||||
*/
|
||||
let gRunningTest = null;
|
||||
let gTestIndex = 0; // The index of the currently running test.
|
||||
function run_next_test()
|
||||
{
|
||||
function _run_next_test()
|
||||
{
|
||||
if (gTestIndex < gTests.length) {
|
||||
do_test_pending();
|
||||
gRunningTest = gTests[gTestIndex++];
|
||||
print("TEST-INFO | " + _TEST_FILE + " | Starting " +
|
||||
gRunningTest.name);
|
||||
// Exceptions do not kill asynchronous tests, so they'll time out.
|
||||
try {
|
||||
gRunningTest();
|
||||
}
|
||||
catch (e) {
|
||||
do_throw(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// For sane stacks during failures, we execute this code soon, but not now.
|
||||
// We do this now, before we call do_test_finished(), to ensure the pending
|
||||
// counter (_tests_pending) never reaches 0 while we still have tests to run
|
||||
// (do_execute_soon bumps that counter).
|
||||
do_execute_soon(_run_next_test);
|
||||
|
||||
if (gRunningTest !== null) {
|
||||
// Close the previous test do_test_pending call.
|
||||
do_test_finished();
|
||||
}
|
||||
}
|
||||
|
@ -135,12 +135,12 @@ function test_shutdown()
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//// Test Harness
|
||||
|
||||
let gTests = [
|
||||
[
|
||||
test_timed,
|
||||
test_debug,
|
||||
test_clear_history,
|
||||
test_shutdown,
|
||||
];
|
||||
].forEach(add_test);
|
||||
|
||||
function run_test()
|
||||
{
|
||||
|
@ -647,40 +647,6 @@ function do_log_info(aMessage)
|
||||
print("TEST-INFO | " + _TEST_FILE + " | " + aMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs the next test in the gTests array. gTests should be a array defined in
|
||||
* each test file.
|
||||
*/
|
||||
let gRunningTest = null;
|
||||
let gTestIndex = 0; // The index of the currently running test.
|
||||
function run_next_test()
|
||||
{
|
||||
function _run_next_test()
|
||||
{
|
||||
if (gTestIndex < gTests.length) {
|
||||
do_test_pending();
|
||||
gRunningTest = gTests[gTestIndex++];
|
||||
print("TEST-INFO | " + _TEST_FILE + " | Starting " +
|
||||
gRunningTest.name);
|
||||
// Exceptions do not kill asynchronous tests, so they'll time out.
|
||||
try {
|
||||
gRunningTest();
|
||||
}
|
||||
catch (e) {
|
||||
do_throw(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// For sane stacks during failures, we execute this code soon, but not now.
|
||||
do_execute_soon(_run_next_test);
|
||||
|
||||
if (gRunningTest !== null) {
|
||||
// Close the previous test do_test_pending call.
|
||||
do_test_finished();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares 2 arrays returning whether they contains the same elements.
|
||||
*
|
||||
|
@ -305,7 +305,7 @@ function test_final_state()
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//// Test Runner
|
||||
|
||||
let gTests = [
|
||||
[
|
||||
test_initial_state,
|
||||
test_moz_bookmarks_guid_exists,
|
||||
test_bookmark_guids_non_null,
|
||||
@ -316,7 +316,7 @@ let gTests = [
|
||||
test_place_guid_annotation_imported,
|
||||
test_place_guid_annotation_removed,
|
||||
test_final_state,
|
||||
];
|
||||
].forEach(add_test);
|
||||
|
||||
function run_test()
|
||||
{
|
||||
|
@ -118,12 +118,12 @@ function test_final_state()
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//// Test Runner
|
||||
|
||||
let gTests = [
|
||||
[
|
||||
test_initial_state,
|
||||
test_bookmark_guids_non_null,
|
||||
test_place_guids_non_null,
|
||||
test_final_state,
|
||||
];
|
||||
].forEach(add_test);
|
||||
|
||||
function run_test()
|
||||
{
|
||||
|
@ -41,9 +41,8 @@
|
||||
* Tests bookmark and history queries with tags. See bug 399799.
|
||||
*/
|
||||
|
||||
// Add your tests here. Each is an object with a summary string |desc| and a
|
||||
// method run() that's called to run the test.
|
||||
var gTests = [
|
||||
// Add your tests here. Each is a function that's called to run the test.
|
||||
[
|
||||
|
||||
function tags_getter_setter()
|
||||
{
|
||||
@ -590,7 +589,7 @@ var gTests = [
|
||||
cleanDatabase(run_next_test);
|
||||
},
|
||||
|
||||
];
|
||||
].forEach(add_test);
|
||||
|
||||
// The tag keys in query URIs, i.e., "place:tag=foo&!tags=1"
|
||||
// --- -----
|
||||
|
@ -58,12 +58,10 @@ function add_visit(aURI, aTime) {
|
||||
return visitId;
|
||||
}
|
||||
|
||||
var gTests = [];
|
||||
|
||||
/**
|
||||
* Tests that sorting date query by none will sort by title asc.
|
||||
*/
|
||||
gTests.push(function() {
|
||||
add_test(function() {
|
||||
var options = hs.getNewQueryOptions();
|
||||
options.resultType = options.RESULTS_AS_DATE_QUERY;
|
||||
// This should sort by title asc.
|
||||
@ -89,7 +87,7 @@ gTests.push(function() {
|
||||
/**
|
||||
* Tests that sorting date query by date will sort accordingly.
|
||||
*/
|
||||
gTests.push(function() {
|
||||
add_test(function() {
|
||||
var options = hs.getNewQueryOptions();
|
||||
options.resultType = options.RESULTS_AS_DATE_QUERY;
|
||||
// This should sort by title asc.
|
||||
@ -115,7 +113,7 @@ gTests.push(function() {
|
||||
/**
|
||||
* Tests that sorting date site query by date will still sort by title asc.
|
||||
*/
|
||||
gTests.push(function() {
|
||||
add_test(function() {
|
||||
var options = hs.getNewQueryOptions();
|
||||
options.resultType = options.RESULTS_AS_DATE_SITE_QUERY;
|
||||
// This should sort by title asc.
|
||||
|
@ -7,7 +7,7 @@
|
||||
|
||||
const TEST_URL = "http://www.example.com/";
|
||||
|
||||
let gTests = [
|
||||
[
|
||||
|
||||
function test_no_bookmark() {
|
||||
PlacesUtils.asyncGetBookmarkIds(TEST_URL, function (aItemIds, aURI) {
|
||||
@ -79,7 +79,7 @@ let gTests = [
|
||||
}, this);
|
||||
},
|
||||
|
||||
];
|
||||
].forEach(add_test);
|
||||
|
||||
function run_test() {
|
||||
run_next_test();
|
||||
|
@ -1252,7 +1252,7 @@ function test_referrer_sessionId_persists()
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//// Test Runner
|
||||
|
||||
let gTests = [
|
||||
[
|
||||
test_interface_exists,
|
||||
test_invalid_uri_throws,
|
||||
test_invalid_places_throws,
|
||||
@ -1283,7 +1283,7 @@ let gTests = [
|
||||
test_title_change_notifies,
|
||||
test_visit_notifies,
|
||||
test_referrer_sessionId_persists,
|
||||
];
|
||||
].forEach(add_test);
|
||||
|
||||
function run_test()
|
||||
{
|
||||
|
@ -98,10 +98,10 @@ function test_guid_on_background()
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//// Test Runner
|
||||
|
||||
let gTests = [
|
||||
[
|
||||
test_guid_invariants,
|
||||
test_guid_on_background,
|
||||
];
|
||||
].forEach(add_test);
|
||||
|
||||
function run_test()
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user