1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
|
<html>
<head>
<style>
#modifyRule {
box-sizing: border-box;
}
#modifyRule {
height: 100%;
}
#modifyRule {
width: 100%;
}
</style>
<style>
#insertRule {
box-sizing: border-box;
}
#insertRule {
width: 100%;
}
</style>
<style>
#removeRule {
box-sizing: border-box;
}
#removeRule {
width: 100%;
}
</style>
<script type="text/javascript" src="../../http/tests/inspector-protocol/inspector-protocol-test.js"></script>
<script type="text/javascript" src="../../http/tests/inspector-protocol/css-protocol-test.js"></script>
<script type="text/javascript" src="../../http/tests/inspector-protocol/dom-protocol-test.js"></script>
<script type="text/javascript">
function test()
{
var documentNodeId;
InspectorTest.requestDocumentNodeId(onDocumentNodeId);
function onDocumentNodeId(nodeId)
{
documentNodeId = nodeId;
InspectorTest.sendCommandOrDie("CSS.enable", {}, function() {
InspectorTest.runTestSuite(testSuite);
});
}
var testSuite = [
function testModifyRule(next)
{
InspectorTest.log("--------------");
InspectorTest.log("Original rule:");
InspectorTest.loadAndDumpMatchingRules(documentNodeId, "#modifyRule", step1, true);
function step1()
{
InspectorTest.evaluateInPage("document.styleSheets[0].rules[0].style.setProperty('color', 'red')");
InspectorTest.log("--------------");
InspectorTest.log("Modified rule 1:");
InspectorTest.loadAndDumpMatchingRules(documentNodeId, "#modifyRule", step2, true);
}
function step2()
{
InspectorTest.evaluateInPage("document.styleSheets[0].rules[2].style.setProperty('color', 'blue')");
InspectorTest.log("---------------");
InspectorTest.log("Modified rule 3:");
InspectorTest.loadAndDumpMatchingRules(documentNodeId, "#modifyRule", step3, true);
}
function step3()
{
InspectorTest.evaluateInPage("document.styleSheets[0].rules[1].style.setProperty('color', 'green')");
InspectorTest.log("---------------");
InspectorTest.log("Modified rule 2:");
InspectorTest.loadAndDumpMatchingRules(documentNodeId, "#modifyRule", step4, true);
}
function step4()
{
InspectorTest.evaluateInPage("document.styleSheets[0].rules[1].style.removeProperty('color')");
InspectorTest.log("---------------");
InspectorTest.log("Restored rule 2:");
InspectorTest.loadAndDumpMatchingRules(documentNodeId, "#modifyRule", step5, true);
}
function step5()
{
InspectorTest.evaluateInPage("document.styleSheets[0].rules[0].style.removeProperty('color')");
InspectorTest.evaluateInPage("document.styleSheets[0].rules[2].style.removeProperty('color')");
InspectorTest.log("-----------------");
InspectorTest.log("Restored rule 1,3:");
InspectorTest.loadAndDumpMatchingRules(documentNodeId, "#modifyRule", next, true);
}
},
function testInsertFirstRule(next)
{
testInsertRule(0, next)
},
function testInsertMiddleRule(next)
{
testInsertRule(1, next)
},
function testInsertLastRule(next)
{
testInsertRule(2, next)
},
function testRemoveRule(next)
{
InspectorTest.log("Original rule:");
InspectorTest.loadAndDumpMatchingRules(documentNodeId, "#removeRule", step1, true);
function step1()
{
InspectorTest.evaluateInPage("document.styleSheets[2].removeRule(0)");
InspectorTest.log("-------------------");
InspectorTest.log("After remove rule 1:");
InspectorTest.loadAndDumpMatchingRules(documentNodeId, "#removeRule", step2, true);
}
function step2()
{
InspectorTest.evaluateInPage("document.styleSheets[2].removeRule(0)");
InspectorTest.log("-------------------");
InspectorTest.log("After remove rule 2:");
InspectorTest.loadAndDumpMatchingRules(documentNodeId, "#removeRule", next, true);
}
}
];
function testInsertRule(index, next)
{
InspectorTest.log("Original rule:");
InspectorTest.loadAndDumpMatchingRules(documentNodeId, "#insertRule", step1, true);
function step1()
{
InspectorTest.evaluateInPage("document.styleSheets[1].insertRule('#insertRule { color: red }', " + index + ")");
InspectorTest.log("--------------");
InspectorTest.log("After inserted rule:");
InspectorTest.loadAndDumpMatchingRules(documentNodeId, "#insertRule", step2, true);
}
function step2()
{
InspectorTest.evaluateInPage("document.styleSheets[1].removeRule(" + index + ")");
InspectorTest.log("--------------");
InspectorTest.log("Restored rule:");
InspectorTest.loadAndDumpMatchingRules(documentNodeId, "#insertRule", next, true);
}
}
}
</script>
</head>
<body onload="runTest();">
<p>The test verifies CSS.getMatchedStylesForNode when used concurrently with the CSSOM modifications.</p>
<article id="modifyRule"></article>
<article id="insertRule"></article>
<article id="removeRule"></article>
</body>
</html>
|