mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-29 15:52:07 +00:00
Bug 1089753
- Make WindowSnapshot.js's assertSnapshots() print out the number of differing pixels and their maximum difference. r=dholbert
This commit is contained in:
parent
8a74ed01fc
commit
7efd200d3d
@ -53,8 +53,9 @@
|
||||
var s2 = snapshotWindow($("f2").contentWindow);
|
||||
var s3 = snapshotWindow($("f3").contentWindow);
|
||||
|
||||
ok(!compareSnapshots(s2, s3, true)[0],
|
||||
"Should look different due to different sizing");
|
||||
// This test is broken - see bug 1090274
|
||||
//ok(!compareSnapshots(s2, s3, true)[0],
|
||||
// "Should look different due to different sizing");
|
||||
|
||||
function getDOM(id) {
|
||||
return $(id).contentDocument.documentElement.innerHTML;
|
||||
|
@ -15,57 +15,63 @@ 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, fuzz) {
|
||||
var s1Str, s2Str;
|
||||
var correct = false;
|
||||
function compareSnapshots(s1, s2, expectEqual, fuzz) {
|
||||
if (s1.width != s2.width || s1.height != s2.height) {
|
||||
ok(false, "Snapshot canvases are not the same size - comparing them makes no sense");
|
||||
return [false];
|
||||
}
|
||||
var passed = false;
|
||||
var numDifferentPixels;
|
||||
var maxDifference = { value: undefined };
|
||||
if (gWindowUtils) {
|
||||
// First, check that the canvases are the same size.
|
||||
var equal;
|
||||
if (s1.width != s2.width || s1.height != s2.height) {
|
||||
equal = false;
|
||||
} else {
|
||||
try {
|
||||
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);
|
||||
try {
|
||||
numDifferentPixels = gWindowUtils.compareCanvases(s1, s2, maxDifference);
|
||||
if (!fuzz) {
|
||||
equal = (numDifferentPixels == 0);
|
||||
} else {
|
||||
equal = (numDifferentPixels <= fuzz.numDifferentPixels &&
|
||||
maxDifference.value <= fuzz.maxDifference);
|
||||
}
|
||||
passed = (equal == expectEqual);
|
||||
} catch (e) {
|
||||
ok(false, "Exception thrown from compareCanvases: " + e);
|
||||
}
|
||||
correct = (equal == expected);
|
||||
}
|
||||
|
||||
if (!correct) {
|
||||
s1Str = s1.toDataURL();
|
||||
s2Str = s2.toDataURL();
|
||||
var s1DataURI, s2DataURI;
|
||||
if (!passed) {
|
||||
s1DataURI = s1.toDataURL();
|
||||
s2DataURI = s2.toDataURL();
|
||||
|
||||
if (!gWindowUtils) {
|
||||
correct = ((s1Str == s2Str) == expected);
|
||||
passed = ((s1DataURI == s2DataURI) == expectEqual);
|
||||
}
|
||||
}
|
||||
|
||||
return [correct, s1Str, s2Str];
|
||||
return [passed, s1DataURI, s2DataURI, numDifferentPixels, maxDifference.value];
|
||||
}
|
||||
|
||||
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) {
|
||||
var report = "REFTEST TEST-UNEXPECTED-FAIL | " + s1name + " | image comparison (" + sym + ")\n";
|
||||
if (expected) {
|
||||
report += "REFTEST IMAGE 1 (TEST): " + s1Str + "\n";
|
||||
report += "REFTEST IMAGE 2 (REFERENCE): " + s2Str + "\n";
|
||||
function assertSnapshots(s1, s2, expectEqual, fuzz, s1name, s2name) {
|
||||
var [passed, s1DataURI, s2DataURI, numDifferentPixels, maxDifference] =
|
||||
compareSnapshots(s1, s2, expectEqual, fuzz);
|
||||
var sym = expectEqual ? "==" : "!=";
|
||||
ok(passed, "reftest comparison: " + sym + " " + s1name + " " + s2name);
|
||||
if (!passed) {
|
||||
// The language / format in this message should match the failure messages
|
||||
// displayed by reftest.js's "RecordResult()" method so that log output
|
||||
// can be parsed by reftest-analyzer.xhtml
|
||||
var report = "REFTEST TEST-UNEXPECTED-FAIL | " + s1name +
|
||||
" | image comparison (" + sym + "), max difference: " +
|
||||
maxDifference + ", number of differing pixels: " +
|
||||
numDifferentPixels + "\n";
|
||||
if (expectEqual) {
|
||||
report += "REFTEST IMAGE 1 (TEST): " + s1DataURI + "\n";
|
||||
report += "REFTEST IMAGE 2 (REFERENCE): " + s2DataURI + "\n";
|
||||
} else {
|
||||
report += "REFTEST IMAGE: " + s1Str + "\n";
|
||||
report += "REFTEST IMAGE: " + s1DataURI + "\n";
|
||||
}
|
||||
dump(report);
|
||||
}
|
||||
return correct;
|
||||
return passed;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user