bug 1322422 use assertSnapshots() to log failures better r?ehsan draft
authorKarl Tomlinson <karlt+@karlt.net>
Tue, 06 Dec 2016 22:38:23 -1000
changeset 448066 2dfc9379d15043b8aea2d5f02c193b2c28b1d300
parent 447934 d8f63b2935af0915a6a24b3ea8e27d9a09f66416
child 539201 d16f2deaef5fa560567646adc0147d9b6651e3fe
push id38246
push userktomlinson@mozilla.com
push dateFri, 09 Dec 2016 01:11:51 +0000
reviewersehsan
bugs1322422
milestone53.0a1
bug 1322422 use assertSnapshots() to log failures better r?ehsan MozReview-Commit-ID: 54WgoCdKjMX
editor/libeditor/tests/browser_bug629172.js
--- a/editor/libeditor/tests/browser_bug629172.js
+++ b/editor/libeditor/tests/browser_bug629172.js
@@ -28,22 +28,18 @@ add_task(function*() {
       LTRRef.style.display = "";
       document.body.clientWidth;
       window.Screenshots.ltr = window.snapshotWindow(window);
       LTRRef.parentNode.removeChild(LTRRef);
       RTLRef.style.display = "";
       document.body.clientWidth;
       window.Screenshots.rtl = window.snapshotWindow(window);
       RTLRef.parentNode.removeChild(RTLRef);
-      window.Screenshots.get = function(dir, flip) {
-        if (flip) {
-          return this[dir == "rtl" ? "ltr" : "rtl"];
-        } else {
-          return this[dir];
-        }
+      window.Screenshots.get = function(dir) {
+        return this[dir];
       };
     });
 
     function simulateCtrlShiftX(aBrowser) {
       // In e10s, the keypress event will be dispatched to the content process,
       // but in non-e10s it is handled by the browser UI code and hence won't
       // reach the web page.  As a result, we need to observe the event in
       // the content process only in e10s mode.
@@ -63,44 +59,60 @@ add_task(function*() {
         var t = window.t = document.createElement("textarea");
         t.setAttribute("dir", initialDir);
         t.value = "test.";
         window.inputEventCount = 0;
         t.oninput = function() { window.inputEventCount++; };
         document.getElementById("content").appendChild(t);
         document.body.clientWidth;
         var s1 = window.snapshotWindow(window);
-        ok(window.compareSnapshots(s1, window.Screenshots.get(initialDir, false), true)[0],
-           "Textarea should appear correctly before switching the direction (" + initialDir + ")");
+        window.ok = ok; // for assertSnapshots
+        window.
+          assertSnapshots(s1, window.Screenshots.get(initialDir), true,
+                          /* fuzz = */ null,
+                          "Textarea before switching the direction from " +
+                            initialDir,
+                          "Reference " + initialDir + " textarea");
         t.focus();
         is(window.inputEventCount, 0, "input event count must be 0 before");
       });
       yield simulateCtrlShiftX(aBrowser);
       yield ContentTask.spawn(aBrowser, {initialDir}, function({initialDir}) {
         var window = content.window.wrappedJSObject;
-
-        is(window.t.getAttribute("dir"), initialDir == "ltr" ? "rtl" : "ltr", "The dir attribute must be correctly updated");
+        var expectedDir = initialDir == "ltr" ? "rtl" : "ltr"
+        is(window.t.getAttribute("dir"), expectedDir,
+           "The dir attribute must be correctly updated");
         is(window.inputEventCount, 1, "input event count must be 1 after");
         window.t.blur();
         var s2 = window.snapshotWindow(window);
-        ok(window.compareSnapshots(s2, window.Screenshots.get(initialDir, true), true)[0],
-           "Textarea should appear correctly after switching the direction (" + initialDir + ")");
+        window.ok = ok; // for assertSnapshots
+        window.
+          assertSnapshots(s2, window.Screenshots.get(expectedDir), true,
+                        /* fuzz = */ null,
+                          "Textarea after switching the direction from " +
+                            initialDir,
+                          "Reference " + expectedDir + " textarea");
         window.t.focus();
         is(window.inputEventCount, 1, "input event count must be 1 before");
       });
       yield simulateCtrlShiftX(aBrowser);
       yield ContentTask.spawn(aBrowser, {initialDir}, function({initialDir}) {
         var window = content.window.wrappedJSObject;
 
         is(window.inputEventCount, 2, "input event count must be 2 after");
         is(window.t.getAttribute("dir"), initialDir == "ltr" ? "ltr" : "rtl", "The dir attribute must be correctly updated");
         window.t.blur();
         var s3 = window.snapshotWindow(window);
-        ok(window.compareSnapshots(s3, window.Screenshots.get(initialDir, false), true)[0],
-           "Textarea should appear correctly after switching back the direction (" + initialDir + ")");
+        window.ok = ok; // for assertSnapshots
+        window.
+          assertSnapshots(s3, window.Screenshots.get(initialDir), true,
+                          /* fuzz = */ null,
+                          "Textarea after switching back the direction to " +
+                            initialDir,
+                          "Reference " + initialDir + " textarea");
         window.t.parentNode.removeChild(window.t);
       });
     }
 
     yield testDirection("ltr", aBrowser);
     yield testDirection("rtl", aBrowser);
   });
 });