2008-12-02 17:34:07 -08:00
|
|
|
var gWindowUtils;
|
2008-08-18 12:22:19 -07:00
|
|
|
|
|
|
|
try {
|
2011-07-21 13:21:24 -07:00
|
|
|
gWindowUtils = SpecialPowers.DOMWindowUtils;
|
2008-12-02 17:34:07 -08:00
|
|
|
if (gWindowUtils && !gWindowUtils.compareCanvases)
|
|
|
|
gWindowUtils = null;
|
2008-08-18 12:22:19 -07:00
|
|
|
} catch (e) {
|
2008-12-02 17:34:07 -08:00
|
|
|
gWindowUtils = null;
|
2008-08-18 12:22:19 -07:00
|
|
|
}
|
|
|
|
|
2010-02-09 08:09:59 -08:00
|
|
|
function snapshotWindow(win, withCaret) {
|
2011-07-21 13:21:24 -07:00
|
|
|
return SpecialPowers.snapshotWindow(win, withCaret);
|
2008-08-18 12:22:19 -07:00
|
|
|
}
|
|
|
|
|
2009-02-19 19:04:19 -08:00
|
|
|
// 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) {
|
2008-08-18 12:22:19 -07:00
|
|
|
var s1Str, s2Str;
|
2009-02-19 19:04:19 -08:00
|
|
|
var correct = false;
|
2008-12-02 17:34:07 -08:00
|
|
|
if (gWindowUtils) {
|
2011-07-12 09:06:34 -07:00
|
|
|
// First, check that the canvases are the same size.
|
|
|
|
var equal;
|
|
|
|
if (s1.width != s2.width || s1.height != s2.height) {
|
|
|
|
equal = false;
|
|
|
|
} else {
|
|
|
|
try {
|
|
|
|
equal = (gWindowUtils.compareCanvases(s1, s2, {}) == 0);
|
|
|
|
} catch (e) {
|
|
|
|
equal = false;
|
|
|
|
ok(false, "Exception thrown from compareCanvases: " + e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
correct = (equal == expected);
|
2008-08-18 12:22:19 -07:00
|
|
|
}
|
|
|
|
|
2009-02-19 19:04:19 -08:00
|
|
|
if (!correct) {
|
2008-08-18 12:22:19 -07:00
|
|
|
s1Str = s1.toDataURL();
|
|
|
|
s2Str = s2.toDataURL();
|
|
|
|
|
2008-12-02 17:34:07 -08:00
|
|
|
if (!gWindowUtils) {
|
2009-02-19 19:04:19 -08:00
|
|
|
correct = ((s1Str == s2Str) == expected);
|
2008-08-18 12:22:19 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-19 19:04:19 -08:00
|
|
|
return [correct, s1Str, s2Str];
|
2008-08-18 12:22:19 -07:00
|
|
|
}
|