diff --git a/browser/components/resistfingerprinting/test/browser/browser_performanceAPI.js b/browser/components/resistfingerprinting/test/browser/browser_performanceAPI.js index 90b4b81710fc..a89fd169d951 100644 --- a/browser/components/resistfingerprinting/test/browser/browser_performanceAPI.js +++ b/browser/components/resistfingerprinting/test/browser/browser_performanceAPI.js @@ -37,10 +37,15 @@ let isRounded = (x, expectedPrecision) => { return true; // When we're diving by non-whole numbers, we may not get perfect - // multiplication/division because of floating points - if (Math.abs(rounded - x + expectedPrecision) < .0000001) { + // multiplication/division because of floating points. + // When dealing with ms since epoch, a double's precision is on the order + // of 1/5 of a microsecond, so we use a value a little higher than that as + // our epsilon. + // To be clear, this error is introduced in our re-calculation of 'rounded' + // above in JavaScript. + if (Math.abs(rounded - x + expectedPrecision) < .0005) { return true; - } else if (Math.abs(rounded - x) < .0000001) { + } else if (Math.abs(rounded - x) < .0005) { return true; } diff --git a/browser/components/resistfingerprinting/test/browser/file_workerPerformance.js b/browser/components/resistfingerprinting/test/browser/file_workerPerformance.js index 1791e015af1e..132accc5951c 100644 --- a/browser/components/resistfingerprinting/test/browser/file_workerPerformance.js +++ b/browser/components/resistfingerprinting/test/browser/file_workerPerformance.js @@ -17,10 +17,15 @@ let isRounded = (x, expectedPrecision) => { return true; // When we're diving by non-whole numbers, we may not get perfect - // multiplication/division because of floating points - if (Math.abs(rounded - x + expectedPrecision) < .0000001) { + // multiplication/division because of floating points. + // When dealing with ms since epoch, a double's precision is on the order + // of 1/5 of a microsecond, so we use a value a little higher than that as + // our epsilon. + // To be clear, this error is introduced in our re-calculation of 'rounded' + // above in JavaScript. + if (Math.abs(rounded - x + expectedPrecision) < .0005) { return true; - } else if (Math.abs(rounded - x) < .0000001) { + } else if (Math.abs(rounded - x) < .0005) { return true; } diff --git a/browser/components/resistfingerprinting/test/mochitest/file_animation_api.html b/browser/components/resistfingerprinting/test/mochitest/file_animation_api.html index 789afecbe94f..9c4ecdce1fb8 100644 --- a/browser/components/resistfingerprinting/test/mochitest/file_animation_api.html +++ b/browser/components/resistfingerprinting/test/mochitest/file_animation_api.html @@ -36,10 +36,15 @@ return true; // When we're diving by non-whole numbers, we may not get perfect - // multiplication/division because of floating points - if (Math.abs(rounded - x + expectedPrecision) < .0000001) { + // multiplication/division because of floating points. + // When dealing with ms since epoch, a double's precision is on the order + // of 1/5 of a microsecond, so we use a value a little higher than that as + // our epsilon. + // To be clear, this error is introduced in our re-calculation of 'rounded' + // above in JavaScript. + if (Math.abs(rounded - x + expectedPrecision) < .0005) { return true; - } else if (Math.abs(rounded - x) < .0000001) { + } else if (Math.abs(rounded - x) < .0005) { return true; } diff --git a/browser/components/resistfingerprinting/test/mochitest/test_reduce_time_precision.html b/browser/components/resistfingerprinting/test/mochitest/test_reduce_time_precision.html index 319d3fda4c65..4ad80fde8568 100644 --- a/browser/components/resistfingerprinting/test/mochitest/test_reduce_time_precision.html +++ b/browser/components/resistfingerprinting/test/mochitest/test_reduce_time_precision.html @@ -50,13 +50,18 @@ https://trac.torproject.org/projects/tor/ticket/1517 if (rounded === x || x === 0) return true; - // When we're diving by non-whole numbers, we may not get perfect - // multiplication/division because of floating points - if (Math.abs(rounded - x + expectedPrecision) < .0000001) { - return true; - } else if (Math.abs(rounded - x) < .0000001) { - return true; - } + // When we're diving by non-whole numbers, we may not get perfect + // multiplication/division because of floating points. + // When dealing with ms since epoch, a double's precision is on the order + // of 1/5 of a microsecond, so we use a value a little higher than that as + // our epsilon. + // To be clear, this error is introduced in our re-calculation of 'rounded' + // above in JavaScript. + if (Math.abs(rounded - x + expectedPrecision) < .0005) { + return true; + } else if (Math.abs(rounded - x) < .0005) { + return true; + } // Then we handle the case where you're sub-millisecond and the timer is not // We check that the timer is not sub-millisecond by assuming it is not if it