Bug 1129978 - Replace custom addVisits() implementations with the one in PlacesTestUtils r=mak

This commit is contained in:
Tim Taubert 2015-02-05 21:58:58 +01:00
parent 73b1f9f5e6
commit c13a420c17
20 changed files with 55 additions and 329 deletions

View File

@ -68,7 +68,7 @@ var gAllTests = [
uris.push(pURI);
}
addVisits(places, function() {
PlacesTestUtils.addVisits(places).then(() => {
let wh = new WindowHelper();
wh.onload = function () {
this.selectDuration(Sanitizer.TIMESPAN_HOUR);
@ -132,7 +132,7 @@ var gAllTests = [
olderURIs.push(pURI);
}
addVisits(places, function() {
PlacesTestUtils.addVisits(places).then(() => {
let totalHistoryVisits = uris.length + olderURIs.length;
let wh = new WindowHelper();
@ -213,7 +213,7 @@ var gAllTests = [
uris.push(pURI);
}
addVisits(places, function() {
PlacesTestUtils.addVisits(places).then(() => {
let wh = new WindowHelper();
wh.onload = function () {
is(this.isWarningPanelVisible(), false,
@ -270,7 +270,7 @@ var gAllTests = [
places.push({uri: pURI, visitDate: visitTimeForMinutesAgo(aValue)});
uris.push(pURI);
});
addVisits(places, function() {
PlacesTestUtils.addVisits(places).then(() => {
let wh = new WindowHelper();
wh.onload = function () {
is(this.isWarningPanelVisible(), false,
@ -317,7 +317,7 @@ var gAllTests = [
places.push({uri: pURI, visitDate: visitTimeForMinutesAgo(aValue)});
uris.push(pURI);
});
addVisits(places, function() {
PlacesTestUtils.addVisits(places).then(() => {
let wh = new WindowHelper();
wh.onload = function () {
is(this.isWarningPanelVisible(), true,
@ -359,7 +359,7 @@ var gAllTests = [
function () {
// Add history.
let pURI = makeURI("http://" + 10 + "-minutes-ago.com/");
addVisits({uri: pURI, visitDate: visitTimeForMinutesAgo(10)}, function() {
PlacesTestUtils.addVisits({uri: pURI, visitDate: visitTimeForMinutesAgo(10)}).then(() => {
let uris = [ pURI ];
let wh = new WindowHelper();

View File

@ -317,45 +317,6 @@ function promiseTabLoaded(aTab) {
return deferred.promise;
}
function addVisits(aPlaceInfo, aCallback) {
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;
}
places[i].visits = [{
transitionType: places[i].transition === undefined ? Ci.nsINavHistoryService.TRANSITION_LINK
: places[i].transition,
visitDate: places[i].visitDate || (now++) * 1000,
referrerURI: places[i].referrer
}];
}
PlacesUtils.asyncHistory.updatePlaces(
places,
{
handleError: function AAV_handleError() {
throw("Unexpected error in adding visit.");
},
handleResult: function () {},
handleCompletion: function UP_handleCompletion() {
if (aCallback)
aCallback();
}
}
);
}
/**
* Ensures that the specified URIs are either cleared or not.
*

View File

@ -66,10 +66,9 @@ let tests = {
// need to add a history object
let testURI1 = NetUtil.newURI(MOZURISPEC);
isnot(testURI1, null, "testURI is not null");
addVisits(
{uri: testURI1, transition: PlacesUtils.history.TRANSITION_TYPED},
window,
aCallback);
PlacesTestUtils.addVisits(
{uri: testURI1, transition: PlacesUtils.history.TRANSITION_TYPED}
).then(aCallback);
},
makeTag: function() {

View File

@ -418,11 +418,10 @@ gTests.push({
setup: function(aCallback) {
// Add a visit.
addVisits(
PlacesTestUtils.addVisits(
{uri: PlacesUtils._uri(TEST_URL),
transition: PlacesUtils.history.TRANSITION_TYPED},
window,
aCallback);
transition: PlacesUtils.history.TRANSITION_TYPED}
).then(aCallback);
},
selectNode: function(tree) {

View File

@ -16,7 +16,7 @@ function test() {
places.push({uri: PlacesUtils._uri(TEST_URI),
transition: PlacesUtils.history.TRANSITION_TYPED});
});
addVisits(places, window, function() {
PlacesTestUtils.addVisits(places).then(() => {
testForgetThisSiteVisibility(1, function() {
testForgetThisSiteVisibility(2, function() {
// Cleanup

View File

@ -43,7 +43,7 @@ function continue_test() {
places.push({uri: uri(pages[i]), visitDate: (time - i) * 1000,
transition: hs.TRANSITION_TYPED});
}
addVisits(places, window, function() {
PlacesTestUtils.addVisits(places).then(() => {
toggleSidebar("viewHistorySidebar", true);
});

View File

@ -111,11 +111,10 @@ gTests.push({
PlacesTestUtils.clearHistory().then(nextTest);
}
// add a visit to browser history
addVisits(
PlacesTestUtils.addVisits(
{ uri: PlacesUtils._uri(TEST_URI), visitDate: Date.now() * 1000,
transition: PlacesUtils.history.TRANSITION_TYPED },
window,
addVisitsCallback);
transition: PlacesUtils.history.TRANSITION_TYPED }
).then(addVisitsCallback);
}
});

View File

@ -45,11 +45,10 @@ function test() {
waitForExplicitFinish();
// Add an history entry.
ok(PlacesUtils, "checking PlacesUtils, running in chrome context?");
addVisits(
PlacesTestUtils.addVisits(
{uri: PlacesUtils._uri(TEST_URI), visitDate: Date.now() * 1000,
transition: PlacesUtils.history.TRANSITION_TYPED},
window,
function() {
transition: PlacesUtils.history.TRANSITION_TYPED}
).then(() => {
openLibrary(onLibraryReady);
});
}

View File

@ -169,13 +169,12 @@ function test() {
ok(PlacesUtils, "PlacesUtils in context");
// Add visits, a bookmark and a tag.
addVisits(
PlacesTestUtils.addVisits(
[{ uri: PlacesUtils._uri(TEST_URL), visitDate: Date.now() * 1000,
transition: PlacesUtils.history.TRANSITION_TYPED },
{ uri: PlacesUtils._uri(TEST_DOWNLOAD_URL), visitDate: Date.now() * 1000,
transition: PlacesUtils.history.TRANSITION_DOWNLOAD }],
window,
function() {
transition: PlacesUtils.history.TRANSITION_DOWNLOAD }]
).then(() => {
PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId,
PlacesUtils._uri(TEST_URL),
PlacesUtils.bookmarks.DEFAULT_INDEX,

View File

@ -53,11 +53,10 @@ function test() {
init: function(aCallback) {
// Add a history entry.
let uri = PlacesUtils._uri(TEST_URL);
addVisits(
{ uri: uri, visitDate: Date.now() * 1000,
transition: PlacesUtils.history.TRANSITION_TYPED },
window,
aCallback);
PlacesTestUtils.addVisits({
uri: uri, visitDate: Date.now() * 1000,
transition: PlacesUtils.history.TRANSITION_TYPED
}).then(aCallback);
},
prepare: function() {
sidebar.contentDocument.getElementById("byvisited").doCommand();

View File

@ -114,65 +114,6 @@ function waitForAsyncUpdates(aCallback, aScope, aArguments)
commit.finalize();
}
/**
* 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
* 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
* }
* @param [optional] aCallback
* Function to be invoked on completion.
* @param [optional] aStack
* The stack frame used to report errors.
*/
function addVisits(aPlaceInfo, aWindow, aCallback, aStack) {
let stack = aStack || Components.stack.caller;
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;
}
places[i].visits = [{
transitionType: places[i].transition === undefined ? PlacesUtils.history.TRANSITION_LINK
: places[i].transition,
visitDate: places[i].visitDate || (now++) * 1000,
referrerURI: places[i].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();
}
}
);
}
function synthesizeClickOnSelectedTreeCell(aTree, aOptions) {
let tbo = aTree.treeBoxObject;
if (tbo.view.selection.count != 1)

View File

@ -5,59 +5,3 @@ Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "PlacesTestUtils",
"resource://testing-common/PlacesTestUtils.jsm");
/**
* 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
* 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
* }
* @param [optional] aCallback
* Function to be invoked on completion.
*/
function addVisits(aPlaceInfo, aCallback) {
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;
}
places[i].visits = [{
transitionType: places[i].transition === undefined ? PlacesUtils.history.TRANSITION_LINK
: places[i].transition,
visitDate: places[i].visitDate || (now++) * 1000,
referrerURI: places[i].referrer
}];
}
PlacesUtils.asyncHistory.updatePlaces(
places,
{
handleError: function AAV_handleError() {
throw("Unexpected error in adding visit.");
},
handleResult: function () {},
handleCompletion: function UP_handleCompletion() {
if (aCallback)
aCallback();
}
}
);
}

View File

@ -58,7 +58,7 @@
{ uri: Services.io.newURI("http://example3.tld/", null, null),
visitDate: ++vtime, transition: ttype }];
yield new Promise(resolve => addVisits(places, resolve));
yield PlacesTestUtils.addVisits(places);
// Make a history query.
let query = PlacesUtils.history.getNewQuery();
@ -86,7 +86,7 @@
// First check live-update of the view when adding visits.
places.forEach(place => place.visitDate = ++vtime);
yield new Promise(resolve => addVisits(places, resolve));
yield PlacesTestUtils.addVisits(places);
for (let i = 0; i < rc; i++) {
selection.select(i);

View File

@ -50,11 +50,10 @@
Task.spawn(function* () {
yield PlacesTestUtils.clearHistory();
let visits = {
yield PlacesTestUtils.addVisits({
uri: Services.io.newURI("http://example.tld/", null, null),
transition: PlacesUtils.history.TRANSITION_TYPED
};
yield new Promise(resolve => addVisits(visits, resolve));
});
// Make a history query.
let query = PlacesUtils.history.getNewQuery();

View File

@ -71,17 +71,17 @@
// Add a visit 1ms before midnight, a visit at midnight, and
// a visit 1ms after midnight.
yield new Promise(resolve => addVisits(
[{uri: uri("http://before.midnight.com/"),
visitDate: (midnight.getTime() - 1) * 1000,
transition: PlacesUtils.history.TRANSITION_TYPED},
{uri: uri("http://at.midnight.com/"),
visitDate: (midnight.getTime()) * 1000,
transition: PlacesUtils.history.TRANSITION_TYPED},
{uri: uri("http://after.midnight.com/"),
visitDate: (midnight.getTime() + 1) * 1000,
transition: PlacesUtils.history.TRANSITION_TYPED}],
resolve));
yield PlacesTestUtils.addVisits([
{uri: uri("http://before.midnight.com/"),
visitDate: (midnight.getTime() - 1) * 1000,
transition: PlacesUtils.history.TRANSITION_TYPED},
{uri: uri("http://at.midnight.com/"),
visitDate: (midnight.getTime()) * 1000,
transition: PlacesUtils.history.TRANSITION_TYPED},
{uri: uri("http://after.midnight.com/"),
visitDate: (midnight.getTime() + 1) * 1000,
transition: PlacesUtils.history.TRANSITION_TYPED}
]);
// add a bookmark to the midnight visit
let bm = yield PlacesUtils.bookmarks.insert({

View File

@ -34,7 +34,7 @@ function test() {
function setup(aCallback) {
// add test history visit
addVisits(TEST_URI_1, function() {
PlacesTestUtils.addVisits(TEST_URI_1).then(() => {
// set permissions ourselves to avoid problems with different defaults
// from test harness configuration
for (let type in TEST_PERMS) {

View File

@ -44,7 +44,7 @@ function test() {
registerCleanupFunction(cleanUp);
// add test history visit
addVisits(TEST_URI_1, function() {
PlacesTestUtils.addVisits(TEST_URI_1).then(() => {
// set permissions ourselves to avoid problems with different defaults
// from test harness configuration
for (let type in TEST_PERMS) {

View File

@ -2,59 +2,3 @@ Components.utils.import("resource://gre/modules/PlacesUtils.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "PlacesTestUtils",
"resource://testing-common/PlacesTestUtils.jsm");
/**
* 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
* 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
* }
* @param [optional] aCallback
* Function to be invoked on completion.
*/
function addVisits(aPlaceInfo, aCallback) {
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;
}
places[i].visits = [{
transitionType: places[i].transition === undefined ? PlacesUtils.history.TRANSITION_LINK
: places[i].transition,
visitDate: places[i].visitDate || (now++) * 1000,
referrerURI: places[i].referrer
}];
}
PlacesUtils.asyncHistory.updatePlaces(
places,
{
handleError: function AAV_handleError() {
throw("Unexpected error in adding visit.");
},
handleResult: function () {},
handleCompletion: function UP_handleCompletion() {
if (aCallback)
aCallback();
}
}
);
}

View File

@ -53,17 +53,17 @@ function runTests() {
}
function clearFile(aFile, aURL) {
if (aFile.exists())
if (aFile.exists()) {
// Re-add our URL to the history so that history observer's onDeleteURI()
// is called again.
addVisits(makeURI(aURL), function() {
PlacesTestUtils.addVisits(makeURI(aURL)).then(() => {
// Try again...
yield clearHistory(true);
clearFile(aFile, aURL);
clearHistory(true, () => clearFile(aFile, aURL));
});
}
}
function clearHistory(aUseRange) {
function clearHistory(aUseRange, aCallback = next) {
let s = new Sanitizer();
s.prefDomain = "privacy.cpd.";
@ -88,7 +88,7 @@ function clearHistory(aUseRange) {
s.range = null;
s.ignoreTimespan = true;
executeSoon(next);
executeSoon(aCallback);
}
function createThumbnail() {

View File

@ -10,7 +10,8 @@ Cu.import("resource://gre/modules/FileUtils.jsm", tmp);
Cu.import("resource://gre/modules/osfile.jsm", tmp);
let {PageThumbs, BackgroundPageThumbs, NewTabUtils, PageThumbsStorage, SessionStore, FileUtils, OS} = tmp;
Cu.import("resource://gre/modules/PlacesUtils.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "PlacesTestUtils",
"resource://testing-common/PlacesTestUtils.jsm");
let oldEnabledPref = Services.prefs.getBoolPref("browser.pagethumbnails.capturing_disabled");
Services.prefs.setBoolPref("browser.pagethumbnails.capturing_disabled", false);
@ -200,72 +201,14 @@ function removeThumbnail(aURL) {
file.remove(false);
}
/**
* Asynchronously adds visits to a page, invoking a callback function when done.
*
* @param aPlaceInfo
* One of the following: a string spec, an nsIURI, an object describing
* the Place as described below, or an array of any such types. An
* object describing a Place must look like this:
* { 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
* }
* @param [optional] aCallback
* Function to be invoked on completion.
*/
function addVisits(aPlaceInfo, aCallback) {
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 (typeof(places[i]) == "string") {
places[i] = { uri: Services.io.newURI(places[i], "", null) };
}
if (!places[i].title) {
places[i].title = "test visit for " + places[i].uri.spec;
}
places[i].visits = [{
transitionType: places[i].transition === undefined ? PlacesUtils.history.TRANSITION_LINK
: places[i].transition,
visitDate: places[i].visitDate || (now++) * 1000,
referrerURI: places[i].referrer
}];
}
PlacesUtils.asyncHistory.updatePlaces(
places,
{
handleError: function AAV_handleError() {
throw("Unexpected error in adding visit.");
},
handleResult: function () {},
handleCompletion: function UP_handleCompletion() {
if (aCallback)
aCallback();
}
}
);
}
/**
* Calls addVisits, and then forces the newtab module to repopulate its links.
* See addVisits for parameter descriptions.
*/
function addVisitsAndRepopulateNewTabLinks(aPlaceInfo, aCallback) {
addVisits(aPlaceInfo, () => NewTabUtils.links.populateCache(aCallback, true));
PlacesTestUtils.addVisits(makeURI(aPlaceInfo)).then(() => {
NewTabUtils.links.populateCache(aCallback, true);
});
}
/**