From ec99eade1aabbf1203dec7df4a2477c80ae09970 Mon Sep 17 00:00:00 2001 From: Asaf Romano Date: Tue, 25 Nov 2014 14:34:20 +0200 Subject: [PATCH] Bug 1098296 - addLivemark should take a dateAdded input property. r=mak --- .../components/places/mozIAsyncLivemarks.idl | 7 +++- .../places/nsINavBookmarksService.idl | 3 +- .../components/places/nsLivemarkService.js | 35 +++++++++++++------ .../tests/unit/test_mozIAsyncLivemarks.js | 14 ++++++++ 4 files changed, 45 insertions(+), 14 deletions(-) diff --git a/toolkit/components/places/mozIAsyncLivemarks.idl b/toolkit/components/places/mozIAsyncLivemarks.idl index 3bcc1358d2a..035dea0080a 100644 --- a/toolkit/components/places/mozIAsyncLivemarks.idl +++ b/toolkit/components/places/mozIAsyncLivemarks.idl @@ -101,7 +101,7 @@ interface mozILivemarkCallback : nsISupports in mozILivemark aLivemark); }; -[scriptable, uuid(6e40d5b1-ce48-4458-8b68-6bee17d30ef3)] +[scriptable, uuid(E52B2273-729D-4EBC-A039-E9CD9E18FF86)] interface mozILivemarkInfo : nsISupports { /** @@ -129,6 +129,11 @@ interface mozILivemarkInfo : nsISupports */ readonly attribute long index; + /** + * Time this livemark was created. + */ + readonly attribute PRTime dateAdded; + /** * Time this livemark's details were last modified. Doesn't track changes to * the livemark contents. diff --git a/toolkit/components/places/nsINavBookmarksService.idl b/toolkit/components/places/nsINavBookmarksService.idl index a7d81605fe0..f8877d45693 100644 --- a/toolkit/components/places/nsINavBookmarksService.idl +++ b/toolkit/components/places/nsINavBookmarksService.idl @@ -113,8 +113,7 @@ interface nsINavBookmarkObserver : nsISupports * For certain properties, this is set to the new value of the * property (see the list below). * @param aLastModified - * If lastModified changed, this parameter is the new value, otherwise - * it's set to 0. + * The updated last-modified value. * @param aItemType * The type of the item to be removed (see TYPE_* constants below). * @param aParentId diff --git a/toolkit/components/places/nsLivemarkService.js b/toolkit/components/places/nsLivemarkService.js index 1141aadd15c..fe94747a149 100644 --- a/toolkit/components/places/nsLivemarkService.js +++ b/toolkit/components/places/nsLivemarkService.js @@ -80,7 +80,8 @@ LivemarkService.prototype = { AND n.name = ${aAnnoParam}`; } - return `SELECT b.id, b.title, b.parent, b.position, b.guid, b.lastModified, + return `SELECT b.id, b.title, b.parent, b.position, b.guid, + b.dateAdded, b.lastModified, ( ${getAnnoSQLFragment(":feedURI_anno")} ) AS feedURI, ( ${getAnnoSQLFragment(":siteURI_anno")} ) AS siteURI FROM moz_bookmarks b @@ -106,6 +107,7 @@ LivemarkService.prototype = { title: row.getResultByName("title"), parentId: row.getResultByName("parent"), index: row.getResultByName("position"), + dateAdded: row.getResultByName("dateAdded"), lastModified: row.getResultByName("lastModified"), feedURI: NetUtil.newURI(row.getResultByName("feedURI")), siteURI: siteURL ? NetUtil.newURI(siteURL) : null }); @@ -202,11 +204,15 @@ LivemarkService.prototype = { , feedURI: aLivemarkInfo.feedURI , siteURI: aLivemarkInfo.siteURI , guid: aLivemarkInfo.guid + , dateAdded: aLivemarkInfo.dateAdded , lastModified: aLivemarkInfo.lastModified }); if (this._itemAdded && this._itemAdded.id == livemark.id) { livemark.index = this._itemAdded.index; livemark.guid = this._itemAdded.guid; + if (!aLivemarkInfo.dateAdded) { + livemark.dateAdded = this._itemAdded.dateAdded; + } if (!aLivemarkInfo.lastModified) { livemark.lastModified = this._itemAdded.lastModified; } @@ -411,6 +417,7 @@ LivemarkService.prototype = { this._itemAdded = { id: aItemId , guid: aGUID , index: aIndex + , dateAdded: aDateAdded , lastModified: aDateAdded }; } @@ -422,11 +429,15 @@ LivemarkService.prototype = { if (aItemType == Ci.nsINavBookmarksService.TYPE_FOLDER) { if (this._itemAdded && this._itemAdded.id == aItemId) { this._itemAdded.lastModified = aLastModified; - } + } if (aItemId in this._livemarks) { if (aProperty == "title") { this._livemarks[aItemId].title = aValue; } + else if (aProperty == "dateAdded") { + this._livemark[aItemId].dateAdded = parseInt(aValue, 10); + } + this._livemarks[aItemId].lastModified = aLastModified; } } @@ -526,8 +537,8 @@ function Livemark(aLivemarkInfo) this._nodes = new Map(); this._guid = ""; + this._dateAdded = 0; this._lastModified = 0; - this.loadGroup = null; this.feedURI = null; this.siteURI = null; @@ -539,6 +550,7 @@ function Livemark(aLivemarkInfo) this.guid = aLivemarkInfo.guid; this.feedURI = aLivemarkInfo.feedURI; this.siteURI = aLivemarkInfo.siteURI; + this.dateAdded = aLivemarkInfo.dateAdded; this.lastModified = aLivemarkInfo.lastModified; } else { @@ -551,6 +563,10 @@ function Livemark(aLivemarkInfo) if (aLivemarkInfo.siteURI) { this.writeSiteURI(aLivemarkInfo.siteURI); } + if (aLivemarkInfo.dateAdded) { + this.dateAdded = aLivemarkInfo.dateAdded; + PlacesUtils.bookmarks.setItemDateAdded(this.id, this.dateAdded); + } // Last modified time must be the last change. if (aLivemarkInfo.lastModified) { this.lastModified = aLivemarkInfo.lastModified; @@ -614,16 +630,13 @@ Livemark.prototype = { this.siteURI = aSiteURI; }, - set guid(aGUID) { - this._guid = aGUID; - return aGUID; - }, + set guid(aGUID) this._guid = aGUID, get guid() this._guid, - set lastModified(aLastModified) { - this._lastModified = aLastModified; - return aLastModified; - }, + set dateAdded(aDateAdded) this._dateAdded = aDateAdded, + get dateAdded() this._dateAdded, + + set lastModified(aLastModified) this._lastModified = aLastModified, get lastModified() this._lastModified, /** diff --git a/toolkit/components/places/tests/unit/test_mozIAsyncLivemarks.js b/toolkit/components/places/tests/unit/test_mozIAsyncLivemarks.js index eeb6fa2b7ca..8e4e43e579f 100644 --- a/toolkit/components/places/tests/unit/test_mozIAsyncLivemarks.js +++ b/toolkit/components/places/tests/unit/test_mozIAsyncLivemarks.js @@ -192,6 +192,7 @@ add_task(function test_addLivemark_noSiteURI_succeeds() do_check_eq(livemark.parentId, PlacesUtils.unfiledBookmarksFolderId); do_check_eq(livemark.index, PlacesUtils.bookmarks.getItemIndex(livemark.id)); do_check_eq(livemark.lastModified, PlacesUtils.bookmarks.getItemLastModified(livemark.id)); + do_check_eq(livemark.dateAdded, PlacesUtils.bookmarks.getItemDateAdded(livemark.id)); do_check_true(livemark.feedURI.equals(FEED_URI)); do_check_eq(livemark.siteURI, null); }); @@ -211,6 +212,7 @@ add_task(function test_addLivemark_succeeds() do_check_eq(livemark.title, "test"); do_check_eq(livemark.parentId, PlacesUtils.unfiledBookmarksFolderId); do_check_eq(livemark.index, PlacesUtils.bookmarks.getItemIndex(livemark.id)); + do_check_eq(livemark.dateAdded, PlacesUtils.bookmarks.getItemDateAdded(livemark.id)); do_check_eq(livemark.lastModified, PlacesUtils.bookmarks.getItemLastModified(livemark.id)); do_check_true(livemark.feedURI.equals(FEED_URI)); do_check_true(livemark.siteURI.equals(SITE_URI)); @@ -287,6 +289,18 @@ add_task(function test_addLivemark_forceGuid_succeeds() checkLivemark(livemark); }); +add_task(function* test_addLivemark_dateAdded_succeeds() { + let dateAdded = new Date("2013-03-01T01:10:00") * 1000; + let livemark = yield PlacesUtils.livemarks.addLivemark( + { title: "test" + , parentId: PlacesUtils.unfiledBookmarksFolderId + , index: PlacesUtils.bookmarks.DEFAULT_INDEX + , feedURI: FEED_URI + , dateAdded + }); + do_check_eq(livemark.dateAdded, dateAdded); +}); + add_task(function test_addLivemark_lastModified_succeeds() { let now = Date.now() * 1000;