Backed out changeset b7450f64aa87 (bug 1219794) for adding a failing test

This commit is contained in:
Wes Kocher 2016-02-18 17:05:09 -08:00
parent 6026a7a80a
commit 23fbb39083
5 changed files with 74 additions and 326 deletions

View File

@ -9,8 +9,6 @@ var StarUI = {
_itemId: -1,
uri: null,
_batching: false,
_isNewBookmark: false,
_autoCloseTimer: 0,
_element: function(aID) {
return document.getElementById(aID);
@ -23,11 +21,8 @@ var StarUI = {
// initially the panel is hidden
// to avoid impacting startup / new window performance
element.hidden = false;
element.addEventListener("keypress", this, false);
element.addEventListener("mouseout", this, false);
element.addEventListener("mouseover", this, false);
element.addEventListener("popuphidden", this, false);
element.addEventListener("popupshown", this, false);
element.addEventListener("keypress", this, false);
return this.panel = element;
},
@ -63,11 +58,7 @@ var StarUI = {
// nsIDOMEventListener
handleEvent(aEvent) {
switch (aEvent.type) {
case "mouseover":
clearTimeout(this._autoCloseTimer);
break;
case "popuphidden":
clearTimeout(this._autoCloseTimer);
if (aEvent.originalTarget == this.panel) {
if (!this._element("editBookmarkPanelContent").hidden)
this.quitEditMode();
@ -81,42 +72,44 @@ var StarUI = {
if (this._batching)
this.endBatch();
if (this._uriForRemoval) {
if (this._isNewBookmark) {
if (!PlacesUtils.useAsyncTransactions) {
switch (this._actionOnHide) {
case "cancel": {
if (!PlacesUIUtils.useAsyncTransactions) {
PlacesUtils.transactionManager.undoTransaction();
break;
}
PlacesTransactions().undo().catch(Cu.reportError);
PlacesTransactions.undo().catch(Cu.reportError);
break;
}
// Remove all bookmarks for the bookmark's url, this also removes
// the tags for the url.
if (!PlacesUIUtils.useAsyncTransactions) {
let itemIds = PlacesUtils.getBookmarksForURI(this._uriForRemoval);
for (let itemId of itemIds) {
let txn = new PlacesRemoveItemTransaction(itemId);
PlacesUtils.transactionManager.doTransaction(txn);
case "remove": {
// Remove all bookmarks for the bookmark's url, this also removes
// the tags for the url.
if (!PlacesUIUtils.useAsyncTransactions) {
let itemIds = PlacesUtils.getBookmarksForURI(this._uriForRemoval);
for (let itemId of itemIds) {
let txn = new PlacesRemoveItemTransaction(itemId);
PlacesUtils.transactionManager.doTransaction(txn);
}
break;
}
PlacesTransactions.RemoveBookmarksForUrls(this._uriForRemoval)
.transact().catch(Cu.reportError);
break;
}
PlacesTransactions.RemoveBookmarksForUrls([this._uriForRemoval])
.transact().catch(Cu.reportError);
}
this._actionOnHide = "";
}
break;
case "keypress":
clearTimeout(this._autoCloseTimer);
if (aEvent.defaultPrevented) {
// The event has already been consumed inside of the panel.
break;
}
switch (aEvent.keyCode) {
case KeyEvent.DOM_VK_ESCAPE:
this.panel.hidePopup();
if (!this._element("editBookmarkPanelContent").hidden)
this.cancelButtonOnCommand();
break;
case KeyEvent.DOM_VK_RETURN:
if (aEvent.target.classList.contains("expander-up") ||
@ -130,33 +123,12 @@ var StarUI = {
break;
}
break;
case "mouseout": {
// Don't handle events for descendent elements.
if (aEvent.target != aEvent.currentTarget) {
break;
}
// Explicit fall-through
}
case "popupshown":
// auto-close if new and not interacted with
if (this._isNewBookmark) {
// 3500ms matches the timeout that Pocket uses in
// browser/extensions/pocket/content/panels/js/saved.js
let delay = 3500;
if (this._closePanelQuickForTesting) {
delay /= 10;
}
this._autoCloseTimer = setTimeout(() => this.panel.hidePopup(), delay, this);
}
break;
}
},
_overlayLoaded: false,
_overlayLoading: false,
showEditBookmarkPopup: Task.async(function* (aNode, aAnchorElement, aPosition, aIsNewBookmark) {
this._isNewBookmark = aIsNewBookmark;
this._uriForRemoval = "";
showEditBookmarkPopup: Task.async(function* (aNode, aAnchorElement, aPosition) {
// TODO: Deprecate this once async transactions are enabled and the legacy
// transactions code is gone (bug 1131491) - we don't want addons to to use
// the completeNodeLikeObjectForItemId, so it's better if they keep passing
@ -205,18 +177,26 @@ var StarUI = {
if (this.panel.state != "closed")
return;
this._blockCommands(); // un-done in the popuphidden handler
this._blockCommands(); // un-done in the popuphiding handler
// Set panel title:
// if we are batching, i.e. the bookmark has been added now,
// then show Page Bookmarked, else if the bookmark did already exist,
// we are about editing it, then use Edit This Bookmark.
this._element("editBookmarkPanelTitle").value =
this._isNewBookmark ?
this._batching ?
gNavigatorBundle.getString("editBookmarkPanel.pageBookmarkedTitle") :
gNavigatorBundle.getString("editBookmarkPanel.editBookmarkTitle");
// No description; show the Done, Remove;
// No description; show the Done, Cancel;
this._element("editBookmarkPanelDescription").textContent = "";
this._element("editBookmarkPanelBottomButtons").hidden = false;
this._element("editBookmarkPanelContent").hidden = false;
// The remove button is shown only if we're not already batching, i.e.
// if the cancel button/ESC does not remove the bookmark.
this._element("editBookmarkPanelRemoveButton").hidden = this._batching;
// The label of the remove button differs if the URI is bookmarked
// multiple times.
let bookmarks = PlacesUtils.getBookmarksForURI(gBrowser.currentURI);
@ -270,8 +250,14 @@ var StarUI = {
gEditItemOverlay.uninitPanel(true);
},
cancelButtonOnCommand: function SU_cancelButtonOnCommand() {
this._actionOnHide = "cancel";
this.panel.hidePopup(true);
},
removeBookmarkButtonCommand: function SU_removeBookmarkButtonCommand() {
this._uriForRemoval = PlacesUtils.bookmarks.getBookmarkURI(this._itemId);
this._actionOnHide = "remove";
this.panel.hidePopup();
},
@ -339,8 +325,7 @@ var PlacesCommandHook = {
var uri = aBrowser.currentURI;
var itemId = PlacesUtils.getMostRecentBookmarkForURI(uri);
let isNewBookmark = itemId == -1;
if (isNewBookmark) {
if (itemId == -1) {
// Bug 1148838 - Make this code work for full page plugins.
var title;
var description;
@ -357,10 +342,10 @@ var PlacesCommandHook = {
}
catch (e) { }
if (aShowEditUI && isNewBookmark) {
// If we bookmark the page here but open right into a cancelable
// state (i.e. new bookmark in Library), start batching here so
// all of the actions can be undone in a single undo step.
if (aShowEditUI) {
// If we bookmark the page here (i.e. page was not "starred" already)
// but open right into the "edit" state, start batching here, so
// "Cancel" in that state removes the bookmark.
StarUI.beginBatch();
}
@ -391,16 +376,16 @@ var PlacesCommandHook = {
// 3. the content area
if (BookmarkingUI.anchor) {
StarUI.showEditBookmarkPopup(itemId, BookmarkingUI.anchor,
"bottomcenter topright", isNewBookmark);
"bottomcenter topright");
return;
}
let identityIcon = document.getElementById("identity-icon");
if (isElementVisible(identityIcon)) {
StarUI.showEditBookmarkPopup(itemId, identityIcon,
"bottomcenter topright", isNewBookmark);
"bottomcenter topright");
} else {
StarUI.showEditBookmarkPopup(itemId, aBrowser, "overlap", isNewBookmark);
StarUI.showEditBookmarkPopup(itemId, aBrowser, "overlap");
}
}),
@ -409,7 +394,6 @@ var PlacesCommandHook = {
_bookmarkPagePT: Task.async(function* (aBrowser, aParentId, aShowEditUI) {
let url = new URL(aBrowser.currentURI.spec);
let info = yield PlacesUtils.bookmarks.fetch({ url });
let isNewBookmark = !info;
if (!info) {
let parentGuid = aParentId !== undefined ?
yield PlacesUtils.promiseItemGuid(aParentId) :
@ -433,10 +417,10 @@ var PlacesCommandHook = {
Components.utils.reportError(e);
}
if (aShowEditUI && isNewBookmark) {
// If we bookmark the page here but open right into a cancelable
// state (i.e. new bookmark in Library), start batching here so
// all of the actions can be undone in a single undo step.
if (aShowEditUI) {
// If we bookmark the page here (i.e. page was not "starred" already)
// but open right into the "edit" state, start batching here, so
// "Cancel" in that state removes the bookmark.
StarUI.beginBatch();
}
@ -468,16 +452,16 @@ var PlacesCommandHook = {
// 3. the content area
if (BookmarkingUI.anchor) {
StarUI.showEditBookmarkPopup(node, BookmarkingUI.anchor,
"bottomcenter topright", isNewBookmark);
"bottomcenter topright");
return;
}
let identityIcon = document.getElementById("identity-icon");
if (isElementVisible(identityIcon)) {
StarUI.showEditBookmarkPopup(node, identityIcon,
"bottomcenter topright", isNewBookmark);
"bottomcenter topright");
} else {
StarUI.showEditBookmarkPopup(node, aBrowser, "overlap", isNewBookmark);
StarUI.showEditBookmarkPopup(node, aBrowser, "overlap");
}
}),
@ -1719,15 +1703,19 @@ var BookmarkingUI = {
let widget = CustomizableUI.getWidget(this.BOOKMARK_BUTTON_ID)
.forWindow(window);
if (widget.overflowed) {
// Close the overflow panel because the Edit Bookmark panel will appear.
widget.node.removeAttribute("closemenu");
// Allow to close the panel if the page is already bookmarked, cause
// we are going to open the edit bookmark panel.
if (isBookmarked)
widget.node.removeAttribute("closemenu");
else
widget.node.setAttribute("closemenu", "none");
}
// Ignore clicks on the star if we are updating its state.
if (!this._pendingStmt) {
if (!isBookmarked)
this._showBookmarkedNotification();
PlacesCommandHook.bookmarkCurrentPage(true);
PlacesCommandHook.bookmarkCurrentPage(isBookmarked);
}
},

View File

@ -180,6 +180,12 @@
<vbox>
<label id="editBookmarkPanelTitle"/>
<description id="editBookmarkPanelDescription"/>
<hbox>
<button id="editBookmarkPanelRemoveButton"
class="editBookmarkPanelHeaderButton"
oncommand="StarUI.removeBookmarkButtonCommand();"
accesskey="&editBookmark.removeBookmark.accessKey;"/>
</hbox>
</vbox>
</row>
<vbox id="editBookmarkPanelContent" flex="1" hidden="true"/>
@ -190,15 +196,15 @@
label="&editBookmark.done.label;"
default="true"
oncommand="StarUI.panel.hidePopup();"/>
<button id="editBookmarkPanelRemoveButton"
<button id="editBookmarkPanelDeleteButton"
class="editBookmarkPanelBottomButton"
oncommand="StarUI.removeBookmarkButtonCommand();"
accesskey="&editBookmark.removeBookmark.accessKey;"/>
label="&editBookmark.cancel.label;"
oncommand="StarUI.cancelButtonOnCommand();"/>
#else
<button id="editBookmarkPanelRemoveButton"
<button id="editBookmarkPanelDeleteButton"
class="editBookmarkPanelBottomButton"
oncommand="StarUI.removeBookmarkButtonCommand();"
accesskey="&editBookmark.removeBookmark.accessKey;"/>
label="&editBookmark.cancel.label;"
oncommand="StarUI.cancelButtonOnCommand();"/>
<button id="editBookmarkPanelDoneButton"
class="editBookmarkPanelBottomButton"
label="&editBookmark.done.label;"

View File

@ -153,7 +153,6 @@ skip-if = e10s # Bug 1101993 - times out for unknown reasons when run in the dir
skip-if = os == "mac" # The Fitt's Law back button is not supported on OS X
[browser_beforeunload_duplicate_dialogs.js]
[browser_blob-channelname.js]
[browser_bookmark_popup.js]
[browser_bookmark_titles.js]
skip-if = buildapp == 'mulet' || toolkit == "windows" # Disabled on Windows due to frequent failures (bugs 825739, 841341)
[browser_bug304198.js]

View File

@ -1,246 +0,0 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
/**
* Test opening and closing the bookmarks panel.
*/
let bookmarkPanel = document.getElementById("editBookmarkPanel");
let bookmarkStar = document.getElementById("bookmarks-menu-button");
let bookmarkPanelTitle = document.getElementById("editBookmarkPanelTitle");
StarUI._closePanelQuickForTesting = true;
Services.prefs.setBoolPref("browser.bookmarks.closePanelQuickForTesting", true);
function* test_bookmarks_popup({isNewBookmark, popupShowFn, popupEditFn,
shouldAutoClose, popupHideFn, isBookmarkRemoved}) {
let tab = yield BrowserTestUtils.openNewForegroundTab(gBrowser, "about:home");
try {
if (!isNewBookmark) {
yield PlacesUtils.bookmarks.insert({
parentGuid: PlacesUtils.bookmarks.unfiledGuid,
url: "about:home",
title: "Home Page"
});
}
is(bookmarkStar.hasAttribute("starred"), !isNewBookmark,
"Page should only be starred prior to popupshown if editing bookmark");
let shownPromise = promisePopupShown(bookmarkPanel);
yield popupShowFn(tab.linkedBrowser);
yield shownPromise;
if (popupEditFn) {
yield popupEditFn();
}
let bookmarks = [];
yield PlacesUtils.bookmarks.fetch({url: "about:home"}, bm => bookmarks.push(bm));
is(bookmarks.length, 1, "Only one bookmark should exist");
is(bookmarkStar.getAttribute("starred"), "true", "Page is starred");
is(bookmarkPanel.state, "open", "Check that panel state is 'open'");
is(bookmarkPanelTitle.value,
isNewBookmark ?
gNavigatorBundle.getString("editBookmarkPanel.pageBookmarkedTitle") :
gNavigatorBundle.getString("editBookmarkPanel.editBookmarkTitle"),
"title should match isEditingBookmark state");
if (!shouldAutoClose) {
yield new Promise(resolve => setTimeout(resolve, 400));
}
let hiddenPromise = promisePopupHidden(bookmarkPanel);
if (popupHideFn) {
yield popupHideFn();
}
yield hiddenPromise;
is(bookmarkStar.hasAttribute("starred"), !isBookmarkRemoved,
"Page is starred after closing");
} finally {
let bookmark = yield PlacesUtils.bookmarks.fetch({url: "about:home"});
is(!!bookmark, !isBookmarkRemoved,
"bookmark should not be present if a panel action should've removed it");
if (bookmark) {
yield PlacesUtils.bookmarks.remove(bookmark);
}
gBrowser.removeTab(tab);
}
}
add_task(function* panel_shown_for_new_bookmarks_and_autocloses() {
yield test_bookmarks_popup({
isNewBookmark: true,
popupShowFn() {
bookmarkStar.click();
},
shouldAutoClose: true,
isBookmarkRemoved: false,
});
});
add_task(function* panel_shown_for_once_for_doubleclick_on_new_bookmark_star_and_autocloses() {
yield test_bookmarks_popup({
isNewBookmark: true,
popupShowFn() {
EventUtils.synthesizeMouse(bookmarkStar, 10, 10, { clickCount: 2 },
window);
},
shouldAutoClose: true,
isBookmarkRemoved: false,
});
});
add_task(function* panel_shown_once_for_slow_doubleclick_on_new_bookmark_star_and_autocloses() {
yield test_bookmarks_popup({
isNewBookmark: true,
*popupShowFn() {
EventUtils.synthesizeMouse(bookmarkStar, 10, 10, window);
yield new Promise(resolve => setTimeout(resolve, 500));
EventUtils.synthesizeMouse(bookmarkStar, 10, 10, window);
},
shouldAutoClose: true,
isBookmarkRemoved: false,
});
});
add_task(function* panel_shown_for_keyboardshortcut_on_new_bookmark_star_and_autocloses() {
yield test_bookmarks_popup({
isNewBookmark: true,
popupShowFn() {
EventUtils.synthesizeKey("D", {accelKey: true}, window);
},
shouldAutoClose: true,
isBookmarkRemoved: false,
});
});
add_task(function* panel_shown_for_new_bookmarks_mouseover_mouseout() {
yield test_bookmarks_popup({
isNewBookmark: true,
popupShowFn() {
bookmarkStar.click();
},
*popupEditFn() {
yield new Promise(resolve => {
EventUtils.synthesizeNativeMouseMove(bookmarkPanel, 0, 0, resolve, window);
});
yield new Promise(resolve => setTimeout(resolve, 400));
is(bookmarkPanel.state, "open", "Panel should still be open on mouseover");
yield new Promise(resolve => {
EventUtils.synthesizeNativeMouseMove(bookmarkStar, 0, 0, resolve, window);
});
info("Should autoclose now on mouseout");
},
shouldAutoClose: true,
isBookmarkRemoved: false,
});
});
add_task(function* panel_shown_for_new_bookmark_no_autoclose_close_with_ESC() {
yield test_bookmarks_popup({
isNewBookmark: false,
popupShowFn() {
bookmarkStar.click();
},
shouldAutoClose: false,
popupHideFn() {
EventUtils.synthesizeKey("VK_ESCAPE", {accelKey: true}, window);
},
isBookmarkRemoved: false,
});
});
add_task(function* panel_shown_for_editing_no_autoclose_close_with_ESC() {
yield test_bookmarks_popup({
isNewBookmark: false,
popupShowFn() {
bookmarkStar.click();
},
shouldAutoClose: false,
popupHideFn() {
EventUtils.synthesizeKey("VK_ESCAPE", {accelKey: true}, window);
},
isBookmarkRemoved: false,
});
});
add_task(function* panel_shown_for_new_bookmark_keypress_no_autoclose() {
yield test_bookmarks_popup({
isNewBookmark: true,
popupShowFn() {
bookmarkStar.click();
},
popupEditFn() {
EventUtils.sendChar("VK_TAB", window);
},
shouldAutoClose: false,
popupHideFn() {
bookmarkPanel.hidePopup();
},
isBookmarkRemoved: false,
});
});
add_task(function* contextmenu_new_bookmark_click_no_autoclose() {
yield test_bookmarks_popup({
isNewBookmark: true,
*popupShowFn(browser) {
let contextMenu = document.getElementById("contentAreaContextMenu");
let awaitPopupShown = BrowserTestUtils.waitForEvent(contextMenu,
"popupshown");
let awaitPopupHidden = BrowserTestUtils.waitForEvent(contextMenu,
"popuphidden");
yield BrowserTestUtils.synthesizeMouseAtCenter("body", {
type: "contextmenu",
button: 2
}, browser);
yield awaitPopupShown;
document.getElementById("context-bookmarkpage").click();
contextMenu.hidePopup();
yield awaitPopupHidden;
},
popupEditFn() {
bookmarkPanelTitle.click();
},
shouldAutoClose: false,
popupHideFn() {
bookmarkPanel.hidePopup();
},
isBookmarkRemoved: false,
});
});
add_task(function* bookmarks_menu_new_bookmark_remove_bookmark() {
yield test_bookmarks_popup({
isNewBookmark: true,
popupShowFn(browser) {
document.getElementById("menu_bookmarkThisPage").doCommand();
},
shouldAutoClose: true,
popupHideFn() {
document.getElementById("editBookmarkPanelRemoveButton").click();
},
isBookmarkRemoved: true,
});
});
add_task(function* ctrl_d_edit_bookmark_remove_bookmark() {
yield test_bookmarks_popup({
isNewBookmark: false,
popupShowFn(browser) {
EventUtils.synthesizeKey("D", {accelKey: true}, window);
},
shouldAutoClose: true,
popupHideFn() {
document.getElementById("editBookmarkPanelRemoveButton").click();
},
isBookmarkRemoved: true,
});
});
registerCleanupFunction(function() {
Services.prefs.clearUserPref("browser.bookmarks.closePanelQuickForTesting");
delete StarUI._closePanelQuickForTesting;
})

View File

@ -744,6 +744,7 @@ you can use these alternative items. Otherwise, their values should be empty. -
<!ENTITY spellAddDictionaries.accesskey "A">
<!ENTITY editBookmark.done.label "Done">
<!ENTITY editBookmark.cancel.label "Cancel">
<!ENTITY editBookmark.removeBookmark.accessKey "R">
<!ENTITY identity.connectionSecure "Secure Connection">