Bug 1098552 - Bookmarks.jsm should use case-insensitive keywords. r=Mano

--HG--
extra : rebase_source : 50db985a28194821d3e5e48d829e5af240ffdb31
extra : histedit_source : 8f26bfec9edbb82c4e1f5487c45583a563bb491f%2Cc41fba608e5de3958c8702adc5b779be30b0b0d7
This commit is contained in:
Marco Bonardo 2014-12-10 17:56:57 +01:00
Родитель 47d6d474ac
Коммит 8358e1d6f7
6 изменённых файлов: 30 добавлений и 6 удалений

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

@ -1228,7 +1228,12 @@ const VALIDATORS = Object.freeze({
return new URL(v.spec);
return v;
},
keyword: simpleValidateFunc(v => typeof(v) == "string" && /^\S*$/.test(v)),
keyword: v => {
simpleValidateFunc(val => typeof(val) == "string" && /^\S*$/.test(val))
.call(this, v);
// Keywords are handled as case-insensitive.
return v.toLowerCase();
}
});
/**

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

@ -329,6 +329,7 @@ add_task(function* fetch_bykeyword() {
Assert.equal(bm2.url.href, "http://bykeyword1.com/");
Assert.equal(bm2.keyword, "bykeyword");
// Add a second url using the same keyword.
let bm3 = yield PlacesUtils.bookmarks.insert({ parentGuid: PlacesUtils.bookmarks.unfiledGuid,
type: PlacesUtils.bookmarks.TYPE_BOOKMARK,
url: "http://bykeyword2.com/",
@ -352,6 +353,16 @@ add_task(function* fetch_bykeyword() {
Assert.equal(gAccumulator.results.length, 2);
gAccumulator.results.forEach(checkBookmarkObject);
Assert.deepEqual(gAccumulator.results[0], bm5);
// Check fetching by keyword is case-insensitive.
let bm6 = yield PlacesUtils.bookmarks.fetch({ keyword: "ByKeYwOrD" },
gAccumulator.callback);
checkBookmarkObject(bm6);
// Cannot use deepEqual cause lastModified changed.
Assert.equal(bm1.guid, bm6.guid);
Assert.equal(gAccumulator.results.length, 2);
gAccumulator.results.forEach(checkBookmarkObject);
Assert.deepEqual(gAccumulator.results[0], bm6);
});
function run_test() {

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

@ -243,10 +243,11 @@ add_task(function* create_bookmark() {
let parent = yield PlacesUtils.bookmarks.fetch({ guid: bm.parentGuid });
Assert.deepEqual(parent.lastModified, bm.dateAdded);
// While here, also check keywords are case-insensitive.
bm = yield PlacesUtils.bookmarks.insert({ parentGuid: parentGuid,
type: PlacesUtils.bookmarks.TYPE_BOOKMARK,
url: NetUtil.newURI("http://example.com/"),
keyword: "test" });
keyword: "tEsT" });
checkBookmarkObject(bm);
Assert.equal(bm.parentGuid, parentGuid);
Assert.equal(bm.index, 1);

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

@ -75,9 +75,11 @@ add_task(function* insert_bookmark_keyword_notification() {
let bm = yield PlacesUtils.bookmarks.insert({ type: PlacesUtils.bookmarks.TYPE_BOOKMARK,
parentGuid: PlacesUtils.bookmarks.unfiledGuid,
url: new URL("http://example.com/"),
keyword: "kw" });
keyword: "Kw" });
let itemId = yield PlacesUtils.promiseItemId(bm.guid);
let parentId = yield PlacesUtils.promiseItemId(bm.parentGuid);
// Keywords are case-insensitive.
Assert.equal(bm.keyword, "kw");
observer.check([ { name: "onItemAdded",
arguments: [ itemId, parentId, bm.index, bm.type,
bm.url, null, bm.dateAdded,
@ -173,7 +175,9 @@ add_task(function* update_bookmark_keyword() {
parentGuid: PlacesUtils.bookmarks.unfiledGuid,
url: new URL("http://keyword.example.com/") });
let observer = expectNotifications();
bm = yield PlacesUtils.bookmarks.update({ guid: bm.guid, keyword: "kw" });
bm = yield PlacesUtils.bookmarks.update({ guid: bm.guid, keyword: "kW" });
// Keywords are case-insensitive.
Assert.equal(bm.keyword, "kw");
let itemId = yield PlacesUtils.promiseItemId(bm.guid);
let parentId = yield PlacesUtils.promiseItemId(bm.parentGuid);

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

@ -90,13 +90,14 @@ add_task(function* remove_bookmark_orphans() {
type: PlacesUtils.bookmarks.TYPE_BOOKMARK,
url: "http://example.com/",
title: "a bookmark",
keyword: "test"});
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);
// Keywords are case-insensitive.
Assert.equal(bm2.keyword, "test");
// Check there are no orphan keywords or annotations.

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

@ -248,12 +248,14 @@ add_task(function* update_keyword() {
let lastModified = bm.lastModified;
bm = yield PlacesUtils.bookmarks.update({ guid: bm.guid,
keyword: "kw2" });
keyword: "KW2" });
checkBookmarkObject(bm);
Assert.ok(bm.lastModified >= lastModified);
// Keywords are case-insensitive.
Assert.equal(bm.keyword, "kw2");
bm = yield PlacesUtils.bookmarks.fetch(bm.guid);
// Keywords are case-insensitive.
Assert.equal(bm.keyword, "kw2");
lastModified = bm.lastModified;