[MSHTML_WINETEST]
[reactos.git] / rostests / winetests / mshtml / exectest.html
1 <html>
2 <body>
3 Script execution test
4 <div id="b1"></div>
5 <div id="b2"></div>
6 <div id="b3"></div>
7 <script id="emptyscript"></script>
8 <script id="put_text_script">2+2</script>
9 <script>
10 function ok(b, msg) {
11 return external.ok(b, msg);
12 }
13
14 var executed = false;
15 var extern_cnt = 0;
16 var exec_cnt;
17
18 function testWriteScript() {
19 var len = document.getElementsByTagName('div').length;
20 ok(len === 3, "init length = " + len);
21
22 document.write("<script>"
23 + "var len = document.getElementsByTagName('div').length;"
24 + "ok(len === 3, 'unexpected length ' + len);"
25 + "executed = true;"
26 + "<" + "/script>");
27
28 len = document.getElementsByTagName('script').length;
29 ok(len === 4, "script col length = " + len);
30 ok(executed, "written script not executed");
31 }
32
33 function testPutSrc() {
34 var elem = document.getElementById("emptyscript");
35
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");
39 }
40
41 function testPutText() {
42 var elem = document.getElementById("put_text_script");
43
44 exec_cnt = 0;
45 elem.text = "exec_cnt++;";
46 ok(exec_cnt === 1, "put_text_script exec_cnt " + exec_cnt);
47
48 exec_cnt = 0;
49 elem.text = "exec_cnt++;";
50 ok(exec_cnt === 1, "put_text_script exec_cnt " + exec_cnt);
51 }
52
53 try {
54 testWriteScript();
55 testPutSrc();
56 testPutText();
57 }catch(e) {
58 ok(false, "Got an exception " + e.message);
59 }
60
61 function testPutSrc2() {
62 var elem, elem2;
63
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");
69
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");
75
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");
83 }
84
85 function testPutText2() {
86 var elem;
87
88 elem = document.createElement("script");
89 exec_cnt = 0;
90 elem.text = "exec_cnt++;";
91 ok(exec_cnt === 0, "script exec_cnt " + exec_cnt);
92
93 document.body.appendChild(elem);
94 ok(exec_cnt === 1, "script exec_cnt " + exec_cnt);
95 exec_cnt = 0;
96 elem.text = "exec_cnt++;";
97 ok(exec_cnt === 1, "script exec_cnt " + exec_cnt);
98
99 elem.src = "externscr.js";
100 ok(extern_cnt === 5, "extern_cnt = " + extern_cnt + " expected 5");
101
102 exec_cnt = 0;
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");
107
108 elem = document.createElement("script");
109 exec_cnt = 0;
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");
114
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");
118 }
119
120 document.body.onload = function() {
121 ok(extern_cnt === 1, "extern_cnt = " + extern_cnt);
122 try {
123 testPutSrc2();
124 testPutText2();
125 }catch(e) {
126 ok(false, "got an exception " + e.message);
127 }
128
129 external.reportSuccess();
130 }
131 </script>
132 <script>
133 ok(extern_cnt === 1, "extern_cnt = " + extern_cnt);
134 </script>
135 <div id="a1"></div>
136 <div id="a2"></div>
137 <div id="b3"></div>
138 </body>
139 </html>