Bug 1098296 - addLivemark should take a dateAdded input property. r=mak

This commit is contained in:
Asaf Romano 2014-11-25 14:34:20 +02:00
Родитель 4fc8bdf986
Коммит 7b844a88ce
4 изменённых файлов: 45 добавлений и 14 удалений

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

@ -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.

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

@ -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

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

@ -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
};
}
@ -427,6 +434,10 @@ LivemarkService.prototype = {
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,
/**

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

@ -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;