<!doctype html>
<html>
<head>
<script src="../../http/tests/inspector/resources/inspector-test.js"></script>
<script src="../debugger/resources/breakpoint-options-utilities.js"></script>
<script src="../debugger/resources/log-active-stack-trace.js"></script>
<script src="resources/event-breakpoint-utilities.js"></script>
<script>
function handleBody_click(event) {
    TestPage.dispatchEventToFrontend("TestPage-click");
}

function handleBody_custom(event) {
    TestPage.dispatchEventToFrontend("TestPage-custom");
}

function handleX_click(event) {
}

function trigger_click() {
    document.body.click();
}

function trigger_custom() {
    document.body.dispatchEvent(new Event("custom"));
}

function clickX() {
    document.getElementById("x").click();
}

function test() {
    let suite = InspectorTest.createAsyncSuite("DOMDebugger.Event.Listener");

    function addTestCasesForEventName(eventName) {
        suite.addTestCase({
            name: `DOMDebugger.Event.Listener.AddBreakpoint "${eventName}"`,
            description: "Check that the debugger pauses for enabled breakpoints.",
            test(resolve, reject) {
                let paused = false;

                let listener = WI.debuggerManager.singleFireEventListener(WI.DebuggerManager.Event.Paused, (event) => {
                    paused = true;

                    InspectorTest.pass("Should pause before event handler is run.");
                    logActiveStackTrace();

                    WI.debuggerManager.resume()
                    .catch(reject);
                });

                InspectorTest.singleFireEventListener(`TestPage-${eventName}`, (event) => {
                    if (!paused) {
                        WI.debuggerManager.removeEventListener(WI.DebuggerManager.Event.Paused, listener);

                        InspectorTest.fail("Should pause before event handler is run.");
                    }

                    resolve();
                });

                InspectorTest.EventBreakpoint.createBreakpoint(WI.EventBreakpoint.Type.Listener, {eventName})
                .then(InspectorTest.EventBreakpoint.awaitEvent("body", eventName))
                .catch(reject);
            },
            teardown: InspectorTest.EventBreakpoint.teardown,
        });

        suite.addTestCase({
            name: `DOMDebugger.Event.Listener.AddDisabledBreakpoint "${eventName}"`,
            description: "Check that debugger does not pause for disabled breakpoints.",
            test(resolve, reject) {
                InspectorTest.EventBreakpoint.failOnPause(resolve, reject, WI.DebuggerManager.PauseReason.Listener, eventName, "Should not pause for disabled breakpoint.");

                InspectorTest.EventBreakpoint.createBreakpoint(WI.EventBreakpoint.Type.Listener, {eventName})
                .then(InspectorTest.EventBreakpoint.disableBreakpoint)
                .then(InspectorTest.EventBreakpoint.awaitEvent("body", eventName))
                .catch(reject);
            },
            teardown: InspectorTest.EventBreakpoint.teardown,
        });

        suite.addTestCase({
            name: `DOMDebugger.Event.Listener.RemoveBreakpoint "${eventName}"`,
            description: "Check that debugger does not pause for removed breakpoint.",
            test(resolve, reject) {
                InspectorTest.EventBreakpoint.failOnPause(resolve, reject, WI.DebuggerManager.PauseReason.Listener, eventName, "Should not pause for removed breakpoint.");

                InspectorTest.EventBreakpoint.createBreakpoint(WI.EventBreakpoint.Type.Listener, {eventName})
                .then(InspectorTest.EventBreakpoint.removeBreakpoint)
                .then(InspectorTest.EventBreakpoint.awaitEvent("body", eventName))
                .catch(reject);
            },
            teardown: InspectorTest.EventBreakpoint.teardown,
        });

        suite.addTestCase({
            name: `DOMDebugger.Event.Listener.RemoveDisabledBreakpoint "${eventName}"`,
            description: "Check that a disabled breakpoint can be removed.",
            test(resolve, reject) {
                InspectorTest.EventBreakpoint.failOnPause(resolve, reject, WI.DebuggerManager.PauseReason.Listener, eventName, "Should not pause for removed disabled breakpoint.");

                InspectorTest.EventBreakpoint.createBreakpoint(WI.EventBreakpoint.Type.Listener, {eventName})
                .then(InspectorTest.EventBreakpoint.disableBreakpoint)
                .then(InspectorTest.EventBreakpoint.removeBreakpoint)
                .then(InspectorTest.EventBreakpoint.awaitEvent("body", eventName))
                .catch(reject);
            },
            teardown: InspectorTest.EventBreakpoint.teardown,
        });
    }

    addTestCasesForEventName("click");
    addTestCasesForEventName("custom");

    suite.addTestCase({
        name: `DOMDebugger.Event.Listener.AllEventsBreakpoint`,
        description: "Check that the all events breakpoint pauses for every event.",
        test(resolve, reject) {
            let pauseCount = 0;

            let listener = WI.debuggerManager.addEventListener(WI.DebuggerManager.Event.Paused, (event) => {
                ++pauseCount;

                InspectorTest.pass("Should pause before event handler is run.");
                logActiveStackTrace();

                WI.debuggerManager.resume()
                .catch(reject);
            });

            InspectorTest.EventBreakpoint.createBreakpoint(WI.EventBreakpoint.Type.Listener)
            .then(() => {
                InspectorTest.log("Firing \"click\" on body...");
                return InspectorTest.evaluateInPage(`trigger_click()`);
            })
            .then(() => {
                InspectorTest.log("Firing \"custom\" on body...");
                return InspectorTest.evaluateInPage(`trigger_custom()`);
            })
            .then(() => {
                InspectorTest.expectEqual(pauseCount, 2, "Should have paused twice.");
                InspectorTest.assert(!WI.debuggerManager.paused, "Should not be paused.");

                WI.debuggerManager.removeEventListener(WI.DebuggerManager.Event.Paused, listener);
            })
            .then(resolve, reject);
        },
        teardown: InspectorTest.EventBreakpoint.teardown,
    });

    suite.addTestCase({
        name: `DOMDebugger.Event.Listener.AddMultipleBreakpoints`,
        description: "Check that a single breakpoint pauses for every event of that type.",
        test(resolve, reject) {
            let pauseCount = 0;

            let listener = WI.debuggerManager.addEventListener(WI.DebuggerManager.Event.Paused, (event) => {
                ++pauseCount;

                InspectorTest.pass("Should pause before event handler is run.");
                logActiveStackTrace();

                WI.debuggerManager.resume()
                .catch(reject);
            });

            InspectorTest.singleFireEventListener(`TestPage-click`, (event) => {
                InspectorTest.expectEqual(pauseCount, 2, "Should have paused twice.");
                InspectorTest.assert(!WI.debuggerManager.paused, "Should not be paused.");

                WI.debuggerManager.removeEventListener(WI.DebuggerManager.Event.Paused, listener);

                resolve();
            });

            InspectorTest.EventBreakpoint.createBreakpoint(WI.EventBreakpoint.Type.Listener, {eventName: "click"})
            .then(() => {
                InspectorTest.log("Firing \"click\" on div#x...");
                return InspectorTest.evaluateInPage(`clickX()`);
            })
            .catch(reject);
        },
        teardown: InspectorTest.EventBreakpoint.teardown,
    });

    suite.addTestCase({
        name: `DOMDebugger.Event.Listener.DisableBetweenDispatches`,
        description: "Check that event listener breakpoints only pause when breakpoints are enabled.",
        test(resolve, reject) {
            let pauseCount = 0;

            let listener = WI.debuggerManager.addEventListener(WI.DebuggerManager.Event.Paused, (event) => {
                ++pauseCount;

                InspectorTest.pass("Should pause before event handler is run.");
                logActiveStackTrace();

                InspectorTest.log("Disabling breakpoints...");
                DebuggerAgent.setBreakpointsActive(false)
                .then(() => WI.debuggerManager.resume())
                .catch(reject);
            });

            InspectorTest.singleFireEventListener(`TestPage-click`, (event) => {
                InspectorTest.expectEqual(pauseCount, 1, "Should have paused once.");
                InspectorTest.assert(!WI.debuggerManager.paused, "Should not be paused.");

                WI.debuggerManager.removeEventListener(WI.DebuggerManager.Event.Paused, listener);

                DebuggerAgent.setBreakpointsActive(true)
                .then(resolve, reject);
            });

            InspectorTest.EventBreakpoint.createBreakpoint(WI.EventBreakpoint.Type.Listener, {eventName: "click"})
            .then(() => {
                InspectorTest.log("Firing \"click\" on div#x...");
                return InspectorTest.evaluateInPage(`clickX()`);
            })
            .catch(reject);
        },
        teardown: InspectorTest.EventBreakpoint.teardown,
    });

    InspectorTest.BreakpointOptions.addTestCases(suite, {
        createBreakpoint() {
            return InspectorTest.EventBreakpoint.createBreakpoint(WI.EventBreakpoint.Type.Listener, {eventName: "click"});
        },
        triggerBreakpoint() {
            return Promise.all([
                InspectorTest.awaitEvent("TestPage-click"),
                InspectorTest.evaluateInPage(`trigger_click()`),
            ]);
        },
    });

    suite.runTestCasesAndFinish();
}
</script>
</head>
<body onload="runTest()">
    <p>Tests for Event Listener breakpoints.</p>
    <div id="x"></div>
    <script>
        document.body.addEventListener("click", handleBody_click);
        document.body.addEventListener("custom", handleBody_custom);

        document.getElementById("x").addEventListener("click", handleX_click);
    </script>
</body>
</html>
