+/**
+ * Assert that all elements have a certain style property.
+ */
+Util.assertStyleOfChildren = function(selector, property, expectedValue) {
+ assertTrue(selector.length > 0);
+ $.each(selector, function(idx, child) {
+ assertEquals(expectedValue, $(child).css(property));
+ });
+};
+
+
+/**
+ * Takes in an array of strings and returns an array of floats.
+ */
+Util.makeNumbers = function(ary) {
+ var ret = [];
+ for (var i = 0; i < ary.length; i++) {
+ ret.push(parseFloat(ary[i]));
+ }
+ return ret;
+};
+
+
+/**
+ * Sample a pixel from the canvas.
+ * Returns an [r, g, b, a] tuple where each values is in [0, 255].
+ */
+Util.samplePixel = function(canvas, x, y) {
+ var ctx = canvas.getContext("2d"); // bypasses Proxy if applied.
+
+ // TODO(danvk): Any performance issues with this?
+ var imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
+
+ var i = 4 * (x + imageData.width * y);
+ var d = imageData.data;
+ return [d[i], d[i+1], d[i+2], d[i+3]];
+};