chromium/third_party/blink/web_tests/fast/canvas/canvas-strokeText-invalid-maxWidth.html

<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<body>
<script>
test(function(t) {

    var canvas = document.createElement('canvas');
    var ctx = canvas.getContext('2d');
    var canvasWidth = 100;
    var canvasHeight = 50;
    canvas.setWidth = canvasWidth;
    canvas.setHeight = canvasHeight;
    
    ctx.fillStyle = '#0f0';
    ctx.fillRect(0, 0, canvasWidth, canvasHeight);
    ctx.font = '35px Arial, sans-serif';
    
    ctx.strokeStyle = '#f00';
    ctx.strokeText("fail fail fail fail fail", 5, 35, 0);
    
    var imageData = ctx.getImageData(0, 0, canvasWidth, canvasHeight);
    var w = imageData.width, h = imageData.height, d = imageData.data;
    var testPassed = true;
    var expectedColor = [0, 255, 0, 255];
    mainLoop1:
    for (var i = 0; i < h; ++i) {
        for (var k = 0; k < 4; ++k) {
            var j = w;
            while (--j > 0 && d[4 * (w * i + j) + k] == expectedColor[k]);
            testPassed = testPassed && j == 0;
            if(!testPassed)
                break mainLoop1;
    
        }
    }
    assert_true(testPassed);
    
    ctx.fillStyle = '#0f0';
    ctx.fillRect(0, 0, canvasWidth, canvasHeight);
    
    ctx.strokeStyle = '#f00';
    ctx.strokeText("fail fail fail fail fail", 5, 35, -1);
    
    imageData = ctx.getImageData(0, 0, canvasWidth, canvasHeight);
    d = imageData.data;
    testPassed = true;
    mainLoop2:
    for (var i = 0; i < h; ++i) {
        for (var k = 0; k < 4; ++k) {
            var j = w;
            while (--j > 0 && d[4 * (w * i + j) + k] == expectedColor[k]);
            testPassed = testPassed && j == 0;
            if(!testPassed)
                break mainLoop2;
        }
    }
    assert_true(testPassed);

}, 'Series of tests to ensure that strokeText() does not display any text when maxWidth is invalid.');
</script>
</body>