};
fail("Can't find a line drawn between " + p1 +
" and " + p2 + " with attributes " + toString(attrs));
-}
+};
+
+/**
+ * Verifies that every call to context.save() has a matching call to
+ * context.restore().
+ */
+CanvasAssertions.assertBalancedSaveRestore = function(proxy) {
+ var depth = 0;
+ for (var i = 0; i < proxy.calls__.length; i++) {
+ var call = proxy.calls__[i];
+ if (call.name == "save") depth++
+ if (call.name == "restore") {
+ if (depth == 0) {
+ fail("Too many calls to restore()");
+ }
+ depth--;
+ }
+ }
+
+ if (depth > 0) {
+ fail("Missing matching 'context.restore()' calls.");
+ }
+};
/**
* Checks how many lines of the given color have been drawn.
}
}
return num_lines;
-}
+};
CanvasAssertions.matchPixels = function(expected, actual) {
// Expect array of two integers. Assuming the values are within one
// who knows what pixel a value of 5.8888 results in.
return Math.abs(expected[0] - actual[0]) < 1 &&
Math.abs(expected[1] - actual[1]) < 1;
-}
+};
CanvasAssertions.matchAttributes = function(expected, actual) {
for (var attr in expected) {
}
}
return true;
-}
+};
xy2 = g.toDomCoords(data[i + 1][0], data[i + 1][1][1]);
CanvasAssertions.assertLineDrawn(htx, xy1, xy2, attrs);
}
+ CanvasAssertions.assertBalancedSaveRestore(htx);
};
strokeStyle: "#008080",
lineWidth: 1
});
-}
+ CanvasAssertions.assertBalancedSaveRestore(htx);
+};
+
+SimpleDrawingTestCase.prototype.testDrawWithAxis = function() {
+ var graph = document.getElementById("graph");
+ var g = new Dygraph(graph, ZERO_TO_FIFTY);
+
+ var htx = g.hidden_ctx_;
+ CanvasAssertions.assertBalancedSaveRestore(htx);
+};
/**
* Tests that it is drawing dashes, and it remember the dash history between
htx = g.hidden_ctx_;
assertEquals(29, CanvasAssertions.numLinesDrawn(htx, "#ff0000"));
+ CanvasAssertions.assertBalancedSaveRestore(htx);
};