<!doctype html>
<html>
<head>
<meta http-equiv="Content-Security-Policy" content="script-src 'self' 'unsafe-inline'">
<script src="../../http/tests/inspector/resources/inspector-test.js"></script>
<script src="./resources/timeline-helper.js"></script>
<script>
function installTimer()
{
    setTimeout(function() {
        callFunction(mul, add(1, 3), 3);
        hook();
    });
}

function add(a, b)
{
    TestPage.addResult("Calling add(): " + a + " + " + b);
    return a + b;
}

function mul(a, b)
{
    TestPage.addResult("Calling mul(): " + a + " * " + b);
    return a * b;
}

function test()
{
    // First, set up the breakpoint, start timeline capturing, and trigger execution of installTimer().
    WI.debuggerManager.addEventListener(WI.DebuggerManager.Event.ScriptAdded, function(event) {
        var scriptObject = event.data.script;

        if (!/timeline-helper\.js$/.test(scriptObject.url))
            return;

        var location = scriptObject.createSourceCodeLocation(17, 0);  // Inside timeline-helper.js:hook()
        var breakpoint = new WI.Breakpoint(location);
        WI.debuggerManager.addBreakpoint(breakpoint);
        InspectorTest.addResult("Added a breakpoint inside hook().")

        WI.timelineManager.startCapturing();
        InspectorTest.evaluateInPage("installTimer()");
    });

    // Second, the debugger will pause during timeline capturing. Resume, then stop timeline capturing.
    WI.debuggerManager.addEventListener(WI.DebuggerManager.Event.Paused, function(event) {
        InspectorTest.addResult("Debugger paused;");
        checkIfExceptionLoopsForever();
    });

    function checkIfExceptionLoopsForever() {
        WI.runtimeManager.evaluateInInspectedWindow("({}).x.x", {objectGroup: "test", includeCommandLineAPI: true, doNotPauseOnExceptionsAndMuteConsole: true}, function(result, wasThrown) {
            InspectorTest.addResult("An exception was " + (wasThrown ? "" : "not ") + "thrown from the injected script.");
            WI.debuggerManager.resume().then(function() {
                InspectorTest.addResult("Debugger resumed; stopping timeline capture.");
                WI.timelineManager.stopCapturing();
            });
        });
    }

    // When timeline capturing stops, inspect the resulting timeline records for a profile.
    WI.timelineManager.addEventListener(WI.TimelineManager.Event.CapturingStateChanged, (event) => {
        if (WI.timelineManager.capturingState !== WI.TimelineManager.CapturingState.Inactive)
            return;

        var recording = WI.timelineManager.activeRecording;
        var scriptTimeline = recording.timelines.get(WI.TimelineRecord.Type.Script);
        console.assert(scriptTimeline);

        InspectorTest.addResult("Timeline capturing stopped. Inspecting the active recording....");

        for (var record of scriptTimeline.records) {
            if (record.eventType !== WI.ScriptTimelineRecord.EventType.TimerFired)
                continue;

            var result = record.profile ? "TRUE" : "FALSE";
            InspectorTest.addResult("TimerFired timeline record has profile attached: " + result);
        }

        InspectorTest.completeTest();
    });

    InspectorTest.reloadPage();
}
</script>
</head>
<body onload="runTest()">
    <p>Testing that an injected script, run while the debugger is paused and the timeline profiler is enabled, should not loop forever if it has an exception thrown.</p>
</body>
</html>
