browser/components/places/tests/chrome/head.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /**
michael@0 2 * Asynchronously adds visits to a page, invoking a callback function when done.
michael@0 3 *
michael@0 4 * @param aPlaceInfo
michael@0 5 * Can be an nsIURI, in such a case a single LINK visit will be added.
michael@0 6 * Otherwise can be an object describing the visit to add, or an array
michael@0 7 * of these objects:
michael@0 8 * { uri: nsIURI of the page,
michael@0 9 * transition: one of the TRANSITION_* from nsINavHistoryService,
michael@0 10 * [optional] title: title of the page,
michael@0 11 * [optional] visitDate: visit date in microseconds from the epoch
michael@0 12 * [optional] referrer: nsIURI of the referrer for this visit
michael@0 13 * }
michael@0 14 * @param [optional] aCallback
michael@0 15 * Function to be invoked on completion.
michael@0 16 */
michael@0 17 function addVisits(aPlaceInfo, aCallback) {
michael@0 18 let places = [];
michael@0 19 if (aPlaceInfo instanceof Ci.nsIURI) {
michael@0 20 places.push({ uri: aPlaceInfo });
michael@0 21 }
michael@0 22 else if (Array.isArray(aPlaceInfo)) {
michael@0 23 places = places.concat(aPlaceInfo);
michael@0 24 } else {
michael@0 25 places.push(aPlaceInfo)
michael@0 26 }
michael@0 27
michael@0 28 // Create mozIVisitInfo for each entry.
michael@0 29 let now = Date.now();
michael@0 30 for (let i = 0; i < places.length; i++) {
michael@0 31 if (!places[i].title) {
michael@0 32 places[i].title = "test visit for " + places[i].uri.spec;
michael@0 33 }
michael@0 34 places[i].visits = [{
michael@0 35 transitionType: places[i].transition === undefined ? PlacesUtils.history.TRANSITION_LINK
michael@0 36 : places[i].transition,
michael@0 37 visitDate: places[i].visitDate || (now++) * 1000,
michael@0 38 referrerURI: places[i].referrer
michael@0 39 }];
michael@0 40 }
michael@0 41
michael@0 42 PlacesUtils.asyncHistory.updatePlaces(
michael@0 43 places,
michael@0 44 {
michael@0 45 handleError: function AAV_handleError() {
michael@0 46 throw("Unexpected error in adding visit.");
michael@0 47 },
michael@0 48 handleResult: function () {},
michael@0 49 handleCompletion: function UP_handleCompletion() {
michael@0 50 if (aCallback)
michael@0 51 aCallback();
michael@0 52 }
michael@0 53 }
michael@0 54 );
michael@0 55 }
michael@0 56
michael@0 57 /**
michael@0 58 * Clears history invoking callback when done.
michael@0 59 */
michael@0 60 function waitForClearHistory(aCallback) {
michael@0 61 const TOPIC_EXPIRATION_FINISHED = "places-expiration-finished";
michael@0 62 Services.obs.addObserver(function observer(aSubject, aTopic, aData) {
michael@0 63 Services.obs.removeObserver(observer, TOPIC_EXPIRATION_FINISHED);
michael@0 64 aCallback();
michael@0 65 }, TOPIC_EXPIRATION_FINISHED, false);
michael@0 66 Cc["@mozilla.org/browser/nav-history-service;1"]
michael@0 67 .getService(Ci.nsINavHistoryService)
michael@0 68 .QueryInterface(Ci.nsIBrowserHistory).removeAllPages();
michael@0 69 }

mercurial