Bug 358946. Let the places unit tests pass. r=sspitzer,mano

This commit is contained in:
sayrer%gmail.com 2006-12-14 17:28:52 +00:00
Родитель eabb19cef3
Коммит 6d284e0017
9 изменённых файлов: 111 добавлений и 43 удалений

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

@ -241,7 +241,7 @@ var PlacesController = {
_livemarks: null,
get livemarks() {
if (!this._livemarks) {
this._livemarks =
this._livemarks =
Cc["@mozilla.org/browser/livemark-service;2"].
getService(Ci.nsILivemarkService);
}
@ -2249,8 +2249,16 @@ function PlacesBaseTransaction() {
PlacesBaseTransaction.prototype = {
bookmarks: Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
getService(Ci.nsINavBookmarksService),
livemarks: Cc["@mozilla.org/browser/livemark-service;2"].
getService(Ci.nsILivemarkService),
_livemarks: null,
get livemarks() {
if (!this._livemarks) {
this._livemarks =
Cc["@mozilla.org/browser/livemark-service;2"].
getService(Ci.nsILivemarkService);
}
return this._livemarks;
},
LOG: LOG,
redoTransaction: function PIT_redoTransaction() {
throw Cr.NS_ERROR_NOT_IMPLEMENTED;

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

@ -75,3 +75,14 @@ var iosvc = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
function uri(spec) {
return iosvc.newURI(spec, null, null);
}
// Delete a previously created sqlite file
function clearDB() {
try {
var file = dirSvc.get('ProfD', Ci.nsIFile);
file.append("places.sqlite");
if (file.exists())
file.remove(false);
} catch(ex) { dump("Exception: " + ex); }
}
clearDB();

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

@ -38,8 +38,4 @@
// put cleanup of the bookmarks test here.
// remove bookmarks file
try {
var file = dirSvc.get('ProfD', Ci.nsIFile);
file.append("places.sqlite");
file.remove(false);
} catch(ex) { dump(ex); }
clearDB();

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

@ -39,14 +39,16 @@
// Get livemark service
try {
var lmsvc = Cc["@mozilla.org/browser/livemark-service;2"].getService(Ci.nsILivemarkService);
var lmsvc = Cc["@mozilla.org/browser/livemark-service;2"].
getService(Ci.nsILivemarkService);
} catch(ex) {
do_throw("Could not get livemark-service\n");
}
// Get bookmark service
try {
var bmsvc = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].getService(Ci.nsINavBookmarksService);
var bmsvc = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
getService(Ci.nsINavBookmarksService);
} catch(ex) {
do_throw("Could not get nav-bookmarks-service\n");
}
@ -56,8 +58,10 @@ var root = bmsvc.bookmarksRoot;
// main
function run_test() {
var livemarkId = lmsvc.createLivemark(root, "foo", uri("http://example.com/"),
uri("http://example.com/rss.xml"), -1);
var livemarkId =
lmsvc.createLivemarkFolderOnly(bmsvc, root, "foo",
uri("http://example.com/"),
uri("http://example.com/rss.xml"), -1);
do_check_true(lmsvc.isLivemark(livemarkId));
do_check_true(lmsvc.getSiteURI(livemarkId).spec == "http://example.com/");
@ -85,5 +89,5 @@ function run_test() {
// make sure folders don't get counted as bookmarks
// create folder
var randomFolder = bmsvc.createFolder(root, "Random", -1);
do_check_true(!lmsvc.isLivemark(randomFolder))
do_check_true(!lmsvc.isLivemark(randomFolder));
}

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

@ -41,8 +41,9 @@
#include "nsIRemoteContainer.idl"
interface nsIURI;
interface nsINavBookmarksService;
[scriptable, uuid(1e66ec55-87fa-45c2-a912-dd44afb06922)]
[scriptable, uuid(86f0be08-7b7f-4ec6-97ff-ecace917b852)]
interface nsILivemarkService : nsIRemoteContainer
{
/**
@ -60,6 +61,16 @@ interface nsILivemarkService : nsIRemoteContainer
in nsIURI feedURI,
in PRInt32 index);
/**
* Same as above, use during startup to avoid HTTP traffic
*/
PRInt64 createLivemarkFolderOnly(in nsINavBookmarksService bms,
in PRInt64 folder,
in AString name,
in nsIURI siteURI,
in nsIURI feedURI,
in PRInt32 index);
/**
* Determines whether the folder with the given folder ID identifies
* a livemark container.

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

@ -213,7 +213,8 @@ class BookmarkContentSink : public nsIHTMLContentSink
public:
nsresult Init(PRBool aAllowRootChanges,
nsINavBookmarksService* bookmarkService,
PRInt64 aFolder);
PRInt64 aFolder,
PRBool aIsImportDefaults);
NS_DECL_ISUPPORTS
@ -276,6 +277,10 @@ protected:
// to reparent it on import.
PRBool mAllowRootChanges;
// if set, this is an import of initial bookmarks.html content,
// so we don't want to kick off HTTP traffic
PRBool mIsImportDefaults;
// If a folder was specified to import into, then ignore flags to put
// bookmarks in the bookmarks menu or toolbar and keep them inside
// the folder.
@ -327,7 +332,8 @@ protected:
nsresult
BookmarkContentSink::Init(PRBool aAllowRootChanges,
nsINavBookmarksService* bookmarkService,
PRInt64 aFolder)
PRInt64 aFolder,
PRBool aIsImportDefaults)
{
nsresult rv;
mBookmarksService = bookmarkService;
@ -339,6 +345,7 @@ BookmarkContentSink::Init(PRBool aAllowRootChanges,
NS_ENSURE_SUCCESS(rv, rv);
mAllowRootChanges = aAllowRootChanges;
mIsImportDefaults = aIsImportDefaults;
// initialize the root frame with the menu root
PRInt64 menuRoot;
@ -730,12 +737,23 @@ BookmarkContentSink::HandleLinkEnd()
// (It gets created here instead of in HandleLinkBegin()
// because we need to know the title before creating it.)
PRInt64 folderId;
mLivemarkService->CreateLivemark(frame.mContainerID,
frame.mPreviousText,
frame.mPreviousLink,
frame.mPreviousFeed,
-1,
&folderId);
if (mIsImportDefaults) {
mLivemarkService->CreateLivemarkFolderOnly(mBookmarksService,
frame.mContainerID,
frame.mPreviousText,
frame.mPreviousLink,
frame.mPreviousFeed,
-1,
&folderId);
} else {
mLivemarkService->CreateLivemark(frame.mContainerID,
frame.mPreviousText,
frame.mPreviousLink,
frame.mPreviousFeed,
-1,
&folderId);
}
#ifdef DEBUG_IMPORT
PrintNesting();
printf("Creating livemark '%s'\n",
@ -1033,20 +1051,21 @@ NS_IMETHODIMP
nsNavBookmarks::ImportBookmarksHTML(nsIURI* aURL)
{
// this version is exposed on the interface and disallows changing of roots
return ImportBookmarksHTMLInternal(aURL, PR_FALSE, 0);
return ImportBookmarksHTMLInternal(aURL, PR_FALSE, 0, PR_FALSE);
}
NS_IMETHODIMP
nsNavBookmarks::ImportBookmarksHTMLToFolder(nsIURI* aURL, PRInt64 aFolder)
{
// this version is exposed on the interface and disallows changing of roots
return ImportBookmarksHTMLInternal(aURL, PR_FALSE, aFolder);
return ImportBookmarksHTMLInternal(aURL, PR_FALSE, aFolder, PR_FALSE);
}
nsresult
nsNavBookmarks::ImportBookmarksHTMLInternal(nsIURI* aURL,
PRBool aAllowRootChanges,
PRInt64 aFolder)
PRInt64 aFolder,
PRBool aIsImportDefaults)
{
// wrap the import in a transaction to make it faster
mozStorageTransaction transaction(DBConn(), PR_FALSE);
@ -1063,7 +1082,7 @@ nsNavBookmarks::ImportBookmarksHTMLInternal(nsIURI* aURL,
nsCOMPtr<BookmarkContentSink> sink = new BookmarkContentSink;
NS_ENSURE_TRUE(sink, NS_ERROR_OUT_OF_MEMORY);
rv = sink->Init(aAllowRootChanges, this, aFolder);
rv = sink->Init(aAllowRootChanges, this, aFolder, aIsImportDefaults);
NS_ENSURE_SUCCESS(rv, rv);
parser->SetContentSink(sink);

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

@ -206,10 +206,10 @@ LivemarkService.prototype = {
this._bms.removeFolderChildren(folderId);
},
insertLivemarkLoadingItem: function LS_insertLivemarkLoading(folderId) {
insertLivemarkLoadingItem: function LS_insertLivemarkLoading(bms, folderId) {
var loadingURI = gIoService.newURI("about:livemark-loading", null, null);
this._bms.insertItem(folderId, loadingURI, -1);
this._bms.setItemTitle(loadingURI, this._loading);
bms.insertItem(folderId, loadingURI, -1);
bms.setItemTitle(loadingURI, this._loading);
},
_updateLivemarkChildren:
@ -234,7 +234,7 @@ LivemarkService.prototype = {
}
catch (ex) {
// This livemark has never been loaded, since it has no expire time.
this.insertLivemarkLoadingItem(livemark.folderId);
this.insertLivemarkLoadingItem(this._bms, livemark.folderId);
}
var loadgroup;
@ -268,9 +268,33 @@ LivemarkService.prototype = {
// Don't add livemarks to livemarks
if (this.isLivemark(folder))
throw Cr.NS_ERROR_INVALID_ARG;
var [livemarkID, livemarkURI] =
this._createFolder(this._bms, folder, name, siteURI, feedURI, index);
// kick off http fetch
this._updateLivemarkChildren(
this._pushLivemark(livemarkID, livemarkURI, feedURI) - 1,
false
);
var livemark = this._bms.createContainer(folder, name, LS_CONTRACTID, index);
var livemarkURI = this._bms.getFolderURI(livemark);
return livemarkID;
},
createLivemarkFolderOnly:
function LS_createLivemarkFolderOnly(bms, folder, name, siteURI,
feedURI, index) {
var [livemarkID, livemarkURI] =
this._createFolder(bms, folder, name, siteURI, feedURI, index);
this.insertLivemarkLoadingItem(bms, livemarkID);
this._pushLivemark(livemarkID, livemarkURI, feedURI);
return livemarkID;
},
_createFolder:
function LS__createFolder(bms, folder, name, siteURI, feedURI, index) {
var livemarkID = bms.createContainer(folder, name, LS_CONTRACTID, index);
var livemarkURI = bms.getFolderURI(livemarkID);
// Add an annotation to map the folder URI to the livemark feed URI
this._ans.setAnnotationString(livemarkURI, LMANNO_FEEDURI, feedURI.spec, 0,
@ -285,12 +309,7 @@ LivemarkService.prototype = {
0, this._ans.EXPIRE_NEVER);
}
this._updateLivemarkChildren(
this._pushLivemark(livemark, livemarkURI, feedURI) - 1,
false
);
return livemark;
return [livemarkID, livemarkURI];
},
isLivemark: function LS_isLivemark(folder) {
@ -475,7 +494,6 @@ LivemarkLoadListener.prototype = {
* See nsIFeedResultListener.idl
*/
handleResult: function LLL_handleResult(result) {
if (this._isAborted) {
this._livemark.locked = false;
return;
@ -669,7 +687,6 @@ var Module = {
getClassObject: function M_getClassObject(cm, cid, iid) {
if (!iid.equals(Ci.nsIFactory))
throw Cr.NS_ERROR_NOT_IMPLEMENTED;
if (cid.equals(LS_CLASSID))
return new GenericComponentFactory(LivemarkService);

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

@ -401,7 +401,7 @@ nsNavBookmarks::InitRoots()
NS_LITERAL_CSTRING("chrome://browser/locale/places/default_places.html"),
nsnull);
NS_ENSURE_SUCCESS(rv, rv);
rv = ImportBookmarksHTMLInternal(defaultPlaces, PR_TRUE, 0);
rv = ImportBookmarksHTMLInternal(defaultPlaces, PR_TRUE, 0, PR_TRUE);
NS_ENSURE_SUCCESS(rv, rv);
// migrate the user's old bookmarks
@ -420,7 +420,8 @@ nsNavBookmarks::InitRoots()
rv = ioservice->NewFileURI(bookmarksFile,
getter_AddRefs(bookmarksFileURI));
NS_ENSURE_SUCCESS(rv, rv);
rv = ImportBookmarksHTMLInternal(bookmarksFileURI, PR_FALSE, 0);
rv = ImportBookmarksHTMLInternal(bookmarksFileURI, PR_FALSE,
0, PR_TRUE);
NS_ENSURE_SUCCESS(rv, rv);
}
}

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

@ -241,7 +241,8 @@ private:
// in nsBookmarksHTML
nsresult ImportBookmarksHTMLInternal(nsIURI* aURL,
PRBool aAllowRootChanges,
PRInt64 aFolder);
PRInt64 aFolder,
PRBool aIsImportDefaults);
nsresult WriteContainer(PRInt64 aFolder, const nsCString& aIndent,
nsIOutputStream* aOutput);
nsresult WriteContainerHeader(PRInt64 aFolder, const nsCString& aIndent,