
// ../base.js must also be included

/* Work done for Netscape.  Public domain. */

is_moz5 = navigator &&
          navigator.userAgent &&
          navigator.userAgent.substring &&
          navigator.userAgent.substring(0,11) == "Mozilla/5.0";

function assertOrderInit() {
	// using obscure name etlOrderArray nobody else will choose
	// event-test-library order array
	// XXX not working to check if defined in assertOrder...
	etlOrderArray = new Array();
}

function assertOrder( text, num, /* opt */ allowRepeated ) {

	if ( (! allowRepeated) && (etlOrderArray.length == num + 1) ) {
		outTaggedText("fail", text + " occurred twice, at position " + num + ".");
		return;
	}

	if ( (! allowRepeated) && (etlOrderArray[num] == true) ) {
		outTaggedText("fail", text + " occurred a second time.  It should have occurred once at position " + num + ".");
		return;
	}

	if (etlOrderArray.length > num + 1) {
		etlOrderArray[num] = true;
		outTaggedText("fail", text + " occurred too late.  It should have been position " + num + ", but the event at position " + (etlOrderArray.length - 1) + " has already occurred.");
		return;
	}

	etlOrderArray[num] = true;

	var missingEvents = "";
	for (var i = 0; i < num; i++ ) {
		if ( ! etlOrderArray[i] ) {
			missingEvents += " " + i;
		}
	}

	if (missingEvents == "") {
		outTaggedText("pass", text + " correctly occured at position " + num + ".");
	} else {
		outTaggedText("fail", text + " occured at position " + num + " before the following events occurred: " + missingEvents + ".");
	}
}

function shouldNotHappen (text) {
	outTaggedText("fail", text + " occurred, but it should not have.");
}

