4 #inspected:before, .some-other-selector {
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)
32 WebInspector.Revealer.reveal(node);
36 InspectorTest.findNode(nodeIdMatches, onNodeFound);
37 function nodeIdMatches(node)
39 return node.parentNode && node.pseudoType() === pseudoType && node.parentNode.getAttribute("id") === idValue;
43 InspectorTest.waitForPseudoIdNodeStyles = function(idValue, pseudoType, callback, requireRebuild)
45 callback = InspectorTest.safeWrap(callback);
47 (function sniff(node, rebuild)
49 if ((rebuild || !requireRebuild) && node && node.parentNode && node.pseudoType() === pseudoType && node.parentNode.getAttribute("id") === idValue) {
53 InspectorTest.addSniffer(WebInspector.StylesSidebarPane.prototype, "_nodeStylesUpdatedForTest", sniff);
57 InspectorTest.selectPseudoIdNodeAndWaitForStyles = function(idValue, pseudoType, callback)
59 callback = InspectorTest.safeWrap(callback);
63 InspectorTest.waitForPseudoIdNodeStyles(idValue, pseudoType, stylesUpdated, true);
64 InspectorTest.selectIdNodeWithId(idValue, pseudoType, nodeSelected);
66 function nodeSelected(node)
71 function stylesUpdated()
79 function removeLastRule()
81 document.styleSheets[0].deleteRule(document.styleSheets[0].cssRules.length - 1);
84 function addAfterRule()
86 document.styleSheets[0].addRule("#inspected:after", "content: \"AFTER\"");
89 function addBeforeRule()
91 document.styleSheets[0].addRule("#inspected:before", "content: \"BEFORE\"");
94 function modifyTextContent()
96 document.getElementById("inspected").textContent = "bar";
99 function clearTextContent()
101 document.getElementById("inspected").textContent = "";
104 function removeNode()
106 document.getElementById("inspected").remove();
114 InspectorTest.runTestSuite([
115 function dumpOriginalTree(next)
117 InspectorTest.expandElementsTree(callback);
120 containerNode = InspectorTest.expandedNodeWithId("container");
121 inspectedNode = InspectorTest.expandedNodeWithId("inspected");
122 InspectorTest.addResult("Original elements tree:");
123 InspectorTest.dumpElementsTree(containerNode);
128 function dumpNormalNodeStyles(next)
130 selectNodeAndDumpStyles("inspected", "", next);
133 function dumpBeforeStyles(next)
135 selectNodeAndDumpStyles("inspected", "before", next);
138 function dumpAfterStyles(next)
140 selectNodeAndDumpStyles("inspected", "after", next);
143 function removeAfter(next)
145 executeAndDumpTree("removeLastRule()", WebInspector.DOMModel.Events.NodeRemoved, next);
148 function removeBefore(next)
150 executeAndDumpTree("removeLastRule()", WebInspector.DOMModel.Events.NodeRemoved, next);
153 function addAfter(next)
155 executeAndDumpTree("addAfterRule()", WebInspector.DOMModel.Events.NodeInserted, expandAndDumpTree.bind(this, next));
158 function addBefore(next)
160 executeAndDumpTree("addBeforeRule()", WebInspector.DOMModel.Events.NodeInserted, next);
163 function modifyTextContent(next)
165 executeAndDumpTree("modifyTextContent()", WebInspector.DOMModel.Events.NodeInserted, next);
168 function clearTextContent(next)
170 executeAndDumpTree("clearTextContent()", WebInspector.DOMModel.Events.NodeRemoved, next);
173 function removeNodeAndCheckPseudoElementsUnbound(next)
175 var inspectedBefore = inspectedNode.pseudoElements()["before"];
176 var inspectedAfter = inspectedNode.pseudoElements()["after"];
178 executeAndDumpTree("removeNode()", WebInspector.DOMModel.Events.NodeRemoved, callback);
181 InspectorTest.addResult("inspected:before DOMNode in DOMAgent: " + !!(WebInspector.domModel.nodeForId(inspectedBefore.id)));
182 InspectorTest.addResult("inspected:after DOMNode in DOMAgent: " + !!(WebInspector.domModel.nodeForId(inspectedAfter.id)));
188 function executeAndDumpTree(pageFunction, eventName, next)
190 WebInspector.domModel.addEventListener(eventName, domCallback, this);
191 InspectorTest.evaluateInPage(pageFunction);
193 function domCallback()
195 WebInspector.domModel.removeEventListener(eventName, domCallback, this);
196 InspectorTest.firstElementsTreeOutline().addEventListener(WebInspector.ElementsTreeOutline.Events.ElementsTreeUpdated, treeCallback, this);
199 function treeCallback()
201 InspectorTest.firstElementsTreeOutline().removeEventListener(WebInspector.ElementsTreeOutline.Events.ElementsTreeUpdated, treeCallback, this);
202 InspectorTest.dumpElementsTree(containerNode);
207 function expandAndDumpTree(next)
209 InspectorTest.addResult("== Expanding: ==");
210 InspectorTest.expandElementsTree(callback);
213 InspectorTest.dumpElementsTree(containerNode);
218 function selectNodeAndDumpStyles(id, pseudoTypeName, callback)
221 InspectorTest.selectPseudoIdNodeAndWaitForStyles("inspected", pseudoTypeName, stylesCallback);
223 InspectorTest.selectNodeAndWaitForStyles("inspected", stylesCallback);
225 function stylesCallback()
227 InspectorTest.dumpSelectedElementStyles(false, false, false, true);
236 <body onload="runTest()">
238 Tests that pseudo elements and their styles are handled properly.
242 <div id="inspected">Text</div>
243 <div id="empty"></div>