3 <script src=
"../../../http/tests/inspector/inspector-test.js"></script>
4 <script src=
"../../../http/tests/inspector/elements-test.js"></script>
12 border:
1px solid black;
23 function flattenRuleRanges(rule
)
26 var medias
= rule
.media
|| [];
27 for (var i
= 0; i
< medias
.length
; ++i
) {
28 var media
= medias
[i
];
36 for (var i
= 0; i
< rule
.selectors
.length
; ++i
) {
37 var selector
= rule
.selectors
[i
];
41 range
: selector
.range
,
42 name
: "selector #" + i
45 if (rule
.style
.range
) {
47 range
: rule
.style
.range
,
51 var properties
= rule
.style
.allProperties
;
52 for (var i
= 0; i
< properties
.length
; ++i
) {
53 var property
= properties
[i
];
57 range
: property
.range
,
58 name
: "property >>" + property
.text
+ "<<"
64 function compareRuleRanges(lazyRule
, originalRule
)
66 if (lazyRule
.selectorText
!== originalRule
.selectorText
) {
67 InspectorTest
.addResult("Error: rule selectors are not equal: " + lazyRule
.selectorText
+ " != " + originalRule
.selectorText
);
70 var flattenLazy
= flattenRuleRanges(lazyRule
);
71 var flattenOriginal
= flattenRuleRanges(originalRule
);
72 if (flattenLazy
.length
!== flattenOriginal
.length
) {
73 InspectorTest
.addResult("Error: rule range amount is not equal: " + flattenLazy
.length
+ " != " + flattenOriginal
.length
);
76 for (var i
= 0; i
< flattenLazy
.length
; ++i
) {
77 var lazyRange
= flattenLazy
[i
];
78 var originalRange
= flattenOriginal
[i
];
79 if (lazyRange
.name
!== originalRange
.name
) {
80 InspectorTest
.addResult("Error: rule names are not equal: " + lazyRange
.name
+ " != " + originalRange
.name
);
83 if (!lazyRange
.range
.equal(originalRange
.range
)) {
84 InspectorTest
.addResult("Error: ranges '" + lazyRange
.name
+ "' are not equal: " + lazyRange
.range
.toString() + " != " + originalRange
.range
.toString());
88 InspectorTest
.addResult(flattenLazy
.length
+ " rule ranges are equal.");
92 function validateRuleRanges(selector
, rules
, callback
)
94 InspectorTest
.selectNodeAndWaitForStyles("other", onOtherSelected
);
96 function onOtherSelected()
98 InspectorTest
.selectNodeAndWaitForStyles(selector
, onContainerSelected
);
101 function onContainerSelected()
103 var fetchedRules
= getMatchedRules();
104 if (fetchedRules
.length
!== rules
.length
) {
105 InspectorTest
.addResult(String
.sprintf("Error: rules sizes are not equal! Expected: %d, actual: %d", fetchedRules
.length
, rules
.length
));
106 InspectorTest
.completeTest();
109 for (var i
= 0; i
< fetchedRules
.length
; ++i
) {
110 if (!compareRuleRanges(rules
[i
], fetchedRules
[i
])) {
111 InspectorTest
.completeTest();
119 function getMatchedRules()
122 for (var block
of WebInspector
.panels
.elements
.sidebarPanes
.styles
._sectionBlocks
) {
123 for (var section
of block
.sections
) {
124 var rule
= section
.rule();
132 InspectorTest
.runTestSuite([
133 function selectInitialNode(next
)
135 InspectorTest
.selectNodeAndWaitForStyles("container", next
);
138 function testInsertProperty(next
)
140 InspectorTest
.dumpSelectedElementStyles(true, false, true);
141 var treeItem
= InspectorTest
.getMatchedStylePropertyTreeItem("color");
142 var treeElement
= treeItem
.section().addNewBlankProperty(1);
143 InspectorTest
.waitForStyleApplied(onPropertyInserted
);
144 treeElement
.applyStyleText("PROPERTY: INSERTED;", true);
146 function onPropertyInserted()
148 InspectorTest
.addResult("\n\n#### AFTER PROPERTY INSERTION ####\n\n");
149 InspectorTest
.dumpSelectedElementStyles(true, false, true);
150 var rules
= getMatchedRules();
151 validateRuleRanges("container", rules
, next
);
155 function testEditSelector(next
)
157 var section
= WebInspector
.panels
.elements
.sidebarPanes
.styles
._sectionBlocks
[0].sections
[3];
158 section
.startEditingSelector();
159 section
._selectorElement
.textContent
= ".should-change, .INSERTED-OTHER-SELECTOR";
160 InspectorTest
.waitForSelectorCommitted(onSelectorEdited
);
161 section
._selectorElement
.dispatchEvent(InspectorTest
.createKeyEvent("Enter"));
163 function onSelectorEdited()
165 InspectorTest
.addResult("\n\n#### AFTER SELECTOR EDIT ####\n\n");
166 InspectorTest
.dumpSelectedElementStyles(true, false, true);
167 var rules
= getMatchedRules();
168 validateRuleRanges("container", rules
, next
);
172 function testDisableProperty(next
)
174 var treeItem
= InspectorTest
.getMatchedStylePropertyTreeItem("border");
175 InspectorTest
.waitForStyleApplied(onPropertyDisabled
);
176 treeItem
._toggleEnabled({ target
: { checked
: false }, consume: function() { } });
178 function onPropertyDisabled()
180 InspectorTest
.addResult("\n\n#### AFTER PROPERTY DISABLED ####\n\n");
181 InspectorTest
.dumpSelectedElementStyles(true, false, true);
182 var rules
= getMatchedRules();
183 validateRuleRanges("container", rules
, next
);
187 function selectNodeWithPseudoElements(next
)
189 InspectorTest
.selectNodeAndWaitForStyles("pseudo", next
);
192 function testPseudoSectionPropertyEdit(next
)
194 var treeItem
= InspectorTest
.getMatchedStylePropertyTreeItem("pseudo-property");
195 var treeElement
= treeItem
.section().addNewBlankProperty(1);
196 InspectorTest
.waitForStyleApplied(onPropertyInserted
);
197 treeElement
.applyStyleText("PROPERTY: INSERTED;", true);
199 function onPropertyInserted()
201 InspectorTest
.addResult("\n\n#### AFTER PROPERTY INSERTED ####\n\n");
202 InspectorTest
.dumpSelectedElementStyles(true, false, true);
203 var rules
= getMatchedRules();
204 validateRuleRanges("pseudo", rules
, next
);
210 <link rel=
"stylesheet" href=
"../styles/resources/styles-update-links-2.css"></link>
211 <link rel=
"stylesheet" href=
"../styles/resources/styles-update-links.css"></link>
214 <body onload=
"runTest()">
216 Tests that removal of property following its disabling works.
219 <div id=
"container" class=
"left-intact should-change">
223 <div id=
"other"></div>
225 <section id=
"pseudo"></div>