Release 1.6-rc2.
[wine/testsucceed.git] / dlls / mshtml / tests / events.html
blob131ba19cfda9d3c72a1dda520e7e74781de0786f
1 <html>
2 <head>
3 <script>
4 var testevent_divid2_called = false, cnt=0;
6 function ok(b,m) {
7 return external.ok(b, m);
10 function ondataavailable_test() {
11 var evobj, div, b = false;
13 div = document.getElementById("divid");
15 function ondataavailableHandler() {
16 b = true;
17 ok(window.event === evobj, "window.event != evobj");
19 ok(evobj.srcElement === div, "evobj.srcElement = " + evobj.srcElement);
20 ok(evobj.fromElement === null, "evobj.srcElement = " + evobj.fromElement);
21 ok(evobj.toElement === null, "evobj.srcElement = " + evobj.toElement);
22 ok(evobj.type === "dataavailable", "evobj.type = " + evobj.type);
25 function ondataavailableDocHandler() {
26 b = true;
27 ok(window.event === evobj, "window.event != evobj");
29 ok(evobj.srcElement === null, "evobj.srcElement = " + evobj.srcElement);
30 ok(evobj.fromElement === null, "evobj.srcElement = " + evobj.fromElement);
31 ok(evobj.toElement === null, "evobj.srcElement = " + evobj.toElement);
32 ok(evobj.type === "dataavailable", "evobj.type = " + evobj.type);
35 div.attachEvent("ondataavailable", ondataavailableHandler);
37 evobj = document.createEventObject();
38 ok(evobj.srcElement === null, "evobj.srcElement = " + evobj.srcElement);
39 ok(evobj.fromElement === null, "evobj.srcElement = " + evobj.fromElement);
40 ok(evobj.toElement === null, "evobj.srcElement = " + evobj.toElement);
41 ok(evobj.type === "", "evobj.type = " + evobj.type);
43 div.fireEvent("ondataavailable", evobj);
44 ok(b, "ondataavailable handler not called?");
46 ok(evobj.srcElement === div, "evobj.srcElement = " + evobj.srcElement);
47 ok(evobj.type === "dataavailable", "evobj.type = " + evobj.type);
49 div.detachEvent("ondataavailable", ondataavailableHandler);
51 b = false;
52 div.fireEvent("ondataavailable", evobj);
53 ok(!b, "ondataavailable handler called?");
55 ok(evobj.srcElement === div, "evobj.srcElement = " + evobj.srcElement);
56 ok(evobj.type === "dataavailable", "evobj.type = " + evobj.type);
58 document.attachEvent("ondataavailable", ondataavailableDocHandler);
60 evobj = document.createEventObject();
62 document.fireEvent("ondataavailable", evobj);
63 ok(b, "ondataavailable handler not called?");
65 ok(evobj.srcElement === null, "evobj.srcElement = " + evobj.srcElement);
66 ok(evobj.type === "dataavailable", "evobj.type = " + evobj.type);
69 function test_scriptfor() {
70 var div = document.getElementById("divid2");
71 ok("onclick" in div, "testevent not in div");
72 ok(typeof(div.onclick) === "function", "typeof(div.onclick) = " + typeof(div.onclick));
73 ok(testevent_divid2_called === false, "testevent_divid2_called = " + testevent_divid2_called);
74 div.click();
75 ok(testevent_divid2_called === true, "testevent_divid2_called = " + testevent_divid2_called);
77 ok(!("ontest" in div), "testevent in div");
78 ok(typeof(div.ontest) === "undefined", "typeof(div.ontest) = " + typeof(div.ontest));
81 function test_handler_this() {
82 document.body.innerHTML = '<div id="d1"><div id="d2"></div></div>';
84 var div1 = document.getElementById("d1");
85 var div2 = document.getElementById("d2");
86 var calls = new Array();
88 function createHandler(name, node) {
89 return function() {
90 ok(this === node, "this !== node");
91 calls.push(name);
95 function registerHandler(name, target) {
96 var b = target.attachEvent("onclick", function() {
97 ok(this === window, "this !== window");
98 calls.push(name+"*");
99 });
100 ok(b, "attachEvent failed");
103 registerHandler("div1", div1);
104 registerHandler("div2", div2);
105 registerHandler("body", document.body);
106 div1.onclick = createHandler("div1", div1);
107 div2.onclick = createHandler("div2", div2);
108 document.body.onclick = createHandler("body", document.body);
110 div2.click();
111 ok(calls == "div2,div2*,div1,div1*,body,body*", "calls = " + calls);
114 function runTests(t) {
115 try {
116 ok(cnt == 1, "cnt=" + cnt + " exception during loading?");
117 ok(t === window, "t !== window");
119 ok(typeof(window.onload) === "function", "typeof(window.onload) = " + typeof(window.onload));
120 ok(document.body.onload === window.onload, "document.body.onload !== window.onload");
122 test_scriptfor();
123 ondataavailable_test();
124 test_handler_this();
125 }catch(e) {
126 ok(false, "Got an exception: " + e.message);
129 external.reportSuccess();
131 </script>
132 </head>
133 <body onload="runTests(this)">
134 <div id="divid"></div>
135 <div id="divid2"></div>
136 <script event="onclick" for="divid2">
137 testevent_divid2_called = true;
138 </script>
139 <script event="ontest" for="divid2">
140 ok(false, "unexpected ontest");
141 </script>
142 <script>
143 (function() {
144 var div = document.getElementById("divid2");
145 ok(div.onclick === null, "div.onclick = null");
146 cnt++;
147 })();
148 </script>
149 </body>
150 </html>