Bug 1448064 - Use PlacesUtils.history.insert instead of updatePlaces in TPS r?kitcambridge
MozReview-Commit-ID: 1egxfjYE2yt
--- a/services/sync/tps/extensions/tps/resource/modules/forms.jsm
+++ b/services/sync/tps/extensions/tps/resource/modules/forms.jsm
@@ -113,22 +113,22 @@ var FormDB = {
},
};
/**
* FormData class constructor
*
* Initializes instance properties.
*/
-function FormData(props, usSinceEpoch) {
+function FormData(props, msSinceEpoch) {
this.fieldname = null;
this.value = null;
this.date = 0;
this.newvalue = null;
- this.usSinceEpoch = usSinceEpoch;
+ this.usSinceEpoch = msSinceEpoch * 1000;
for (var prop in props) {
if (prop in this)
this[prop] = props[prop];
}
}
/**
--- a/services/sync/tps/extensions/tps/resource/modules/history.jsm
+++ b/services/sync/tps/extensions/tps/resource/modules/history.jsm
@@ -44,66 +44,53 @@ var HistoryEntry = {
*
* Adds visits for a uri to the history database. Throws on error.
*
* @param item An object representing one or more visits to a specific uri
* @param usSinceEpoch The number of microseconds from Epoch to
* the time the current Crossweave run was started
* @return nothing
*/
- async Add(item, usSinceEpoch) {
+ async Add(item, msSinceEpoch) {
Logger.AssertTrue("visits" in item && "uri" in item,
"History entry in test file must have both 'visits' " +
"and 'uri' properties");
- let uri = Services.io.newURI(item.uri);
let place = {
- uri,
+ url: item.uri,
visits: []
};
for (let visit of item.visits) {
- place.visits.push({
- visitDate: usSinceEpoch + (visit.date * 60 * 60 * 1000 * 1000),
- transitionType: visit.type
- });
+ let date = new Date(Math.round(msSinceEpoch + visit.date * 60 * 60 * 1000));
+ place.visits.push({ date, transition: visit.type });
}
if ("title" in item) {
place.title = item.title;
}
- return new Promise((resolve, reject) => {
- PlacesUtils.asyncHistory.updatePlaces(place, {
- handleError() {
- reject(new Error("Error adding history entry"));
- },
- handleResult() {},
- handleCompletion() {
- resolve();
- }
- });
- });
+ return PlacesUtils.history.insert(place);
},
/**
* Find
*
* Finds visits for a uri to the history database. Throws on error.
*
* @param item An object representing one or more visits to a specific uri
* @param usSinceEpoch The number of microseconds from Epoch to
* the time the current Crossweave run was started
* @return true if all the visits for the uri are found, otherwise false
*/
- async Find(item, usSinceEpoch) {
+ async Find(item, msSinceEpoch) {
Logger.AssertTrue("visits" in item && "uri" in item,
"History entry in test file must have both 'visits' " +
"and 'uri' properties");
let curvisits = await PlacesSyncUtils.history.fetchVisitsForURL(item.uri);
for (let visit of curvisits) {
for (let itemvisit of item.visits) {
- let expectedDate = itemvisit.date * 60 * 60 * 1000 * 1000
- + usSinceEpoch;
+ // Note: in microseconds.
+ let expectedDate = itemvisit.date * 60 * 60 * 1000 * 1000 + msSinceEpoch * 1000;
if (visit.type == itemvisit.type && visit.date == expectedDate) {
itemvisit.found = true;
}
}
}
let all_items_found = true;
for (let itemvisit of item.visits) {
@@ -121,26 +108,25 @@ var HistoryEntry = {
*
* Removes visits from the history database. Throws on error.
*
* @param item An object representing items to delete
* @param usSinceEpoch The number of microseconds from Epoch to
* the time the current Crossweave run was started
* @return nothing
*/
- async Delete(item, usSinceEpoch) {
+ async Delete(item, msSinceEpoch) {
if ("uri" in item) {
let removedAny = await PlacesUtils.history.remove(item.uri);
if (!removedAny) {
Logger.log("Warning: Removed 0 history visits for uri " + item.uri);
}
} else if ("host" in item) {
await PlacesUtils.history.removePagesFromHost(item.host, false);
} else if ("begin" in item && "end" in item) {
- let msSinceEpoch = parseInt(usSinceEpoch / 1000);
let filter = {
beginDate: new Date(msSinceEpoch + (item.begin * 60 * 60 * 1000)),
endDate: new Date(msSinceEpoch + (item.end * 60 * 60 * 1000))
};
let removedAny = await PlacesUtils.history.removeVisitsByFilter(filter);
if (!removedAny) {
Logger.log("Warning: Removed 0 history visits with " + JSON.stringify({ item, filter }));
}
--- a/services/sync/tps/extensions/tps/resource/tps.jsm
+++ b/services/sync/tps/extensions/tps/resource/tps.jsm
@@ -125,17 +125,17 @@ var TPS = {
_syncCount: 0,
_syncsReportedViaTelemetry: 0,
_syncErrors: 0,
_syncWipeAction: null,
_tabsAdded: 0,
_tabsFinished: 0,
_test: null,
_triggeredSync: false,
- _usSinceEpoch: 0,
+ _msSinceEpoch: 0,
_requestedQuit: false,
shouldValidateAddons: false,
shouldValidateBookmarks: false,
shouldValidatePasswords: false,
shouldValidateForms: false,
_windowsUpDeferred: PromiseUtils.defer(),
_placesInitDeferred: PromiseUtils.defer(),
@@ -372,17 +372,17 @@ var TPS = {
Logger.logPass("executing action " + action.toUpperCase() + " on pref");
},
async HandleForms(data, action) {
this.shouldValidateForms = true;
for (let datum of data) {
Logger.logInfo("executing action " + action.toUpperCase() +
" on form entry " + JSON.stringify(datum));
- let formdata = new FormData(datum, this._usSinceEpoch);
+ let formdata = new FormData(datum, this._msSinceEpoch);
switch (action) {
case ACTION_ADD:
await formdata.Create();
break;
case ACTION_DELETE:
await formdata.Remove();
break;
case ACTION_VERIFY:
@@ -404,27 +404,27 @@ var TPS = {
async HandleHistory(entries, action) {
try {
for (let entry of entries) {
const entryString = JSON.stringify(entry);
Logger.logInfo("executing action " + action.toUpperCase() +
" on history entry " + entryString);
switch (action) {
case ACTION_ADD:
- await HistoryEntry.Add(entry, this._usSinceEpoch);
+ await HistoryEntry.Add(entry, this._msSinceEpoch);
break;
case ACTION_DELETE:
- await HistoryEntry.Delete(entry, this._usSinceEpoch);
+ await HistoryEntry.Delete(entry, this._msSinceEpoch);
break;
case ACTION_VERIFY:
- Logger.AssertTrue((await HistoryEntry.Find(entry, this._usSinceEpoch)),
+ Logger.AssertTrue((await HistoryEntry.Find(entry, this._msSinceEpoch)),
"Uri visits not found in history database: " + entryString);
break;
case ACTION_VERIFY_NOT:
- Logger.AssertTrue(!(await HistoryEntry.Find(entry, this._usSinceEpoch)),
+ Logger.AssertTrue(!(await HistoryEntry.Find(entry, this._msSinceEpoch)),
"Uri visits found in history database, but they shouldn't be: " + entryString);
break;
default:
Logger.AssertTrue(false, "invalid action: " + action);
}
}
Logger.logPass("executing action " + action.toUpperCase() +
" on history");
@@ -813,17 +813,17 @@ var TPS = {
this.quit();
return;
}
this.seconds_since_epoch = Services.prefs.getIntPref("tps.seconds_since_epoch");
if (this.seconds_since_epoch) {
// Places dislikes it if we add visits in the future. We pretend the
// real time is 1 minute ago to avoid issues caused by places using a
// different clock than the one that set the seconds_since_epoch pref.
- this._usSinceEpoch = (this.seconds_since_epoch - 60) * 1000 * 1000;
+ this._msSinceEpoch = (this.seconds_since_epoch - 60) * 1000;
} else {
this.DumpError("seconds-since-epoch not set");
return;
}
let phase = this._phaselist[this._currentPhase];
let action = phase[this._currentAction];
Logger.logInfo("starting action: " + action[0].name);