mshtml: Bind events to document node instead of body element.
[wine/wine-gecko.git] / dlls / mshtml / tests / events.html
blobd4e264412235b75fabb247cc540e7fdc1252076e
1 <html>
2 <head>
3 <script>
4 var testevent_divid2_called = false, testevent_document_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 ok(typeof(document.onclick) === "function", "typeof(document.onclick) = " + typeof(document.onclick));
75 ok(testevent_document_called === false, "testevent_document_called = " + testevent_document_called);
76 div.click();
77 ok(testevent_divid2_called === true, "testevent_divid2_called = " + testevent_divid2_called);
78 ok(testevent_document_called === true, "testevent_document_called = " + testevent_document_called);
80 ok(!("ontest" in div), "testevent in div");
81 ok(typeof(div.ontest) === "undefined", "typeof(div.ontest) = " + typeof(div.ontest));
84 function test_handler_this() {
85 document.body.innerHTML = '<div id="d1"><div id="d2"></div></div>';
87 var div1 = document.getElementById("d1");
88 var div2 = document.getElementById("d2");
89 var calls = new Array();
91 function createHandler(name, node) {
92 return function() {
93 ok(this === node, "this !== node");
94 calls.push(name);
98 function registerHandler(name, target) {
99 var b = target.attachEvent("onclick", function() {
100 ok(this === window, "this !== window");
101 calls.push(name+"*");
103 ok(b, "attachEvent failed");
106 registerHandler("div1", div1);
107 registerHandler("div2", div2);
108 registerHandler("body", document.body);
109 div1.onclick = createHandler("div1", div1);
110 div2.onclick = createHandler("div2", div2);
111 document.body.onclick = createHandler("body", document.body);
113 div2.click();
114 ok(calls == "div2,div2*,div1,div1*,body,body*", "calls = " + calls);
117 window.onload = function() {
118 try {
119 ok(cnt == 1, "cnt=" + cnt + " exception during loading?");
120 ok(this === window, "this !== window");
122 ok(typeof(window.onload) === "function", "typeof(window.onload) = " + typeof(window.onload));
123 ok(document.body.onload === window.onload, "document.body.onload !== window.onload");
125 ok(img_onload_called, "img.onload not called before window.onload");
127 test_scriptfor();
128 ondataavailable_test();
129 test_handler_this();
130 }catch(e) {
131 ok(false, "Got an exception: " + e.message);
134 external.reportSuccess();
136 </script>
137 <script>
138 var img = document.createElement("img");
139 img.src = "http://test.winehq.org/tests/winehq_snapshot/index_files/winehq_logo_glass.png";
141 var img_onload_called = false;
142 img.onload = function() {
143 external.trace("img.onload");
144 img_onload_called = true;
146 </script>
147 </head>
148 <body>
149 <div id="divid"></div>
150 <div id="divid2"></div>
151 <script event="onclick" for="divid2">
152 testevent_divid2_called = true;
153 </script>
154 <script event="onclick" for="document">
155 testevent_document_called = true;
156 </script>
157 <script event="ontest" for="divid2">
158 ok(false, "unexpected ontest");
159 </script>
160 <script>
161 (function() {
162 var div = document.getElementById("divid2");
163 ok(div.onclick === null, "div.onclick = null");
164 cnt++;
165 })();
166 </script>
167 <script>
168 document.body.appendChild(img);
169 </script>
170 </body>
171 </html>