mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-03 20:49:27 +00:00
Bug 1087224 - Allow compareSnapshots and assertSnapshots to be passed fuzz values. r=smontagu
This commit is contained in:
parent
950664615e
commit
916e8d8c23
@ -45,14 +45,14 @@ function runDrawWindowTests(win, drawWindowFlags, transparentBackground) {
|
||||
refCx.fillRect(50, 10, 20, 20);
|
||||
refCx.fillStyle = "yellow";
|
||||
refCx.fillRect(90, 10, 20, 20);
|
||||
assertSnapshots(testCanvas, refCanvas, true /* equal */,
|
||||
assertSnapshots(testCanvas, refCanvas, true /* equal */, null /*no fuzz*/,
|
||||
"full draw of source on white background", "reference");
|
||||
|
||||
clearTest("white");
|
||||
testWrapCx.drawWindow(win, 0, 0, CANVAS_WIDTH, CANVAS_HEIGHT,
|
||||
"rgb(255, 255, 0)", drawWindowFlags);
|
||||
assertSnapshots(testCanvas, refCanvas,
|
||||
!transparentBackground /* not equal */,
|
||||
!transparentBackground /* not equal */, null /*no fuzz*/,
|
||||
"full draw of source on yellow background", "reference");
|
||||
|
||||
clearRef("yellow");
|
||||
@ -64,6 +64,7 @@ function runDrawWindowTests(win, drawWindowFlags, transparentBackground) {
|
||||
refCx.fillRect(90, 10, 20, 20);
|
||||
|
||||
assertSnapshots(testCanvas, refCanvas, transparentBackground /* equal */,
|
||||
null /*no fuzz*/,
|
||||
"full draw of source on yellow background", "reference");
|
||||
|
||||
// Test drawing a region within the document.
|
||||
@ -77,7 +78,7 @@ function runDrawWindowTests(win, drawWindowFlags, transparentBackground) {
|
||||
refCx.fillStyle = "aqua";
|
||||
refCx.fillRect(17 + 10, 31 + 10, 20, 20);
|
||||
|
||||
assertSnapshots(testCanvas, refCanvas, true /* equal */,
|
||||
assertSnapshots(testCanvas, refCanvas, true /* equal */, null /*no fuzz*/,
|
||||
"draw of subrect of source with matching background",
|
||||
"reference");
|
||||
|
||||
@ -96,7 +97,7 @@ function runDrawWindowTests(win, drawWindowFlags, transparentBackground) {
|
||||
refCx.fillStyle = "aqua";
|
||||
refCx.fillRect(17 + 10, 31 + 10, 20, 20);
|
||||
|
||||
assertSnapshots(testCanvas, refCanvas, true /* equal */,
|
||||
assertSnapshots(testCanvas, refCanvas, true /* equal */, null /*no fuzz*/,
|
||||
"draw of subrect of source with different background",
|
||||
"reference");
|
||||
|
||||
@ -114,7 +115,7 @@ function runDrawWindowTests(win, drawWindowFlags, transparentBackground) {
|
||||
refCx.fillStyle = "aqua";
|
||||
refCx.fillRect(17 + 10, 31 + 10, 20, 20);
|
||||
|
||||
assertSnapshots(testCanvas, refCanvas, true /* equal */,
|
||||
assertSnapshots(testCanvas, refCanvas, true /* equal */, null /*no fuzz*/,
|
||||
"draw of subrect of source with different background",
|
||||
"reference");
|
||||
|
||||
@ -151,7 +152,7 @@ function runDrawWindowTests(win, drawWindowFlags, transparentBackground) {
|
||||
refCx.fillStyle = "yellow";
|
||||
refCx.fillRect(9 + 15 + 5, 3 + 0 + 5, 20, 20);
|
||||
|
||||
assertSnapshots(testCanvas, refCanvas, true /* equal */,
|
||||
assertSnapshots(testCanvas, refCanvas, true /* equal */, null /*no fuzz*/,
|
||||
"multiple drawWindow calls on top of each other",
|
||||
"reference");
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ function callbackTestIframe(iframe)
|
||||
// Using assertSnapshots is important to get the data-URIs of failing tests
|
||||
// dumped into the log in a format that reftest-analyzer.xhtml can process.
|
||||
var passed = assertSnapshots(result.snapshot, reference.snapshot, true,
|
||||
result.src, reference.src);
|
||||
null /*no fuzz*/, result.src, reference.src);
|
||||
|
||||
// Remove the iframes if the test was successful
|
||||
if (passed) {
|
||||
|
@ -262,7 +262,8 @@ function doTest(aTest)
|
||||
aTest.decoration.style == kDecorationStyleWavy) {
|
||||
todo(false, "Rendering of" + description);
|
||||
} else {
|
||||
assertSnapshots(result.snapshot, reference.snapshot, true, description, "");
|
||||
assertSnapshots(result.snapshot, reference.snapshot, true,
|
||||
null /*no fuzz*/, description, "");
|
||||
}
|
||||
|
||||
canvases = [];
|
||||
|
@ -15,7 +15,7 @@ function snapshotWindow(win, withCaret) {
|
||||
// If the two snapshots don't compare as expected (true for equal, false for
|
||||
// unequal), returns their serializations as data URIs. In all cases, returns
|
||||
// whether the comparison was as expected.
|
||||
function compareSnapshots(s1, s2, expected) {
|
||||
function compareSnapshots(s1, s2, expected, fuzz) {
|
||||
var s1Str, s2Str;
|
||||
var correct = false;
|
||||
if (gWindowUtils) {
|
||||
@ -25,7 +25,14 @@ function compareSnapshots(s1, s2, expected) {
|
||||
equal = false;
|
||||
} else {
|
||||
try {
|
||||
equal = (gWindowUtils.compareCanvases(s1, s2, {}) == 0);
|
||||
var maxDifference = {};
|
||||
var numDifferentPixels = gWindowUtils.compareCanvases(s1, s2, maxDifference);
|
||||
if (!fuzz) {
|
||||
equal = (numDifferentPixels == 0);
|
||||
} else {
|
||||
equal = (numDifferentPixels <= fuzz.numDifferentPixels &&
|
||||
maxDifference.value <= fuzz.maxDifference);
|
||||
}
|
||||
} catch (e) {
|
||||
equal = false;
|
||||
ok(false, "Exception thrown from compareCanvases: " + e);
|
||||
@ -46,8 +53,8 @@ function compareSnapshots(s1, s2, expected) {
|
||||
return [correct, s1Str, s2Str];
|
||||
}
|
||||
|
||||
function assertSnapshots(s1, s2, expected, s1name, s2name) {
|
||||
var [correct, s1Str, s2Str] = compareSnapshots(s1, s2, expected);
|
||||
function assertSnapshots(s1, s2, expected, fuzz, s1name, s2name) {
|
||||
var [correct, s1Str, s2Str] = compareSnapshots(s1, s2, expected, fuzz);
|
||||
var sym = expected ? "==" : "!=";
|
||||
ok(correct, "reftest comparison: " + sym + " " + s1name + " " + s2name);
|
||||
if (!correct) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user