Bug 400544 - nsINavHistoryService::addVisit should take a uri for the referrer, not a place id. r=mano, a=beltzner.

git-svn-id: svn://10.0.0.236/trunk@241962 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
sdwilsh%shawnwilsher.com 2007-12-21 19:37:18 +00:00
parent 0e3578d8b3
commit f1d5f60eb3
9 changed files with 85 additions and 50 deletions

View File

@ -1160,7 +1160,7 @@ interface nsINavHistoryQueryOptions : nsISupports
nsINavHistoryQueryOptions clone();
};
[scriptable, uuid(c5846d2c-5340-4cfb-9c0d-c15feca939ce)]
[scriptable, uuid(a9bea2db-0a3e-4895-9ccc-24bac41a0674)]
interface nsINavHistoryService : nsISupports
{
/**
@ -1265,9 +1265,8 @@ interface nsINavHistoryService : nsISupports
*
* @param aURI Visited page
* @param aTime Time page was visited (microseconds)
* @param aReferringVisit The ID of the visit that generated this one. Use 0
* for no referrer. This must be a valid visit already
* in the DB or 0.
* @param aReferringURI The URI of the visit that generated this one. Use
* null for no referrer.
* @param aTranstitionType Type of transition: one of TRANSITION_* above
* @param aIsRedirect True if the given visit redirects to somewhere else.
* (ie you will create an visit out of here that is a
@ -1280,7 +1279,7 @@ interface nsINavHistoryService : nsISupports
* valid for adding to history (canAddURI = false).
*/
long long addVisit(in nsIURI aURI, in PRTime aTime,
in long long aReferringVisit, in long aTransitionType,
in nsIURI aReferringURI, in long aTransitionType,
in boolean aIsRedirect, in long long aSessionID);
/**

View File

@ -1885,7 +1885,7 @@ nsNavHistory::SetPageDetails(nsIURI* aURI, const nsAString& aTitle,
// added to the history.
NS_IMETHODIMP
nsNavHistory::AddVisit(nsIURI* aURI, PRTime aTime, PRInt64 aReferringVisit,
nsNavHistory::AddVisit(nsIURI* aURI, PRTime aTime, nsIURI* aReferringURI,
PRInt32 aTransitionType, PRBool aIsRedirect,
PRInt64 aSessionID, PRInt64* aVisitID)
{
@ -2001,7 +2001,19 @@ nsNavHistory::AddVisit(nsIURI* aURI, PRTime aTime, PRInt64 aReferringVisit,
NS_ENSURE_SUCCESS(rv, rv);
}
rv = InternalAddVisit(pageID, aReferringVisit, aSessionID, aTime,
// Get the place id for the referrer, if we have one
PRInt64 referringVisitID = 0;
PRInt64 referringSessionID;
if (aReferringURI &&
!FindLastVisit(aReferringURI, &referringVisitID, &referringSessionID)) {
// Add the referrer
rv = AddVisit(aReferringURI, aTime - 1, nsnull, TRANSITION_LINK, PR_FALSE,
aSessionID, &referringVisitID);
if (NS_FAILED(rv))
referringVisitID = 0;
}
rv = InternalAddVisit(pageID, referringVisitID, aSessionID, aTime,
aTransitionType, aVisitID);
// Notify observers: The hidden detection code must match that in
@ -2011,7 +2023,7 @@ nsNavHistory::AddVisit(nsIURI* aURI, PRTime aTime, PRInt64 aReferringVisit,
if (! hidden && aTransitionType != TRANSITION_EMBED) {
ENUMERATE_WEAKARRAY(mObservers, nsINavHistoryObserver,
OnVisit(aURI, *aVisitID, aTime, aSessionID,
aReferringVisit, aTransitionType));
referringVisitID, aTransitionType));
}
// Normally docshell send the link visited observer notification for us (this
@ -3254,7 +3266,7 @@ nsNavHistory::AddVisitChain(nsIURI* aURI, PRTime aTime,
}
// this call will create the visit and create/update the page entry
return AddVisit(aURI, visitTime, referringVisit, transitionType,
return AddVisit(aURI, visitTime, aReferrer, transitionType,
aIsRedirect, *aSessionID, aVisitID);
}

View File

@ -664,7 +664,7 @@ function run_test() {
// bug 378820
var uri1 = uri("http://foo.tld/a");
bmsvc.insertBookmark(testRoot, uri1, bmsvc.DEFAULT_INDEX, "");
histsvc.addVisit(uri1, Date.now(), 0, histsvc.TRANSITION_TYPED, false, 0);
histsvc.addVisit(uri1, Date.now(), null, histsvc.TRANSITION_TYPED, false, 0);
testSimpleFolderResult();
}

View File

@ -50,7 +50,7 @@ try {
function add_visit(aURI, aWhen, aType) {
var placeID = histsvc.addVisit(aURI,
aWhen,
0, // no referrer
null, // no referrer
aType,
false, // not redirect
0);

View File

@ -50,7 +50,7 @@ try {
function add_visit(aURI, aType) {
var placeID = histsvc.addVisit(uri(aURI),
Date.now(),
0, // no referrer
null, // no referrer
aType,
false, // not redirect
0);

View File

@ -118,7 +118,7 @@ function run_test() {
test that nsIBrowserHistory.removePagesFromHost does remove expirable annotations
but doesn't remove bookmarks or EXPIRE_NEVER annotations.
*/
histsvc.addVisit(testURI, Date.now() * 1000, 0, histsvc.TRANSITION_TYPED, false, 0);
histsvc.addVisit(testURI, Date.now() * 1000, null, histsvc.TRANSITION_TYPED, false, 0);
annosvc.setPageAnnotation(testURI, testAnnoName + "Hist", testAnnoVal, 0, annosvc.EXPIRE_WITH_HISTORY);
annosvc.setPageAnnotation(testURI, testAnnoName + "Never", testAnnoVal, 0, annosvc.EXPIRE_NEVER);
bhist.removePagesFromHost("mozilla.com", false);
@ -136,7 +136,7 @@ function run_test() {
*/
var removeAllTestURI = uri("http://removeallpages.com");
var removeAllTestURINever = uri("http://removeallpagesnever.com");
histsvc.addVisit(removeAllTestURI, Date.now() * 1000, 0, histsvc.TRANSITION_TYPED, false, 0);
histsvc.addVisit(removeAllTestURI, Date.now() * 1000, null, histsvc.TRANSITION_TYPED, false, 0);
var bmURI = uri("http://bookmarked");
bmsvc.insertBookmark(bmsvc.bookmarksMenuFolder, bmURI, bmsvc.DEFAULT_INDEX, "foo");
//bhist.addPageWithDetails(placeURI, "place uri", Date.now());
@ -167,7 +167,7 @@ function run_test() {
/*
test anno expiration (expire never)
*/
histsvc.addVisit(testURI, Date.now() * 1000, 0, histsvc.TRANSITION_TYPED, false, 0);
histsvc.addVisit(testURI, Date.now() * 1000, null, histsvc.TRANSITION_TYPED, false, 0);
annosvc.setPageAnnotation(testURI, testAnnoName, testAnnoVal, 0, annosvc.EXPIRE_NEVER);
annosvc.setItemAnnotation(bookmark, testAnnoName, testAnnoVal, 0, annosvc.EXPIRE_NEVER);
histsvc.removeAllPages();
@ -179,7 +179,7 @@ function run_test() {
/*
test anno expiration (expire with history)
*/
histsvc.addVisit(testURI, Date.now() * 1000, 0, histsvc.TRANSITION_TYPED, false, 0);
histsvc.addVisit(testURI, Date.now() * 1000, null, histsvc.TRANSITION_TYPED, false, 0);
annosvc.setPageAnnotation(testURI, testAnnoName, testAnnoVal, 0, annosvc.EXPIRE_WITH_HISTORY);
histsvc.removeAllPages();
try {
@ -195,7 +195,7 @@ function run_test() {
- try to get the anno (should fail. maybe race here? is there a way to determine
if the page has been added, so we know that expiration is done?)
*/
histsvc.addVisit(testURI, Date.now() * 1000, 0, histsvc.TRANSITION_TYPED, false, 0);
histsvc.addVisit(testURI, Date.now() * 1000, null, histsvc.TRANSITION_TYPED, false, 0);
// these annotations should be removed (after manually tweaking their dateAdded)
annosvc.setPageAnnotation(testURI, testAnnoName, testAnnoVal, 0, annosvc.EXPIRE_DAYS);
@ -211,7 +211,7 @@ function run_test() {
annosvc.setItemAnnotation(bookmark, testAnnoName + "NotExpired", testAnnoVal, 0, annosvc.EXPIRE_DAYS);
// add a uri and then remove it, to trigger expiration
histsvc.addVisit(triggerURI, Date.now() * 1000, 0, histsvc.TRANSITION_TYPED, false, 0);
histsvc.addVisit(triggerURI, Date.now() * 1000, null, histsvc.TRANSITION_TYPED, false, 0);
bhist.removePage(triggerURI);
// test for unexpired annos
@ -239,7 +239,7 @@ function run_test() {
} catch(ex) {}
// test anno expiration (days) removes annos annos 6 days old
histsvc.addVisit(testURI, Date.now() * 1000, 0, histsvc.TRANSITION_TYPED, false, 0);
histsvc.addVisit(testURI, Date.now() * 1000, null, histsvc.TRANSITION_TYPED, false, 0);
annosvc.setPageAnnotation(testURI, testAnnoName, testAnnoVal, 0, annosvc.EXPIRE_DAYS);
annosvc.setItemAnnotation(bookmark, testAnnoName, testAnnoVal, 0, annosvc.EXPIRE_DAYS);
// these annotations should remain as they are only 6 days old
@ -248,7 +248,7 @@ function run_test() {
dbConnection.executeSimpleSQL("UPDATE moz_items_annos SET dateAdded = " + expirationDate);
// add a uri and then remove it, to trigger expiration
histsvc.addVisit(triggerURI, Date.now() * 1000, 0, histsvc.TRANSITION_TYPED, false, 0);
histsvc.addVisit(triggerURI, Date.now() * 1000, null, histsvc.TRANSITION_TYPED, false, 0);
bhist.removePage(triggerURI);
// test for unexpired annos
@ -267,7 +267,7 @@ function run_test() {
// test anno expiration (weeks) removes annos 31 days old
histsvc.addVisit(testURI, Date.now() * 1000, 0, histsvc.TRANSITION_TYPED, false, 0);
histsvc.addVisit(testURI, Date.now() * 1000, null, histsvc.TRANSITION_TYPED, false, 0);
annosvc.setPageAnnotation(testURI, testAnnoName, testAnnoVal, 0, annosvc.EXPIRE_WEEKS);
annosvc.setItemAnnotation(bookmark, testAnnoName, testAnnoVal, 0, annosvc.EXPIRE_WEEKS);
// these annotations should not remain as they are 31 days old
@ -279,7 +279,7 @@ function run_test() {
annosvc.setItemAnnotation(bookmark, testAnnoName + "NotExpired", testAnnoVal, 0, annosvc.EXPIRE_WEEKS);
// add a uri and then remove it, to trigger expiration
histsvc.addVisit(triggerURI, Date.now() * 1000, 0, histsvc.TRANSITION_TYPED, false, 0);
histsvc.addVisit(triggerURI, Date.now() * 1000, null, histsvc.TRANSITION_TYPED, false, 0);
bhist.removePage(triggerURI);
// test for unexpired annos
@ -306,7 +306,7 @@ function run_test() {
} catch(ex) {}
// test anno expiration (weeks) does not remove annos 29 days old
histsvc.addVisit(testURI, Date.now() * 1000, 0, histsvc.TRANSITION_TYPED, false, 0);
histsvc.addVisit(testURI, Date.now() * 1000, null, histsvc.TRANSITION_TYPED, false, 0);
annosvc.setPageAnnotation(testURI, testAnnoName, testAnnoVal, 0, annosvc.EXPIRE_WEEKS);
annosvc.setItemAnnotation(bookmark, testAnnoName, testAnnoVal, 0, annosvc.EXPIRE_WEEKS);
// these annotations should remain as they are only 29 days old
@ -315,7 +315,7 @@ function run_test() {
dbConnection.executeSimpleSQL("UPDATE moz_items_annos SET dateAdded = " + expirationDate);
// add a uri and then remove it, to trigger expiration
histsvc.addVisit(triggerURI, Date.now() * 1000, 0, histsvc.TRANSITION_TYPED, false, 0);
histsvc.addVisit(triggerURI, Date.now() * 1000, null, histsvc.TRANSITION_TYPED, false, 0);
bhist.removePage(triggerURI);
// test for unexpired annos
@ -343,7 +343,7 @@ function run_test() {
annosvc.setItemAnnotation(bookmark, testAnnoName + "NotExpired", testAnnoVal, 0, annosvc.EXPIRE_MONTHS);
// add a uri and then remove it, to trigger expiration
histsvc.addVisit(triggerURI, Date.now() * 1000, 0, histsvc.TRANSITION_TYPED, false, 0);
histsvc.addVisit(triggerURI, Date.now() * 1000, null, histsvc.TRANSITION_TYPED, false, 0);
bhist.removePage(triggerURI);
// test for unexpired annos
@ -370,7 +370,7 @@ function run_test() {
} catch(ex) {}
// test anno expiration (months) does not remove annos 179 days old
histsvc.addVisit(testURI, Date.now() * 1000, 0, histsvc.TRANSITION_TYPED, false, 0);
histsvc.addVisit(testURI, Date.now() * 1000, null, histsvc.TRANSITION_TYPED, false, 0);
annosvc.setPageAnnotation(testURI, testAnnoName, testAnnoVal, 0, annosvc.EXPIRE_MONTHS);
annosvc.setItemAnnotation(bookmark, testAnnoName, testAnnoVal, 0, annosvc.EXPIRE_MONTHS);
// these annotations should remain as they are only 179 days old
@ -379,7 +379,7 @@ function run_test() {
dbConnection.executeSimpleSQL("UPDATE moz_items_annos SET dateAdded = " + expirationDate);
// add a uri and then remove it, to trigger expiration
histsvc.addVisit(triggerURI, Date.now() * 1000, 0, histsvc.TRANSITION_TYPED, false, 0);
histsvc.addVisit(triggerURI, Date.now() * 1000, null, histsvc.TRANSITION_TYPED, false, 0);
bhist.removePage(triggerURI);
// test for unexpired annos
@ -411,7 +411,7 @@ function run_test() {
annosvc.setPageAnnotation(testURI, testAnnoName, "mod", 0, annosvc.EXPIRE_DAYS);
annosvc.setItemAnnotation(bookmark, testAnnoName, "mod", 0, annosvc.EXPIRE_DAYS);
// add a uri and then remove it, to trigger expiration
histsvc.addVisit(triggerURI, Date.now() * 1000, 0, histsvc.TRANSITION_TYPED, false, 0);
histsvc.addVisit(triggerURI, Date.now() * 1000, null, histsvc.TRANSITION_TYPED, false, 0);
bhist.removePage(triggerURI);
// anno should still be there
try {
@ -430,7 +430,7 @@ function run_test() {
dbConnection.executeSimpleSQL("UPDATE moz_annos SET lastModified = " + expirationDate);
dbConnection.executeSimpleSQL("UPDATE moz_items_annos SET lastModified = " + expirationDate);
// add a uri and then remove it, to trigger expiration
histsvc.addVisit(triggerURI, Date.now() * 1000, 0, histsvc.TRANSITION_TYPED, false, 0);
histsvc.addVisit(triggerURI, Date.now() * 1000, null, histsvc.TRANSITION_TYPED, false, 0);
bhist.removePage(triggerURI);
// anno should have been deleted
try {
@ -483,7 +483,7 @@ function startExpireNeither() {
observer.expiredURI = null;
// add data
histsvc.addVisit(testURI, Date.now() * 1000, 0, histsvc.TRANSITION_TYPED, false, 0);
histsvc.addVisit(testURI, Date.now() * 1000, null, histsvc.TRANSITION_TYPED, false, 0);
annosvc.setPageAnnotation(testURI, testAnnoName, testAnnoVal, 0, annosvc.EXPIRE_WITH_HISTORY);
// set visit cap to 2
@ -540,11 +540,11 @@ function startExpireDaysOnly() {
dump("startExpireDaysOnly()\n");
// add expirable visit
histsvc.addVisit(testURI, (Date.now() - (86400 * 2 * 1000)) * 1000, 0, histsvc.TRANSITION_TYPED, false, 0);
histsvc.addVisit(testURI, (Date.now() - (86400 * 2 * 1000)) * 1000, null, histsvc.TRANSITION_TYPED, false, 0);
annosvc.setPageAnnotation(testURI, testAnnoName, testAnnoVal, 0, annosvc.EXPIRE_WITH_HISTORY);
// add un-expirable visit
histsvc.addVisit(uri("http://unexpirable.com"), (Date.now() - (86400 * 1000)) * 1000, 0, histsvc.TRANSITION_TYPED, false, 0);
histsvc.addVisit(uri("http://unexpirable.com"), (Date.now() - (86400 * 1000)) * 1000, null, histsvc.TRANSITION_TYPED, false, 0);
// set visit cap to 2
prefs.setIntPref("browser.history_expire_sites", 2);
@ -603,8 +603,8 @@ function startExpireBoth() {
// 2 days old, in microseconds
var age = (Date.now() - (86400 * 2 * 1000)) * 1000;
dump("AGE: " + age + "\n");
histsvc.addVisit(testURI, age, 0, histsvc.TRANSITION_TYPED, false, 0);
histsvc.addVisit(testURI, age, 0, histsvc.TRANSITION_TYPED, false, 0);
histsvc.addVisit(testURI, age, null, histsvc.TRANSITION_TYPED, false, 0);
histsvc.addVisit(testURI, age, null, histsvc.TRANSITION_TYPED, false, 0);
annosvc.setPageAnnotation(testURI, testAnnoName, testAnnoVal, 0, annosvc.EXPIRE_WITH_HISTORY);
// set visit cap to 1

View File

@ -45,11 +45,19 @@ try {
do_throw("Could not get history service\n");
}
// adds a test URI visit to the database, and checks for a valid place ID
function add_visit(aURI) {
/**
* Adds a test URI visit to the database, and checks for a valid place ID.
*
* @param aURI
* The URI to add a visit for.
* @param aReferrer
* The referring URI for the given URI. This can be null.
* @returns the place id for aURI.
*/
function add_visit(aURI, aReferrer) {
var placeID = histsvc.addVisit(aURI,
Date.now(),
0, // no referrer
aReferrer,
histsvc.TRANSITION_TYPED, // user typed in URL bar
false, // not redirect
0);
@ -57,6 +65,25 @@ function add_visit(aURI) {
return placeID;
}
/**
* Checks to see that a URI is in the database.
*
* @param aURI
* The URI to check.
* @returns true if the URI is in the DB, false otherwise.
*/
function uri_in_db(aURI) {
var options = histsvc.getNewQueryOptions();
options.maxResults = 1;
options.resultType = options.RESULTS_AS_URI
var query = histsvc.getNewQuery();
query.uri = aURI;
var result = histsvc.executeQuery(query, options);
var root = result.root;
root.containerOpen = true;
return (root.childCount == 1);
}
// main
function run_test() {
// add a visit
@ -161,16 +188,7 @@ function run_test() {
do_check_eq(title, "mozilla.com");
// query for the visit
var options = histsvc.getNewQueryOptions();
options.maxResults = 1;
options.resultType = options.RESULTS_AS_URI
var query = histsvc.getNewQuery();
query.uri = testURI;
var result = histsvc.executeQuery(query, options);
var root = result.root;
root.containerOpen = true;
do_check_eq(root.childCount, 1);
root.containerOpen = false;
do_check_true(uri_in_db(testURI));
// test for schema changes in bug 373239
// get direct db connection
@ -199,4 +217,10 @@ function run_test() {
var root = result.root;
root.containerOpen = true;
do_check_true(root.childCount > 0);
// bug 400544 - testing that a referrer that is not in the DB gets added
var referrerURI = uri("http://yahoo.com");
do_check_false(uri_in_db(referrerURI));
add_visit(uri("http://mozilla.com"), referrerURI);
do_check_true(uri_in_db(referrerURI));
}

View File

@ -56,7 +56,7 @@ function add_visit(aURI, aDate) {
var date = aDate || Date.now();
var placeID = histsvc.addVisit(aURI,
date,
0, // no referrer
null, // no referrer
histsvc.TRANSITION_TYPED, // user typed in URL bar
false, // not redirect
0);

View File

@ -71,9 +71,9 @@ function run_test() {
tagssvc.tagURI(uri1, ["tag 1"]);
tagssvc.tagURI(uri2, ["tag 2"]);
histsvc.addVisit(uri1, Date.now(), 0, histsvc.TRANSITION_TYPED, false, 0);
histsvc.addVisit(uri1, Date.now(), null, histsvc.TRANSITION_TYPED, false, 0);
histsvc.setPageDetails(uri1, "foo title", 0, false, true);
histsvc.addVisit(uri2, Date.now(), 0, histsvc.TRANSITION_TYPED, false, 0);
histsvc.addVisit(uri2, Date.now(), null, histsvc.TRANSITION_TYPED, false, 0);
histsvc.setPageDetails(uri2, "bar title", 0, false, true);
var options = histsvc.getNewQueryOptions();