michael@0: var gWindowUtils; michael@0: michael@0: try { michael@0: gWindowUtils = SpecialPowers.getDOMWindowUtils(window); michael@0: if (gWindowUtils && !gWindowUtils.compareCanvases) michael@0: gWindowUtils = null; michael@0: } catch (e) { michael@0: gWindowUtils = null; michael@0: } michael@0: michael@0: function snapshotWindow(win, withCaret) { michael@0: return SpecialPowers.snapshotWindow(win, withCaret); michael@0: } michael@0: michael@0: // If the two snapshots don't compare as expected (true for equal, false for michael@0: // unequal), returns their serializations as data URIs. In all cases, returns michael@0: // whether the comparison was as expected. michael@0: function compareSnapshots(s1, s2, expected) { michael@0: var s1Str, s2Str; michael@0: var correct = false; michael@0: if (gWindowUtils) { michael@0: // First, check that the canvases are the same size. michael@0: var equal; michael@0: if (s1.width != s2.width || s1.height != s2.height) { michael@0: equal = false; michael@0: } else { michael@0: try { michael@0: equal = (gWindowUtils.compareCanvases(s1, s2, {}) == 0); michael@0: } catch (e) { michael@0: equal = false; michael@0: ok(false, "Exception thrown from compareCanvases: " + e); michael@0: } michael@0: } michael@0: correct = (equal == expected); michael@0: } michael@0: michael@0: if (!correct) { michael@0: s1Str = s1.toDataURL(); michael@0: s2Str = s2.toDataURL(); michael@0: michael@0: if (!gWindowUtils) { michael@0: correct = ((s1Str == s2Str) == expected); michael@0: } michael@0: } michael@0: michael@0: return [correct, s1Str, s2Str]; michael@0: } michael@0: michael@0: function assertSnapshots(s1, s2, expected, s1name, s2name) { michael@0: var [correct, s1Str, s2Str] = compareSnapshots(s1, s2, expected); michael@0: var sym = expected ? "==" : "!="; michael@0: ok(correct, "reftest comparison: " + sym + " " + s1name + " " + s2name); michael@0: if (!correct) { michael@0: var report = "REFTEST TEST-UNEXPECTED-FAIL | " + s1name + " | image comparison (" + sym + ")\n"; michael@0: if (expected) { michael@0: report += "REFTEST IMAGE 1 (TEST): " + s1Str + "\n"; michael@0: report += "REFTEST IMAGE 2 (REFERENCE): " + s2Str + "\n"; michael@0: } else { michael@0: report += "REFTEST IMAGE: " + s1Str + "\n"; michael@0: } michael@0: dump(report); michael@0: } michael@0: }