2008-08-18 12:22:19 -07:00
|
|
|
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
|
|
|
|
|
2008-12-02 17:34:07 -08:00
|
|
|
var gWindowUtils;
|
2008-08-18 12:22:19 -07:00
|
|
|
|
|
|
|
try {
|
2011-07-01 10:03:43 -07:00
|
|
|
gWindowUtils = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor).getInterface(Components.interfaces.nsIDOMWindowUtils);
|
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) {
|
2010-09-03 15:53:28 -07:00
|
|
|
// drawWindow requires privileges, as might innerWidth/innerHeight if it's
|
|
|
|
// a cross domain window
|
|
|
|
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
|
|
|
|
|
2008-08-18 12:22:19 -07:00
|
|
|
var el = document.createElementNS("http://www.w3.org/1999/xhtml", "canvas");
|
|
|
|
el.width = win.innerWidth;
|
|
|
|
el.height = win.innerHeight;
|
|
|
|
|
2010-02-09 08:09:59 -08:00
|
|
|
var ctx = el.getContext("2d");
|
|
|
|
ctx.drawWindow(win, win.scrollX, win.scrollY,
|
|
|
|
win.innerWidth, win.innerHeight,
|
|
|
|
"rgb(255,255,255)",
|
|
|
|
withCaret ? ctx.DRAWWINDOW_DRAW_CARET : 0);
|
2008-08-18 12:22:19 -07:00
|
|
|
return el;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
|
|
|
|
|
|
|
|
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
|
|
|
}
|