DevTools: [SSP] update ranges for all section in sidebar pane

There is a bug due to which source ranges in inherited styles sections
and pseudo elements style sections are not updated on the front-end
as the editing happens. This patch fixes it.

BUG=430129
R=vsevik

Review URL: https://codereview.chromium.org/698113006

git-svn-id: svn://svn.chromium.org/blink/trunk@184861 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 4f84ed62
...@@ -368,11 +368,17 @@ InspectorTest.getElementStylePropertyTreeItem = function(propertyName) ...@@ -368,11 +368,17 @@ InspectorTest.getElementStylePropertyTreeItem = function(propertyName)
// FIXME: this returns the first tree item found (may fail for same-named properties in a style). // FIXME: this returns the first tree item found (may fail for same-named properties in a style).
InspectorTest.getMatchedStylePropertyTreeItem = function(propertyName) InspectorTest.getMatchedStylePropertyTreeItem = function(propertyName)
{ {
var styleSections = WebInspector.panels.elements.sidebarPanes.styles.sections[0]; var sections = WebInspector.panels.elements.sidebarPanes.styles.sections;
for (var i = 1; i < styleSections.length; ++i) { for (var pseudoId in sections) {
var treeItem = InspectorTest.getFirstPropertyTreeItemForSection(styleSections[i], propertyName); var styleSections = sections[pseudoId];
if (treeItem) for (var i = 0; i < styleSections.length; ++i) {
return treeItem; var section = styleSections[i];
if (section.computedStyle)
continue;
var treeItem = InspectorTest.getFirstPropertyTreeItemForSection(section, propertyName);
if (treeItem)
return treeItem;
}
} }
return null; return null;
}; };
......
Tests that removal of property following its disabling works. Tests that removal of property following its disabling works.
Red text here. Red text here.
Running: selectInitialNode
Running: testInsertProperty
[expanded] [expanded]
element.style { () element.style { ()
...@@ -92,6 +96,8 @@ display: block; ...@@ -92,6 +96,8 @@ display: block;
3 rule ranges are equal. 3 rule ranges are equal.
0 rule ranges are equal. 0 rule ranges are equal.
Running: testEditSelector
#### AFTER SELECTOR EDIT #### #### AFTER SELECTOR EDIT ####
...@@ -144,6 +150,8 @@ display: block; ...@@ -144,6 +150,8 @@ display: block;
3 rule ranges are equal. 3 rule ranges are equal.
0 rule ranges are equal. 0 rule ranges are equal.
Running: testDisableProperty
#### AFTER PROPERTY DISABLED #### #### AFTER PROPERTY DISABLED ####
...@@ -196,3 +204,42 @@ display: block; ...@@ -196,3 +204,42 @@ display: block;
3 rule ranges are equal. 3 rule ranges are equal.
0 rule ranges are equal. 0 rule ranges are equal.
Running: selectNodeWithPseudoElements
Running: testPseudoSectionPropertyEdit
#### AFTER PROPERTY INSERTED ####
[expanded]
element.style { ()
[expanded]
article, aside, footer, header, hgroup, main, nav, section { (user agent stylesheet)
display: block;
======== Pseudo ::before element ========
[expanded]
#pseudo::before { (styles-update-links.html:213 -> styles-update-links.html:213:1)
color: blue;
======== Pseudo ::after element ========
[expanded]
#pseudo::after { (styles-update-links.html:209 -> styles-update-links.html:209:1)
border: 1px solid black;
[expanded]
#pseudo::after { (styles-update-links.html:203 -> styles-update-links.html:203:1)
/-- overloaded --/ pseudo-property: "12";
/-- overloaded --/ PROPERTY: INSERTED;
color: red;
0 rule ranges are equal.
3 rule ranges are equal.
3 rule ranges are equal.
5 rule ranges are equal.
...@@ -75,20 +75,20 @@ function test() ...@@ -75,20 +75,20 @@ function test()
return true; return true;
} }
function validateRuleRanges(rules, callback) function validateRuleRanges(selector, rules, callback)
{ {
InspectorTest.selectNodeAndWaitForStyles("other", onOtherSelected); InspectorTest.selectNodeAndWaitForStyles("other", onOtherSelected);
function onOtherSelected() function onOtherSelected()
{ {
InspectorTest.selectNodeAndWaitForStyles("container", onContainerSelected); InspectorTest.selectNodeAndWaitForStyles(selector, onContainerSelected);
} }
function onContainerSelected() function onContainerSelected()
{ {
var fetchedRules = getMatchedRules(); var fetchedRules = getMatchedRules();
if (fetchedRules.length !== rules.length) { if (fetchedRules.length !== rules.length) {
InspectorTest.addResult("Error: rules sizes are not equal!"); InspectorTest.addResult(String.sprintf("Error: rules sizes are not equal! Expected: %d, actual: %d", fetchedRules.length, rules.length));
InspectorTest.completeTest(); InspectorTest.completeTest();
return; return;
} }
...@@ -104,70 +104,115 @@ function test() ...@@ -104,70 +104,115 @@ function test()
function getMatchedRules() function getMatchedRules()
{ {
var matchedStyleSections = WebInspector.panels.elements.sidebarPanes.styles.sections[0];
var rules = []; var rules = [];
for (var i = 1; i < matchedStyleSections.length; ++i) { for (var pseudoId in WebInspector.panels.elements.sidebarPanes.styles.sections) {
var rule = matchedStyleSections[i].rule; var matchedStyleSections = WebInspector.panels.elements.sidebarPanes.styles.sections[pseudoId];
if (rule) for (var i = 0; i < matchedStyleSections.length; ++i) {
rules.push(rule); var section = matchedStyleSections[i];
if (section.computedStyle)
continue;
var rule = section.rule;
if (rule)
rules.push(rule);
}
} }
return rules; return rules;
} }
function insertProperty() InspectorTest.runTestSuite([
{ function selectInitialNode(next)
InspectorTest.dumpSelectedElementStyles(true, false, true); {
var treeItem = InspectorTest.getMatchedStylePropertyTreeItem("color"); InspectorTest.selectNodeAndWaitForStyles("container", next);
var treeElement = treeItem.section().addNewBlankProperty(1); },
InspectorTest.waitForStyleApplied(onPropertyInserted);
treeElement.applyStyleText("PROPERTY: INSERTED;", true, true);
}
function onPropertyInserted()
{
InspectorTest.addResult("\n\n#### AFTER PROPERTY INSERTION ####\n\n");
InspectorTest.dumpSelectedElementStyles(true, false, true);
var rules = getMatchedRules();
validateRuleRanges(rules, editSelector);
}
function editSelector() function testInsertProperty(next)
{ {
var section = WebInspector.panels.elements.sidebarPanes.styles.sections[0][4]; InspectorTest.dumpSelectedElementStyles(true, false, true);
section.startEditingSelector(); var treeItem = InspectorTest.getMatchedStylePropertyTreeItem("color");
section._selectorElement.textContent = ".should-change, .INSERTED-OTHER-SELECTOR"; var treeElement = treeItem.section().addNewBlankProperty(1);
InspectorTest.waitForSelectorCommitted(onSelectorEdited); InspectorTest.waitForStyleApplied(onPropertyInserted);
section._selectorElement.dispatchEvent(InspectorTest.createKeyEvent("Enter")); treeElement.applyStyleText("PROPERTY: INSERTED;", true, true);
}
function onPropertyInserted()
{
InspectorTest.addResult("\n\n#### AFTER PROPERTY INSERTION ####\n\n");
InspectorTest.dumpSelectedElementStyles(true, false, true);
var rules = getMatchedRules();
validateRuleRanges("container", rules, next);
}
},
function onSelectorEdited() function testEditSelector(next)
{ {
InspectorTest.addResult("\n\n#### AFTER SELECTOR EDIT ####\n\n"); var section = WebInspector.panels.elements.sidebarPanes.styles.sections[0][4];
InspectorTest.dumpSelectedElementStyles(true, false, true); section.startEditingSelector();
var rules = getMatchedRules(); section._selectorElement.textContent = ".should-change, .INSERTED-OTHER-SELECTOR";
validateRuleRanges(rules, disableProperty); InspectorTest.waitForSelectorCommitted(onSelectorEdited);
} section._selectorElement.dispatchEvent(InspectorTest.createKeyEvent("Enter"));
function onSelectorEdited()
{
InspectorTest.addResult("\n\n#### AFTER SELECTOR EDIT ####\n\n");
InspectorTest.dumpSelectedElementStyles(true, false, true);
var rules = getMatchedRules();
validateRuleRanges("container", rules, next);
}
},
function disableProperty() function testDisableProperty(next)
{ {
var treeItem = InspectorTest.getMatchedStylePropertyTreeItem("border"); var treeItem = InspectorTest.getMatchedStylePropertyTreeItem("border");
InspectorTest.waitForStyleApplied(onPropertyDisabled); InspectorTest.waitForStyleApplied(onPropertyDisabled);
treeItem.toggleEnabled({ target: { checked: false }, consume: function() { } }); treeItem.toggleEnabled({ target: { checked: false }, consume: function() { } });
}
function onPropertyDisabled()
{
InspectorTest.addResult("\n\n#### AFTER PROPERTY DISABLED ####\n\n");
InspectorTest.dumpSelectedElementStyles(true, false, true);
var rules = getMatchedRules();
validateRuleRanges("container", rules, next);
}
},
function onPropertyDisabled() function selectNodeWithPseudoElements(next)
{ {
InspectorTest.addResult("\n\n#### AFTER PROPERTY DISABLED ####\n\n"); InspectorTest.selectNodeAndWaitForStyles("pseudo", next);
InspectorTest.dumpSelectedElementStyles(true, false, true); },
var rules = getMatchedRules();
validateRuleRanges(rules, InspectorTest.completeTest.bind(InspectorTest));
}
InspectorTest.selectNodeAndWaitForStyles("container", insertProperty); function testPseudoSectionPropertyEdit(next)
{
var treeItem = InspectorTest.getMatchedStylePropertyTreeItem("pseudo-property");
var treeElement = treeItem.section().addNewBlankProperty(1);
InspectorTest.waitForStyleApplied(onPropertyInserted);
treeElement.applyStyleText("PROPERTY: INSERTED;", true, true);
function onPropertyInserted()
{
InspectorTest.addResult("\n\n#### AFTER PROPERTY INSERTED ####\n\n");
InspectorTest.dumpSelectedElementStyles(true, false, true);
var rules = getMatchedRules();
validateRuleRanges("pseudo", rules, next);
}
},
]);
} }
</script> </script>
<link rel="stylesheet" href="resources/styles-update-links-2.css"></link> <link rel="stylesheet" href="resources/styles-update-links-2.css"></link>
<link rel="stylesheet" href="resources/styles-update-links.css"></link> <link rel="stylesheet" href="resources/styles-update-links.css"></link>
<style>
#pseudo::after {
pseudo-property: "12";
color: red;
}
#pseudo::after {
border: 1px solid black;
}
#pseudo::before {
color: blue;
}
</style>
</head> </head>
<body onload="runTest()"> <body onload="runTest()">
...@@ -181,5 +226,7 @@ Red text here. ...@@ -181,5 +226,7 @@ Red text here.
<div id="other"></div> <div id="other"></div>
<section id="pseudo"></div>
</body> </body>
</html> </html>
...@@ -266,9 +266,15 @@ WebInspector.StylesSidebarPane.prototype = { ...@@ -266,9 +266,15 @@ WebInspector.StylesSidebarPane.prototype = {
*/ */
_styleSheetRuleEdited: function(editedRule, oldRange, newRange) _styleSheetRuleEdited: function(editedRule, oldRange, newRange)
{ {
var styleRuleSections = this.sections[0]; for (var pseudoId in this.sections) {
for (var i = 1; i < styleRuleSections.length; ++i) var styleRuleSections = this.sections[pseudoId];
styleRuleSections[i]._styleSheetRuleEdited(editedRule, oldRange, newRange); for (var i = 0; i < styleRuleSections.length; ++i) {
var section = styleRuleSections[i];
if (section.computedStyle)
continue;
section._styleSheetRuleEdited(editedRule, oldRange, newRange);
}
}
}, },
/** /**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment