Bug 585969 - getBookmarkedURIFor should not try to add new pages. r+a=sdwilsh

This commit is contained in:
Marco Bonardo 2010-08-26 12:19:34 +02:00
parent 41399eac8a
commit 5f01872653
3 changed files with 33 additions and 7 deletions

View File

@ -2497,7 +2497,7 @@ nsNavBookmarks::GetBookmarkedURIFor(nsIURI* aURI, nsIURI** _retval)
nsNavHistory* history = nsNavHistory::GetHistoryService();
NS_ENSURE_TRUE(history, NS_ERROR_OUT_OF_MEMORY);
PRInt64 placeId;
nsresult rv = history->GetUrlIdFor(aURI, &placeId, PR_TRUE);
nsresult rv = history->GetUrlIdFor(aURI, &placeId, PR_FALSE);
NS_ENSURE_SUCCESS(rv, rv);
if (!placeId) {
// This URI is unknown, just return null.

View File

@ -40,17 +40,14 @@
* Test bookmarksService.getBookmarkedURIFor(aURI);
*/
let hs = Cc["@mozilla.org/browser/nav-history-service;1"].
getService(Ci.nsINavHistoryService);
let bs = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
getService(Ci.nsINavBookmarksService);
let hs = PlacesUtils.history;
let bs = PlacesUtils.bookmarks;
/**
* Adds a fake redirect between two visits.
*/
function addFakeRedirect(aSourceVisitId, aDestVisitId, aRedirectType) {
let dbConn = DBConn();
let stmt = dbConn.createStatement(
let stmt = DBConn().createStatement(
"UPDATE moz_historyvisits " +
"SET from_visit = :source, visit_type = :type " +
"WHERE id = :dest");
@ -122,6 +119,7 @@ function run_test() {
"bookmark");
do_check_true(bs.getBookmarkedURIFor(sourceURI).equals(sourceURI));
do_check_true(bs.getBookmarkedURIFor(tempURI).equals(tempURI));
// Now remove the bookmark on the destination.
bs.removeItem(tempItemId);
// We should see the source as bookmark.
@ -129,4 +127,9 @@ function run_test() {
// Remove the source bookmark as well.
bs.removeItem(sourceItemId);
do_check_eq(bs.getBookmarkedURIFor(tempURI), null);
// Try to pass in a never seen URI, should return null and a new entry should
// not be added to the database.
do_check_eq(bs.getBookmarkedURIFor(uri("http://does.not.exist/")), null);
do_check_false(page_in_database("http://does.not.exist/"));
}

View File

@ -251,6 +251,29 @@ function dump_table(aName)
}
/**
* Checks if an address is found in the database.
* @param aUrl
* Address to look for.
* @return place id of the page or 0 if not found
*/
function page_in_database(aUrl)
{
let stmt = DBConn().createStatement(
"SELECT id FROM moz_places_view WHERE url = :url"
);
stmt.params.url = aUrl;
try {
if (!stmt.executeStep())
return 0;
return stmt.getInt64(0);
}
finally {
stmt.finalize();
}
}
/**
* Removes all bookmarks and checks for correct cleanup
*/