chromium/third_party/blink/web_tests/fast/canvas/canvas-path-context-stroke.html

<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<body>
<canvas id="canvas" width="200" height="200"></canvas>
<script>

var ctx = document.getElementById('canvas').getContext('2d');

function checkResult(expectedColors, sigma) {
    data = ctx.getImageData(75, 75, 1, 1).data;
    for (var i = 0; i < 4; i++)
        assert_approx_equals(data[i], expectedColors[i], sigma);
}

function drawRectangleOn(contextOrPath) {
    contextOrPath.rect(25, 25, 50, 50);
}

function testStrokeWith(path) {
    ctx.fillStyle = 'rgb(255,0,0)';
    ctx.beginPath();
    ctx.fillRect(0, 0, 100, 100);
    ctx.strokeStyle = 'rgb(0,255,0)';
    ctx.lineWidth = 5;
    if (path) {
        ctx.stroke(path);
    } else {
        ctx.beginPath();
        drawRectangleOn(ctx);
        ctx.stroke();
    }
    checkResult([0, 255, 0, 255], 5);
}

test(function(t) {
    var path = new Path2D();
    drawRectangleOn(path);

    testStrokeWith();
    testStrokeWith(path);

    // Test exception cases.
    assert_throws_js(TypeError, function() {
      ctx.stroke(null);
    });
    assert_throws_js(TypeError, function() {
      ctx.stroke(undefined);
    });
    assert_throws_js(TypeError, function() {
      ctx.stroke([]);
    });
    assert_throws_js(TypeError, function() {
      ctx.stroke({});
    });
}, "Series of tests to ensure stroke() works with optional path parameter.");
</script>
</body>