Chromium Code Reviews| Index: third_party/WebKit/LayoutTests/fast/canvas/canvas-direction.html |
| diff --git a/third_party/WebKit/LayoutTests/fast/canvas/canvas-direction.html b/third_party/WebKit/LayoutTests/fast/canvas/canvas-direction.html |
| index bf576b2c22c41326411202c2919ff88549516624..30f3aa020f89225c262a641606dcfb6a4d21cd37 100644 |
| --- a/third_party/WebKit/LayoutTests/fast/canvas/canvas-direction.html |
| +++ b/third_party/WebKit/LayoutTests/fast/canvas/canvas-direction.html |
| @@ -1,16 +1,7 @@ |
| <html> |
| <head> |
| -<style> |
| -.pass { |
| - color: green; |
| - font-weight: bold; |
| -} |
| - |
| -.fail { |
| - color: red; |
| - font-weight: bold; |
| -} |
| -</style> |
| +<script src="../../resources/testharness.js"></script> |
| +<script src="../../resources/testharnessreport.js"></script> |
| </head> |
| <body> |
| <span>Tests that canvas 2d context supports 'direction' attribute: <span id="supported"></span></span> |
| @@ -61,36 +52,20 @@ |
| <div id="results"> |
| </div> |
| <script> |
| -if (window.testRunner) |
| - testRunner.dumpAsText(); |
| +test(function(t) { |
| var newCanvasElement = document.createElement('canvas'); |
|
Justin Novosad
2017/02/09 20:32:01
indent
zakerinasab
2017/02/13 16:25:19
Done.
|
| -document.getElementById('supported').textContent = newCanvasElement.getContext('2d').direction ? 'PASS' : 'FAIL'; |
| -document.getElementById('supported').className = newCanvasElement.getContext('2d').direction ? 'pass' : 'fail'; |
| +assert_not_equals(newCanvasElement.getContext('2d').direction, null); |
| var fontSettings = "12px 'Arial'"; |
| -function appendResult(description, result) |
| -{ |
| - var descriptionElement = document.createElement('span'); |
| - var resultElement = document.createElement('span'); |
| - descriptionElement.innerHTML = description; |
| - resultElement.textContent = result; |
| - resultElement.className = (result === 'PASS') ? 'pass' : 'fail'; |
| - descriptionElement.appendChild(resultElement); |
| - document.getElementById("results").appendChild(descriptionElement); |
| - document.getElementById("results").appendChild(document.createElement('br')); |
| -} |
| - |
| -function verifyDrawText(canvasId, resultId, text, expectedDirection) |
| +function verifyDrawText(canvasId, text, expectedDirection) |
| { |
| var canvasElement = document.getElementById(canvasId); |
| - var resultElement = document.getElementById(resultId); |
| var ctx = canvasElement.getContext('2d'); |
| var width = canvasElement.width/2; |
| var height = canvasElement.height; |
| - resultElement.textContent = (ctx.direction == expectedDirection) ? 'PASS' : 'FAIL'; |
| - resultElement.className = (ctx.direction == expectedDirection) ? 'pass' : 'fail'; |
| + assert_equals(ctx.direction, expectedDirection); |
| ctx.moveTo(width, 0); |
| ctx.lineTo(width, height); |
| ctx.stroke(); |
| @@ -98,17 +73,16 @@ function verifyDrawText(canvasId, resultId, text, expectedDirection) |
| ctx.fillText(text, width, height/2); |
| } |
| -function verifyDrawTextWithSpecifiedDirection(canvasId, resultId, text, direction, expectedDirection) |
| +function verifyDrawTextWithSpecifiedDirection(canvasId, text, direction, expectedDirection) |
| { |
| var canvasElement = document.getElementById(canvasId); |
| - var resultElement = document.getElementById(resultId); |
| var ctx = canvasElement.getContext('2d'); |
| var width = canvasElement.width/2; |
| var height = canvasElement.height; |
| var currentDirection = ctx.direction; |
| ctx.direction = direction; |
| - resultElement.textContent = (currentDirection && (ctx.direction == expectedDirection)) ? 'PASS' : 'FAIL'; |
| - resultElement.className = (currentDirection && (ctx.direction == expectedDirection)) ? 'pass' : 'fail'; |
| + assert_not_equals(currentDirection, null); |
| + assert_equals(ctx.direction, expectedDirection); |
| ctx.moveTo(width, 0); |
| ctx.lineTo(width, height); |
| ctx.stroke(); |
| @@ -129,16 +103,13 @@ function verifyDirectionAfterReset(canvasId, text, direction, expectedDirection) |
| ctx.font = fontSettings; |
| ctx.fillText(text, width, height/2); |
| canvasElement.width = canvasElement.width + 1; |
| - var description = 'Tests that context.reset() sets the context.direction to ' + expectedDirection + ': '; |
| - var result = (ctx.direction == expectedDirection) ? 'PASS' : 'FAIL'; |
| - appendResult(description, result); |
| + assert_equals(ctx.direction, expectedDirection); |
| document.body.removeChild(canvasElement.parentElement); |
| } |
| -function verifyDirectionAfterAttributeChange(canvasId, resultId, text, newDirection, forParentElement) |
| +function verifyDirectionAfterAttributeChange(canvasId, text, newDirection, forParentElement) |
| { |
| var canvasElement = document.getElementById(canvasId); |
| - var resultElement = document.getElementById(resultId); |
| var ctx = canvasElement.getContext('2d'); |
| var width = canvasElement.width/2; |
| var height = canvasElement.height; |
| @@ -147,8 +118,7 @@ function verifyDirectionAfterAttributeChange(canvasId, resultId, text, newDirect |
| canvasElement.parentElement.dir = newDirection; |
| else |
| canvasElement.dir = newDirection; |
| - resultElement.textContent = ctx.direction == newDirection ? 'PASS' : 'FAIL'; |
| - resultElement.className = ctx.direction == newDirection ? 'pass' : 'fail'; |
| + assert_equals(ctx.direction, newDirection); |
| ctx.moveTo(width, 0); |
| ctx.lineTo(width, height); |
| ctx.stroke(); |
| @@ -156,10 +126,9 @@ function verifyDirectionAfterAttributeChange(canvasId, resultId, text, newDirect |
| ctx.fillText(text, width, height/2); |
| } |
| -function verifyDirectionAcrossSaveRestores(canvasId, resultId, testVector) |
| +function verifyDirectionAcrossSaveRestores(canvasId, testVector) |
| { |
| var canvasElement = document.getElementById(canvasId); |
| - var resultElement = document.getElementById(resultId); |
| var ctx = canvasElement.getContext('2d'); |
| var width = canvasElement.width/2; |
| var height = 0; |
| @@ -182,8 +151,7 @@ function verifyDirectionAcrossSaveRestores(canvasId, resultId, testVector) |
| if (ctx.direction == testVector[i - 1].direction) |
| validDirectionCount++; |
| } |
| - resultElement.textContent = validDirectionCount == testVectorLength - 1 ? 'PASS' : 'FAIL'; |
| - resultElement.className = validDirectionCount == testVectorLength - 1 ? 'pass' : 'fail'; |
| + assert_equals(validDirectionCount, testVectorLength - 1); |
| } |
| function verifyInvalidDirection(direction) |
| @@ -191,27 +159,24 @@ function verifyInvalidDirection(direction) |
| var ctx = document.createElement('canvas').getContext('2d'); |
| var currentDirection = ctx.direction; |
| ctx.direction = direction; |
| - var description = 'Tests that invalid direction value ' + direction + ' has no effect on the context.direction: '; |
| - var result = (ctx.direction == currentDirection) ? 'PASS' : 'FAIL'; |
| - appendResult(description, result); |
| + assert_equals(ctx.direction, currentDirection); |
| } |
| -verifyDrawText('canvas1', 'result1', 'Left-to-Right text', 'ltr'); |
| -verifyDrawText('canvas2', 'result2', 'Right-to-Left text', 'rtl'); |
| +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.
|
| +verifyDrawText('canvas2', 'Right-to-Left text', 'rtl'); |
| -verifyDrawTextWithSpecifiedDirection('canvas3', 'result3', 'Right-to-Left text', 'rtl', 'rtl'); |
| -verifyDrawTextWithSpecifiedDirection('canvas4', 'result4', 'Left-to-Right text', 'ltr', 'ltr'); |
| -verifyDrawTextWithSpecifiedDirection('canvas5', 'result5', 'Left-to-Right text', 'inherit', 'ltr'); |
| -verifyDrawTextWithSpecifiedDirection('canvas6', 'result6', 'Right-to-Left text', 'inherit', 'rtl'); |
| +verifyDrawTextWithSpecifiedDirection('canvas3', 'Right-to-Left text', 'rtl', 'rtl'); |
| +verifyDrawTextWithSpecifiedDirection('canvas4', 'Left-to-Right text', 'ltr', 'ltr'); |
| +verifyDrawTextWithSpecifiedDirection('canvas5', 'Left-to-Right text', 'inherit', 'ltr'); |
| +verifyDrawTextWithSpecifiedDirection('canvas6', 'Right-to-Left text', 'inherit', 'rtl'); |
| verifyDirectionAfterReset('canvas7', 'Right-to-Left', 'rtl', 'ltr'); |
| verifyDirectionAfterReset('canvas8', 'Right-to-Left', 'ltr', 'rtl'); |
| -verifyDirectionAfterAttributeChange('canvas9', 'result9', 'Right-to-Left text', 'rtl', true); |
| -verifyDirectionAfterAttributeChange('canvas10', 'result10', 'Left-to-Right text', 'ltr', false); |
| +verifyDirectionAfterAttributeChange('canvas9', 'Right-to-Left text', 'rtl', true); |
| +verifyDirectionAfterAttributeChange('canvas10', 'Left-to-Right text', 'ltr', false); |
| verifyDirectionAcrossSaveRestores('canvas11', |
| - 'result11', |
| [{ text: 'Left-to-Right text', direction: 'ltr' }, |
| { text: 'Right-to-Left text', direction: 'rtl' }, |
| { text: 'Right-to-Left text', direction: 'rtl' }, |
| @@ -222,4 +187,5 @@ verifyDirectionAcrossSaveRestores('canvas11', |
| verifyInvalidDirection('RTL'); |
| verifyInvalidDirection('LTR'); |
| verifyInvalidDirection('INHERIT'); |
| +}, 'Test that createImageBitmap from a bitmaprenderer canvas produces correct result'); |
| </script> |