зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1068009 - Implement the async bookmarking API (tests), rs=mano
This commit is contained in:
Родитель
7a99c09c0f
Коммит
0ccc383328
|
@ -28,7 +28,7 @@ const UNEXPECTED_NOTIFICATIONS = [
|
|||
"xpcom-shutdown"
|
||||
];
|
||||
|
||||
const URL = "ftp://localhost/clearHistoryOnShutdown/";
|
||||
const FTP_URL = "ftp://localhost/clearHistoryOnShutdown/";
|
||||
|
||||
// Send the profile-after-change notification to the form history component to ensure
|
||||
// that it has been initialized.
|
||||
|
@ -72,7 +72,7 @@ let notificationsObserver = {
|
|||
}
|
||||
|
||||
// Check cache.
|
||||
checkCache(URL);
|
||||
checkCache(FTP_URL);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -111,7 +111,7 @@ add_task(function test_execute() {
|
|||
transition: PlacesUtils.history.TRANSITION_TYPED})
|
||||
}
|
||||
print("Add cache.");
|
||||
storeCache(URL, "testData");
|
||||
storeCache(FTP_URL, "testData");
|
||||
});
|
||||
|
||||
function run_test_continue()
|
||||
|
|
|
@ -0,0 +1,83 @@
|
|||
/* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
add_task(function* test_eraseEverything() {
|
||||
yield promiseAddVisits({ uri: NetUtil.newURI("http://example.com/") });
|
||||
yield promiseAddVisits({ uri: NetUtil.newURI("http://mozilla.org/") });
|
||||
let frecencyForExample = frecencyForUrl("http://example.com/");
|
||||
let frecencyForMozilla = frecencyForUrl("http://example.com/");
|
||||
Assert.ok(frecencyForExample > 0);
|
||||
Assert.ok(frecencyForMozilla > 0);
|
||||
let unfiledGuid = yield PlacesUtils.promiseItemGuid(PlacesUtils.unfiledBookmarksFolderId);
|
||||
let unfiledFolder = yield PlacesUtils.bookmarks.insert({ parentGuid: unfiledGuid,
|
||||
type: PlacesUtils.bookmarks.TYPE_FOLDER });
|
||||
checkBookmarkObject(unfiledFolder);
|
||||
let unfiledBookmark = yield PlacesUtils.bookmarks.insert({ parentGuid: unfiledGuid,
|
||||
type: PlacesUtils.bookmarks.TYPE_BOOKMARK,
|
||||
url: "http://example.com/",
|
||||
keyword: "kw1" });
|
||||
checkBookmarkObject(unfiledBookmark);
|
||||
let unfiledBookmarkInFolder =
|
||||
yield PlacesUtils.bookmarks.insert({ parentGuid: unfiledFolder.guid,
|
||||
type: PlacesUtils.bookmarks.TYPE_BOOKMARK,
|
||||
url: "http://mozilla.org/" });
|
||||
checkBookmarkObject(unfiledBookmarkInFolder);
|
||||
PlacesUtils.annotations.setItemAnnotation((yield PlacesUtils.promiseItemId(unfiledBookmarkInFolder.guid)),
|
||||
"testanno1", "testvalue1", 0, 0);
|
||||
|
||||
let menuGuid = yield PlacesUtils.promiseItemGuid(PlacesUtils.bookmarksMenuFolderId);
|
||||
let menuFolder = yield PlacesUtils.bookmarks.insert({ parentGuid: menuGuid,
|
||||
type: PlacesUtils.bookmarks.TYPE_FOLDER });
|
||||
checkBookmarkObject(menuFolder);
|
||||
let menuBookmark = yield PlacesUtils.bookmarks.insert({ parentGuid: menuGuid,
|
||||
type: PlacesUtils.bookmarks.TYPE_BOOKMARK,
|
||||
url: "http://example.com/",
|
||||
keyword: "kw2" });
|
||||
checkBookmarkObject(unfiledBookmark);
|
||||
let menuBookmarkInFolder =
|
||||
yield PlacesUtils.bookmarks.insert({ parentGuid: menuFolder.guid,
|
||||
type: PlacesUtils.bookmarks.TYPE_BOOKMARK,
|
||||
url: "http://mozilla.org/" });
|
||||
checkBookmarkObject(menuBookmarkInFolder);
|
||||
PlacesUtils.annotations.setItemAnnotation((yield PlacesUtils.promiseItemId(menuBookmarkInFolder.guid)),
|
||||
"testanno1", "testvalue1", 0, 0);
|
||||
|
||||
let toolbarGuid = yield PlacesUtils.promiseItemGuid(PlacesUtils.toolbarFolderId);
|
||||
let toolbarFolder = yield PlacesUtils.bookmarks.insert({ parentGuid: toolbarGuid,
|
||||
type: PlacesUtils.bookmarks.TYPE_FOLDER });
|
||||
checkBookmarkObject(toolbarFolder);
|
||||
let toolbarBookmark = yield PlacesUtils.bookmarks.insert({ parentGuid: toolbarGuid,
|
||||
type: PlacesUtils.bookmarks.TYPE_BOOKMARK,
|
||||
url: "http://example.com/",
|
||||
keyword: "kw3" });
|
||||
checkBookmarkObject(toolbarBookmark);
|
||||
let toolbarBookmarkInFolder =
|
||||
yield PlacesUtils.bookmarks.insert({ parentGuid: toolbarFolder.guid,
|
||||
type: PlacesUtils.bookmarks.TYPE_BOOKMARK,
|
||||
url: "http://mozilla.org/" });
|
||||
checkBookmarkObject(toolbarBookmarkInFolder);
|
||||
PlacesUtils.annotations.setItemAnnotation((yield PlacesUtils.promiseItemId(toolbarBookmarkInFolder.guid)),
|
||||
"testanno1", "testvalue1", 0, 0);
|
||||
|
||||
yield promiseAsyncUpdates();
|
||||
Assert.ok(frecencyForUrl("http://example.com/") > frecencyForExample);
|
||||
Assert.ok(frecencyForUrl("http://example.com/") > frecencyForMozilla);
|
||||
|
||||
yield PlacesUtils.bookmarks.eraseEverything();
|
||||
|
||||
Assert.equal(frecencyForUrl("http://example.com/"), frecencyForExample);
|
||||
Assert.equal(frecencyForUrl("http://example.com/"), frecencyForMozilla);
|
||||
|
||||
// Check there are no orphan keywords or annotations.
|
||||
let conn = yield PlacesUtils.promiseDBConnection();
|
||||
let rows = yield conn.execute(`SELECT * FROM moz_keywords`);
|
||||
Assert.equal(rows.length, 0);
|
||||
rows = yield conn.execute(`SELECT * FROM moz_items_annos`);
|
||||
Assert.equal(rows.length, 0);
|
||||
rows = yield conn.execute(`SELECT * FROM moz_anno_attributes`);
|
||||
Assert.equal(rows.length, 0);
|
||||
});
|
||||
|
||||
function run_test() {
|
||||
run_next_test();
|
||||
}
|
|
@ -0,0 +1,363 @@
|
|||
/* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
let gAccumulator = {
|
||||
get callback() {
|
||||
this.results = [];
|
||||
return result => this.results.push(result);
|
||||
}
|
||||
};
|
||||
|
||||
add_task(function* invalid_input_throws() {
|
||||
Assert.throws(() => PlacesUtils.bookmarks.fetch(),
|
||||
/Input should be a valid object/);
|
||||
Assert.throws(() => PlacesUtils.bookmarks.fetch(null),
|
||||
/Input should be a valid object/);
|
||||
|
||||
Assert.throws(() => PlacesUtils.bookmarks.fetch({ guid: "123456789012",
|
||||
parentGuid: "012345678901" }),
|
||||
/The following properties were expected: index/);
|
||||
Assert.throws(() => PlacesUtils.bookmarks.fetch({ guid: "123456789012",
|
||||
index: 0 }),
|
||||
/The following properties were expected: parentGuid/);
|
||||
|
||||
Assert.throws(() => PlacesUtils.bookmarks.fetch({}),
|
||||
/Unexpected number of conditions provided: 0/);
|
||||
Assert.throws(() => PlacesUtils.bookmarks.fetch({ guid: "123456789012",
|
||||
parentGuid: "012345678901",
|
||||
index: 0 }),
|
||||
/Unexpected number of conditions provided: 2/);
|
||||
Assert.throws(() => PlacesUtils.bookmarks.fetch({ guid: "123456789012",
|
||||
url: "http://example.com"}),
|
||||
/Unexpected number of conditions provided: 2/);
|
||||
|
||||
Assert.throws(() => PlacesUtils.bookmarks.fetch({ keyword: "test",
|
||||
url: "http://example.com"}),
|
||||
/Unexpected number of conditions provided: 2/);
|
||||
|
||||
Assert.throws(() => PlacesUtils.bookmarks.fetch("test"),
|
||||
/Invalid value for property 'guid'/);
|
||||
Assert.throws(() => PlacesUtils.bookmarks.fetch(123),
|
||||
/Invalid value for property 'guid'/);
|
||||
|
||||
Assert.throws(() => PlacesUtils.bookmarks.fetch({ guid: "test" }),
|
||||
/Invalid value for property 'guid'/);
|
||||
Assert.throws(() => PlacesUtils.bookmarks.fetch({ guid: null }),
|
||||
/Invalid value for property 'guid'/);
|
||||
Assert.throws(() => PlacesUtils.bookmarks.fetch({ guid: 123 }),
|
||||
/Invalid value for property 'guid'/);
|
||||
|
||||
Assert.throws(() => PlacesUtils.bookmarks.fetch({ parentGuid: "test",
|
||||
index: 0 }),
|
||||
/Invalid value for property 'parentGuid'/);
|
||||
Assert.throws(() => PlacesUtils.bookmarks.fetch({ parentGuid: null,
|
||||
index: 0 }),
|
||||
/Invalid value for property 'parentGuid'/);
|
||||
Assert.throws(() => PlacesUtils.bookmarks.fetch({ parentGuid: 123,
|
||||
index: 0 }),
|
||||
/Invalid value for property 'parentGuid'/);
|
||||
|
||||
Assert.throws(() => PlacesUtils.bookmarks.fetch({ parentGuid: "123456789012",
|
||||
index: "0" }),
|
||||
/Invalid value for property 'index'/);
|
||||
Assert.throws(() => PlacesUtils.bookmarks.fetch({ parentGuid: "123456789012",
|
||||
index: null }),
|
||||
/Invalid value for property 'index'/);
|
||||
Assert.throws(() => PlacesUtils.bookmarks.fetch({ parentGuid: "123456789012",
|
||||
index: -10 }),
|
||||
/Invalid value for property 'index'/);
|
||||
Assert.throws(() => PlacesUtils.bookmarks.fetch({ parentGuid: "123456789012",
|
||||
index: -1 }),
|
||||
/Invalid value for property 'index'/);
|
||||
|
||||
Assert.throws(() => PlacesUtils.bookmarks.fetch({ url: "http://te st/" }),
|
||||
/Invalid value for property 'url'/);
|
||||
Assert.throws(() => PlacesUtils.bookmarks.fetch({ url: null }),
|
||||
/Invalid value for property 'url'/);
|
||||
Assert.throws(() => PlacesUtils.bookmarks.fetch({ url: -10 }),
|
||||
/Invalid value for property 'url'/);
|
||||
|
||||
Assert.throws(() => PlacesUtils.bookmarks.fetch({ keyword: "te st" }),
|
||||
/Invalid value for property 'keyword'/);
|
||||
Assert.throws(() => PlacesUtils.bookmarks.fetch({ keyword: null }),
|
||||
/Invalid value for property 'keyword'/);
|
||||
Assert.throws(() => PlacesUtils.bookmarks.fetch({ keyword: "" }),
|
||||
/Invalid value for property 'keyword'/);
|
||||
Assert.throws(() => PlacesUtils.bookmarks.fetch({ keyword: 5 }),
|
||||
/Invalid value for property 'keyword'/);
|
||||
|
||||
Assert.throws(() => PlacesUtils.bookmarks.fetch("123456789012", "test"),
|
||||
/onResult callback must be a valid function/);
|
||||
Assert.throws(() => PlacesUtils.bookmarks.fetch("123456789012", {}),
|
||||
/onResult callback must be a valid function/);
|
||||
});
|
||||
|
||||
add_task(function* fetch_nonexistent_guid() {
|
||||
let bm = yield PlacesUtils.bookmarks.fetch({ guid: "123456789012" },
|
||||
gAccumulator.callback);
|
||||
Assert.equal(bm, null);
|
||||
Assert.equal(gAccumulator.results.length, 0);
|
||||
});
|
||||
|
||||
add_task(function* fetch_bookmark() {
|
||||
let unfiledGuid = yield PlacesUtils.promiseItemGuid(PlacesUtils.unfiledBookmarksFolderId);
|
||||
let bm1 = yield PlacesUtils.bookmarks.insert({ parentGuid: unfiledGuid,
|
||||
type: PlacesUtils.bookmarks.TYPE_BOOKMARK,
|
||||
url: "http://example.com/",
|
||||
title: "a bookmark" });
|
||||
checkBookmarkObject(bm1);
|
||||
|
||||
let bm2 = yield PlacesUtils.bookmarks.fetch(bm1.guid,
|
||||
gAccumulator.callback);
|
||||
checkBookmarkObject(bm2);
|
||||
Assert.equal(gAccumulator.results.length, 1);
|
||||
checkBookmarkObject(gAccumulator.results[0]);
|
||||
Assert.deepEqual(gAccumulator.results[0], bm1);
|
||||
|
||||
Assert.deepEqual(bm1, bm2);
|
||||
Assert.equal(bm2.parentGuid, unfiledGuid);
|
||||
Assert.equal(bm2.index, 0);
|
||||
Assert.deepEqual(bm2.dateAdded, bm2.lastModified);
|
||||
Assert.equal(bm2.type, PlacesUtils.bookmarks.TYPE_BOOKMARK);
|
||||
Assert.equal(bm2.url.href, "http://example.com/");
|
||||
Assert.equal(bm2.title, "a bookmark");
|
||||
Assert.ok(!("keyword" in bm2));
|
||||
|
||||
yield PlacesUtils.bookmarks.remove(bm1.guid);
|
||||
});
|
||||
|
||||
add_task(function* fetch_bookmar_empty_title() {
|
||||
let unfiledGuid = yield PlacesUtils.promiseItemGuid(PlacesUtils.unfiledBookmarksFolderId);
|
||||
let bm1 = yield PlacesUtils.bookmarks.insert({ parentGuid: unfiledGuid,
|
||||
type: PlacesUtils.bookmarks.TYPE_BOOKMARK,
|
||||
url: "http://example.com/",
|
||||
title: "" });
|
||||
checkBookmarkObject(bm1);
|
||||
|
||||
let bm2 = yield PlacesUtils.bookmarks.fetch(bm1.guid);
|
||||
checkBookmarkObject(bm2);
|
||||
|
||||
Assert.deepEqual(bm1, bm2);
|
||||
Assert.equal(bm2.index, 0);
|
||||
Assert.ok(!("title" in bm2));
|
||||
Assert.ok(!("keyword" in bm2));
|
||||
|
||||
yield PlacesUtils.bookmarks.remove(bm1.guid);
|
||||
});
|
||||
|
||||
add_task(function* fetch_folder() {
|
||||
let unfiledGuid = yield PlacesUtils.promiseItemGuid(PlacesUtils.unfiledBookmarksFolderId);
|
||||
let bm1 = yield PlacesUtils.bookmarks.insert({ parentGuid: unfiledGuid,
|
||||
type: PlacesUtils.bookmarks.TYPE_FOLDER,
|
||||
title: "a folder" });
|
||||
checkBookmarkObject(bm1);
|
||||
|
||||
let bm2 = yield PlacesUtils.bookmarks.fetch(bm1.guid);
|
||||
checkBookmarkObject(bm2);
|
||||
|
||||
Assert.deepEqual(bm1, bm2);
|
||||
Assert.equal(bm2.parentGuid, unfiledGuid);
|
||||
Assert.equal(bm2.index, 0);
|
||||
Assert.deepEqual(bm2.dateAdded, bm2.lastModified);
|
||||
Assert.equal(bm2.type, PlacesUtils.bookmarks.TYPE_FOLDER);
|
||||
Assert.equal(bm2.title, "a folder");
|
||||
Assert.ok(!("url" in bm2));
|
||||
Assert.ok(!("keyword" in bm2));
|
||||
|
||||
yield PlacesUtils.bookmarks.remove(bm1.guid);
|
||||
});
|
||||
|
||||
add_task(function* fetch_folder_empty_title() {
|
||||
let unfiledGuid = yield PlacesUtils.promiseItemGuid(PlacesUtils.unfiledBookmarksFolderId);
|
||||
let bm1 = yield PlacesUtils.bookmarks.insert({ parentGuid: unfiledGuid,
|
||||
type: PlacesUtils.bookmarks.TYPE_FOLDER,
|
||||
title: "" });
|
||||
checkBookmarkObject(bm1);
|
||||
|
||||
let bm2 = yield PlacesUtils.bookmarks.fetch(bm1.guid);
|
||||
checkBookmarkObject(bm2);
|
||||
|
||||
Assert.deepEqual(bm1, bm2);
|
||||
Assert.equal(bm2.index, 0);
|
||||
Assert.ok(!("title" in bm2));
|
||||
|
||||
yield PlacesUtils.bookmarks.remove(bm1.guid);
|
||||
});
|
||||
|
||||
add_task(function* fetch_separator() {
|
||||
|
||||
let unfiledGuid = yield PlacesUtils.promiseItemGuid(PlacesUtils.unfiledBookmarksFolderId);
|
||||
let bm1 = yield PlacesUtils.bookmarks.insert({ parentGuid: unfiledGuid,
|
||||
type: PlacesUtils.bookmarks.TYPE_SEPARATOR });
|
||||
checkBookmarkObject(bm1);
|
||||
|
||||
let bm2 = yield PlacesUtils.bookmarks.fetch(bm1.guid);
|
||||
checkBookmarkObject(bm2);
|
||||
|
||||
Assert.deepEqual(bm1, bm2);
|
||||
Assert.equal(bm2.parentGuid, unfiledGuid);
|
||||
Assert.equal(bm2.index, 0);
|
||||
Assert.deepEqual(bm2.dateAdded, bm2.lastModified);
|
||||
Assert.equal(bm2.type, PlacesUtils.bookmarks.TYPE_SEPARATOR);
|
||||
Assert.ok(!("url" in bm2));
|
||||
Assert.ok(!("title" in bm2));
|
||||
Assert.ok(!("keyword" in bm2));
|
||||
|
||||
yield PlacesUtils.bookmarks.remove(bm1.guid);
|
||||
});
|
||||
|
||||
add_task(function* fetch_byposition_nonexisting_parentGuid() {
|
||||
let bm = yield PlacesUtils.bookmarks.fetch({ parentGuid: "123456789012",
|
||||
index: 0 },
|
||||
gAccumulator.callback);
|
||||
Assert.equal(bm, null);
|
||||
Assert.equal(gAccumulator.results.length, 0);
|
||||
});
|
||||
|
||||
add_task(function* fetch_byposition_nonexisting_index() {
|
||||
let unfiledGuid = yield PlacesUtils.promiseItemGuid(PlacesUtils.unfiledBookmarksFolderId);
|
||||
let bm = yield PlacesUtils.bookmarks.fetch({ parentGuid: unfiledGuid,
|
||||
index: 100 },
|
||||
gAccumulator.callback);
|
||||
Assert.equal(bm, null);
|
||||
Assert.equal(gAccumulator.results.length, 0);
|
||||
});
|
||||
|
||||
add_task(function* fetch_byposition() {
|
||||
let unfiledGuid = yield PlacesUtils.promiseItemGuid(PlacesUtils.unfiledBookmarksFolderId);
|
||||
let bm1 = yield PlacesUtils.bookmarks.insert({ parentGuid: unfiledGuid,
|
||||
type: PlacesUtils.bookmarks.TYPE_BOOKMARK,
|
||||
url: "http://example.com/",
|
||||
title: "a bookmark" });
|
||||
checkBookmarkObject(bm1);
|
||||
|
||||
let bm2 = yield PlacesUtils.bookmarks.fetch({ parentGuid: bm1.parentGuid,
|
||||
index: bm1.index },
|
||||
gAccumulator.callback);
|
||||
checkBookmarkObject(bm2);
|
||||
Assert.equal(gAccumulator.results.length, 1);
|
||||
checkBookmarkObject(gAccumulator.results[0]);
|
||||
Assert.deepEqual(gAccumulator.results[0], bm1);
|
||||
|
||||
Assert.deepEqual(bm1, bm2);
|
||||
Assert.equal(bm2.parentGuid, unfiledGuid);
|
||||
Assert.equal(bm2.index, 0);
|
||||
Assert.deepEqual(bm2.dateAdded, bm2.lastModified);
|
||||
Assert.equal(bm2.type, PlacesUtils.bookmarks.TYPE_BOOKMARK);
|
||||
Assert.equal(bm2.url.href, "http://example.com/");
|
||||
Assert.equal(bm2.title, "a bookmark");
|
||||
Assert.ok(!("keyword" in bm2));
|
||||
});
|
||||
|
||||
add_task(function* fetch_byurl_nonexisting() {
|
||||
let bm = yield PlacesUtils.bookmarks.fetch({ url: "http://nonexisting.com/" },
|
||||
gAccumulator.callback);
|
||||
Assert.equal(bm, null);
|
||||
Assert.equal(gAccumulator.results.length, 0);
|
||||
});
|
||||
|
||||
add_task(function* fetch_byurl() {
|
||||
let unfiledGuid = yield PlacesUtils.promiseItemGuid(PlacesUtils.unfiledBookmarksFolderId);
|
||||
let bm1 = yield PlacesUtils.bookmarks.insert({ parentGuid: unfiledGuid,
|
||||
type: PlacesUtils.bookmarks.TYPE_BOOKMARK,
|
||||
url: "http://byurl.com/",
|
||||
title: "a bookmark" });
|
||||
checkBookmarkObject(bm1);
|
||||
|
||||
let bm2 = yield PlacesUtils.bookmarks.fetch({ url: bm1.url },
|
||||
gAccumulator.callback);
|
||||
checkBookmarkObject(bm2);
|
||||
Assert.equal(gAccumulator.results.length, 1);
|
||||
checkBookmarkObject(gAccumulator.results[0]);
|
||||
Assert.deepEqual(gAccumulator.results[0], bm1);
|
||||
|
||||
Assert.deepEqual(bm1, bm2);
|
||||
Assert.equal(bm2.parentGuid, unfiledGuid);
|
||||
Assert.deepEqual(bm2.dateAdded, bm2.lastModified);
|
||||
Assert.equal(bm2.type, PlacesUtils.bookmarks.TYPE_BOOKMARK);
|
||||
Assert.equal(bm2.url.href, "http://byurl.com/");
|
||||
Assert.equal(bm2.title, "a bookmark");
|
||||
Assert.ok(!("keyword" in bm2));
|
||||
|
||||
let bm3 = yield PlacesUtils.bookmarks.insert({ parentGuid: unfiledGuid,
|
||||
type: PlacesUtils.bookmarks.TYPE_BOOKMARK,
|
||||
url: "http://byurl.com/",
|
||||
title: "a bookmark" });
|
||||
let bm4 = yield PlacesUtils.bookmarks.fetch({ url: bm1.url },
|
||||
gAccumulator.callback);
|
||||
checkBookmarkObject(bm4);
|
||||
Assert.deepEqual(bm3, bm4);
|
||||
Assert.equal(gAccumulator.results.length, 2);
|
||||
gAccumulator.results.forEach(checkBookmarkObject);
|
||||
Assert.deepEqual(gAccumulator.results[0], bm4);
|
||||
|
||||
// After an update the returned bookmark should change.
|
||||
yield PlacesUtils.bookmarks.update({ guid: bm1.guid, title: "new title" });
|
||||
let bm5 = yield PlacesUtils.bookmarks.fetch({ url: bm1.url },
|
||||
gAccumulator.callback);
|
||||
checkBookmarkObject(bm5);
|
||||
// Cannot use deepEqual cause lastModified changed.
|
||||
Assert.equal(bm1.guid, bm5.guid);
|
||||
Assert.ok(bm5.lastModified > bm1.lastModified);
|
||||
Assert.equal(gAccumulator.results.length, 2);
|
||||
gAccumulator.results.forEach(checkBookmarkObject);
|
||||
Assert.deepEqual(gAccumulator.results[0], bm5);
|
||||
});
|
||||
|
||||
add_task(function* fetch_bykeyword_nonexisting() {
|
||||
let bm = yield PlacesUtils.bookmarks.fetch({ keyword: "nonexisting" },
|
||||
gAccumulator.callback);
|
||||
Assert.equal(bm, null);
|
||||
Assert.equal(gAccumulator.results.length, 0);
|
||||
});
|
||||
|
||||
add_task(function* fetch_bykeyword() {
|
||||
let unfiledGuid = yield PlacesUtils.promiseItemGuid(PlacesUtils.unfiledBookmarksFolderId);
|
||||
let bm1 = yield PlacesUtils.bookmarks.insert({ parentGuid: unfiledGuid,
|
||||
type: PlacesUtils.bookmarks.TYPE_BOOKMARK,
|
||||
url: "http://bykeyword1.com/",
|
||||
keyword: "bykeyword" });
|
||||
checkBookmarkObject(bm1);
|
||||
|
||||
let bm2 = yield PlacesUtils.bookmarks.fetch({ keyword: "bykeyword" },
|
||||
gAccumulator.callback);
|
||||
checkBookmarkObject(bm2);
|
||||
Assert.equal(gAccumulator.results.length, 1);
|
||||
checkBookmarkObject(gAccumulator.results[0]);
|
||||
Assert.deepEqual(gAccumulator.results[0], bm1);
|
||||
|
||||
Assert.deepEqual(bm1, bm2);
|
||||
Assert.equal(bm2.parentGuid, unfiledGuid);
|
||||
Assert.deepEqual(bm2.dateAdded, bm2.lastModified);
|
||||
Assert.equal(bm2.type, PlacesUtils.bookmarks.TYPE_BOOKMARK);
|
||||
Assert.equal(bm2.url.href, "http://bykeyword1.com/");
|
||||
Assert.equal(bm2.keyword, "bykeyword");
|
||||
|
||||
let bm3 = yield PlacesUtils.bookmarks.insert({ parentGuid: unfiledGuid,
|
||||
type: PlacesUtils.bookmarks.TYPE_BOOKMARK,
|
||||
url: "http://bykeyword2.com/",
|
||||
keyword: "bykeyword" });
|
||||
let bm4 = yield PlacesUtils.bookmarks.fetch({ keyword: "bykeyword" },
|
||||
gAccumulator.callback);
|
||||
checkBookmarkObject(bm4);
|
||||
Assert.deepEqual(bm3, bm4);
|
||||
Assert.equal(gAccumulator.results.length, 2);
|
||||
gAccumulator.results.forEach(checkBookmarkObject);
|
||||
Assert.deepEqual(gAccumulator.results[0], bm4);
|
||||
|
||||
// After an update the returned bookmark should change.
|
||||
yield PlacesUtils.bookmarks.update({ guid: bm1.guid, title: "new title" });
|
||||
let bm5 = yield PlacesUtils.bookmarks.fetch({ keyword: "bykeyword" },
|
||||
gAccumulator.callback);
|
||||
checkBookmarkObject(bm5);
|
||||
// Cannot use deepEqual cause lastModified changed.
|
||||
Assert.equal(bm1.guid, bm5.guid);
|
||||
Assert.ok(bm5.lastModified > bm1.lastModified);
|
||||
Assert.equal(gAccumulator.results.length, 2);
|
||||
gAccumulator.results.forEach(checkBookmarkObject);
|
||||
Assert.deepEqual(gAccumulator.results[0], bm5);
|
||||
});
|
||||
|
||||
function run_test() {
|
||||
run_next_test();
|
||||
}
|
|
@ -0,0 +1,294 @@
|
|||
/* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
add_task(function* invalid_input_throws() {
|
||||
Assert.throws(() => PlacesUtils.bookmarks.insert(),
|
||||
/Input should be a valid object/);
|
||||
Assert.throws(() => PlacesUtils.bookmarks.insert(null),
|
||||
/Input should be a valid object/);
|
||||
Assert.throws(() => PlacesUtils.bookmarks.insert({}),
|
||||
/The following properties were expected/);
|
||||
|
||||
Assert.throws(() => PlacesUtils.bookmarks.insert({ guid: "test" }),
|
||||
/Invalid value for property 'guid'/);
|
||||
Assert.throws(() => PlacesUtils.bookmarks.insert({ guid: null }),
|
||||
/Invalid value for property 'guid'/);
|
||||
Assert.throws(() => PlacesUtils.bookmarks.insert({ guid: 123 }),
|
||||
/Invalid value for property 'guid'/);
|
||||
|
||||
Assert.throws(() => PlacesUtils.bookmarks.insert({ parentGuid: "test" }),
|
||||
/Invalid value for property 'parentGuid'/);
|
||||
Assert.throws(() => PlacesUtils.bookmarks.insert({ parentGuid: null }),
|
||||
/Invalid value for property 'parentGuid'/);
|
||||
Assert.throws(() => PlacesUtils.bookmarks.insert({ parentGuid: 123 }),
|
||||
/Invalid value for property 'parentGuid'/);
|
||||
|
||||
Assert.throws(() => PlacesUtils.bookmarks.insert({ index: "1" }),
|
||||
/Invalid value for property 'index'/);
|
||||
Assert.throws(() => PlacesUtils.bookmarks.insert({ index: -10 }),
|
||||
/Invalid value for property 'index'/);
|
||||
|
||||
Assert.throws(() => PlacesUtils.bookmarks.insert({ dateAdded: -10 }),
|
||||
/Invalid value for property 'dateAdded'/);
|
||||
Assert.throws(() => PlacesUtils.bookmarks.insert({ dateAdded: "today" }),
|
||||
/Invalid value for property 'dateAdded'/);
|
||||
Assert.throws(() => PlacesUtils.bookmarks.insert({ dateAdded: Date.now() }),
|
||||
/Invalid value for property 'dateAdded'/);
|
||||
|
||||
Assert.throws(() => PlacesUtils.bookmarks.insert({ lastModified: -10 }),
|
||||
/Invalid value for property 'lastModified'/);
|
||||
Assert.throws(() => PlacesUtils.bookmarks.insert({ lastModified: "today" }),
|
||||
/Invalid value for property 'lastModified'/);
|
||||
Assert.throws(() => PlacesUtils.bookmarks.insert({ lastModified: Date.now() }),
|
||||
/Invalid value for property 'lastModified'/);
|
||||
let time = new Date();
|
||||
let future = new Date(time + 86400000);
|
||||
Assert.throws(() => PlacesUtils.bookmarks.insert({ dateAdded: future,
|
||||
lastModified: time }),
|
||||
/Invalid value for property 'dateAdded'/);
|
||||
let past = new Date(time - 86400000);
|
||||
Assert.throws(() => PlacesUtils.bookmarks.insert({ lastModified: past }),
|
||||
/Invalid value for property 'lastModified'/);
|
||||
|
||||
Assert.throws(() => PlacesUtils.bookmarks.insert({ type: -1 }),
|
||||
/Invalid value for property 'type'/);
|
||||
Assert.throws(() => PlacesUtils.bookmarks.insert({ type: 100 }),
|
||||
/Invalid value for property 'type'/);
|
||||
Assert.throws(() => PlacesUtils.bookmarks.insert({ type: "bookmark" }),
|
||||
/Invalid value for property 'type'/);
|
||||
|
||||
Assert.throws(() => PlacesUtils.bookmarks.insert({ type: PlacesUtils.bookmarks.TYPE_BOOKMARK,
|
||||
title: -1 }),
|
||||
/Invalid value for property 'title'/);
|
||||
|
||||
Assert.throws(() => PlacesUtils.bookmarks.insert({ type: PlacesUtils.bookmarks.TYPE_BOOKMARK,
|
||||
url: 10 }),
|
||||
/Invalid value for property 'url'/);
|
||||
Assert.throws(() => PlacesUtils.bookmarks.insert({ type: PlacesUtils.bookmarks.TYPE_BOOKMARK,
|
||||
url: "http://te st" }),
|
||||
/Invalid value for property 'url'/);
|
||||
let longurl = "http://www.example.com/";
|
||||
for (let i = 0; i < 65536; i++) {
|
||||
longurl += "a";
|
||||
}
|
||||
Assert.throws(() => PlacesUtils.bookmarks.insert({ type: PlacesUtils.bookmarks.TYPE_BOOKMARK,
|
||||
url: longurl }),
|
||||
/Invalid value for property 'url'/);
|
||||
Assert.throws(() => PlacesUtils.bookmarks.insert({ type: PlacesUtils.bookmarks.TYPE_BOOKMARK,
|
||||
url: NetUtil.newURI(longurl) }),
|
||||
/Invalid value for property 'url'/);
|
||||
Assert.throws(() => PlacesUtils.bookmarks.insert({ type: PlacesUtils.bookmarks.TYPE_BOOKMARK,
|
||||
url: "te st" }),
|
||||
/Invalid value for property 'url'/);
|
||||
|
||||
Assert.throws(() => PlacesUtils.bookmarks.insert({ type: PlacesUtils.bookmarks.TYPE_BOOKMARK,
|
||||
keyword: 10 }),
|
||||
/Invalid value for property 'keyword'/);
|
||||
Assert.throws(() => PlacesUtils.bookmarks.insert({ type: PlacesUtils.bookmarks.TYPE_BOOKMARK,
|
||||
keyword: null }),
|
||||
/Invalid value for property 'keyword'/);
|
||||
Assert.throws(() => PlacesUtils.bookmarks.insert({ type: PlacesUtils.bookmarks.TYPE_BOOKMARK,
|
||||
keyword: "" }),
|
||||
/Invalid value for property 'keyword'/);
|
||||
});
|
||||
|
||||
add_task(function* invalid_properties_for_bookmark_type() {
|
||||
Assert.throws(() => PlacesUtils.bookmarks.insert({ type: PlacesUtils.bookmarks.TYPE_FOLDER,
|
||||
url: "http://www.moz.com/" }),
|
||||
/Invalid value for property 'url'/);
|
||||
Assert.throws(() => PlacesUtils.bookmarks.insert({ type: PlacesUtils.bookmarks.TYPE_SEPARATOR,
|
||||
url: "http://www.moz.com/" }),
|
||||
/Invalid value for property 'url'/);
|
||||
Assert.throws(() => PlacesUtils.bookmarks.insert({ type: PlacesUtils.bookmarks.TYPE_SEPARATOR,
|
||||
title: "test" }),
|
||||
/Invalid value for property 'title'/);
|
||||
Assert.throws(() => PlacesUtils.bookmarks.insert({ type: PlacesUtils.bookmarks.TYPE_SEPARATOR,
|
||||
keyword: "test" }),
|
||||
/Invalid value for property 'keyword'/);
|
||||
Assert.throws(() => PlacesUtils.bookmarks.insert({ type: PlacesUtils.bookmarks.TYPE_FOLDER,
|
||||
keyword: "test" }),
|
||||
/Invalid value for property 'keyword'/);
|
||||
});
|
||||
|
||||
add_task(function* long_title_trim() {
|
||||
let longtitle = "a";
|
||||
for (let i = 0; i < 4096; i++) {
|
||||
longtitle += "a";
|
||||
}
|
||||
let unfiledGuid = yield PlacesUtils.promiseItemGuid(PlacesUtils.unfiledBookmarksFolderId);
|
||||
let bm = yield PlacesUtils.bookmarks.insert({ parentGuid: unfiledGuid,
|
||||
type: PlacesUtils.bookmarks.TYPE_FOLDER,
|
||||
title: longtitle });
|
||||
checkBookmarkObject(bm);
|
||||
Assert.equal(bm.parentGuid, unfiledGuid);
|
||||
Assert.equal(bm.index, 0);
|
||||
Assert.equal(bm.dateAdded, bm.lastModified);
|
||||
Assert.equal(bm.type, PlacesUtils.bookmarks.TYPE_FOLDER);
|
||||
Assert.equal(bm.title.length, 4096, "title should have been trimmed");
|
||||
Assert.ok(!("url" in bm), "url should not be set");
|
||||
Assert.ok(!("keyword" in bm), "keyword should not be set");
|
||||
});
|
||||
|
||||
add_task(function* create_separator() {
|
||||
let unfiledGuid = yield PlacesUtils.promiseItemGuid(PlacesUtils.unfiledBookmarksFolderId);
|
||||
let bm = yield PlacesUtils.bookmarks.insert({ parentGuid: unfiledGuid,
|
||||
type: PlacesUtils.bookmarks.TYPE_SEPARATOR,
|
||||
index: PlacesUtils.bookmarks.DEFAULT_INDEX });
|
||||
checkBookmarkObject(bm);
|
||||
Assert.equal(bm.parentGuid, unfiledGuid);
|
||||
Assert.equal(bm.index, 1);
|
||||
Assert.equal(bm.dateAdded, bm.lastModified);
|
||||
Assert.equal(bm.type, PlacesUtils.bookmarks.TYPE_SEPARATOR);
|
||||
Assert.ok(!("title" in bm), "title should not be set");
|
||||
});
|
||||
|
||||
add_task(function* create_separator_w_title_fail() {
|
||||
let unfiledGuid = yield PlacesUtils.promiseItemGuid(PlacesUtils.unfiledBookmarksFolderId);
|
||||
try {
|
||||
yield PlacesUtils.bookmarks.insert({ parentGuid: unfiledGuid,
|
||||
type: PlacesUtils.bookmarks.TYPE_SEPARATOR,
|
||||
title: "a separator" });
|
||||
Assert.ok(false, "Trying to set title for a separator should reject");
|
||||
} catch (ex) {}
|
||||
});
|
||||
|
||||
add_task(function* create_separator_invalid_parent_fail() {
|
||||
try {
|
||||
yield PlacesUtils.bookmarks.insert({ parentGuid: "123456789012",
|
||||
type: PlacesUtils.bookmarks.TYPE_SEPARATOR,
|
||||
title: "a separator" });
|
||||
Assert.ok(false, "Trying to create an item in a non existing parent reject");
|
||||
} catch (ex) {}
|
||||
});
|
||||
|
||||
add_task(function* create_separator_given_guid() {
|
||||
let unfiledGuid = yield PlacesUtils.promiseItemGuid(PlacesUtils.unfiledBookmarksFolderId);
|
||||
let bm = yield PlacesUtils.bookmarks.insert({ parentGuid: unfiledGuid,
|
||||
type: PlacesUtils.bookmarks.TYPE_SEPARATOR,
|
||||
index: PlacesUtils.bookmarks.DEFAULT_INDEX,
|
||||
guid: "123456789012" });
|
||||
checkBookmarkObject(bm);
|
||||
Assert.equal(bm.guid, "123456789012");
|
||||
Assert.equal(bm.parentGuid, unfiledGuid);
|
||||
Assert.equal(bm.index, 2);
|
||||
Assert.equal(bm.dateAdded, bm.lastModified);
|
||||
Assert.equal(bm.type, PlacesUtils.bookmarks.TYPE_SEPARATOR);
|
||||
Assert.ok(!("title" in bm), "title should not be set");
|
||||
});
|
||||
|
||||
add_task(function* create_item_given_guid_no_type_fail() {
|
||||
try {
|
||||
yield PlacesUtils.bookmarks.insert({ parentGuid: "123456789012" });
|
||||
Assert.ok(false, "Trying to create an item with a given guid but no type should reject");
|
||||
} catch (ex) {}
|
||||
});
|
||||
|
||||
add_task(function* create_separator_big_index() {
|
||||
let unfiledGuid = yield PlacesUtils.promiseItemGuid(PlacesUtils.unfiledBookmarksFolderId);
|
||||
let bm = yield PlacesUtils.bookmarks.insert({ parentGuid: unfiledGuid,
|
||||
type: PlacesUtils.bookmarks.TYPE_SEPARATOR,
|
||||
index: 9999 });
|
||||
checkBookmarkObject(bm);
|
||||
Assert.equal(bm.parentGuid, unfiledGuid);
|
||||
Assert.equal(bm.index, 3);
|
||||
Assert.equal(bm.dateAdded, bm.lastModified);
|
||||
Assert.equal(bm.type, PlacesUtils.bookmarks.TYPE_SEPARATOR);
|
||||
Assert.ok(!("title" in bm), "title should not be set");
|
||||
});
|
||||
|
||||
add_task(function* create_separator_given_dateAdded() {
|
||||
let time = new Date();
|
||||
let past = new Date(time - 86400000);
|
||||
let unfiledGuid = yield PlacesUtils.promiseItemGuid(PlacesUtils.unfiledBookmarksFolderId);
|
||||
let bm = yield PlacesUtils.bookmarks.insert({ parentGuid: unfiledGuid,
|
||||
type: PlacesUtils.bookmarks.TYPE_SEPARATOR,
|
||||
dateAdded: past });
|
||||
checkBookmarkObject(bm);
|
||||
Assert.equal(bm.dateAdded, past);
|
||||
Assert.equal(bm.lastModified, past);
|
||||
});
|
||||
|
||||
add_task(function* create_folder() {
|
||||
let unfiledGuid = yield PlacesUtils.promiseItemGuid(PlacesUtils.unfiledBookmarksFolderId);
|
||||
let bm = yield PlacesUtils.bookmarks.insert({ parentGuid: unfiledGuid,
|
||||
type: PlacesUtils.bookmarks.TYPE_FOLDER });
|
||||
checkBookmarkObject(bm);
|
||||
Assert.equal(bm.parentGuid, unfiledGuid);
|
||||
Assert.equal(bm.dateAdded, bm.lastModified);
|
||||
Assert.equal(bm.type, PlacesUtils.bookmarks.TYPE_FOLDER);
|
||||
Assert.ok(!("title" in bm), "title should not be set");
|
||||
|
||||
// And then create a nested folder.
|
||||
let parentGuid = bm.guid;
|
||||
bm = yield PlacesUtils.bookmarks.insert({ parentGuid: parentGuid,
|
||||
type: PlacesUtils.bookmarks.TYPE_FOLDER,
|
||||
title: "a folder" });
|
||||
checkBookmarkObject(bm);
|
||||
Assert.equal(bm.parentGuid, parentGuid);
|
||||
Assert.equal(bm.index, 0);
|
||||
Assert.equal(bm.type, PlacesUtils.bookmarks.TYPE_FOLDER);
|
||||
Assert.strictEqual(bm.title, "a folder");
|
||||
});
|
||||
|
||||
add_task(function* create_bookmark() {
|
||||
let unfiledGuid = yield PlacesUtils.promiseItemGuid(PlacesUtils.unfiledBookmarksFolderId);
|
||||
let bm = yield PlacesUtils.bookmarks.insert({ parentGuid: unfiledGuid,
|
||||
type: PlacesUtils.bookmarks.TYPE_FOLDER });
|
||||
let parentGuid = bm.guid;
|
||||
|
||||
bm = yield PlacesUtils.bookmarks.insert({ parentGuid: parentGuid,
|
||||
type: PlacesUtils.bookmarks.TYPE_BOOKMARK,
|
||||
url: "http://example.com/",
|
||||
title: "a bookmark" });
|
||||
checkBookmarkObject(bm);
|
||||
Assert.equal(bm.parentGuid, parentGuid);
|
||||
Assert.equal(bm.index, 0);
|
||||
Assert.equal(bm.type, PlacesUtils.bookmarks.TYPE_BOOKMARK);
|
||||
Assert.equal(bm.url.href, "http://example.com/");
|
||||
Assert.equal(bm.title, "a bookmark");
|
||||
|
||||
// Check parent lastModified.
|
||||
let parent = yield PlacesUtils.bookmarks.fetch({ guid: bm.parentGuid });
|
||||
Assert.deepEqual(parent.lastModified, bm.dateAdded);
|
||||
|
||||
bm = yield PlacesUtils.bookmarks.insert({ parentGuid: parentGuid,
|
||||
type: PlacesUtils.bookmarks.TYPE_BOOKMARK,
|
||||
url: NetUtil.newURI("http://example.com/"),
|
||||
keyword: "test" });
|
||||
checkBookmarkObject(bm);
|
||||
Assert.equal(bm.parentGuid, parentGuid);
|
||||
Assert.equal(bm.index, 1);
|
||||
Assert.equal(bm.type, PlacesUtils.bookmarks.TYPE_BOOKMARK);
|
||||
Assert.equal(bm.url.href, "http://example.com/");
|
||||
Assert.equal(bm.keyword, "test");
|
||||
|
||||
// Check parent lastModified.
|
||||
parent = yield PlacesUtils.bookmarks.fetch({ guid: bm.parentGuid });
|
||||
Assert.deepEqual(parent.lastModified, bm.dateAdded);
|
||||
|
||||
bm = yield PlacesUtils.bookmarks.insert({ parentGuid: parentGuid,
|
||||
type: PlacesUtils.bookmarks.TYPE_BOOKMARK,
|
||||
url: new URL("http://example.com/") });
|
||||
checkBookmarkObject(bm);
|
||||
Assert.equal(bm.parentGuid, parentGuid);
|
||||
Assert.equal(bm.index, 2);
|
||||
Assert.equal(bm.type, PlacesUtils.bookmarks.TYPE_BOOKMARK);
|
||||
Assert.equal(bm.url.href, "http://example.com/");
|
||||
Assert.ok(!("title" in bm), "title should not be set");
|
||||
});
|
||||
|
||||
add_task(function* create_bookmark_frecency() {
|
||||
let unfiledGuid = yield PlacesUtils.promiseItemGuid(PlacesUtils.unfiledBookmarksFolderId);
|
||||
let bm = yield PlacesUtils.bookmarks.insert({ parentGuid: unfiledGuid,
|
||||
type: PlacesUtils.bookmarks.TYPE_BOOKMARK,
|
||||
url: "http://example.com/",
|
||||
title: "a bookmark" });
|
||||
checkBookmarkObject(bm);
|
||||
|
||||
yield promiseAsyncUpdates();
|
||||
Assert.ok(frecencyForUrl(bm.url) > 0, "Check frecency has been updated")
|
||||
});
|
||||
|
||||
function run_test() {
|
||||
run_next_test();
|
||||
}
|
|
@ -0,0 +1,186 @@
|
|||
/* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
add_task(function* invalid_input_throws() {
|
||||
Assert.throws(() => PlacesUtils.bookmarks.remove(),
|
||||
/Input should be a valid object/);
|
||||
Assert.throws(() => PlacesUtils.bookmarks.remove(null),
|
||||
/Input should be a valid object/);
|
||||
|
||||
Assert.throws(() => PlacesUtils.bookmarks.remove("test"),
|
||||
/Invalid value for property 'guid'/);
|
||||
Assert.throws(() => PlacesUtils.bookmarks.remove(123),
|
||||
/Invalid value for property 'guid'/);
|
||||
|
||||
Assert.throws(() => PlacesUtils.bookmarks.remove({ guid: "test" }),
|
||||
/Invalid value for property 'guid'/);
|
||||
Assert.throws(() => PlacesUtils.bookmarks.remove({ guid: null }),
|
||||
/Invalid value for property 'guid'/);
|
||||
Assert.throws(() => PlacesUtils.bookmarks.remove({ guid: 123 }),
|
||||
/Invalid value for property 'guid'/);
|
||||
|
||||
Assert.throws(() => PlacesUtils.bookmarks.remove({ parentGuid: "test" }),
|
||||
/Invalid value for property 'parentGuid'/);
|
||||
Assert.throws(() => PlacesUtils.bookmarks.remove({ parentGuid: null }),
|
||||
/Invalid value for property 'parentGuid'/);
|
||||
Assert.throws(() => PlacesUtils.bookmarks.remove({ parentGuid: 123 }),
|
||||
/Invalid value for property 'parentGuid'/);
|
||||
|
||||
Assert.throws(() => PlacesUtils.bookmarks.remove({ url: "http://te st/" }),
|
||||
/Invalid value for property 'url'/);
|
||||
Assert.throws(() => PlacesUtils.bookmarks.remove({ url: null }),
|
||||
/Invalid value for property 'url'/);
|
||||
Assert.throws(() => PlacesUtils.bookmarks.remove({ url: -10 }),
|
||||
/Invalid value for property 'url'/);
|
||||
});
|
||||
|
||||
add_task(function* remove_nonexistent_guid() {
|
||||
try {
|
||||
yield PlacesUtils.bookmarks.remove({ guid: "123456789012"});
|
||||
Assert.ok(false, "Should have thrown");
|
||||
} catch (ex) {
|
||||
Assert.ok(/No bookmarks found for the provided GUID/.test(ex));
|
||||
}
|
||||
});
|
||||
|
||||
add_task(function* remove_roots_fail() {
|
||||
let unfiledGuid = yield PlacesUtils.promiseItemGuid(PlacesUtils.unfiledBookmarksFolderId);
|
||||
try {
|
||||
yield PlacesUtils.bookmarks.remove(unfiledGuid);
|
||||
Assert.ok(false, "Should have thrown");
|
||||
} catch (ex) {
|
||||
Assert.ok(/It's not possible to remove Places root folders/.test(ex));
|
||||
}
|
||||
|
||||
let placesRootGuid = yield PlacesUtils.promiseItemGuid(PlacesUtils.placesRootId);
|
||||
try {
|
||||
yield PlacesUtils.bookmarks.remove(placesRootGuid);
|
||||
Assert.ok(false, "Should have thrown");
|
||||
} catch (ex) {
|
||||
Assert.ok(/It's not possible to remove Places root folders/.test(ex));
|
||||
}
|
||||
});
|
||||
|
||||
add_task(function* remove_bookmark() {
|
||||
let unfiledGuid = yield PlacesUtils.promiseItemGuid(PlacesUtils.unfiledBookmarksFolderId);
|
||||
let bm1 = yield PlacesUtils.bookmarks.insert({ parentGuid: unfiledGuid,
|
||||
type: PlacesUtils.bookmarks.TYPE_BOOKMARK,
|
||||
url: "http://example.com/",
|
||||
title: "a bookmark" });
|
||||
checkBookmarkObject(bm1);
|
||||
|
||||
let bm2 = yield PlacesUtils.bookmarks.remove(bm1.guid);
|
||||
checkBookmarkObject(bm2);
|
||||
|
||||
Assert.deepEqual(bm1, bm2);
|
||||
Assert.equal(bm2.parentGuid, unfiledGuid);
|
||||
Assert.equal(bm2.index, 0);
|
||||
Assert.deepEqual(bm2.dateAdded, bm2.lastModified);
|
||||
Assert.equal(bm2.type, PlacesUtils.bookmarks.TYPE_BOOKMARK);
|
||||
Assert.equal(bm2.url.href, "http://example.com/");
|
||||
Assert.equal(bm2.title, "a bookmark");
|
||||
Assert.ok(!("keyword" in bm2));
|
||||
});
|
||||
|
||||
|
||||
add_task(function* remove_bookmark_orphans() {
|
||||
let unfiledGuid = yield PlacesUtils.promiseItemGuid(PlacesUtils.unfiledBookmarksFolderId);
|
||||
let bm1 = yield PlacesUtils.bookmarks.insert({ parentGuid: unfiledGuid,
|
||||
type: PlacesUtils.bookmarks.TYPE_BOOKMARK,
|
||||
url: "http://example.com/",
|
||||
title: "a bookmark",
|
||||
keyword: "test"});
|
||||
checkBookmarkObject(bm1);
|
||||
PlacesUtils.annotations.setItemAnnotation((yield PlacesUtils.promiseItemId(bm1.guid)),
|
||||
"testanno", "testvalue", 0, 0);
|
||||
|
||||
let bm2 = yield PlacesUtils.bookmarks.remove(bm1.guid);
|
||||
checkBookmarkObject(bm2);
|
||||
Assert.equal(bm2.keyword, "test");
|
||||
|
||||
// Check there are no orphan keywords or annotations.
|
||||
let conn = yield PlacesUtils.promiseDBConnection();
|
||||
let rows = yield conn.execute(`SELECT * FROM moz_keywords`);
|
||||
Assert.equal(rows.length, 0);
|
||||
rows = yield conn.execute(`SELECT * FROM moz_items_annos`);
|
||||
Assert.equal(rows.length, 0);
|
||||
// removeItemAnnotations doesn't remove orphan annotations, cause it likely
|
||||
// relies on expiration to do so.
|
||||
//rows = yield conn.execute(`SELECT * FROM moz_anno_attributes`);
|
||||
//Assert.equal(rows.length, 0);
|
||||
});
|
||||
|
||||
add_task(function* remove_bookmark_empty_title() {
|
||||
let unfiledGuid = yield PlacesUtils.promiseItemGuid(PlacesUtils.unfiledBookmarksFolderId);
|
||||
let bm1 = yield PlacesUtils.bookmarks.insert({ parentGuid: unfiledGuid,
|
||||
type: PlacesUtils.bookmarks.TYPE_BOOKMARK,
|
||||
url: "http://example.com/",
|
||||
title: "" });
|
||||
checkBookmarkObject(bm1);
|
||||
|
||||
let bm2 = yield PlacesUtils.bookmarks.remove(bm1.guid);
|
||||
checkBookmarkObject(bm2);
|
||||
|
||||
Assert.deepEqual(bm1, bm2);
|
||||
Assert.equal(bm2.index, 0);
|
||||
Assert.ok(!("title" in bm2));
|
||||
Assert.ok(!("keyword" in bm2));
|
||||
});
|
||||
|
||||
add_task(function* remove_folder() {
|
||||
let unfiledGuid = yield PlacesUtils.promiseItemGuid(PlacesUtils.unfiledBookmarksFolderId);
|
||||
let bm1 = yield PlacesUtils.bookmarks.insert({ parentGuid: unfiledGuid,
|
||||
type: PlacesUtils.bookmarks.TYPE_FOLDER,
|
||||
title: "a folder" });
|
||||
checkBookmarkObject(bm1);
|
||||
|
||||
let bm2 = yield PlacesUtils.bookmarks.remove(bm1.guid);
|
||||
checkBookmarkObject(bm2);
|
||||
|
||||
Assert.deepEqual(bm1, bm2);
|
||||
Assert.equal(bm2.parentGuid, unfiledGuid);
|
||||
Assert.equal(bm2.index, 0);
|
||||
Assert.deepEqual(bm2.dateAdded, bm2.lastModified);
|
||||
Assert.equal(bm2.type, PlacesUtils.bookmarks.TYPE_FOLDER);
|
||||
Assert.equal(bm2.title, "a folder");
|
||||
Assert.ok(!("url" in bm2));
|
||||
Assert.ok(!("keyword" in bm2));
|
||||
});
|
||||
|
||||
add_task(function* remove_folder_empty_title() {
|
||||
let unfiledGuid = yield PlacesUtils.promiseItemGuid(PlacesUtils.unfiledBookmarksFolderId);
|
||||
let bm1 = yield PlacesUtils.bookmarks.insert({ parentGuid: unfiledGuid,
|
||||
type: PlacesUtils.bookmarks.TYPE_FOLDER,
|
||||
title: "" });
|
||||
checkBookmarkObject(bm1);
|
||||
|
||||
let bm2 = yield PlacesUtils.bookmarks.remove(bm1.guid);
|
||||
checkBookmarkObject(bm2);
|
||||
|
||||
Assert.deepEqual(bm1, bm2);
|
||||
Assert.equal(bm2.index, 0);
|
||||
Assert.ok(!("title" in bm2));
|
||||
});
|
||||
|
||||
add_task(function* remove_separator() {
|
||||
let unfiledGuid = yield PlacesUtils.promiseItemGuid(PlacesUtils.unfiledBookmarksFolderId);
|
||||
let bm1 = yield PlacesUtils.bookmarks.insert({ parentGuid: unfiledGuid,
|
||||
type: PlacesUtils.bookmarks.TYPE_SEPARATOR });
|
||||
checkBookmarkObject(bm1);
|
||||
|
||||
let bm2 = yield PlacesUtils.bookmarks.remove(bm1.guid);
|
||||
checkBookmarkObject(bm2);
|
||||
|
||||
Assert.deepEqual(bm1, bm2);
|
||||
Assert.equal(bm2.parentGuid, unfiledGuid);
|
||||
Assert.equal(bm2.index, 0);
|
||||
Assert.deepEqual(bm2.dateAdded, bm2.lastModified);
|
||||
Assert.equal(bm2.type, PlacesUtils.bookmarks.TYPE_SEPARATOR);
|
||||
Assert.ok(!("url" in bm2));
|
||||
Assert.ok(!("title" in bm2));
|
||||
Assert.ok(!("keyword" in bm2));
|
||||
});
|
||||
|
||||
function run_test() {
|
||||
run_next_test();
|
||||
}
|
|
@ -0,0 +1,415 @@
|
|||
/* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
add_task(function* invalid_input_throws() {
|
||||
Assert.throws(() => PlacesUtils.bookmarks.update(),
|
||||
/Input should be a valid object/);
|
||||
Assert.throws(() => PlacesUtils.bookmarks.update(null),
|
||||
/Input should be a valid object/);
|
||||
Assert.throws(() => PlacesUtils.bookmarks.update({}),
|
||||
/The following properties were expected/);
|
||||
|
||||
Assert.throws(() => PlacesUtils.bookmarks.update({ guid: "test" }),
|
||||
/Invalid value for property 'guid'/);
|
||||
Assert.throws(() => PlacesUtils.bookmarks.update({ guid: null }),
|
||||
/Invalid value for property 'guid'/);
|
||||
Assert.throws(() => PlacesUtils.bookmarks.update({ guid: 123 }),
|
||||
/Invalid value for property 'guid'/);
|
||||
|
||||
Assert.throws(() => PlacesUtils.bookmarks.update({ parentGuid: "test" }),
|
||||
/Invalid value for property 'parentGuid'/);
|
||||
Assert.throws(() => PlacesUtils.bookmarks.update({ parentGuid: null }),
|
||||
/Invalid value for property 'parentGuid'/);
|
||||
Assert.throws(() => PlacesUtils.bookmarks.update({ parentGuid: 123 }),
|
||||
/Invalid value for property 'parentGuid'/);
|
||||
|
||||
Assert.throws(() => PlacesUtils.bookmarks.update({ index: "1" }),
|
||||
/Invalid value for property 'index'/);
|
||||
Assert.throws(() => PlacesUtils.bookmarks.update({ index: -10 }),
|
||||
/Invalid value for property 'index'/);
|
||||
|
||||
Assert.throws(() => PlacesUtils.bookmarks.update({ dateAdded: -10 }),
|
||||
/Invalid value for property 'dateAdded'/);
|
||||
Assert.throws(() => PlacesUtils.bookmarks.update({ dateAdded: "today" }),
|
||||
/Invalid value for property 'dateAdded'/);
|
||||
Assert.throws(() => PlacesUtils.bookmarks.update({ dateAdded: Date.now() }),
|
||||
/Invalid value for property 'dateAdded'/);
|
||||
|
||||
Assert.throws(() => PlacesUtils.bookmarks.update({ lastModified: -10 }),
|
||||
/Invalid value for property 'lastModified'/);
|
||||
Assert.throws(() => PlacesUtils.bookmarks.update({ lastModified: "today" }),
|
||||
/Invalid value for property 'lastModified'/);
|
||||
Assert.throws(() => PlacesUtils.bookmarks.update({ lastModified: Date.now() }),
|
||||
/Invalid value for property 'lastModified'/);
|
||||
|
||||
Assert.throws(() => PlacesUtils.bookmarks.update({ type: -1 }),
|
||||
/Invalid value for property 'type'/);
|
||||
Assert.throws(() => PlacesUtils.bookmarks.update({ type: 100 }),
|
||||
/Invalid value for property 'type'/);
|
||||
Assert.throws(() => PlacesUtils.bookmarks.update({ type: "bookmark" }),
|
||||
/Invalid value for property 'type'/);
|
||||
|
||||
Assert.throws(() => PlacesUtils.bookmarks.update({ url: 10 }),
|
||||
/Invalid value for property 'url'/);
|
||||
Assert.throws(() => PlacesUtils.bookmarks.update({ url: "http://te st" }),
|
||||
/Invalid value for property 'url'/);
|
||||
let longurl = "http://www.example.com/";
|
||||
for (let i = 0; i < 65536; i++) {
|
||||
longurl += "a";
|
||||
}
|
||||
Assert.throws(() => PlacesUtils.bookmarks.update({ url: longurl }),
|
||||
/Invalid value for property 'url'/);
|
||||
|
||||
Assert.throws(() => PlacesUtils.bookmarks.update({ url: NetUtil.newURI(longurl) }),
|
||||
/Invalid value for property 'url'/);
|
||||
Assert.throws(() => PlacesUtils.bookmarks.update({ url: "te st" }),
|
||||
/Invalid value for property 'url'/);
|
||||
|
||||
Assert.throws(() => PlacesUtils.bookmarks.insert({ title: -1 }),
|
||||
/Invalid value for property 'title'/);
|
||||
Assert.throws(() => PlacesUtils.bookmarks.insert({ title: undefined }),
|
||||
/Invalid value for property 'title'/);
|
||||
|
||||
Assert.throws(() => PlacesUtils.bookmarks.update({ keyword: 10 }),
|
||||
/Invalid value for property 'keyword'/);
|
||||
Assert.throws(() => PlacesUtils.bookmarks.update({ keyword: null }),
|
||||
/Invalid value for property 'keyword'/);
|
||||
|
||||
Assert.throws(() => PlacesUtils.bookmarks.update({ guid: "123456789012" }),
|
||||
/Not enough properties to update/);
|
||||
|
||||
Assert.throws(() => PlacesUtils.bookmarks.update({ guid: "123456789012",
|
||||
parentGuid: "012345678901" }),
|
||||
/The following properties were expected: index/);
|
||||
Assert.throws(() => PlacesUtils.bookmarks.update({ guid: "123456789012",
|
||||
index: 1 }),
|
||||
/The following properties were expected: parentGuid/);
|
||||
});
|
||||
|
||||
add_task(function* nonexisting_bookmark_throws() {
|
||||
try {
|
||||
yield PlacesUtils.bookmarks.update({ guid: "123456789012",
|
||||
title: "test" });
|
||||
Assert.ok(false, "Should have thrown");
|
||||
} catch (ex) {
|
||||
Assert.ok(/No bookmarks found for the provided GUID/.test(ex));
|
||||
}
|
||||
});
|
||||
|
||||
add_task(function* invalid_properties_for_existing_bookmark() {
|
||||
let unfiledGuid = yield PlacesUtils.promiseItemGuid(PlacesUtils.unfiledBookmarksFolderId);
|
||||
let bm = yield PlacesUtils.bookmarks.insert({ type: PlacesUtils.bookmarks.TYPE_BOOKMARK,
|
||||
parentGuid: unfiledGuid,
|
||||
url: "http://example.com/" });
|
||||
|
||||
try {
|
||||
yield PlacesUtils.bookmarks.update({ guid: bm.guid,
|
||||
type: PlacesUtils.bookmarks.TYPE_FOLDER });
|
||||
Assert.ok(false, "Should have thrown");
|
||||
} catch (ex) {
|
||||
Assert.ok(/The bookmark type cannot be changed/.test(ex));
|
||||
}
|
||||
|
||||
try {
|
||||
yield PlacesUtils.bookmarks.update({ guid: bm.guid,
|
||||
dateAdded: new Date() });
|
||||
Assert.ok(false, "Should have thrown");
|
||||
} catch (ex) {
|
||||
Assert.ok(/The bookmark dateAdded cannot be changed/.test(ex));
|
||||
}
|
||||
|
||||
try {
|
||||
yield PlacesUtils.bookmarks.update({ guid: bm.guid,
|
||||
dateAdded: new Date() });
|
||||
Assert.ok(false, "Should have thrown");
|
||||
} catch (ex) {
|
||||
Assert.ok(/The bookmark dateAdded cannot be changed/.test(ex));
|
||||
}
|
||||
|
||||
try {
|
||||
yield PlacesUtils.bookmarks.update({ guid: bm.guid,
|
||||
parentGuid: "123456789012",
|
||||
index: 1 });
|
||||
Assert.ok(false, "Should have thrown");
|
||||
} catch (ex) {
|
||||
Assert.ok(/No bookmarks found for the provided parentGuid/.test(ex));
|
||||
}
|
||||
|
||||
let past = new Date(Date.now() - 86400000);
|
||||
try {
|
||||
yield PlacesUtils.bookmarks.update({ guid: bm.guid,
|
||||
lastModified: past });
|
||||
Assert.ok(false, "Should have thrown");
|
||||
} catch (ex) {
|
||||
Assert.ok(/Invalid value for property 'lastModified'/.test(ex));
|
||||
}
|
||||
|
||||
let folder = yield PlacesUtils.bookmarks.insert({ type: PlacesUtils.bookmarks.TYPE_FOLDER,
|
||||
parentGuid: unfiledGuid });
|
||||
try {
|
||||
yield PlacesUtils.bookmarks.update({ guid: folder.guid,
|
||||
url: "http://example.com/" });
|
||||
Assert.ok(false, "Should have thrown");
|
||||
} catch (ex) {
|
||||
Assert.ok(/Invalid value for property 'url'/.test(ex));
|
||||
}
|
||||
try {
|
||||
yield PlacesUtils.bookmarks.update({ guid: folder.guid,
|
||||
keyword: "test" });
|
||||
Assert.ok(false, "Should have thrown");
|
||||
} catch (ex) {
|
||||
Assert.ok(/Invalid value for property 'keyword'/.test(ex));
|
||||
}
|
||||
|
||||
let separator = yield PlacesUtils.bookmarks.insert({ type: PlacesUtils.bookmarks.TYPE_SEPARATOR,
|
||||
parentGuid: unfiledGuid });
|
||||
try {
|
||||
yield PlacesUtils.bookmarks.update({ guid: separator.guid,
|
||||
url: "http://example.com/" });
|
||||
Assert.ok(false, "Should have thrown");
|
||||
} catch (ex) {
|
||||
Assert.ok(/Invalid value for property 'url'/.test(ex));
|
||||
}
|
||||
try {
|
||||
yield PlacesUtils.bookmarks.update({ guid: separator.guid,
|
||||
keyword: "test" });
|
||||
Assert.ok(false, "Should have thrown");
|
||||
} catch (ex) {
|
||||
Assert.ok(/Invalid value for property 'keyword'/.test(ex));
|
||||
}
|
||||
try {
|
||||
yield PlacesUtils.bookmarks.update({ guid: separator.guid,
|
||||
title: "test" });
|
||||
Assert.ok(false, "Should have thrown");
|
||||
} catch (ex) {
|
||||
Assert.ok(/Invalid value for property 'title'/.test(ex));
|
||||
}
|
||||
});
|
||||
|
||||
add_task(function* long_title_trim() {
|
||||
let longtitle = "a";
|
||||
for (let i = 0; i < 4096; i++) {
|
||||
longtitle += "a";
|
||||
}
|
||||
let unfiledGuid = yield PlacesUtils.promiseItemGuid(PlacesUtils.unfiledBookmarksFolderId);
|
||||
let bm = yield PlacesUtils.bookmarks.insert({ parentGuid: unfiledGuid,
|
||||
type: PlacesUtils.bookmarks.TYPE_FOLDER,
|
||||
title: "title" });
|
||||
checkBookmarkObject(bm);
|
||||
|
||||
bm = yield PlacesUtils.bookmarks.update({ guid: bm.guid,
|
||||
title: longtitle });
|
||||
let newTitle = bm.title;
|
||||
Assert.equal(newTitle.length, 4096, "title should have been trimmed");
|
||||
|
||||
bm = yield PlacesUtils.bookmarks.fetch(bm.guid);
|
||||
Assert.equal(bm.title, newTitle);
|
||||
});
|
||||
|
||||
add_task(function* update_lastModified() {
|
||||
let unfiledGuid = yield PlacesUtils.promiseItemGuid(PlacesUtils.unfiledBookmarksFolderId);
|
||||
let yesterday = new Date(Date.now() - 86400000);
|
||||
let bm = yield PlacesUtils.bookmarks.insert({ parentGuid: unfiledGuid,
|
||||
type: PlacesUtils.bookmarks.TYPE_FOLDER,
|
||||
title: "title",
|
||||
dateAdded: yesterday });
|
||||
checkBookmarkObject(bm);
|
||||
Assert.deepEqual(bm.lastModified, yesterday);
|
||||
|
||||
let time = new Date();
|
||||
bm = yield PlacesUtils.bookmarks.update({ guid: bm.guid,
|
||||
lastModified: time });
|
||||
checkBookmarkObject(bm);
|
||||
Assert.deepEqual(bm.lastModified, time);
|
||||
|
||||
bm = yield PlacesUtils.bookmarks.fetch(bm.guid);
|
||||
Assert.deepEqual(bm.lastModified, time);
|
||||
|
||||
bm = yield PlacesUtils.bookmarks.update({ guid: bm.guid,
|
||||
lastModified: yesterday });
|
||||
Assert.deepEqual(bm.lastModified, yesterday);
|
||||
|
||||
bm = yield PlacesUtils.bookmarks.update({ guid: bm.guid,
|
||||
title: "title2" });
|
||||
Assert.ok(bm.lastModified >= time);
|
||||
|
||||
bm = yield PlacesUtils.bookmarks.update({ guid: bm.guid,
|
||||
title: "" });
|
||||
Assert.ok(!("title" in bm));
|
||||
|
||||
bm = yield PlacesUtils.bookmarks.fetch(bm.guid);
|
||||
Assert.ok(!("title" in bm));
|
||||
});
|
||||
|
||||
add_task(function* update_keyword() {
|
||||
let unfiledGuid = yield PlacesUtils.promiseItemGuid(PlacesUtils.unfiledBookmarksFolderId);
|
||||
let bm = yield PlacesUtils.bookmarks.insert({ parentGuid: unfiledGuid,
|
||||
type: PlacesUtils.bookmarks.TYPE_BOOKMARK,
|
||||
url: "http://example.com/",
|
||||
title: "title",
|
||||
keyword: "kw" });
|
||||
checkBookmarkObject(bm);
|
||||
let lastModified = bm.lastModified;
|
||||
|
||||
bm = yield PlacesUtils.bookmarks.update({ guid: bm.guid,
|
||||
keyword: "kw2" });
|
||||
checkBookmarkObject(bm);
|
||||
Assert.ok(bm.lastModified >= lastModified);
|
||||
Assert.equal(bm.keyword, "kw2");
|
||||
|
||||
bm = yield PlacesUtils.bookmarks.fetch(bm.guid);
|
||||
Assert.equal(bm.keyword, "kw2");
|
||||
lastModified = bm.lastModified;
|
||||
|
||||
bm = yield PlacesUtils.bookmarks.update({ guid: bm.guid,
|
||||
keyword: "" });
|
||||
Assert.ok(!("keyword" in bm));
|
||||
|
||||
bm = yield PlacesUtils.bookmarks.fetch(bm.guid);
|
||||
Assert.ok(!("keyword" in bm));
|
||||
Assert.ok(bm.lastModified >= lastModified);
|
||||
|
||||
// Check orphan keyword has been removed from the database.
|
||||
let conn = yield PlacesUtils.promiseDBConnection();
|
||||
let rows = yield conn.executeCached(
|
||||
`SELECT id from moz_keywords WHERE keyword >= :keyword`, { keyword: "kw" });
|
||||
Assert.equal(rows.length, 0);
|
||||
});
|
||||
|
||||
add_task(function* update_url() {
|
||||
let unfiledGuid = yield PlacesUtils.promiseItemGuid(PlacesUtils.unfiledBookmarksFolderId);
|
||||
let bm = yield PlacesUtils.bookmarks.insert({ parentGuid: unfiledGuid,
|
||||
type: PlacesUtils.bookmarks.TYPE_BOOKMARK,
|
||||
url: "http://example.com/",
|
||||
title: "title",
|
||||
keyword: "kw" });
|
||||
checkBookmarkObject(bm);
|
||||
let lastModified = bm.lastModified;
|
||||
let frecency = frecencyForUrl(bm.url);
|
||||
Assert.ok(frecency > 0, "Check frecency has been updated");
|
||||
|
||||
bm = yield PlacesUtils.bookmarks.update({ guid: bm.guid,
|
||||
url: "http://mozilla.org/" });
|
||||
checkBookmarkObject(bm);
|
||||
Assert.ok(bm.lastModified >= lastModified);
|
||||
Assert.equal(bm.url.href, "http://mozilla.org/");
|
||||
|
||||
bm = yield PlacesUtils.bookmarks.fetch(bm.guid);
|
||||
Assert.equal(bm.url.href, "http://mozilla.org/");
|
||||
Assert.ok(bm.lastModified >= lastModified);
|
||||
|
||||
Assert.equal(frecencyForUrl("http://example.com/"), frecency, "Check frecency for example.com");
|
||||
Assert.equal(frecencyForUrl("http://mozilla.org/"), frecency, "Check frecency for mozilla.org");
|
||||
});
|
||||
|
||||
add_task(function* update_index() {
|
||||
let unfiledGuid = yield PlacesUtils.promiseItemGuid(PlacesUtils.unfiledBookmarksFolderId);
|
||||
let parent = yield PlacesUtils.bookmarks.insert({ parentGuid: unfiledGuid,
|
||||
type: PlacesUtils.bookmarks.TYPE_FOLDER }) ;
|
||||
let f1 = yield PlacesUtils.bookmarks.insert({ parentGuid: parent.guid,
|
||||
type: PlacesUtils.bookmarks.TYPE_FOLDER });
|
||||
Assert.equal(f1.index, 0);
|
||||
let f2 = yield PlacesUtils.bookmarks.insert({ parentGuid: parent.guid,
|
||||
type: PlacesUtils.bookmarks.TYPE_FOLDER });
|
||||
Assert.equal(f2.index, 1);
|
||||
let f3 = yield PlacesUtils.bookmarks.insert({ parentGuid: parent.guid,
|
||||
type: PlacesUtils.bookmarks.TYPE_FOLDER });
|
||||
Assert.equal(f3.index, 2);
|
||||
let lastModified = f1.lastModified;
|
||||
|
||||
f1 = yield PlacesUtils.bookmarks.update({ guid: f1.guid,
|
||||
parentGuid: f1.parentGuid,
|
||||
index: 1});
|
||||
checkBookmarkObject(f1);
|
||||
Assert.equal(f1.index, 1);
|
||||
Assert.ok(f1.lastModified >= lastModified);
|
||||
|
||||
parent = yield PlacesUtils.bookmarks.fetch(f1.parentGuid);
|
||||
Assert.deepEqual(parent.lastModified, f1.lastModified);
|
||||
|
||||
f2 = yield PlacesUtils.bookmarks.fetch(f2.guid);
|
||||
Assert.equal(f2.index, 0);
|
||||
|
||||
f3 = yield PlacesUtils.bookmarks.fetch(f3.guid);
|
||||
Assert.equal(f3.index, 2);
|
||||
|
||||
f3 = yield PlacesUtils.bookmarks.update({ guid: f3.guid,
|
||||
parentGuid: f1.parentGuid,
|
||||
index: 0 });
|
||||
f1 = yield PlacesUtils.bookmarks.fetch(f1.guid);
|
||||
Assert.equal(f1.index, 2);
|
||||
|
||||
f2 = yield PlacesUtils.bookmarks.fetch(f2.guid);
|
||||
Assert.equal(f2.index, 1);
|
||||
});
|
||||
|
||||
add_task(function* update_move_folder_into_descendant_throws() {
|
||||
let unfiledGuid = yield PlacesUtils.promiseItemGuid(PlacesUtils.unfiledBookmarksFolderId);
|
||||
let parent = yield PlacesUtils.bookmarks.insert({ parentGuid: unfiledGuid,
|
||||
type: PlacesUtils.bookmarks.TYPE_FOLDER }) ;
|
||||
let descendant = yield PlacesUtils.bookmarks.insert({ parentGuid: parent.guid,
|
||||
type: PlacesUtils.bookmarks.TYPE_FOLDER });
|
||||
|
||||
try {
|
||||
yield PlacesUtils.bookmarks.update({ guid: parent.guid,
|
||||
parentGuid: parent.guid,
|
||||
index: 0 });
|
||||
Assert.ok(false, "Should have thrown");
|
||||
} catch (ex) {
|
||||
Assert.ok(/Cannot insert a folder into itself or one of its descendants/.test(ex));
|
||||
}
|
||||
|
||||
try {
|
||||
yield PlacesUtils.bookmarks.update({ guid: parent.guid,
|
||||
parentGuid: descendant.guid,
|
||||
index: 0 });
|
||||
Assert.ok(false, "Should have thrown");
|
||||
} catch (ex) {
|
||||
Assert.ok(/Cannot insert a folder into itself or one of its descendants/.test(ex));
|
||||
}
|
||||
});
|
||||
|
||||
add_task(function* update_move() {
|
||||
let unfiledGuid = yield PlacesUtils.promiseItemGuid(PlacesUtils.unfiledBookmarksFolderId);
|
||||
let parent = yield PlacesUtils.bookmarks.insert({ parentGuid: unfiledGuid,
|
||||
type: PlacesUtils.bookmarks.TYPE_FOLDER }) ;
|
||||
let bm = yield PlacesUtils.bookmarks.insert({ parentGuid: parent.guid,
|
||||
url: "http://example.com/",
|
||||
type: PlacesUtils.bookmarks.TYPE_BOOKMARK }) ;
|
||||
let descendant = yield PlacesUtils.bookmarks.insert({ parentGuid: parent.guid,
|
||||
type: PlacesUtils.bookmarks.TYPE_FOLDER });
|
||||
Assert.equal(descendant.index, 1);
|
||||
let lastModified = bm.lastModified;
|
||||
|
||||
// This is moving to a nonexisting index by purpose, it will be appended.
|
||||
bm = yield PlacesUtils.bookmarks.update({ guid: bm.guid,
|
||||
parentGuid: descendant.guid,
|
||||
index: 1 });
|
||||
checkBookmarkObject(bm);
|
||||
Assert.equal(bm.parentGuid, descendant.guid);
|
||||
Assert.equal(bm.index, 0);
|
||||
Assert.ok(bm.lastModified >= lastModified);
|
||||
|
||||
parent = yield PlacesUtils.bookmarks.fetch(parent.guid);
|
||||
descendant = yield PlacesUtils.bookmarks.fetch(descendant.guid);
|
||||
Assert.deepEqual(parent.lastModified, bm.lastModified);
|
||||
Assert.deepEqual(descendant.lastModified, bm.lastModified);
|
||||
Assert.equal(descendant.index, 0);
|
||||
|
||||
bm = yield PlacesUtils.bookmarks.fetch(bm.guid);
|
||||
Assert.equal(bm.parentGuid, descendant.guid);
|
||||
Assert.equal(bm.index, 0);
|
||||
|
||||
bm = yield PlacesUtils.bookmarks.update({ guid: bm.guid,
|
||||
parentGuid: parent.guid,
|
||||
index: 0 });
|
||||
Assert.equal(bm.parentGuid, parent.guid);
|
||||
Assert.equal(bm.index, 0);
|
||||
|
||||
descendant = yield PlacesUtils.bookmarks.fetch(descendant.guid);
|
||||
Assert.equal(descendant.index, 1);
|
||||
});
|
||||
|
||||
function run_test() {
|
||||
run_next_test();
|
||||
}
|
|
@ -3,6 +3,8 @@ head = head_bookmarks.js
|
|||
tail =
|
||||
skip-if = toolkit == 'android' || toolkit == 'gonk'
|
||||
|
||||
[test_1016953-renaming-uncompressed.js]
|
||||
[test_1017502-bookmarks_foreign_count.js]
|
||||
[test_384228.js]
|
||||
[test_385829.js]
|
||||
[test_388695.js]
|
||||
|
@ -17,22 +19,25 @@ skip-if = toolkit == 'android' || toolkit == 'gonk'
|
|||
[test_458683.js]
|
||||
[test_466303-json-remove-backups.js]
|
||||
[test_477583_json-backup-in-future.js]
|
||||
[test_675416.js]
|
||||
[test_711914.js]
|
||||
[test_818584-discard-duplicate-backups.js]
|
||||
[test_818587_compress-bookmarks-backups.js]
|
||||
[test_818593-store-backup-metadata.js]
|
||||
[test_992901-backup-unsorted-hierarchy.js]
|
||||
[test_997030-bookmarks-html-encode.js]
|
||||
[test_async_observers.js]
|
||||
[test_bmindex.js]
|
||||
[test_bookmarks.js]
|
||||
[test_bookmarks_eraseEverything.js]
|
||||
[test_bookmarks_fetch.js]
|
||||
[test_bookmarks_insert.js]
|
||||
[test_bookmarks_remove.js]
|
||||
[test_bookmarks_update.js]
|
||||
[test_changeBookmarkURI.js]
|
||||
[test_getBookmarkedURIFor.js]
|
||||
[test_keywords.js]
|
||||
[test_nsINavBookmarkObserver.js]
|
||||
[test_protectRoots.js]
|
||||
[test_removeItem.js]
|
||||
[test_savedsearches.js]
|
||||
[test_675416.js]
|
||||
[test_711914.js]
|
||||
[test_protectRoots.js]
|
||||
[test_818593-store-backup-metadata.js]
|
||||
[test_818584-discard-duplicate-backups.js]
|
||||
[test_818587_compress-bookmarks-backups.js]
|
||||
[test_992901-backup-unsorted-hierarchy.js]
|
||||
[test_997030-bookmarks-html-encode.js]
|
||||
[test_1016953-renaming-uncompressed.js]
|
||||
[test_1017502-bookmarks_foreign_count.js]
|
||||
|
|
|
@ -20,8 +20,9 @@ const TRANSITION_DOWNLOAD = Ci.nsINavHistoryService.TRANSITION_DOWNLOAD;
|
|||
|
||||
const TITLE_LENGTH_MAX = 4096;
|
||||
|
||||
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
Cu.importGlobalProperties(["URL"]);
|
||||
|
||||
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "FileUtils",
|
||||
"resource://gre/modules/FileUtils.jsm");
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "NetUtil",
|
||||
|
@ -549,7 +550,9 @@ function check_JSON_backup(aIsAutomaticBackup) {
|
|||
*/
|
||||
function frecencyForUrl(aURI)
|
||||
{
|
||||
let url = aURI instanceof Ci.nsIURI ? aURI.spec : aURI;
|
||||
let url = aURI instanceof Ci.nsIURI ? aURI.spec
|
||||
: aURI instanceof URL ? aURI.href
|
||||
: aURI;
|
||||
let stmt = DBConn().createStatement(
|
||||
"SELECT frecency FROM moz_places WHERE url = ?1"
|
||||
);
|
||||
|
@ -967,3 +970,13 @@ function promiseSetIconForPage(aPageURI, aIconURI) {
|
|||
() => { deferred.resolve(); });
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
function checkBookmarkObject(info) {
|
||||
do_check_valid_places_guid(info.guid);
|
||||
do_check_valid_places_guid(info.parentGuid);
|
||||
Assert.ok(typeof info.index == "number", "index should be a number");
|
||||
Assert.ok(info.dateAdded.constructor.name == "Date", "dateAdded should be a Date");
|
||||
Assert.ok(info.lastModified.constructor.name == "Date", "lastModified should be a Date");
|
||||
Assert.ok(info.lastModified >= info.dateAdded, "lastModified should never be smaller than dateAdded");
|
||||
Assert.ok(typeof info.type == "number", "type should be a number");
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче