Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / inspector / sources / debugger-breakpoints / dom-breakpoints.html
blob40de3d5174624c8c5f9d4203adc44b1de4e53806
1 <html>
2 <head>
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>
6 <script>
8 function appendElement(parentId, childId)
10 var child = document.createElement("div");
11 child.id = childId;
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);
31 attr.value = value;
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()
55 debugger;
58 function authorShadowRoot()
60 return document.getElementById("hostElement").shadowRoot;
63 function authorShadowElement(id)
65 return authorShadowRoot().getElementById(id);
68 function appendElementToAuthorShadowTree(parentId, childId)
70 var child = document.createElement("div");
71 child.id = childId;
72 authorShadowElement(parentId).appendChild(child);
75 function appendElementToOpenShadowRoot(childId)
77 var child = document.createElement("div");
78 child.id = childId;
79 authorShadowRoot().appendChild(child);
82 function test()
85 var pane = WebInspector.domBreakpointsSidebarPane;
86 var rootElement;
87 var outerElement;
88 var authorShadowRoot;
89 InspectorTest.runDebuggerTestSuite([
90 function testInsertChild(next)
92 InspectorTest.addResult("Test that 'Subtree Modified' breakpoint is hit when appending a child.");
93 InspectorTest.nodeWithId("rootElement", step2);
95 function step2(node)
97 rootElement = node;
98 pane._setBreakpoint(node, pane._breakpointTypes.SubtreeModified, true);
99 InspectorTest.addResult("Set 'Subtree Modified' DOM breakpoint on rootElement.");
100 InspectorTest.evaluateInPageWithTimeout("appendElement('rootElement', 'childElement')");
101 InspectorTest.addResult("Append childElement to rootElement.");
102 InspectorTest.waitUntilPausedAndDumpStackAndResume(next);
106 function testInsertGrandchild(next)
108 InspectorTest.addResult("Test that 'Subtree Modified' breakpoint is hit when appending a grandchild.");
109 InspectorTest.evaluateInPageWithTimeout("appendElement('childElement', 'grandchildElement')");
110 InspectorTest.addResult("Append grandchildElement to childElement.");
111 InspectorTest.waitUntilPausedAndDumpStackAndResume(next);
114 function testRemoveChild(next)
116 InspectorTest.addResult("Test that 'Subtree Modified' breakpoint is hit when removing a child.");
117 InspectorTest.evaluateInPageWithTimeout("removeElement('grandchildElement')");
118 InspectorTest.addResult("Remove grandchildElement.");
119 InspectorTest.waitUntilPausedAndDumpStackAndResume(next);
122 function testInnerHTML(next)
124 InspectorTest.addResult("Test that 'Subtree Modified' breakpoint is hit exactly once when setting innerHTML.");
125 InspectorTest.evaluateInPageWithTimeout("setInnerHTML('childElement', '<br><br>')");
126 InspectorTest.addResult("Set childElement.innerHTML.");
127 InspectorTest.waitUntilPausedAndDumpStackAndResume(step2);
129 function step2()
131 InspectorTest.waitUntilPaused(step3);
132 InspectorTest.evaluateInPageWithTimeout("breakDebugger()");
133 InspectorTest.addResult("Call breakDebugger, expect it to show up in next stack trace.");
136 function step3(frames)
138 InspectorTest.captureStackTrace(frames);
139 pane._removeBreakpoint(rootElement, pane._breakpointTypes.SubtreeModified);
140 InspectorTest.resumeExecution(next);
144 function testModifyAttribute(next)
146 InspectorTest.addResult("Test that 'Attribute Modified' breakpoint is hit when modifying attribute.");
147 pane._setBreakpoint(rootElement, pane._breakpointTypes.AttributeModified, true);
148 InspectorTest.addResult("Set 'Attribute Modified' DOM breakpoint on rootElement.");
149 InspectorTest.evaluateInPageWithTimeout("modifyAttribute('rootElement', 'data-test', 'foo')");
150 InspectorTest.addResult("Modify rootElement data-test attribute.");
151 InspectorTest.waitUntilPausedAndDumpStackAndResume(step2);
153 function step2(callFrames)
155 pane._removeBreakpoint(rootElement, pane._breakpointTypes.AttributeModified);
156 next();
160 function testModifyAttrNode(next)
162 InspectorTest.addResult("Test that 'Attribute Modified' breakpoint is hit when modifying Attr node.");
163 pane._setBreakpoint(rootElement, pane._breakpointTypes.AttributeModified, true);
164 InspectorTest.addResult("Set 'Attribute Modified' DOM breakpoint on rootElement.");
165 InspectorTest.evaluateInPageWithTimeout("modifyAttrNode('rootElement', 'data-test', 'bar')");
166 InspectorTest.addResult("Modify rootElement data-test attribute.");
167 InspectorTest.waitUntilPausedAndDumpStackAndResume(step2);
169 function step2(callFrames)
171 pane._removeBreakpoint(rootElement, pane._breakpointTypes.AttributeModified);
172 next();
176 function testSetAttrNode(next)
178 InspectorTest.addResult("Test that 'Attribute Modified' breakpoint is hit when adding a new Attr node.");
179 pane._setBreakpoint(rootElement, pane._breakpointTypes.AttributeModified, true);
180 InspectorTest.addResult("Set 'Attribute Modified' DOM breakpoint on rootElement.");
181 InspectorTest.evaluateInPageWithTimeout("setAttrNode('rootElement', 'data-foo', 'bar')");
182 InspectorTest.addResult("Modify rootElement data-foo attribute.");
183 InspectorTest.waitUntilPausedAndDumpStackAndResume(step2);
185 function step2(callFrames)
187 pane._removeBreakpoint(rootElement, pane._breakpointTypes.AttributeModified);
188 next();
192 function testModifyStyleAttribute(next)
194 InspectorTest.addResult("Test that 'Attribute Modified' breakpoint is hit when modifying style attribute.");
195 pane._setBreakpoint(rootElement, pane._breakpointTypes.AttributeModified, true);
196 InspectorTest.addResult("Set 'Attribute Modified' DOM breakpoint on rootElement.");
197 InspectorTest.evaluateInPageWithTimeout("modifyStyleAttribute('rootElement', 'color', 'green')");
198 InspectorTest.addResult("Modify rootElement style.color attribute.");
199 InspectorTest.waitUntilPausedAndDumpStackAndResume(step2);
201 function step2(callFrames)
203 pane._removeBreakpoint(rootElement, pane._breakpointTypes.AttributeModified);
204 next();
208 function testRemoveNode(next)
210 InspectorTest.addResult("Test that 'Node Removed' breakpoint is hit when removing a node.");
211 InspectorTest.nodeWithId("elementToRemove", step2);
213 function step2(node)
215 pane._setBreakpoint(node, pane._breakpointTypes.NodeRemoved, true);
216 InspectorTest.addResult("Set 'Node Removed' DOM breakpoint on elementToRemove.");
217 InspectorTest.evaluateInPageWithTimeout("removeElement('elementToRemove')");
218 InspectorTest.addResult("Remove elementToRemove.");
219 InspectorTest.waitUntilPausedAndDumpStackAndResume(next);
223 function testReload(next)
225 InspectorTest.addResult("Test that DOM breakpoints are persisted between page reloads.");
226 InspectorTest.nodeWithId("rootElement", step2);
228 function step2(node)
230 pane._setBreakpoint(node, pane._breakpointTypes.SubtreeModified, true);
231 pane._saveBreakpoints();
232 InspectorTest.addResult("Set 'Subtree Modified' DOM breakpoint on rootElement.");
233 InspectorTest.reloadPage(step3);
236 function step3()
238 InspectorTest.expandElementsTree(step4);
241 function step4()
243 InspectorTest.evaluateInPageWithTimeout("appendElement('rootElement', 'childElement')");
244 InspectorTest.addResult("Append childElement to rootElement.");
245 InspectorTest.waitUntilPausedAndDumpStackAndResume(next);
249 function testInsertChildIntoAuthorShadowTree(next)
251 InspectorTest.shadowRootByHostId("hostElement", callback);
253 function callback(node)
255 authorShadowRoot = node;
256 InspectorTest.addResult("Test that 'Subtree Modified' breakpoint on author shadow root is hit when appending a child.");
257 pane._setBreakpoint(authorShadowRoot, pane._breakpointTypes.SubtreeModified, true);
258 InspectorTest.addResult("Set 'Subtree Modified' DOM breakpoint on author shadow root.");
259 InspectorTest.evaluateInPageWithTimeout("appendElementToOpenShadowRoot('childElement')");
260 InspectorTest.addResult("Append childElement to author shadow root.");
261 InspectorTest.waitUntilPausedAndDumpStackAndResume(next);
265 function testReloadWithShadowElementBreakpoint(next)
267 InspectorTest.nodeWithId("outerElement", step1);
269 function step1(node)
271 outerElement = node;
273 InspectorTest.addResult("Test that shadow DOM breakpoints are persisted between page reloads.");
274 pane._setBreakpoint(outerElement, pane._breakpointTypes.SubtreeModified, true);
275 pane._saveBreakpoints();
276 InspectorTest.addResult("Set 'Subtree Modified' DOM breakpoint on outerElement.");
277 InspectorTest.reloadPage(step2);
280 function step2()
282 InspectorTest.expandElementsTree(step3);
285 function step3()
287 InspectorTest.evaluateInPageWithTimeout("appendElementToAuthorShadowTree('outerElement', 'childElement')");
288 InspectorTest.addResult("Append childElement to outerElement.");
289 InspectorTest.waitUntilPausedAndDumpStackAndResume(next);
296 </script>
297 </head>
299 <body onload="runTest()">
301 Tests DOM breakpoints. <a href="https://bugs.webkit.org/show_bug.cgi?id=42886">Bug 42886</a>
302 </p>
304 <div id="rootElement" style="color: red">
305 <div id="elementToRemove"></div>
306 </div>
308 <div id="hostElement"></div>
309 <script>
310 var root = document.getElementById("hostElement").createShadowRoot();
311 root.innerHTML = "<div id='outerElement' style='red'><input id='input'/></div>";
312 </script>
314 </body>
315 </html>