$OpenBSD$ index 39ae3f3..1a429cf 100644 --- toolkit/components/places/tests/browser/head.js.orig Fri Feb 20 15:40:39 2015 +++ toolkit/components/places/tests/browser/head.js Fri Feb 20 15:40:39 2015 @@ -2,6 +2,12 @@ http://creativecommons.org/publicdomain/zero/1.0/ */ const TRANSITION_LINK = Ci.nsINavHistoryService.TRANSITION_LINK; const TRANSITION_TYPED = Ci.nsINavHistoryService.TRANSITION_TYPED; +const TRANSITION_BOOKMARK = Ci.nsINavHistoryService.TRANSITION_BOOKMARK; +const TRANSITION_REDIRECT_PERMANENT = Ci.nsINavHistoryService.TRANSITION_REDIRECT_PERMANENT; +const TRANSITION_REDIRECT_TEMPORARY = Ci.nsINavHistoryService.TRANSITION_REDIRECT_TEMPORARY; +const TRANSITION_EMBED = Ci.nsINavHistoryService.TRANSITION_EMBED; +const TRANSITION_FRAMED_LINK = Ci.nsINavHistoryService.TRANSITION_FRAMED_LINK; +const TRANSITION_DOWNLOAD = Ci.nsINavHistoryService.TRANSITION_DOWNLOAD; Components.utils.import("resource://gre/modules/NetUtil.jsm"); @@ -178,8 +184,8 @@ function waitForFaviconChanged(aExpectedPageURI, aExpectedFaviconURI, aWindow, * Asynchronously adds visits to a page, invoking a callback function when done. * * @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 + * Either an nsIURI, in such a case a single LINK visit will be added. + * Or can be an object describing the visit to add, or an array * of these objects: * { uri: nsIURI of the page, * transition: one of the TRANSITION_* from nsINavHistoryService, @@ -206,6 +212,66 @@ function addVisits(aPlaceInfo, aWindow, aCallback, aStack) { // Create mozIVisitInfo for each entry. let now = Date.now(); + for (let place of places) { + if (!place.title) { + place.title = "test visit for " + place.uri.spec; + } + place.visits = [{ + transitionType: place.transition === undefined ? TRANSITION_LINK + : place.transition, + visitDate: place.visitDate || (now++) * 1000, + referrerURI: place.referrer + }]; + } + + aWindow.PlacesUtils.asyncHistory.updatePlaces( + places, + { + handleError: function AAV_handleError() { + throw("Unexpected error in adding visit."); + }, + handleResult: function () {}, + handleCompletion: function UP_handleCompletion() { + if (aCallback) + aCallback(); + } + } + ); +} + +/** + * 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, + * 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. + */ +function promiseAddVisits(aPlaceInfo) +{ + let deferred = Promise.defer(); + let places = []; + if (aPlaceInfo instanceof Ci.nsIURI) { + places.push({ uri: aPlaceInfo }); + } + else if (Array.isArray(aPlaceInfo)) { + places = places.concat(aPlaceInfo); + } else { + places.push(aPlaceInfo) + } + + // Create mozIVisitInfo for each entry. + let now = Date.now(); for (let i = 0; i < places.length; i++) { if (!places[i].title) { places[i].title = "test visit for " + places[i].uri.spec; @@ -218,19 +284,22 @@ function addVisits(aPlaceInfo, aWindow, aCallback, aStack) { }]; } - aWindow.PlacesUtils.asyncHistory.updatePlaces( + PlacesUtils.asyncHistory.updatePlaces( places, { - handleError: function AAV_handleError() { - throw("Unexpected error in adding visit."); + handleError: function AAV_handleError(aResultCode, aPlaceInfo) { + let ex = new Components.Exception("Unexpected error in adding visits.", + aResultCode); + deferred.reject(ex); }, handleResult: function () {}, handleCompletion: function UP_handleCompletion() { - if (aCallback) - aCallback(); + deferred.resolve(); } } ); + + return deferred.promise; } /** @@ -372,3 +441,28 @@ function promiseIsURIVisited(aURI, aExpectedValue) { return deferred.promise; } + +function waitForCondition(condition, nextTest, errorMsg) { + let tries = 0; + let interval = setInterval(function() { + if (tries >= 30) { + ok(false, errorMsg); + moveOn(); + } + let conditionPassed; + try { + conditionPassed = condition(); + } catch (e) { + ok(false, e + "\n" + e.stack); + conditionPassed = false; + } + if (conditionPassed) { + moveOn(); + } + tries++; + }, 200); + function moveOn() { + clearInterval(interval); + nextTest(); + }; +}