Bug 1306466 - Add timers resolution skew to History future date check, to avoid intermittent failures. r=adw
MozReview-Commit-ID: CI4rakbklhq
--- a/toolkit/components/places/History.jsm
+++ b/toolkit/components/places/History.jsm
@@ -85,16 +85,19 @@ Cu.importGlobalProperties(["URL"]);
* Whenever we update or remove numerous pages, it is preferable
* to yield time to the main thread every so often to avoid janking.
* These constants determine the maximal number of notifications we
* may emit before we yield.
*/
const NOTIFICATION_CHUNK_SIZE = 300;
const ONRESULT_CHUNK_SIZE = 300;
+// Timers resolution is not always good, it can have a 16ms precision on Win.
+const TIMERS_RESOLUTION_SKEW_MS = 16;
+
/**
* Sends a bookmarks notification through the given observers.
*
* @param observers
* array of nsINavBookmarkObserver objects.
* @param notification
* the notification name.
* @param args
@@ -495,17 +498,17 @@ function validatePageInfo(pageInfo) {
};
if (!isValidTransitionType(visit.transition)) {
throw new TypeError(`transition: ${visit.transition} is not a valid transition type`);
}
if (inVisit.date) {
ensureDate(inVisit.date);
- if (inVisit.date > Date.now()) {
+ if (inVisit.date > (Date.now() + TIMERS_RESOLUTION_SKEW_MS)) {
throw new TypeError(`date: ${inVisit.date} cannot be a future date`);
}
visit.date = inVisit.date;
}
if (inVisit.referrer) {
visit.referrer = normalizeToURLOrGUID(inVisit.referrer);
}
--- a/toolkit/components/places/tests/history/test_insert.js
+++ b/toolkit/components/places/tests/history/test_insert.js
@@ -73,17 +73,17 @@ add_task(function* test_insert_error_cas
transition: TRANSITION_LINK,
date: "a"
}
]}),
/TypeError: Expected a Date, got a/,
"passing a second visit object with an invalid date to History.insert should throw a TypeError"
);
let futureDate = new Date();
- futureDate.setDate(futureDate.getDate() + 1);
+ futureDate.setDate(futureDate.getDate() + 1000);
Assert.throws(
() => PlacesUtils.history.insert({
url: TEST_URL,
visits: [
{
transition: TRANSITION_LINK,
date: futureDate,
}