TestPage.registerInitializer(function() {

InspectorTest.startTracingBreakpoints = function()
{
    if (!WI.debuggerManager)
        return;

    WI.debuggerManager.addEventListener(WI.DebuggerManager.Event.BreakpointAdded, function(event) {
        InspectorTest.log("Breakpoint was added.");
    });

    WI.debuggerManager.addEventListener(WI.DebuggerManager.Event.BreakpointRemoved, function(event) {
        InspectorTest.log("Breakpoint was removed.");
    });

    WI.JavaScriptBreakpoint.addEventListener(WI.Breakpoint.Event.DisabledStateDidChange, function(event) {
        var breakpoint = event.target;
        console.assert(breakpoint instanceof WI.JavaScriptBreakpoint, "Unexpected object type!");

        InspectorTest.log("Breakpoint disabled state changed: " + breakpoint.disabled);
    });

    WI.JavaScriptBreakpoint.addEventListener(WI.JavaScriptBreakpoint.Event.ResolvedStateDidChange, function(event) {
        var breakpoint = event.target;
        console.assert(breakpoint instanceof WI.JavaScriptBreakpoint, "Unexpected object type!");

        InspectorTest.log("Breakpoint resolved state changed: " + breakpoint.resolved);
    });

    WI.JavaScriptBreakpoint.addEventListener(WI.Breakpoint.Event.AutoContinueDidChange, function(event) {
        var breakpoint = event.target;
        console.assert(breakpoint instanceof WI.JavaScriptBreakpoint, "Unexpected object type!");

        InspectorTest.log("Breakpoint autocontinue state changed: " + breakpoint.autoContinue);
    });

    WI.JavaScriptBreakpoint.addEventListener(WI.Breakpoint.Event.ConditionDidChange, function(event) {
        var breakpoint = event.target;
        console.assert(breakpoint instanceof WI.JavaScriptBreakpoint, "Unexpected object type!");

        InspectorTest.log("Breakpoint condition changed: " + breakpoint.condition);
    });

    WI.JavaScriptBreakpoint.addEventListener(WI.Breakpoint.Event.ActionsDidChange, function(event) {
        var breakpoint = event.target;
        console.assert(breakpoint instanceof WI.JavaScriptBreakpoint, "Unexpected object type!");

        InspectorTest.log("Breakpoint actions changed. New count: " + breakpoint.actions.length);
    });
}

InspectorTest.startTracingProbes = function()
{
    if (!WI.debuggerManager)
        return;

    WI.debuggerManager.addEventListener(WI.DebuggerManager.Event.ProbeSetAdded, function(event) {
        var probeSet = event.data.probeSet;
        console.assert(probeSet instanceof WI.ProbeSet, "Unexpected object type!");

        InspectorTest.log("Probe set was added. New count: " + WI.debuggerManager.probeSets.length);
    });

    WI.debuggerManager.addEventListener(WI.DebuggerManager.Event.ProbeSetRemoved, function(event) {
        var probeSet = event.data.probeSet;
        console.assert(probeSet instanceof WI.ProbeSet, "Unexpected object type!");

        InspectorTest.log("Probe set was removed. New count: " + WI.debuggerManager.probeSets.length);
    });

    WI.Probe.addEventListener(WI.Probe.Event.ExpressionChanged, function(event) {
        var probe = event.target;
        console.assert(probe instanceof WI.Probe, "Unexpected object type!");

        InspectorTest.log("Probe with identifier " + probe.id + " changed expression: " + probe.expression);
    });

    WI.Probe.addEventListener(WI.Probe.Event.SampleAdded, function(event) {
        var probe = event.target;
        var sample = event.data;
        console.assert(probe instanceof WI.Probe, "Unexpected object type!");
        console.assert(sample instanceof WI.ProbeSample, "Unexpected object type!");

        InspectorTest.log("Probe with identifier " + probe.id + " added sample: " + sample);
    });

    WI.Probe.addEventListener(WI.Probe.Event.SamplesCleared, function(event) {
        var probe = event.target;
        console.assert(probe instanceof WI.Probe, "Unexpected object type!");

        InspectorTest.log("Probe with identifier " + probe.id + " cleared all samples.");
    });

    WI.ProbeSet.addEventListener(WI.ProbeSet.Event.ProbeAdded, function(event) {
        var probe = event.data;
        var probeSet = event.target;
        console.assert(probe instanceof WI.Probe, "Unexpected object type!");
        console.assert(probeSet instanceof WI.ProbeSet, "Unexpected object type!");

        InspectorTest.log("Probe with identifier " + probe.id + " was added to probe set.");
        InspectorTest.log("Probe set's probe count: " + probeSet.probes.length);
    });

    WI.ProbeSet.addEventListener(WI.ProbeSet.Event.ProbeRemoved, function(event) {
        var probe = event.data;
        var probeSet = event.target;
        console.assert(probe instanceof WI.Probe, "Unexpected object type!");
        console.assert(probeSet instanceof WI.ProbeSet, "Unexpected object type!");

        InspectorTest.log("Probe with identifier " + probe.id + " was removed from probe set.");
        InspectorTest.log("Probe set's probe count: " + probeSet.probes.length);
    });
}

});
