describe("Integration test", function () {
    var canvas = $('<canvas width="204" height="100"></canvas>'), // Firefox adds a space between the divs and needs the canvas to fit horizontally for all content to be rendered
        finished = false,
        callback = function () { finished = true; },
        referenceImg;

    var loadDocFixture = function (url, callback) {
        var request = new window.XMLHttpRequest(),
            doc;

        request.onreadystatechange = function () {
            if (request.readyState === 4) {
                callback(request.responseXML);
            }
        };
        request.open('GET', url, true);
        // Seems to not work on Safari (https://developer.mozilla.org/en/HTML_in_XMLHttpRequest)
        request.responseType = "document";
        request.overrideMimeType("text/html");
        request.send(null);

        return doc;
    };

    beforeEach(function () {
        this.addMatchers(imagediff.jasmine);

        referenceImg = $('<img src="'+ jasmine.getFixtures().fixturesPath + '/testResult.png" alt="test image"/>');
        finished = false;
    });

    ifNotInWebkitIt("should take a document, inline all displayable content and render to the given canvas (flaky in Firefox)", function () {
        var doc = null;

        loadDocFixture(jasmine.getFixtures().fixturesPath + "test.html", function (xmlDoc) {
            doc = xmlDoc;
        });

        waitsFor(function () {
            return doc !== null;
        });

        runs(function () {
            rasterizeHTML.drawDocument(doc, canvas.get(0), callback);
        });

        waitsFor(function () {
            return finished;
        });

        runs(function () {
            expect(canvas.get(0)).toImageDiffEqual(referenceImg.get(0), 50);
        });
    });

    ifNotInWebkitIt("should take a HTML string, inline all displayable content and render to the given canvas (flaky in Firefox)", function () {
        var html = null;

        html = readFixtures("test.html");

        runs(function () {
            rasterizeHTML.drawHTML(html, canvas.get(0), {baseUrl: jasmine.getFixtures().fixturesPath}, callback);
        });

        waitsFor(function () {
            return finished;
        });

        runs(function () {
            expect(canvas.get(0)).toImageDiffEqual(referenceImg.get(0), 70);
        });
    });

    ifNotInWebkitIt("should take a URL, inline all displayable content and render to the given canvas (flaky in Firefox)", function () {
        runs(function () {
            rasterizeHTML.drawURL(jasmine.getFixtures().fixturesPath + "test.html", canvas.get(0), callback);
        });

        waitsFor(function () {
            return finished;
        });

        runs(function () {
            expect(canvas.get(0)).toImageDiffEqual(referenceImg.get(0), 90);
        });
    });

});
@@ -54,259 +54,29 @@
 nvas
- = $('%3Ccanvas width=%22204%22 height=%22100%22%3E%3C/canvas%3E'), // Firefox adds a space between the divs and needs the canvas to fit horizontally for all content to be rendered%0A        finished = false,%0A        callback = function () %7B finished = true; %7D,%0A       
+, finished, callback,
  ref
@@ -732,16 +732,195 @@
 asmine);
+%0A        canvas = $('%3Ccanvas width=%22204%22 height=%22100%22%3E%3C/canvas%3E'); // Firefox adds a space between the divs and needs the canvas to fit horizontally for all content to be rendered
 %0A%0A      
@@ -1029,16 +1029,17 @@
 e%22/%3E');%0A
+%0A
         
@@ -1056,16 +1056,112 @@
  false;%0A
+        callback = jasmine.createSpy(%22callback%22).andCallFake(function () %7B finished = true; %7D);%0A
     %7D);%0A
@@ -1614,32 +1614,48 @@
 , canvas.get(0),
+ %7Bcache: false%7D,
  callback);%0A    
@@ -1755,32 +1755,102 @@
 s(function () %7B%0A
+            expect(callback).toHaveBeenCalledWith(canvas.get(0), %5B%5D);%0A
             expe
@@ -1909,9 +1909,9 @@
 0), 
-5
+1
 0);%0A
@@ -2272,16 +2272,30 @@
 uresPath
+, cache: false
 %7D, callb
@@ -2405,32 +2405,102 @@
 s(function () %7B%0A
+            expect(callback).toHaveBeenCalledWith(canvas.get(0), %5B%5D);%0A
             expe
@@ -2843,16 +2843,32 @@
 .get(0),
+ %7Bcache: false%7D,
  callbac
@@ -2976,32 +2976,102 @@
 s(function () %7B%0A
+            expect(callback).toHaveBeenCalledWith(canvas.get(0), %5B%5D);%0A
             expe

Fix integration tests