Bug 1345873 - Part 0: Minor cleanup in existing test_flexbox_order mochitests. a=test-only
authorDaniel Holbert <dholbert@cs.stanford.edu>
Fri, 10 Mar 2017 13:37:00 -0500
changeset 379484 dd6de9fcdc8f7e2dc5b3c00ee586fbac3c1c40ab
parent 379483 37a857c0c3d33d51fb8a0f020e7553e69629b65d
child 379485 15eeffc957863531c7fc42ef8b0a39406b0a195e
push id1419
push userjlund@mozilla.com
push dateMon, 10 Apr 2017 20:44:07 +0000
treeherdermozilla-release@5e6801b73ef6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstest-only
bugs1345873
milestone53.0
Bug 1345873 - Part 0: Minor cleanup in existing test_flexbox_order mochitests. a=test-only This patch: - does s/var/let/ to upgrade to modern JS best-practices. - Wraps some lines that are too long. - Changes loops to "for (let foo of [...])" rather than foreach+function-pointer. - Changes some copypasted cleanup code to use a loop instead (which will be especially useful in a forthcoming version of this test that'll add another thing to clean up). MozReview-Commit-ID: DWK8jFbfqeB
layout/style/test/test_flexbox_order.html
layout/style/test/test_flexbox_order_table.html
--- a/layout/style/test/test_flexbox_order.html
+++ b/layout/style/test/test_flexbox_order.html
@@ -57,17 +57,17 @@ https://bugzilla.mozilla.org/show_bug.cg
     <div class="ref" id="bac"><refB></refB><refA></refA><refC></refC></div>
     <div class="ref" id="bca"><refB></refB><refC></refC><refA></refA></div>
     <div class="ref" id="cab"><refC></refC><refA></refA><refB></refB></div>
     <div class="ref" id="cba"><refC></refC><refB></refB><refA></refA></div>
   </div>
 
   <div id="flexContainerParent">
     <!-- The flex container that we'll be testing
-         (its  parent is display:none initially) -->
+         (its parent is display:none initially) -->
     <div id="flexContainer">
       <div id="a"></div>
       <div id="b"></div>
       <div id="c"></div>
     </div>
   </div>
 
 </div>
@@ -83,23 +83,23 @@ https://bugzilla.mozilla.org/show_bug.cg
  * Note: The items in this testcase don't overlap, so this testcase does _not_
  * test paint ordering.  It only tests horizontal ordering in a flex container.
  */
 
 // DATA
 // ----
 
 // This will store snapshots of our reference divs
-var gRefSnapshots = {};
+let gRefSnapshots = {};
 
 // These are the sets of 'order' values that we'll test.
 // The first three values in each array are the 'order' values that we'll
 // assign to elements a, b, and c (respectively).  The final value in each
 // array is the ID of the expected reference rendering.
-var gOrderTestcases = [
+let gOrderTestcases = [
   // The 6 basic permutations:
   [ 1, 2, 3, "abc"],
   [ 1, 3, 2, "acb"],
   [ 2, 1, 3, "bac"],
   [ 2, 3, 1, "cab"],
   [ 3, 1, 2, "bca"],
   [ 3, 2, 1, "cba"],
 
@@ -122,65 +122,67 @@ var gOrderTestcases = [
   [ "3.0", "2.0", "1.0", "abc"],
   [ 3, "2.0", 1, "bca"],
 ];
 
 // FUNCTIONS
 // ---------
 
 function initRefSnapshots() {
-  var refIds = ["abc", "acb", "bac", "bca", "cab", "cba"];
-  refIds.forEach(function(aRefId) {
-    var elem = document.getElementById(aRefId);
+  let refIds = ["abc", "acb", "bac", "bca", "cab", "cba"];
+  for (let id of refIds) {
+    let elem = document.getElementById(id);
     elem.style.display = "block";
-    gRefSnapshots[aRefId] = snapshotWindow(window, false);
+    gRefSnapshots[id] = snapshotWindow(window, false);
     elem.style.display = "";
-  });
+  }
 }
 
 function complainIfSnapshotsDiffer(aSnap1, aSnap2, aMsg) {
-  var compareResult = compareSnapshots(aSnap1, aSnap2, true);
-  ok(compareResult[0], "flex container rendering should match expected (" + aMsg +")");
+  let compareResult = compareSnapshots(aSnap1, aSnap2, true);
+  ok(compareResult[0],
+     "flex container rendering should match expected (" + aMsg +")");
   if (!compareResult[0]) {
     todo(false, "TESTCASE: " + compareResult[1]);
     todo(false, "REFERENCE: "+ compareResult[2]);
   }
 }
 
 function runOrderTestcase(aOrderTestcase) {
   // Sanity-check
   ok(Array.isArray(aOrderTestcase), "expecting testcase to be an array");
   is(aOrderTestcase.length, 4, "expecting testcase to have 4 elements");
 
   document.getElementById("a").style.order = aOrderTestcase[0];
   document.getElementById("b").style.order = aOrderTestcase[1];
   document.getElementById("c").style.order = aOrderTestcase[2];
 
-  var snapshot = snapshotWindow(window, false);
+  let snapshot = snapshotWindow(window, false);
   complainIfSnapshotsDiffer(snapshot, gRefSnapshots[aOrderTestcase[3]],
                             aOrderTestcase);
 
   // Clean up
-  document.getElementById("a").style.order = "";
-  document.getElementById("b").style.order = "";
-  document.getElementById("c").style.order = "";
+  for (let id of ["a", "b", "c"]) {
+    document.getElementById(id).style.order = "";
+  }
 }
 
 // Main Function
 function main() {
   initRefSnapshots();
 
   // un-hide the flex container's parent
-  var flexContainerParent = document.getElementById("flexContainerParent");
+  let flexContainerParent = document.getElementById("flexContainerParent");
   flexContainerParent.style.display = "block";
 
   // Initial sanity-check: should be in expected document order
-  var initialSnapshot = snapshotWindow(window, false);
+  let initialSnapshot = snapshotWindow(window, false);
   complainIfSnapshotsDiffer(initialSnapshot, gRefSnapshots["abc"],
-                            "initial flex container rendering, no 'order' value yet");
+                            "initial flex container rendering, " +
+                            "no 'order' value yet");
 
   // OK, now we run our tests
   gOrderTestcases.forEach(runOrderTestcase);
 
   // Re-hide the flex container at the end
   flexContainerParent.style.display = "";
 }
 
--- a/layout/style/test/test_flexbox_order_table.html
+++ b/layout/style/test/test_flexbox_order_table.html
@@ -61,17 +61,17 @@ https://bugzilla.mozilla.org/show_bug.cg
     <div class="ref" id="bac"><refB></refB><refA></refA><refC></refC></div>
     <div class="ref" id="bca"><refB></refB><refC></refC><refA></refA></div>
     <div class="ref" id="cab"><refC></refC><refA></refA><refB></refB></div>
     <div class="ref" id="cba"><refC></refC><refB></refB><refA></refA></div>
   </div>
 
   <div id="flexContainerParent">
     <!-- The flex container that we'll be testing
-         (its  parent is display:none initially) -->
+         (its parent is display:none initially) -->
     <div id="flexContainer">
       <div id="a"></div>
       <div id="b"></div>
       <div id="c"></div>
     </div>
   </div>
 
 </div>
@@ -87,23 +87,23 @@ https://bugzilla.mozilla.org/show_bug.cg
  * Note: The items in this testcase don't overlap, so this testcase does _not_
  * test paint ordering.  It only tests horizontal ordering in a flex container.
  */
 
 // DATA
 // ----
 
 // This will store snapshots of our reference divs
-var gRefSnapshots = {};
+let gRefSnapshots = {};
 
 // These are the sets of 'order' values that we'll test.
 // The first three values in each array are the 'order' values that we'll
 // assign to elements a, b, and c (respectively).  The final value in each
 // array is the ID of the expected reference rendering.
-var gOrderTestcases = [
+let gOrderTestcases = [
   // The 6 basic permutations:
   [ 1, 2, 3, "abc"],
   [ 1, 3, 2, "acb"],
   [ 2, 1, 3, "bac"],
   [ 2, 3, 1, "cab"],
   [ 3, 1, 2, "bca"],
   [ 3, 2, 1, "cba"],
 
@@ -126,65 +126,67 @@ var gOrderTestcases = [
   [ "3.0", "2.0", "1.0", "abc"],
   [ 3, "2.0", 1, "bca"],
 ];
 
 // FUNCTIONS
 // ---------
 
 function initRefSnapshots() {
-  var refIds = ["abc", "acb", "bac", "bca", "cab", "cba"];
-  refIds.forEach(function(aRefId) {
-    var elem = document.getElementById(aRefId);
+  let refIds = ["abc", "acb", "bac", "bca", "cab", "cba"];
+  for (let id of refIds) {
+    let elem = document.getElementById(id);
     elem.style.display = "block";
-    gRefSnapshots[aRefId] = snapshotWindow(window, false);
+    gRefSnapshots[id] = snapshotWindow(window, false);
     elem.style.display = "";
-  });
+  }
 }
 
 function complainIfSnapshotsDiffer(aSnap1, aSnap2, aMsg) {
-  var compareResult = compareSnapshots(aSnap1, aSnap2, true);
-  ok(compareResult[0], "flex container rendering should match expected (" + aMsg +")");
+  let compareResult = compareSnapshots(aSnap1, aSnap2, true);
+  ok(compareResult[0],
+     "flex container rendering should match expected (" + aMsg +")");
   if (!compareResult[0]) {
     todo(false, "TESTCASE: " + compareResult[1]);
     todo(false, "REFERENCE: "+ compareResult[2]);
   }
 }
 
 function runOrderTestcase(aOrderTestcase) {
   // Sanity-check
   ok(Array.isArray(aOrderTestcase), "expecting testcase to be an array");
   is(aOrderTestcase.length, 4, "expecting testcase to have 4 elements");
 
   document.getElementById("a").style.order = aOrderTestcase[0];
   document.getElementById("b").style.order = aOrderTestcase[1];
   document.getElementById("c").style.order = aOrderTestcase[2];
 
-  var snapshot = snapshotWindow(window, false);
+  let snapshot = snapshotWindow(window, false);
   complainIfSnapshotsDiffer(snapshot, gRefSnapshots[aOrderTestcase[3]],
                             aOrderTestcase);
 
   // Clean up
-  document.getElementById("a").style.order = "";
-  document.getElementById("b").style.order = "";
-  document.getElementById("c").style.order = "";
+  for (let id of ["a", "b", "c"]) {
+    document.getElementById(id).style.order = "";
+  }
 }
 
 // Main Function
 function main() {
   initRefSnapshots();
 
   // un-hide the flex container's parent
-  var flexContainerParent = document.getElementById("flexContainerParent");
+  let flexContainerParent = document.getElementById("flexContainerParent");
   flexContainerParent.style.display = "block";
 
   // Initial sanity-check: should be in expected document order
-  var initialSnapshot = snapshotWindow(window, false);
+  let initialSnapshot = snapshotWindow(window, false);
   complainIfSnapshotsDiffer(initialSnapshot, gRefSnapshots["abc"],
-                            "initial flex container rendering, no 'order' value yet");
+                            "initial flex container rendering, " +
+                            "no 'order' value yet");
 
   // OK, now we run our tests
   gOrderTestcases.forEach(runOrderTestcase);
 
   // Re-hide the flex container at the end
   flexContainerParent.style.display = "";
 }