Bug 1430841 Fix compiler errors and a failing test relating to Time Precision Reduction r?froydnj draft
authorTom Ritter <tom@mozilla.com>
Mon, 29 Jan 2018 12:16:59 -0600
changeset 748509 1b34b2f4c7f77da0791178e1c31a1ff611c00383
parent 748508 1fc52fec6fa32f37b46f9ce27e51294d723014d3
push id97192
push userbmo:tom@mozilla.com
push dateMon, 29 Jan 2018 22:46:52 +0000
reviewersfroydnj
bugs1430841, 1000000, 1429648
milestone60.0a1
Bug 1430841 Fix compiler errors and a failing test relating to Time Precision Reduction r?froydnj We caused three errors: 1) 9007199254740992 (and similar numbers) are interpretted as int64's then passed as a double parameter. This warned about generic loss of precision converting from int64 -> double. That warning is generic, but was actually quite specific since these values DO lose precision in doubles, and that's what we're testing. Anyway, add a .0 to have the compiler treat them as double constants. 2) 1000000 * 60 * 60 * 5 overflows an int. Make the first value 1000000.0 so that it becomes a double. 3) dom/animation/test/css-animations/test_animation-finish.html was doing math about the expected times it should receive. When timer precision reduction is present, those times are wrong. So turn off timer precision reduction for the test, and note we should improve this test also over in Bug 1429648 MozReview-Commit-ID: J2G4WDP9uDQ
dom/animation/test/css-animations/test_animation-finish.html
toolkit/components/resistfingerprinting/tests/test_reduceprecision.cpp
--- a/dom/animation/test/css-animations/test_animation-finish.html
+++ b/dom/animation/test/css-animations/test_animation-finish.html
@@ -2,14 +2,16 @@
 <meta charset=utf-8>
 <script src="/resources/testharness.js"></script>
 <script src="/resources/testharnessreport.js"></script>
 <div id="log"></div>
 <script>
 'use strict';
 setup({explicit_done: true});
 SpecialPowers.pushPrefEnv(
-  { "set": [["dom.animations-api.core.enabled", true]]},
+  { "set": [
+  	["dom.animations-api.core.enabled", true],
+  	["privacy.resistFingerprinting.reduceTimerPrecision.microseconds", 0]]},
   function() {
     window.open("file_animation-finish.html");
   });
 </script>
 </html>
--- a/toolkit/components/resistfingerprinting/tests/test_reduceprecision.cpp
+++ b/toolkit/components/resistfingerprinting/tests/test_reduceprecision.cpp
@@ -81,27 +81,27 @@ TEST(ResistFingerprinting, ReducePrecisi
   process(2601.64, nsRFPService::TimeScale::MilliSeconds, 20);
   process(2595.16, nsRFPService::TimeScale::MilliSeconds, 20);
   process(2578.66, nsRFPService::TimeScale::MilliSeconds, 20);
 }
 
 TEST(ResistFingerprinting, ReducePrecision_ExpectedLossOfPrecision) {
   double result;
   // We lose integer precision at 9007199254740992 - let's confirm that.
-  result = nsRFPService::ReduceTimePrecisionImpl(9007199254740992, nsRFPService::TimeScale::MicroSeconds, 5);
-  ASSERT_EQ(result, 9007199254740990);
+  result = nsRFPService::ReduceTimePrecisionImpl(9007199254740992.0, nsRFPService::TimeScale::MicroSeconds, 5);
+  ASSERT_EQ(result, 9007199254740990.0);
   // 9007199254740995 is approximated to 9007199254740996
-  result = nsRFPService::ReduceTimePrecisionImpl(9007199254740995, nsRFPService::TimeScale::MicroSeconds, 5);
-  ASSERT_EQ(result, 9007199254740996);
+  result = nsRFPService::ReduceTimePrecisionImpl(9007199254740995.0, nsRFPService::TimeScale::MicroSeconds, 5);
+  ASSERT_EQ(result, 9007199254740996.0);
   // 9007199254740999 is approximated as 9007199254741000
-  result = nsRFPService::ReduceTimePrecisionImpl(9007199254740999, nsRFPService::TimeScale::MicroSeconds, 5);
-  ASSERT_EQ(result, 9007199254741000);
+  result = nsRFPService::ReduceTimePrecisionImpl(9007199254740999.0, nsRFPService::TimeScale::MicroSeconds, 5);
+  ASSERT_EQ(result, 9007199254741000.0);
   // 9007199254743568 can be represented exactly, but will be clamped to 9007199254743564
-  result = nsRFPService::ReduceTimePrecisionImpl(9007199254743568, nsRFPService::TimeScale::MicroSeconds, 5);
-  ASSERT_EQ(result, 9007199254743564);
+  result = nsRFPService::ReduceTimePrecisionImpl(9007199254743568.0, nsRFPService::TimeScale::MicroSeconds, 5);
+  ASSERT_EQ(result, 9007199254743564.0);
 }
 
 
 TEST(ResistFingerprinting, ReducePrecision_Expectations) {
   double result;
   result = nsRFPService::ReduceTimePrecisionImpl(2611.14, nsRFPService::TimeScale::MilliSeconds, 20);
   ASSERT_EQ(result, 2611.14);
   result = nsRFPService::ReduceTimePrecisionImpl(2611.145, nsRFPService::TimeScale::MilliSeconds, 20);
@@ -128,23 +128,23 @@ TEST(ResistFingerprinting, ReducePrecisi
      return;
   }
 
   for (int i=0; i<10000; i++) {
      // Test three different time magnitudes, with decimals.
      // Note that we need separate variables for the different units, as scaling
      // them after calculating them will erase effects of approximation.
      // A magnitude in the seconds since epoch range.
-     double time1_s = fmod(RAND_DOUBLE, 1516305819);
-     double time1_ms = fmod(RAND_DOUBLE, 1516305819000);
-     double time1_us = fmod(RAND_DOUBLE, 1516305819000000);
+     double time1_s = fmod(RAND_DOUBLE, 1516305819L);
+     double time1_ms = fmod(RAND_DOUBLE, 1516305819000L);
+     double time1_us = fmod(RAND_DOUBLE, 1516305819000000L);
      // A magnitude in the 'couple of minutes worth of milliseconds' range.
-     double time2_s = fmod(RAND_DOUBLE, (60 * 60 * 5));
-     double time2_ms = fmod(RAND_DOUBLE, (1000 * 60 * 60 * 5));
-     double time2_us = fmod(RAND_DOUBLE, (1000000 * 60 * 60 * 5));
+     double time2_s = fmod(RAND_DOUBLE, (60.0 * 60 * 5));
+     double time2_ms = fmod(RAND_DOUBLE, (1000.0 * 60 * 60 * 5));
+     double time2_us = fmod(RAND_DOUBLE, (1000000.0 * 60 * 60 * 5));
      // A magnitude in the small range.
      double time3_s = fmod(RAND_DOUBLE, 10);
      double time3_ms = fmod(RAND_DOUBLE, 10000);
      double time3_us = fmod(RAND_DOUBLE, 10000000);
 
      // Test two precision magnitudes, no decimals.
      // A magnitude in the high milliseconds.
      double precision1 = rand() % 250000;