Bug 498407 - Adding search keyword doesn't work on many sites, transactions manager tries to get anno for an invalid itemId, r=dietrich

This commit is contained in:
Marco Bonardo 2009-06-16 17:17:43 +02:00
parent 0d06184f97
commit 0e672ad5f9
2 changed files with 38 additions and 16 deletions

View File

@ -752,20 +752,6 @@ function placesSetItemAnnotationTransactions(aItemId, aAnnotationObject) {
flags: 0,
value: null,
expires: Ci.nsIAnnotationService.EXPIRE_NEVER };
if (PlacesUtils.annotations.itemHasAnnotation(this.id, this._anno.name)) {
// fill the old anno if it is set
var flags = {}, expires = {}, mimeType = {}, type = {};
PlacesUtils.annotations.getItemAnnotationInfo(this.id, this._anno.name,
flags, expires, mimeType, type);
this._oldAnno.flags = flags.value;
this._oldAnno.expires = expires.value;
this._oldAnno.mimeType = mimeType.value;
this._oldAnno.type = type.value;
this._oldAnno.value = PlacesUtils.annotations
.getItemAnnotation(this.id, this._anno.name);
}
this.redoTransaction = this.doTransaction;
}
@ -773,6 +759,23 @@ placesSetItemAnnotationTransactions.prototype = {
__proto__: placesBaseTransaction.prototype,
doTransaction: function PSIAT_doTransaction() {
// Since this can be used as a child transaction this.id will be known
// only at this point, after the external caller has set it.
if (PlacesUtils.annotations.itemHasAnnotation(this.id, this._anno.name)) {
// Save the old annotation if it is set.
var flags = {}, expires = {}, mimeType = {}, type = {};
PlacesUtils.annotations.getItemAnnotationInfo(this.id, this._anno.name,
flags, expires, mimeType,
type);
this._oldAnno.flags = flags.value;
this._oldAnno.expires = expires.value;
this._oldAnno.mimeType = mimeType.value;
this._oldAnno.type = type.value;
this._oldAnno.value = PlacesUtils.annotations
.getItemAnnotation(this.id,
this._anno.name);
}
PlacesUtils.setAnnotationsForItem(this.id, [this._anno]);
},

View File

@ -716,14 +716,28 @@ function run_test() {
do_check_eq(bmsvc.getItemTitle(newBkmk3_3Id), "folder");
// Test creating an item with child transactions.
var childTxns = [];
var newDateAdded = Date.now() - 20000;
var childTxn = ptSvc.editItemDateAdded(null, newDateAdded);
var itemWChildTxn = ptSvc.createItem(uri("http://www.example.com"), root, bmStartIndex, "Testing1", null, null, [childTxn]);
childTxns.push(ptSvc.editItemDateAdded(null, newDateAdded));
var itemChildAnnoObj = { name: "testAnno/testInt",
type: Ci.nsIAnnotationService.TYPE_INT32,
flags: 0,
value: 123,
expires: Ci.nsIAnnotationService.EXPIRE_NEVER };
childTxns.push(ptSvc.setItemAnnotation(null, itemChildAnnoObj));
var itemWChildTxn = ptSvc.createItem(uri("http://www.example.com"), root,
bmStartIndex, "Testing1", null, null,
childTxns);
try {
ptSvc.doTransaction(itemWChildTxn); // Also testing doTransaction
var itemId = (bmsvc.getBookmarkIdsForURI(uri("http://www.example.com"), {}))[0];
do_check_eq(observer._itemAddedId, itemId);
do_check_eq(newDateAdded, bmsvc.getItemDateAdded(itemId));
do_check_eq(observer._itemChangedProperty, "testAnno/testInt");
do_check_eq(observer._itemChanged_isAnnotationProperty, true);
do_check_true(annosvc.itemHasAnnotation(itemId, itemChildAnnoObj.name))
do_check_eq(annosvc.getItemAnnotation(itemId, itemChildAnnoObj.name),
itemChildAnnoObj.value);
itemWChildTxn.undoTransaction();
do_check_eq(observer._itemRemovedId, itemId);
itemWChildTxn.redoTransaction();
@ -731,6 +745,11 @@ function run_test() {
var newId = (bmsvc.getBookmarkIdsForURI(uri("http://www.example.com"), {}))[0];
do_check_eq(newDateAdded, bmsvc.getItemDateAdded(newId));
do_check_eq(observer._itemAddedId, newId);
do_check_eq(observer._itemChangedProperty, "testAnno/testInt");
do_check_eq(observer._itemChanged_isAnnotationProperty, true);
do_check_true(annosvc.itemHasAnnotation(newId, itemChildAnnoObj.name))
do_check_eq(annosvc.getItemAnnotation(newId, itemChildAnnoObj.name),
itemChildAnnoObj.value);
itemWChildTxn.undoTransaction();
do_check_eq(observer._itemRemovedId, newId);
} catch (ex) {