X-Git-Url: https://adrianiainlam.tk/git/?a=blobdiff_plain;ds=sidebyside;f=auto_tests%2Ftests%2FCanvasAssertions.js;h=4059a0aeee189614ef6fceb62dc4e9e2c9f9f24f;hb=ccb0001c3c8aadd02358995c8d7b71fbb37c0bc3;hp=6481c60ddb55e88c2a4df2f9a7098781662b3759;hpb=e26b71566419e1c051f3fbd1f4f8f64b063a04c9;p=dygraphs.git diff --git a/auto_tests/tests/CanvasAssertions.js b/auto_tests/tests/CanvasAssertions.js index 6481c60..4059a0a 100644 --- a/auto_tests/tests/CanvasAssertions.js +++ b/auto_tests/tests/CanvasAssertions.js @@ -86,6 +86,35 @@ CanvasAssertions.assertLineDrawn = function(proxy, p1, p2, attrs) { }; /** + * Return the lines drawn with specific attributes. + * + * This merely looks for one of these four possibilities: + * moveTo(p1) -> lineTo(p2) + * moveTo(p2) -> lineTo(p1) + * lineTo(p1) -> lineTo(p2) + * lineTo(p2) -> lineTo(p1) + * + * attrs is meant to be used when you want to track things like + * color and stroke width. + */ +CanvasAssertions.getLinesDrawn = function(proxy) { + var lastCall; + var lines = []; + for (var i = 0; i < proxy.calls__.length; i++) { + var call = proxy.calls__[i]; + + if (call.name == "lineTo") { + if (lastCall != null) { + lines.push([lastCall, call]); + } + } + + lastCall = (call.name === "lineTo" || call.name === "moveTo") ? call : null; + } + return lines; +}; + +/** * Verifies that every call to context.save() has a matching call to * context.restore(). */