1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/components/preferences/tests/head.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,57 @@ 1.4 +Components.utils.import("resource://gre/modules/PlacesUtils.jsm"); 1.5 + 1.6 +/** 1.7 + * Asynchronously adds visits to a page, invoking a callback function when done. 1.8 + * 1.9 + * @param aPlaceInfo 1.10 + * Can be an nsIURI, in such a case a single LINK visit will be added. 1.11 + * Otherwise can be an object describing the visit to add, or an array 1.12 + * of these objects: 1.13 + * { uri: nsIURI of the page, 1.14 + * transition: one of the TRANSITION_* from nsINavHistoryService, 1.15 + * [optional] title: title of the page, 1.16 + * [optional] visitDate: visit date in microseconds from the epoch 1.17 + * [optional] referrer: nsIURI of the referrer for this visit 1.18 + * } 1.19 + * @param [optional] aCallback 1.20 + * Function to be invoked on completion. 1.21 + */ 1.22 +function addVisits(aPlaceInfo, aCallback) { 1.23 + let places = []; 1.24 + if (aPlaceInfo instanceof Ci.nsIURI) { 1.25 + places.push({ uri: aPlaceInfo }); 1.26 + } 1.27 + else if (Array.isArray(aPlaceInfo)) { 1.28 + places = places.concat(aPlaceInfo); 1.29 + } else { 1.30 + places.push(aPlaceInfo) 1.31 + } 1.32 + 1.33 + // Create mozIVisitInfo for each entry. 1.34 + let now = Date.now(); 1.35 + for (let i = 0; i < places.length; i++) { 1.36 + if (!places[i].title) { 1.37 + places[i].title = "test visit for " + places[i].uri.spec; 1.38 + } 1.39 + places[i].visits = [{ 1.40 + transitionType: places[i].transition === undefined ? PlacesUtils.history.TRANSITION_LINK 1.41 + : places[i].transition, 1.42 + visitDate: places[i].visitDate || (now++) * 1000, 1.43 + referrerURI: places[i].referrer 1.44 + }]; 1.45 + } 1.46 + 1.47 + PlacesUtils.asyncHistory.updatePlaces( 1.48 + places, 1.49 + { 1.50 + handleError: function AAV_handleError() { 1.51 + throw("Unexpected error in adding visit."); 1.52 + }, 1.53 + handleResult: function () {}, 1.54 + handleCompletion: function UP_handleCompletion() { 1.55 + if (aCallback) 1.56 + aCallback(); 1.57 + } 1.58 + } 1.59 + ); 1.60 +} 1.61 \ No newline at end of file