X-Git-Url: https://adrianiainlam.tk/git/?a=blobdiff_plain;f=auto_tests%2Ftests%2FCanvasAssertions.js;h=8b521552f43587020c4f9a84dc7ad0b4d1143662;hb=d0c3910871966e227d08a5ea7d80b55981a19e88;hp=cd9994d3962dba29dbec6aedd69a55ebc6d44ed3;hpb=644eff8b76ca1a39ac2841d4f76a46a32042f071;p=dygraphs.git diff --git a/auto_tests/tests/CanvasAssertions.js b/auto_tests/tests/CanvasAssertions.js index cd9994d..8b52155 100644 --- a/auto_tests/tests/CanvasAssertions.js +++ b/auto_tests/tests/CanvasAssertions.js @@ -1,4 +1,4 @@ -// Copyright (c) 2011 Google, Inc. +// Copyright (c) 2011 Google, Inc. // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal @@ -42,8 +42,8 @@ CanvasAssertions.assertLineDrawn = function(proxy, p1, p2, attrs) { // found = 1 when prior loop found p1. // found = 2 when prior loop found p2. var priorFound = 0; - for (var callNum in proxy.calls__) { - var call = proxy.calls__[callNum]; + for (var i = 0; i < proxy.calls__.length; i++) { + var call = proxy.calls__[i]; // This disables lineTo -> moveTo pairs. if (call.name == "moveTo" && priorFound > 0) { @@ -85,6 +85,21 @@ CanvasAssertions.assertLineDrawn = function(proxy, p1, p2, attrs) { " and " + p2 + " with attributes " + toString(attrs)); } +/** + * Checks how many lines of the given color have been drawn. + * @return {Integer} The number of lines of the given color. + */ +CanvasAssertions.numLinesDrawn = function(proxy, color) { + var num_lines = 0; + for (var i = 0; i < proxy.calls__.length; i++) { + var call = proxy.calls__[i]; + if (call.name == "lineTo" && call.properties.strokeStyle == color) { + num_lines++; + } + } + return num_lines; +} + CanvasAssertions.matchPixels = function(expected, actual) { // Expect array of two integers. Assuming the values are within one // integer unit of each other. This should be tightened down by someone