2011-01-31 00:32:04 +01:00
|
|
|
<html>
|
|
|
|
<body>
|
|
|
|
Script execution test
|
|
|
|
<div id="b1"></div>
|
|
|
|
<div id="b2"></div>
|
|
|
|
<div id="b3"></div>
|
2012-10-16 17:10:11 +02:00
|
|
|
<script id="emptyscript"></script>
|
2013-01-15 13:40:04 +01:00
|
|
|
<script id="put_text_script">2+2</script>
|
2011-01-31 00:32:04 +01:00
|
|
|
<script>
|
|
|
|
function ok(b, msg) {
|
|
|
|
return external.ok(b, msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
var executed = false;
|
2012-10-16 17:10:11 +02:00
|
|
|
var extern_cnt = 0;
|
2013-01-15 13:40:04 +01:00
|
|
|
var exec_cnt;
|
2011-01-31 00:32:04 +01:00
|
|
|
|
2012-10-16 17:10:11 +02:00
|
|
|
function testWriteScript() {
|
|
|
|
var len = document.getElementsByTagName('div').length;
|
|
|
|
ok(len === 3, "init length = " + len);
|
2011-01-31 00:32:04 +01:00
|
|
|
|
2012-10-16 17:10:11 +02:00
|
|
|
document.write("<script>"
|
|
|
|
+ "var len = document.getElementsByTagName('div').length;"
|
|
|
|
+ "ok(len === 3, 'unexpected length ' + len);"
|
|
|
|
+ "executed = true;"
|
|
|
|
+ "<" + "/script>");
|
2011-01-31 00:32:04 +01:00
|
|
|
|
2012-10-16 17:10:11 +02:00
|
|
|
len = document.getElementsByTagName('script').length;
|
2013-01-15 13:40:04 +01:00
|
|
|
ok(len === 4, "script col length = " + len);
|
2012-10-16 17:10:11 +02:00
|
|
|
ok(executed, "written script not executed");
|
|
|
|
}
|
|
|
|
|
|
|
|
function testPutSrc() {
|
|
|
|
var elem = document.getElementById("emptyscript");
|
|
|
|
|
|
|
|
ok(extern_cnt === 0, "extern_cnt = " + extern_cnt + " expected 0");
|
|
|
|
elem.src = "externscr.js";
|
|
|
|
ok(extern_cnt === 0, "extern_cnt = " + extern_cnt + " expected 0");
|
|
|
|
}
|
|
|
|
|
2013-01-15 13:40:04 +01:00
|
|
|
function testPutText() {
|
|
|
|
var elem = document.getElementById("put_text_script");
|
|
|
|
|
|
|
|
exec_cnt = 0;
|
|
|
|
elem.text = "exec_cnt++;";
|
|
|
|
ok(exec_cnt === 1, "put_text_script exec_cnt " + exec_cnt);
|
|
|
|
|
|
|
|
exec_cnt = 0;
|
|
|
|
elem.text = "exec_cnt++;";
|
|
|
|
ok(exec_cnt === 1, "put_text_script exec_cnt " + exec_cnt);
|
|
|
|
}
|
|
|
|
|
2012-10-16 17:10:11 +02:00
|
|
|
try {
|
|
|
|
testWriteScript();
|
|
|
|
testPutSrc();
|
2013-01-15 13:40:04 +01:00
|
|
|
testPutText();
|
2012-10-16 17:10:11 +02:00
|
|
|
}catch(e) {
|
|
|
|
ok(false, "Got an exception");
|
|
|
|
}
|
|
|
|
|
|
|
|
function testPutSrc2() {
|
|
|
|
var elem, elem2;
|
|
|
|
|
|
|
|
elem = document.createElement("script");
|
|
|
|
elem.src = "externscr.js";
|
|
|
|
ok(extern_cnt === 1, "extern_cnt = " + extern_cnt + " expected 1");
|
|
|
|
document.body.appendChild(elem);
|
|
|
|
ok(extern_cnt === 2, "extern_cnt = " + extern_cnt + " expected 2");
|
|
|
|
|
|
|
|
elem = document.createElement("script");
|
|
|
|
document.body.appendChild(elem);
|
|
|
|
ok(extern_cnt === 2, "extern_cnt = " + extern_cnt + " expected 2");
|
|
|
|
elem.src = "externscr.js";
|
|
|
|
ok(extern_cnt === 3, "extern_cnt = " + extern_cnt + " expected 3");
|
|
|
|
|
|
|
|
elem2 = document.createElement("div");
|
|
|
|
elem = document.createElement("script");
|
|
|
|
elem.src = "externscr.js";
|
|
|
|
ok(extern_cnt === 3, "extern_cnt = " + extern_cnt + " expected 3");
|
|
|
|
elem2.appendChild(elem);
|
|
|
|
document.body.appendChild(elem2);
|
|
|
|
ok(extern_cnt === 4, "extern_cnt = " + extern_cnt + " expected 4");
|
|
|
|
}
|
|
|
|
|
2013-01-15 13:40:04 +01:00
|
|
|
function testPutText2() {
|
|
|
|
var elem;
|
|
|
|
|
|
|
|
elem = document.createElement("script");
|
|
|
|
exec_cnt = 0;
|
|
|
|
elem.text = "exec_cnt++;";
|
|
|
|
ok(exec_cnt === 0, "script exec_cnt " + exec_cnt);
|
|
|
|
|
|
|
|
document.body.appendChild(elem);
|
|
|
|
ok(exec_cnt === 1, "script exec_cnt " + exec_cnt);
|
|
|
|
exec_cnt = 0;
|
|
|
|
elem.text = "exec_cnt++;";
|
|
|
|
ok(exec_cnt === 1, "script exec_cnt " + exec_cnt);
|
|
|
|
|
|
|
|
elem.src = "externscr.js";
|
|
|
|
ok(extern_cnt === 5, "extern_cnt = " + extern_cnt + " expected 5");
|
|
|
|
|
|
|
|
exec_cnt = 0;
|
|
|
|
ok(extern_cnt === 5, "> extern_cnt = " + extern_cnt + " expected 5");
|
|
|
|
elem.text = "exec_cnt++;"; /* forces evaluation, but src will be executed */
|
|
|
|
ok(exec_cnt === 0, "script exec_cnt " + exec_cnt);
|
|
|
|
ok(extern_cnt === 6, "< extern_cnt = " + extern_cnt + " expected 6");
|
|
|
|
|
|
|
|
elem = document.createElement("script");
|
|
|
|
exec_cnt = 0;
|
|
|
|
elem.text = "exec_cnt++;";
|
|
|
|
ok(exec_cnt === 0, "script exec_cnt " + exec_cnt);
|
|
|
|
elem.src = "externscr.js";
|
|
|
|
ok(extern_cnt === 6, "extern_cnt = " + extern_cnt + " expected 6");
|
|
|
|
|
|
|
|
document.body.appendChild(elem);
|
|
|
|
ok(exec_cnt === 0, "script exec_cnt " + exec_cnt);
|
|
|
|
ok(extern_cnt === 7, "extern_cnt = " + extern_cnt + " expected 7");
|
|
|
|
}
|
|
|
|
|
2012-10-16 17:10:11 +02:00
|
|
|
document.body.onload = function() {
|
|
|
|
ok(extern_cnt === 1, "extern_cnt = " + extern_cnt);
|
|
|
|
try {
|
|
|
|
testPutSrc2();
|
2013-01-15 13:40:04 +01:00
|
|
|
testPutText2();
|
2012-10-16 17:10:11 +02:00
|
|
|
}catch(e) {
|
|
|
|
ok(false, "got an exception");
|
|
|
|
}
|
|
|
|
|
|
|
|
external.reportSuccess();
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
<script>
|
|
|
|
ok(extern_cnt === 1, "extern_cnt = " + extern_cnt);
|
2011-01-31 00:32:04 +01:00
|
|
|
</script>
|
|
|
|
<div id="a1"></div>
|
|
|
|
<div id="a2"></div>
|
|
|
|
<div id="b3"></div>
|
|
|
|
</body>
|
|
|
|
</html>
|