Backed out changeset d7e7ced3622f (bug 1360872) for failing xpcshell's test_async_transactions.js | test_creating_and_removing_a_separator, at least on OS X. r=backout

This commit is contained in:
Sebastian Hengst 2017-06-30 19:29:17 +02:00
parent df3233b549
commit acb0601c26
17 changed files with 95 additions and 152 deletions

View File

@ -1133,15 +1133,15 @@ this.PlacesUIUtils = {
"Tags": { title: this.getString("OrganizerQueryTags") },
"AllBookmarks": { title: this.getString("OrganizerQueryAllBookmarks") },
"BookmarksToolbar":
{ title: "",
{ title: null,
concreteTitle: PlacesUtils.getString("BookmarksToolbarFolderTitle"),
concreteId: PlacesUtils.toolbarFolderId },
"BookmarksMenu":
{ title: "",
{ title: null,
concreteTitle: PlacesUtils.getString("BookmarksMenuFolderTitle"),
concreteId: PlacesUtils.bookmarksMenuFolderId },
"UnfiledBookmarks":
{ title: "",
{ title: null,
concreteTitle: PlacesUtils.getString("OtherBookmarksFolderTitle"),
concreteId: PlacesUtils.unfiledBookmarksFolderId },
};

View File

@ -34,7 +34,7 @@ add_task(async function() {
"Root title is correct");
// Check the shortcut's title.
let bookmark = await PlacesUtils.bookmarks.fetch(tree.selectedNode.bookmarkGuid);
is(bookmark.title, "",
is(bookmark.title, null,
"Shortcut title is null");
}
);

View File

@ -103,7 +103,7 @@ add_test(function test_bookmark_create() {
do_check_eq(PlacesUtils.bookmarks.getItemType(id),
PlacesUtils.bookmarks.TYPE_BOOKMARK);
do_check_true(PlacesUtils.bookmarks.getBookmarkURI(id).equals(tburi));
do_check_eq(PlacesUtils.bookmarks.getItemTitle(id), "");
do_check_eq(PlacesUtils.bookmarks.getItemTitle(id), null);
let error;
try {
PlacesUtils.annotations.getItemAnnotation(id, "bookmarkProperties/description");
@ -147,7 +147,7 @@ add_test(function test_bookmark_update() {
PlacesUtils.annotations.getItemAnnotation(
bmk1_id, "bookmarkProperties/description");
}, Cr.NS_ERROR_NOT_AVAILABLE);
do_check_eq(PlacesUtils.bookmarks.getItemTitle(bmk1_id), "");
do_check_eq(PlacesUtils.bookmarks.getItemTitle(bmk1_id), null);
do_check_eq(PlacesUtils.bookmarks.getKeywordForBookmark(bmk1_id), null);
} finally {
_("Clean up.");

View File

@ -35,7 +35,8 @@
*
* - title (string)
* The item's title, if any. Empty titles and null titles are considered
* the same. Titles longer than DB_TITLE_LENGTH_MAX will be truncated.
* the same, and the property is unset on retrieval in such a case.
* Titles longer than DB_TITLE_LENGTH_MAX will be truncated.
*
* The following properties are only valid for URLs:
*
@ -190,8 +191,7 @@ var Bookmarks = Object.freeze({
url: { requiredIf: b => b.type == this.TYPE_BOOKMARK,
validIf: b => b.type == this.TYPE_BOOKMARK },
parentGuid: { required: true },
title: { defaultValue: "",
validIf: b => [ this.TYPE_BOOKMARK,
title: { validIf: b => [ this.TYPE_BOOKMARK,
this.TYPE_FOLDER ].includes(b.type) },
dateAdded: { defaultValue: addedTime },
lastModified: { defaultValue: modTime,
@ -224,7 +224,7 @@ var Bookmarks = Object.freeze({
let isTagging = parent._parentId == PlacesUtils.tagsFolderId;
let isTagsFolder = parent._id == PlacesUtils.tagsFolderId;
notify(observers, "onItemAdded", [ itemId, parent._id, item.index,
item.type, uri, item.title,
item.type, uri, item.title || null,
PlacesUtils.toPRTime(item.dateAdded), item.guid,
item.parentGuid, item.source ],
{ isTagging: isTagging || isTagsFolder });
@ -351,8 +351,7 @@ var Bookmarks = Object.freeze({
url: { requiredIf: b => b.type == TYPE_BOOKMARK,
validIf: b => b.type == TYPE_BOOKMARK },
parentGuid: { required: true },
title: { defaultValue: "",
validIf: b => [ TYPE_BOOKMARK,
title: { validIf: b => [ TYPE_BOOKMARK,
TYPE_FOLDER ].includes(b.type) },
dateAdded: { defaultValue: time,
validIf: b => !b.lastModified ||
@ -471,7 +470,7 @@ var Bookmarks = Object.freeze({
}
notify(observers, "onItemAdded", [ itemId, parentId, item.index,
item.type, uri, item.title,
item.type, uri, item.title || null,
PlacesUtils.toPRTime(item.dateAdded), item.guid,
item.parentGuid, item.source ],
{ isTagging: false });
@ -1155,8 +1154,7 @@ function updateBookmark(info, item, newParent) {
let tuples = new Map();
tuples.set("lastModified", { value: PlacesUtils.toPRTime(info.lastModified) });
if (info.hasOwnProperty("title"))
tuples.set("title", { value: info.title,
fragment: `title = NULLIF(:title, "")` });
tuples.set("title", { value: info.title });
if (info.hasOwnProperty("dateAdded"))
tuples.set("dateAdded", { value: PlacesUtils.toPRTime(info.dateAdded) });
@ -1296,6 +1294,10 @@ function updateBookmark(info, item, newParent) {
let updatedItem = mergeIntoNewObject(item, info, additionalParentInfo);
// Don't return an empty title to the caller.
if (updatedItem.hasOwnProperty("title") && updatedItem.title === null)
delete updatedItem.title;
return updatedItem;
});
}
@ -1339,8 +1341,8 @@ function insertBookmark(item, parent) {
dateAdded, lastModified, guid,
syncChangeCounter, syncStatus)
VALUES (CASE WHEN :url ISNULL THEN NULL ELSE (SELECT id FROM moz_places WHERE url_hash = hash(:url) AND url = :url) END,
:type, :parent, :index, NULLIF(:title, ""), :date_added,
:last_modified, :guid, :syncChangeCounter, :syncStatus)
:type, :parent, :index, :title, :date_added, :last_modified,
:guid, :syncChangeCounter, :syncStatus)
`, { url: item.hasOwnProperty("url") ? item.url.href : null,
type: item.type, parent: parent._id, index: item.index,
title: item.title, date_added: PlacesUtils.toPRTime(item.dateAdded),
@ -1374,6 +1376,10 @@ function insertBookmark(item, parent) {
updateFrecency(db, [item.url]).catch(Cu.reportError);
}
// Don't return an empty title to the caller.
if (item.hasOwnProperty("title") && item.title === null)
delete item.title;
return item;
});
}
@ -1414,7 +1420,7 @@ function insertBookmarkTree(items, source, parent, urls, lastAddedForParent) {
VALUES (CASE WHEN :url ISNULL THEN NULL ELSE (SELECT id FROM moz_places WHERE url_hash = hash(:url) AND url = :url) END, :type,
(SELECT id FROM moz_bookmarks WHERE guid = :parentGuid),
IFNULL(:index, (SELECT count(*) FROM moz_bookmarks WHERE parent = :rootId)),
NULLIF(:title, ""), :date_added, :last_modified, :guid,
:title, :date_added, :last_modified, :guid,
:syncChangeCounter, :syncStatus)`, items);
await setAncestorsLastModified(db, parent.guid, lastAddedForParent,
@ -1560,8 +1566,8 @@ async function queryBookmarks(info) {
// hence setting them to NULL
let rows = await db.executeCached(
`SELECT b.guid, IFNULL(p.guid, "") AS parentGuid, b.position AS 'index',
b.dateAdded, b.lastModified, b.type,
IFNULL(b.title, "") AS title, h.url AS url, b.parent, p.parent,
b.dateAdded, b.lastModified, b.type, b.title,
h.url AS url, b.parent, p.parent,
NULL AS _id,
NULL AS _childCount,
NULL AS _grandParentId,
@ -1585,8 +1591,8 @@ async function fetchBookmark(info, concurrent) {
let query = async function(db) {
let rows = await db.executeCached(
`SELECT b.guid, IFNULL(p.guid, "") AS parentGuid, b.position AS 'index',
b.dateAdded, b.lastModified, b.type, IFNULL(b.title, "") AS title,
h.url AS url, b.id AS _id, b.parent AS _parentId,
b.dateAdded, b.lastModified, b.type, b.title, h.url AS url,
b.id AS _id, b.parent AS _parentId,
(SELECT count(*) FROM moz_bookmarks WHERE parent = b.id) AS _childCount,
p.parent AS _grandParentId, b.syncStatus AS _syncStatus
FROM moz_bookmarks b
@ -1610,8 +1616,8 @@ async function fetchBookmarkByPosition(info, concurrent) {
let index = info.index == Bookmarks.DEFAULT_INDEX ? null : info.index;
let rows = await db.executeCached(
`SELECT b.guid, IFNULL(p.guid, "") AS parentGuid, b.position AS 'index',
b.dateAdded, b.lastModified, b.type, IFNULL(b.title, "") AS title,
h.url AS url, b.id AS _id, b.parent AS _parentId,
b.dateAdded, b.lastModified, b.type, b.title, h.url AS url,
b.id AS _id, b.parent AS _parentId,
(SELECT count(*) FROM moz_bookmarks WHERE parent = b.id) AS _childCount,
p.parent AS _grandParentId, b.syncStatus AS _syncStatus
FROM moz_bookmarks b
@ -1639,8 +1645,8 @@ async function fetchBookmarksByURL(info, concurrent) {
let rows = await db.executeCached(
`/* do not warn (bug no): not worth to add an index */
SELECT b.guid, IFNULL(p.guid, "") AS parentGuid, b.position AS 'index',
b.dateAdded, b.lastModified, b.type, IFNULL(b.title, "") AS title,
h.url AS url, b.id AS _id, b.parent AS _parentId,
b.dateAdded, b.lastModified, b.type, b.title, h.url AS url,
b.id AS _id, b.parent AS _parentId,
NULL AS _childCount, /* Unused for now */
p.parent AS _grandParentId, b.syncStatus AS _syncStatus
FROM moz_bookmarks b
@ -1668,9 +1674,8 @@ function fetchRecentBookmarks(numberOfItems) {
let tagsFolderId = await promiseTagsFolderId();
let rows = await db.executeCached(
`SELECT b.guid, IFNULL(p.guid, "") AS parentGuid, b.position AS 'index',
b.dateAdded, b.lastModified, b.type,
IFNULL(b.title, "") AS title, h.url AS url, NULL AS _id,
NULL AS _parentId, NULL AS _childCount, NULL AS _grandParentId,
b.dateAdded, b.lastModified, b.type, b.title, h.url AS url,
NULL AS _id, NULL AS _parentId, NULL AS _childCount, NULL AS _grandParentId,
NULL AS _syncStatus
FROM moz_bookmarks b
JOIN moz_bookmarks p ON p.id = b.parent
@ -1698,8 +1703,8 @@ function fetchBookmarksByParent(info) {
let rows = await db.executeCached(
`SELECT b.guid, IFNULL(p.guid, "") AS parentGuid, b.position AS 'index',
b.dateAdded, b.lastModified, b.type, IFNULL(b.title, "") AS title,
h.url AS url, b.id AS _id, b.parent AS _parentId,
b.dateAdded, b.lastModified, b.type, b.title, h.url AS url,
b.id AS _id, b.parent AS _parentId,
(SELECT count(*) FROM moz_bookmarks WHERE parent = b.id) AS _childCount,
p.parent AS _grandParentId, b.syncStatus AS _syncStatus
FROM moz_bookmarks b
@ -1983,7 +1988,7 @@ function removeSameValueProperties(dest, src) {
function rowsToItemsArray(rows) {
return rows.map(row => {
let item = {};
for (let prop of ["guid", "index", "type", "title"]) {
for (let prop of ["guid", "index", "type"]) {
item[prop] = row.getResultByName(prop);
}
for (let prop of ["dateAdded", "lastModified"]) {
@ -1991,15 +1996,11 @@ function rowsToItemsArray(rows) {
if (value)
item[prop] = PlacesUtils.toDate(value);
}
let parentGuid = row.getResultByName("parentGuid");
if (parentGuid) {
item.parentGuid = parentGuid;
for (let prop of ["title", "parentGuid", "url" ]) {
let val = row.getResultByName(prop);
if (val)
item[prop] = prop === "url" ? new URL(val) : val;
}
let url = row.getResultByName("url");
if (url) {
item.url = new URL(url);
}
for (let prop of ["_id", "_parentId", "_childCount", "_grandParentId",
"_syncStatus"]) {
let val = row.getResultByName(prop);
@ -2167,9 +2168,8 @@ async function(db, folderGuids, options) {
)
SELECT b.id AS _id, b.parent AS _parentId, b.position AS 'index',
b.type, url, b.guid, p.guid AS parentGuid, b.dateAdded,
b.lastModified, IFNULL(b.title, "") AS title,
p.parent AS _grandParentId, NULL AS _childCount,
b.syncStatus AS _syncStatus
b.lastModified, b.title, p.parent AS _grandParentId,
NULL AS _childCount, b.syncStatus AS _syncStatus
FROM descendants
JOIN moz_bookmarks b ON did = b.id
JOIN moz_bookmarks p ON p.id = b.parent

View File

@ -292,9 +292,6 @@ IsValidGUID(const nsACString& aGUID)
void
TruncateTitle(const nsACString& aTitle, nsACString& aTrimmed)
{
if (aTitle.IsVoid()) {
return;
}
aTrimmed = aTitle;
if (aTitle.Length() > TITLE_LENGTH_MAX) {
aTrimmed = StringHead(aTitle, TITLE_LENGTH_MAX);

View File

@ -230,13 +230,10 @@ const BOOKMARK_VALIDATORS = Object.freeze({
PlacesUtils.bookmarks.TYPE_FOLDER,
PlacesUtils.bookmarks.TYPE_SEPARATOR ].includes(v)),
title: v => {
if (v === null) {
return "";
}
if (typeof(v) == "string") {
return v.slice(0, DB_TITLE_LENGTH_MAX);
}
throw new Error("Invalid title");
simpleValidateFunc(val => val === null || typeof(val) == "string").call(this, v);
if (!v)
return null;
return v.slice(0, DB_TITLE_LENGTH_MAX);
},
url: v => {
simpleValidateFunc(val => (typeof(val) == "string" && val.length <= DB_URL_LENGTH_MAX) ||
@ -1954,8 +1951,8 @@ this.PlacesUtils = {
FROM moz_bookmarks b2
JOIN descendants ON b2.parent = descendants.id AND b2.id <> :tags_folder)
SELECT d.level, d.id, d.guid, d.parent, d.parentGuid, d.type,
d.position AS [index], IFNULL(d.title, "") AS title, d.dateAdded,
d.lastModified, h.url, (SELECT icon_url FROM moz_icons i
d.position AS [index], d.title, d.dateAdded, d.lastModified,
h.url, (SELECT icon_url FROM moz_icons i
JOIN moz_icons_to_pages ON icon_id = i.id
JOIN moz_pages_w_icons pi ON page_id = pi.id
WHERE pi.page_url_hash = hash(h.url) AND pi.page_url = h.url

View File

@ -471,7 +471,8 @@ nsNavBookmarks::InsertBookmarkInDB(int64_t aPlaceId,
rv = stmt->BindInt32ByName(NS_LITERAL_CSTRING("item_index"), aIndex);
NS_ENSURE_SUCCESS(rv, rv);
if (aTitle.IsEmpty())
// Support NULL titles.
if (aTitle.IsVoid())
rv = stmt->BindNullByName(NS_LITERAL_CSTRING("item_title"));
else
rv = stmt->BindUTF8StringByName(NS_LITERAL_CSTRING("item_title"), aTitle);
@ -554,7 +555,10 @@ nsNavBookmarks::InsertBookmarkInDB(int64_t aPlaceId,
BookmarkData bookmark;
bookmark.id = *_itemId;
bookmark.guid.Assign(_guid);
if (!aTitle.IsEmpty()) {
if (aTitle.IsVoid()) {
bookmark.title.SetIsVoid(true);
}
else {
bookmark.title.Assign(aTitle);
}
bookmark.position = aIndex;
@ -933,9 +937,10 @@ nsNavBookmarks::InsertSeparator(int64_t aParent,
}
*aNewItemId = -1;
// Set a NULL title rather than an empty string.
nsAutoCString guid(aGUID);
PRTime dateAdded = RoundedPRNow();
rv = InsertBookmarkInDB(-1, SEPARATOR, aParent, index, EmptyCString(), dateAdded,
rv = InsertBookmarkInDB(-1, SEPARATOR, aParent, index, NullCString(), dateAdded,
0, folderGuid, grandParentId, nullptr, aSource,
aNewItemId, guid);
NS_ENSURE_SUCCESS(rv, rv);
@ -946,7 +951,7 @@ nsNavBookmarks::InsertSeparator(int64_t aParent,
NOTIFY_BOOKMARKS_OBSERVERS(mCanNotify, mCacheObservers, mObservers,
DontSkip,
OnItemAdded(*aNewItemId, aParent, index, TYPE_SEPARATOR,
nullptr, EmptyCString(), dateAdded, guid,
nullptr, NullCString(), dateAdded, guid,
folderGuid, aSource));
return NS_OK;
@ -1527,11 +1532,13 @@ nsNavBookmarks::FetchItemInfo(int64_t aItemId,
_bookmark.id = aItemId;
rv = stmt->GetUTF8String(1, _bookmark.url);
NS_ENSURE_SUCCESS(rv, rv);
bool isNull;
rv = stmt->GetIsNull(2, &isNull);
NS_ENSURE_SUCCESS(rv, rv);
if (!isNull) {
if (isNull) {
_bookmark.title.SetIsVoid(true);
}
else {
rv = stmt->GetUTF8String(2, _bookmark.title);
NS_ENSURE_SUCCESS(rv, rv);
}
@ -1974,7 +1981,7 @@ nsNavBookmarks::SetItemTitle(int64_t aItemId, const nsACString& aTitle,
// transaction for non-tags.
mozStorageTransaction transaction(mDB->MainConn(), false);
rv = SetItemTitleInternal(bookmark, title, syncChangeDelta);
rv = SetItemTitleInternal(bookmark, aTitle, syncChangeDelta);
NS_ENSURE_SUCCESS(rv, rv);
rv = AddSyncChangesForBookmarksInFolder(bookmark.id, syncChangeDelta);
@ -2018,8 +2025,9 @@ nsNavBookmarks::SetItemTitleInternal(BookmarkData& aBookmark,
NS_ENSURE_STATE(statement);
mozStorageStatementScoper scoper(statement);
// Support setting a null title, we support this in insertBookmark.
nsresult rv;
if (aTitle.IsEmpty()) {
if (aTitle.IsVoid()) {
rv = statement->BindNullByName(NS_LITERAL_CSTRING("item_title"));
}
else {

View File

@ -3789,13 +3789,8 @@ nsNavHistory::RowToResult(mozIStorageValueArray* aRow,
// title
nsAutoCString title;
bool isNull;
rv = aRow->GetIsNull(kGetInfoIndex_Title, &isNull);
rv = aRow->GetUTF8String(kGetInfoIndex_Title, title);
NS_ENSURE_SUCCESS(rv, rv);
if (!isNull) {
rv = aRow->GetUTF8String(kGetInfoIndex_Title, title);
NS_ENSURE_SUCCESS(rv, rv);
}
uint32_t accessCount = aRow->AsInt32(kGetInfoIndex_VisitCount);
PRTime time = aRow->AsInt64(kGetInfoIndex_VisitDate);
@ -3970,9 +3965,9 @@ nsNavHistory::QueryRowToResult(int64_t itemId,
resultNode->mBookmarkGuid = aBookmarkGuid;
resultNode->GetAsFolder()->mTargetFolderGuid = targetFolderGuid;
// Use the query item title, unless it's empty (in that case use the
// Use the query item title, unless it's void (in that case use the
// concrete folder title).
if (!aTitle.IsEmpty()) {
if (!aTitle.IsVoid()) {
resultNode->mTitle = aTitle;
}
}

View File

@ -122,7 +122,7 @@ add_task(async function fetch_bookmar_empty_title() {
Assert.deepEqual(bm1, bm2);
Assert.equal(bm2.index, 0);
Assert.strictEqual(bm2.title, "");
Assert.ok(!("title" in bm2));
await PlacesUtils.bookmarks.remove(bm1.guid);
});
@ -158,7 +158,7 @@ add_task(async function fetch_folder_empty_title() {
Assert.deepEqual(bm1, bm2);
Assert.equal(bm2.index, 0);
Assert.strictEqual(bm2.title, "");
Assert.ok(!("title" in bm2));
await PlacesUtils.bookmarks.remove(bm1.guid);
});
@ -177,7 +177,7 @@ add_task(async function fetch_separator() {
Assert.deepEqual(bm2.dateAdded, bm2.lastModified);
Assert.equal(bm2.type, PlacesUtils.bookmarks.TYPE_SEPARATOR);
Assert.ok(!("url" in bm2));
Assert.strictEqual(bm2.title, "");
Assert.ok(!("title" in bm2));
await PlacesUtils.bookmarks.remove(bm1.guid);
});

View File

@ -117,7 +117,7 @@ add_task(async function create_separator() {
Assert.equal(bm.index, 1);
Assert.equal(bm.dateAdded, bm.lastModified);
Assert.equal(bm.type, PlacesUtils.bookmarks.TYPE_SEPARATOR);
Assert.strictEqual(bm.title, "");
Assert.ok(!("title" in bm), "title should not be set");
});
add_task(async function create_separator_w_title_fail() {
@ -149,7 +149,7 @@ add_task(async function create_separator_given_guid() {
Assert.equal(bm.index, 2);
Assert.equal(bm.dateAdded, bm.lastModified);
Assert.equal(bm.type, PlacesUtils.bookmarks.TYPE_SEPARATOR);
Assert.strictEqual(bm.title, "");
Assert.ok(!("title" in bm), "title should not be set");
});
add_task(async function create_item_given_guid_no_type_fail() {
@ -168,7 +168,7 @@ add_task(async function create_separator_big_index() {
Assert.equal(bm.index, 3);
Assert.equal(bm.dateAdded, bm.lastModified);
Assert.equal(bm.type, PlacesUtils.bookmarks.TYPE_SEPARATOR);
Assert.strictEqual(bm.title, "");
Assert.ok(!("title" in bm), "title should not be set");
});
add_task(async function create_separator_given_dateAdded() {
@ -189,7 +189,7 @@ add_task(async function create_folder() {
Assert.equal(bm.parentGuid, PlacesUtils.bookmarks.unfiledGuid);
Assert.equal(bm.dateAdded, bm.lastModified);
Assert.equal(bm.type, PlacesUtils.bookmarks.TYPE_FOLDER);
Assert.strictEqual(bm.title, "");
Assert.ok(!("title" in bm), "title should not be set");
// And then create a nested folder.
let parentGuid = bm.guid;
@ -231,7 +231,7 @@ add_task(async function create_bookmark() {
Assert.equal(bm.index, 1);
Assert.equal(bm.type, PlacesUtils.bookmarks.TYPE_BOOKMARK);
Assert.equal(bm.url.href, "http://example.com/");
Assert.strictEqual(bm.title, "");
Assert.ok(!("title" in bm), "title should not be set");
});
add_task(async function create_bookmark_frecency() {

View File

@ -129,7 +129,7 @@ add_task(async function create_separator() {
Assert.equal(bm.index, 0);
Assert.equal(bm.dateAdded, bm.lastModified);
Assert.equal(bm.type, PlacesUtils.bookmarks.TYPE_SEPARATOR);
Assert.strictEqual(bm.title, "");
Assert.ok(!("title" in bm), "title should not be set");
});
add_task(async function create_plain_bm() {

View File

@ -9,7 +9,7 @@ add_task(async function insert_separator_notification() {
let parentId = await PlacesUtils.promiseItemId(bm.parentGuid);
observer.check([ { name: "onItemAdded",
arguments: [ itemId, parentId, bm.index, bm.type,
null, "", bm.dateAdded * 1000,
null, null, bm.dateAdded * 1000,
bm.guid, bm.parentGuid,
Ci.nsINavBookmarksService.SOURCE_DEFAULT ] }
]);
@ -34,12 +34,11 @@ add_task(async function insert_folder_notitle_notification() {
let observer = expectNotifications();
let bm = await PlacesUtils.bookmarks.insert({ type: PlacesUtils.bookmarks.TYPE_FOLDER,
parentGuid: PlacesUtils.bookmarks.unfiledGuid });
strictEqual(bm.title, "", "Should return empty string for untitled folder");
let itemId = await PlacesUtils.promiseItemId(bm.guid);
let parentId = await PlacesUtils.promiseItemId(bm.parentGuid);
observer.check([ { name: "onItemAdded",
arguments: [ itemId, parentId, bm.index, bm.type,
null, "", bm.dateAdded * 1000,
null, null, bm.dateAdded * 1000,
bm.guid, bm.parentGuid,
Ci.nsINavBookmarksService.SOURCE_DEFAULT ] }
]);
@ -66,12 +65,11 @@ add_task(async function insert_bookmark_notitle_notification() {
let bm = await PlacesUtils.bookmarks.insert({ type: PlacesUtils.bookmarks.TYPE_BOOKMARK,
parentGuid: PlacesUtils.bookmarks.unfiledGuid,
url: new URL("http://example.com/") });
strictEqual(bm.title, "", "Should return empty string for untitled bookmark");
let itemId = await PlacesUtils.promiseItemId(bm.guid);
let parentId = await PlacesUtils.promiseItemId(bm.parentGuid);
observer.check([ { name: "onItemAdded",
arguments: [ itemId, parentId, bm.index, bm.type,
bm.url, "", bm.dateAdded * 1000,
bm.url, null, bm.dateAdded * 1000,
bm.guid, bm.parentGuid,
Ci.nsINavBookmarksService.SOURCE_DEFAULT ] }
]);
@ -96,7 +94,7 @@ add_task(async function insert_bookmark_tag_notification() {
observer.check([ { name: "onItemAdded",
arguments: [ tagId, tagParentId, tag.index, tag.type,
tag.url, "", tag.dateAdded * 1000,
tag.url, null, tag.dateAdded * 1000,
tag.guid, tag.parentGuid,
Ci.nsINavBookmarksService.SOURCE_DEFAULT ] },
{ name: "onItemChanged",
@ -492,54 +490,6 @@ add_task(async function reorder_notification() {
observer.check(expectedNotifications);
});
add_task(async function update_notitle_notification() {
let toolbarBmURI = Services.io.newURI("https://example.com");
let toolbarBmId =
PlacesUtils.bookmarks.insertBookmark(PlacesUtils.toolbarFolderId,
toolbarBmURI, 0, "Bookmark");
let toolbarBmGuid = await PlacesUtils.promiseItemGuid(toolbarBmId);
let menuFolder = await PlacesUtils.bookmarks.insert({
parentGuid: PlacesUtils.bookmarks.menuGuid,
type: PlacesUtils.bookmarks.TYPE_FOLDER,
index: 0,
title: "Folder"
});
let menuFolderId = await PlacesUtils.promiseItemId(menuFolder.guid);
let observer = expectNotifications();
PlacesUtils.bookmarks.setItemTitle(toolbarBmId, null);
strictEqual(PlacesUtils.bookmarks.getItemTitle(toolbarBmId), "",
"Legacy API should return empty string for untitled bookmark");
let updatedMenuBm = await PlacesUtils.bookmarks.update({
guid: menuFolder.guid,
title: null,
});
strictEqual(updatedMenuBm.title, "",
"Async API should return empty string for untitled bookmark");
let toolbarBmModified =
PlacesUtils.toDate(PlacesUtils.bookmarks.getItemLastModified(toolbarBmId));
observer.check([{
name: "onItemChanged",
arguments: [toolbarBmId, "title", false, "", toolbarBmModified * 1000,
PlacesUtils.bookmarks.TYPE_BOOKMARK,
PlacesUtils.toolbarFolderId, toolbarBmGuid,
PlacesUtils.bookmarks.toolbarGuid,
"", PlacesUtils.bookmarks.SOURCES.DEFAULT],
}, {
name: "onItemChanged",
arguments: [menuFolderId, "title", false, "",
updatedMenuBm.lastModified * 1000,
PlacesUtils.bookmarks.TYPE_FOLDER,
PlacesUtils.bookmarksMenuFolderId, menuFolder.guid,
PlacesUtils.bookmarks.menuGuid,
"", PlacesUtils.bookmarks.SOURCES.DEFAULT],
}]);
});
function expectNotifications() {
let notifications = [];
let observer = new Proxy(NavBookmarkObserver, {
@ -555,6 +505,8 @@ function expectNotifications() {
let args = Array.from(origArgs, arg => {
if (arg && arg instanceof Ci.nsIURI)
return new URL(arg.spec);
if (arg && typeof(arg) == "number" && arg >= Date.now() * 1000)
return new Date(parseInt(arg / 1000));
return arg;
});
notifications.push({ name, arguments: args });

View File

@ -165,7 +165,7 @@ add_task(async function remove_bookmark_empty_title() {
Assert.deepEqual(bm1, bm2);
Assert.equal(bm2.index, 0);
Assert.strictEqual(bm2.title, "");
Assert.ok(!("title" in bm2));
});
add_task(async function remove_folder() {
@ -243,7 +243,7 @@ add_task(async function remove_folder_empty_title() {
Assert.deepEqual(bm1, bm2);
Assert.equal(bm2.index, 0);
Assert.strictEqual(bm2.title, "");
Assert.ok(!("title" in bm2));
});
add_task(async function remove_separator() {
@ -260,7 +260,7 @@ add_task(async function remove_separator() {
Assert.deepEqual(bm2.dateAdded, bm2.lastModified);
Assert.equal(bm2.type, PlacesUtils.bookmarks.TYPE_SEPARATOR);
Assert.ok(!("url" in bm2));
Assert.strictEqual(bm2.title, "");
Assert.ok(!("title" in bm2));
});
add_task(async function test_nested_content_fails_when_not_allowed() {

View File

@ -194,10 +194,10 @@ add_task(async function update_lastModified() {
bm = await PlacesUtils.bookmarks.update({ guid: bm.guid,
title: "" });
Assert.strictEqual(bm.title, "");
Assert.ok(!("title" in bm));
bm = await PlacesUtils.bookmarks.fetch(bm.guid);
Assert.strictEqual(bm.title, "");
Assert.ok(!("title" in bm));
});
add_task(async function update_url() {

View File

@ -164,7 +164,7 @@ add_task(async function onItemAdded_separator() {
{ name: "index", check: v => v === 1 },
{ name: "itemType", check: v => v === PlacesUtils.bookmarks.TYPE_SEPARATOR },
{ name: "uri", check: v => v === null },
{ name: "title", check: v => v === "" },
{ name: "title", check: v => v === null },
{ name: "dateAdded", check: v => typeof(v) == "number" && v > 0 },
{ name: "guid", check: v => typeof(v) == "string" && GUID_RE.test(v) },
{ name: "parentGuid", check: v => typeof(v) == "string" && GUID_RE.test(v) },
@ -259,7 +259,7 @@ add_task(async function onItemChanged_tags_bookmark() {
{ name: "index", check: v => v === 0 },
{ name: "itemType", check: v => v === PlacesUtils.bookmarks.TYPE_BOOKMARK },
{ name: "uri", check: v => v instanceof Ci.nsIURI && v.equals(uri) },
{ name: "title", check: v => v === "" },
{ name: "title", check: v => v === null },
{ name: "dateAdded", check: v => typeof(v) == "number" && v > 0 },
{ name: "guid", check: v => typeof(v) == "string" && GUID_RE.test(v) },
{ name: "parentGuid", check: v => typeof(v) == "string" && GUID_RE.test(v) },

View File

@ -20,7 +20,6 @@ var testData = [
// Add a bookmark that should be in the results
{ isBookmark: true,
uri: "http://bookmarked.com/",
title: "",
parentGuid: PlacesUtils.bookmarks.toolbarGuid,
index: PlacesUtils.bookmarks.DEFAULT_INDEX,
isInQuery: true },
@ -28,7 +27,6 @@ var testData = [
// Add a bookmark that should not be in the results
{ isBookmark: true,
uri: "http://bookmarked-elsewhere.com/",
title: "",
parentGuid: PlacesUtils.bookmarks.menuGuid,
index: PlacesUtils.bookmarks.DEFAULT_INDEX,
isInQuery: false },
@ -36,7 +34,6 @@ var testData = [
// Add an un-bookmarked visit
{ isVisit: true,
uri: "http://notbookmarked.com/",
title: "",
isInQuery: false }
];
@ -71,7 +68,6 @@ add_task(async function test_onlyBookmarked() {
// Add a bookmark that should show up
{ isBookmark: true,
uri: "http://bookmarked2.com/",
title: "",
parentGuid: PlacesUtils.bookmarks.toolbarGuid,
index: PlacesUtils.bookmarks.DEFAULT_INDEX,
isInQuery: true },
@ -79,7 +75,6 @@ add_task(async function test_onlyBookmarked() {
// Add a bookmark that should not show up
{ isBookmark: true,
uri: "http://bookmarked-elsewhere2.com/",
title: "",
parentGuid: PlacesUtils.bookmarks.menuGuid,
index: PlacesUtils.bookmarks.DEFAULT_INDEX,
isInQuery: false }

View File

@ -5,8 +5,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/**
* Both SetItemtitle and insertBookmark should default to the empty string
* for null titles.
* Both SetItemtitle and insertBookmark should allow for null titles.
*/
const bs = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
@ -24,8 +23,8 @@ function run_test() {
do_check_eq(bs.getItemTitle(itemId), "");
// Set title to null.
bs.setItemTitle(itemId, null);
// Check returned title defaults to an empty string.
do_check_eq(bs.getItemTitle(itemId), "");
// Check returned title is null.
do_check_eq(bs.getItemTitle(itemId), null);
// Cleanup.
bs.removeItem(itemId);
@ -34,8 +33,8 @@ function run_test() {
uri(TEST_URL),
bs.DEFAULT_INDEX,
null);
// Check returned title defaults to an empty string.
do_check_eq(bs.getItemTitle(itemId), "");
// Check returned title is null.
do_check_eq(bs.getItemTitle(itemId), null);
// Set title to an empty string.
bs.setItemTitle(itemId, "");
// Check returned title is an empty string.