Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 <html> | 1 <html> |
| 2 <head> | 2 <head> |
| 3 <style> | 3 <script src="../../resources/testharness.js"></script> |
| 4 .pass { | 4 <script src="../../resources/testharnessreport.js"></script> |
| 5 color: green; | |
| 6 font-weight: bold; | |
| 7 } | |
| 8 | |
| 9 .fail { | |
| 10 color: red; | |
| 11 font-weight: bold; | |
| 12 } | |
| 13 </style> | |
| 14 </head> | 5 </head> |
| 15 <body> | 6 <body> |
| 16 <span>Tests that canvas 2d context supports 'direction' attribute: <span id="sup ported"></span></span> | 7 <span>Tests that canvas 2d context supports 'direction' attribute: <span id="sup ported"></span></span> |
| 17 <div> | 8 <div> |
| 18 <span>Tests that context.direction is 'ltr' with parent element having unspecifi ed direction: <span id="result1"></span></span><br> | 9 <span>Tests that context.direction is 'ltr' with parent element having unspecifi ed direction: <span id="result1"></span></span><br> |
| 19 <canvas id="canvas1" width=400 height=20 style="border:1px solid black"></canvas > | 10 <canvas id="canvas1" width=400 height=20 style="border:1px solid black"></canvas > |
| 20 </div> | 11 </div> |
| 21 <div dir="rtl"> | 12 <div dir="rtl"> |
| 22 <span>Tests that context.direction is 'rtl' with parent element having direction as rtl: <span id="result2"></span></span><br> | 13 <span>Tests that context.direction is 'rtl' with parent element having direction as rtl: <span id="result2"></span></span><br> |
| 23 <canvas id="canvas2" width=400 height=20 style="border:1px solid black"></canvas > | 14 <canvas id="canvas2" width=400 height=20 style="border:1px solid black"></canvas > |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 54 <span>Tests that change in element's dir attribute is reflected in context.direc tion as ltr: <span id="result10"></span></span><br> | 45 <span>Tests that change in element's dir attribute is reflected in context.direc tion as ltr: <span id="result10"></span></span><br> |
| 55 <canvas id="canvas10" width=400 height=20 style="border:1px solid black"></canva s> | 46 <canvas id="canvas10" width=400 height=20 style="border:1px solid black"></canva s> |
| 56 </div> | 47 </div> |
| 57 <div> | 48 <div> |
| 58 <span>Tests that context.direction reflects the valid direction after save/resto re context operations: <span id="result11"></span></span><br> | 49 <span>Tests that context.direction reflects the valid direction after save/resto re context operations: <span id="result11"></span></span><br> |
| 59 <canvas id="canvas11" style="border:1px solid black"></canvas> | 50 <canvas id="canvas11" style="border:1px solid black"></canvas> |
| 60 </div> | 51 </div> |
| 61 <div id="results"> | 52 <div id="results"> |
| 62 </div> | 53 </div> |
| 63 <script> | 54 <script> |
| 64 if (window.testRunner) | 55 test(function(t) { |
| 65 testRunner.dumpAsText(); | |
| 66 | 56 |
| 67 var newCanvasElement = document.createElement('canvas'); | 57 var newCanvasElement = document.createElement('canvas'); |
|
Justin Novosad
2017/02/09 20:32:01
indent
zakerinasab
2017/02/13 16:25:19
Done.
| |
| 68 document.getElementById('supported').textContent = newCanvasElement.getContext(' 2d').direction ? 'PASS' : 'FAIL'; | 58 assert_not_equals(newCanvasElement.getContext('2d').direction, null); |
| 69 document.getElementById('supported').className = newCanvasElement.getContext('2d ').direction ? 'pass' : 'fail'; | |
| 70 | 59 |
| 71 var fontSettings = "12px 'Arial'"; | 60 var fontSettings = "12px 'Arial'"; |
| 72 | 61 |
| 73 function appendResult(description, result) | 62 function verifyDrawText(canvasId, text, expectedDirection) |
| 74 { | |
| 75 var descriptionElement = document.createElement('span'); | |
| 76 var resultElement = document.createElement('span'); | |
| 77 descriptionElement.innerHTML = description; | |
| 78 resultElement.textContent = result; | |
| 79 resultElement.className = (result === 'PASS') ? 'pass' : 'fail'; | |
| 80 descriptionElement.appendChild(resultElement); | |
| 81 document.getElementById("results").appendChild(descriptionElement); | |
| 82 document.getElementById("results").appendChild(document.createElement('br')) ; | |
| 83 } | |
| 84 | |
| 85 function verifyDrawText(canvasId, resultId, text, expectedDirection) | |
| 86 { | 63 { |
| 87 var canvasElement = document.getElementById(canvasId); | 64 var canvasElement = document.getElementById(canvasId); |
| 88 var resultElement = document.getElementById(resultId); | |
| 89 var ctx = canvasElement.getContext('2d'); | 65 var ctx = canvasElement.getContext('2d'); |
| 90 var width = canvasElement.width/2; | 66 var width = canvasElement.width/2; |
| 91 var height = canvasElement.height; | 67 var height = canvasElement.height; |
| 92 resultElement.textContent = (ctx.direction == expectedDirection) ? 'PASS' : 'FAIL'; | 68 assert_equals(ctx.direction, expectedDirection); |
| 93 resultElement.className = (ctx.direction == expectedDirection) ? 'pass' : 'f ail'; | |
| 94 ctx.moveTo(width, 0); | 69 ctx.moveTo(width, 0); |
| 95 ctx.lineTo(width, height); | 70 ctx.lineTo(width, height); |
| 96 ctx.stroke(); | 71 ctx.stroke(); |
| 97 ctx.font = fontSettings; | 72 ctx.font = fontSettings; |
| 98 ctx.fillText(text, width, height/2); | 73 ctx.fillText(text, width, height/2); |
| 99 } | 74 } |
| 100 | 75 |
| 101 function verifyDrawTextWithSpecifiedDirection(canvasId, resultId, text, directio n, expectedDirection) | 76 function verifyDrawTextWithSpecifiedDirection(canvasId, text, direction, expecte dDirection) |
| 102 { | 77 { |
| 103 var canvasElement = document.getElementById(canvasId); | 78 var canvasElement = document.getElementById(canvasId); |
| 104 var resultElement = document.getElementById(resultId); | |
| 105 var ctx = canvasElement.getContext('2d'); | 79 var ctx = canvasElement.getContext('2d'); |
| 106 var width = canvasElement.width/2; | 80 var width = canvasElement.width/2; |
| 107 var height = canvasElement.height; | 81 var height = canvasElement.height; |
| 108 var currentDirection = ctx.direction; | 82 var currentDirection = ctx.direction; |
| 109 ctx.direction = direction; | 83 ctx.direction = direction; |
| 110 resultElement.textContent = (currentDirection && (ctx.direction == expectedD irection)) ? 'PASS' : 'FAIL'; | 84 assert_not_equals(currentDirection, null); |
| 111 resultElement.className = (currentDirection && (ctx.direction == expectedDir ection)) ? 'pass' : 'fail'; | 85 assert_equals(ctx.direction, expectedDirection); |
| 112 ctx.moveTo(width, 0); | 86 ctx.moveTo(width, 0); |
| 113 ctx.lineTo(width, height); | 87 ctx.lineTo(width, height); |
| 114 ctx.stroke(); | 88 ctx.stroke(); |
| 115 ctx.font = fontSettings; | 89 ctx.font = fontSettings; |
| 116 ctx.fillText(text, width, height/2); | 90 ctx.fillText(text, width, height/2); |
| 117 } | 91 } |
| 118 | 92 |
| 119 function verifyDirectionAfterReset(canvasId, text, direction, expectedDirection) | 93 function verifyDirectionAfterReset(canvasId, text, direction, expectedDirection) |
| 120 { | 94 { |
| 121 var canvasElement = document.getElementById(canvasId); | 95 var canvasElement = document.getElementById(canvasId); |
| 122 var width = canvasElement.width/2; | 96 var width = canvasElement.width/2; |
| 123 var height = canvasElement.height; | 97 var height = canvasElement.height; |
| 124 var ctx = canvasElement.getContext('2d'); | 98 var ctx = canvasElement.getContext('2d'); |
| 125 ctx.direction = direction; | 99 ctx.direction = direction; |
| 126 ctx.moveTo(width, 0); | 100 ctx.moveTo(width, 0); |
| 127 ctx.lineTo(width, height); | 101 ctx.lineTo(width, height); |
| 128 ctx.stroke(); | 102 ctx.stroke(); |
| 129 ctx.font = fontSettings; | 103 ctx.font = fontSettings; |
| 130 ctx.fillText(text, width, height/2); | 104 ctx.fillText(text, width, height/2); |
| 131 canvasElement.width = canvasElement.width + 1; | 105 canvasElement.width = canvasElement.width + 1; |
| 132 var description = 'Tests that context.reset() sets the context.direction to ' + expectedDirection + ': '; | 106 assert_equals(ctx.direction, expectedDirection); |
| 133 var result = (ctx.direction == expectedDirection) ? 'PASS' : 'FAIL'; | |
| 134 appendResult(description, result); | |
| 135 document.body.removeChild(canvasElement.parentElement); | 107 document.body.removeChild(canvasElement.parentElement); |
| 136 } | 108 } |
| 137 | 109 |
| 138 function verifyDirectionAfterAttributeChange(canvasId, resultId, text, newDirect ion, forParentElement) | 110 function verifyDirectionAfterAttributeChange(canvasId, text, newDirection, forPa rentElement) |
| 139 { | 111 { |
| 140 var canvasElement = document.getElementById(canvasId); | 112 var canvasElement = document.getElementById(canvasId); |
| 141 var resultElement = document.getElementById(resultId); | |
| 142 var ctx = canvasElement.getContext('2d'); | 113 var ctx = canvasElement.getContext('2d'); |
| 143 var width = canvasElement.width/2; | 114 var width = canvasElement.width/2; |
| 144 var height = canvasElement.height; | 115 var height = canvasElement.height; |
| 145 | 116 |
| 146 if (forParentElement) | 117 if (forParentElement) |
| 147 canvasElement.parentElement.dir = newDirection; | 118 canvasElement.parentElement.dir = newDirection; |
| 148 else | 119 else |
| 149 canvasElement.dir = newDirection; | 120 canvasElement.dir = newDirection; |
| 150 resultElement.textContent = ctx.direction == newDirection ? 'PASS' : 'FAIL'; | 121 assert_equals(ctx.direction, newDirection); |
| 151 resultElement.className = ctx.direction == newDirection ? 'pass' : 'fail'; | |
| 152 ctx.moveTo(width, 0); | 122 ctx.moveTo(width, 0); |
| 153 ctx.lineTo(width, height); | 123 ctx.lineTo(width, height); |
| 154 ctx.stroke(); | 124 ctx.stroke(); |
| 155 ctx.font = fontSettings; | 125 ctx.font = fontSettings; |
| 156 ctx.fillText(text, width, height/2); | 126 ctx.fillText(text, width, height/2); |
| 157 } | 127 } |
| 158 | 128 |
| 159 function verifyDirectionAcrossSaveRestores(canvasId, resultId, testVector) | 129 function verifyDirectionAcrossSaveRestores(canvasId, testVector) |
| 160 { | 130 { |
| 161 var canvasElement = document.getElementById(canvasId); | 131 var canvasElement = document.getElementById(canvasId); |
| 162 var resultElement = document.getElementById(resultId); | |
| 163 var ctx = canvasElement.getContext('2d'); | 132 var ctx = canvasElement.getContext('2d'); |
| 164 var width = canvasElement.width/2; | 133 var width = canvasElement.width/2; |
| 165 var height = 0; | 134 var height = 0; |
| 166 ctx.moveTo(width, 0); | 135 ctx.moveTo(width, 0); |
| 167 ctx.lineTo(width, canvasElement.height); | 136 ctx.lineTo(width, canvasElement.height); |
| 168 ctx.stroke(); | 137 ctx.stroke(); |
| 169 ctx.font = fontSettings; | 138 ctx.font = fontSettings; |
| 170 var testVectorLength = testVector.length; | 139 var testVectorLength = testVector.length; |
| 171 var i = 0; | 140 var i = 0; |
| 172 for (; i < testVector.length; ++i) { | 141 for (; i < testVector.length; ++i) { |
| 173 height += 20; | 142 height += 20; |
| 174 ctx.direction = testVector[i].direction; | 143 ctx.direction = testVector[i].direction; |
| 175 ctx.fillText(testVector[i].text, width, height); | 144 ctx.fillText(testVector[i].text, width, height); |
| 176 if (i != testVectorLength - 1) | 145 if (i != testVectorLength - 1) |
| 177 ctx.save(); | 146 ctx.save(); |
| 178 } | 147 } |
| 179 var validDirectionCount = 0; | 148 var validDirectionCount = 0; |
| 180 for (--i; i > 0; --i) { | 149 for (--i; i > 0; --i) { |
| 181 ctx.restore(); | 150 ctx.restore(); |
| 182 if (ctx.direction == testVector[i - 1].direction) | 151 if (ctx.direction == testVector[i - 1].direction) |
| 183 validDirectionCount++; | 152 validDirectionCount++; |
| 184 } | 153 } |
| 185 resultElement.textContent = validDirectionCount == testVectorLength - 1 ? 'P ASS' : 'FAIL'; | 154 assert_equals(validDirectionCount, testVectorLength - 1); |
| 186 resultElement.className = validDirectionCount == testVectorLength - 1 ? 'pas s' : 'fail'; | |
| 187 } | 155 } |
| 188 | 156 |
| 189 function verifyInvalidDirection(direction) | 157 function verifyInvalidDirection(direction) |
| 190 { | 158 { |
| 191 var ctx = document.createElement('canvas').getContext('2d'); | 159 var ctx = document.createElement('canvas').getContext('2d'); |
| 192 var currentDirection = ctx.direction; | 160 var currentDirection = ctx.direction; |
| 193 ctx.direction = direction; | 161 ctx.direction = direction; |
| 194 var description = 'Tests that invalid direction value ' + direction + ' has no effect on the context.direction: '; | 162 assert_equals(ctx.direction, currentDirection); |
| 195 var result = (ctx.direction == currentDirection) ? 'PASS' : 'FAIL'; | |
| 196 appendResult(description, result); | |
| 197 } | 163 } |
| 198 | 164 |
| 199 verifyDrawText('canvas1', 'result1', 'Left-to-Right text', 'ltr'); | 165 verifyDrawText('canvas1', 'Left-to-Right text', 'ltr'); |
|
Justin Novosad
2017/02/09 20:32:01
should use generate_tests
zakerinasab
2017/02/13 16:25:19
Done.
| |
| 200 verifyDrawText('canvas2', 'result2', 'Right-to-Left text', 'rtl'); | 166 verifyDrawText('canvas2', 'Right-to-Left text', 'rtl'); |
| 201 | 167 |
| 202 verifyDrawTextWithSpecifiedDirection('canvas3', 'result3', 'Right-to-Left text', 'rtl', 'rtl'); | 168 verifyDrawTextWithSpecifiedDirection('canvas3', 'Right-to-Left text', 'rtl', 'rt l'); |
| 203 verifyDrawTextWithSpecifiedDirection('canvas4', 'result4', 'Left-to-Right text', 'ltr', 'ltr'); | 169 verifyDrawTextWithSpecifiedDirection('canvas4', 'Left-to-Right text', 'ltr', 'lt r'); |
| 204 verifyDrawTextWithSpecifiedDirection('canvas5', 'result5', 'Left-to-Right text', 'inherit', 'ltr'); | 170 verifyDrawTextWithSpecifiedDirection('canvas5', 'Left-to-Right text', 'inherit', 'ltr'); |
| 205 verifyDrawTextWithSpecifiedDirection('canvas6', 'result6', 'Right-to-Left text', 'inherit', 'rtl'); | 171 verifyDrawTextWithSpecifiedDirection('canvas6', 'Right-to-Left text', 'inherit', 'rtl'); |
| 206 | 172 |
| 207 verifyDirectionAfterReset('canvas7', 'Right-to-Left', 'rtl', 'ltr'); | 173 verifyDirectionAfterReset('canvas7', 'Right-to-Left', 'rtl', 'ltr'); |
| 208 verifyDirectionAfterReset('canvas8', 'Right-to-Left', 'ltr', 'rtl'); | 174 verifyDirectionAfterReset('canvas8', 'Right-to-Left', 'ltr', 'rtl'); |
| 209 | 175 |
| 210 verifyDirectionAfterAttributeChange('canvas9', 'result9', 'Right-to-Left text', 'rtl', true); | 176 verifyDirectionAfterAttributeChange('canvas9', 'Right-to-Left text', 'rtl', true ); |
| 211 verifyDirectionAfterAttributeChange('canvas10', 'result10', 'Left-to-Right text' , 'ltr', false); | 177 verifyDirectionAfterAttributeChange('canvas10', 'Left-to-Right text', 'ltr', fal se); |
| 212 | 178 |
| 213 verifyDirectionAcrossSaveRestores('canvas11', | 179 verifyDirectionAcrossSaveRestores('canvas11', |
| 214 'result11', | |
| 215 [{ text: 'Left-to-Right text', direction: 'ltr ' }, | 180 [{ text: 'Left-to-Right text', direction: 'ltr ' }, |
| 216 { text: 'Right-to-Left text', direction: 'rtl ' }, | 181 { text: 'Right-to-Left text', direction: 'rtl ' }, |
| 217 { text: 'Right-to-Left text', direction: 'rtl ' }, | 182 { text: 'Right-to-Left text', direction: 'rtl ' }, |
| 218 { text: 'Left-to-Right text', direction: 'ltr ' }, | 183 { text: 'Left-to-Right text', direction: 'ltr ' }, |
| 219 { text: 'Right-to-Left text', direction: 'rtl ' }, | 184 { text: 'Right-to-Left text', direction: 'rtl ' }, |
| 220 { text: 'Right-to-Left text', direction: 'rtl ' }]); | 185 { text: 'Right-to-Left text', direction: 'rtl ' }]); |
| 221 | 186 |
| 222 verifyInvalidDirection('RTL'); | 187 verifyInvalidDirection('RTL'); |
| 223 verifyInvalidDirection('LTR'); | 188 verifyInvalidDirection('LTR'); |
| 224 verifyInvalidDirection('INHERIT'); | 189 verifyInvalidDirection('INHERIT'); |
| 190 }, 'Test that createImageBitmap from a bitmaprenderer canvas produces correct re sult'); | |
| 225 </script> | 191 </script> |
| OLD | NEW |