Bug 820764 - Stop using addvisit() in browser tests r=mak77

This commit is contained in:
Raymond Lee 2013-01-25 12:55:22 +08:00
parent 0cac9879e7
commit cb52c2a702
26 changed files with 1072 additions and 720 deletions

View File

@ -54,30 +54,36 @@ var gAllTests = [
function () {
// Add history (within the past hour)
let uris = [];
let places = [];
let pURI;
for (let i = 0; i < 30; i++) {
uris.push(addHistoryWithMinutesAgo(i));
pURI = makeURI("http://" + i + "-minutes-ago.com/");
places.push({uri: pURI, visitDate: visitTimeForMinutesAgo(i)});
uris.push(pURI);
}
let wh = new WindowHelper();
wh.onload = function () {
this.selectDuration(Sanitizer.TIMESPAN_HOUR);
this.checkPrefCheckbox("history", false);
this.checkDetails(false);
addVisits(places, function() {
let wh = new WindowHelper();
wh.onload = function () {
this.selectDuration(Sanitizer.TIMESPAN_HOUR);
this.checkPrefCheckbox("history", false);
this.checkDetails(false);
// Show details
this.toggleDetails();
this.checkDetails(true);
// Show details
this.toggleDetails();
this.checkDetails(true);
// Hide details
this.toggleDetails();
this.checkDetails(false);
this.cancelDialog();
// Hide details
this.toggleDetails();
this.checkDetails(false);
this.cancelDialog();
ensureHistoryClearedState(uris, false);
blankSlate();
ensureHistoryClearedState(uris, true);
};
wh.open();
ensureHistoryClearedState(uris, false);
blankSlate();
ensureHistoryClearedState(uris, true);
};
wh.open();
});
},
/**
@ -85,56 +91,67 @@ var gAllTests = [
* visits and downloads when checked; the dialog respects simple timespan.
*/
function () {
// Add history and downloads (within the past hour).
// Add history (within the past hour).
let uris = [];
let places = [];
let pURI;
for (let i = 0; i < 30; i++) {
uris.push(addHistoryWithMinutesAgo(i));
pURI = makeURI("http://" + i + "-minutes-ago.com/");
places.push({uri: pURI, visitDate: visitTimeForMinutesAgo(i)});
uris.push(pURI);
}
let downloadIDs = [];
for (let i = 0; i < 5; i++) {
downloadIDs.push(addDownloadWithMinutesAgo(i));
}
// Add history and downloads (over an hour ago).
// Add history (over an hour ago).
let olderURIs = [];
for (let i = 0; i < 5; i++) {
olderURIs.push(addHistoryWithMinutesAgo(61 + i));
pURI = makeURI("http://" + (61 + i) + "-minutes-ago.com/");
places.push({uri: pURI, visitDate: visitTimeForMinutesAgo(61 + i)});
olderURIs.push(pURI);
}
let olderDownloadIDs = [];
for (let i = 0; i < 5; i++) {
olderDownloadIDs.push(addDownloadWithMinutesAgo(61 + i));
}
let totalHistoryVisits = uris.length + olderURIs.length;
let wh = new WindowHelper();
wh.onload = function () {
this.selectDuration(Sanitizer.TIMESPAN_HOUR);
this.checkPrefCheckbox("history", true);
this.acceptDialog();
addVisits(places, function() {
// Add downloads (within the past hour).
let downloadIDs = [];
for (let i = 0; i < 5; i++) {
downloadIDs.push(addDownloadWithMinutesAgo(i));
}
// Add downloads (over an hour ago).
let olderDownloadIDs = [];
for (let i = 0; i < 5; i++) {
olderDownloadIDs.push(addDownloadWithMinutesAgo(61 + i));
}
let totalHistoryVisits = uris.length + olderURIs.length;
intPrefIs("sanitize.timeSpan", Sanitizer.TIMESPAN_HOUR,
"timeSpan pref should be hour after accepting dialog with " +
"hour selected");
boolPrefIs("cpd.history", true,
"history pref should be true after accepting dialog with " +
"history checkbox checked");
boolPrefIs("cpd.downloads", true,
"downloads pref should be true after accepting dialog with " +
"history checkbox checked");
let wh = new WindowHelper();
wh.onload = function () {
this.selectDuration(Sanitizer.TIMESPAN_HOUR);
this.checkPrefCheckbox("history", true);
this.acceptDialog();
// History visits and downloads within one hour should be cleared.
ensureHistoryClearedState(uris, true);
ensureDownloadsClearedState(downloadIDs, true);
intPrefIs("sanitize.timeSpan", Sanitizer.TIMESPAN_HOUR,
"timeSpan pref should be hour after accepting dialog with " +
"hour selected");
boolPrefIs("cpd.history", true,
"history pref should be true after accepting dialog with " +
"history checkbox checked");
boolPrefIs("cpd.downloads", true,
"downloads pref should be true after accepting dialog with " +
"history checkbox checked");
// Visits and downloads > 1 hour should still exist.
ensureHistoryClearedState(olderURIs, false);
ensureDownloadsClearedState(olderDownloadIDs, false);
// History visits and downloads within one hour should be cleared.
ensureHistoryClearedState(uris, true);
ensureDownloadsClearedState(downloadIDs, true);
// OK, done, cleanup after ourselves.
blankSlate();
ensureHistoryClearedState(olderURIs, true);
ensureDownloadsClearedState(olderDownloadIDs, true);
};
wh.open();
// Visits and downloads > 1 hour should still exist.
ensureHistoryClearedState(olderURIs, false);
ensureDownloadsClearedState(olderDownloadIDs, false);
// OK, done, cleanup after ourselves.
blankSlate();
ensureHistoryClearedState(olderURIs, true);
ensureDownloadsClearedState(olderDownloadIDs, true);
};
wh.open();
});
},
/**
@ -144,51 +161,58 @@ var gAllTests = [
function () {
// Add history, downloads, form entries (within the past hour).
let uris = [];
let places = [];
let pURI;
for (let i = 0; i < 5; i++) {
uris.push(addHistoryWithMinutesAgo(i));
}
let downloadIDs = [];
for (let i = 0; i < 5; i++) {
downloadIDs.push(addDownloadWithMinutesAgo(i));
}
let formEntries = [];
for (let i = 0; i < 5; i++) {
formEntries.push(addFormEntryWithMinutesAgo(i));
pURI = makeURI("http://" + i + "-minutes-ago.com/");
places.push({uri: pURI, visitDate: visitTimeForMinutesAgo(i)});
uris.push(pURI);
}
let wh = new WindowHelper();
wh.onload = function () {
is(this.isWarningPanelVisible(), false,
"Warning panel should be hidden after previously accepting dialog " +
"with a predefined timespan");
this.selectDuration(Sanitizer.TIMESPAN_HOUR);
addVisits(places, function() {
let downloadIDs = [];
for (let i = 0; i < 5; i++) {
downloadIDs.push(addDownloadWithMinutesAgo(i));
}
let formEntries = [];
for (let i = 0; i < 5; i++) {
formEntries.push(addFormEntryWithMinutesAgo(i));
}
// Remove only form entries, leave history (including downloads).
this.checkPrefCheckbox("history", false);
this.checkPrefCheckbox("formdata", true);
this.acceptDialog();
let wh = new WindowHelper();
wh.onload = function () {
is(this.isWarningPanelVisible(), false,
"Warning panel should be hidden after previously accepting dialog " +
"with a predefined timespan");
this.selectDuration(Sanitizer.TIMESPAN_HOUR);
intPrefIs("sanitize.timeSpan", Sanitizer.TIMESPAN_HOUR,
"timeSpan pref should be hour after accepting dialog with " +
"hour selected");
boolPrefIs("cpd.history", false,
"history pref should be false after accepting dialog with " +
"history checkbox unchecked");
boolPrefIs("cpd.downloads", false,
"downloads pref should be false after accepting dialog with " +
"history checkbox unchecked");
// Remove only form entries, leave history (including downloads).
this.checkPrefCheckbox("history", false);
this.checkPrefCheckbox("formdata", true);
this.acceptDialog();
// Of the three only form entries should be cleared.
ensureHistoryClearedState(uris, false);
ensureDownloadsClearedState(downloadIDs, false);
ensureFormEntriesClearedState(formEntries, true);
intPrefIs("sanitize.timeSpan", Sanitizer.TIMESPAN_HOUR,
"timeSpan pref should be hour after accepting dialog with " +
"hour selected");
boolPrefIs("cpd.history", false,
"history pref should be false after accepting dialog with " +
"history checkbox unchecked");
boolPrefIs("cpd.downloads", false,
"downloads pref should be false after accepting dialog with " +
"history checkbox unchecked");
// OK, done, cleanup after ourselves.
blankSlate();
ensureHistoryClearedState(uris, true);
ensureDownloadsClearedState(downloadIDs, true);
};
wh.open();
// Of the three only form entries should be cleared.
ensureHistoryClearedState(uris, false);
ensureDownloadsClearedState(downloadIDs, false);
ensureFormEntriesClearedState(formEntries, true);
// OK, done, cleanup after ourselves.
blankSlate();
ensureHistoryClearedState(uris, true);
ensureDownloadsClearedState(downloadIDs, true);
};
wh.open();
});
},
/**
@ -197,36 +221,42 @@ var gAllTests = [
function () {
// Add history.
let uris = [];
uris.push(addHistoryWithMinutesAgo(10)); // within past hour
uris.push(addHistoryWithMinutesAgo(70)); // within past two hours
uris.push(addHistoryWithMinutesAgo(130)); // within past four hours
uris.push(addHistoryWithMinutesAgo(250)); // outside past four hours
let places = [];
let pURI;
// within past hour, within past two hours, within past four hours and
// outside past four hours
[10, 70, 130, 250].forEach(function(aValue) {
pURI = makeURI("http://" + aValue + "-minutes-ago.com/");
places.push({uri: pURI, visitDate: visitTimeForMinutesAgo(aValue)});
uris.push(pURI);
});
addVisits(places, function() {
let wh = new WindowHelper();
wh.onload = function () {
is(this.isWarningPanelVisible(), false,
"Warning panel should be hidden after previously accepting dialog " +
"with a predefined timespan");
this.selectDuration(Sanitizer.TIMESPAN_EVERYTHING);
this.checkPrefCheckbox("history", true);
this.checkDetails(true);
let wh = new WindowHelper();
wh.onload = function () {
is(this.isWarningPanelVisible(), false,
"Warning panel should be hidden after previously accepting dialog " +
"with a predefined timespan");
this.selectDuration(Sanitizer.TIMESPAN_EVERYTHING);
this.checkPrefCheckbox("history", true);
this.checkDetails(true);
// Hide details
this.toggleDetails();
this.checkDetails(false);
// Hide details
this.toggleDetails();
this.checkDetails(false);
// Show details
this.toggleDetails();
this.checkDetails(true);
// Show details
this.toggleDetails();
this.checkDetails(true);
this.acceptDialog();
this.acceptDialog();
intPrefIs("sanitize.timeSpan", Sanitizer.TIMESPAN_EVERYTHING,
"timeSpan pref should be everything after accepting dialog " +
"with everything selected");
ensureHistoryClearedState(uris, true);
};
wh.open();
intPrefIs("sanitize.timeSpan", Sanitizer.TIMESPAN_EVERYTHING,
"timeSpan pref should be everything after accepting dialog " +
"with everything selected");
ensureHistoryClearedState(uris, true);
};
wh.open();
});
},
/**
@ -236,26 +266,32 @@ var gAllTests = [
function () {
// Add history.
let uris = [];
uris.push(addHistoryWithMinutesAgo(10)); // within past hour
uris.push(addHistoryWithMinutesAgo(70)); // within past two hours
uris.push(addHistoryWithMinutesAgo(130)); // within past four hours
uris.push(addHistoryWithMinutesAgo(250)); // outside past four hours
let places = [];
let pURI;
// within past hour, within past two hours, within past four hours and
// outside past four hours
[10, 70, 130, 250].forEach(function(aValue) {
pURI = makeURI("http://" + aValue + "-minutes-ago.com/");
places.push({uri: pURI, visitDate: visitTimeForMinutesAgo(aValue)});
uris.push(pURI);
});
addVisits(places, function() {
let wh = new WindowHelper();
wh.onload = function () {
is(this.isWarningPanelVisible(), true,
"Warning panel should be visible after previously accepting dialog " +
"with clearing everything");
this.selectDuration(Sanitizer.TIMESPAN_EVERYTHING);
this.checkPrefCheckbox("history", true);
this.acceptDialog();
let wh = new WindowHelper();
wh.onload = function () {
is(this.isWarningPanelVisible(), true,
"Warning panel should be visible after previously accepting dialog " +
"with clearing everything");
this.selectDuration(Sanitizer.TIMESPAN_EVERYTHING);
this.checkPrefCheckbox("history", true);
this.acceptDialog();
intPrefIs("sanitize.timeSpan", Sanitizer.TIMESPAN_EVERYTHING,
"timeSpan pref should be everything after accepting dialog " +
"with everything selected");
ensureHistoryClearedState(uris, true);
};
wh.open();
intPrefIs("sanitize.timeSpan", Sanitizer.TIMESPAN_EVERYTHING,
"timeSpan pref should be everything after accepting dialog " +
"with everything selected");
ensureHistoryClearedState(uris, true);
};
wh.open();
});
},
/**
@ -265,29 +301,32 @@ var gAllTests = [
*/
function () {
// Add history.
let uris = [ addHistoryWithMinutesAgo(10) ];
let formEntries = [ addFormEntryWithMinutesAgo(10) ];
let pURI = makeURI("http://" + 10 + "-minutes-ago.com/");
addVisits({uri: pURI, visitDate: visitTimeForMinutesAgo(10)}, function() {
let uris = [ pURI ];
let formEntries = [ addFormEntryWithMinutesAgo(10) ];
let wh = new WindowHelper();
wh.onload = function() {
// Check that the relevant checkboxes are enabled
var cb = this.win.document.querySelectorAll(
"#itemList > [preference='privacy.cpd.formdata']");
ok(cb.length == 1 && !cb[0].disabled, "There is formdata, checkbox to " +
"clear formdata should be enabled.");
let wh = new WindowHelper();
wh.onload = function() {
// Check that the relevant checkboxes are enabled
var cb = this.win.document.querySelectorAll(
"#itemList > [preference='privacy.cpd.formdata']");
ok(cb.length == 1 && !cb[0].disabled, "There is formdata, checkbox to " +
"clear formdata should be enabled.");
var cb = this.win.document.querySelectorAll(
"#itemList > [preference='privacy.cpd.history']");
ok(cb.length == 1 && !cb[0].disabled, "There is history, checkbox to " +
"clear history should be enabled.");
var cb = this.win.document.querySelectorAll(
"#itemList > [preference='privacy.cpd.history']");
ok(cb.length == 1 && !cb[0].disabled, "There is history, checkbox to " +
"clear history should be enabled.");
this.checkAllCheckboxes();
this.acceptDialog();
this.checkAllCheckboxes();
this.acceptDialog();
ensureHistoryClearedState(uris, true);
ensureFormEntriesClearedState(formEntries, true);
};
wh.open();
ensureHistoryClearedState(uris, true);
ensureFormEntriesClearedState(formEntries, true);
};
wh.open();
});
},
function () {
let wh = new WindowHelper();
@ -853,26 +892,6 @@ function addFormEntryWithMinutesAgo(aMinutesAgo) {
return name;
}
/**
* Adds a history visit to history.
*
* @param aMinutesAgo
* The visit will be visited this many minutes ago
*/
function addHistoryWithMinutesAgo(aMinutesAgo) {
let pURI = makeURI("http://" + aMinutesAgo + "-minutes-ago.com/");
PlacesUtils.history.addVisit(pURI,
now_uSec - aMinutesAgo * kUsecPerMin,
null,
Ci.nsINavHistoryService.TRANSITION_LINK,
false,
0);
is(PlacesUtils.bhistory.isVisited(pURI), true,
"Sanity check: history visit " + pURI.spec +
" should exist after creating it");
return pURI;
}
/**
* Removes all history visits, downloads, and form entries.
*/
@ -1034,6 +1053,16 @@ function intPrefIs(aPrefName, aExpectedVal, aMsg) {
is(gPrefService.getIntPref("privacy." + aPrefName), aExpectedVal, aMsg);
}
/**
* Creates a visit time.
*
* @param aMinutesAgo
* The visit will be visited this many minutes ago
*/
function visitTimeForMinutesAgo(aMinutesAgo) {
return now_uSec - aMinutesAgo * kUsecPerMin;
}
///////////////////////////////////////////////////////////////////////////////
function test() {

View File

@ -35,48 +35,54 @@ var gAllTests = [
function () {
// Add history (within the past hour) to get some rows in the tree.
let uris = [];
let places = [];
let pURI;
for (let i = 0; i < 30; i++) {
uris.push(addHistoryWithMinutesAgo(i));
pURI = makeURI("http://" + i + "-minutes-ago.com/");
places.push({uri: pURI, visitDate: visitTimeForMinutesAgo(i)});
uris.push(pURI);
}
// Open the dialog and do our tests.
openWindow(function (aWin) {
let wh = new WindowHelper(aWin);
wh.selectDuration(Sanitizer.TIMESPAN_HOUR);
wh.checkGrippy("Grippy should be at last row after selecting HOUR " +
"duration",
wh.getRowCount() - 1);
addVisits(places, function() {
// Open the dialog and do our tests.
openWindow(function (aWin) {
let wh = new WindowHelper(aWin);
wh.selectDuration(Sanitizer.TIMESPAN_HOUR);
wh.checkGrippy("Grippy should be at last row after selecting HOUR " +
"duration",
wh.getRowCount() - 1);
// Move the grippy around.
let row = wh.getGrippyRow();
while (row !== 0) {
row--;
// Move the grippy around.
let row = wh.getGrippyRow();
while (row !== 0) {
row--;
wh.moveGrippyBy(-1);
wh.checkGrippy("Grippy should be moved up one row", row);
}
wh.moveGrippyBy(-1);
wh.checkGrippy("Grippy should be moved up one row", row);
}
wh.moveGrippyBy(-1);
wh.checkGrippy("Grippy should remain at first row after trying to move " +
"it up",
0);
while (row !== wh.getRowCount() - 1) {
row++;
wh.checkGrippy("Grippy should remain at first row after trying to move " +
"it up",
0);
while (row !== wh.getRowCount() - 1) {
row++;
wh.moveGrippyBy(1);
wh.checkGrippy("Grippy should be moved down one row", row);
}
wh.moveGrippyBy(1);
wh.checkGrippy("Grippy should be moved down one row", row);
}
wh.moveGrippyBy(1);
wh.checkGrippy("Grippy should remain at last row after trying to move " +
"it down",
wh.getRowCount() - 1);
wh.checkGrippy("Grippy should remain at last row after trying to move " +
"it down",
wh.getRowCount() - 1);
// Cancel the dialog, make sure history visits are not cleared.
wh.checkPrefCheckbox("history", false);
// Cancel the dialog, make sure history visits are not cleared.
wh.checkPrefCheckbox("history", false);
wh.cancelDialog();
ensureHistoryClearedState(uris, false);
wh.cancelDialog();
ensureHistoryClearedState(uris, false);
// OK, done, cleanup after ourselves.
blankSlate();
ensureHistoryClearedState(uris, true);
// OK, done, cleanup after ourselves.
blankSlate();
ensureHistoryClearedState(uris, true);
});
});
},
@ -85,49 +91,60 @@ var gAllTests = [
* visits and downloads when checked; the dialog respects simple timespan.
*/
function () {
// Add history and downloads (within the past hour).
// Add history (within the past hour).
let uris = [];
let places = [];
let pURI;
for (let i = 0; i < 30; i++) {
uris.push(addHistoryWithMinutesAgo(i));
pURI = makeURI("http://" + i + "-minutes-ago.com/");
places.push({uri: pURI, visitDate: visitTimeForMinutesAgo(i)});
uris.push(pURI);
}
let downloadIDs = [];
for (let i = 0; i < 5; i++) {
downloadIDs.push(addDownloadWithMinutesAgo(i));
}
// Add history and downloads (over an hour ago).
// Add history (over an hour ago).
let olderURIs = [];
for (let i = 0; i < 5; i++) {
olderURIs.push(addHistoryWithMinutesAgo(61 + i));
pURI = makeURI("http://" + (60 + i) + "-minutes-ago.com/");
places.push({uri: pURI, visitDate: visitTimeForMinutesAgo(60 + i)});
olderURIs.push(pURI);
}
let olderDownloadIDs = [];
for (let i = 0; i < 5; i++) {
olderDownloadIDs.push(addDownloadWithMinutesAgo(61 + i));
}
let totalHistoryVisits = uris.length + olderURIs.length;
// Open the dialog and do our tests.
openWindow(function (aWin) {
let wh = new WindowHelper(aWin);
wh.selectDuration(Sanitizer.TIMESPAN_HOUR);
wh.checkGrippy("Grippy should be at proper row after selecting HOUR " +
"duration",
uris.length);
addVisits(places, function() {
// Add downloads (within the past hour).
let downloadIDs = [];
for (let i = 0; i < 5; i++) {
downloadIDs.push(addDownloadWithMinutesAgo(i));
}
// Add downloads (over an hour ago).
let olderDownloadIDs = [];
for (let i = 0; i < 5; i++) {
olderDownloadIDs.push(addDownloadWithMinutesAgo(61 + i));
}
let totalHistoryVisits = uris.length + olderURIs.length;
// Accept the dialog, make sure history visits and downloads within one
// hour are cleared.
wh.checkPrefCheckbox("history", true);
wh.acceptDialog();
ensureHistoryClearedState(uris, true);
ensureDownloadsClearedState(downloadIDs, true);
// Open the dialog and do our tests.
openWindow(function (aWin) {
let wh = new WindowHelper(aWin);
wh.selectDuration(Sanitizer.TIMESPAN_HOUR);
wh.checkGrippy("Grippy should be at proper row after selecting HOUR " +
"duration",
uris.length);
// Make sure visits and downloads > 1 hour still exist.
ensureHistoryClearedState(olderURIs, false);
ensureDownloadsClearedState(olderDownloadIDs, false);
// Accept the dialog, make sure history visits and downloads within one
// hour are cleared.
wh.checkPrefCheckbox("history", true);
wh.acceptDialog();
ensureHistoryClearedState(uris, true);
ensureDownloadsClearedState(downloadIDs, true);
// OK, done, cleanup after ourselves.
blankSlate();
ensureHistoryClearedState(olderURIs, true);
ensureDownloadsClearedState(olderDownloadIDs, true);
// Make sure visits and downloads > 1 hour still exist.
ensureHistoryClearedState(olderURIs, false);
ensureDownloadsClearedState(olderDownloadIDs, false);
// OK, done, cleanup after ourselves.
blankSlate();
ensureHistoryClearedState(olderURIs, true);
ensureDownloadsClearedState(olderDownloadIDs, true);
});
});
},
@ -138,40 +155,47 @@ var gAllTests = [
function () {
// Add history, downloads, form entries (within the past hour).
let uris = [];
let places = [];
let pURI;
for (let i = 0; i < 5; i++) {
uris.push(addHistoryWithMinutesAgo(i));
}
let downloadIDs = [];
for (let i = 0; i < 5; i++) {
downloadIDs.push(addDownloadWithMinutesAgo(i));
}
let formEntries = [];
for (let i = 0; i < 5; i++) {
formEntries.push(addFormEntryWithMinutesAgo(i));
pURI = makeURI("http://" + i + "-minutes-ago.com/");
places.push({uri: pURI, visitDate: visitTimeForMinutesAgo(i)});
uris.push(pURI);
}
// Open the dialog and do our tests.
openWindow(function (aWin) {
let wh = new WindowHelper(aWin);
wh.selectDuration(Sanitizer.TIMESPAN_HOUR);
wh.checkGrippy("Grippy should be at last row after selecting HOUR " +
"duration",
wh.getRowCount() - 1);
addVisits(places, function() {
let downloadIDs = [];
for (let i = 0; i < 5; i++) {
downloadIDs.push(addDownloadWithMinutesAgo(i));
}
let formEntries = [];
for (let i = 0; i < 5; i++) {
formEntries.push(addFormEntryWithMinutesAgo(i));
}
// Remove only form entries, leave history (including downloads).
wh.checkPrefCheckbox("history", false);
wh.checkPrefCheckbox("formdata", true);
wh.acceptDialog();
// Open the dialog and do our tests.
openWindow(function (aWin) {
let wh = new WindowHelper(aWin);
wh.selectDuration(Sanitizer.TIMESPAN_HOUR);
wh.checkGrippy("Grippy should be at last row after selecting HOUR " +
"duration",
wh.getRowCount() - 1);
// Of the three only form entries should be cleared.
ensureHistoryClearedState(uris, false);
ensureDownloadsClearedState(downloadIDs, false);
ensureFormEntriesClearedState(formEntries, true);
// Remove only form entries, leave history (including downloads).
wh.checkPrefCheckbox("history", false);
wh.checkPrefCheckbox("formdata", true);
wh.acceptDialog();
// OK, done, cleanup after ourselves.
blankSlate();
ensureHistoryClearedState(uris, true);
ensureDownloadsClearedState(downloadIDs, true);
// Of the three only form entries should be cleared.
ensureHistoryClearedState(uris, false);
ensureDownloadsClearedState(downloadIDs, false);
ensureFormEntriesClearedState(formEntries, true);
// OK, done, cleanup after ourselves.
blankSlate();
ensureHistoryClearedState(uris, true);
ensureDownloadsClearedState(downloadIDs, true);
});
});
},
@ -181,18 +205,25 @@ var gAllTests = [
function () {
// Add history.
let uris = [];
uris.push(addHistoryWithMinutesAgo(10)); // within past hour
uris.push(addHistoryWithMinutesAgo(70)); // within past two hours
uris.push(addHistoryWithMinutesAgo(130)); // within past four hours
uris.push(addHistoryWithMinutesAgo(250)); // outside past four hours
let places = [];
let pURI;
// within past hour, within past two hours, within past four hours and
// outside past four hours
[10, 70, 130, 250].forEach(function(aValue) {
pURI = makeURI("http://" + aValue + "-minutes-ago.com/");
places.push({uri: pURI, visitDate: visitTimeForMinutesAgo(aValue)});
uris.push(pURI);
});
addVisits(places, function() {
// Open the dialog and do our tests.
openWindow(function (aWin) {
let wh = new WindowHelper(aWin);
wh.selectDuration(Sanitizer.TIMESPAN_EVERYTHING);
wh.checkPrefCheckbox("history", true);
wh.acceptDialog();
ensureHistoryClearedState(uris, true);
// Open the dialog and do our tests.
openWindow(function (aWin) {
let wh = new WindowHelper(aWin);
wh.selectDuration(Sanitizer.TIMESPAN_EVERYTHING);
wh.checkPrefCheckbox("history", true);
wh.acceptDialog();
ensureHistoryClearedState(uris, true);
});
});
}
];
@ -462,26 +493,6 @@ function addFormEntryWithMinutesAgo(aMinutesAgo) {
return name;
}
/**
* Adds a history visit to history.
*
* @param aMinutesAgo
* The visit will be visited this many minutes ago
*/
function addHistoryWithMinutesAgo(aMinutesAgo) {
let pURI = makeURI("http://" + aMinutesAgo + "-minutes-ago.com/");
PlacesUtils.history.addVisit(pURI,
now_uSec - (aMinutesAgo * 60 * 1000 * 1000),
null,
Ci.nsINavHistoryService.TRANSITION_LINK,
false,
0);
is(PlacesUtils.bhistory.isVisited(pURI), true,
"Sanity check: history visit " + pURI.spec +
" should exist after creating it");
return pURI;
}
/**
* Removes all history visits, downloads, and form entries.
*/
@ -653,6 +664,16 @@ function openWindow(aOnloadCallback) {
null);
}
/**
* Creates a visit time.
*
* @param aMinutesAgo
* The visit will be visited this many minutes ago
*/
function visitTimeForMinutesAgo(aMinutesAgo) {
return now_uSec - (aMinutesAgo * 60 * 1000000);
}
///////////////////////////////////////////////////////////////////////////////
function test() {

View File

@ -131,3 +131,42 @@ function whenNewWindowLoaded(aOptions, aCallback) {
aCallback(win);
}, false);
}
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();
}
}
);
}

View File

@ -2,12 +2,6 @@
* http://creativecommons.org/publicdomain/zero/1.0/
*/
function add_visit(aURI, aReferrer) {
return PlacesUtils.history.addVisit(aURI, Date.now() * 1000, aReferrer,
PlacesUtils.history.TRANSITION_TYPED,
false, 0);
}
function add_bookmark(aURI) {
return PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId,
aURI, PlacesUtils.bookmarks.DEFAULT_INDEX,
@ -38,13 +32,14 @@ function onLibraryReady() {
ContentTree = gLibrary.ContentTree;
ok(ContentTree, "ContentTree is in scope");
tests.makeHistVisit();
tests.makeTag();
tests.focusTag();
waitForClipboard(function(aData) !!aData,
tests.copyHistNode,
onClipboardReady,
PlacesUtils.TYPE_X_MOZ_PLACE);
tests.makeHistVisit(function() {
tests.makeTag();
tests.focusTag();
waitForClipboard(function(aData) !!aData,
tests.copyHistNode,
onClipboardReady,
PlacesUtils.TYPE_X_MOZ_PLACE);
});
}
function onClipboardReady() {
@ -67,13 +62,17 @@ function onClipboardReady() {
let tests = {
makeHistVisit: function() {
makeHistVisit: function(aCallback) {
// need to add a history object
let testURI1 = NetUtil.newURI(MOZURISPEC);
isnot(testURI1, null, "testURI is not null");
let visitId = add_visit(testURI1);
ok(visitId > 0, "A visit was added to the history");
ok(PlacesUtils.ghistory2.isVisited(testURI1), MOZURISPEC + " is a visited url.");
addVisits(
{uri: testURI1, transition: PlacesUtils.history.TRANSITION_TYPED},
window,
function() {
ok(PlacesUtils.ghistory2.isVisited(testURI1), MOZURISPEC + " is a visited url.");
aCallback();
});
},
makeTag: function() {

View File

@ -40,17 +40,6 @@ var win = wm.getMostRecentWindow("navigator:browser");
var ww = Cc["@mozilla.org/embedcomp/window-watcher;1"].
getService(Ci.nsIWindowWatcher);
function add_visit(aURI, aDate) {
var visitId = PlacesUtils.history
.addVisit(aURI,
aDate,
null, // no referrer
PlacesUtils.history.TRANSITION_TYPED,
false, // not redirect
0);
return visitId;
}
function add_bookmark(aURI) {
var bId = PlacesUtils.bookmarks
.insertBookmark(PlacesUtils.unfiledBookmarksFolderId,
@ -75,8 +64,9 @@ gTests.push({
historyView: SIDEBAR_HISTORY_BYLASTVISITED_VIEW, // See constants above, only for History sidebar.
window: null, // Will contain handle of dialog window
setup: function() {
setup: function(aCallback) {
// Setup everything needed for this test, runs before everything else.
aCallback();
},
selectNode: function(tree) {
@ -110,8 +100,9 @@ gTests.push({
itemType: null,
window: null,
setup: function() {
setup: function(aCallback) {
// Nothing to do.
aCallback();
},
selectNode: function(tree) {
@ -169,7 +160,7 @@ gTests.push({
_itemId: null,
_cleanShutdown: false,
setup: function() {
setup: function(aCallback) {
// Add a bookmark in unsorted bookmarks folder.
this._itemId = add_bookmark(PlacesUtils._uri(TEST_URL));
ok(this._itemId > 0, "Correctly added a bookmark");
@ -178,6 +169,7 @@ gTests.push({
["testTag"]);
var tags = PlacesUtils.tagging.getTagsForURI(PlacesUtils._uri(TEST_URL));
is(tags[0], "testTag", "Correctly added a tag");
aCallback();
},
selectNode: function(tree) {
@ -265,8 +257,9 @@ gTests.push({
window: null,
_itemId: null,
setup: function() {
setup: function(aCallback) {
// Nothing to do.
aCallback();
},
selectNode: function(tree) {
@ -323,7 +316,7 @@ gTests.push({
_itemId: null,
_cleanShutdown: false,
setup: function() {
setup: function(aCallback) {
// Add a bookmark in unsorted bookmarks folder.
this._itemId = add_bookmark(PlacesUtils._uri(TEST_URL));
ok(this._itemId > 0, "Correctly added a bookmark");
@ -332,6 +325,7 @@ gTests.push({
["testTag"]);
var tags = PlacesUtils.tagging.getTagsForURI(PlacesUtils._uri(TEST_URL));
is(tags[0], "testTag", "Correctly added a tag");
aCallback();
},
selectNode: function(tree) {
@ -419,12 +413,13 @@ gTests.push({
historyView: SIDEBAR_HISTORY_BYLASTVISITED_VIEW,
window: null,
setup: function() {
setup: function(aCallback) {
// Add a visit.
add_visit(PlacesUtils._uri(TEST_URL), Date.now() * 1000);
// Sanity check.
var gh = PlacesUtils.history.QueryInterface(Ci.nsIGlobalHistory2);
ok(gh.isVisited(PlacesUtils._uri(TEST_URL)), TEST_URL + " is a visited url.");
addVisits(
{uri: PlacesUtils._uri(TEST_URL),
transition: PlacesUtils.history.TRANSITION_TYPED},
window,
aCallback);
},
selectNode: function(tree) {
@ -511,8 +506,9 @@ function runNextTest() {
// Goto next tests.
gCurrentTest = gTests.shift();
info("Start of test: " + gCurrentTest.desc);
gCurrentTest.setup();
execute_test_in_sidebar();
gCurrentTest.setup(function() {
execute_test_in_sidebar();
});
}
else {
// Finished all tests.

View File

@ -11,11 +11,18 @@ function test() {
// Add a history entry.
let TEST_URIs = ["http://www.mozilla.org/test1", "http://www.mozilla.org/test2"];
ok(PlacesUtils, "checking PlacesUtils, running in chrome context?");
let history = PlacesUtils.history;
let places = [];
TEST_URIs.forEach(function(TEST_URI) {
let visitId = history.addVisit(PlacesUtils._uri(TEST_URI), Date.now() * 1000,
null, PlacesUtils.history.TRANSITION_TYPED, false, 0);
ok(visitId > 0, TEST_URI + " successfully marked visited");
places.push({uri: PlacesUtils._uri(TEST_URI),
transition: PlacesUtils.history.TRANSITION_TYPED});
});
addVisits(places, window, function() {
testForgetThisSiteVisibility(1, function() {
testForgetThisSiteVisibility(2, function() {
// Cleanup
waitForClearHistory(finish);
});
});
});
function testForgetThisSiteVisibility(selectionCount, funcNext) {
@ -62,11 +69,5 @@ function test() {
EventUtils.synthesizeMouse(tree.body, x.value + width.value / 2, y.value + height.value / 2, {type: "contextmenu"}, organizer);
});
}
testForgetThisSiteVisibility(1, function() {
testForgetThisSiteVisibility(2, function() {
// Cleanup
waitForClearHistory(finish);
});
});
}

View File

@ -17,16 +17,6 @@ function uri(spec) {
var sidebar = document.getElementById("sidebar");
function add_visit(aURI, aDate) {
var visitId = hs.addVisit(aURI,
aDate,
null, // no referrer
hs.TRANSITION_TYPED, // user typed in URL bar
false, // not redirect
0);
return visitId;
}
// Visited pages listed by descending visit date.
var pages = [
"http://sidebar.mozilla.org/a",
@ -47,9 +37,15 @@ function test() {
function continue_test() {
// Add some visited page.
var time = Date.now();
for (var i = 0; i < pages.length; i++) {
add_visit(uri(pages[i]), (time - i) * 1000);
var pagesLength = pages.length;
var places = [];
for (var i = 0; i < pagesLength; i++) {
places.push({uri: uri(pages[i]), visitDate: (time - i) * 1000,
transition: hs.TRANSITION_TYPED});
}
addVisits(places, window, function() {
toggleSidebar("viewHistorySidebar", true);
});
sidebar.addEventListener("load", function() {
sidebar.removeEventListener("load", arguments.callee, true);
@ -71,7 +67,6 @@ function continue_test() {
waitForClearHistory(finish);
});
}, true);
toggleSidebar("viewHistorySidebar", true);
}
function check_sidebar_tree_order(aExpectedRows) {

View File

@ -21,101 +21,105 @@ gTests.push({
let ContentTree = gLibrary.ContentTree;
var infoBoxExpanderWrapper = getAndCheckElmtById("infoBoxExpanderWrapper");
function addVisitsCallback() {
var bhist = PlacesUtils.history.QueryInterface(Ci.nsIBrowserHistory);
ok(bhist.isVisited(PlacesUtils._uri(TEST_URI)), "Visit has been added.");
// open all bookmarks node
PO.selectLeftPaneQuery("AllBookmarks");
isnot(PO._places.selectedNode, null,
"Correctly selected all bookmarks node.");
checkInfoBoxSelected(PO);
ok(infoBoxExpanderWrapper.hidden,
"Expander button is hidden for all bookmarks node.");
checkAddInfoFieldsCollapsed(PO);
// open history node
PO.selectLeftPaneQuery("History");
isnot(PO._places.selectedNode, null, "Correctly selected history node.");
checkInfoBoxSelected(PO);
ok(infoBoxExpanderWrapper.hidden,
"Expander button is hidden for history node.");
checkAddInfoFieldsCollapsed(PO);
// open history child node
var historyNode = PO._places.selectedNode.
QueryInterface(Ci.nsINavHistoryContainerResultNode);
historyNode.containerOpen = true;
var childNode = historyNode.getChild(0);
isnot(childNode, null, "History node first child is not null.");
PO._places.selectNode(childNode);
checkInfoBoxSelected(PO);
ok(infoBoxExpanderWrapper.hidden,
"Expander button is hidden for history child node.");
checkAddInfoFieldsCollapsed(PO);
// open history item
var view = ContentTree.view.treeBoxObject.view;
ok(view.rowCount > 0, "History item exists.");
view.selection.select(0);
ok(infoBoxExpanderWrapper.hidden,
"Expander button is hidden for history item.");
checkAddInfoFieldsCollapsed(PO);
historyNode.containerOpen = false;
// open bookmarks menu node
PO.selectLeftPaneQuery("BookmarksMenu");
isnot(PO._places.selectedNode, null,
"Correctly selected bookmarks menu node.");
checkInfoBoxSelected(PO);
ok(infoBoxExpanderWrapper.hidden,
"Expander button is hidden for bookmarks menu node.");
checkAddInfoFieldsCollapsed(PO);
// open recently bookmarked node
var menuNode = PO._places.selectedNode.
QueryInterface(Ci.nsINavHistoryContainerResultNode);
menuNode.containerOpen = true;
childNode = menuNode.getChild(0);
isnot(childNode, null, "Bookmarks menu child node exists.");
var recentlyBookmarkedTitle = PlacesUIUtils.
getString("recentlyBookmarkedTitle");
isnot(recentlyBookmarkedTitle, null,
"Correctly got the recently bookmarked title locale string.");
is(childNode.title, recentlyBookmarkedTitle,
"Correctly selected recently bookmarked node.");
PO._places.selectNode(childNode);
checkInfoBoxSelected(PO);
ok(!infoBoxExpanderWrapper.hidden,
"Expander button is not hidden for recently bookmarked node.");
checkAddInfoFieldsNotCollapsed(PO);
// open first bookmark
var view = ContentTree.view.treeBoxObject.view;
ok(view.rowCount > 0, "Bookmark item exists.");
view.selection.select(0);
checkInfoBoxSelected(PO);
ok(!infoBoxExpanderWrapper.hidden,
"Expander button is not hidden for bookmark item.");
checkAddInfoFieldsNotCollapsed(PO);
checkAddInfoFields(PO, "bookmark item");
// make sure additional fields are still hidden in second bookmark item
ok(view.rowCount > 1, "Second bookmark item exists.");
view.selection.select(1);
checkInfoBoxSelected(PO);
ok(!infoBoxExpanderWrapper.hidden,
"Expander button is not hidden for second bookmark item.");
checkAddInfoFieldsNotCollapsed(PO);
checkAddInfoFields(PO, "second bookmark item");
menuNode.containerOpen = false;
waitForClearHistory(nextTest);
}
// add a visit to browser history
var bhist = PlacesUtils.history.QueryInterface(Ci.nsIBrowserHistory);
PlacesUtils.history.addVisit(PlacesUtils._uri(TEST_URI), Date.now() * 1000,
null, PlacesUtils.history.TRANSITION_TYPED,
false, 0);
ok(bhist.isVisited(PlacesUtils._uri(TEST_URI)), "Visit has been added.");
// open all bookmarks node
PO.selectLeftPaneQuery("AllBookmarks");
isnot(PO._places.selectedNode, null,
"Correctly selected all bookmarks node.");
checkInfoBoxSelected(PO);
ok(infoBoxExpanderWrapper.hidden,
"Expander button is hidden for all bookmarks node.");
checkAddInfoFieldsCollapsed(PO);
// open history node
PO.selectLeftPaneQuery("History");
isnot(PO._places.selectedNode, null, "Correctly selected history node.");
checkInfoBoxSelected(PO);
ok(infoBoxExpanderWrapper.hidden,
"Expander button is hidden for history node.");
checkAddInfoFieldsCollapsed(PO);
// open history child node
var historyNode = PO._places.selectedNode.
QueryInterface(Ci.nsINavHistoryContainerResultNode);
historyNode.containerOpen = true;
var childNode = historyNode.getChild(0);
isnot(childNode, null, "History node first child is not null.");
PO._places.selectNode(childNode);
checkInfoBoxSelected(PO);
ok(infoBoxExpanderWrapper.hidden,
"Expander button is hidden for history child node.");
checkAddInfoFieldsCollapsed(PO);
// open history item
var view = ContentTree.view.treeBoxObject.view;
ok(view.rowCount > 0, "History item exists.");
view.selection.select(0);
ok(infoBoxExpanderWrapper.hidden,
"Expander button is hidden for history item.");
checkAddInfoFieldsCollapsed(PO);
historyNode.containerOpen = false;
// open bookmarks menu node
PO.selectLeftPaneQuery("BookmarksMenu");
isnot(PO._places.selectedNode, null,
"Correctly selected bookmarks menu node.");
checkInfoBoxSelected(PO);
ok(infoBoxExpanderWrapper.hidden,
"Expander button is hidden for bookmarks menu node.");
checkAddInfoFieldsCollapsed(PO);
// open recently bookmarked node
var menuNode = PO._places.selectedNode.
QueryInterface(Ci.nsINavHistoryContainerResultNode);
menuNode.containerOpen = true;
childNode = menuNode.getChild(0);
isnot(childNode, null, "Bookmarks menu child node exists.");
var recentlyBookmarkedTitle = PlacesUIUtils.
getString("recentlyBookmarkedTitle");
isnot(recentlyBookmarkedTitle, null,
"Correctly got the recently bookmarked title locale string.");
is(childNode.title, recentlyBookmarkedTitle,
"Correctly selected recently bookmarked node.");
PO._places.selectNode(childNode);
checkInfoBoxSelected(PO);
ok(!infoBoxExpanderWrapper.hidden,
"Expander button is not hidden for recently bookmarked node.");
checkAddInfoFieldsNotCollapsed(PO);
// open first bookmark
var view = ContentTree.view.treeBoxObject.view;
ok(view.rowCount > 0, "Bookmark item exists.");
view.selection.select(0);
checkInfoBoxSelected(PO);
ok(!infoBoxExpanderWrapper.hidden,
"Expander button is not hidden for bookmark item.");
checkAddInfoFieldsNotCollapsed(PO);
checkAddInfoFields(PO, "bookmark item");
// make sure additional fields are still hidden in second bookmark item
ok(view.rowCount > 1, "Second bookmark item exists.");
view.selection.select(1);
checkInfoBoxSelected(PO);
ok(!infoBoxExpanderWrapper.hidden,
"Expander button is not hidden for second bookmark item.");
checkAddInfoFieldsNotCollapsed(PO);
checkAddInfoFields(PO, "second bookmark item");
menuNode.containerOpen = false;
waitForClearHistory(nextTest);
addVisits(
{ uri: PlacesUtils._uri(TEST_URI), visitDate: Date.now() * 1000,
transition: PlacesUtils.history.TRANSITION_TYPED },
window,
addVisitsCallback);
}
});

View File

@ -18,53 +18,57 @@ var gLibrary;
gTests.push({
desc: "Bug 489351 - Date containers under History in Library cannot be deleted/cut",
run: function() {
var bhist = PlacesUtils.history.QueryInterface(Ci.nsIBrowserHistory);
// Add a visit.
PlacesUtils.history.addVisit(PlacesUtils._uri(TEST_URI), Date.now() * 1000,
null, PlacesUtils.history.TRANSITION_TYPED,
false, 0);
ok(bhist.isVisited(PlacesUtils._uri(TEST_URI)), "Visit has been added");
function addVisitsCallback() {
var bhist = PlacesUtils.history.QueryInterface(Ci.nsIBrowserHistory);
// Add a visit.
ok(bhist.isVisited(PlacesUtils._uri(TEST_URI)), "Visit has been added");
// Select and open the left pane "History" query.
var PO = gLibrary.PlacesOrganizer;
PO.selectLeftPaneQuery('History');
isnot(PO._places.selectedNode, null, "We correctly selected History");
// Select and open the left pane "History" query.
var PO = gLibrary.PlacesOrganizer;
PO.selectLeftPaneQuery('History');
isnot(PO._places.selectedNode, null, "We correctly selected History");
// Check that both delete and cut commands are disabled.
ok(!PO._places.controller.isCommandEnabled("cmd_cut"),
"Cut command is disabled");
ok(!PO._places.controller.isCommandEnabled("cmd_delete"),
"Delete command is disabled");
var historyNode = PO._places.selectedNode
.QueryInterface(Ci.nsINavHistoryContainerResultNode);
historyNode.containerOpen = true;
// Check that both delete and cut commands are disabled.
ok(!PO._places.controller.isCommandEnabled("cmd_cut"),
"Cut command is disabled");
ok(!PO._places.controller.isCommandEnabled("cmd_delete"),
"Delete command is disabled");
var historyNode = PO._places.selectedNode
.QueryInterface(Ci.nsINavHistoryContainerResultNode);
historyNode.containerOpen = true;
// Check that we have a child container. It is "Today" container.
is(historyNode.childCount, 1, "History node has one child");
var todayNode = historyNode.getChild(0);
var todayNodeExpectedTitle = PlacesUtils.getString("finduri-AgeInDays-is-0");
is(todayNode.title, todayNodeExpectedTitle,
"History child is the expected container");
// Check that we have a child container. It is "Today" container.
is(historyNode.childCount, 1, "History node has one child");
var todayNode = historyNode.getChild(0);
var todayNodeExpectedTitle = PlacesUtils.getString("finduri-AgeInDays-is-0");
is(todayNode.title, todayNodeExpectedTitle,
"History child is the expected container");
// Select "Today" container.
PO._places.selectNode(todayNode);
is(PO._places.selectedNode, todayNode,
"We correctly selected Today container");
// Check that delete command is enabled but cut command is disabled.
ok(!PO._places.controller.isCommandEnabled("cmd_cut"),
"Cut command is disabled");
ok(PO._places.controller.isCommandEnabled("cmd_delete"),
"Delete command is enabled");
// Select "Today" container.
PO._places.selectNode(todayNode);
is(PO._places.selectedNode, todayNode,
"We correctly selected Today container");
// Check that delete command is enabled but cut command is disabled.
ok(!PO._places.controller.isCommandEnabled("cmd_cut"),
"Cut command is disabled");
ok(PO._places.controller.isCommandEnabled("cmd_delete"),
"Delete command is enabled");
// Execute the delete command and check visit has been removed.
PO._places.controller.doCommand("cmd_delete");
ok(!bhist.isVisited(PlacesUtils._uri(TEST_URI)), "Visit has been removed");
// Execute the delete command and check visit has been removed.
PO._places.controller.doCommand("cmd_delete");
ok(!bhist.isVisited(PlacesUtils._uri(TEST_URI)), "Visit has been removed");
// Test live update of "History" query.
is(historyNode.childCount, 0, "History node has no more children");
// Test live update of "History" query.
is(historyNode.childCount, 0, "History node has no more children");
historyNode.containerOpen = false;
nextTest();
historyNode.containerOpen = false;
nextTest();
}
addVisits(
{uri: PlacesUtils._uri(TEST_URI), visitDate: Date.now() * 1000,
transition: PlacesUtils.history.TRANSITION_TYPED},
window,
addVisitsCallback);
}
});

View File

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

View File

@ -169,17 +169,19 @@ function test() {
ok(PlacesUtils, "PlacesUtils in context");
// Add visits, a bookmark and a tag.
PlacesUtils.history.addVisit(PlacesUtils._uri(TEST_URL),
Date.now() * 1000, null,
PlacesUtils.history.TRANSITION_TYPED, false, 0);
PlacesUtils.history.addVisit(PlacesUtils._uri(TEST_DOWNLOAD_URL),
Date.now() * 1000, null,
PlacesUtils.history.TRANSITION_DOWNLOAD, false, 0);
PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId,
PlacesUtils._uri(TEST_URL),
PlacesUtils.bookmarks.DEFAULT_INDEX,
"dummy");
PlacesUtils.tagging.tagURI(PlacesUtils._uri(TEST_URL), ["dummyTag"]);
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() {
PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId,
PlacesUtils._uri(TEST_URL),
PlacesUtils.bookmarks.DEFAULT_INDEX,
"dummy");
PlacesUtils.tagging.tagURI(PlacesUtils._uri(TEST_URL), ["dummyTag"]);
gLibrary = openLibrary(onLibraryAvailable);
gLibrary = openLibrary(onLibraryAvailable);
});
}

View File

@ -27,12 +27,13 @@ function test() {
tests.push({
_itemID: null,
init: function() {
init: function(aCallback) {
// Add a bookmark to the Unfiled Bookmarks folder.
this._itemID = PlacesUtils.bookmarks.insertBookmark(
PlacesUtils.unfiledBookmarksFolderId, PlacesUtils._uri(TEST_URL),
PlacesUtils.bookmarks.DEFAULT_INDEX, "test"
);
aCallback();
},
prepare: function() {
},
@ -49,13 +50,14 @@ function test() {
});
tests.push({
init: function() {
init: function(aCallback) {
// Add a history entry.
let uri = PlacesUtils._uri(TEST_URL);
PlacesUtils.history.addVisit(uri, Date.now() * 1000, null,
PlacesUtils.history.TRANSITION_TYPED,
false, 0);
ok(PlacesUtils.ghistory2.isVisited(uri), "Item is visited");
addVisits(
{ uri: uri, visitDate: Date.now() * 1000,
transition: PlacesUtils.history.TRANSITION_TYPED },
window,
aCallback);
},
prepare: function() {
sidebar.contentDocument.getElementById("byvisited").doCommand();
@ -74,7 +76,9 @@ function test() {
});
function testPlacesPanel(preFunc, postFunc) {
currentTest.init();
currentTest.init(function() {
toggleSidebar(currentTest.sidebarName);
});
sidebar.addEventListener("load", function() {
sidebar.removeEventListener("load", arguments.callee, true);
@ -113,7 +117,6 @@ function test() {
// for the purpose of this test.
});
}, true);
toggleSidebar(currentTest.sidebarName);
}
function synthesizeClickOnSelectedTreeCell(aTree) {

View File

@ -82,3 +82,66 @@ 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 ? Ci.nsINavHistoryService.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();
}
}
);
}
XPCOMUtils.defineLazyModuleGetter(this, "Promise",
"resource://gre/modules/commonjs/promise/core.js");

View File

@ -11,6 +11,7 @@ relativesrcdir = @relativesrcdir@
include $(DEPTH)/config/autoconf.mk
MOCHITEST_CHROME_FILES = \
head.js \
test_treeview_date.xul \
test_bug485100-change-case-loses-tag.xul \
test_bug427633_no_newfolder_if_noip.xul \

View File

@ -0,0 +1,55 @@
/**
* 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

@ -19,6 +19,7 @@
<script type="application/javascript"
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js" />
<script type="application/javascript" src="head.js" />
<body xmlns="http://www.w3.org/1999/xhtml" />
@ -51,46 +52,46 @@
// Add some visits.
let vtime = Date.now() * 1000;
const ttype = PlacesUtils.history.TRANSITION_TYPED;
PlacesUtils.history
.addVisit(Services.io.newURI("http://example.tld/", null, null),
vtime, null, ttype, false, 0);
PlacesUtils.history
.addVisit(Services.io.newURI("http://example2.tld/", null, null),
vtime++, null, ttype, false, 0);
PlacesUtils.history
.addVisit(Services.io.newURI("http://exmample3.tld/", null, null),
vtime++, null, ttype, false, 0);
// Make a history query.
let query = PlacesUtils.history.getNewQuery();
let opts = PlacesUtils.history.getNewQueryOptions();
let queryURI = PlacesUtils.history.queriesToQueryString([query], 1, opts);
addVisits(
[{ uri: Services.io.newURI("http://example.tld/", null, null),
visitDate: vtime, transition: ttype },
{ uri: Services.io.newURI("http://example2.tld/", null, null),
visitDate: vtime++, transition: ttype },
{ uri: Services.io.newURI("http://example3.tld/", null, null),
visitDate: vtime++, transition: ttype }],
function() {
// Make a history query.
let query = PlacesUtils.history.getNewQuery();
let opts = PlacesUtils.history.getNewQueryOptions();
let queryURI = PlacesUtils.history.queriesToQueryString([query], 1, opts);
// Setup the places tree contents.
var tree = document.getElementById("tree");
tree.place = queryURI;
// Setup the places tree contents.
var tree = document.getElementById("tree");
tree.place = queryURI;
// loop through the rows and check formatting
let treeView = tree.view;
for (let i = 0; i < rc; i++) {
selection.select(rc);
let node = tree.selectedNode;
ok(true, "found " + node.title);
}
let rc = treeView.rowCount;
is(rc, 3, "Rows found.");
let selection = treeView.selection;
for (let i = 0; i < rc; i++) {
selection.select(0);
let node = tree.selectedNode;
tree.controller.remove("Removing page");
ok(treeView.treeIndexForNode(node) == Ci.nsINavHistoryResultTreeViewer.INDEX_INVISIBLE,
node.uri + " removed.");
ok(treeView.rowCount == rc - i - 1, "Rows count decreased");
}
// loop through the rows and check formatting
let treeView = tree.view;
for (let i = 0; i < rc; i++) {
selection.select(rc);
let node = tree.selectedNode;
ok(true, "found " + node.title);
}
let rc = treeView.rowCount;
is(rc, 3, "Rows found.");
let selection = treeView.selection;
for (let i = 0; i < rc; i++) {
selection.select(0);
let node = tree.selectedNode;
tree.controller.remove("Removing page");
ok(treeView.treeIndexForNode(node) == Ci.nsINavHistoryResultTreeViewer.INDEX_INVISIBLE,
node.uri + " removed.");
ok(treeView.rowCount == rc - i - 1, "Rows count decreased");
}
// Cleanup.
waitForClearHistory(SimpleTest.finish);
// Cleanup.
waitForClearHistory(SimpleTest.finish);
});
}
/**

View File

@ -19,6 +19,7 @@
<script type="application/javascript"
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js" />
<script type="application/javascript" src="head.js" />
<body xmlns="http://www.w3.org/1999/xhtml" />
@ -51,27 +52,28 @@
}
function continue_test() {
PlacesUtils.history
.addVisit(Services.io.newURI("http://example.tld/", null, null),
Date.now() * 1000, null, PlacesUtils.history.TRANSITION_TYPED, false, 0);
addVisits(
{uri: Services.io.newURI("http://example.tld/", null, null),
transition: PlacesUtils.history.TRANSITION_TYPED},
function() {
// Make a history query.
let query = PlacesUtils.history.getNewQuery();
let opts = PlacesUtils.history.getNewQueryOptions();
let queryURI = PlacesUtils.history.queriesToQueryString([query], 1, opts);
// Make a history query.
let query = PlacesUtils.history.getNewQuery();
let opts = PlacesUtils.history.getNewQueryOptions();
let queryURI = PlacesUtils.history.queriesToQueryString([query], 1, opts);
// Setup the places tree contents.
let tree = document.getElementById("tree");
tree.place = queryURI;
// Setup the places tree contents.
let tree = document.getElementById("tree");
tree.place = queryURI;
let rootNode = tree.result.root;
let obs = tree.view.QueryInterface(Ci.nsINavHistoryResultObserver);
obs.nodeHistoryDetailsChanged(rootNode, rootNode.time, rootNode.accessCount);
obs.nodeTitleChanged(rootNode, rootNode.title);
ok(true, "No exceptions thrown");
let rootNode = tree.result.root;
let obs = tree.view.QueryInterface(Ci.nsINavHistoryResultObserver);
obs.nodeHistoryDetailsChanged(rootNode, rootNode.time, rootNode.accessCount);
obs.nodeTitleChanged(rootNode, rootNode.title);
ok(true, "No exceptions thrown");
// Cleanup.
waitForClearHistory(SimpleTest.finish);
// Cleanup.
waitForClearHistory(SimpleTest.finish);
});
}
/**

View File

@ -18,6 +18,7 @@
<script type="application/javascript"
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js" />
<script type="application/javascript" src="head.js" />
<body xmlns="http://www.w3.org/1999/xhtml" />
@ -77,91 +78,92 @@
midnight.setSeconds(0);
midnight.setMilliseconds(0);
// Add a visit 1ms before midnight.
hs.addVisit(uri("http://before.midnight.com/"),
(midnight.getTime() - 1) * 1000,
null, hs.TRANSITION_TYPED, false, 0);
function addVisitsCallback() {
// add a bookmark to the midnight visit
var itemId = bs.insertBookmark(bs.toolbarFolder,
uri("http://at.midnight.com/"),
bs.DEFAULT_INDEX,
"A bookmark at midnight");
// Add a visit at midnight.
hs.addVisit(uri("http://at.midnight.com/"),
(midnight.getTime()) * 1000,
null, hs.TRANSITION_TYPED, false, 0);
// Make a history query.
var query = hs.getNewQuery();
var opts = hs.getNewQueryOptions();
var queryURI = hs.queriesToQueryString([query], 1, opts);
// Add a visit 1ms after midnight.
hs.addVisit(uri("http://after.midnight.com/"),
(midnight.getTime() + 1) * 1000,
null, hs.TRANSITION_TYPED, false, 0);
// Setup the places tree contents.
var tree = document.getElementById("tree");
tree.place = queryURI;
// add a bookmark to the midnight visit
var itemId = bs.insertBookmark(bs.toolbarFolder,
uri("http://at.midnight.com/"),
bs.DEFAULT_INDEX,
"A bookmark at midnight");
// Make a history query.
var query = hs.getNewQuery();
var opts = hs.getNewQueryOptions();
var queryURI = hs.queriesToQueryString([query], 1, opts);
// Setup the places tree contents.
var tree = document.getElementById("tree");
tree.place = queryURI;
// loop through the rows and check formatting
var treeView = tree.view;
var rc = treeView.rowCount;
ok(rc >= 3, "Rows found");
var columns = tree.columns;
ok(columns.count > 0, "Columns found");
for (var r = 0; r < rc; r++) {
var node = treeView.nodeForTreeIndex(r);
ok(node, "Places node found");
for (var ci = 0; ci < columns.count; ci++) {
var c = columns.getColumnAt(ci);
var text = treeView.getCellText(r, c);
switch (c.element.getAttribute("anonid")) {
case "title":
// The title can differ, we did not set any title so we would
// expect null, but in such a case the view will generate a title
// through PlacesUIUtils.getBestTitle.
if (node.title)
is(text, node.title, "Title is correct");
break;
case "url":
is(text, node.uri, "Uri is correct");
break;
case "date":
var timeObj = new Date(node.time / 1000);
// Default is short date format.
var dateFormat = Ci.nsIScriptableDateFormat.dateFormatShort;
// For today's visits we don't show date portion.
if (node.uri == "http://at.midnight.com/" ||
node.uri == "http://after.midnight.com/")
dateFormat = Ci.nsIScriptableDateFormat.dateFormatNone;
else if (node.uri == "http://before.midnight.com/")
dateFormat = Ci.nsIScriptableDateFormat.dateFormatShort;
else {
// Avoid to test spurious uris, due to how the test works
// a redirecting uri could be put in the tree while we test.
// loop through the rows and check formatting
var treeView = tree.view;
var rc = treeView.rowCount;
ok(rc >= 3, "Rows found");
var columns = tree.columns;
ok(columns.count > 0, "Columns found");
for (var r = 0; r < rc; r++) {
var node = treeView.nodeForTreeIndex(r);
ok(node, "Places node found");
for (var ci = 0; ci < columns.count; ci++) {
var c = columns.getColumnAt(ci);
var text = treeView.getCellText(r, c);
switch (c.element.getAttribute("anonid")) {
case "title":
// The title can differ, we did not set any title so we would
// expect null, but in such a case the view will generate a title
// through PlacesUIUtils.getBestTitle.
if (node.title)
is(text, node.title, "Title is correct");
break;
}
var timeStr = ds.FormatDateTime("", dateFormat,
Ci.nsIScriptableDateFormat.timeFormatNoSeconds,
timeObj.getFullYear(), timeObj.getMonth() + 1,
timeObj.getDate(), timeObj.getHours(),
timeObj.getMinutes(), timeObj.getSeconds())
case "url":
is(text, node.uri, "Uri is correct");
break;
case "date":
var timeObj = new Date(node.time / 1000);
// Default is short date format.
var dateFormat = Ci.nsIScriptableDateFormat.dateFormatShort;
// For today's visits we don't show date portion.
if (node.uri == "http://at.midnight.com/" ||
node.uri == "http://after.midnight.com/")
dateFormat = Ci.nsIScriptableDateFormat.dateFormatNone;
else if (node.uri == "http://before.midnight.com/")
dateFormat = Ci.nsIScriptableDateFormat.dateFormatShort;
else {
// Avoid to test spurious uris, due to how the test works
// a redirecting uri could be put in the tree while we test.
break;
}
var timeStr = ds.FormatDateTime("", dateFormat,
Ci.nsIScriptableDateFormat.timeFormatNoSeconds,
timeObj.getFullYear(), timeObj.getMonth() + 1,
timeObj.getDate(), timeObj.getHours(),
timeObj.getMinutes(), timeObj.getSeconds())
is(text, timeStr, "Date format is correct");
break;
case "visitCount":
is(text, 1, "Visit count is correct");
break;
is(text, timeStr, "Date format is correct");
break;
case "visitCount":
is(text, 1, "Visit count is correct");
break;
}
}
}
// Cleanup.
bs.removeItem(itemId);
waitForClearHistory(SimpleTest.finish);
}
// Cleanup.
bs.removeItem(itemId);
waitForClearHistory(SimpleTest.finish);
// Add a visit 1ms before midnight, a visit at midnight, and
// a visit 1ms after midnight.
addVisits(
[{uri: uri("http://before.midnight.com/"),
visitDate: (midnight.getTime() - 1) * 1000,
transition: hs.TRANSITION_TYPED},
{uri: uri("http://at.midnight.com/"),
visitDate: (midnight.getTime()) * 1000,
transition: hs.TRANSITION_TYPED},
{uri: uri("http://after.midnight.com/"),
visitDate: (midnight.getTime() + 1) * 1000,
transition: hs.TRANSITION_TYPED}],
addVisitsCallback);
}
/**

View File

@ -73,6 +73,10 @@ let notificationsObserver = {
let timeInMicroseconds = Date.now() * 1000;
function run_test() {
run_next_test();
}
add_task(function test_execute() {
do_test_pending();
print("Initialize browserglue before Places");
@ -96,14 +100,13 @@ function run_test() {
Services.prefs.setBoolPref("privacy.sanitize.sanitizeOnShutdown", true);
print("Add visits.");
URIS.forEach(function(aUrl) {
PlacesUtils.history.addVisit(uri(aUrl), timeInMicroseconds++, null,
PlacesUtils.history.TRANSITION_TYPED,
false, 0);
});
for (let aUrl of URIS) {
yield promiseAddVisits({uri: uri(aUrl), visitDate: timeInMicroseconds++,
transition: PlacesUtils.history.TRANSITION_TYPED})
}
print("Add cache.");
storeCache(URL, "testData");
}
});
function run_test_continue()
{

View File

@ -12,6 +12,7 @@ include $(DEPTH)/config/autoconf.mk
include $(topsrcdir)/config/rules.mk
_BROWSER_FILES = \
head.js \
browser_advanced_update.js \
browser_bug410900.js \
browser_bug705422.js \

View File

@ -28,27 +28,28 @@ const TEST_PERMS = {
function test() {
waitForExplicitFinish();
registerCleanupFunction(cleanUp);
setup();
runNextTest();
setup(function() {
runNextTest();
});
}
function setup() {
function setup(aCallback) {
// add test history visit
PlacesUtils.history.addVisit(TEST_URI_1, Date.now() * 1000, null,
Ci.nsINavHistoryService.TRANSITION_LINK, false, 0);
// set permissions ourselves to avoid problems with different defaults
// from test harness configuration
for (let type in TEST_PERMS) {
if (type == "password") {
Services.logins.setLoginSavingEnabled(TEST_URI_2.prePath, true);
} else {
// set permissions on a site without history visits to test enumerateServices
Services.perms.add(TEST_URI_2, type, TEST_PERMS[type]);
addVisits(TEST_URI_1, function() {
// set permissions ourselves to avoid problems with different defaults
// from test harness configuration
for (let type in TEST_PERMS) {
if (type == "password") {
Services.logins.setLoginSavingEnabled(TEST_URI_2.prePath, true);
} else {
// set permissions on a site without history visits to test enumerateServices
Services.perms.add(TEST_URI_2, type, TEST_PERMS[type]);
}
}
}
Services.perms.add(TEST_URI_3, "popup", TEST_PERMS["popup"]);
Services.perms.add(TEST_URI_3, "popup", TEST_PERMS["popup"]);
aCallback();
});
}
function cleanUp() {

View File

@ -44,28 +44,27 @@ function test() {
registerCleanupFunction(cleanUp);
// add test history visit
PlacesUtils.history.addVisit(TEST_URI_1, Date.now() * 1000, null,
Ci.nsINavHistoryService.TRANSITION_LINK, false, 0);
// set permissions ourselves to avoid problems with different defaults
// from test harness configuration
for (let type in TEST_PERMS) {
if (type == "password") {
Services.logins.setLoginSavingEnabled(TEST_URI_2.prePath, true);
} else {
// set permissions on a site without history visits to test enumerateServices
Services.perms.addFromPrincipal(TEST_PRINCIPAL_2, type, TEST_PERMS[type]);
addVisits(TEST_URI_1, function() {
// set permissions ourselves to avoid problems with different defaults
// from test harness configuration
for (let type in TEST_PERMS) {
if (type == "password") {
Services.logins.setLoginSavingEnabled(TEST_URI_2.prePath, true);
} else {
// set permissions on a site without history visits to test enumerateServices
Services.perms.addFromPrincipal(TEST_PRINCIPAL_2, type, TEST_PERMS[type]);
}
}
}
// open about:permissions
gBrowser.selectedTab = gBrowser.addTab("about:permissions");
});
function observer() {
Services.obs.removeObserver(observer, "browser-permissions-initialized", false);
runNextTest();
}
Services.obs.addObserver(observer, "browser-permissions-initialized", false);
// open about:permissions
gBrowser.selectedTab = gBrowser.addTab("about:permissions");
}
function cleanUp() {

View File

@ -0,0 +1,57 @@
Components.utils.import("resource://gre/modules/PlacesUtils.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

@ -32,10 +32,34 @@ function test() {
// Add a history entry.
const TEST_URI = "http://www.mozilla.org/privatebrowsing";
ok(PlacesUtils, "checking PlacesUtils, running in chrome context?");
let history = PlacesUtils.history;
let visitId = history.addVisit(PlacesUtils._uri(TEST_URI), Date.now() * 1000,
null, PlacesUtils.history.TRANSITION_TYPED, false, 0);
ok(visitId > 0, TEST_URI + " successfully marked visited");
let place = {
uri: PlacesUtils._uri(TEST_URI),
visits: [{
visitDate: Date.now() * 1000,
transitionType: PlacesUtils.history.TRANSITION_TYPED
}]
}
PlacesUtils.asyncHistory.updatePlaces(place, {
handleError: function () ok(false, "couldn't add visit"),
handleResult: function () {},
handleCompletion: function () {
ok(true, TEST_URI + " successfully marked visited");
testForgetThisSiteVisibility(true, function() {
// Enter private browsing mode
pb.privateBrowsingEnabled = true;
testForgetThisSiteVisibility(false, function() {
// Leave private browsing mode
pb.privateBrowsingEnabled = false;
testForgetThisSiteVisibility(true, function() {
// Cleanup
waitForClearHistory(finish);
});
});
});
}
});
function testForgetThisSiteVisibility(expected, funcNext) {
function observer(aSubject, aTopic, aData) {
@ -102,17 +126,4 @@ function test() {
"chrome,toolbar=yes,dialog=no,resizable",
null);
}
testForgetThisSiteVisibility(true, function() {
// Enter private browsing mode
pb.privateBrowsingEnabled = true;
testForgetThisSiteVisibility(false, function() {
// Leave private browsing mode
pb.privateBrowsingEnabled = false;
testForgetThisSiteVisibility(true, function() {
// Cleanup
waitForClearHistory(finish);
});
});
});
}

View File

@ -45,16 +45,18 @@ function runTests() {
yield clearHistory(true);
// Retry until the file is gone because Windows locks it sometimes.
while (file.exists()) {
clearFile(file, URL);
}
function clearFile(aFile, aURL) {
if (aFile.exists())
// Re-add our URL to the history so that history observer's onDeleteURI()
// is called again.
let time = Date.now() * 1000;
let trans = Ci.nsINavHistoryService.TRANSITION_LINK;
PlacesUtils.history.addVisit(makeURI(URL), time, null, trans, false, 0);
// Try again...
yield clearHistory(true);
}
addVisits(makeURI(aURL), function() {
// Try again...
yield clearHistory(true);
clearFile(aFile, aURL);
});
}
function clearHistory(aUseRange) {

View File

@ -6,6 +6,8 @@ Cu.import("resource:///modules/PageThumbs.jsm", tmp);
let PageThumbs = tmp.PageThumbs;
let PageThumbsStorage = tmp.PageThumbsStorage;
Cu.import("resource://gre/modules/PlacesUtils.jsm");
registerCleanupFunction(function () {
while (gBrowser.tabs.length > 1)
gBrowser.removeTab(gBrowser.tabs[1]);
@ -155,3 +157,60 @@ function thumbnailExists(aURL) {
let file = PageThumbsStorage.getFileForURL(aURL);
return file.exists() && file.fileSize;
}
/**
* 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();
}
}
);
}