Bug 1094900 - Livemarks service should use the new Bookmarks.jsm. r=ttaubert

This commit is contained in:
Marco Bonardo 2015-04-25 10:51:48 +02:00
Родитель da97f25d34
Коммит b97d610763
10 изменённых файлов: 598 добавлений и 817 удалений

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

@ -664,13 +664,14 @@ BookmarkImporter.prototype = {
if (frame.previousFeed) {
// The is a live bookmark. We create it here since in HandleLinkBegin we
// don't know the title.
PlacesUtils.livemarks.addLivemark({
let lmPromise = PlacesUtils.livemarks.addLivemark({
"title": frame.previousText,
"parentId": frame.containerId,
"index": PlacesUtils.bookmarks.DEFAULT_INDEX,
"feedURI": frame.previousFeed,
"siteURI": frame.previousLink,
}).then(null, Cu.reportError);
});
this._importPromises.push(lmPromise);
} else if (frame.previousLink) {
// This is a common bookmark.
PlacesUtils.bookmarks.setItemTitle(frame.previousId,

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

@ -411,7 +411,7 @@ BookmarkImporter.prototype = {
});
if (feedURI) {
PlacesUtils.livemarks.addLivemark({
let lmPromise = PlacesUtils.livemarks.addLivemark({
title: aData.title,
feedURI: feedURI,
parentId: aContainer,
@ -424,7 +424,8 @@ BookmarkImporter.prototype = {
PlacesUtils.bookmarks.setItemDateAdded(id, aData.dateAdded);
if (aData.annos && aData.annos.length)
PlacesUtils.setAnnotationsForItem(id, aData.annos);
}, Cu.reportError);
});
this._importPromises.push(lmPromise);
}
} else {
id = PlacesUtils.bookmarks.createFolder(

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

@ -1065,7 +1065,9 @@ function removeSameValueProperties(dest, src) {
* the URL object to convert.
* @return nsIURI for the given URL.
*/
function toURI(url) NetUtil.newURI(url.href);
function toURI(url) {
return NetUtil.newURI(url.href);
}
/**
* Convert a Date object to a PRTime (microseconds).
@ -1074,7 +1076,9 @@ function toURI(url) NetUtil.newURI(url.href);
* the Date object to convert.
* @return microseconds from the epoch.
*/
function toPRTime(date) date * 1000;
function toPRTime(date) {
return date * 1000;
}
/**
* Convert a PRTime to a Date object.
@ -1083,7 +1087,9 @@ function toPRTime(date) date * 1000;
* microseconds from the epoch.
* @return a Date object.
*/
function toDate(time) new Date(parseInt(time / 1000));
function toDate(time) {
return new Date(parseInt(time / 1000));
}
/**
* Convert an array of mozIStorageRow objects to an array of bookmark objects.
@ -1216,8 +1222,12 @@ function validateBookmarkObject(input, behavior={}) {
}
for (let prop in input) {
if (required.has(prop))
if (required.has(prop)) {
required.delete(prop);
} else if (input[prop] === undefined) {
// Skip undefined properties that are not required.
continue;
}
if (VALIDATORS.hasOwnProperty(prop)) {
try {
normalizedInput[prop] = VALIDATORS[prop](input[prop], input);
@ -1264,8 +1274,8 @@ let updateFrecency = Task.async(function* (db, urls) {
let removeOrphanAnnotations = Task.async(function* (db) {
yield db.executeCached(
`DELETE FROM moz_items_annos
WHERE id IN (SELECT a.id from moz_items_annos a
LEFT JOIN moz_bookmarks b ON a.item_id = b.id
WHERE id IN (SELECT a.id from moz_items_annos a
LEFT JOIN moz_bookmarks b ON a.item_id = b.id
WHERE b.id ISNULL)
`);
yield db.executeCached(
@ -1293,8 +1303,9 @@ let removeAnnotationsForItem = Task.async(function* (db, itemId) {
yield db.executeCached(
`DELETE FROM moz_anno_attributes
WHERE id IN (SELECT n.id from moz_anno_attributes n
LEFT JOIN moz_items_annos a ON a.anno_attribute_id = n.id
WHERE a.id ISNULL)
LEFT JOIN moz_annos a1 ON a1.anno_attribute_id = n.id
LEFT JOIN moz_items_annos a2 ON a2.anno_attribute_id = n.id
WHERE a1.id ISNULL AND a2.id ISNULL)
`);
});

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

@ -6,13 +6,12 @@
interface nsIURI;
interface mozILivemarkCallback;
interface mozILivemarkInfo;
interface mozILivemark;
interface nsINavHistoryResultObserver;
[scriptable, uuid(5B48E5A2-F07A-4E64-A935-C722A3D60B65)]
[scriptable, uuid(672387b7-a75d-4e8f-9b49-5c1dcbfff46b)]
interface mozIAsyncLivemarks : nsISupports
{
/**
@ -21,18 +20,12 @@ interface mozIAsyncLivemarks : nsISupports
* @param aLivemarkInfo
* mozILivemarkInfo object containing at least title, parentId,
* index and feedURI of the livemark to create.
* @param [optional] aCallback
* Invoked when the creation process is done. In case of failure will
* receive an error code.
*
* @return {Promise}
* @throws NS_ERROR_INVALID_ARG if the supplied information is insufficient
* for the creation.
* @deprecated passing a callback is deprecated. Moreover, for backwards
* compatibility reasons, when a callback is provided this method
* won't return a promise.
*/
jsval addLivemark(in jsval aLivemarkInfo,
[optional] in mozILivemarkCallback aCallback);
jsval addLivemark(in jsval aLivemarkInfo);
/**
* Removes an existing livemark.
@ -40,18 +33,11 @@ interface mozIAsyncLivemarks : nsISupports
* @param aLivemarkInfo
* mozILivemarkInfo object containing either an id or a guid of the
* livemark to remove.
* @param [optional] aCallback
* Invoked when the removal process is done. In case of failure will
* receive an error code.
*
* @return {Promise}
* @throws NS_ERROR_INVALID_ARG if the id/guid is invalid.
* @deprecated passing a callback is deprecated. Moreover, for backwards
* compatibility reasons, when a callback is provided this method
* won't return a promise.
*/
jsval removeLivemark(in jsval aLivemarkInfo,
[optional] in mozILivemarkCallback aCallback);
jsval removeLivemark(in jsval aLivemarkInfo);
/**
* Gets an existing livemark.
@ -59,19 +45,12 @@ interface mozIAsyncLivemarks : nsISupports
* @param aLivemarkInfo
* mozILivemarkInfo object containing either an id or a guid of the
* livemark to retrieve.
* @param [optional] aCallback
* Invoked when the fetching process is done. In case of failure will
* receive an error code.
*
* @return {Promise}
* @throws NS_ERROR_INVALID_ARG if the id/guid is invalid or an invalid
* callback is provided.
* @deprecated passing a callback is deprecated. Moreover, for backwards
* compatibility reasons, when a callback is provided this method
* won't return a promise.
*/
jsval getLivemark(in jsval aLivemarkInfo,
[optional] in mozILivemarkCallback aCallback);
jsval getLivemark(in jsval aLivemarkInfo);
/**
* Reloads all livemarks if they are expired or if forced to do so.
@ -85,27 +64,13 @@ interface mozIAsyncLivemarks : nsISupports
void reloadLivemarks([optional]in boolean aForceUpdate);
};
[scriptable, function, uuid(62a426f9-39a6-42f0-ad48-b7404d48188f)]
interface mozILivemarkCallback : nsISupports
{
/**
* Invoked when a livemark is added, removed or retrieved.
*
* @param aStatus
* Whether the request was completed successfully.
* Use Components.isSuccessCode(aStatus) to check this.
* @param aLivemark
* A mozILivemark object representing the livemark, or null on removal.
*/
void onCompletion(in nsresult aStatus,
in mozILivemark aLivemark);
};
[scriptable, uuid(E52B2273-729D-4EBC-A039-E9CD9E18FF86)]
[scriptable, uuid(3a3c5e8f-ec4a-4086-ae0a-d16420d30c9f)]
interface mozILivemarkInfo : nsISupports
{
/**
* Id of the bookmarks folder representing this livemark.
*
* @deprecated Use guid instead.
*/
readonly attribute long long id;
@ -121,9 +86,16 @@ interface mozILivemarkInfo : nsISupports
/**
* Id of the bookmarks parent folder containing this livemark.
*
* @deprecated Use parentGuid instead.
*/
readonly attribute long long parentId;
/**
* Guid of the bookmarks parent folder containing this livemark.
*/
readonly attribute long long parentGuid;
/**
* The position of this livemark in the bookmarks parent folder.
*/

Разница между файлами не показана из-за своего большого размера Загрузить разницу

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

@ -65,9 +65,9 @@ add_task(function* invalid_input_throws() {
Assert.throws(() => PlacesUtils.bookmarks.update({ url: "te st" }),
/Invalid value for property 'url'/);
Assert.throws(() => PlacesUtils.bookmarks.insert({ title: -1 }),
Assert.throws(() => PlacesUtils.bookmarks.update({ title: -1 }),
/Invalid value for property 'title'/);
Assert.throws(() => PlacesUtils.bookmarks.insert({ title: undefined }),
Assert.throws(() => PlacesUtils.bookmarks.update({ title: {} }),
/Invalid value for property 'title'/);
Assert.throws(() => PlacesUtils.bookmarks.update({ guid: "123456789012" }),

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

@ -45,7 +45,8 @@ let test_bookmarks = {
keyword: "test",
sidebar: true,
postData: "hidden1%3Dbar&text1%3D%25s",
charset: "ISO-8859-1"
charset: "ISO-8859-1",
url: "http://test/post"
}
]
}
@ -72,8 +73,6 @@ let gBookmarksFileOld;
// Places bookmarks.html file pointer.
let gBookmarksFileNew;
Cu.import("resource://gre/modules/BookmarkHTMLUtils.jsm");
function run_test()
{
run_next_test();
@ -138,10 +137,10 @@ add_task(function* test_emptytitle_export()
yield PlacesTestUtils.promiseAsyncUpdates();
const NOTITLE_URL = "http://notitle.mozilla.org/";
let id = PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId,
NetUtil.newURI(NOTITLE_URL),
PlacesUtils.bookmarks.DEFAULT_INDEX,
"");
let bookmark = yield PlacesUtils.bookmarks.insert({
parentGuid: PlacesUtils.bookmarks.unfiledGuid,
url: NOTITLE_URL
});
test_bookmarks.unfiled.push({ title: "", url: NOTITLE_URL });
yield BookmarkHTMLUtils.exportToFile(gBookmarksFileNew);
@ -154,7 +153,13 @@ add_task(function* test_emptytitle_export()
// Cleanup.
test_bookmarks.unfiled.pop();
PlacesUtils.bookmarks.removeItem(id);
// HTML imports don't restore GUIDs yet.
let reimportedBookmark = yield PlacesUtils.bookmarks.fetch({
parentGuid: PlacesUtils.bookmarks.unfiledGuid,
index: PlacesUtils.bookmarks.DEFAULT_INDEX
});
Assert.equal(reimportedBookmark.url.href, bookmark.url.href);
yield PlacesUtils.bookmarks.remove(reimportedBookmark);
yield BookmarkHTMLUtils.exportToFile(gBookmarksFileNew);
yield PlacesTestUtils.promiseAsyncUpdates();
@ -178,24 +183,29 @@ add_task(function* test_import_chromefavicon()
const CHROME_FAVICON_URI = NetUtil.newURI("chrome://global/skin/icons/information-16.png");
const CHROME_FAVICON_URI_2 = NetUtil.newURI("chrome://global/skin/icons/error-16.png");
do_print("Importing from html");
yield BookmarkHTMLUtils.importFromFile(gBookmarksFileNew, true);
yield PlacesTestUtils.promiseAsyncUpdates();
let id = PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId,
PAGE_URI,
PlacesUtils.bookmarks.DEFAULT_INDEX,
"Test");
let deferred = Promise.defer();
PlacesUtils.favicons.setAndFetchFaviconForPage(
PAGE_URI, CHROME_FAVICON_URI, true,
PlacesUtils.favicons.FAVICON_LOAD_NON_PRIVATE,
deferred.resolve);
yield deferred.promise;
do_print("Insert bookmark");
let bookmark = yield PlacesUtils.bookmarks.insert({
parentGuid: PlacesUtils.bookmarks.unfiledGuid,
url: PAGE_URI,
title: "Test"
});
deferred = Promise.defer();
PlacesUtils.favicons.getFaviconDataForPage(PAGE_URI,
function (aURI, aDataLen, aData, aMimeType) deferred.resolve(aData));
let data = yield deferred.promise;
do_print("Set favicon");
yield new Promise(resolve => {
PlacesUtils.favicons.setAndFetchFaviconForPage(
PAGE_URI, CHROME_FAVICON_URI, true,
PlacesUtils.favicons.FAVICON_LOAD_NON_PRIVATE,
resolve);
});
let data = yield new Promise(resolve => {
PlacesUtils.favicons.getFaviconDataForPage(
PAGE_URI, (uri, dataLen, data, mimeType) => resolve(data));
});
let base64Icon = "data:image/png;base64," +
base64EncodeString(String.fromCharCode.apply(String, data));
@ -203,26 +213,35 @@ add_task(function* test_import_chromefavicon()
test_bookmarks.unfiled.push(
{ title: "Test", url: PAGE_URI.spec, icon: base64Icon });
do_print("Export to html");
yield BookmarkHTMLUtils.exportToFile(gBookmarksFileNew);
yield PlacesTestUtils.promiseAsyncUpdates();
do_print("Set favicon");
// Change the favicon to check it's really imported again later.
deferred = Promise.defer();
PlacesUtils.favicons.setAndFetchFaviconForPage(
PAGE_URI, CHROME_FAVICON_URI_2, true,
PlacesUtils.favicons.FAVICON_LOAD_NON_PRIVATE,
deferred.resolve);
yield deferred.promise;
yield new Promise(resolve => {
PlacesUtils.favicons.setAndFetchFaviconForPage(
PAGE_URI, CHROME_FAVICON_URI_2, true,
PlacesUtils.favicons.FAVICON_LOAD_NON_PRIVATE,
resolve);
});
do_print("import from html");
yield PlacesUtils.bookmarks.eraseEverything();
yield BookmarkHTMLUtils.importFromFile(gBookmarksFileNew, true);
yield PlacesTestUtils.promiseAsyncUpdates();
do_print("Test imported bookmarks");
yield testImportedBookmarks();
// Cleanup.
test_bookmarks.unfiled.pop();
PlacesUtils.bookmarks.removeItem(id);
// HTML imports don't restore GUIDs yet.
let reimportedBookmark = yield PlacesUtils.bookmarks.fetch({
parentGuid: PlacesUtils.bookmarks.unfiledGuid,
index: PlacesUtils.bookmarks.DEFAULT_INDEX
});
yield PlacesUtils.bookmarks.remove(reimportedBookmark);
yield BookmarkHTMLUtils.exportToFile(gBookmarksFileNew);
yield PlacesTestUtils.promiseAsyncUpdates();

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

@ -101,14 +101,22 @@ let database_check = Task.async(function* () {
root = PlacesUtils.getFolderContents(PlacesUtils.toolbarFolderId).root;
Assert.equal(root.childCount, 3);
let livemarkNode = root.getChild(1);
Assert.equal("Latest Headlines", livemarkNode.title);
// For now some promises are resolved later, so we can't guarantee an order.
let foundLivemark = false;
for (let i = 0; i < root.childCount; ++i) {
let node = root.getChild(i);
if (node.title == "Latest Headlines") {
foundLivemark = true;
Assert.equal("Latest Headlines", node.title);
let livemark = yield PlacesUtils.livemarks.getLivemark({ id: livemarkNode.itemId });
Assert.equal("http://en-us.fxfeeds.mozilla.com/en-US/firefox/livebookmarks/",
livemark.siteURI.spec);
Assert.equal("http://en-us.fxfeeds.mozilla.com/en-US/firefox/headlines.xml",
livemark.feedURI.spec);
let livemark = yield PlacesUtils.livemarks.getLivemark({ guid: node.bookmarkGuid });
Assert.equal("http://en-us.fxfeeds.mozilla.com/en-US/firefox/livebookmarks/",
livemark.siteURI.spec);
Assert.equal("http://en-us.fxfeeds.mozilla.com/en-US/firefox/headlines.xml",
livemark.feedURI.spec);
}
}
Assert.ok(foundLivemark);
// cleanup
root.containerOpen = false;

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

@ -1,40 +1,35 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
// Test that asking for a livemark in a annotationChanged notification works.
add_task(function* () {
let annoPromise = new Promise(resolve => {
let annoObserver = {
onItemAnnotationSet(id, name) {
if (name == PlacesUtils.LMANNO_FEEDURI) {
PlacesUtils.annotations.removeObserver(this);
resolve();
}
},
onItemAnnotationRemoved() {},
onPageAnnotationSet() {},
onPageAnnotationRemoved() {},
QueryInterface: XPCOMUtils.generateQI([
Ci.nsIAnnotationObserver
]),
};
PlacesUtils.annotations.addObserver(annoObserver, false);
});
// Test that asking for isLivemark in a annotationChanged notification
// correctly returns true.
function run_test()
{
do_test_pending();
let annoObserver = {
onItemAnnotationSet:
function AO_onItemAnnotationSet(aItemId, aAnnotationName)
{
if (aAnnotationName == PlacesUtils.LMANNO_FEEDURI) {
PlacesUtils.annotations.removeObserver(this);
PlacesUtils.livemarks.getLivemark({ id: aItemId })
.then(aLivemark => {
PlacesUtils.bookmarks.removeItem(aItemId);
do_test_finished();
}, do_throw);
}
},
onItemAnnotationRemoved: function () {},
onPageAnnotationSet: function() {},
onPageAnnotationRemoved: function() {},
QueryInterface: XPCOMUtils.generateQI([
Ci.nsIAnnotationObserver
]),
}
PlacesUtils.annotations.addObserver(annoObserver, false);
PlacesUtils.livemarks.addLivemark(
let livemark = yield PlacesUtils.livemarks.addLivemark(
{ title: "livemark title"
, parentId: PlacesUtils.unfiledBookmarksFolderId
, parentGuid: PlacesUtils.bookmarks.unfiledGuid
, index: PlacesUtils.bookmarks.DEFAULT_INDEX
, siteURI: uri("http://example.com/")
, feedURI: uri("http://example.com/rdf")
}
).then(null, do_throw);
}
});
yield annoPromise;
livemark = yield PlacesUtils.livemarks.getLivemark({ guid: livemark.guid });
Assert.ok(livemark);
yield PlacesUtils.livemarks.removeLivemark({ guid: livemark.guid });
});

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

@ -6,20 +6,16 @@
const FEED_URI = NetUtil.newURI("http://feed.rss/");
const SITE_URI = NetUtil.newURI("http://site.org/");
add_task(function test_addLivemark_noArguments_throws()
{
add_task(function* test_addLivemark_noArguments_throws() {
try {
yield PlacesUtils.livemarks.addLivemark();
do_throw("Invoking addLivemark with no arguments should throw");
} catch (ex) {
// The error is actually generated by XPConnect.
do_check_eq(ex.result, Cr.NS_ERROR_XPC_NOT_ENOUGH_ARGS);
}
});
add_task(function test_addLivemark_emptyObject_throws()
{
add_task(function* test_addLivemark_emptyObject_throws() {
try {
yield PlacesUtils.livemarks.addLivemark({});
do_throw("Invoking addLivemark with empty object should throw");
@ -28,8 +24,7 @@ add_task(function test_addLivemark_emptyObject_throws()
}
});
add_task(function test_addLivemark_badParentId_throws()
{
add_task(function* test_addLivemark_badParentId_throws() {
try {
yield PlacesUtils.livemarks.addLivemark({ parentId: "test" });
do_throw("Invoking addLivemark with a bad parent id should throw");
@ -38,8 +33,7 @@ add_task(function test_addLivemark_badParentId_throws()
}
});
add_task(function test_addLivemark_invalidParentId_throws()
{
add_task(function* test_addLivemark_invalidParentId_throws() {
try {
yield PlacesUtils.livemarks.addLivemark({ parentId: -2 });
do_throw("Invoking addLivemark with an invalid parent id should throw");
@ -48,8 +42,7 @@ add_task(function test_addLivemark_invalidParentId_throws()
}
});
add_task(function test_addLivemark_noIndex_throws()
{
add_task(function* test_addLivemark_noIndex_throws() {
try {
yield PlacesUtils.livemarks.addLivemark({
parentId: PlacesUtils.unfiledBookmarksFolderId });
@ -59,8 +52,7 @@ add_task(function test_addLivemark_noIndex_throws()
}
});
add_task(function test_addLivemark_badIndex_throws()
{
add_task(function* test_addLivemark_badIndex_throws() {
try {
yield PlacesUtils.livemarks.addLivemark(
{ parentId: PlacesUtils.unfiledBookmarksFolderId
@ -71,8 +63,7 @@ add_task(function test_addLivemark_badIndex_throws()
}
});
add_task(function test_addLivemark_invalidIndex_throws()
{
add_task(function* test_addLivemark_invalidIndex_throws() {
try {
yield PlacesUtils.livemarks.addLivemark(
{ parentId: PlacesUtils.unfiledBookmarksFolderId
@ -84,24 +75,20 @@ add_task(function test_addLivemark_invalidIndex_throws()
}
});
add_task(function test_addLivemark_noFeedURI_throws()
{
add_task(function* test_addLivemark_noFeedURI_throws() {
try {
yield PlacesUtils.livemarks.addLivemark(
{ parentId: PlacesUtils.unfiledBookmarksFolderId
, index: PlacesUtils.bookmarks.DEFAULT_INDEX });
{ parentGuid: PlacesUtils.bookmarks.unfiledGuid });
do_throw("Invoking addLivemark with no feedURI should throw");
} catch (ex) {
do_check_eq(ex.result, Cr.NS_ERROR_INVALID_ARG);
}
});
add_task(function test_addLivemark_badFeedURI_throws()
{
add_task(function* test_addLivemark_badFeedURI_throws() {
try {
yield PlacesUtils.livemarks.addLivemark(
{ parentId: PlacesUtils.unfiledBookmarksFolderId
, index: PlacesUtils.bookmarks.DEFAULT_INDEX
{ parentGuid: PlacesUtils.bookmarks.unfiledGuid
, feedURI: "test" });
do_throw("Invoking addLivemark with a bad feedURI should throw");
} catch (ex) {
@ -109,12 +96,10 @@ add_task(function test_addLivemark_badFeedURI_throws()
}
});
add_task(function test_addLivemark_badSiteURI_throws()
{
add_task(function* test_addLivemark_badSiteURI_throws() {
try {
yield PlacesUtils.livemarks.addLivemark(
{ parentId: PlacesUtils.unfiledBookmarksFolderId
, index: PlacesUtils.bookmarks.DEFAULT_INDEX
{ parentGuid: PlacesUtils.bookmarks.unfiledGuid
, feedURI: FEED_URI
, siteURI: "test" });
do_throw("Invoking addLivemark with a bad siteURI should throw");
@ -123,12 +108,10 @@ add_task(function test_addLivemark_badSiteURI_throws()
}
});
add_task(function test_addLivemark_badGuid_throws()
{
add_task(function* test_addLivemark_badGuid_throws() {
try {
yield PlacesUtils.livemarks.addLivemark(
{ parentId: PlacesUtils.unfiledBookmarksFolderId
, index: PlacesUtils.bookmarks.DEFAULT_INDEX
{ parentGuid: PlacesUtils.bookmarks.unfileGuid
, feedURI: FEED_URI
, guid: "123456" });
do_throw("Invoking addLivemark with a bad guid should throw");
@ -137,23 +120,7 @@ add_task(function test_addLivemark_badGuid_throws()
}
});
add_task(function test_addLivemark_badCallback_throws()
{
try {
yield PlacesUtils.livemarks.addLivemark(
{ parentId: PlacesUtils.unfiledBookmarksFolderId
, index: PlacesUtils.bookmarks.DEFAULT_INDEX
, feedURI: FEED_URI
}, "test");
do_throw("Invoking addLivemark with a bad callback should throw");
} catch (ex) {
// The error is actually generated by XPConnect.
do_check_eq(ex.result, Cr.NS_ERROR_XPC_BAD_CONVERT_JS);
}
});
add_task(function test_addLivemark_noCallback_succeeds()
{
add_task(function* test_addLivemark_parentId_succeeds() {
let onItemAddedCalled = false;
PlacesUtils.bookmarks.addObserver({
__proto__: NavBookmarkObserver.prototype,
@ -172,37 +139,35 @@ add_task(function test_addLivemark_noCallback_succeeds()
yield PlacesUtils.livemarks.addLivemark(
{ title: "test"
, parentId: PlacesUtils.unfiledBookmarksFolderId
, index: PlacesUtils.bookmarks.DEFAULT_INDEX
, feedURI: FEED_URI });
do_check_true(onItemAddedCalled);
});
add_task(function test_addLivemark_noSiteURI_succeeds()
{
add_task(function* test_addLivemark_noSiteURI_succeeds() {
let livemark = yield PlacesUtils.livemarks.addLivemark(
{ title: "test"
, parentId: PlacesUtils.unfiledBookmarksFolderId
, index: PlacesUtils.bookmarks.DEFAULT_INDEX
, parentGuid: PlacesUtils.bookmarks.unfiledGuid
, feedURI: FEED_URI
});
do_check_true(livemark.id > 0);
do_check_valid_places_guid(livemark.guid);
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.lastModified, PlacesUtils.bookmarks.getItemLastModified(livemark.id));
do_check_eq(livemark.dateAdded, PlacesUtils.bookmarks.getItemDateAdded(livemark.id));
do_check_eq(livemark.parentGuid, PlacesUtils.bookmarks.unfiledGuid);
do_check_true(livemark.feedURI.equals(FEED_URI));
do_check_eq(livemark.siteURI, null);
do_check_true(livemark.lastModified > 0);
let bookmark = yield PlacesUtils.bookmarks.fetch(livemark.guid);
do_check_eq(livemark.index, bookmark.index);
do_check_eq(livemark.dateAdded, bookmark.dateAdded * 1000);
});
add_task(function test_addLivemark_succeeds()
{
add_task(function* test_addLivemark_succeeds() {
let livemark = yield PlacesUtils.livemarks.addLivemark(
{ title: "test"
, parentId: PlacesUtils.unfiledBookmarksFolderId
, index: PlacesUtils.bookmarks.DEFAULT_INDEX
, parentGuid: PlacesUtils.bookmarks.unfiledGuid
, feedURI: FEED_URI
, siteURI: SITE_URI
});
@ -211,9 +176,7 @@ add_task(function test_addLivemark_succeeds()
do_check_valid_places_guid(livemark.guid);
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_eq(livemark.parentGuid, PlacesUtils.bookmarks.unfiledGuid);
do_check_true(livemark.feedURI.equals(FEED_URI));
do_check_true(livemark.siteURI.equals(SITE_URI));
do_check_true(PlacesUtils.annotations
@ -224,13 +187,11 @@ add_task(function test_addLivemark_succeeds()
PlacesUtils.LMANNO_SITEURI));
});
add_task(function test_addLivemark_bogusid_succeeds()
{
add_task(function* test_addLivemark_bogusid_succeeds() {
let livemark = yield PlacesUtils.livemarks.addLivemark(
{ id: 100 // Should be ignored.
, title: "test"
, parentId: PlacesUtils.unfiledBookmarksFolderId
, index: PlacesUtils.bookmarks.DEFAULT_INDEX
, parentGuid: PlacesUtils.bookmarks.unfiledGuid
, feedURI: FEED_URI
, siteURI: SITE_URI
});
@ -238,84 +199,83 @@ add_task(function test_addLivemark_bogusid_succeeds()
do_check_neq(livemark.id, 100);
});
add_task(function test_addLivemark_bogusParent_fails()
{
add_task(function* test_addLivemark_bogusParentId_fails() {
try {
yield PlacesUtils.livemarks.addLivemark(
{ title: "test"
, parentId: 187
, index: PlacesUtils.bookmarks.DEFAULT_INDEX
, feedURI: FEED_URI
});
do_throw("Adding a livemark with a bogus parent should fail");
} catch(ex) {}
});
add_task(function test_addLivemark_intoLivemark_fails()
{
add_task(function* test_addLivemark_bogusParentGuid_fails() {
try {
yield PlacesUtils.livemarks.addLivemark(
{ title: "test"
, parentGuid: "123456789012"
, feedURI: FEED_URI
});
do_throw("Adding a livemark with a bogus parent should fail");
} catch(ex) {}
})
add_task(function* test_addLivemark_intoLivemark_fails() {
let livemark = yield PlacesUtils.livemarks.addLivemark(
{ title: "test"
, parentId: PlacesUtils.unfiledBookmarksFolderId
, index: PlacesUtils.bookmarks.DEFAULT_INDEX
, parentGuid: PlacesUtils.bookmarks.unfiledGuid
, feedURI: FEED_URI
});
do_check_true(Boolean(livemark));
try {
yield PlacesUtils.livemarks.addLivemark(
{ title: "test"
, parentId: livemark.id
, index: PlacesUtils.bookmarks.DEFAULT_INDEX
, parentGuid: livemark.guid
, feedURI: FEED_URI
});
do_throw("Adding a livemark into a livemark should fail");
} catch(ex) {}
} catch(ex) {
do_check_eq(ex.result, Cr.NS_ERROR_INVALID_ARG);
}
});
add_task(function test_addLivemark_forceGuid_succeeds()
{
let checkLivemark = aLivemark => {
do_check_eq(aLivemark.guid, "1234567890AB");
do_check_guid_for_bookmark(aLivemark.id, "1234567890AB");
};
add_task(function* test_addLivemark_forceGuid_succeeds() {
let livemark = yield PlacesUtils.livemarks.addLivemark(
{ title: "test"
, parentId: PlacesUtils.unfiledBookmarksFolderId
, index: PlacesUtils.bookmarks.DEFAULT_INDEX
, parentGuid: PlacesUtils.bookmarks.unfiledGuid
, feedURI: FEED_URI
, guid: "1234567890AB"
});
checkLivemark(livemark);
do_check_eq(livemark.guid, "1234567890AB");
do_check_guid_for_bookmark(livemark.id, "1234567890AB");
});
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
, parentGuid: PlacesUtils.bookmarks.unfiledGuid
, feedURI: FEED_URI
, dateAdded
});
do_check_eq(livemark.dateAdded, dateAdded);
});
add_task(function test_addLivemark_lastModified_succeeds()
{
add_task(function* test_addLivemark_lastModified_succeeds() {
let now = Date.now() * 1000;
let livemark = yield PlacesUtils.livemarks.addLivemark(
{ title: "test"
, parentId: PlacesUtils.unfiledBookmarksFolderId
, index: PlacesUtils.bookmarks.DEFAULT_INDEX
, parentGuid: PlacesUtils.bookmarks.unfiledGuid
, feedURI: FEED_URI
, lastModified: now
});
do_check_eq(livemark.lastModified, now);
do_check_eq(livemark.dateAdded, now);
// lastModified is updated when annotations are added to the livemark.
do_check_true(livemark.lastModified >= now);
});
add_task(function test_removeLivemark_emptyObject_throws()
{
add_task(function* test_removeLivemark_emptyObject_throws() {
try {
yield PlacesUtils.livemarks.removeLivemark({});
do_throw("Invoking removeLivemark with empty object should throw");
@ -324,8 +284,7 @@ add_task(function test_removeLivemark_emptyObject_throws()
}
});
add_task(function test_removeLivemark_noValidId_throws()
{
add_task(function* test_removeLivemark_noValidId_throws() {
try {
yield PlacesUtils.livemarks.removeLivemark({ id: -10, guid: "test"});
do_throw("Invoking removeLivemark with no valid id should throw");
@ -334,8 +293,7 @@ add_task(function test_removeLivemark_noValidId_throws()
}
});
add_task(function test_removeLivemark_nonExistent_fails()
{
add_task(function* test_removeLivemark_nonExistent_fails() {
try {
yield PlacesUtils.livemarks.removeLivemark({ id: 1337 });
do_throw("Removing a non-existent livemark should fail");
@ -344,41 +302,36 @@ add_task(function test_removeLivemark_nonExistent_fails()
}
});
add_task(function test_removeLivemark_guid_succeeds()
{
add_task(function* test_removeLivemark_guid_succeeds() {
let livemark = yield PlacesUtils.livemarks.addLivemark(
{ title: "test"
, parentId: PlacesUtils.unfiledBookmarksFolderId
, index: PlacesUtils.bookmarks.DEFAULT_INDEX
, parentGuid: PlacesUtils.bookmarks.unfiledGuid
, feedURI: FEED_URI
, guid: "234567890ABC"
});
do_check_eq(livemark.guid, "234567890ABC");
yield PlacesUtils.livemarks.removeLivemark({
id: 789, guid: "234567890ABC"
});
do_check_eq(PlacesUtils.bookmarks.getItemIndex(livemark.id), -1);
do_check_eq((yield PlacesUtils.bookmarks.fetch("234567890ABC")), null);
});
add_task(function test_removeLivemark_id_succeeds()
{
add_task(function* test_removeLivemark_id_succeeds() {
let livemark = yield PlacesUtils.livemarks.addLivemark(
{ title: "test"
, parentId: PlacesUtils.unfiledBookmarksFolderId
, index: PlacesUtils.bookmarks.DEFAULT_INDEX
, parentGuid: PlacesUtils.bookmarks.unfiledGuid
, feedURI: FEED_URI
});
yield PlacesUtils.livemarks.removeLivemark({ id: livemark.id });
do_check_eq(PlacesUtils.bookmarks.getItemIndex(livemark.id), -1);
do_check_eq((yield PlacesUtils.bookmarks.fetch("234567890ABC")), null);
});
add_task(function test_getLivemark_emptyObject_throws()
{
add_task(function* test_getLivemark_emptyObject_throws() {
try {
yield PlacesUtils.livemarks.getLivemark({});
do_throw("Invoking getLivemark with empty object should throw");
@ -387,8 +340,7 @@ add_task(function test_getLivemark_emptyObject_throws()
}
});
add_task(function test_getLivemark_noValidId_throws()
{
add_task(function* test_getLivemark_noValidId_throws() {
try {
yield PlacesUtils.livemarks.getLivemark({ id: -10, guid: "test"});
do_throw("Invoking getLivemark with no valid id should throw");
@ -397,30 +349,24 @@ add_task(function test_getLivemark_noValidId_throws()
}
});
add_task(function test_getLivemark_nonExistentId_fails()
{
add_task(function* test_getLivemark_nonExistentId_fails() {
try {
yield PlacesUtils.livemarks.getLivemark({ id: 1234 });
do_throw("getLivemark for a non existent id should fail");
}
catch(ex) {}
} catch (ex) {}
});
add_task(function test_getLivemark_nonExistentGUID_fails()
{
add_task(function* test_getLivemark_nonExistentGUID_fails() {
try {
yield PlacesUtils.livemarks.getLivemark({ guid: "34567890ABCD" });
do_throw("getLivemark for a non-existent guid should fail");
}
catch(ex) {}
} catch (ex) {}
});
add_task(function test_getLivemark_guid_succeeds()
{
add_task(function* test_getLivemark_guid_succeeds() {
yield PlacesUtils.livemarks.addLivemark(
{ title: "test"
, parentId: PlacesUtils.unfiledBookmarksFolderId
, index: PlacesUtils.bookmarks.DEFAULT_INDEX
, parentGuid: PlacesUtils.bookmarks.unfiledGuid
, feedURI: FEED_URI
, guid: "34567890ABCD" });
@ -430,18 +376,19 @@ add_task(function test_getLivemark_guid_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.parentGuid, PlacesUtils.bookmarks.unfiledGuid);
do_check_true(livemark.feedURI.equals(FEED_URI));
do_check_eq(livemark.siteURI, null);
do_check_eq(livemark.guid, "34567890ABCD");
let bookmark = yield PlacesUtils.bookmarks.fetch("34567890ABCD");
do_check_eq(livemark.index, bookmark.index);
});
add_task(function test_getLivemark_id_succeeds()
{
add_task(function* test_getLivemark_id_succeeds() {
let livemark = yield PlacesUtils.livemarks.addLivemark(
{ title: "test"
, parentId: PlacesUtils.unfiledBookmarksFolderId
, index: PlacesUtils.bookmarks.DEFAULT_INDEX
, parentGuid: PlacesUtils.bookmarks.unfiledGuid
, feedURI: FEED_URI
});
@ -449,65 +396,87 @@ add_task(function test_getLivemark_id_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.parentGuid, PlacesUtils.bookmarks.unfiledGuid);
do_check_true(livemark.feedURI.equals(FEED_URI));
do_check_eq(livemark.siteURI, null);
do_check_guid_for_bookmark(livemark.id, livemark.guid);
let bookmark = yield PlacesUtils.bookmarks.fetch(livemark.guid);
do_check_eq(livemark.index, bookmark.index);
});
add_task(function test_getLivemark_removeItem_contention()
{
add_task(function* test_getLivemark_removeItem_contention() {
// do not yield.
PlacesUtils.livemarks.addLivemark({ title: "test"
, parentId: PlacesUtils.unfiledBookmarksFolderId
, index: PlacesUtils.bookmarks.DEFAULT_INDEX
, parentGuid: PlacesUtils.bookmarks.unfiledGuid
, feedURI: FEED_URI
});
PlacesUtils.bookmarks.removeFolderChildren(PlacesUtils.unfiledBookmarksFolderId);
PlacesUtils.livemarks.addLivemark({ title: "test"
, parentId: PlacesUtils.unfiledBookmarksFolderId
, index: PlacesUtils.bookmarks.DEFAULT_INDEX
, feedURI: FEED_URI
});
let id = PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.unfiledBookmarksFolderId,
PlacesUtils.bookmarks.DEFAULT_INDEX);
yield PlacesUtils.bookmarks.eraseEverything();
let livemark = yield PlacesUtils.livemarks.addLivemark(
{ title: "test"
, parentGuid: PlacesUtils.bookmarks.unfiledGuid
, feedURI: FEED_URI
});
let livemark = yield PlacesUtils.livemarks.getLivemark({ id: id });
livemark = yield PlacesUtils.livemarks.getLivemark({ guid: livemark.guid });
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_true(livemark.feedURI.equals(FEED_URI));
do_check_eq(livemark.siteURI, null);
do_check_guid_for_bookmark(livemark.id, livemark.guid);
});
add_task(function test_title_change()
{
add_task(function* test_title_change() {
let livemark = yield PlacesUtils.livemarks.addLivemark(
{ title: "test"
, parentId: PlacesUtils.unfiledBookmarksFolderId
, index: PlacesUtils.bookmarks.DEFAULT_INDEX
, feedURI: FEED_URI });
, parentGuid: PlacesUtils.bookmarks.unfiledGuid
, feedURI: FEED_URI
});
PlacesUtils.bookmarks.setItemTitle(livemark.id, "test2");
do_check_eq(livemark.title, "test2");
yield PlacesUtils.bookmarks.update({ guid: livemark.guid,
title: "test2" });
// Poll for the title change.
while (true) {
let lm = yield PlacesUtils.livemarks.getLivemark({ guid: livemark.guid });
if (lm.title == "test2")
break;
yield new Promise(resolve => do_timeout(resolve, 100));
}
});
add_task(function test_livemark_move()
{
add_task(function* test_livemark_move() {
let livemark = yield PlacesUtils.livemarks.addLivemark(
{ title: "test"
, parentId: PlacesUtils.unfiledBookmarksFolderId
, index: PlacesUtils.bookmarks.DEFAULT_INDEX
, parentGuid: PlacesUtils.bookmarks.unfiledGuid
, feedURI: FEED_URI } );
PlacesUtils.bookmarks.moveItem(livemark.id,
PlacesUtils.toolbarFolderId,
PlacesUtils.bookmarks.DEFAULT_INDEX);
do_check_eq(livemark.parentId, PlacesUtils.toolbarFolderId);
do_check_eq(livemark.index, PlacesUtils.bookmarks.getItemIndex(livemark.id));
yield PlacesUtils.bookmarks.update({ guid: livemark.guid,
parentGuid: PlacesUtils.bookmarks.toolbarGuid,
index: PlacesUtils.bookmarks.DEFAULT_INDEX });
// Poll for the parent change.
while (true) {
let lm = yield PlacesUtils.livemarks.getLivemark({ guid: livemark.guid });
if (lm.parentGuid == PlacesUtils.bookmarks.toolbarGuid)
break;
yield new Promise(resolve => do_timeout(resolve, 100));
}
});
function run_test() {
run_next_test();
}
add_task(function* test_livemark_removed() {
let livemark = yield PlacesUtils.livemarks.addLivemark(
{ title: "test"
, parentGuid: PlacesUtils.bookmarks.unfiledGuid
, feedURI: FEED_URI } );
yield PlacesUtils.bookmarks.remove(livemark.guid);
// Poll for the livemark removal.
while (true) {
try {
yield PlacesUtils.livemarks.getLivemark({ guid: livemark.guid });
} catch (ex) {
break;
}
yield new Promise(resolve => do_timeout(resolve, 100));
}
});