7 <script id="emptyscript"></script>
8 <script id="put_text_script">2+2</script>
11 return external.ok(b, msg);
18 function testWriteScript() {
19 var len = document.getElementsByTagName('div').length;
20 ok(len === 3, "init length = " + len);
22 document.write("<script>"
23 + "var len = document.getElementsByTagName('div').length;"
24 + "ok(len === 3, 'unexpected length ' + len);"
28 len = document.getElementsByTagName('script').length;
29 ok(len === 4, "script col length = " + len);
30 ok(executed, "written script not executed");
33 function testPutSrc() {
34 var elem = document.getElementById("emptyscript");
36 ok(extern_cnt === 0, "extern_cnt = " + extern_cnt + " expected 0");
37 elem.src = "externscr.js";
38 ok(extern_cnt === 0, "extern_cnt = " + extern_cnt + " expected 0");
41 function testPutText() {
42 var elem = document.getElementById("put_text_script");
45 elem.text = "exec_cnt++;";
46 ok(exec_cnt === 1, "put_text_script exec_cnt " + exec_cnt);
49 elem.text = "exec_cnt++;";
50 ok(exec_cnt === 1, "put_text_script exec_cnt " + exec_cnt);
58 ok(false, "Got an exception");
61 function testPutSrc2() {
64 elem = document.createElement("script");
65 elem.src = "externscr.js";
66 ok(extern_cnt === 1, "extern_cnt = " + extern_cnt + " expected 1");
67 document.body.appendChild(elem);
68 ok(extern_cnt === 2, "extern_cnt = " + extern_cnt + " expected 2");
70 elem = document.createElement("script");
71 document.body.appendChild(elem);
72 ok(extern_cnt === 2, "extern_cnt = " + extern_cnt + " expected 2");
73 elem.src = "externscr.js";
74 ok(extern_cnt === 3, "extern_cnt = " + extern_cnt + " expected 3");
76 elem2 = document.createElement("div");
77 elem = document.createElement("script");
78 elem.src = "externscr.js";
79 ok(extern_cnt === 3, "extern_cnt = " + extern_cnt + " expected 3");
80 elem2.appendChild(elem);
81 document.body.appendChild(elem2);
82 ok(extern_cnt === 4, "extern_cnt = " + extern_cnt + " expected 4");
85 function testPutText2() {
88 elem = document.createElement("script");
90 elem.text = "exec_cnt++;";
91 ok(exec_cnt === 0, "script exec_cnt " + exec_cnt);
93 document.body.appendChild(elem);
94 ok(exec_cnt === 1, "script exec_cnt " + exec_cnt);
96 elem.text = "exec_cnt++;";
97 ok(exec_cnt === 1, "script exec_cnt " + exec_cnt);
99 elem.src = "externscr.js";
100 ok(extern_cnt === 5, "extern_cnt = " + extern_cnt + " expected 5");
103 ok(extern_cnt === 5, "> extern_cnt = " + extern_cnt + " expected 5");
104 elem.text = "exec_cnt++;"; /* forces evaluation, but src will be executed */
105 ok(exec_cnt === 0, "script exec_cnt " + exec_cnt);
106 ok(extern_cnt === 6, "< extern_cnt = " + extern_cnt + " expected 6");
108 elem = document.createElement("script");
110 elem.text = "exec_cnt++;";
111 ok(exec_cnt === 0, "script exec_cnt " + exec_cnt);
112 elem.src = "externscr.js";
113 ok(extern_cnt === 6, "extern_cnt = " + extern_cnt + " expected 6");
115 document.body.appendChild(elem);
116 ok(exec_cnt === 0, "script exec_cnt " + exec_cnt);
117 ok(extern_cnt === 7, "extern_cnt = " + extern_cnt + " expected 7");
120 document.body.onload = function() {
121 ok(extern_cnt === 1, "extern_cnt = " + extern_cnt);
126 ok(false, "got an exception");
129 external.reportSuccess();
133 ok(extern_cnt === 1, "extern_cnt = " + extern_cnt);