var CanvasAssertions = {};
/**
+ * Updates path attributes to match fill/stroke operations.
+ *
+ * This sets fillStyle to undefined for stroked paths,
+ * and strokeStyle to undefined for filled paths, to simplify
+ * matchers such as numLinesDrawn.
+ *
+ * @private
+ * @param {Array.<Object>} List of operations.
+ */
+CanvasAssertions.cleanPathAttrs_ = function(calls) {
+ var isStroked = true;
+ for (var i = calls.length - 1; i >= 0; --i) {
+ var call = calls[i];
+ var name = call.name;
+ if (name == 'stroke') {
+ isStroked = true;
+ } else if (name == 'fill') {
+ isStroked = false;
+ } else if (name == 'lineTo') {
+ if (isStroked) {
+ call.properties.fillStyle = undefined;
+ } else {
+ call.properties.strokeStyle = undefined;
+ }
+ }
+ }
+};
+
+
+/**
* Assert that a line is drawn between the two points
*
* This merely looks for one of these four possibilities:
* or a function that accepts the current call.
*/
CanvasAssertions.assertLineDrawn = function(proxy, p1, p2, predicate) {
+ CanvasAssertions.cleanPathAttrs_(proxy.calls__);
// found = 1 when prior loop found p1.
// found = 2 when prior loop found p2.
var priorFound = 0;
}
}
if (priorFound == 2 && matchp1) {
- if (CanvasAssertions.match(predicate, call.properties)) {
+ if (CanvasAssertions.match(predicate, call)) {
return;
}
}
* color and stroke width.
*/
CanvasAssertions.getLinesDrawn = function(proxy, predicate) {
+ CanvasAssertions.cleanPathAttrs_(proxy.calls__);
var lastCall;
var lines = [];
for (var i = 0; i < proxy.calls__.length; i++) {
// common case. Possibly allow predicate to be function, hash, or
// string representing color?
CanvasAssertions.numLinesDrawn = function(proxy, color) {
+ CanvasAssertions.cleanPathAttrs_(proxy.calls__);
var num_lines = 0;
for (var i = 0; i < proxy.calls__.length; i++) {
var call = proxy.calls__[i];