blob: 14de12dd3fdcd6755893f7ed80d91403d140f054 [file] [log] [blame]
<!DOCTYPE html>
<html>
<head>
<script src="../../http/tests/inspector/resources/inspector-test.js"></script>
<script>
function eventListenerJSONFilter(key, value) {
if (typeof value === "function")
return `<function ${value.name}>`;
return value;
}
function stringify(object) {
return JSON.stringify(object, eventListenerJSONFilter, 2);
}
function test()
{
function evaluateWithCommandLineAPI(expression) {
return new Promise((resolve, reject) => {
WI.runtimeManager.evaluateInInspectedWindow(expression, {objectGroup: "test", includeCommandLineAPI: true}, (object, wasThrown) => {
resolve(object);
});
});
}
InspectorTest.debug();
let suite = InspectorTest.createAsyncSuite("Console.CommandLineAPI.getEventListeners");
function addTestCase({name, expression}) {
suite.addTestCase({
name,
async test() {
await evaluateWithCommandLineAPI(`
try {
TestPage.addResult(stringify(getEventListeners(${expression})));
} catch (e) {
TestPage.addResult(e);
}
TestPage.log("");
`);
}
});
}
addTestCase({
name: "Console.CommandLineAPI.getEventListeners.NoArguments",
expression: ``,
});
addTestCase({
name: "Console.CommandLineAPI.getEventListeners.Undefined",
expression: `undefined`,
});
addTestCase({
name: "Console.CommandLineAPI.getEventListeners.Null",
expression: `null`,
});
addTestCase({
name: "Console.CommandLineAPI.getEventListeners.String",
expression: `"test"`,
});
addTestCase({
name: "Console.CommandLineAPI.getEventListeners.window",
expression: `window`,
});
addTestCase({
name: "Console.CommandLineAPI.getEventListeners.NodeNoListeners",
expression: `document.createElement("p")`,
});
addTestCase({
name: "Console.CommandLineAPI.getEventListeners.NodeWithListeners",
expression: `document.getElementById("target")`,
});
suite.runTestCasesAndFinish();
}
</script>
</head>
<body onload="runTest()">
<p>Test for CommandLineAPI getEventListeners.</p>
<div id="target"></div>
<script>
let target = document.getElementById("target");
target.onclick = function onclickHandler() { console.log("click"); };
target.addEventListener("hover", function hoverHandler() { console.log("hover"); }, {once: true, passive: true});
target.addEventListener("click", function clickHandler() { console.log("click 2"); }, true);
target.addEventListener("fake", function fakeHandler() { console.log("fake"); });
</script>
</body>
</html>