Bug 1420811 - Rename bookmark tag to empty will cause issue. r=standard8
MozReview-Commit-ID: HcgDlC2qlCM
--- a/browser/components/places/content/editBookmarkOverlay.js
+++ b/browser/components/places/content/editBookmarkOverlay.js
@@ -620,17 +620,17 @@ var gEditItemOverlay = {
},
async onNamePickerChange() {
if (this.readOnly || !(this._paneInfo.isItem || this._paneInfo.isTag))
return;
// Here we update either the item title or its cached static title
let newTitle = this._namePicker.value;
- if (!newTitle && this._paneInfo.parentGuid == PlacesUtils.bookmarks.tagsGuid) {
+ if (!newTitle && this._paneInfo.isTag) {
// We don't allow setting an empty title for a tag, restore the old one.
this._initNamePicker();
} else {
this._mayUpdateFirstEditField("namePicker");
if (!PlacesUIUtils.useAsyncTransactions) {
let txn = new PlacesEditItemTitleTransaction(this._paneInfo.itemId,
newTitle);
PlacesUtils.transactionManager.doTransaction(txn);
@@ -1103,50 +1103,50 @@ var gEditItemOverlay = {
// Any tags change should be reflected in the tags selector.
if (this._element("tagsSelector")) {
this._rebuildTagsSelectorList();
}
}
},
_onItemTitleChange(aItemId, aNewTitle) {
- if (!this._paneInfo.isBookmark)
- return;
if (aItemId == this._paneInfo.itemId) {
this._paneInfo.title = aNewTitle;
this._initTextField(this._namePicker, aNewTitle);
} else if (this._paneInfo.visibleRows.has("folderRow")) {
// If the title of a folder which is listed within the folders
// menulist has been changed, we need to update the label of its
// representing element.
let menupopup = this._folderMenuList.menupopup;
for (let menuitem of menupopup.childNodes) {
if ("folderId" in menuitem && menuitem.folderId == aItemId) {
menuitem.label = aNewTitle;
break;
}
}
}
// We need to also update title of recent folders.
- for (let folder of this._recentFolders) {
- if (folder.folderId == aItemId) {
- folder.title = aNewTitle;
- break;
+ if (this._recentFolders) {
+ for (let folder of this._recentFolders) {
+ if (folder.folderId == aItemId) {
+ folder.title = aNewTitle;
+ break;
+ }
}
}
},
// nsINavBookmarkObserver
onItemChanged(aItemId, aProperty, aIsAnnotationProperty, aValue,
aLastModified, aItemType, aParentId, aGuid) {
if (aProperty == "tags" && this._paneInfo.visibleRows.has("tagsRow")) {
this._onTagsChange(aGuid).catch(Components.utils.reportError);
return;
}
- if (aProperty == "title" && this._paneInfo.isItem) {
+ if (aProperty == "title" && (this._paneInfo.isItem || this._paneInfo.isTag)) {
// This also updates titles of folders in the folder menu list.
this._onItemTitleChange(aItemId, aValue);
return;
}
if (!this._paneInfo.isItem || this._paneInfo.itemId != aItemId) {
return;
}
--- a/browser/components/places/tests/browser/browser_bookmarkProperties_editTagContainer.js
+++ b/browser/components/places/tests/browser/browser_bookmarkProperties_editTagContainer.js
@@ -55,16 +55,21 @@ add_task(async function() {
await promiseTitleChangeNotification;
Assert.equal(namepicker.value, "tag2", "Node title has been properly edited");
// Check the shortcut's title.
Assert.equal(tree.selectedNode.title, "tag2", "The node has the correct title");
+ // Try to set an empty title, it should restore the previous one.
+ fillBookmarkTextField("editBMPanel_namePicker", "", dialogWin);
+ Assert.equal(namepicker.value, "tag2", "Title has not been changed");
+ Assert.equal(tree.selectedNode.title, "tag2", "The node has the correct title");
+
// Check the tags have been edited.
let tags = PlacesUtils.tagging.getTagsForURI(uri);
Assert.equal(tags.length, 1, "Found the right number of tags");
Assert.ok(tags.includes("tag2"), "Found the expected tag");
// Ensure that the addition really is finished before we hit cancel.
await PlacesTestUtils.promiseAsyncUpdates();
}
--- a/browser/components/places/tests/browser/head.js
+++ b/browser/components/places/tests/browser/head.js
@@ -386,18 +386,22 @@ var waitForCondition = async function(co
* dialog window
* @param [optional] blur
* whether to blur at the end.
*/
function fillBookmarkTextField(id, text, win, blur = true) {
let elt = win.document.getElementById(id);
elt.focus();
elt.select();
- for (let c of text.split("")) {
- EventUtils.synthesizeKey(c, {}, win);
+ if (!text) {
+ EventUtils.synthesizeKey("VK_DELETE", {}, win);
+ } else {
+ for (let c of text.split("")) {
+ EventUtils.synthesizeKey(c, {}, win);
+ }
}
if (blur)
elt.blur();
}
/**
* Executes a task after opening the bookmarks or history sidebar. Takes care
* of closing the sidebar once done.