summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/LayoutTests/inspector-protocol/css/css-add-rule.html
blob: a8735b5f977a454c026e471b4362cddf001c51f0 (plain)
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
177
178
179
180
<html>
<head>
<link rel="stylesheet" href="resources/add-rule.css"/>
<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 addRule;
    var verifyProtocolError;
    var dumpStyleSheet;
    var documentNodeId;

    InspectorTest.requestDocumentNodeId(onDocumentNodeId);

    function onDocumentNodeId(nodeId)
    {
        documentNodeId = nodeId;
        InspectorTest.eventHandler["CSS.styleSheetAdded"] = styleSheetAdded;
        InspectorTest.sendCommandOrDie("CSS.enable", {});
    }

    function styleSheetAdded(result)
    {
        var styleSheetId = result.params.header.styleSheetId;
        addRule = InspectorTest.addRule.bind(InspectorTest, styleSheetId, false);
        verifyProtocolError = InspectorTest.addRule.bind(InspectorTest, styleSheetId, true);
        dumpStyleSheet = InspectorTest.dumpStyleSheetText.bind(null, styleSheetId);
        InspectorTest.sendCommandOrDie("CSS.getStyleSheetText", { styleSheetId: styleSheetId }, onInitialStyleSheetText);
    }

    function dumpAndNext(next)
    {
        return InspectorTest.loadAndDumpMatchingRules.bind(InspectorTest, documentNodeId, "#test", InspectorTest.undoAndNext(next));
    }

    function onInitialStyleSheetText(result)
    {
        InspectorTest.log("==== Initial style sheet text ====");
        InspectorTest.log(result.text);
        InspectorTest.runTestSuite(testSuite);
    }

    var testSuite = [
        /* Tests that add rule into style sheet. */

        function testAddRuleToStyleSheetBeginning(next)
        {
            addRule({
                location: { startLine: 0, startColumn: 0, endLine: 0, endColumn: 0 },
                ruleText: "#test { content: 'EDITED'; }",
            }, dumpAndNext(next));
        },

        function testAddRuleToStyleSheetEnding(next)
        {
            addRule({
                location: { startLine: 20, startColumn: 0, endLine: 20, endColumn: 0 },
                ruleText: "#test { content: 'EDITED'; }",
            }, dumpAndNext(next));
        },

        function testAddRuleToStyleSheetCenter(next)
        {
            addRule({
                location: { startLine: 11, startColumn: 0, endLine: 11, endColumn: 0 },
                ruleText: "#test { content: 'EDITED'; }",
            }, dumpAndNext(next));
        },

        function testAddRuleToRuleEnding(next)
        {
            addRule({
                location: { startLine: 2, startColumn: 1, endLine: 2, endColumn: 1 },
                ruleText: "#test{\n    content: 'EDITED';\n}",
            }, dumpAndNext(next));
        },

        function testAddRuleWithFormatting(next)
        {
            addRule({
                location: { startLine: 2, startColumn: 1, endLine: 2, endColumn: 1 },
                ruleText: "\n\n#test{\n    content: 'EDITED';\n}",
            }, dumpAndNext(next));
        },

        /* Tests that add rule into MediaRule. */

        function testAddRuleToMediaRuleBeginning(next)
        {
            addRule({
                location: { startLine: 12, startColumn: 25, endLine: 12, endColumn: 25 },
                ruleText: "#test { content: 'EDITED'; }",
            }, dumpAndNext(next));
        },

        function testAddRuleToMediaRuleCenter(next)
        {
            addRule({
                location: { startLine: 16, startColumn: 0, endLine: 16, endColumn: 0 },
                ruleText: "#test { content: 'EDITED'; }",
            }, dumpAndNext(next));
        },

        function testAddRuleToMediaRuleEnd(next)
        {
            addRule({
                location: { startLine: 19, startColumn: 0, endLine: 19, endColumn: 0 },
                ruleText: "#test { content: 'EDITED'; }",
            }, dumpAndNext(next));
        },

        /* Tests that verify error reporting. */

        function testInvalidRule(next)
        {
            verifyProtocolError({
                location: { startLine: 0, startColumn: 0, endLine: 0, endColumn: 0 },
                ruleText: "#test { content: 'EDITED';",
            }, next);
        },

        function testAddingRuleInsideSelector(next)
        {
            verifyProtocolError({
                location: { startLine: 0, startColumn: 2, endLine: 0, endColumn: 2 },
                ruleText: "#test { content: 'EDITED'; }",
            }, next);
        },

        function testAddingRuleBeforeRuleBody(next)
        {
            verifyProtocolError({
                location: { startLine: 4, startColumn: 6, endLine: 4, endColumn: 6 },
                ruleText: "#test { content: 'EDITED'; }",
            }, next);
        },

        function testAddingRuleInsideMedia1(next)
        {
            verifyProtocolError({
                location: { startLine: 12, startColumn: 9, endLine: 12, endColumn: 9 },
                ruleText: "#test { content: 'EDITED'; }",
            }, next);
        },

        function testAddingRuleInsideMedia2(next)
        {
            verifyProtocolError({
                location: { startLine: 12, startColumn: 15, endLine: 12, endColumn: 15 },
                ruleText: "#test { content: 'EDITED'; }",
            }, next);
        },

        function testAddingRuleBeforeMediaBody(next)
        {
            verifyProtocolError({
                location: { startLine: 12, startColumn: 24, endLine: 12, endColumn: 24 },
                ruleText: "#test { content: 'EDITED'; }",
            }, next);
        },

        function testAddingRuleInsideStyleRule(next)
        {
            verifyProtocolError({
                location: { startLine: 18, startColumn: 0, endLine: 18, endColumn: 0 },
                ruleText: "#test { content: 'EDITED'; }",
            }, next);
        },
   ];
}

</script>
</head>
<body onload="runTest();">
<p>The test verifies functionality of protocol method CSS.addRule.</p>
<article id="test"></article>
</body>
</html>