blob: d6d4e230e88e9cceb2e04e0f61dc2c7466ce2adb [file] [log] [blame]
<?xml version="1.0"?>
<svg width="100%" height="100%" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xhtml="http://www.w3.org/1999/xhtml" onerror="testGlobalErrorHandlerNotFired(evt)" onload="testLoadEventNotFired()">
<defs>
<title>&lt;SCRIPT&gt; load and error events</title>
<script type="text/javascript">
//<![CDATA[
var status_ = new Array();
var shouldContinue = 1;
var lastTest = 0;
for (i = 0; i < 7; ++i)
status_[i] = "";
if (window.testRunner) {
testRunner.dumpAsText();
testRunner.waitUntilDone();
}
function testGlobalErrorHandlerNotFired(evt) {
status_[evt.target.id] += "G";
}
function testLoadEventNotFired() {
shouldContinue = 0;
}
function loadEventHandler(evt) {
status_[evt.target.id] += "L";
}
function errorEventHandler(evt) {
status_[evt.target.id] += "E";
if (lastTest)
window.setTimeout('endTest()', 0);
}
function endTest() {
var failures = "";
if (status_[0] != "LE")
failures += "0 (actual result: " + status_[0] + ") ";
if (status_[1] != "E")
failures += "1 (actual result: " + status_[1] + ") ";
if (status_[2] != "L")
failures += "2 (actual result: " + status_[2] + ") ";
if (status_[3] != "L")
failures += "3 (actual result: " + status_[3] + ") ";
if (status_[4] != "L")
failures += "4 (actual result: " + status_[4] + ") ";
if (status_[5] != "LE")
failures += "5 (actual result: " + status_[5] + ") ";
if (status_[6] != "E")
failures += "6 (actual result: " + status_[6] + ")";
var results = document.getElementById("results");
if (failures)
results.innerHTML = "FAIL: The following tests failed: " + failures;
else
results.innerHTML = "PASS";
if (window.testRunner)
testRunner.notifyDone();
}
function lastTestBeforeRootElementLoaded() {
// Ensure the SVGSVGElement onload handler doesn't fire, because one script element points to a nonexistent
// resource, and specifies externalResourcesRequired=true. This prevents SVGLoad from being dispatched.
window.setTimeout('startDynamicTests()', 0);
}
function startDynamicTests() {
if (shouldContinue) {
var scriptElement = document.createElementNS("http://www.w3.org/2000/svg", "svg:script");
scriptElement.id = 4;
scriptElement.type.baseVal = "text/javascript";
scriptElement.href.baseVal = "resources/script-load.js";
scriptElement.onload = function(loadEvent) {
loadEventHandler(loadEvent);
window.setTimeout('continueDynamicTest1()', 0);
};
document.getElementsByTagName("defs")[0].appendChild(scriptElement);
} else {
var results = document.getElementById("results");
results.innerHTML = "FAIL: SVGLoad event on root element shouldn't fire.";
if (window.testRunner)
testRunner.notifyDone();
}
}
function continueDynamicTest1() {
var scriptElement = document.createElementNS("http://www.w3.org/2000/svg", "svg:script");
scriptElement.id = 5;
scriptElement.type.baseVal = "text/javascript";
scriptElement.href.baseVal = "resources/nonexistent.js";
scriptElement.onload = loadEventHandler;
scriptElement.onerror = function(errorEvent) {
errorEventHandler(errorEvent);
window.setTimeout('continueDynamicTest2()', 0);
};
document.getElementsByTagName("defs")[0].appendChild(scriptElement);
}
function continueDynamicTest2() {
var scriptElement = document.createElementNS("http://www.w3.org/2000/svg", "svg:script");
scriptElement.id = 6;
scriptElement.type.baseVal = "text/javascript";
scriptElement.href.baseVal = "resources/nonexistent.js";
scriptElement.externalResourcesRequired.baseVal = true;
scriptElement.onerror = errorEventHandler;
lastTest = 1;
document.getElementsByTagName("defs")[0].appendChild(scriptElement);
}
//]]>
</script>
<script id="0" type="text/javascript" onerror="errorEventHandler(evt)" onload="loadEventHandler(evt)" xlink:href="resources/certainlydoesnotexist.js"></script>
<script id="1" type="text/javascript" onerror="errorEventHandler(evt)" externalResourcesRequired="true" onload="loadEventHandler(evt)" xlink:href="resources/certainlydoesnotexisttoo.js"/>
<script id="2" type="text/javascript" onerror="errorEventHandler(evt)" onload="loadEventHandler(evt)" xlink:href="resources/script-load.js"></script>
<script id="3" type="text/javascript" onerror="errorEventHandler(evt)" externalResourcesRequired="true" onload="loadEventHandler(evt); lastTestBeforeRootElementLoaded();" xlink:href="resources/script-load.js"/>
</defs>
<foreignObject>
Test load and error event handling with SVGScriptElement
<xhtml:hr/>
<xhtml:p id="results">FAIL: Test never finished.</xhtml:p>
</foreignObject>
</svg>