|
1 var gWindowUtils; |
|
2 |
|
3 try { |
|
4 gWindowUtils = SpecialPowers.getDOMWindowUtils(window); |
|
5 if (gWindowUtils && !gWindowUtils.compareCanvases) |
|
6 gWindowUtils = null; |
|
7 } catch (e) { |
|
8 gWindowUtils = null; |
|
9 } |
|
10 |
|
11 function snapshotWindow(win, withCaret) { |
|
12 return SpecialPowers.snapshotWindow(win, withCaret); |
|
13 } |
|
14 |
|
15 // If the two snapshots don't compare as expected (true for equal, false for |
|
16 // unequal), returns their serializations as data URIs. In all cases, returns |
|
17 // whether the comparison was as expected. |
|
18 function compareSnapshots(s1, s2, expected) { |
|
19 var s1Str, s2Str; |
|
20 var correct = false; |
|
21 if (gWindowUtils) { |
|
22 // First, check that the canvases are the same size. |
|
23 var equal; |
|
24 if (s1.width != s2.width || s1.height != s2.height) { |
|
25 equal = false; |
|
26 } else { |
|
27 try { |
|
28 equal = (gWindowUtils.compareCanvases(s1, s2, {}) == 0); |
|
29 } catch (e) { |
|
30 equal = false; |
|
31 ok(false, "Exception thrown from compareCanvases: " + e); |
|
32 } |
|
33 } |
|
34 correct = (equal == expected); |
|
35 } |
|
36 |
|
37 if (!correct) { |
|
38 s1Str = s1.toDataURL(); |
|
39 s2Str = s2.toDataURL(); |
|
40 |
|
41 if (!gWindowUtils) { |
|
42 correct = ((s1Str == s2Str) == expected); |
|
43 } |
|
44 } |
|
45 |
|
46 return [correct, s1Str, s2Str]; |
|
47 } |
|
48 |
|
49 function assertSnapshots(s1, s2, expected, s1name, s2name) { |
|
50 var [correct, s1Str, s2Str] = compareSnapshots(s1, s2, expected); |
|
51 var sym = expected ? "==" : "!="; |
|
52 ok(correct, "reftest comparison: " + sym + " " + s1name + " " + s2name); |
|
53 if (!correct) { |
|
54 var report = "REFTEST TEST-UNEXPECTED-FAIL | " + s1name + " | image comparison (" + sym + ")\n"; |
|
55 if (expected) { |
|
56 report += "REFTEST IMAGE 1 (TEST): " + s1Str + "\n"; |
|
57 report += "REFTEST IMAGE 2 (REFERENCE): " + s2Str + "\n"; |
|
58 } else { |
|
59 report += "REFTEST IMAGE: " + s1Str + "\n"; |
|
60 } |
|
61 dump(report); |
|
62 } |
|
63 } |