blob: 96de7807a50399e7e5c0a07373aa4a057e716d12 [file] [log] [blame]
<!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/dom-breakpoint-utilities.js"></script>
<script>
function testSubtreeModified() {
document.getElementById("subtree-modified-test").appendChild(document.createElement("div"));
}
function test()
{
let suite = InspectorTest.createAsyncSuite("DOMBreakpoint.SubtreeModified");
suite.addTestCase({
name: `DOMBreakpoint.SubtreeModified.Remove.BreakpointEnabled`,
description: "Check that debugger pauses for breakpoint type.",
async test() {
let node = await InspectorTest.DOMBreakpoint.awaitQuerySelector("#subtree-modified-test");
let breakpoint = await InspectorTest.DOMBreakpoint.createBreakpoint(node, WI.DOMBreakpoint.Type.SubtreeModified);
let paused = false;
let pausedListener = WI.debuggerManager.addEventListener(WI.DebuggerManager.Event.Paused, (event) => {
paused = true;
let targetData = WI.debuggerManager.dataForTarget(WI.debuggerManager.activeCallFrame.target);
InspectorTest.log("PAUSED:");
InspectorTest.expectEqual(targetData.pauseReason, WI.DebuggerManager.PauseReason.DOM, "Pause reason should be DOM.");
let pauseData = targetData.pauseData;
InspectorTest.expectEqual(pauseData.type, breakpoint.type, `Pause type should be '${breakpoint.type}'.`);
InspectorTest.expectEqual(pauseData.nodeId, breakpoint.domNode.id, "Pause nodeId should be expected value.");
InspectorTest.expectTrue(pauseData.insertion, "Should have 'insertion'.");
InspectorTest.assert(!("targetNodeId" in pauseData), "Should not have 'targetNodeId'.");
logActiveStackTrace();
WI.debuggerManager.resume();
});
await InspectorTest.evaluateInPage(`testSubtreeModified()`);
InspectorTest.assert(breakpoint.domNode === node, "Should have domNode.");
InspectorTest.assert(paused, "Should pause.");
WI.debuggerManager.removeEventListener(WI.DebuggerManager.Event.Paused, pausedListener);
},
teardown: InspectorTest.DOMBreakpoint.teardown,
});
suite.addTestCase({
name: `DOMBreakpoint.SubtreeModified.Remove.BreakpointDisabled`,
description: "Check that debugger does not pause for disabled breakpoint.",
async test() {
let paused = false;
let pausedListener = WI.debuggerManager.addEventListener(WI.DebuggerManager.Event.Paused, (event) => {
paused = true;
WI.debuggerManager.resume();
});
let node = await InspectorTest.DOMBreakpoint.awaitQuerySelector("#subtree-modified-test");
let breakpoint = await InspectorTest.DOMBreakpoint.createBreakpoint(node, WI.DOMBreakpoint.Type.SubtreeModified);
InspectorTest.log("Disabling breakpoint...");
breakpoint.disabled = true;
InspectorTest.assert(breakpoint.domNode === node, "Should have domNode.");
InspectorTest.log("Triggering breakpoint...");
await InspectorTest.evaluateInPage(`testSubtreeModified()`);
InspectorTest.assert(breakpoint.domNode === node, "Should have domNode.");
InspectorTest.expectFalse(paused, "Should not pause for disabled breakpoint.");
WI.debuggerManager.removeEventListener(WI.DebuggerManager.Event.Paused, pausedListener);
},
teardown: InspectorTest.DOMBreakpoint.teardown,
});
suite.addTestCase({
name: `DOMBreakpoint.SubtreeModified.Remove.DebuggerDisabled`,
description: "Check that debugger does not pause when the debugger is disabled.",
async test() {
let paused = false;
let pausedListener = WI.debuggerManager.addEventListener(WI.DebuggerManager.Event.Paused, (event) => {
paused = true;
WI.debuggerManager.resume();
});
let node = await InspectorTest.DOMBreakpoint.awaitQuerySelector("#subtree-modified-test");
let breakpoint = await InspectorTest.DOMBreakpoint.createBreakpoint(node, WI.DOMBreakpoint.Type.SubtreeModified);
InspectorTest.log("Disabling all breakpoints...");
await DebuggerAgent.setBreakpointsActive(false);
InspectorTest.log("Triggering breakpoint...");
await InspectorTest.evaluateInPage(`testSubtreeModified()`);
InspectorTest.assert(breakpoint.domNode === node, "Should have domNode.");
InspectorTest.log("Enabling all breakpoints...");
await DebuggerAgent.setBreakpointsActive(true);
InspectorTest.expectFalse(paused, "Should not pause when all breakpoints disabled.");
WI.debuggerManager.removeEventListener(WI.DebuggerManager.Event.Paused, pausedListener);
},
teardown: InspectorTest.DOMBreakpoint.teardown,
});
suite.addTestCase({
name: `DOMBreakpoint.SubtreeModified.Remove.RemoveBreakpoint`,
description: "Check that debugger does not pause for removed breakpoint.",
async test() {
let paused = false;
let pausedListener = WI.debuggerManager.addEventListener(WI.DebuggerManager.Event.Paused, (event) => {
paused = true;
WI.debuggerManager.resume();
});
let node = await InspectorTest.DOMBreakpoint.awaitQuerySelector("#subtree-modified-test");
let breakpoint = await InspectorTest.DOMBreakpoint.createBreakpoint(node, WI.DOMBreakpoint.Type.SubtreeModified);
InspectorTest.log("Removing breakpoint...");
WI.domDebuggerManager.removeDOMBreakpoint(breakpoint);
InspectorTest.assert(!breakpoint.domNode, "Should not have domNode.");
InspectorTest.log("Triggering breakpoint...");
await InspectorTest.evaluateInPage(`testSubtreeModified()`);
InspectorTest.assert(!breakpoint.domNode, "Should not have domNode.");
InspectorTest.expectFalse(paused, "Should not pause for removed breakpoint.");
WI.debuggerManager.removeEventListener(WI.DebuggerManager.Event.Paused, pausedListener);
},
teardown: InspectorTest.DOMBreakpoint.teardown,
});
InspectorTest.BreakpointOptions.addTestCases(suite, {
testCaseNamePrefix: "Remove.",
async createBreakpoint() {
let node = await InspectorTest.DOMBreakpoint.awaitQuerySelector("#subtree-modified-test");
return InspectorTest.DOMBreakpoint.createBreakpoint(node, WI.DOMBreakpoint.Type.SubtreeModified);
},
async triggerBreakpoint(breakpoint) {
InspectorTest.assert(breakpoint.domNode, "Should have domNode.");
return InspectorTest.evaluateInPage(`testSubtreeModified()`);
},
});
suite.runTestCasesAndFinish();
}
</script>
</head>
<body onload="runTest()">
<p>Tests for DOM breakpoints.</p>
<div id="test-container" style="display: none">
<div id="subtree-modified-test"></div>
</div>
</body>
</html>