3 <script src="../../http/tests/inspector/inspector-test.js"></script>
4 <script src="../../http/tests/inspector/elements-test.js"></script>
5 <script src="../../http/tests/inspector/debugger-test.js"></script>
8 function appendElement(parentId, childId)
10 var child = document.createElement("div");
12 document.getElementById(parentId).appendChild(child);
15 function modifyAttribute(elementId, name, value)
17 var element = document.getElementById(elementId);
18 element.setAttribute(name, value);
21 function modifyAttrNode(elementId, name, value)
23 var element = document.getElementById(elementId);
24 element.attributes[name].value = value;
27 function setAttrNode(elementId, name, value)
29 var element = document.getElementById(elementId);
30 var attr = document.createAttribute(name);
32 element.attributes.setNamedItem(attr);
35 function modifyStyleAttribute(elementId, name, value)
37 var element = document.getElementById(elementId);
38 element.style.setProperty(name, value);
41 function removeElement(elementId)
43 var element = document.getElementById(elementId);
44 element.parentNode.removeChild(element);
47 function setInnerHTML(elementId, html)
49 var element = document.getElementById(elementId);
50 element.innerHTML = html;
53 function breakDebugger()
60 WebInspector.showPanel("elements");
62 var pane = WebInspector.domBreakpointsSidebarPane;
64 InspectorTest.runDebuggerTestSuite([
65 function testInsertChild(next)
67 InspectorTest.addResult("Test that 'Subtree Modified' breakpoint is hit when appending a child.");
68 InspectorTest.nodeWithId("rootElement", step2);
73 pane._setBreakpoint(node, pane._breakpointTypes.SubtreeModified, true);
74 InspectorTest.addResult("Set 'Subtree Modified' DOM breakpoint on rootElement.");
75 InspectorTest.evaluateInPageWithTimeout("appendElement('rootElement', 'childElement')");
76 InspectorTest.addResult("Append childElement to rootElement.");
77 waitUntilPausedAndDumpStack(next);
81 function testInsertGrandchild(next)
83 InspectorTest.addResult("Test that 'Subtree Modified' breakpoint is hit when appending a grandchild.");
84 InspectorTest.evaluateInPageWithTimeout("appendElement('childElement', 'grandchildElement')");
85 InspectorTest.addResult("Append grandchildElement to childElement.");
86 waitUntilPausedAndDumpStack(next);
89 function testRemoveChild(next)
91 InspectorTest.addResult("Test that 'Subtree Modified' breakpoint is hit when removing a child.");
92 InspectorTest.evaluateInPageWithTimeout("removeElement('grandchildElement')");
93 InspectorTest.addResult("Remove grandchildElement.");
94 waitUntilPausedAndDumpStack(next);
97 function testInnerHTML(next)
99 InspectorTest.addResult("Test that 'Subtree Modified' breakpoint is hit exactly once when setting innerHTML.");
100 InspectorTest.evaluateInPageWithTimeout("setInnerHTML('childElement', '<br><br>')");
101 InspectorTest.addResult("Set childElement.innerHTML.");
102 waitUntilPausedAndDumpStack(step2);
106 InspectorTest.waitUntilPaused(step3);
107 InspectorTest.evaluateInPageWithTimeout("breakDebugger()");
108 InspectorTest.addResult("Call breakDebugger, expect it to show up in next stack trace.");
111 function step3(frames)
113 InspectorTest.captureStackTrace(frames);
114 pane._removeBreakpoint(rootElement, pane._breakpointTypes.SubtreeModified);
115 InspectorTest.resumeExecution(next);
119 function testModifyAttribute(next)
121 InspectorTest.addResult("Test that 'Attribute Modified' breakpoint is hit when modifying attribute.");
122 pane._setBreakpoint(rootElement, pane._breakpointTypes.AttributeModified, true);
123 InspectorTest.addResult("Set 'Attribute Modified' DOM breakpoint on rootElement.");
124 InspectorTest.evaluateInPageWithTimeout("modifyAttribute('rootElement', 'data-test', 'foo')");
125 InspectorTest.addResult("Modify rootElement data-test attribute.");
126 waitUntilPausedAndDumpStack(step2);
128 function step2(callFrames)
130 pane._removeBreakpoint(rootElement, pane._breakpointTypes.AttributeModified);
135 function testModifyAttrNode(next)
137 InspectorTest.addResult("Test that 'Attribute Modified' breakpoint is hit when modifying Attr node.");
138 pane._setBreakpoint(rootElement, pane._breakpointTypes.AttributeModified, true);
139 InspectorTest.addResult("Set 'Attribute Modified' DOM breakpoint on rootElement.");
140 InspectorTest.evaluateInPageWithTimeout("modifyAttrNode('rootElement', 'data-test', 'bar')");
141 InspectorTest.addResult("Modify rootElement data-test attribute.");
142 waitUntilPausedAndDumpStack(step2);
144 function step2(callFrames)
146 pane._removeBreakpoint(rootElement, pane._breakpointTypes.AttributeModified);
151 function testSetAttrNode(next)
153 InspectorTest.addResult("Test that 'Attribute Modified' breakpoint is hit when adding a new Attr node.");
154 pane._setBreakpoint(rootElement, pane._breakpointTypes.AttributeModified, true);
155 InspectorTest.addResult("Set 'Attribute Modified' DOM breakpoint on rootElement.");
156 InspectorTest.evaluateInPageWithTimeout("setAttrNode('rootElement', 'data-foo', 'bar')");
157 InspectorTest.addResult("Modify rootElement data-foo attribute.");
158 waitUntilPausedAndDumpStack(step2);
160 function step2(callFrames)
162 pane._removeBreakpoint(rootElement, pane._breakpointTypes.AttributeModified);
167 function testModifyStyleAttribute(next)
169 InspectorTest.addResult("Test that 'Attribute Modified' breakpoint is hit when modifying style attribute.");
170 pane._setBreakpoint(rootElement, pane._breakpointTypes.AttributeModified, true);
171 InspectorTest.addResult("Set 'Attribute Modified' DOM breakpoint on rootElement.");
172 InspectorTest.evaluateInPageWithTimeout("modifyStyleAttribute('rootElement', 'color', 'green')");
173 InspectorTest.addResult("Modify rootElement style.color attribute.");
174 waitUntilPausedAndDumpStack(step2);
176 function step2(callFrames)
178 pane._removeBreakpoint(rootElement, pane._breakpointTypes.AttributeModified);
183 function testRemoveNode(next)
185 InspectorTest.addResult("Test that 'Node Removed' breakpoint is hit when removing a node.");
186 InspectorTest.nodeWithId("elementToRemove", step2);
190 pane._setBreakpoint(node, pane._breakpointTypes.NodeRemoved, true);
191 InspectorTest.addResult("Set 'Node Removed' DOM breakpoint on elementToRemove.");
192 InspectorTest.evaluateInPageWithTimeout("removeElement('elementToRemove')");
193 InspectorTest.addResult("Remove elementToRemove.");
194 waitUntilPausedAndDumpStack(next);
198 function testReload(next)
200 InspectorTest.addResult("Test that DOM breakpoints are persisted between page reloads.");
201 InspectorTest.nodeWithId("rootElement", step2);
205 pane._setBreakpoint(node, pane._breakpointTypes.SubtreeModified, true);
206 pane._saveBreakpoints();
207 InspectorTest.addResult("Set 'Subtree Modified' DOM breakpoint on rootElement.");
208 InspectorTest.reloadPage(step3);
213 InspectorTest.expandElementsTree(step4);
218 InspectorTest.evaluateInPageWithTimeout("appendElement('rootElement', 'childElement')");
219 InspectorTest.addResult("Append childElement to rootElement.");
220 waitUntilPausedAndDumpStack(next);
225 function waitUntilPausedAndDumpStack(callback)
227 InspectorTest.waitUntilPaused(paused);
228 InspectorTest.addSniffer(WebInspector.CallStackSidebarPane.prototype, "setStatus", setStatus);
233 function setStatus(status)
235 if (typeof status === "string")
238 caption = status.textContent;
243 function paused(frames)
246 if (typeof caption === "string")
252 InspectorTest.captureStackTrace(callFrames);
253 InspectorTest.addResult(caption);
254 InspectorTest.runAfterPendingDispatches(step2);
259 InspectorTest.resumeExecution(InspectorTest.safeWrap(callback));
267 <body onload="runTest()">
269 Tests DOM breakpoints. <a href="https://bugs.webkit.org/show_bug.cgi?id=42886">Bug 42886</a>
272 <div id="rootElement" style="color: red">
273 <div id="elementToRemove"></div>