blob: 3ba08b0150d0c336c09da3b1a1360086d068e0d0 [file] [log] [blame]
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<body>
<script>
var ctx = document.createElement('canvas').getContext('2d');
document.body.appendChild(ctx.canvas);
ctx.strokeStyle = '#0ff';
// Create new path.
var path = new Path2D();
path.rect(20, 20, 100, 100);
function testPointInStroke(x, y, isPointInStroke) {
if(isPointInStroke)
assert_true(ctx.isPointInStroke(path, x, y));
else
assert_false(ctx.isPointInStroke(path, x, y));
}
testScenarios1 =
[
['TestScenario 1, Case 1', 20, 20, true],
['TestScenario 1, Case 2', 120, 20, true],
['TestScenario 1, Case 3', 20, 120, true],
['TestScenario 1, Case 4', 120, 120, true],
['TestScenario 1, Case 5', 70, 20, true],
['TestScenario 1, Case 6', 20, 70, true],
['TestScenario 1, Case 7', 120, 70, true],
['TestScenario 1, Case 8', 70, 120, true],
['TestScenario 1, Case 9', 22, 22, false],
['TestScenario 1, Case 10', 118, 22, false],
['TestScenario 1, Case 11', 22, 118, false],
['TestScenario 1, Case 12', 118, 118, false],
['TestScenario 1, Case 13', 70, 18, false],
['TestScenario 1, Case 14', 122, 70, false],
['TestScenario 1, Case 15', 70, 122, false],
['TestScenario 1, Case 16', 18, 70, false],
['TestScenario 1, Case 17', NaN, 122, false],
['TestScenario 1, Case 18', 18, NaN, false]
];
generate_tests(testPointInStroke, testScenarios1);
test(function(t) {
assert_throws(new TypeError(), function() {ctx.isPointInStroke(null, 70, 20);});
assert_throws(new TypeError(), function() {ctx.isPointInStroke(undefined, 70, 20);});
assert_throws(new TypeError(), function() {ctx.isPointInStroke([], 20, 70);});
assert_throws(new TypeError(), function() {ctx.isPointInStroke({}, 120, 70);});
}, "isPointInStroke in Canvas throws exception with invalid parameters.");
ctx.lineWidth = 10;
testScenarios2 =
[
['TestScenario 2, Case 1', 22, 22, true],
['TestScenario 2, Case 2', 118, 22, true],
['TestScenario 2, Case 3', 22, 118, true],
['TestScenario 2, Case 4', 118, 118, true],
['TestScenario 2, Case 5', 70, 18, true],
['TestScenario 2, Case 6', 122, 70, true],
['TestScenario 2, Case 7', 70, 122, true],
['TestScenario 2, Case 8', 18, 70, true],
['TestScenario 2, Case 9', 26, 70, false],
['TestScenario 2, Case 10', 70, 26, false],
['TestScenario 2, Case 11', 70, 114, false],
['TestScenario 2, Case 12', 114, 70, false]
];
generate_tests(testPointInStroke, testScenarios2);
test(function(t) {
path = new Path2D();
path.moveTo(10,10);
path.lineTo(110,20);
path.lineTo(10,30);
ctx.lineJoin = "bevel";
assert_false(ctx.isPointInStroke(path,113,20));
ctx.miterLimit = 40.0;
ctx.lineJoin = "miter";
assert_true(ctx.isPointInStroke(path,113,20));
ctx.miterLimit = 2.0;
assert_false(ctx.isPointInStroke(path,113,20));
path = new Path2D();
path.moveTo(10,10);
path.lineTo(110,10);
ctx.lineCap = "butt";
assert_false(ctx.isPointInStroke(path,112,10));
ctx.lineCap = "round";
assert_true(ctx.isPointInStroke(path,112,10));
assert_false(ctx.isPointInStroke(path,117,10));
ctx.lineCap = "square";
assert_true(ctx.isPointInStroke(path,112,10));
assert_false(ctx.isPointInStroke(path,117,10));
ctx.lineCap = "butt";
ctx.setLineDash([10,10]);
assert_true(ctx.isPointInStroke(path,15,10));
assert_false(ctx.isPointInStroke(path,25,10));
assert_true(ctx.isPointInStroke(path,35,10));
ctx.lineDashOffset = 10;
assert_false(ctx.isPointInStroke(path,15,10));
assert_true(ctx.isPointInStroke(path,25,10));
assert_false(ctx.isPointInStroke(path,35,10));
}, "Test the behavior of isPointInStroke in Canvas with path object");
</script>
</body>