Merge Places and mozilla-central

This commit is contained in:
Marco Bonardo 2011-06-02 13:34:44 +02:00
Родитель c3e4d29168 0c7dc8c967
Коммит d43f7544d9
7 изменённых файлов: 588 добавлений и 724 удалений

Просмотреть файл

@ -58,36 +58,28 @@ function windowObserver(aSubject, aTopic, aData) {
return;
ww.unregisterNotification(windowObserver);
let organizer = aSubject.QueryInterface(Ci.nsIDOMWindow);
organizer.addEventListener("load", function onLoad(event) {
organizer.removeEventListener("load", onLoad, false);
executeSoon(function () {
let contentTree = organizer.document.getElementById("placeContent");
isnot(contentTree, null, "Sanity check: placeContent tree should exist");
isnot(organizer.PlacesOrganizer, null, "Sanity check: PlacesOrganizer should exist");
isnot(organizer.gEditItemOverlay, null, "Sanity check: gEditItemOverlay should exist");
waitForFocus(function () {
let contentTree = organizer.document.getElementById("placeContent");
isnot(contentTree, null, "Sanity check: placeContent tree should exist");
isnot(organizer.PlacesOrganizer, null, "Sanity check: PlacesOrganizer should exist");
isnot(organizer.gEditItemOverlay, null, "Sanity check: gEditItemOverlay should exist");
if (!organizer.gEditItemOverlay._initialized){
// The overlay is initialized on focus, we wait for it to be fully operational.
setTimeout(arguments.callee, 10);
return;
}
ok(organizer.gEditItemOverlay._initialized, "gEditItemOverlay is initialized");
isnot(organizer.gEditItemOverlay.itemId, -1, "Editing a bookmark");
isnot(organizer.gEditItemOverlay.itemId, -1, "Editing a bookmark");
// Select History in the left pane.
organizer.PlacesOrganizer.selectLeftPaneQuery('History');
// Select the first history entry.
let selection = contentTree.view.selection;
selection.clearSelection();
selection.rangedSelect(0, 0, true);
// Check the panel is editing the history entry.
is(organizer.gEditItemOverlay.itemId, -1, "Editing an history entry");
// Close Library window.
organizer.close();
// Clean up history.
PlacesUtils.history.QueryInterface(Ci.nsIBrowserHistory).removeAllPages();
finish();
});
}, false);
// Select History in the left pane.
organizer.PlacesOrganizer.selectLeftPaneQuery('History');
// Select the first history entry.
let selection = contentTree.view.selection;
selection.clearSelection();
selection.rangedSelect(0, 0, true);
// Check the panel is editing the history entry.
is(organizer.gEditItemOverlay.itemId, -1, "Editing an history entry");
// Close Library window.
organizer.close();
// Clean up history.
waitForClearHistory(finish);
}, organizer);
}
function test() {
@ -105,3 +97,14 @@ function test() {
"chrome,toolbar=yes,dialog=no,resizable",
null);
}
function waitForClearHistory(aCallback) {
let observer = {
observe: function(aSubject, aTopic, aData) {
Services.obs.removeObserver(this, PlacesUtils.TOPIC_EXPIRATION_FINISHED);
aCallback(aSubject, aTopic, aData);
}
};
Services.obs.addObserver(observer, PlacesUtils.TOPIC_EXPIRATION_FINISHED, false);
PlacesUtils.bhistory.removeAllPages();
}

Просмотреть файл

@ -477,7 +477,23 @@ namespace places {
// The page is already in the database, and we can fetch current
// params from the database.
nsCOMPtr<mozIStorageStatement> getPageInfo =
history->GetStatementByStoragePool(DB_PAGE_INFO_FOR_FRECENCY);
history->GetStatementByStoragePool(
"SELECT typed, hidden, visit_count, "
"(SELECT count(*) FROM moz_historyvisits WHERE place_id = :page_id), "
"EXISTS ( "
"SELECT 1 FROM moz_bookmarks "
"WHERE fk = :page_id "
"AND NOT EXISTS( "
"SELECT 1 "
"FROM moz_items_annos a "
"JOIN moz_anno_attributes n ON a.anno_attribute_id = n.id "
"WHERE n.name = :anno_name "
"AND a.item_id = parent "
") "
"), "
"(url > 'place:' AND url < 'place;') "
"FROM moz_places "
"WHERE id = :page_id ");
NS_ENSURE_STATE(getPageInfo);
mozStorageStatementScoper infoScoper(getPageInfo);
@ -504,20 +520,40 @@ namespace places {
rv = getPageInfo->GetInt32(5, &isQuery);
NS_ENSURE_SUCCESS(rv, rv);
// NOTE: This is not limited to visits with "visit_type NOT IN (0,4,7,8)"
// because otherwise it would not return any visit for those transitions
// causing an incorrect frecency, see CalculateFrecencyInternal().
// In case of a temporary or permanent redirect, calculate the frecency
// as if the original page was visited.
nsCAutoString visitsForFrecencySQL(NS_LITERAL_CSTRING(
"/* do not warn (bug 659740 - SQLite may ignore index if few visits exist) */"
"SELECT "
"ROUND((strftime('%s','now','localtime','utc') - v.visit_date/1000000)/86400), "
"IFNULL(r.visit_type, v.visit_type), "
"v.visit_date "
"FROM moz_historyvisits v "
"LEFT JOIN moz_historyvisits r ON r.id = v.from_visit AND v.visit_type BETWEEN "
) + nsPrintfCString("%d AND %d ", nsINavHistoryService::TRANSITION_REDIRECT_PERMANENT,
nsINavHistoryService::TRANSITION_REDIRECT_TEMPORARY) +
NS_LITERAL_CSTRING("WHERE v.place_id = :page_id "
"ORDER BY v.visit_date DESC ")
);
// Get a sample of the last visits to the page, to calculate its weight.
nsCOMPtr<mozIStorageStatement> getVisits =
history->GetStatementByStoragePool(DB_VISITS_FOR_FRECENCY);
history->GetStatementByStoragePool(visitsForFrecencySQL);
NS_ENSURE_STATE(getVisits);
mozStorageStatementScoper visitsScoper(getVisits);
rv = getVisits->BindInt64ByName(NS_LITERAL_CSTRING("page_id"), pageId);
NS_ENSURE_SUCCESS(rv, rv);
// Fetch only a limited number of recent visits.
PRInt32 numSampledVisits = 0;
// The visits query is already limited to the last N visits.
while (NS_SUCCEEDED(getVisits->ExecuteStep(&hasResult)) && hasResult) {
numSampledVisits++;
for (PRInt32 maxVisits = history->GetNumVisitsForFrecency();
numSampledVisits < maxVisits &&
NS_SUCCEEDED(getVisits->ExecuteStep(&hasResult)) && hasResult;
numSampledVisits++) {
PRInt32 visitType;
rv = getVisits->GetInt32(1, &visitType);
NS_ENSURE_SUCCESS(rv, rv);

Просмотреть файл

@ -376,6 +376,8 @@ PLACES_FACTORY_SINGLETON_IMPLEMENTATION(nsNavHistory, gHistoryService)
nsNavHistory::nsNavHistory()
: mBatchLevel(0)
, mBatchDBTransaction(nsnull)
, mAsyncThreadStatements(mDBConn)
, mStatements(mDBConn)
, mDBPageSize(0)
, mCurrentJournalMode(JOURNAL_DELETE)
, mCachedNow(0)
@ -911,16 +913,6 @@ nsNavHistory::InitAdditionalDBItems()
nsresult rv = InitTriggers();
NS_ENSURE_SUCCESS(rv, rv);
// These statements are used by frecency calculation. Since frecency runs in
// the storage async thread, it needs to access them through a const history
// object, for thread-safety. Due to const correctness it's not possible for
// the statements getter to lazily initialize them on first use, thus they
// are initialized here.
(void*)GetStatement(mDBPageInfoForFrecency);
(void*)GetStatement(mDBAsyncThreadPageInfoForFrecency);
(void*)GetStatement(mDBVisitsForFrecency);
(void*)GetStatement(mDBAsyncThreadVisitsForFrecency);
return NS_OK;
}
@ -1292,34 +1284,6 @@ nsNavHistory::GetStatement(const nsCOMPtr<mozIStorageStatement>& aStmt)
"WHERE url = :page_url "
));
// NOTE: This is not limited to visits with "visit_type NOT IN (0,4,7,8)"
// because otherwise mDBVisitsForFrecency would return no visits
// for places with only embed (or undefined) visits. That would
// cause an incorrect frecency, see CalculateFrecencyInternal().
// In such a case a place with only EMBED visits would result in a non-zero
// frecency.
// In case of a temporary or permanent redirect, calculate the frecency as if
// the original page was visited.
nsCAutoString visitsForFrecencySQL(NS_LITERAL_CSTRING(
"SELECT "
"ROUND((strftime('%s','now','localtime','utc') - v.visit_date/1000000)/86400), "
"COALESCE( "
"(SELECT r.visit_type FROM moz_historyvisits r WHERE v.visit_type IN ") +
nsPrintfCString("(%d,%d) ", TRANSITION_REDIRECT_PERMANENT,
TRANSITION_REDIRECT_TEMPORARY) +
NS_LITERAL_CSTRING(" AND r.id = v.from_visit), "
"visit_type), "
"visit_date "
"FROM moz_historyvisits v "
"WHERE v.place_id = :page_id "
"ORDER BY visit_date DESC LIMIT ") +
nsPrintfCString("%d", mNumVisitsForFrecency)
);
RETURN_IF_STMT(mDBVisitsForFrecency, visitsForFrecencySQL);
RETURN_IF_STMT(mDBAsyncThreadVisitsForFrecency, visitsForFrecencySQL);
RETURN_IF_STMT(mDBUpdateFrecency, NS_LITERAL_CSTRING(
"UPDATE moz_places "
"SET frecency = CALCULATE_FRECENCY(:page_id) "
@ -1332,34 +1296,6 @@ nsNavHistory::GetStatement(const nsCOMPtr<mozIStorageStatement>& aStmt)
"WHERE id = :page_id AND frecency <> 0"
));
RETURN_IF_STMT(mDBGetPlaceVisitStats, NS_LITERAL_CSTRING(
"SELECT typed, hidden, frecency "
"FROM moz_places "
"WHERE id = :page_id "
));
// When calculating frecency, we need special information for the page.
nsCAutoString pageInfoForFrecencySQL(NS_LITERAL_CSTRING(
"SELECT typed, hidden, visit_count, "
"(SELECT count(*) FROM moz_historyvisits WHERE place_id = :page_id), "
"(SELECT id FROM moz_bookmarks "
"WHERE fk = :page_id "
"AND parent NOT IN ("
"SELECT a.item_id "
"FROM moz_items_annos a "
"JOIN moz_anno_attributes n ON a.anno_attribute_id = n.id "
"WHERE n.name = :anno_name"
") "
"LIMIT 1), "
"(url > 'place:' AND url < 'place;') "
"FROM moz_places "
"WHERE id = :page_id "
));
RETURN_IF_STMT(mDBPageInfoForFrecency, pageInfoForFrecencySQL);
RETURN_IF_STMT(mDBAsyncThreadPageInfoForFrecency, pageInfoForFrecencySQL);
#ifdef MOZ_XUL
RETURN_IF_STMT(mDBFeedbackIncrease, NS_LITERAL_CSTRING(
// Leverage the PRIMARY KEY (place_id, input) to insert/update entries.
@ -2514,16 +2450,14 @@ nsNavHistory::FixInvalidFrecenciesForExcludedPlaces()
"SET frecency = 0 WHERE id IN ("
"SELECT h.id FROM moz_places h "
"WHERE h.url >= 'place:' AND h.url < 'place;' "
"UNION "
"UNION ALL "
// Unvisited child of a livemark
"SELECT b.fk FROM moz_bookmarks b "
"JOIN moz_places h ON b.fk = h.id AND visit_count = 0 AND frecency < 0 "
"JOIN moz_bookmarks bp ON bp.id = b.parent "
"JOIN moz_items_annos a ON a.item_id = bp.id "
"JOIN moz_anno_attributes n ON n.id = a.anno_attribute_id "
"WHERE n.name = :anno_name "
"AND b.fk IN( "
"SELECT id FROM moz_places WHERE visit_count = 0 AND frecency < 0 "
") "
")"),
getter_AddRefs(dbUpdateStatement));
NS_ENSURE_SUCCESS(rv, rv);
@ -7269,13 +7203,8 @@ nsNavHistory::FinalizeStatements() {
mDBVisitToVisitResult,
mDBBookmarkToUrlResult,
mDBUrlToUrlResult,
mDBVisitsForFrecency,
mDBUpdateFrecency,
mDBUpdateHiddenOnFrecency,
mDBGetPlaceVisitStats,
mDBPageInfoForFrecency,
mDBAsyncThreadPageInfoForFrecency,
mDBAsyncThreadVisitsForFrecency,
};
for (PRUint32 i = 0; i < NS_ARRAY_LENGTH(stmts); i++) {
@ -7283,6 +7212,17 @@ nsNavHistory::FinalizeStatements() {
NS_ENSURE_SUCCESS(rv, rv);
}
// Finalize the statementCaches on the correct threads.
mStatements.FinalizeStatements();
nsRefPtr<FinalizeStatementCacheProxy<mozIStorageStatement> > event =
new FinalizeStatementCacheProxy<mozIStorageStatement>(
mAsyncThreadStatements, NS_ISUPPORTS_CAST(nsINavHistoryService*, this));
nsCOMPtr<nsIEventTarget> target = do_GetInterface(mDBConn);
NS_ENSURE_TRUE(target, NS_ERROR_OUT_OF_MEMORY);
nsresult rv = target->Dispatch(event, NS_DISPATCH_NORMAL);
NS_ENSURE_SUCCESS(rv, rv);
return NS_OK;
}

Просмотреть файл

@ -72,6 +72,7 @@
#include "nsNavHistoryQuery.h"
#include "mozilla/storage.h"
#include "mozilla/storage/StatementCache.h"
#define QUERYUPDATE_TIME 0
#define QUERYUPDATE_SIMPLE 1
@ -137,8 +138,6 @@ namespace places {
, DB_ADD_NEW_PAGE
, DB_GET_URL_PAGE_INFO
, DB_SET_PLACE_TITLE
, DB_PAGE_INFO_FOR_FRECENCY
, DB_VISITS_FOR_FRECENCY
};
enum JournalMode {
@ -493,31 +492,32 @@ public:
return GetStatement(mDBGetURLPageInfo);
case DB_SET_PLACE_TITLE:
return GetStatement(mDBSetPlaceTitle);
case DB_PAGE_INFO_FOR_FRECENCY:
return GetStatement(mDBPageInfoForFrecency);
case DB_VISITS_FOR_FRECENCY:
return GetStatement(mDBVisitsForFrecency);
}
return nsnull;
}
mozIStorageStatement* GetStatementByStoragePool(
enum mozilla::places::HistoryStatementId aStatementId
) const
{
using namespace mozilla::places;
/**
* This cache should be used only for background thread statements.
*
* @pre must be running on the background thread of mDBConn.
*/
mutable mozilla::storage::StatementCache<mozIStorageStatement> mAsyncThreadStatements;
mutable mozilla::storage::StatementCache<mozIStorageStatement> mStatements;
switch(aStatementId) {
case DB_PAGE_INFO_FOR_FRECENCY:
return NS_IsMainThread() ? mDBPageInfoForFrecency
: mDBAsyncThreadPageInfoForFrecency;
case DB_VISITS_FOR_FRECENCY:
return NS_IsMainThread() ? mDBVisitsForFrecency
: mDBAsyncThreadVisitsForFrecency;
default:
NS_NOTREACHED("Trying to handle an unknown statement");
}
return nsnull;
template<int N>
already_AddRefed<mozIStorageStatement>
GetStatementByStoragePool(const char (&aQuery)[N]) const
{
nsDependentCString query(aQuery, N - 1);
return GetStatementByStoragePool(query);
}
already_AddRefed<mozIStorageStatement>
GetStatementByStoragePool(const nsACString& aQuery) const
{
return NS_IsMainThread()
? mStatements.GetCachedStatement(aQuery)
: mAsyncThreadStatements.GetCachedStatement(aQuery);
}
PRInt32 GetFrecencyAgedWeight(PRInt32 aAgeInDays) const
@ -580,6 +580,11 @@ public:
}
}
PRInt32 GetNumVisitsForFrecency() const
{
return mNumVisitsForFrecency;
}
PRInt64 GetNewSessionID();
/**
@ -647,14 +652,6 @@ protected:
nsCOMPtr<mozIStorageStatement> mDBUrlToUrlResult; // kGetInfoIndex_* results
nsCOMPtr<mozIStorageStatement> mDBUpdateFrecency;
nsCOMPtr<mozIStorageStatement> mDBUpdateHiddenOnFrecency;
nsCOMPtr<mozIStorageStatement> mDBGetPlaceVisitStats;
// Cached statements used in frecency calculation. Since it could happen on
// both main thread or storage async thread, we keep two versions of them
// for thread-safety.
mutable nsCOMPtr<mozIStorageStatement> mDBVisitsForFrecency;
mutable nsCOMPtr<mozIStorageStatement> mDBPageInfoForFrecency;
mutable nsCOMPtr<mozIStorageStatement> mDBAsyncThreadVisitsForFrecency;
mutable nsCOMPtr<mozIStorageStatement> mDBAsyncThreadPageInfoForFrecency;
#ifdef MOZ_XUL
// AutoComplete stuff
nsCOMPtr<mozIStorageStatement> mDBFeedbackIncrease;

Просмотреть файл

@ -46,28 +46,22 @@ const Cc = Components.classes;
const Ci = Components.interfaces;
const Cr = Components.results;
// This is just a helper for the next constant.
function book_tag_sql_fragment(aName, aColumn, aForTag)
{
return ["(",
"SELECT ", aColumn, " ",
"FROM moz_bookmarks b ",
"JOIN moz_bookmarks t ",
"ON t.id = b.parent ",
"AND t.parent ", (aForTag ? "" : "!"), "= :parent ",
"WHERE b.fk = h.id ",
(aForTag ? "" : "ORDER BY b.lastModified DESC LIMIT 1"),
") AS ", aName].join("");
}
// This SQL query fragment provides the following:
// - the parent folder for bookmarked entries (kQueryIndexParent)
// - whether the entry is bookmarked (kQueryIndexBookmarked)
// - the bookmark title, if it is a bookmark (kQueryIndexBookmarkTitle)
// - the tags associated with a bookmarked entry (kQueryIndexTags)
const kBookTagSQLFragment =
book_tag_sql_fragment("parent", "b.parent", false) + ", " +
book_tag_sql_fragment("bookmark", "b.title", false) + ", " +
book_tag_sql_fragment("tags", "GROUP_CONCAT(t.title, ',')", true);
"EXISTS(SELECT 1 FROM moz_bookmarks WHERE fk = h.id) AS bookmarked, "
+ "( "
+ "SELECT title FROM moz_bookmarks WHERE fk = h.id AND title NOTNULL "
+ "ORDER BY lastModified DESC LIMIT 1 "
+ ") AS btitle, "
+ "( "
+ "SELECT GROUP_CONCAT(t.title, ',') "
+ "FROM moz_bookmarks b "
+ "JOIN moz_bookmarks t ON t.id = b.parent AND t.parent = :parent "
+ "WHERE b.fk = h.id "
+ ") AS tags";
// observer topics
const kTopicShutdown = "places-shutdown";
@ -85,7 +79,7 @@ const MATCH_BEGINNING = Ci.mozIPlacesAutoComplete.MATCH_BEGINNING;
const kQueryIndexURL = 0;
const kQueryIndexTitle = 1;
const kQueryIndexFaviconURL = 2;
const kQueryIndexParentId = 3;
const kQueryIndexBookmarked = 3;
const kQueryIndexBookmarkTitle = 4;
const kQueryIndexTags = 5;
const kQueryIndexVisitCount = 6;
@ -235,9 +229,9 @@ function nsPlacesAutoComplete()
+ "LEFT JOIN moz_openpages_temp t ON t.url = h.url "
+ "WHERE h.frecency <> 0 "
+ "AND AUTOCOMPLETE_MATCH(:searchString, h.url, "
+ "IFNULL(bookmark, h.title), tags, "
+ "h.visit_count, h.typed, parent, "
+ "t.open_count, "
+ "IFNULL(btitle, h.title), tags, "
+ "h.visit_count, h.typed, "
+ "bookmarked, t.open_count, "
+ ":matchBehavior, :searchBehavior) "
+ "{ADDITIONAL_CONDITIONS} "
+ "ORDER BY h.frecency DESC, h.id DESC "
@ -297,7 +291,7 @@ function nsPlacesAutoComplete()
});
XPCOMUtils.defineLazyGetter(this, "_bookmarkQuery", function() {
let replacementText = "AND bookmark IS NOT NULL";
let replacementText = "AND bookmarked";
return this._db.createAsyncStatement(
SQL_BASE.replace("{ADDITIONAL_CONDITIONS}", replacementText, "g")
);
@ -333,31 +327,24 @@ function nsPlacesAutoComplete()
});
XPCOMUtils.defineLazyGetter(this, "_adaptiveQuery", function() {
// In this query, we are taking kBookTagSQLFragment only for h.id because it
// uses data from the moz_bookmarks table and we sync tables on bookmark
// insert. So, most likely, h.id will always be populated when we have any
// bookmark.
return this._db.createAsyncStatement(
"/* do not warn (bug 487789) */ "
+ "SELECT h.url, h.title, f.url, " + kBookTagSQLFragment + ", "
+ "h.visit_count, h.typed, h.id, :query_type, t.open_count, rank "
+ "h.visit_count, h.typed, h.id, :query_type, t.open_count "
+ "FROM ( "
+ "SELECT ROUND( "
+ "MAX(((i.input = :search_string) + "
+ "(SUBSTR(i.input, 1, LENGTH(:search_string)) = :search_string) "
+ ") * i.use_count "
+ ") , 1 " // Round at first decimal.
+ "SELECT ROUND( "
+ "MAX(use_count) * (1 + (input = :search_string)), 1 "
+ ") AS rank, place_id "
+ "FROM moz_inputhistory i "
+ "GROUP BY i.place_id "
+ "HAVING rank > 0 "
+ "FROM moz_inputhistory "
+ "WHERE input BETWEEN :search_string AND :search_string || X'FFFF' "
+ "GROUP BY place_id "
+ ") AS i "
+ "JOIN moz_places h ON h.id = i.place_id "
+ "LEFT JOIN moz_favicons f ON f.id = h.favicon_id "
+ "LEFT JOIN moz_openpages_temp t ON t.url = h.url "
+ "WHERE AUTOCOMPLETE_MATCH(NULL, h.url, "
+ "IFNULL(bookmark, h.title), tags, "
+ "h.visit_count, h.typed, parent, "
+ "IFNULL(btitle, h.title), tags, "
+ "h.visit_count, h.typed, bookmarked, "
+ "t.open_count, "
+ ":matchBehavior, :searchBehavior) "
+ "ORDER BY rank DESC, h.frecency DESC "
@ -376,7 +363,7 @@ function nsPlacesAutoComplete()
+ "WHERE rev_host = (SELECT rev_host FROM moz_places WHERE id = b.fk) "
+ "ORDER BY frecency DESC "
+ "LIMIT 1) "
+ "), b.parent, b.title, NULL, h.visit_count, h.typed, IFNULL(h.id, b.fk), "
+ "), 1, b.title, NULL, h.visit_count, h.typed, IFNULL(h.id, b.fk), "
+ ":query_type, t.open_count "
+ "FROM moz_keywords k "
+ "JOIN moz_bookmarks b ON b.keyword_id = k.id "
@ -1012,8 +999,8 @@ nsPlacesAutoComplete.prototype = {
let entryTitle = aRow.getResultByIndex(kQueryIndexTitle) || "";
let entryFavicon = aRow.getResultByIndex(kQueryIndexFaviconURL) || "";
let entryParentId = aRow.getResultByIndex(kQueryIndexParentId);
let entryBookmarkTitle = entryParentId ?
let entryBookmarked = aRow.getResultByIndex(kQueryIndexBookmarked);
let entryBookmarkTitle = entryBookmarked ?
aRow.getResultByIndex(kQueryIndexBookmarkTitle) : null;
let entryTags = aRow.getResultByIndex(kQueryIndexTags) || "";
@ -1056,7 +1043,7 @@ nsPlacesAutoComplete.prototype = {
// haven't already done so.
if (showTags)
style = "tag";
else if (entryParentId)
else if (entryBookmarked)
style = "bookmark";
else
style = "favicon";

Просмотреть файл

@ -44,194 +44,170 @@
* https://bugzilla.mozilla.org/show_bug.cgi?id=412132
*/
const bmServ = PlacesUtils.bookmarks;
const histServ = PlacesUtils.history;
const lmServ = PlacesUtils.livemarks;
let tests = [
add_test(function unvisited_bookmarked_livemarkItem()
{
desc: ["Frecency of unvisited, separately bookmarked livemark item's URI ",
"should be zero after bookmark's URI changed."].join(""),
run: function ()
{
// Add livemark and bookmark. Bookmark's URI is the URI of the livemark's
// only item.
let lmItemURL = "http://example.com/livemark-item";
let lmItemURI = uri(lmItemURL);
createLivemark(lmItemURI);
let bmId = bmServ.insertBookmark(bmServ.unfiledBookmarksFolder,
lmItemURI,
bmServ.DEFAULT_INDEX,
"bookmark title");
waitForFrecency(lmItemURL, function(aFrecency) aFrecency > 0,
this.check1, this, [lmItemURL, bmId]);
},
check1: function (aUrl, aItemId)
{
print("Bookmarked => frecency of URI should be != 0.");
do_check_neq(frecencyForUrl(aUrl), 0);
do_log_info("Frecency of unvisited, separately bookmarked livemark item's " +
"URI should be zero after bookmark's URI changed.");
bmServ.changeBookmarkURI(aItemId, uri("http://example.com/new-uri"));
waitForFrecency(aUrl, function(aFrecency) aFrecency == 0,
this.check2, this, [aUrl]);
},
check2: function (aUrl)
// Add livemark and bookmark. Bookmark's URI is the URI of the livemark's
// only item.
const TEST_URI = NetUtil.newURI("http://example.com/livemark-item");
createLivemark(TEST_URI);
let id = PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId,
TEST_URI,
PlacesUtils.bookmarks.DEFAULT_INDEX,
"bookmark title");
waitForAsyncUpdates(function ()
{
print("URI's only bookmark is now unvisited livemark item => frecency = 0");
do_check_eq(frecencyForUrl(aUrl), 0);
run_next_test();
}
},
do_log_info("Bookmarked => frecency of URI should be != 0.");
do_check_neq(frecencyForUrl(TEST_URI), 0);
PlacesUtils.bookmarks.changeBookmarkURI(id, NetUtil.newURI("http://example.com/new-uri"));
waitForAsyncUpdates(function ()
{
do_log_info("URI's only bookmark is now unvisited livemark item => frecency = 0");
do_check_eq(frecencyForUrl(TEST_URI), 0);
remove_all_bookmarks();
waitForClearHistory(run_next_test);
});
});
});
add_test(function visited_bookmarked_livemarkItem()
{
desc: ["Frecency of visited, separately bookmarked livemark item's URI ",
"should not be zero after bookmark's URI changed."].join(""),
run: function ()
{
// Add livemark and bookmark. Bookmark's URI is the URI of the livemark's
// only item.
let lmItemURL = "http://example.com/livemark-item";
let lmItemURI = uri(lmItemURL);
createLivemark(lmItemURI);
let bmId = bmServ.insertBookmark(bmServ.unfiledBookmarksFolder,
lmItemURI,
bmServ.DEFAULT_INDEX,
"bookmark title");
waitForFrecency(lmItemURL, function(aFrecency) aFrecency > 0,
this.check1, this, [lmItemURL, bmId]);
},
check1: function (aUrl, aItemId)
{
print("Bookmarked => frecency of URI should be != 0");
do_check_neq(frecencyForUrl(aUrl), 0);
do_log_info("Frecency of visited, separately bookmarked livemark item's " +
"URI should not be zero after bookmark's URI changed.");
visit(uri(aUrl));
bmServ.changeBookmarkURI(aItemId, uri("http://example.com/new-uri"));
waitForFrecency(aUrl, function(aFrecency) aFrecency > 0,
this.check2, this, [aUrl]);
},
check2: function (aUrl)
// Add livemark and bookmark. Bookmark's URI is the URI of the livemark's
// only item.
const TEST_URI = NetUtil.newURI("http://example.com/livemark-item");
createLivemark(TEST_URI);
let id = PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId,
TEST_URI,
PlacesUtils.bookmarks.DEFAULT_INDEX,
"bookmark title");
waitForAsyncUpdates(function ()
{
print("URI's only bookmark is now *visited* livemark item => frecency != 0");
do_check_neq(frecencyForUrl(aUrl), 0);
run_next_test();
}
},
do_log_info("Bookmarked => frecency of URI should be != 0");
do_check_neq(frecencyForUrl(TEST_URI), 0);
visit(TEST_URI);
PlacesUtils.bookmarks.changeBookmarkURI(id, uri("http://example.com/new-uri"));
waitForAsyncUpdates(function ()
{
do_log_info("URI's only bookmark is now *visited* livemark item => frecency != 0");
do_check_neq(frecencyForUrl(TEST_URI), 0);
remove_all_bookmarks();
waitForClearHistory(run_next_test);
});
});
});
add_test(function changeuri_unvisited_bookmark()
{
desc: ["After changing URI of bookmark, frecency of bookmark's original URI ",
"should be zero if original URI is unvisited and no longer ",
"bookmarked."].join(""),
run: function ()
do_log_info("After changing URI of bookmark, frecency of bookmark's " +
"original URI should be zero if original URI is unvisited and " +
"no longer bookmarked.");
const TEST_URI = NetUtil.newURI("http://example.com/1");
let id = PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId,
TEST_URI,
PlacesUtils.bookmarks.DEFAULT_INDEX,
"bookmark title");
waitForAsyncUpdates(function ()
{
let url = "http://example.com/1";
let bmId = bmServ.insertBookmark(bmServ.unfiledBookmarksFolder,
uri(url),
bmServ.DEFAULT_INDEX,
"bookmark title");
waitForFrecency(url, function(aFrecency) aFrecency > 0,
this.check1, this, [url, bmId]);
},
check1: function (aUrl, aItemId) {
print("Bookmarked => frecency of URI should be != 0");
do_check_neq(frecencyForUrl(aUrl), 0);
do_log_info("Bookmarked => frecency of URI should be != 0");
do_check_neq(frecencyForUrl(TEST_URI), 0);
bmServ.changeBookmarkURI(aItemId, uri("http://example.com/2"));
PlacesUtils.bookmarks.changeBookmarkURI(id, uri("http://example.com/2"));
waitForFrecency(aUrl, function(aFrecency) aFrecency == 0,
this.check2, this, [aUrl]);
},
check2: function (aUrl)
{
print("Unvisited URI no longer bookmarked => frecency should = 0");
do_check_eq(frecencyForUrl(aUrl), 0);
run_next_test();
}
},
waitForAsyncUpdates(function ()
{
do_log_info("Unvisited URI no longer bookmarked => frecency should = 0");
do_check_eq(frecencyForUrl(TEST_URI), 0);
remove_all_bookmarks();
waitForClearHistory(run_next_test);
});
});
});
add_test(function changeuri_visited_bookmark()
{
desc: ["After changing URI of bookmark, frecency of bookmark's original URI ",
"should not be zero if original URI is visited."].join(""),
run: function ()
do_log_info("After changing URI of bookmark, frecency of bookmark's " +
"original URI should not be zero if original URI is visited.");
const TEST_URI = NetUtil.newURI("http://example.com/1");
let id = PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId,
TEST_URI,
PlacesUtils.bookmarks.DEFAULT_INDEX,
"bookmark title");
waitForAsyncUpdates(function ()
{
let bmURL = "http://example.com/1";
let bmId = bmServ.insertBookmark(bmServ.unfiledBookmarksFolder,
uri(bmURL),
bmServ.DEFAULT_INDEX,
"bookmark title");
waitForFrecency(bmURL, function(aFrecency) aFrecency > 0,
this.check1, this, [bmURL, bmId]);
},
check1: function (aUrl, aItemId)
{
print("Bookmarked => frecency of URI should be != 0");
do_check_neq(frecencyForUrl(aUrl), 0);
do_log_info("Bookmarked => frecency of URI should be != 0");
do_check_neq(frecencyForUrl(TEST_URI), 0);
visit(uri(aUrl));
waitForFrecency(aUrl, function(aFrecency) aFrecency > 0,
this.check2, this, [aUrl, aItemId]);
},
check2: function (aUrl, aItemId)
{
bmServ.changeBookmarkURI(aItemId, uri("http://example.com/2"));
waitForFrecency(aUrl, function(aFrecency) aFrecency > 0,
this.check3, this, [aUrl]);
},
check3: function (aUrl)
{
print("*Visited* URI no longer bookmarked => frecency should != 0");
do_check_neq(frecencyForUrl(aUrl), 0);
run_next_test();
}
},
visit(TEST_URI);
waitForAsyncUpdates(function ()
{
PlacesUtils.bookmarks.changeBookmarkURI(id, uri("http://example.com/2"));
waitForAsyncUpdates(function ()
{
do_log_info("*Visited* URI no longer bookmarked => frecency should != 0");
do_check_neq(frecencyForUrl(TEST_URI), 0);
remove_all_bookmarks();
waitForClearHistory(run_next_test);
});
});
});
});
add_test(function changeuri_bookmark_still_bookmarked()
{
desc: ["After changing URI of bookmark, frecency of bookmark's original URI ",
"should not be zero if original URI is still bookmarked."].join(""),
run: function ()
do_log_info("After changing URI of bookmark, frecency of bookmark's " +
"original URI should not be zero if original URI is still " +
"bookmarked.");
const TEST_URI = NetUtil.newURI("http://example.com/1");
let id1 = PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId,
TEST_URI,
PlacesUtils.bookmarks.DEFAULT_INDEX,
"bookmark 1 title");
let id2 = PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId,
TEST_URI,
PlacesUtils.bookmarks.DEFAULT_INDEX,
"bookmark 2 title");
waitForAsyncUpdates(function ()
{
let bmURL = "http://example.com/1";
let bm1Id = bmServ.insertBookmark(bmServ.unfiledBookmarksFolder,
uri(bmURL),
bmServ.DEFAULT_INDEX,
"bookmark 1 title");
do_log_info("Bookmarked => frecency of URI should be != 0");
do_check_neq(frecencyForUrl(TEST_URI), 0);
let bm2Id = bmServ.insertBookmark(bmServ.unfiledBookmarksFolder,
uri(bmURL),
bmServ.DEFAULT_INDEX,
"bookmark 2 title");
waitForFrecency(bmURL, function(aFrecency) aFrecency > 0,
this.check1, this, [bmURL, bm1Id]);
},
check1: function (aUrl, aItemId)
{
print("Bookmarked => frecency of URI should be != 0");
do_check_neq(frecencyForUrl(aUrl), 0);
PlacesUtils.bookmarks.changeBookmarkURI(id1, uri("http://example.com/2"));
waitForAsyncUpdates(function ()
{
do_log_info("URI still bookmarked => frecency should != 0");
do_check_neq(frecencyForUrl(TEST_URI), 0);
bmServ.changeBookmarkURI(aItemId, uri("http://example.com/2"));
waitForFrecency(aUrl, function(aFrecency) aFrecency > 0,
this.check2, this, [aUrl]);
},
check2: function (aUrl)
{
print("URI still bookmarked => frecency should != 0");
do_check_neq(frecencyForUrl(aUrl), 0);
run_next_test();
}
},
remove_all_bookmarks();
waitForClearHistory(run_next_test);
});
});
});
add_test(function changeuri_nonexistent_bookmark()
{
desc: "Changing the URI of a nonexistent bookmark should fail.",
run: function ()
{
do_log_info("Changing the URI of a nonexistent bookmark should fail.");
function tryChange(itemId)
{
try {
bmServ.changeBookmarkURI(itemId + 1, uri("http://example.com/2"));
PlacesUtils.bookmarks.changeBookmarkURI(itemId + 1, uri("http://example.com/2"));
do_throw("Nonexistent bookmark should throw.");
}
catch (exc) {}
catch (ex) {}
}
// First try a straight-up bogus item ID, one greater than the current max
@ -243,62 +219,54 @@ let tests = [
tryChange(maxId + 1);
// Now add a bookmark, delete it, and check.
let bmId = bmServ.insertBookmark(bmServ.unfiledBookmarksFolder,
uri("http://example.com/"),
bmServ.DEFAULT_INDEX,
"bookmark title");
bmServ.removeItem(bmId);
tryChange(bmId);
run_next_test();
}
},
let id = PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId,
uri("http://example.com/"),
PlacesUtils.bookmarks.DEFAULT_INDEX,
"bookmark title");
PlacesUtils.bookmarks.removeItem(id);
tryChange(id);
];
remove_all_bookmarks();
waitForClearHistory(run_next_test);
});
/******************************************************************************/
///////////////////////////////////////////////////////////////////////////////
function createLivemark(lmItemURI)
/**
* Creates a livemark with a single child item.
*
* @param aChildURI
* the URI of the livemark's single child item
* @return the item ID of the single child item
*/
function createLivemark(aChildURI)
{
let lmId = lmServ.createLivemarkFolderOnly(bmServ.unfiledBookmarksFolder,
"livemark title",
uri("http://www.mozilla.org/"),
uri("http://www.mozilla.org/news.rdf"),
-1);
return bmServ.insertBookmark(lmId,
lmItemURI,
bmServ.DEFAULT_INDEX,
"livemark item title");
let livemarkId = PlacesUtils.livemarks.createLivemarkFolderOnly(
PlacesUtils.unfiledBookmarksFolderId, "livemark title",
uri("http://example.com/"), uri("http://example.com/rdf"), -1
);
return PlacesUtils.bookmarks.insertBookmark(livemarkId,
aChildURI,
PlacesUtils.bookmarks.DEFAULT_INDEX,
"livemark item title");
}
function visit(uri)
/**
* Adds a visit for aURI.
*
* @param aURI
* the URI of the Place for which to add a visit
*/
function visit(aURI)
{
histServ.addVisit(uri,
Date.now() * 1000,
null,
histServ.TRANSITION_BOOKMARK,
false,
0);
PlacesUtils.history.addVisit(aURI, Date.now() * 1000, null,
PlacesUtils.history.TRANSITION_BOOKMARK,
false, 0);
}
/******************************************************************************/
///////////////////////////////////////////////////////////////////////////////
function run_test()
{
do_test_pending();
run_next_test();
}
function run_next_test()
{
if (tests.length) {
let test = tests.shift();
print("\n ***Test: " + test.desc);
remove_all_bookmarks();
waitForClearHistory(function() {
test.run.call(test);
});
}
else {
do_test_finished();
}
}

Просмотреть файл

@ -45,376 +45,325 @@
* bookmark is deleted.
*/
const bmServ = PlacesUtils.bookmarks;
const histServ = PlacesUtils.history;
const lmServ = PlacesUtils.livemarks;
let tests = [
add_test(function unvisited_bookmarked_livemarkItem()
{
desc: ["Frecency of unvisited, separately bookmarked livemark item's URI ",
"should be zero after bookmark removed."].join(""),
run: function ()
do_log_info("Frecency of unvisited, separately bookmarked livemark item's " +
"URI should be zero after bookmark removed.");
// Add livemark and bookmark. Bookmark's URI is the URI of the livemark's
// only item.
const TEST_URI = NetUtil.newURI("http://example.com/livemark-item");
createLivemark(TEST_URI);
let id = PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId,
TEST_URI,
PlacesUtils.bookmarks.DEFAULT_INDEX,
"bookmark title");
waitForAsyncUpdates(function ()
{
// Add livemark and bookmark. Bookmark's URI is the URI of the livemark's
// only item.
let lmItemURL = "http://example.com/livemark-item";
let lmItemURI = uri(lmItemURL);
createLivemark(lmItemURI);
let bmId = bmServ.insertBookmark(bmServ.unfiledBookmarksFolder,
lmItemURI,
bmServ.DEFAULT_INDEX,
"bookmark title");
waitForFrecency(lmItemURL, function(aFrecency) aFrecency > 0,
this.check1, this, [lmItemURL, bmId]);
},
check1: function (aUrl, aItemId)
{
print("Bookmarked => frecency of URI should be != 0");
do_check_neq(frecencyForUrl(aUrl), 0);
do_log_info("Bookmarked => frecency of URI should be != 0");
do_check_neq(frecencyForUrl(TEST_URI), 0);
bmServ.removeItem(aItemId);
waitForFrecency(aUrl, function(aFrecency) aFrecency == 0,
this.check2, this, [aUrl]);
},
check2: function (aUrl)
{
print("URI's only bookmark is now unvisited livemark item => frecency = 0");
do_check_eq(frecencyForUrl(aUrl), 0);
run_next_test();
}
},
PlacesUtils.bookmarks.removeItem(id);
waitForAsyncUpdates(function ()
{
do_log_info("URI's only bookmark is now unvisited livemark item => frecency = 0");
do_check_eq(frecencyForUrl(TEST_URI), 0);
remove_all_bookmarks();
waitForClearHistory(run_next_test);
});
});
});
add_test(function visited_bookmarked_livemarkItem()
{
desc: ["Frecency of visited, separately bookmarked livemark item's URI ",
"should not be zero after bookmark removed."].join(""),
run: function ()
do_log_info("Frecency of visited, separately bookmarked livemark item's " +
"URI should not be zero after bookmark removed.");
// Add livemark and bookmark. Bookmark's URI is the URI of the livemark's
// only item.
const TEST_URI = NetUtil.newURI("http://example.com/livemark-item");
createLivemark(TEST_URI);
let id = PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId,
TEST_URI,
PlacesUtils.bookmarks.DEFAULT_INDEX,
"bookmark title");
waitForAsyncUpdates(function ()
{
// Add livemark and bookmark. Bookmark's URI is the URI of the livemark's
// only item.
let lmItemURL = "http://example.com/livemark-item";
let lmItemURI = uri(lmItemURL);
createLivemark(lmItemURI);
let bmId = bmServ.insertBookmark(bmServ.unfiledBookmarksFolder,
lmItemURI,
bmServ.DEFAULT_INDEX,
"bookmark title");
waitForFrecency(lmItemURL, function(aFrecency) aFrecency > 0,
this.check1, this, [lmItemURL, bmId]);
},
check1: function (aUrl, aItemId)
{
print("Bookmarked => frecency of URI should be != 0");
do_check_neq(frecencyForUrl(aUrl), 0);
do_log_info("Bookmarked => frecency of URI should be != 0");
do_check_neq(frecencyForUrl(TEST_URI), 0);
visit(uri(aUrl));
bmServ.removeItem(aItemId);
waitForFrecency(aUrl, function(aFrecency) aFrecency > 0,
this.check2, this, [aUrl]);
},
check2: function (aUrl)
{
print("URI's only bookmark is now *visited* livemark item => frecency != 0");
do_check_neq(frecencyForUrl(aUrl), 0);
run_next_test();
}
},
visit(TEST_URI);
PlacesUtils.bookmarks.removeItem(id);
waitForAsyncUpdates(function ()
{
do_log_info("URI's only bookmark is now *visited* livemark item => frecency != 0");
do_check_neq(frecencyForUrl(TEST_URI), 0);
remove_all_bookmarks();
waitForClearHistory(run_next_test);
});
});
});
add_test(function removed_bookmark()
{
desc: ["After removing bookmark, frecency of bookmark's URI should be zero ",
"if URI is unvisited and no longer bookmarked."].join(""),
run: function ()
do_log_info("After removing bookmark, frecency of bookmark's URI should be " +
"zero if URI is unvisited and no longer bookmarked.");
const TEST_URI = NetUtil.newURI("http://example.com/1");
let id = PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId,
TEST_URI,
PlacesUtils.bookmarks.DEFAULT_INDEX,
"bookmark title");
waitForAsyncUpdates(function ()
{
let url = "http://example.com/1";
let bmId = bmServ.insertBookmark(bmServ.unfiledBookmarksFolder,
uri(url),
bmServ.DEFAULT_INDEX,
"bookmark title");
waitForFrecency(url, function(aFrecency) aFrecency > 0,
this.check1, this, [url, bmId]);
},
check1: function (aUrl, aItemId)
{
print("Bookmarked => frecency of URI should be != 0");
do_check_neq(frecencyForUrl(aUrl), 0);
do_log_info("Bookmarked => frecency of URI should be != 0");
do_check_neq(frecencyForUrl(TEST_URI), 0);
bmServ.removeItem(aItemId);
waitForFrecency(aUrl, function(aFrecency) aFrecency == 0,
this.check2, this, [aUrl]);
},
check2: function (aUrl)
{
print("Unvisited URI no longer bookmarked => frecency should = 0");
do_check_eq(frecencyForUrl(aUrl), 0);
run_next_test();
}
},
PlacesUtils.bookmarks.removeItem(id);
waitForAsyncUpdates(function ()
{
do_log_info("Unvisited URI no longer bookmarked => frecency should = 0");
do_check_eq(frecencyForUrl(TEST_URI), 0);
remove_all_bookmarks();
waitForClearHistory(run_next_test);
});
});
});
add_test(function removed_but_visited_bookmark()
{
desc: ["After removing bookmark, frecency of bookmark's URI should not be ",
"zero if URI is visited."].join(""),
run: function ()
do_log_info("After removing bookmark, frecency of bookmark's URI should " +
"not be zero if URI is visited.");
const TEST_URI = NetUtil.newURI("http://example.com/1");
let id = PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId,
TEST_URI,
PlacesUtils.bookmarks.DEFAULT_INDEX,
"bookmark title");
waitForAsyncUpdates(function ()
{
let bmURL = "http://example.com/1";
let bmURI = uri(bmURL);
do_log_info("Bookmarked => frecency of URI should be != 0");
do_check_neq(frecencyForUrl(TEST_URI), 0);
let bmId = bmServ.insertBookmark(bmServ.unfiledBookmarksFolder,
bmURI,
bmServ.DEFAULT_INDEX,
"bookmark title");
waitForFrecency(bmURL, function(aFrecency) aFrecency > 0,
this.check1, this, [bmURL, bmId]);
},
check1: function (aUrl, aItemId)
{
print("Bookmarked => frecency of URI should be != 0");
do_check_neq(frecencyForUrl(aUrl), 0);
visit(TEST_URI);
PlacesUtils.bookmarks.removeItem(id);
visit(uri(aUrl));
bmServ.removeItem(aItemId);
waitForFrecency(aUrl, function(aFrecency) aFrecency > 0,
this.check2, this, [aUrl]);
},
check2: function (aUrl)
{
print("*Visited* URI no longer bookmarked => frecency should != 0");
do_check_neq(frecencyForUrl(aUrl), 0);
run_next_test();
}
},
waitForAsyncUpdates(function ()
{
do_log_info("*Visited* URI no longer bookmarked => frecency should != 0");
do_check_neq(frecencyForUrl(TEST_URI), 0);
remove_all_bookmarks();
waitForClearHistory(run_next_test);
});
});
});
add_test(function remove_bookmark_still_bookmarked()
{
desc: ["After removing bookmark, frecency of bookmark's URI should not be ",
"zero if URI is still bookmarked."].join(""),
run: function ()
do_log_info("After removing bookmark, frecency of bookmark's URI should ",
"not be zero if URI is still bookmarked.");
const TEST_URI = NetUtil.newURI("http://example.com/1");
let id1 = PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId,
TEST_URI,
PlacesUtils.bookmarks.DEFAULT_INDEX,
"bookmark 1 title");
let id2 = PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId,
TEST_URI,
PlacesUtils.bookmarks.DEFAULT_INDEX,
"bookmark 2 title");
waitForAsyncUpdates(function ()
{
let bmURL = "http://example.com/1";
let bmURI = uri(bmURL);
do_log_info("Bookmarked => frecency of URI should be != 0");
do_check_neq(frecencyForUrl(TEST_URI), 0);
let bm1Id = bmServ.insertBookmark(bmServ.unfiledBookmarksFolder,
bmURI,
bmServ.DEFAULT_INDEX,
"bookmark 1 title");
PlacesUtils.bookmarks.removeItem(id1);
bmServ.insertBookmark(bmServ.unfiledBookmarksFolder,
bmURI,
bmServ.DEFAULT_INDEX,
"bookmark 2 title");
waitForFrecency(bmURL, function(aFrecency) aFrecency > 0,
this.check1, this, [bmURL, bm1Id]);
},
check1: function (aUrl, aItemId)
{
print("Bookmarked => frecency of URI should be != 0");
do_check_neq(frecencyForUrl(aUrl), 0);
waitForAsyncUpdates(function ()
{
do_log_info("URI still bookmarked => frecency should != 0");
do_check_neq(frecencyForUrl(TEST_URI), 0);
bmServ.removeItem(aItemId);
waitForFrecency(aUrl, function(aFrecency) aFrecency > 0,
this.check2, this, [aUrl]);
},
check2: function (aUrl)
{
print("URI still bookmarked => frecency should != 0");
do_check_neq(frecencyForUrl(aUrl), 0);
run_next_test();
}
},
remove_all_bookmarks();
waitForClearHistory(run_next_test);
});
});
});
add_test(function cleared_parent_of_unvisited_bookmark_to_livemarkItem()
{
desc: ["Frecency of unvisited, separately bookmarked livemark item's URI ",
"should be zero after all children removed from bookmark's ",
"parent."].join(""),
run: function ()
{
// Add livemark and bookmark. Bookmark's URI is the URI of the livemark's
// only item.
let lmItemURL = "http://example.com/livemark-item";
let lmItemURI = uri(lmItemURL);
createLivemark(lmItemURI);
do_log_info("Frecency of unvisited, separately bookmarked livemark item's " +
"URI should be zero after all children removed from bookmark's " +
"parent.");
// Add livemark and bookmark. Bookmark's URI is the URI of the livemark's
// only item.
const TEST_URI = NetUtil.newURI("http://example.com/livemark-item");
createLivemark(TEST_URI);
bmServ.insertBookmark(bmServ.unfiledBookmarksFolder,
lmItemURI,
bmServ.DEFAULT_INDEX,
"bookmark title");
waitForFrecency(lmItemURL, function(aFrecency) aFrecency > 0,
this.check1, this, [lmItemURL]);
},
check1: function (aUrl)
let id = PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId,
TEST_URI,
PlacesUtils.bookmarks.DEFAULT_INDEX,
"bookmark title");
waitForAsyncUpdates(function ()
{
print("Bookmarked => frecency of URI should be != 0");
do_check_neq(frecencyForUrl(aUrl), 0);
do_log_info("Bookmarked => frecency of URI should be != 0");
do_check_neq(frecencyForUrl(TEST_URI), 0);
bmServ.removeFolderChildren(bmServ.unfiledBookmarksFolder);
waitForFrecency(aUrl, function(aFrecency) aFrecency == 0,
this.check2, this, [aUrl]);
},
check2: function (aUrl)
{
print("URI's only bookmark is now unvisited livemark item => frecency = 0");
do_check_eq(frecencyForUrl(aUrl), 0);
run_next_test();
}
},
PlacesUtils.bookmarks.removeFolderChildren(PlacesUtils.unfiledBookmarksFolderId);
waitForAsyncUpdates(function ()
{
do_log_info("URI's only bookmark is now unvisited livemark item => frecency = 0");
do_check_eq(frecencyForUrl(TEST_URI), 0);
remove_all_bookmarks();
waitForClearHistory(run_next_test);
});
});
});
add_test(function cleared_parent_of_visited_bookmark_to_livemarkItem()
{
desc: ["Frecency of visited, separately bookmarked livemark item's URI ",
"should not be zero after all children removed from bookmark's ",
"parent."].join(""),
run: function ()
do_log_info("Frecency of visited, separately bookmarked livemark item's " +
"URI should not be zero after all children removed from " +
"bookmark's parent.");
// Add livemark and bookmark. Bookmark's URI is the URI of the livemark's
// only item.
const TEST_URI = NetUtil.newURI("http://example.com/livemark-item");
createLivemark(TEST_URI);
let id = PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId,
TEST_URI,
PlacesUtils.bookmarks.DEFAULT_INDEX,
"bookmark title");
waitForAsyncUpdates(function ()
{
// Add livemark and bookmark. Bookmark's URI is the URI of the livemark's
// only item.
let lmItemURL = "http://example.com/livemark-item";
let lmItemURI = uri(lmItemURL);
createLivemark(lmItemURI);
bmServ.insertBookmark(bmServ.unfiledBookmarksFolder,
lmItemURI,
bmServ.DEFAULT_INDEX,
"bookmark title");
waitForFrecency(lmItemURL, function(aFrecency) aFrecency > 0,
this.check1, this, [lmItemURL]);
},
check1: function (aUrl, aItemId)
{
print("Bookmarked => frecency of URI should be != 0");
do_check_neq(frecencyForUrl(aUrl), 0);
do_log_info("Bookmarked => frecency of URI should be != 0");
do_check_neq(frecencyForUrl(TEST_URI), 0);
visit(uri(aUrl));
bmServ.removeFolderChildren(bmServ.unfiledBookmarksFolder);
waitForFrecency(aUrl, function(aFrecency) aFrecency > 0,
this.check2, this, [aUrl]);
},
check2: function (aUrl)
{
print("URI's only bookmark is now *visited* livemark item => frecency != 0");
do_check_neq(frecencyForUrl(aUrl), 0);
run_next_test();
}
},
visit(TEST_URI);
PlacesUtils.bookmarks.removeFolderChildren(PlacesUtils.unfiledBookmarksFolderId);
waitForAsyncUpdates(function ()
{
do_log_info("URI's only bookmark is now *visited* livemark item => frecency != 0");
do_check_neq(frecencyForUrl(TEST_URI), 0);
remove_all_bookmarks();
waitForClearHistory(run_next_test);
});
});
});
add_test(function cleared_parent_of_unvisited_unbookmarked_livemarkItem()
{
desc: ["After removing all children from bookmark's parent, frecency of ",
"bookmark's URI should be zero if URI is unvisited and no longer ",
"bookmarked."].join(""),
run: function ()
do_log_info("After removing all children from bookmark's parent, frecency " +
"of bookmark's URI should be zero if URI is unvisited and no " +
"longer bookmarked.");
const TEST_URI = NetUtil.newURI("http://example.com/1");
let id = PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId,
TEST_URI,
PlacesUtils.bookmarks.DEFAULT_INDEX,
"bookmark title");
waitForAsyncUpdates(function ()
{
let url = "http://example.com/1";
bmServ.insertBookmark(bmServ.unfiledBookmarksFolder,
uri(url),
bmServ.DEFAULT_INDEX,
"bookmark title");
waitForFrecency(url, function(aFrecency) aFrecency > 0,
this.check1, this, [url]);
},
check1: function (aUrl, aItemId)
{
print("Bookmarked => frecency of URI should be != 0");
do_check_neq(frecencyForUrl(aUrl), 0);
do_log_info("Bookmarked => frecency of URI should be != 0");
do_check_neq(frecencyForUrl(TEST_URI), 0);
bmServ.removeFolderChildren(bmServ.unfiledBookmarksFolder);
waitForFrecency(aUrl, function(aFrecency) aFrecency == 0,
this.check2, this, [aUrl]);
},
check2: function (aUrl)
{
print("Unvisited URI no longer bookmarked => frecency should = 0");
do_check_eq(frecencyForUrl(aUrl), 0);
run_next_test();
}
},
PlacesUtils.bookmarks.removeFolderChildren(PlacesUtils.unfiledBookmarksFolderId);
waitForAsyncUpdates(function ()
{
do_log_info("Unvisited URI no longer bookmarked => frecency should = 0");
do_check_eq(frecencyForUrl(TEST_URI), 0);
remove_all_bookmarks();
waitForClearHistory(run_next_test);
});
});
});
add_test(function cleared_parent_of_visited_bookmark()
{
desc: ["After removing all children from bookmark's parent, frecency of ",
"bookmark's URI should not be zero if URI is visited."].join(""),
run: function ()
do_log_info("After removing all children from bookmark's parent, frecency " +
"of bookmark's URI should not be zero if URI is visited.");
const TEST_URI = NetUtil.newURI("http://example.com/1");
let id = PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId,
TEST_URI,
PlacesUtils.bookmarks.DEFAULT_INDEX,
"bookmark title");
waitForAsyncUpdates(function ()
{
let bmURL = "http://example.com/1";
let bmURI = uri(bmURL);
do_log_info("Bookmarked => frecency of URI should be != 0");
do_check_neq(frecencyForUrl(TEST_URI), 0);
bmServ.insertBookmark(bmServ.unfiledBookmarksFolder,
bmURI,
bmServ.DEFAULT_INDEX,
"bookmark title");
waitForFrecency(bmURL, function(aFrecency) aFrecency > 0,
this.check1, this, [bmURL]);
},
check1: function (aUrl)
{
print("Bookmarked => frecency of URI should be != 0");
do_check_neq(frecencyForUrl(aUrl), 0);
visit(TEST_URI);
PlacesUtils.bookmarks.removeFolderChildren(PlacesUtils.unfiledBookmarksFolderId);
visit(uri(aUrl));
bmServ.removeFolderChildren(bmServ.unfiledBookmarksFolder);
waitForFrecency(aUrl, function(aFrecency) aFrecency > 0,
this.check2, this, [aUrl]);
},
check2: function (aUrl)
{
print("*Visited* URI no longer bookmarked => frecency should != 0");
do_check_neq(frecencyForUrl(aUrl), 0);
run_next_test();
}
},
waitForAsyncUpdates(function ()
{
do_log_info("*Visited* URI no longer bookmarked => frecency should != 0");
do_check_neq(frecencyForUrl(TEST_URI), 0);
remove_all_bookmarks();
waitForClearHistory(run_next_test);
});
});
});
add_test(function cleared_parent_of_bookmark_still_bookmarked()
{
desc: ["After removing all children from bookmark's parent, frecency of ",
"bookmark's URI should not be zero if URI is still ",
"bookmarked."].join(""),
run: function ()
do_log_info("After removing all children from bookmark's parent, frecency " +
"of bookmark's URI should not be zero if URI is still " +
"bookmarked.");
const TEST_URI = NetUtil.newURI("http://example.com/1");
let id1 = PlacesUtils.bookmarks.insertBookmark(PlacesUtils.toolbarFolderId,
TEST_URI,
PlacesUtils.bookmarks.DEFAULT_INDEX,
"bookmark 1 title");
let id2 = PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId,
TEST_URI,
PlacesUtils.bookmarks.DEFAULT_INDEX,
"bookmark 2 title");
waitForAsyncUpdates(function ()
{
let bmURL = "http://example.com/1";
let bmURI = uri(bmURL);
do_log_info("Bookmarked => frecency of URI should be != 0");
do_check_neq(frecencyForUrl(TEST_URI), 0);
bmServ.insertBookmark(bmServ.toolbarFolder,
bmURI,
bmServ.DEFAULT_INDEX,
"bookmark 1 title");
PlacesUtils.bookmarks.removeFolderChildren(PlacesUtils.unfiledBookmarksFolderId);
bmServ.insertBookmark(bmServ.unfiledBookmarksFolder,
bmURI,
bmServ.DEFAULT_INDEX,
"bookmark 2 title");
waitForFrecency(bmURL, function(aFrecency) aFrecency > 0,
this.check1, this, [bmURL]);
},
check1: function (aUrl)
{
print("Bookmarked => frecency of URI should be != 0");
do_check_neq(frecencyForUrl(aUrl), 0);
waitForAsyncUpdates(function ()
{
// URI still bookmarked => frecency should != 0.
do_check_neq(frecencyForUrl(TEST_URI), 0);
bmServ.removeFolderChildren(bmServ.unfiledBookmarksFolder);
waitForFrecency(aUrl, function(aFrecency) aFrecency > 0,
this.check2, this, [aUrl]);
},
check2: function (aUrl)
{
// URI still bookmarked => frecency should != 0.
do_check_neq(frecencyForUrl(aUrl), 0);
run_next_test();
}
},
];
remove_all_bookmarks();
waitForClearHistory(run_next_test);
});
});
});
///////////////////////////////////////////////////////////////////////////////
/**
* Creates a livemark with a single child item.
*
* @param aLmChildItemURI
* @param aChildURI
* the URI of the livemark's single child item
* @return the item ID of the single child item
*/
function createLivemark(aLmChildItemURI) {
let lmItemId = lmServ.createLivemarkFolderOnly(bmServ.unfiledBookmarksFolder,
"livemark title",
uri("http://example.com/"),
uri("http://example.com/rdf"),
-1);
return bmServ.insertBookmark(lmItemId,
aLmChildItemURI,
bmServ.DEFAULT_INDEX,
"livemark item title");
function createLivemark(aChildURI)
{
let livemarkId = PlacesUtils.livemarks.createLivemarkFolderOnly(
PlacesUtils.unfiledBookmarksFolderId, "livemark title",
uri("http://example.com/"), uri("http://example.com/rdf"), -1
);
return PlacesUtils.bookmarks.insertBookmark(livemarkId,
aChildURI,
PlacesUtils.bookmarks.DEFAULT_INDEX,
"livemark item title");
}
/**
@ -423,32 +372,16 @@ function createLivemark(aLmChildItemURI) {
* @param aURI
* the URI of the Place for which to add a visit
*/
function visit(aURI) {
let visitId = histServ.addVisit(aURI,
Date.now() * 1000,
null,
histServ.TRANSITION_BOOKMARK,
false,
0);
function visit(aURI)
{
PlacesUtils.history.addVisit(aURI, Date.now() * 1000, null,
PlacesUtils.history.TRANSITION_BOOKMARK,
false, 0);
}
///////////////////////////////////////////////////////////////////////////////
function run_test() {
do_test_pending();
function run_test()
{
run_next_test();
}
function run_next_test() {
if (tests.length) {
let test = tests.shift();
print("\n ***Test: " + test.desc);
remove_all_bookmarks();
waitForClearHistory(function() {
test.run.call(test);
});
}
else {
do_test_finished();
}
}