3 <link rel=
"stylesheet" href=
"resources/add-rule.css"/>
4 <script type=
"text/javascript" src=
"../../http/tests/inspector-protocol/inspector-protocol-test.js"></script>
5 <script type=
"text/javascript" src=
"../../http/tests/inspector-protocol/css-protocol-test.js"></script>
6 <script type=
"text/javascript" src=
"../../http/tests/inspector-protocol/dom-protocol-test.js"></script>
7 <script type=
"text/javascript">
11 var verifyProtocolError
;
15 InspectorTest
.requestDocumentNodeId(onDocumentNodeId
);
17 function onDocumentNodeId(nodeId
)
19 documentNodeId
= nodeId
;
20 InspectorTest
.eventHandler
["CSS.styleSheetAdded"] = styleSheetAdded
;
21 InspectorTest
.sendCommandOrDie("CSS.enable", {});
24 function styleSheetAdded(result
)
26 var styleSheetId
= result
.params
.header
.styleSheetId
;
27 addRule
= InspectorTest
.addRule
.bind(InspectorTest
, styleSheetId
, false);
28 verifyProtocolError
= InspectorTest
.addRule
.bind(InspectorTest
, styleSheetId
, true);
29 dumpStyleSheet
= InspectorTest
.dumpStyleSheetText
.bind(null, styleSheetId
);
30 InspectorTest
.sendCommandOrDie("CSS.getStyleSheetText", { styleSheetId
: styleSheetId
}, onInitialStyleSheetText
);
33 function dumpAndNext(next
)
35 return InspectorTest
.loadAndDumpMatchingRules
.bind(InspectorTest
, documentNodeId
, "#test", InspectorTest
.undoAndNext(next
));
38 function onInitialStyleSheetText(result
)
40 InspectorTest
.log("==== Initial style sheet text ====");
41 InspectorTest
.log(result
.text
);
42 InspectorTest
.runTestSuite(testSuite
);
46 /* Tests that add rule into style sheet. */
48 function testAddRuleToStyleSheetBeginning(next
)
51 location
: { startLine
: 0, startColumn
: 0, endLine
: 0, endColumn
: 0 },
52 ruleText
: "#test { content: 'EDITED'; }",
53 }, dumpAndNext(next
));
56 function testAddRuleToStyleSheetEnding(next
)
59 location
: { startLine
: 20, startColumn
: 0, endLine
: 20, endColumn
: 0 },
60 ruleText
: "#test { content: 'EDITED'; }",
61 }, dumpAndNext(next
));
64 function testAddRuleToStyleSheetCenter(next
)
67 location
: { startLine
: 11, startColumn
: 0, endLine
: 11, endColumn
: 0 },
68 ruleText
: "#test { content: 'EDITED'; }",
69 }, dumpAndNext(next
));
72 function testAddRuleToRuleEnding(next
)
75 location
: { startLine
: 2, startColumn
: 1, endLine
: 2, endColumn
: 1 },
76 ruleText
: "#test{\n content: 'EDITED';\n}",
77 }, dumpAndNext(next
));
80 function testAddRuleWithFormatting(next
)
83 location
: { startLine
: 2, startColumn
: 1, endLine
: 2, endColumn
: 1 },
84 ruleText
: "\n\n#test{\n content: 'EDITED';\n}",
85 }, dumpAndNext(next
));
88 /* Tests that add rule into MediaRule. */
90 function testAddRuleToMediaRuleBeginning(next
)
93 location
: { startLine
: 12, startColumn
: 25, endLine
: 12, endColumn
: 25 },
94 ruleText
: "#test { content: 'EDITED'; }",
95 }, dumpAndNext(next
));
98 function testAddRuleToMediaRuleCenter(next
)
101 location
: { startLine
: 16, startColumn
: 0, endLine
: 16, endColumn
: 0 },
102 ruleText
: "#test { content: 'EDITED'; }",
103 }, dumpAndNext(next
));
106 function testAddRuleToMediaRuleEnd(next
)
109 location
: { startLine
: 19, startColumn
: 0, endLine
: 19, endColumn
: 0 },
110 ruleText
: "#test { content: 'EDITED'; }",
111 }, dumpAndNext(next
));
114 /* Tests that verify error reporting. */
116 function testInvalidRule(next
)
118 verifyProtocolError({
119 location
: { startLine
: 0, startColumn
: 0, endLine
: 0, endColumn
: 0 },
120 ruleText
: "#test { content: 'EDITED';",
124 function testAddingRuleInsideSelector(next
)
126 verifyProtocolError({
127 location
: { startLine
: 0, startColumn
: 2, endLine
: 0, endColumn
: 2 },
128 ruleText
: "#test { content: 'EDITED'; }",
132 function testAddingRuleBeforeRuleBody(next
)
134 verifyProtocolError({
135 location
: { startLine
: 4, startColumn
: 6, endLine
: 4, endColumn
: 6 },
136 ruleText
: "#test { content: 'EDITED'; }",
140 function testAddingRuleInsideMedia1(next
)
142 verifyProtocolError({
143 location
: { startLine
: 12, startColumn
: 9, endLine
: 12, endColumn
: 9 },
144 ruleText
: "#test { content: 'EDITED'; }",
148 function testAddingRuleInsideMedia2(next
)
150 verifyProtocolError({
151 location
: { startLine
: 12, startColumn
: 15, endLine
: 12, endColumn
: 15 },
152 ruleText
: "#test { content: 'EDITED'; }",
156 function testAddingRuleBeforeMediaBody(next
)
158 verifyProtocolError({
159 location
: { startLine
: 12, startColumn
: 24, endLine
: 12, endColumn
: 24 },
160 ruleText
: "#test { content: 'EDITED'; }",
164 function testAddingRuleInsideStyleRule(next
)
166 verifyProtocolError({
167 location
: { startLine
: 18, startColumn
: 0, endLine
: 18, endColumn
: 0 },
168 ruleText
: "#test { content: 'EDITED'; }",
176 <body onload=
"runTest();">
177 <p>The test verifies functionality of protocol method CSS.addRule.
</p>
178 <article id=
"test"></article>