<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -0,0 +1,63 @@
+(function(){
+  /**
+   * @private
+   * @method iterateData
+   * @param {CanvasRenderingContext2D} ctx context to test
+   * @param {Function} fn Callback, invoked with `currentValue`, `previousValue` and `index`. 
+   *                      Breaks out of the loop if callback returns `false`.
+   */
+  function iterateData(ctx, fn) {
+    var data = ctx.getImageData(0, 0, ctx.canvas.width, ctx.canvas.height).data;
+    for (var i = data.length; i--; ) {
+      if (i &gt; 4) {
+        if (fn(data[i], data[i - 4], i) === false) break;
+      }
+    }
+  }
+  
+  /**
+   * @method assertColor
+   * @param {CanvasRenderingContext2D} ctx context to test
+   * @param {String} color color in a hex value
+   * @return {Boolean | null} `true` if all canvas pixels are of a given color, `null` if wrong color is given 
+   * @example `assertColor(canvas._oContextContainer, 'ff5555');`
+   */
+  function assertColor(ctx, color) {
+    var match, r, g, b;
+    if (match = String(color).match(/^#?([a-f0-9]{2})([a-f0-9]{2})([a-f0-9]{2})$/i)) {
+      r = parseInt(match[1], 16);
+      g = parseInt(match[2], 16);
+      b = parseInt(match[3], 16);
+    }
+    else return null;
+    var result = true;
+    iterateData(ctx, function(currentValue, prevValue, i) {
+      if ((!(i % 4) &amp;&amp; (currentValue !== r)) ||
+          (!((i-1) % 4) &amp;&amp; (currentValue !== g)) ||
+          (!((i-2) % 4) &amp;&amp; (currentValue !== b))) {
+        return (result = false);
+      }
+    });
+    return result;
+  }
+  
+  /**
+   * @method assertSameColor
+   * @param {CanvasRenderingContext2D} ctx context to test
+   * @return {Boolean} `true` if all canvas pixels are of the same color
+   * @example `assertSameColor(canvas._oContextContainer);`
+   */
+  function assertSameColor(ctx) {
+    var result = true;
+    iterateData(ctx, function(currentValue, prevValue, i) {
+      if (currentValue !== prevValue) {
+        return (result = false);
+      }
+    });
+    return result;
+  }
+
+  // export as global
+  this.assertColor = assertColor;
+  this.assertSameColor = assertSameColor;
+})();
\ No newline at end of file</diff>
      <filename>canvas_assertions.js</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>5c1da6016b51fdc8edb3b188855ca310b00ec257</id>
    </parent>
  </parents>
  <author>
    <name>Juriy Zaytsev</name>
    <email>juriy@kangax.local</email>
  </author>
  <url>http://github.com/kangax/protolicious/commit/889a60d6d22cd59e93664ae04866e245c89b35aa</url>
  <id>889a60d6d22cd59e93664ae04866e245c89b35aa</id>
  <committed-date>2009-04-24T09:17:05-07:00</committed-date>
  <authored-date>2009-04-24T09:17:05-07:00</authored-date>
  <message>Add `assertColor` and `assertSameColor`.</message>
  <tree>fc5f7e1f9faaee7798c10e160e72d3a0dd04714a</tree>
  <committer>
    <name>Juriy Zaytsev</name>
    <email>juriy@kangax.local</email>
  </committer>
</commit>
