OLD | NEW |
(Empty) | |
| 1 <html> |
| 2 <head> |
| 3 <link rel="stylesheet" href="resources/add-rule.css"/> |
| 4 <script type="text/javascript" src="../../http/tests/inspector-protocol/inspecto
r-protocol-test.js"></script> |
| 5 <script type="text/javascript" src="css-protocol-test.js"></script> |
| 6 <script type="text/javascript"> |
| 7 function test() |
| 8 { |
| 9 var addRule; |
| 10 var verifyProtocolError; |
| 11 var dumpStyleSheet; |
| 12 var documentNodeId; |
| 13 |
| 14 InspectorTest.requestDocumentNodeId(onDocumentNodeId); |
| 15 |
| 16 function onDocumentNodeId(nodeId) |
| 17 { |
| 18 documentNodeId = nodeId; |
| 19 InspectorTest.eventHandler["CSS.styleSheetAdded"] = styleSheetAdded; |
| 20 InspectorTest.sendCommandOrDie("CSS.enable", {}); |
| 21 } |
| 22 |
| 23 function styleSheetAdded(result) |
| 24 { |
| 25 var styleSheetId = result.params.header.styleSheetId; |
| 26 addRule = InspectorTest.addRule.bind(InspectorTest, styleSheetId, false)
; |
| 27 verifyProtocolError = InspectorTest.addRule.bind(InspectorTest, styleShe
etId, true); |
| 28 dumpStyleSheet = InspectorTest.dumpStyleSheetText.bind(null, styleSheetI
d); |
| 29 InspectorTest.sendCommandOrDie("CSS.getStyleSheetText", { styleSheetId:
styleSheetId }, onInitialStyleSheetText); |
| 30 } |
| 31 |
| 32 function dumpAndNext(next) |
| 33 { |
| 34 return InspectorTest.loadAndDumpMatchingRules.bind(InspectorTest, docume
ntNodeId, "#test", InspectorTest.undoAndNext(next)); |
| 35 } |
| 36 |
| 37 function onInitialStyleSheetText(result) |
| 38 { |
| 39 InspectorTest.log("==== Initial style sheet text ===="); |
| 40 InspectorTest.log(result.text); |
| 41 InspectorTest.runTestSuite(testSuite); |
| 42 } |
| 43 |
| 44 var testSuite = [ |
| 45 /* Tests that add rule into style sheet. */ |
| 46 |
| 47 function testAddRuleToStyleSheetBeginning(next) |
| 48 { |
| 49 addRule({ |
| 50 location: { startLine: 0, startColumn: 0, endLine: 0, endColumn:
0 }, |
| 51 ruleText: "#test { content: 'EDITED'; }", |
| 52 }, dumpAndNext(next)); |
| 53 }, |
| 54 |
| 55 function testAddRuleToStyleSheetEnding(next) |
| 56 { |
| 57 addRule({ |
| 58 location: { startLine: 20, startColumn: 0, endLine: 20, endColum
n: 0 }, |
| 59 ruleText: "#test { content: 'EDITED'; }", |
| 60 }, dumpAndNext(next)); |
| 61 }, |
| 62 |
| 63 function testAddRuleToStyleSheetCenter(next) |
| 64 { |
| 65 addRule({ |
| 66 location: { startLine: 11, startColumn: 0, endLine: 11, endColum
n: 0 }, |
| 67 ruleText: "#test { content: 'EDITED'; }", |
| 68 }, dumpAndNext(next)); |
| 69 }, |
| 70 |
| 71 function testAddRuleToRuleEnding(next) |
| 72 { |
| 73 addRule({ |
| 74 location: { startLine: 2, startColumn: 1, endLine: 2, endColumn:
1 }, |
| 75 ruleText: "#test{\n content: 'EDITED';\n}", |
| 76 }, dumpAndNext(next)); |
| 77 }, |
| 78 |
| 79 function testAddRuleWithFormatting(next) |
| 80 { |
| 81 addRule({ |
| 82 location: { startLine: 2, startColumn: 1, endLine: 2, endColumn:
1 }, |
| 83 ruleText: "\n\n#test{\n content: 'EDITED';\n}", |
| 84 }, dumpAndNext(next)); |
| 85 }, |
| 86 |
| 87 /* Tests that add rule into MediaRule. */ |
| 88 |
| 89 function testAddRuleToMediaRuleBeginning(next) |
| 90 { |
| 91 addRule({ |
| 92 location: { startLine: 12, startColumn: 25, endLine: 12, endColu
mn: 25 }, |
| 93 ruleText: "#test { content: 'EDITED'; }", |
| 94 }, dumpAndNext(next)); |
| 95 }, |
| 96 |
| 97 function testAddRuleToMediaRuleCenter(next) |
| 98 { |
| 99 addRule({ |
| 100 location: { startLine: 16, startColumn: 0, endLine: 16, endColum
n: 0 }, |
| 101 ruleText: "#test { content: 'EDITED'; }", |
| 102 }, dumpAndNext(next)); |
| 103 }, |
| 104 |
| 105 function testAddRuleToMediaRuleEnd(next) |
| 106 { |
| 107 addRule({ |
| 108 location: { startLine: 19, startColumn: 0, endLine: 19, endColum
n: 0 }, |
| 109 ruleText: "#test { content: 'EDITED'; }", |
| 110 }, dumpAndNext(next)); |
| 111 }, |
| 112 |
| 113 /* Tests that verify error reporting. */ |
| 114 |
| 115 function testInvalidRule(next) |
| 116 { |
| 117 verifyProtocolError({ |
| 118 location: { startLine: 0, startColumn: 0, endLine: 0, endColumn:
0 }, |
| 119 ruleText: "#test { content: 'EDITED';", |
| 120 }, next); |
| 121 }, |
| 122 |
| 123 function testAddingRuleInsideSelector(next) |
| 124 { |
| 125 verifyProtocolError({ |
| 126 location: { startLine: 0, startColumn: 2, endLine: 0, endColumn:
2 }, |
| 127 ruleText: "#test { content: 'EDITED'; }", |
| 128 }, next); |
| 129 }, |
| 130 |
| 131 function testAddingRuleBeforeRuleBody(next) |
| 132 { |
| 133 verifyProtocolError({ |
| 134 location: { startLine: 4, startColumn: 6, endLine: 4, endColumn:
6 }, |
| 135 ruleText: "#test { content: 'EDITED'; }", |
| 136 }, next); |
| 137 }, |
| 138 |
| 139 function testAddingRuleInsideMedia1(next) |
| 140 { |
| 141 verifyProtocolError({ |
| 142 location: { startLine: 12, startColumn: 3, endLine: 12, endColum
n: 3 }, |
| 143 ruleText: "#test { content: 'EDITED'; }", |
| 144 }, next); |
| 145 }, |
| 146 |
| 147 function testAddingRuleInsideMedia2(next) |
| 148 { |
| 149 verifyProtocolError({ |
| 150 location: { startLine: 12, startColumn: 15, endLine: 12, endColu
mn: 15 }, |
| 151 ruleText: "#test { content: 'EDITED'; }", |
| 152 }, next); |
| 153 }, |
| 154 |
| 155 function testAddingRuleBeforeMediaBody(next) |
| 156 { |
| 157 verifyProtocolError({ |
| 158 location: { startLine: 12, startColumn: 24, endLine: 12, endColu
mn: 24 }, |
| 159 ruleText: "#test { content: 'EDITED'; }", |
| 160 }, next); |
| 161 }, |
| 162 |
| 163 function testAddingRuleInsideStyleRule(next) |
| 164 { |
| 165 verifyProtocolError({ |
| 166 location: { startLine: 18, startColumn: 0, endLine: 18, endColum
n: 0 }, |
| 167 ruleText: "#test { content: 'EDITED'; }", |
| 168 }, next); |
| 169 }, |
| 170 ]; |
| 171 } |
| 172 |
| 173 </script> |
| 174 </head> |
| 175 <body onload="runTest();"> |
| 176 <p>The test verifies functionality of protocol method CSS.addRule.</p> |
| 177 <article id="test"></article> |
| 178 </body> |
| 179 </html> |
OLD | NEW |