| OLD | NEW |
| (Empty) | |
| 1 <html> |
| 2 <head> |
| 3 <script type="text/javascript" src="../../http/tests/inspector-protocol/resource
s/protocol-test.js"></script> |
| 4 <script type="text/javascript"> |
| 5 function test() |
| 6 { |
| 7 InspectorTest.eventHandler["CSS.styleSheetAdded"] = styleSheetAdded; |
| 8 InspectorTest.sendCommandAndBailOnError("CSS.enable", {}); |
| 9 |
| 10 var styleSheetId; |
| 11 |
| 12 function styleSheetAdded(result) |
| 13 { |
| 14 styleSheetId = result.params.header.styleSheetId; |
| 15 InspectorTest.sendCommandAndBailOnError("CSS.getStyleSheetText", { style
SheetId: styleSheetId }, onInitialStyleSheetText); |
| 16 } |
| 17 |
| 18 function onInitialStyleSheetText(result) |
| 19 { |
| 20 InspectorTest.log("==== Initial style sheet text ===="); |
| 21 InspectorTest.log(result.text); |
| 22 InspectorTest.runTestSuite(testSuite); |
| 23 } |
| 24 |
| 25 var testSuite = [ |
| 26 function testInsertTextInTheBeginning(next) |
| 27 { |
| 28 editStyleSheetAndDump({ |
| 29 range: { startLine: 0, startColumn: 0, endLine: 0, endColumn: 0
}, |
| 30 text: "* { border: 1px }" |
| 31 }, next); |
| 32 }, |
| 33 |
| 34 function testMultiLineEdit(next) |
| 35 { |
| 36 editStyleSheetAndDump({ |
| 37 range: { startLine: 1, startColumn: 5, endLine: 3, endColumn: 0
}, |
| 38 text: "\n background-color: blue;\n font-size: 12px;\n" |
| 39 }, next); |
| 40 }, |
| 41 |
| 42 function testReplaceText(next) |
| 43 { |
| 44 editStyleSheetAndDump({ |
| 45 range: { startLine: 1, startColumn: 0, endLine: 1, endColumn: 3
}, |
| 46 text: "p, span:hover" |
| 47 }, next); |
| 48 }, |
| 49 |
| 50 function testInsertInTheEnd(next) |
| 51 { |
| 52 editStyleSheetAndDump({ |
| 53 range: { startLine: 4, startColumn: 1, endLine: 4, endColumn: 1
}, |
| 54 text: "\n* { box-sizing: border-box; }" |
| 55 }, next); |
| 56 }, |
| 57 |
| 58 function testRemoveText(next) |
| 59 { |
| 60 editStyleSheetAndDump({ |
| 61 range: { startLine: 3, startColumn: 0, endLine: 4, endColumn: 0
}, |
| 62 text: "" |
| 63 }, next); |
| 64 }, |
| 65 |
| 66 function testInvalidParameters(next) |
| 67 { |
| 68 checkProtocolError({ |
| 69 range: { startLine: "three", startColumn: 0, endLine: 4, endColu
mn: 0 }, |
| 70 text: "no matter what is here" |
| 71 }, next); |
| 72 }, |
| 73 |
| 74 function testNegativeRangeParameters(next) |
| 75 { |
| 76 checkProtocolError({ |
| 77 range: { startLine: -1, startColumn: -1, endLine: 1, endColumn:
2 }, |
| 78 text: "a:hover { color: blue }" |
| 79 }, next); |
| 80 }, |
| 81 |
| 82 function testStartLineOutOfBounds(next) |
| 83 { |
| 84 checkProtocolError({ |
| 85 range: { startLine: 7, startColumn: 0, endLine: 7, endColumn: 0
}, |
| 86 text: "a:hover { color: blue }" |
| 87 }, next); |
| 88 }, |
| 89 |
| 90 function testEndLineOutOfBounds(next) |
| 91 { |
| 92 checkProtocolError({ |
| 93 range: { startLine: 0, startColumn: 0, endLine: 7, endColumn: 0
}, |
| 94 text: "a:hover { color: blue }" |
| 95 }, next); |
| 96 }, |
| 97 |
| 98 function testStartColumnBeyondLastLineCharacter(next) |
| 99 { |
| 100 checkProtocolError({ |
| 101 range: { startLine: 3, startColumn: 2, endLine: 3, endColumn: 2
}, |
| 102 text: "a:hover { color: blue }" |
| 103 }, next); |
| 104 }, |
| 105 |
| 106 function testEndColumnBeyondLastLineCharacter(next) |
| 107 { |
| 108 checkProtocolError({ |
| 109 range: { startLine: 3, startColumn: 0, endLine: 3, endColumn: 2
}, |
| 110 text: "a:hover { color: blue }" |
| 111 }, next); |
| 112 }, |
| 113 |
| 114 function testInsertBeyondLastCharacterOfLastLine(next) |
| 115 { |
| 116 checkProtocolError({ |
| 117 range: { startLine: 4, startColumn: 30, endLine: 4, endColumn: 3
0 }, |
| 118 text: "a:hover { color: blue }" |
| 119 }, next); |
| 120 }, |
| 121 |
| 122 function testReversedRange(next) |
| 123 { |
| 124 checkProtocolError({ |
| 125 range: { startLine: 2, startColumn: 0, endLine: 0, endColumn: 0
}, |
| 126 text: "a:hover { color: blue }" |
| 127 }, next); |
| 128 } |
| 129 ]; |
| 130 |
| 131 function editStyleSheetAndDump(options, callback) |
| 132 { |
| 133 options.styleSheetId = styleSheetId; |
| 134 InspectorTest.sendCommandAndBailOnError("CSS.editRangeInStyleSheetText",
options, onEditDone); |
| 135 function onEditDone() |
| 136 { |
| 137 InspectorTest.sendCommandAndBailOnError("CSS.getStyleSheetText", { s
tyleSheetId: styleSheetId }, onStyleSheetText); |
| 138 } |
| 139 function onStyleSheetText(result) |
| 140 { |
| 141 InspectorTest.log("==== Style sheet text ===="); |
| 142 InspectorTest.log(result.text); |
| 143 callback(); |
| 144 } |
| 145 } |
| 146 |
| 147 function checkProtocolError(options, next) |
| 148 { |
| 149 options.styleSheetId = styleSheetId; |
| 150 InspectorTest.sendCommand("CSS.editRangeInStyleSheetText", options, call
back); |
| 151 |
| 152 function callback(message) |
| 153 { |
| 154 if (!message.error) { |
| 155 InspectorTest.log("ERROR: protocol method call did not raise exp
ected error. Instead, the following message was received: " + JSON.stringify(mes
sage)); |
| 156 InspectorTest.completeTest(); |
| 157 return; |
| 158 } |
| 159 InspectorTest.log("Expected protocol error: " + message.error.messag
e); |
| 160 next(); |
| 161 } |
| 162 } |
| 163 |
| 164 } |
| 165 |
| 166 </script> |
| 167 <link rel="stylesheet" href="resources/edit-range.css"/> |
| 168 </head> |
| 169 <body onload="runTest();"> |
| 170 </body> |
| 171 </html> |
| OLD | NEW |