canvasAppearanceTest(name, width, height, method, expectedSrc, tolerance = 256) {
        this.test(name, status => {
            let actualCanvas = /** @type {!HTMLCanvasElement} */ document.createElement("canvas");
            actualCanvas.width = width;
            actualCanvas.height = height;
            method(actualCanvas, status);
            let actualData = actualCanvas.getContext("2d").getImageData(0, 0, actualCanvas.width, actualCanvas.height);

            return promiseImageDataFromSrc(expectedSrc).then(expectedData => {
                let mse = meanSquaredError(actualData.data, expectedData.data);
                if (expectedData.width !== actualData.width ||
                    expectedData.height !== actualData.height ||
                    mse > tolerance) {

                    let actualSrc = actualCanvas.toDataURL("image/png");
                    fail(`Drawn image <\n\n${actualSrc}\n\n> differed with MSE=${mse} from <\n${expectedSrc}\n>.`);
                }

                // When things get hairy, it's useful to see the tolerance-vs-difference. But usually it's just noise.
                //if (mse > 0) {
                //    let s = `${this.name}.${name} image differed, but within tolerance (MSE=${mse}).`;
                //    (mse < 0.1 ? console.info : console.warn)(s);
                //}
            });
        });
    }
A test that compares the drawing, performed by the test method on the given canvas, to the given expected image
or data.
@param {!string} name
@param {!int} width
@param {!int} height
@param {!function(!HTMLCanvasElement, !{ warn_only: !boolean|!string })} method
@param {!string} expectedSrc Either the location of an accessible image, or a 'data:image/' link.
@param {!int=} tolerance