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