michael@0: function invokeUsingCtrlD(phase) { michael@0: switch (phase) { michael@0: case 1: michael@0: EventUtils.synthesizeKey("d", { accelKey: true }); michael@0: break; michael@0: case 2: michael@0: case 4: michael@0: EventUtils.synthesizeKey("VK_ESCAPE", {}); michael@0: break; michael@0: case 3: michael@0: EventUtils.synthesizeKey("d", { accelKey: true }); michael@0: EventUtils.synthesizeKey("d", { accelKey: true }); michael@0: break; michael@0: } michael@0: } michael@0: michael@0: function invokeUsingStarButton(phase) { michael@0: switch (phase) { michael@0: case 1: michael@0: EventUtils.synthesizeMouseAtCenter(BookmarkingUI.star, {}); michael@0: break; michael@0: case 2: michael@0: case 4: michael@0: EventUtils.synthesizeKey("VK_ESCAPE", {}); michael@0: break; michael@0: case 3: michael@0: EventUtils.synthesizeMouseAtCenter(BookmarkingUI.star, michael@0: { clickCount: 2 }); michael@0: break; michael@0: } michael@0: } michael@0: michael@0: var testURL = "data:text/plain,Content"; michael@0: var bookmarkId; michael@0: michael@0: function add_bookmark(aURI, aTitle) { michael@0: return PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId, michael@0: aURI, PlacesUtils.bookmarks.DEFAULT_INDEX, michael@0: aTitle); michael@0: } michael@0: michael@0: // test bug 432599 michael@0: function test() { michael@0: waitForExplicitFinish(); michael@0: michael@0: gBrowser.selectedTab = gBrowser.addTab(); michael@0: gBrowser.selectedBrowser.addEventListener("load", function onLoad() { michael@0: gBrowser.selectedBrowser.removeEventListener("load", onLoad, true); michael@0: waitForStarChange(false, initTest); michael@0: }, true); michael@0: michael@0: content.location = testURL; michael@0: } michael@0: michael@0: function initTest() { michael@0: // First, bookmark the page. michael@0: bookmarkId = add_bookmark(makeURI(testURL), "Bug 432599 Test"); michael@0: michael@0: checkBookmarksPanel(invokers[currentInvoker], 1); michael@0: } michael@0: michael@0: function waitForStarChange(aValue, aCallback) { michael@0: let expectedStatus = aValue ? BookmarkingUI.STATUS_STARRED michael@0: : BookmarkingUI.STATUS_UNSTARRED; michael@0: if (BookmarkingUI.status == BookmarkingUI.STATUS_UPDATING || michael@0: BookmarkingUI.status != expectedStatus) { michael@0: info("Waiting for star button change."); michael@0: setTimeout(waitForStarChange, 50, aValue, aCallback); michael@0: return; michael@0: } michael@0: aCallback(); michael@0: } michael@0: michael@0: let invokers = [invokeUsingStarButton, invokeUsingCtrlD]; michael@0: let currentInvoker = 0; michael@0: michael@0: let initialValue; michael@0: let initialRemoveHidden; michael@0: michael@0: let popupElement = document.getElementById("editBookmarkPanel"); michael@0: let titleElement = document.getElementById("editBookmarkPanelTitle"); michael@0: let removeElement = document.getElementById("editBookmarkPanelRemoveButton"); michael@0: michael@0: function checkBookmarksPanel(invoker, phase) michael@0: { michael@0: let onPopupShown = function(aEvent) { michael@0: if (aEvent.originalTarget == popupElement) { michael@0: popupElement.removeEventListener("popupshown", arguments.callee, false); michael@0: checkBookmarksPanel(invoker, phase + 1); michael@0: } michael@0: }; michael@0: let onPopupHidden = function(aEvent) { michael@0: if (aEvent.originalTarget == popupElement) { michael@0: popupElement.removeEventListener("popuphidden", arguments.callee, false); michael@0: if (phase < 4) { michael@0: checkBookmarksPanel(invoker, phase + 1); michael@0: } else { michael@0: ++currentInvoker; michael@0: if (currentInvoker < invokers.length) { michael@0: checkBookmarksPanel(invokers[currentInvoker], 1); michael@0: } else { michael@0: gBrowser.removeCurrentTab(); michael@0: PlacesUtils.bookmarks.removeItem(bookmarkId); michael@0: executeSoon(finish); michael@0: } michael@0: } michael@0: } michael@0: }; michael@0: michael@0: switch (phase) { michael@0: case 1: michael@0: case 3: michael@0: popupElement.addEventListener("popupshown", onPopupShown, false); michael@0: break; michael@0: case 2: michael@0: popupElement.addEventListener("popuphidden", onPopupHidden, false); michael@0: initialValue = titleElement.value; michael@0: initialRemoveHidden = removeElement.hidden; michael@0: break; michael@0: case 4: michael@0: popupElement.addEventListener("popuphidden", onPopupHidden, false); michael@0: is(titleElement.value, initialValue, "The bookmark panel's title should be the same"); michael@0: is(removeElement.hidden, initialRemoveHidden, "The bookmark panel's visibility should not change"); michael@0: break; michael@0: } michael@0: invoker(phase); michael@0: }