chromium/third_party/blink/web_tests/fast/canvas-api/pointInPath.html

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

    ctx = document.createElement("canvas").getContext("2d");
    ctx.save();
    // Rectangle at (0,0) 20x20
    ctx.rect(0, 0, 20, 20);
    assert_true(ctx.isPointInPath(5, 5));
    assert_true(ctx.isPointInPath(10, 10));
    assert_true(ctx.isPointInPath(19, 19));
    assert_false(ctx.isPointInPath(30, 30));
    assert_false(ctx.isPointInPath(-1, 10));
    assert_false(ctx.isPointInPath(10, -1));
    
    // Translate context (10,10)
    ctx.translate(10,10);
    assert_true(ctx.isPointInPath(5, 5));
    assert_true(ctx.isPointInPath(10, 10));
    assert_true(ctx.isPointInPath(19, 19));
    assert_false(ctx.isPointInPath(30, 30));
    assert_false(ctx.isPointInPath(-1, 10));
    assert_false(ctx.isPointInPath(10, -1));
    
    // Collapse ctm to non-invertible matrix
    ctx.scale(0,0);
    assert_false(ctx.isPointInPath(5, 5));
    assert_false(ctx.isPointInPath(10, 10));
    assert_false(ctx.isPointInPath(20, 20));
    assert_false(ctx.isPointInPath(30, 30));
    assert_false(ctx.isPointInPath(-1, 10));
    assert_false(ctx.isPointInPath(10, -1));
    // Resetting context to a clean state
    ctx.restore();
    
    ctx.save();
    ctx.beginPath();
    // Translate context (10,10)
    ctx.translate(10,10);
    // Rectangle at (0,0) 20x20
    ctx.rect(0, 0, 20, 20);
    assert_false(ctx.isPointInPath(5, 5));
    assert_true(ctx.isPointInPath(10, 10));
    assert_true(ctx.isPointInPath(20, 20));
    assert_true(ctx.isPointInPath(29, 29));
    assert_false(ctx.isPointInPath(-1, 10));
    assert_false(ctx.isPointInPath(10, -1));
    ctx.restore();
    
    ctx.save();
    ctx.beginPath();
    // Translate context (10,20)
    ctx.translate(10,20);
    // Transform context (1, 0, 0, -1, 0, 0)
    ctx.transform(1, 0, 0, -1, 0, 0);
    // Rectangle at (0,0) 20x20
    ctx.rect(0, 0, 20, 20);
    // After the flip, rect is actually 10, 0, 20, 20
    assert_false(ctx.isPointInPath(5, 5));
    assert_true(ctx.isPointInPath(10, 0));
    assert_true(ctx.isPointInPath(29, 0));
    assert_true(ctx.isPointInPath(10, 19));
    assert_true(ctx.isPointInPath(21, 10));
    assert_true(ctx.isPointInPath(29, 19));
    ctx.strokeStyle = 'green';
    ctx.stroke();
    ctx.restore();

}, "Series of tests for Canvas.isPointInPath");
</script>