Bug 1435296 Update the CSS Animations tests to handle our new Timer Precision decision draft
authorTom Ritter <tom@mozilla.com>
Wed, 07 Feb 2018 20:35:38 -0600
changeset 753921 a3c8d0bec6d60e232680a4aaa18311a419f66ba5
parent 753920 403cd7bb8f8dd6d5731237f528a3c925afe79c24
child 753922 eff79385bb51755fc00a019688de44d27dc09af0
push id98722
push userbmo:tom@mozilla.com
push dateMon, 12 Feb 2018 17:42:43 +0000
bugs1435296
milestone60.0a1
Bug 1435296 Update the CSS Animations tests to handle our new Timer Precision decision This commit does several subtle things. 1: It changes ok() to opener.ok() ok is not defined, we have to use opener.ok. This was not caught before because this call is used to provide additional debugging information when a test fails. Test didn't fail, didn't hit that line. 2: It disables the call to opener.ok() we just fixed. As the comment there describes, we expect that function to fail, so we don't want to assert(false). 3: It inverts failures to successes if only the reduceTimerPrecision pref is set MozReview-Commit-ID: lpKKhJoDs6
browser/components/resistfingerprinting/test/mochitest/file_animation_api.html
--- a/browser/components/resistfingerprinting/test/mochitest/file_animation_api.html
+++ b/browser/components/resistfingerprinting/test/mochitest/file_animation_api.html
@@ -47,37 +47,49 @@
       // We check that the timer is not sub-millisecond by assuming it is not if it
       // returns an even number of milliseconds
       if (expectedPrecision < 1 && Math.round(x) == x) {
         if (Math.round(rounded) == x) {
           return true;
         }
       }
 
-      ok(false, "Looming Test Failure, Additional Debugging Info: Expected Precision: " + expectedPrecision + " Measured Value: " + x +
-        " Rounded Vaue: " + rounded + " Fuzzy1: " + Math.abs(rounded - x + expectedPrecision) +
-        " Fuzzy 2: " + Math.abs(rounded - x));
+      // We are temporarily disabling this extra debugging failure because we expect to return false in some instances
+      // When we correct things we will re-enable it for debugging assistance
+      // opener.ok(false, "Looming Test Failure, Additional Debugging Info: Expected Precision: " + expectedPrecision + " Measured Value: " + x +
+      //   " Rounded Vaue: " + rounded + " Fuzzy1: " + Math.abs(rounded - x + expectedPrecision) +
+      //   " Fuzzy 2: " + Math.abs(rounded - x));
 
       return false;
     };
     const testDiv = document.getElementById("testDiv");
     const animation = testDiv.animate({ opacity: [0, 1] }, 100000);
     animation.play();
 
     waitForCondition(
       () => animation.currentTime > 100,
         () => {
-          opener.ok(isRounded(animation.startTime),
+
+          // We have disabled Time Precision Reduction for CSS Animations, so we expect those tests to fail.
+          // If we are testing that preference, turn failures into successes and successes into failures
+          var maybeInvert = function(value) {
+            if (opener.prefName.includes("privacy.reduceTimerPrecision") &&
+                !opener.prefName.includes("privacy.resistFingerprinting"))
+              return !value;
+            return value;
+          };
+
+          opener.ok(maybeInvert(isRounded(animation.startTime)),
              "pref: " + opener.prefName + " - animation.startTime with precision " + expectedPrecision + " is not rounded: " + animation.startTime);
-          opener.ok(isRounded(animation.currentTime),
+          opener.ok(maybeInvert(isRounded(animation.currentTime)),
              "pref: " + opener.prefName + " - animation.currentTime with precision " + expectedPrecision + " is not rounded: " + animation.currentTime);
-          opener.ok(isRounded(animation.timeline.currentTime),
+          opener.ok(maybeInvert(isRounded(animation.timeline.currentTime)),
              "pref: " + opener.prefName + " - animation.timeline.currentTime with precision " + expectedPrecision + " is not rounded: " + animation.timeline.currentTime);
           if (document.timeline) {
-            opener.ok(isRounded(document.timeline.currentTime),
+            opener.ok(maybeInvert(isRounded(document.timeline.currentTime)),
                "pref: " + opener.prefName + " - document.timeline.currentTime with precision " + expectedPrecision + " is not rounded: " + document.timeline.currentTime);
           }
           opener.done();
           window.close();
         },
         "animation failed to start");
   }
 </script>