From 412b4d1fc989cd01e590b6c998023e9b029fd72d Mon Sep 17 00:00:00 2001 From: Ehsan Akhgari Date: Thu, 18 Dec 2008 23:42:40 +0330 Subject: [PATCH] Bug 432599 - Double-click on the Star icon leads to incorrect display of the bookmark properties panel; r=mano --- browser/base/content/browser-places.js | 19 ++- browser/base/content/test/Makefile.in | 1 + .../base/content/test/browser_bug432599.js | 109 ++++++++++++++++++ 3 files changed, 118 insertions(+), 11 deletions(-) create mode 100644 browser/base/content/test/browser_bug432599.js diff --git a/browser/base/content/browser-places.js b/browser/base/content/browser-places.js index 1a48ce04d40..ffb521235fa 100644 --- a/browser/base/content/browser-places.js +++ b/browser/base/content/browser-places.js @@ -22,6 +22,7 @@ # Annie Sullivan # Joe Hughes # Asaf Romano +# Ehsan Akhgari # # Alternatively, the contents of this file may be used under the terms of # either the GNU General Public License Version 2 or later (the "GPL"), or @@ -166,6 +167,9 @@ var StarUI = { _doShowEditBookmarkPanel: function SU__doShowEditBookmarkPanel(aItemId, aAnchorElement, aPosition) { + if (this.panel.state != "closed") + return; + this._blockCommands(); // un-done in the popuphiding handler var bundle = this._element("bundle_browser"); @@ -216,17 +220,10 @@ var StarUI = { isTransient: false, merge: function() { return false; } }); - if (this.panel.state == "closed") { - // Consume dismiss clicks, see bug 400924 - this.panel.popupBoxObject - .setConsumeRollupEvent(Ci.nsIPopupBoxObject.ROLLUP_CONSUME); - this.panel.openPopup(aAnchorElement, aPosition, -1, -1); - } - else { - var namePicker = this._element("editBMPanel_namePicker"); - namePicker.focus(); - namePicker.editor.selectAll(); - } + // Consume dismiss clicks, see bug 400924 + this.panel.popupBoxObject + .setConsumeRollupEvent(Ci.nsIPopupBoxObject.ROLLUP_CONSUME); + this.panel.openPopup(aAnchorElement, aPosition, -1, -1); gEditItemOverlay.initPanel(this._itemId, { hiddenRows: ["description", "location", diff --git a/browser/base/content/test/Makefile.in b/browser/base/content/test/Makefile.in index c94c7fe8d38..9b45687268f 100644 --- a/browser/base/content/test/Makefile.in +++ b/browser/base/content/test/Makefile.in @@ -60,6 +60,7 @@ _BROWSER_FILES = browser_bug321000.js \ browser_bug409481.js \ browser_bug413915.js \ browser_bug420160.js \ + browser_bug432599.js \ browser_bug427559.js \ browser_bug441778.js \ browser_discovery.js \ diff --git a/browser/base/content/test/browser_bug432599.js b/browser/base/content/test/browser_bug432599.js new file mode 100644 index 00000000000..a358e55f5a7 --- /dev/null +++ b/browser/base/content/test/browser_bug432599.js @@ -0,0 +1,109 @@ +function invokeUsingCtrlD(phase) { + switch (phase) { + case 1: + EventUtils.synthesizeKey("d", { accelKey: true }); + break; + case 2: + case 4: + EventUtils.synthesizeKey("VK_ESCAPE", {}); + break; + case 3: + EventUtils.synthesizeKey("d", { accelKey: true }); + EventUtils.synthesizeKey("d", { accelKey: true }); + break; + } +} + +function invokeUsingStarButton(phase) { + switch (phase) { + case 1: + EventUtils.sendMouseEvent({ type: "click" }, "star-button"); + break; + case 2: + case 4: + EventUtils.synthesizeKey("VK_ESCAPE", {}); + break; + case 3: + EventUtils.synthesizeMouse(document.getElementById("star-button"), + 1, 1, { clickCount: 2 }); + break; + } +} + +// test bug 432599 +function test() { + waitForExplicitFinish(); + + let testTab = gBrowser.addTab(); + gBrowser.selectedTab = testTab; + let testBrowser = gBrowser.getBrowserForTab(testTab); + testBrowser.addEventListener("load", initTest, true); + + testBrowser.contentWindow.location = "data:text/plain,Content"; +} + +let invokers = [invokeUsingStarButton, invokeUsingCtrlD]; +let currentInvoker = 0; + +function initTest() { + // first, bookmark the page + let app = Components.classes["@mozilla.org/fuel/application;1"] + .getService(Components.interfaces.fuelIApplication); + let ios = Components.classes["@mozilla.org/network/io-service;1"] + .getService(Ci.nsIIOService); + app.bookmarks.toolbar.addBookmark("Bug 432599 Test", + ios.newURI("data:text/plain,Content", null, null)); + + checkBookmarksPanel(invokers[currentInvoker], 1); +} + +let initialValue; +let initialRemoveHidden; + +let popupElement = document.getElementById("editBookmarkPanel"); +let titleElement = document.getElementById("editBookmarkPanelTitle"); +let removeElement = document.getElementById("editBookmarkPanelRemoveButton"); + +function checkBookmarksPanel(invoker, phase) +{ + let onPopupShown = function(aEvent) { + if (aEvent.originalTarget == popupElement) { + checkBookmarksPanel(invoker, phase + 1); + popupElement.removeEventListener("popupshown", onPopupShown, false); + } + }; + let onPopupHidden = function(aEvent) { + if (aEvent.originalTarget == popupElement) { + if (phase < 4) { + checkBookmarksPanel(invoker, phase + 1); + } else { + ++ currentInvoker; + if (currentInvoker < invokers.length) { + checkBookmarksPanel(invokers[currentInvoker], 1); + } else { + gBrowser.removeCurrentTab(); + finish(); + } + } + popupElement.removeEventListener("popuphidden", onPopupHidden, false); + } + }; + + switch (phase) { + case 1: + case 3: + popupElement.addEventListener("popupshown", onPopupShown, false); + break; + case 2: + popupElement.addEventListener("popuphidden", onPopupHidden, false); + initialValue = titleElement.value; + initialRemoveHidden = removeElement.hidden; + break; + case 4: + popupElement.addEventListener("popuphidden", onPopupHidden, false); + is(titleElement.value, initialValue, "The bookmark panel's title should be the same"); + is(removeElement.hidden, initialRemoveHidden, "The bookmark panel's visibility should not change"); + break; + } + invoker(phase); +}