14 content: "EmptyBefore";
18 content: "EmptyAfter";
21 <script src="../../../http/tests/inspector/inspector-test.js"></script>
22 <script src="../../../http/tests/inspector/elements-test.js"></script>
25 var initialize_PseudoElementsTest = function() {
27 InspectorTest.selectIdNodeWithId = function(idValue, pseudoType, callback)
29 callback = InspectorTest.safeWrap(callback);
30 function onNodeFound(node)
33 WebInspector._updateFocusedNode(node.id);
37 InspectorTest.findNode(nodeIdMatches, onNodeFound);
38 function nodeIdMatches(node)
40 return node.parentNode && node.pseudoType() === pseudoType && node.parentNode.getAttribute("id") === idValue;
44 InspectorTest.waitForPseudoIdNodeStyles = function(idValue, pseudoType, callback, requireRebuild)
46 callback = InspectorTest.safeWrap(callback);
48 (function sniff(node, rebuild)
50 if ((rebuild || !requireRebuild) && node && node.parentNode && node.pseudoType() === pseudoType && node.parentNode.getAttribute("id") === idValue) {
54 InspectorTest.addSniffer(WebInspector.StylesSidebarPane.prototype, "_nodeStylesUpdatedForTest", sniff);
58 InspectorTest.selectPseudoIdNodeAndWaitForStyles = function(idValue, pseudoType, callback)
60 WebInspector.showPanel("elements");
61 callback = InspectorTest.safeWrap(callback);
65 InspectorTest.waitForPseudoIdNodeStyles(idValue, pseudoType, stylesUpdated, true);
66 InspectorTest.selectIdNodeWithId(idValue, pseudoType, nodeSelected);
68 function nodeSelected(node)
73 function stylesUpdated()
81 function removeLastRule()
83 document.styleSheets[0].deleteRule(document.styleSheets[0].cssRules.length - 1);
86 function addAfterRule()
88 document.styleSheets[0].addRule("#inspected:after", "content: \"AFTER\"");
91 function addBeforeRule()
93 document.styleSheets[0].addRule("#inspected:before", "content: \"BEFORE\"");
96 function modifyTextContent()
98 document.getElementById("inspected").textContent = "bar";
101 function clearTextContent()
103 document.getElementById("inspected").textContent = "";
106 function removeNode()
108 document.getElementById("inspected").remove();
116 InspectorTest.runTestSuite([
117 function dumpOriginalTree(next)
119 InspectorTest.expandElementsTree(callback);
122 containerNode = InspectorTest.expandedNodeWithId("container");
123 inspectedNode = InspectorTest.expandedNodeWithId("inspected");
124 InspectorTest.addResult("Original elements tree:");
125 InspectorTest.dumpElementsTree(containerNode);
130 function dumpNormalNodeStyles(next)
132 selectNodeAndDumpStyles("inspected", "", next);
135 function dumpBeforeStyles(next)
137 selectNodeAndDumpStyles("inspected", "before", next);
140 function dumpAfterStyles(next)
142 selectNodeAndDumpStyles("inspected", "after", next);
145 function removeAfter(next)
147 executeAndDumpTree("removeLastRule()", WebInspector.DOMAgent.Events.NodeRemoved, next);
150 function removeBefore(next)
152 executeAndDumpTree("removeLastRule()", WebInspector.DOMAgent.Events.NodeRemoved, next);
155 function addAfter(next)
157 executeAndDumpTree("addAfterRule()", WebInspector.DOMAgent.Events.NodeInserted, next);
160 function addBefore(next)
162 executeAndDumpTree("addBeforeRule()", WebInspector.DOMAgent.Events.NodeInserted, next);
165 function modifyTextContent(next)
167 executeAndDumpTree("modifyTextContent()", WebInspector.DOMAgent.Events.NodeInserted, next);
170 function clearTextContent(next)
172 executeAndDumpTree("clearTextContent()", WebInspector.DOMAgent.Events.NodeRemoved, next);
175 function removeNodeAndCheckPseudoElementsUnbound(next)
177 var inspectedBefore = inspectedNode.pseudoElements()["before"];
178 var inspectedAfter = inspectedNode.pseudoElements()["after"];
180 executeAndDumpTree("removeNode()", WebInspector.DOMAgent.Events.NodeRemoved, callback);
183 InspectorTest.addResult("inspected:before DOMNode in DOMAgent: " + !!(WebInspector.domAgent.nodeForId(inspectedBefore.id)));
184 InspectorTest.addResult("inspected:after DOMNode in DOMAgent: " + !!(WebInspector.domAgent.nodeForId(inspectedAfter.id)));
190 function executeAndDumpTree(pageFunction, eventName, next)
192 WebInspector.domAgent.addEventListener(eventName, domCallback, this);
193 InspectorTest.evaluateInPage(pageFunction);
195 function domCallback()
197 WebInspector.domAgent.removeEventListener(eventName, domCallback, this);
198 WebInspector.panel("elements").treeOutline.addEventListener(WebInspector.ElementsTreeOutline.Events.ElementsTreeUpdated, treeCallback, this);
201 function treeCallback()
203 WebInspector.panel("elements").treeOutline.removeEventListener(WebInspector.ElementsTreeOutline.Events.ElementsTreeUpdated, treeCallback, this);
204 InspectorTest.dumpElementsTree(containerNode);
209 function selectNodeAndDumpStyles(id, pseudoTypeName, callback)
212 InspectorTest.selectPseudoIdNodeAndWaitForStyles("inspected", pseudoTypeName, stylesCallback);
214 InspectorTest.selectNodeAndWaitForStyles("inspected", stylesCallback);
216 function stylesCallback()
218 InspectorTest.dumpSelectedElementStyles(false, false, false, true);
227 <body onload="runTest()">
229 Tests that pseudo elements and their styles are handled properly.
233 <div id="inspected">Text</div>
234 <div id="empty"></div>