2012-09-13 12:29:05 +02:00
|
|
|
<html>
|
|
|
|
<head>
|
2017-10-12 14:27:08 +02:00
|
|
|
<script src="winetest.js" type="text/javascript"></script>
|
|
|
|
</head>
|
|
|
|
<head>
|
2012-09-13 12:29:05 +02:00
|
|
|
<script>
|
2013-10-01 15:43:52 +02:00
|
|
|
var testevent_divid2_called = false, testevent_document_called = false, cnt=0;
|
2012-10-02 15:47:06 +02:00
|
|
|
|
2012-09-13 12:29:05 +02:00
|
|
|
function ondataavailable_test() {
|
|
|
|
var evobj, div, b = false;
|
|
|
|
|
|
|
|
div = document.getElementById("divid");
|
|
|
|
|
|
|
|
function ondataavailableHandler() {
|
|
|
|
b = true;
|
|
|
|
ok(window.event === evobj, "window.event != evobj");
|
|
|
|
|
|
|
|
ok(evobj.srcElement === div, "evobj.srcElement = " + evobj.srcElement);
|
|
|
|
ok(evobj.fromElement === null, "evobj.srcElement = " + evobj.fromElement);
|
|
|
|
ok(evobj.toElement === null, "evobj.srcElement = " + evobj.toElement);
|
|
|
|
ok(evobj.type === "dataavailable", "evobj.type = " + evobj.type);
|
|
|
|
}
|
|
|
|
|
2012-09-13 12:29:17 +02:00
|
|
|
function ondataavailableDocHandler() {
|
|
|
|
b = true;
|
|
|
|
ok(window.event === evobj, "window.event != evobj");
|
|
|
|
|
|
|
|
ok(evobj.srcElement === null, "evobj.srcElement = " + evobj.srcElement);
|
|
|
|
ok(evobj.fromElement === null, "evobj.srcElement = " + evobj.fromElement);
|
|
|
|
ok(evobj.toElement === null, "evobj.srcElement = " + evobj.toElement);
|
|
|
|
ok(evobj.type === "dataavailable", "evobj.type = " + evobj.type);
|
|
|
|
}
|
|
|
|
|
2012-09-13 12:29:05 +02:00
|
|
|
div.attachEvent("ondataavailable", ondataavailableHandler);
|
|
|
|
|
|
|
|
evobj = document.createEventObject();
|
|
|
|
ok(evobj.srcElement === null, "evobj.srcElement = " + evobj.srcElement);
|
|
|
|
ok(evobj.fromElement === null, "evobj.srcElement = " + evobj.fromElement);
|
|
|
|
ok(evobj.toElement === null, "evobj.srcElement = " + evobj.toElement);
|
|
|
|
ok(evobj.type === "", "evobj.type = " + evobj.type);
|
|
|
|
|
|
|
|
div.fireEvent("ondataavailable", evobj);
|
|
|
|
ok(b, "ondataavailable handler not called?");
|
|
|
|
|
|
|
|
ok(evobj.srcElement === div, "evobj.srcElement = " + evobj.srcElement);
|
|
|
|
ok(evobj.type === "dataavailable", "evobj.type = " + evobj.type);
|
2012-09-13 12:29:17 +02:00
|
|
|
|
|
|
|
div.detachEvent("ondataavailable", ondataavailableHandler);
|
|
|
|
|
|
|
|
b = false;
|
|
|
|
div.fireEvent("ondataavailable", evobj);
|
|
|
|
ok(!b, "ondataavailable handler called?");
|
|
|
|
|
|
|
|
ok(evobj.srcElement === div, "evobj.srcElement = " + evobj.srcElement);
|
|
|
|
ok(evobj.type === "dataavailable", "evobj.type = " + evobj.type);
|
|
|
|
|
|
|
|
document.attachEvent("ondataavailable", ondataavailableDocHandler);
|
|
|
|
|
|
|
|
evobj = document.createEventObject();
|
|
|
|
|
|
|
|
document.fireEvent("ondataavailable", evobj);
|
|
|
|
ok(b, "ondataavailable handler not called?");
|
|
|
|
|
|
|
|
ok(evobj.srcElement === null, "evobj.srcElement = " + evobj.srcElement);
|
|
|
|
ok(evobj.type === "dataavailable", "evobj.type = " + evobj.type);
|
2012-09-13 12:29:05 +02:00
|
|
|
}
|
|
|
|
|
2012-10-02 15:47:06 +02:00
|
|
|
function test_scriptfor() {
|
|
|
|
var div = document.getElementById("divid2");
|
|
|
|
ok("onclick" in div, "testevent not in div");
|
|
|
|
ok(typeof(div.onclick) === "function", "typeof(div.onclick) = " + typeof(div.onclick));
|
|
|
|
ok(testevent_divid2_called === false, "testevent_divid2_called = " + testevent_divid2_called);
|
2013-10-01 15:43:52 +02:00
|
|
|
ok(typeof(document.onclick) === "function", "typeof(document.onclick) = " + typeof(document.onclick));
|
|
|
|
ok(testevent_document_called === false, "testevent_document_called = " + testevent_document_called);
|
2012-10-02 15:47:06 +02:00
|
|
|
div.click();
|
|
|
|
ok(testevent_divid2_called === true, "testevent_divid2_called = " + testevent_divid2_called);
|
2013-10-01 15:43:52 +02:00
|
|
|
ok(testevent_document_called === true, "testevent_document_called = " + testevent_document_called);
|
2012-10-02 15:47:06 +02:00
|
|
|
|
|
|
|
ok(!("ontest" in div), "testevent in div");
|
|
|
|
ok(typeof(div.ontest) === "undefined", "typeof(div.ontest) = " + typeof(div.ontest));
|
|
|
|
}
|
|
|
|
|
2012-10-22 12:00:06 +02:00
|
|
|
function test_handler_this() {
|
|
|
|
document.body.innerHTML = '<div id="d1"><div id="d2"></div></div>';
|
|
|
|
|
|
|
|
var div1 = document.getElementById("d1");
|
|
|
|
var div2 = document.getElementById("d2");
|
|
|
|
var calls = new Array();
|
|
|
|
|
|
|
|
function createHandler(name, node) {
|
|
|
|
return function() {
|
|
|
|
ok(this === node, "this !== node");
|
|
|
|
calls.push(name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function registerHandler(name, target) {
|
2017-10-12 14:27:24 +02:00
|
|
|
var b = target.attachEvent("onclick", function(event_arg) {
|
2012-10-22 12:00:06 +02:00
|
|
|
ok(this === window, "this !== window");
|
|
|
|
calls.push(name+"*");
|
2017-10-12 14:27:24 +02:00
|
|
|
with(todo_wine)
|
|
|
|
ok(event_arg != window.event, "event_arg == window.event");
|
2012-10-22 12:00:06 +02:00
|
|
|
});
|
|
|
|
ok(b, "attachEvent failed");
|
|
|
|
}
|
|
|
|
|
|
|
|
registerHandler("div1", div1);
|
|
|
|
registerHandler("div2", div2);
|
|
|
|
registerHandler("body", document.body);
|
|
|
|
div1.onclick = createHandler("div1", div1);
|
|
|
|
div2.onclick = createHandler("div2", div2);
|
|
|
|
document.body.onclick = createHandler("body", document.body);
|
|
|
|
|
|
|
|
div2.click();
|
|
|
|
ok(calls == "div2,div2*,div1,div1*,body,body*", "calls = " + calls);
|
|
|
|
}
|
|
|
|
|
2014-12-24 13:10:33 +01:00
|
|
|
function test_insert_script() {
|
|
|
|
var e = document.createElement("script");
|
|
|
|
|
|
|
|
extern_cnt = 0;
|
|
|
|
e.src = "externscr.js";
|
|
|
|
|
|
|
|
var readystatechange_log = "";
|
|
|
|
e.onreadystatechange = function() {
|
2017-10-20 15:10:30 +02:00
|
|
|
ok(window.event.srcElement === e, "srcElement != e");
|
2014-12-24 13:10:33 +01:00
|
|
|
readystatechange_log += "," + e.readyState;
|
|
|
|
ok(extern_cnt === 1, "extern_cnt = " + extern_cnt);
|
|
|
|
if(e.readyState === "complete") {
|
|
|
|
ok(readystatechange_log === "append,complete", "readystatechange_log = " + readystatechange_log);
|
2017-10-12 14:27:08 +02:00
|
|
|
reportSuccess();
|
2014-12-24 13:10:33 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
document.body.appendChild(e);
|
|
|
|
ok(extern_cnt === 1, "extern_cnt = " + extern_cnt);
|
|
|
|
readystatechange_log = "append";
|
|
|
|
}
|
|
|
|
|
2015-03-10 18:27:31 +01:00
|
|
|
var string_handler_called = false;
|
|
|
|
|
|
|
|
function test_string_event_handler() {
|
|
|
|
var e = document.createElement("div");
|
|
|
|
var event_str = "string_handler_called = true;";
|
|
|
|
|
|
|
|
document.body.appendChild(e);
|
|
|
|
e.onclick = event_str;
|
|
|
|
ok(e.onclick === event_str, "e.onclick = " + e.onclick);
|
|
|
|
e.click();
|
|
|
|
ok(string_handler_called === false, "string handler called");
|
|
|
|
|
|
|
|
e.setAttribute("onclick", event_str);
|
|
|
|
ok(e.onclick === event_str, "e.onclick = " + e.onclick);
|
|
|
|
e.click();
|
|
|
|
ok(string_handler_called === false, "string handler called");
|
|
|
|
}
|
|
|
|
|
2017-02-13 21:10:38 +01:00
|
|
|
function test_body_events() {
|
2017-10-16 22:31:42 +02:00
|
|
|
var f = function() {}, g = function() {};
|
2017-02-13 21:10:38 +01:00
|
|
|
|
|
|
|
document.body.onload = f;
|
|
|
|
ok(document.body.onload === f, "body.onload != f");
|
|
|
|
ok(window.onload === f, "window.onload != f");
|
|
|
|
|
|
|
|
document.body.onfocus = f;
|
|
|
|
ok(document.body.onfocus === f, "body.onfocus != f");
|
|
|
|
ok(window.onfocus === f, "window.onfocus != f");
|
2017-10-16 22:31:42 +02:00
|
|
|
window.onfocus = g;
|
|
|
|
ok(document.body.onfocus === g, "body.onfocus != g");
|
|
|
|
ok(window.onfocus === g, "window.onfocus != g");
|
|
|
|
|
|
|
|
var onclick_called = false;
|
|
|
|
var onclick_handler = function() { onclick_called = true; };
|
|
|
|
document.body.attachEvent("onclick", onclick_handler);
|
|
|
|
window.detachEvent("onclick", onclick_handler);
|
|
|
|
document.body.click();
|
|
|
|
ok(onclick_called, "onclick handler not invoked");
|
2017-02-13 21:10:38 +01:00
|
|
|
}
|
|
|
|
|
2017-10-19 17:01:55 +02:00
|
|
|
function test_event_target() {
|
|
|
|
var div = document.createElement("div");
|
|
|
|
document.body.appendChild(div);
|
|
|
|
|
|
|
|
var last_event_arg;
|
|
|
|
div.attachEvent("onclick", function(event_arg) {
|
|
|
|
ok(event_arg.srcElement === div, "srcElement != div");
|
|
|
|
last_event_arg = event_arg;
|
|
|
|
});
|
|
|
|
|
|
|
|
div.click();
|
|
|
|
with(todo_wine)
|
|
|
|
ok(last_event_arg.srcElement === null, "srcElement != null");
|
2017-10-25 18:13:07 +02:00
|
|
|
|
|
|
|
document.body.removeChild(div);
|
|
|
|
}
|
|
|
|
|
|
|
|
function test_attach_event() {
|
|
|
|
var calls;
|
|
|
|
|
|
|
|
var div = document.createElement("div");
|
|
|
|
document.body.appendChild(div);
|
|
|
|
|
|
|
|
function listener() {
|
|
|
|
calls += "listener,";
|
|
|
|
}
|
|
|
|
|
|
|
|
function listener2() {
|
|
|
|
calls += "listener2,";
|
|
|
|
}
|
|
|
|
|
|
|
|
/* if the same listener is added twice, it will be called twice */
|
|
|
|
div.attachEvent("onclick", listener);
|
|
|
|
div.attachEvent("onclick", listener2);
|
|
|
|
div.attachEvent("onclick", listener);
|
|
|
|
|
|
|
|
calls = "";
|
|
|
|
div.click();
|
|
|
|
ok(calls === "listener,listener2,listener,", "calls = " + calls);
|
|
|
|
|
|
|
|
/* remove listener once, it will be called once */
|
|
|
|
div.detachEvent("onclick", listener);
|
|
|
|
|
|
|
|
calls = "";
|
|
|
|
div.click();
|
|
|
|
ok(calls === "listener2,listener,", "calls = " + calls);
|
|
|
|
|
|
|
|
div.detachEvent("onclick", listener);
|
|
|
|
div.detachEvent("onclick", listener2);
|
|
|
|
|
|
|
|
calls = "";
|
|
|
|
div.click();
|
|
|
|
ok(calls === "", "calls = " + calls);
|
|
|
|
|
|
|
|
document.body.removeChild(div);
|
|
|
|
}
|
|
|
|
|
|
|
|
function test_listener_order() {
|
2018-01-10 22:59:55 +01:00
|
|
|
if(!("documentMode" in document)) {
|
|
|
|
win_skip("Skipping test_listener_order on too old IE");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-10-25 18:13:07 +02:00
|
|
|
var div = document.createElement("div");
|
|
|
|
document.body.appendChild(div);
|
|
|
|
|
|
|
|
var calls;
|
|
|
|
function record_call(msg) {
|
|
|
|
return function() { calls += msg + "," };
|
|
|
|
}
|
|
|
|
|
|
|
|
div.attachEvent("onclick", record_call("click1"));
|
|
|
|
div.onclick = record_call("onclick");
|
|
|
|
div.attachEvent("onclick", record_call("click2"));
|
|
|
|
div.attachEvent("onclick", record_call("click3"));
|
|
|
|
|
|
|
|
calls = "";
|
|
|
|
div.click();
|
|
|
|
ok(calls === "onclick,click3,click2,click1,", "calls = " + calls);
|
|
|
|
|
|
|
|
document.body.removeChild(div);
|
|
|
|
}
|
|
|
|
|
|
|
|
function test_attach_in_attach() {
|
|
|
|
var calls;
|
|
|
|
|
|
|
|
var div = document.createElement("div");
|
|
|
|
document.body.appendChild(div);
|
|
|
|
|
|
|
|
/* listener attached inside onevent handler will be invoked in this propagation */
|
|
|
|
div.onclick = function () {
|
|
|
|
calls += "div.onclick,";
|
|
|
|
div.attachEvent("onclick", function() {
|
|
|
|
calls += "div.click,";
|
2018-01-04 15:57:22 +01:00
|
|
|
/* listener attached inside another attached listener will not be invoked */
|
2017-10-25 18:13:07 +02:00
|
|
|
div.attachEvent("onclick", function () { ok(false, "unexpected call"); });
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
calls = "";
|
|
|
|
div.click();
|
|
|
|
ok(calls === "div.onclick,div.click,", "calls = " + calls);
|
|
|
|
|
|
|
|
document.body.removeChild(div);
|
2017-10-19 17:01:55 +02:00
|
|
|
}
|
|
|
|
|
2014-09-10 17:30:24 +02:00
|
|
|
window.onload = function() {
|
2012-09-13 12:29:05 +02:00
|
|
|
try {
|
2014-12-24 13:10:33 +01:00
|
|
|
ok(inlscr_complete_called, "onreadystatechange not fired");
|
2016-02-24 16:12:24 +01:00
|
|
|
ok(extern_res_script_rs === "eval,complete1," || extern_res_script_rs == "loaded0,eval,complete1,",
|
|
|
|
"extern_res_script_rs = " + extern_res_script_rs + " expected (loaded0)?,eval,complete1,");
|
2014-12-24 13:10:33 +01:00
|
|
|
ok(extern_http_script_rs === "loading,loaded,complete,",
|
|
|
|
"extern_http_script_rs = " + extern_http_script_rs + " expected loading,loaded,complete,");
|
|
|
|
|
2012-10-02 15:47:06 +02:00
|
|
|
ok(cnt == 1, "cnt=" + cnt + " exception during loading?");
|
2014-09-10 17:30:24 +02:00
|
|
|
ok(this === window, "this !== window");
|
2012-10-22 12:00:06 +02:00
|
|
|
|
|
|
|
ok(typeof(window.onload) === "function", "typeof(window.onload) = " + typeof(window.onload));
|
|
|
|
ok(document.body.onload === window.onload, "document.body.onload !== window.onload");
|
2012-10-02 15:47:06 +02:00
|
|
|
|
2014-09-10 17:30:24 +02:00
|
|
|
ok(img_onload_called, "img.onload not called before window.onload");
|
|
|
|
|
2012-10-02 15:47:06 +02:00
|
|
|
test_scriptfor();
|
2012-09-13 12:29:05 +02:00
|
|
|
ondataavailable_test();
|
2012-10-22 12:00:06 +02:00
|
|
|
test_handler_this();
|
2014-12-24 13:10:33 +01:00
|
|
|
test_insert_script();
|
2015-03-10 18:27:31 +01:00
|
|
|
test_string_event_handler();
|
2017-02-13 21:10:38 +01:00
|
|
|
test_body_events();
|
2017-10-19 17:01:55 +02:00
|
|
|
test_event_target();
|
2017-10-25 18:13:07 +02:00
|
|
|
test_attach_event();
|
|
|
|
test_listener_order();
|
|
|
|
test_attach_in_attach();
|
2012-09-13 12:29:05 +02:00
|
|
|
}catch(e) {
|
|
|
|
ok(false, "Got an exception: " + e.message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
2014-09-10 17:30:24 +02:00
|
|
|
<script>
|
|
|
|
var img = document.createElement("img");
|
|
|
|
img.src = "http://test.winehq.org/tests/winehq_snapshot/index_files/winehq_logo_glass.png";
|
|
|
|
|
|
|
|
var img_onload_called = false;
|
|
|
|
img.onload = function() {
|
2017-10-12 14:27:08 +02:00
|
|
|
trace("img.onload");
|
2014-09-10 17:30:24 +02:00
|
|
|
img_onload_called = true;
|
|
|
|
}
|
|
|
|
</script>
|
2012-09-13 12:29:05 +02:00
|
|
|
</head>
|
2014-09-10 17:30:24 +02:00
|
|
|
<body>
|
2012-09-13 12:29:05 +02:00
|
|
|
<div id="divid"></div>
|
2012-10-02 15:47:06 +02:00
|
|
|
<div id="divid2"></div>
|
|
|
|
<script event="onclick" for="divid2">
|
|
|
|
testevent_divid2_called = true;
|
|
|
|
</script>
|
2013-10-01 15:43:52 +02:00
|
|
|
<script event="onclick" for="document">
|
|
|
|
testevent_document_called = true;
|
|
|
|
</script>
|
2012-10-02 15:47:06 +02:00
|
|
|
<script event="ontest" for="divid2">
|
|
|
|
ok(false, "unexpected ontest");
|
|
|
|
</script>
|
|
|
|
<script>
|
|
|
|
(function() {
|
|
|
|
var div = document.getElementById("divid2");
|
|
|
|
ok(div.onclick === null, "div.onclick = null");
|
|
|
|
cnt++;
|
|
|
|
})();
|
|
|
|
</script>
|
2014-09-10 17:30:24 +02:00
|
|
|
<script>
|
2014-12-24 13:10:33 +01:00
|
|
|
var inlscr_complete_called = false, extern_res_script_rs = "", extern_http_script_rs = "";
|
|
|
|
var extern_cnt = 0;
|
|
|
|
|
|
|
|
function expect_inlscr_complete() {
|
|
|
|
var elem = document.getElementById("inlscr");
|
|
|
|
ok(elem.readyState === "complete" || broken(elem.readyState === "loading"), "expect_inlscr_complete: elem.readyState = " + elem.readyState);
|
|
|
|
if(elem.readyState === "complete")
|
|
|
|
inlscr_complete_called = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
function extern_res_script_readystatechange() {
|
|
|
|
var elem = document.getElementById("extscr");
|
|
|
|
if(elem.readyState != "loading")
|
|
|
|
extern_res_script_rs += elem.readyState + extern_cnt + ",";
|
|
|
|
else
|
2017-10-12 14:27:08 +02:00
|
|
|
trace("Got loading readyState from external res script.");
|
2014-12-24 13:10:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function http_script_readystatechange() {
|
|
|
|
var elem = document.getElementById("httpscr");
|
|
|
|
extern_http_script_rs += elem.readyState + ",";
|
|
|
|
}
|
|
|
|
|
|
|
|
function on_externscr() {
|
|
|
|
var elem = document.getElementById("extscr");
|
|
|
|
ok(elem.readyState === "interactive" || broken(elem.readyState === "loading"),
|
|
|
|
"on_externscr: elem.readyState = " + elem.readyState);
|
|
|
|
extern_res_script_rs += "eval,";
|
|
|
|
}
|
|
|
|
|
|
|
|
</script>
|
|
|
|
<script id="inlscr" onreadystatechange="expect_inlscr_complete();">
|
|
|
|
(function() {
|
|
|
|
ok(inlscr_complete_called === false || broken(inlscr_complete_called), "onreadystatechange fired too early");
|
|
|
|
|
|
|
|
var elem = document.getElementById("inlscr");
|
|
|
|
ok(elem.readyState === "interactive", "inlscr: elem.readyState = " + elem.readyState);
|
|
|
|
})();
|
|
|
|
</script>
|
|
|
|
<script id="extscr" onreadystatechange="extern_res_script_readystatechange()" src="externscr.js"></script>
|
|
|
|
<script id="httpscr" onreadystatechange="http_script_readystatechange()" src="https://test.winehq.org/tests/empty.js?123456"></script>
|
|
|
|
<script>
|
2014-09-10 17:30:24 +02:00
|
|
|
document.body.appendChild(img);
|
|
|
|
</script>
|
2012-09-13 12:29:05 +02:00
|
|
|
</body>
|
|
|
|
</html>
|