mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-01 06:35:42 +00:00
6a76308101
--HG-- extra : transplant_source : %27%23%DC/%3E%866%CB%AC%FD%87%8C%16hP%28%B8%04%F4O
77 lines
2.4 KiB
JavaScript
77 lines
2.4 KiB
JavaScript
"use strict";
|
|
|
|
this.EXPORTED_SYMBOLS = [
|
|
"PlacesTestUtils",
|
|
];
|
|
|
|
const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
|
|
|
|
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "PlacesUtils",
|
|
"resource://gre/modules/PlacesUtils.jsm");
|
|
|
|
|
|
this.PlacesTestUtils = Object.freeze({
|
|
/**
|
|
* Asynchronously adds visits to a page.
|
|
*
|
|
* @param aPlaceInfo
|
|
* Can be an nsIURI, in such a case a single LINK visit will be added.
|
|
* Otherwise can be an object describing the visit to add, or an array
|
|
* of these objects:
|
|
* { uri: nsIURI of the page,
|
|
* [optional] transition: one of the TRANSITION_* from nsINavHistoryService,
|
|
* [optional] title: title of the page,
|
|
* [optional] visitDate: visit date in microseconds from the epoch
|
|
* [optional] referrer: nsIURI of the referrer for this visit
|
|
* }
|
|
*
|
|
* @return {Promise}
|
|
* @resolves When all visits have been added successfully.
|
|
* @rejects JavaScript exception.
|
|
*/
|
|
addVisits(placeInfo) {
|
|
return new Promise((resolve, reject) => {
|
|
let places = [];
|
|
if (placeInfo instanceof Ci.nsIURI) {
|
|
places.push({ uri: placeInfo });
|
|
}
|
|
else if (Array.isArray(placeInfo)) {
|
|
places = places.concat(placeInfo);
|
|
} else {
|
|
places.push(placeInfo)
|
|
}
|
|
|
|
// Create mozIVisitInfo for each entry.
|
|
let now = Date.now();
|
|
for (let place of places) {
|
|
if (typeof place.title != "string") {
|
|
place.title = "test visit for " + place.uri.spec;
|
|
}
|
|
place.visits = [{
|
|
transitionType: place.transition === undefined ? Ci.nsINavHistoryService.TRANSITION_LINK
|
|
: place.transition,
|
|
visitDate: place.visitDate || (now++) * 1000,
|
|
referrerURI: place.referrer
|
|
}];
|
|
}
|
|
|
|
PlacesUtils.asyncHistory.updatePlaces(
|
|
places,
|
|
{
|
|
handleError: function AAV_handleError(resultCode, placeInfo) {
|
|
let ex = new Components.Exception("Unexpected error in adding visits.",
|
|
resultCode);
|
|
reject(ex);
|
|
},
|
|
handleResult: function () {},
|
|
handleCompletion: function UP_handleCompletion() {
|
|
resolve();
|
|
}
|
|
}
|
|
);
|
|
});
|
|
},
|
|
});
|