3 <link rel=
"stylesheet" href=
"resources/set-style-text.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 document
.styleSheets
[0].removeRule(0);
17 var verifyProtocolError
;
22 InspectorTest
.requestDocumentNodeId(onDocumentNodeId
);
24 function onDocumentNodeId(nodeId
)
26 documentNodeId
= nodeId
;
27 InspectorTest
.eventHandler
["CSS.styleSheetAdded"] = styleSheetAdded
;
28 InspectorTest
.sendCommandOrDie("CSS.enable", {});
31 function styleSheetAdded(result
)
33 styleSheetId
= result
.params
.header
.styleSheetId
;
34 setStyleText
= InspectorTest
.setStyleText
.bind(InspectorTest
, styleSheetId
, false);
35 verifyProtocolError
= InspectorTest
.setStyleText
.bind(InspectorTest
, styleSheetId
, true);
36 dumpStyleSheet
= InspectorTest
.dumpStyleSheetText
.bind(null, styleSheetId
);
37 InspectorTest
.sendCommandOrDie("CSS.getStyleSheetText", { styleSheetId
: styleSheetId
}, onInitialStyleSheetText
);
40 function dumpAndCall(next
)
42 return InspectorTest
.loadAndDumpMatchingRules
.bind(InspectorTest
, documentNodeId
, "#test", next
);
45 function dumpUndoAndNext(next
)
47 return InspectorTest
.loadAndDumpMatchingRules
.bind(InspectorTest
, documentNodeId
, "#test", InspectorTest
.undoAndNext(next
));
50 function onInitialStyleSheetText(result
)
52 InspectorTest
.log("==== Initial style sheet text ====");
53 InspectorTest
.log(result
.text
);
54 InspectorTest
.runTestSuite(testSuite
);
58 function testBasicSetStyle(next
)
61 styleSheetId
: styleSheetId
,
62 range
: { startLine
: 0, startColumn
: 7, endLine
: 2, endColumn
: 0 },
63 text
: "\n content: 'EDITED';\n",
64 }, dumpUndoAndNext(next
));
67 function testSetStyleTwice(next
)
70 styleSheetId
: styleSheetId
,
71 range
: { startLine
: 0, startColumn
: 7, endLine
: 2, endColumn
: 0 },
72 text
: "\n color: green;\n padding: 0 4px;\n cursor: pointer\n",
73 }, dumpAndCall(step2
));
78 styleSheetId
: styleSheetId
,
79 range
: { startLine
: 0, startColumn
: 7, endLine
: 4, endColumn
: 0 },
80 text
: "\n color: green;\n padding: 0 6px;\n cursor: pointer\n",
81 }, dumpAndCall(step3
));
87 styleSheetId
: styleSheetId
,
88 range
: { startLine
: 0, startColumn
: 7, endLine
: 4, endColumn
: 0 },
89 text
: "\n color: green;\n padding: 0 8px;\n cursor: pointer\n",
90 }, dumpUndoAndNext(next
));
94 function testSetStylePoorContent(next
)
97 styleSheetId
: styleSheetId
,
98 range
: { startLine
: 0, startColumn
: 7, endLine
: 2, endColumn
: 0 },
100 }, dumpUndoAndNext(next
));
103 function testSetStyleInMedia(next
)
106 styleSheetId
: styleSheetId
,
107 range
: { startLine
: 13, startColumn
: 11, endLine
: 15, endColumn
: 4 },
108 text
: "\n content: 'EDITED';\n color: red;\n /** foo */\n ",
109 }, dumpUndoAndNext(next
));
112 function testDeleteStyleBody(next
)
115 styleSheetId
: styleSheetId
,
116 range
: { startLine
: 13, startColumn
: 11, endLine
: 15, endColumn
: 4 },
118 }, dumpUndoAndNext(next
));
121 function testSetStylePoorRange(next
)
123 verifyProtocolError({
124 styleSheetId
: styleSheetId
,
125 range
: { startLine
: 11, startColumn
: 11, endLine
: 15, endColumn
: 4 },
126 text
: "\n content: 'EDITED';\n",
127 }, dumpUndoAndNext(next
));
130 function testSetStyleOpenComment(next
)
132 verifyProtocolError({
133 styleSheetId
: styleSheetId
,
134 range
: { startLine
: 13, startColumn
: 11, endLine
: 15, endColumn
: 4 },
135 text
: "\n content: 'EDITED'/* ;\n",
136 }, dumpUndoAndNext(next
));
139 function testSetStyleOfRemovedRule(next
)
141 InspectorTest
.sendCommandOrDie("Runtime.evaluate", {expression
: "removeRule()"}, mutateRule
);
142 function mutateRule()
145 styleSheetId
: styleSheetId
,
146 range
: { startLine
: 0, startColumn
: 7, endLine
: 2, endColumn
: 0 },
147 text
: "\n content: 'EDITED';\n",
148 }, dumpUndoAndNext(next
));
156 <body onload=
"runTest();">
157 <p>The test verifies functionality of protocol method CSS.setStyleText.
</p>
158 <article id=
"test"></article>