Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 <!doctype html> | 1 <script src="../../resources/testharness.js"></script> |
| 2 <html> | 2 <script src="../../resources/testharnessreport.js"></script> |
| 3 <head> | |
| 4 <script src="../../resources/js-test.js"></script> | |
| 5 </head> | |
| 6 <body> | 3 <body> |
| 7 <script src="script-tests/canvas-isPointInStroke-with-path.js"></script> | 4 <script> |
| 5 var ctx = document.createElement('canvas').getContext('2d'); | |
| 6 document.body.appendChild(ctx.canvas); | |
| 7 ctx.strokeStyle = '#0ff'; | |
| 8 | |
| 9 // Create new path. | |
| 10 var path = new Path2D(); | |
| 11 path.rect(20, 20, 100, 100); | |
| 12 | |
| 13 function testPointInStroke(x, y, isPointInStroke) { | |
| 14 if(isPointInStroke) | |
| 15 assert_true(ctx.isPointInStroke(path, x, y)); | |
| 16 else | |
| 17 assert_false(ctx.isPointInStroke(path, x, y)); | |
| 18 } | |
| 19 | |
| 20 testScenarios1 = | |
| 21 [ | |
| 22 ['TestScenario 1, Case 1', 20, 20, true], | |
| 23 ['TestScenario 1, Case 2', 120, 20, true], | |
| 24 ['TestScenario 1, Case 3', 20, 120, true], | |
| 25 ['TestScenario 1, Case 4', 120, 120, true], | |
| 26 ['TestScenario 1, Case 5', 70, 20, true], | |
| 27 ['TestScenario 1, Case 6', 20, 70, true], | |
| 28 ['TestScenario 1, Case 7', 120, 70, true], | |
| 29 ['TestScenario 1, Case 8', 70, 120, true], | |
| 30 | |
| 31 ['TestScenario 1, Case 9', 22, 22, false], | |
| 32 ['TestScenario 1, Case 10', 118, 22, false], | |
| 33 ['TestScenario 1, Case 11', 22, 118, false], | |
| 34 ['TestScenario 1, Case 12', 118, 118, false], | |
| 35 ['TestScenario 1, Case 13', 70, 18, false], | |
| 36 ['TestScenario 1, Case 14', 122, 70, false], | |
| 37 ['TestScenario 1, Case 15', 70, 122, false], | |
| 38 ['TestScenario 1, Case 16', 18, 70, false], | |
| 39 ['TestScenario 1, Case 17', NaN, 122, false], | |
| 40 ['TestScenario 1, Case 18', 18, NaN, false] | |
| 41 ]; | |
| 42 generate_tests(testPointInStroke, testScenarios1); | |
| 43 | |
| 44 assert_throws(null, function() {ctx.isPointInStroke(null, 70, 20);}); | |
|
Justin Novosad
2017/02/16 15:41:55
These asserts should be inside a test()
zakerinasab
2017/02/16 18:12:40
Done.
| |
| 45 assert_throws(null, function() {ctx.isPointInStroke(undefined, 70, 20);}); | |
| 46 assert_throws(null, function() {ctx.isPointInStroke([], 20, 70);}); | |
| 47 assert_throws(null, function() {ctx.isPointInStroke({}, 120, 70);}); | |
| 48 | |
| 49 ctx.lineWidth = 10; | |
| 50 testScenarios2 = | |
| 51 [ | |
| 52 ['TestScenario 2, Case 1', 22, 22, true], | |
| 53 ['TestScenario 2, Case 2', 118, 22, true], | |
| 54 ['TestScenario 2, Case 3', 22, 118, true], | |
| 55 ['TestScenario 2, Case 4', 118, 118, true], | |
| 56 ['TestScenario 2, Case 5', 70, 18, true], | |
| 57 ['TestScenario 2, Case 6', 122, 70, true], | |
| 58 ['TestScenario 2, Case 7', 70, 122, true], | |
| 59 ['TestScenario 2, Case 8', 18, 70, true], | |
| 60 | |
| 61 ['TestScenario 2, Case 9', 26, 70, false], | |
| 62 ['TestScenario 2, Case 10', 70, 26, false], | |
| 63 ['TestScenario 2, Case 11', 70, 114, false], | |
| 64 ['TestScenario 2, Case 12', 114, 70, false] | |
| 65 ]; | |
| 66 generate_tests(testPointInStroke, testScenarios2); | |
| 67 | |
| 68 test(function(t) { | |
| 69 | |
| 70 path = new Path2D(); | |
| 71 path.moveTo(10,10); | |
| 72 path.lineTo(110,20); | |
| 73 path.lineTo(10,30); | |
| 74 ctx.lineJoin = "bevel"; | |
| 75 assert_false(ctx.isPointInStroke(path,113,20)); | |
| 76 | |
| 77 ctx.miterLimit = 40.0; | |
| 78 ctx.lineJoin = "miter"; | |
| 79 assert_true(ctx.isPointInStroke(path,113,20)); | |
| 80 | |
| 81 ctx.miterLimit = 2.0; | |
| 82 assert_false(ctx.isPointInStroke(path,113,20)); | |
| 83 | |
| 84 path = new Path2D(); | |
| 85 path.moveTo(10,10); | |
| 86 path.lineTo(110,10); | |
| 87 ctx.lineCap = "butt"; | |
| 88 assert_false(ctx.isPointInStroke(path,112,10)); | |
| 89 | |
| 90 ctx.lineCap = "round"; | |
| 91 assert_true(ctx.isPointInStroke(path,112,10)); | |
| 92 assert_false(ctx.isPointInStroke(path,117,10)); | |
| 93 | |
| 94 ctx.lineCap = "square"; | |
| 95 assert_true(ctx.isPointInStroke(path,112,10)); | |
| 96 assert_false(ctx.isPointInStroke(path,117,10)); | |
| 97 | |
| 98 ctx.lineCap = "butt"; | |
| 99 ctx.setLineDash([10,10]); | |
| 100 assert_true(ctx.isPointInStroke(path,15,10)); | |
| 101 assert_false(ctx.isPointInStroke(path,25,10)); | |
| 102 assert_true(ctx.isPointInStroke(path,35,10)); | |
| 103 | |
| 104 ctx.lineDashOffset = 10; | |
| 105 assert_false(ctx.isPointInStroke(path,15,10)); | |
| 106 assert_true(ctx.isPointInStroke(path,25,10)); | |
| 107 assert_false(ctx.isPointInStroke(path,35,10)); | |
| 108 | |
| 109 }, "Test the behavior of isPointInStroke in Canvas with path object"); | |
| 110 </script> | |
| 8 </body> | 111 </body> |
| OLD | NEW |