Backed out changeset 8107b1fc07e0 (bug 1812083) for causing failures at browser_bookmarks_change_url.js. CLOSED TREE

This commit is contained in:
Butkovits Atila 2023-02-17 07:14:36 +02:00
parent b778f2672a
commit 7d923b6c43
18 changed files with 410 additions and 1533 deletions

View file

@ -1269,11 +1269,7 @@ pref("browser.bookmarks.editDialog.maxRecentFolders", 7);
// By default the Edit Bookmark dialog is instant-apply. This feature pref will allow to // By default the Edit Bookmark dialog is instant-apply. This feature pref will allow to
// just save on Accept, once the project is complete. // just save on Accept, once the project is complete.
#ifdef NIGHTLY_BUILD pref("browser.bookmarks.editDialog.delayedApply.enabled", false);
pref("browser.bookmarks.editDialog.delayedApply.enabled", true);
#else
pref("browser.bookmarks.editDialog.delayedApply.enabled", false);
#endif
#if defined(XP_WIN) && defined(MOZ_SANDBOX) #if defined(XP_WIN) && defined(MOZ_SANDBOX)
// This controls the strength of the Windows content process sandbox for // This controls the strength of the Windows content process sandbox for

View file

@ -204,11 +204,11 @@ var StarUI = {
return; return;
} }
await this._storeRecentlyUsedFolder(selectedFolderGuid, didChangeFolder);
await bookmarkState.save(); await bookmarkState.save();
if (this._isNewBookmark) { if (this._isNewBookmark) {
this.showConfirmation(); this.showConfirmation();
} }
await this._storeRecentlyUsedFolder(selectedFolderGuid, didChangeFolder);
}, },
/** /**

View file

@ -30,107 +30,86 @@ add_task(async function bookmark() {
// Open a unique page. // Open a unique page.
// eslint-disable-next-line @microsoft/sdl/no-insecure-url // eslint-disable-next-line @microsoft/sdl/no-insecure-url
let url = "http://example.com/browser_page_action_menu"; let url = "http://example.com/browser_page_action_menu";
await BrowserTestUtils.withNewTab(url, async () => {
// The bookmark button should read "Bookmark this page ([shortcut])" and not
// be starred.
let bookmarkButton = BrowserPageActions.urlbarButtonNodeForActionID(
"bookmark"
);
let tooltipText = bookmarkButton.getAttribute("tooltiptext");
Assert.ok(
tooltipText.startsWith("Bookmark this page"),
`Expecting the tooltip text to be updated. Tooltip text: ${tooltipText}`
);
Assert.ok(!bookmarkButton.hasAttribute("starred"));
// Open a new window with delayed apply mode disabled. In the new window, info("Click the button.");
// opening the star panel should instantly create a new bookmark. // The button ignores activation while the bookmarked status is being
await SpecialPowers.pushPrefEnv({ // updated. So, wait for it to finish updating.
set: [["browser.bookmarks.editDialog.delayedApply.enabled", false]], await TestUtils.waitForCondition(
() => BookmarkingUI.status != BookmarkingUI.STATUS_UPDATING
);
let onItemAddedPromise = PlacesTestUtils.waitForNotification(
"bookmark-added",
events => events.some(event => event.url == url)
);
let promise = BrowserTestUtils.waitForPopupEvent(StarUI.panel, "shown");
EventUtils.synthesizeMouseAtCenter(bookmarkButton, {});
await promise;
await onItemAddedPromise;
Assert.equal(
BookmarkingUI.starBox.getAttribute("open"),
"true",
"Star has open attribute"
);
// The bookmark button should now read "Edit this bookmark ([shortcut])" and
// be starred.
tooltipText = bookmarkButton.getAttribute("tooltiptext");
Assert.ok(
tooltipText.startsWith("Edit this bookmark"),
`Expecting the tooltip text to be updated. Tooltip text: ${tooltipText}`
);
Assert.equal(bookmarkButton.firstChild.getAttribute("starred"), "true");
StarUI.panel.hidePopup();
Assert.ok(
!BookmarkingUI.starBox.hasAttribute("open"),
"Star no longer has open attribute"
);
info("Click it again.");
// The button ignores activation while the bookmarked status is being
// updated. So, wait for it to finish updating.
await TestUtils.waitForCondition(
() => BookmarkingUI.status != BookmarkingUI.STATUS_UPDATING
);
promise = BrowserTestUtils.waitForPopupEvent(StarUI.panel, "shown");
EventUtils.synthesizeMouseAtCenter(bookmarkButton, {});
await promise;
let onItemRemovedPromise = PlacesTestUtils.waitForNotification(
"bookmark-removed",
events => events.some(event => event.url == url)
);
// Click the remove-bookmark button in the panel.
StarUI._element("editBookmarkPanelRemoveButton").click();
// Wait for the bookmark to be removed before continuing.
await onItemRemovedPromise;
// Check there's no contextual menu on the button.
let contextMenuPromise = promisePopupNotShown("pageActionContextMenu");
// The button ignores activation while the bookmarked status is being
// updated. So, wait for it to finish updating.
await TestUtils.waitForCondition(
() => BookmarkingUI.status != BookmarkingUI.STATUS_UPDATING
);
EventUtils.synthesizeMouseAtCenter(bookmarkButton, {
type: "contextmenu",
button: 2,
});
await contextMenuPromise;
}); });
const win = await BrowserTestUtils.openNewBrowserWindow();
registerCleanupFunction(async () => {
await BrowserTestUtils.closeWindow(win);
});
await BrowserTestUtils.withNewTab(
{ gBrowser: win.gBrowser, url },
async () => {
// The bookmark button should read "Bookmark this page ([shortcut])" and not
// be starred.
let bookmarkButton = win.BrowserPageActions.urlbarButtonNodeForActionID(
"bookmark"
);
let tooltipText = bookmarkButton.getAttribute("tooltiptext");
Assert.ok(
tooltipText.startsWith("Bookmark this page"),
`Expecting the tooltip text to be updated. Tooltip text: ${tooltipText}`
);
Assert.ok(!bookmarkButton.hasAttribute("starred"));
info("Click the button.");
// The button ignores activation while the bookmarked status is being
// updated. So, wait for it to finish updating.
await TestUtils.waitForCondition(
() => win.BookmarkingUI.status != win.BookmarkingUI.STATUS_UPDATING
);
let onItemAddedPromise = PlacesTestUtils.waitForNotification(
"bookmark-added",
events => events.some(event => event.url == url)
);
let promise = BrowserTestUtils.waitForPopupEvent(
win.StarUI.panel,
"shown"
);
EventUtils.synthesizeMouseAtCenter(bookmarkButton, {}, win);
await promise;
await onItemAddedPromise;
Assert.equal(
win.BookmarkingUI.starBox.getAttribute("open"),
"true",
"Star has open attribute"
);
// The bookmark button should now read "Edit this bookmark ([shortcut])" and
// be starred.
tooltipText = bookmarkButton.getAttribute("tooltiptext");
Assert.ok(
tooltipText.startsWith("Edit this bookmark"),
`Expecting the tooltip text to be updated. Tooltip text: ${tooltipText}`
);
Assert.equal(bookmarkButton.firstChild.getAttribute("starred"), "true");
win.StarUI.panel.hidePopup();
Assert.ok(
!win.BookmarkingUI.starBox.hasAttribute("open"),
"Star no longer has open attribute"
);
info("Click it again.");
// The button ignores activation while the bookmarked status is being
// updated. So, wait for it to finish updating.
await TestUtils.waitForCondition(
() => win.BookmarkingUI.status != win.BookmarkingUI.STATUS_UPDATING
);
promise = BrowserTestUtils.waitForPopupEvent(win.StarUI.panel, "shown");
EventUtils.synthesizeMouseAtCenter(bookmarkButton, {}, win);
await promise;
let onItemRemovedPromise = PlacesTestUtils.waitForNotification(
"bookmark-removed",
events => events.some(event => event.url == url)
);
// Click the remove-bookmark button in the panel.
win.StarUI._element("editBookmarkPanelRemoveButton").click();
// Wait for the bookmark to be removed before continuing.
await onItemRemovedPromise;
// Check there's no contextual menu on the button.
let contextMenuPromise = promisePopupNotShown("pageActionContextMenu");
// The button ignores activation while the bookmarked status is being
// updated. So, wait for it to finish updating.
await TestUtils.waitForCondition(
() => win.BookmarkingUI.status != win.BookmarkingUI.STATUS_UPDATING
);
EventUtils.synthesizeMouseAtCenter(
bookmarkButton,
{
type: "contextmenu",
button: 2,
},
win
);
await contextMenuPromise;
}
);
}); });
add_task(async function bookmarkDelayedApply() { add_task(async function bookmarkDelayedApply() {

View file

@ -282,8 +282,6 @@ class BookmarkState {
* If changes to bookmark fields should be saved immediately after calling * If changes to bookmark fields should be saved immediately after calling
* its respective "changed" method, rather than waiting for save() to be * its respective "changed" method, rather than waiting for save() to be
* called. * called.
* @param {number} [options.index]
* The insertion point index of the bookmark.
*/ */
constructor({ constructor({
info, info,
@ -292,7 +290,6 @@ class BookmarkState {
isFolder = false, isFolder = false,
children = [], children = [],
autosave = false, autosave = false,
index,
}) { }) {
this._guid = info.itemGuid; this._guid = info.itemGuid;
this._postData = info.postData; this._postData = info.postData;
@ -312,7 +309,6 @@ class BookmarkState {
.filter(tag => !!tag.length), .filter(tag => !!tag.length),
keyword, keyword,
parentGuid: info.parentGuid, parentGuid: info.parentGuid,
index,
}; };
// Edited bookmark // Edited bookmark
@ -395,7 +391,6 @@ class BookmarkState {
tags: this._newState.tags, tags: this._newState.tags,
title: this._newState.title ?? this._originalState.title, title: this._newState.title ?? this._originalState.title,
url: this._newState.uri ?? this._originalState.uri, url: this._newState.uri ?? this._originalState.uri,
index: this._originalState.index,
}).transact(); }).transact();
if (this._newState.keyword) { if (this._newState.keyword) {
await lazy.PlacesTransactions.EditKeyword({ await lazy.PlacesTransactions.EditKeyword({
@ -421,7 +416,6 @@ class BookmarkState {
url: item.uri, url: item.uri,
title: item.title, title: item.title,
})), })),
index: this._originalState.index,
}).transact(); }).transact();
return this._guid; return this._guid;
} }

View file

@ -508,7 +508,6 @@ var BookmarkPropertiesPanel = {
? undefined ? undefined
: await PlacesUtils.promiseItemId(parentGuid); : await PlacesUtils.promiseItemId(parentGuid);
return Object.freeze({ return Object.freeze({
index,
itemId, itemId,
bookmarkGuid: itemGuid, bookmarkGuid: itemGuid,
title: this._title, title: this._title,

View file

@ -378,17 +378,6 @@ var gEditItemOverlay = {
); );
} }
// Observe changes.
if (!this._observersAdded) {
this.handlePlacesEvents = this.handlePlacesEvents.bind(this);
PlacesUtils.observers.addListener(
["bookmark-title-changed"],
this.handlePlacesEvents
);
window.addEventListener("unload", this);
this._observersAdded = true;
}
let focusElement = () => { let focusElement = () => {
// The focusedElement possible values are: // The focusedElement possible values are:
// * preferred: focus the field that the user touched first the last // * preferred: focus the field that the user touched first the last
@ -423,7 +412,7 @@ var gEditItemOverlay = {
await this._tagsUpdatePromise; await this._tagsUpdatePromise;
} }
this._bookmarkState = this.makeNewStateObject({ index: aInfo.node?.index }); this._bookmarkState = this.makeNewStateObject();
if (isBookmark || bulkTagging) { if (isBookmark || bulkTagging) {
await this._initAllTags(); await this._initAllTags();
await this._rebuildTagsSelectorList(); await this._rebuildTagsSelectorList();
@ -595,15 +584,6 @@ var gEditItemOverlay = {
} }
} }
if (this._observersAdded) {
PlacesUtils.observers.removeListener(
["bookmark-title-changed"],
this.handlePlacesEvents
);
window.removeEventListener("unload", this);
this._observersAdded = false;
}
if (this._folderMenuListListenerAdded) { if (this._folderMenuListListenerAdded) {
this._folderMenuList.removeEventListener("select", this); this._folderMenuList.removeEventListener("select", this);
this._folderMenuListListenerAdded = false; this._folderMenuListListenerAdded = false;
@ -624,7 +604,7 @@ var gEditItemOverlay = {
); );
}, },
makeNewStateObject(extraOptions) { makeNewStateObject() {
if ( if (
this._paneInfo.isItem || this._paneInfo.isItem ||
this._paneInfo.isTag || this._paneInfo.isTag ||
@ -633,11 +613,7 @@ var gEditItemOverlay = {
const isLibraryWindow = const isLibraryWindow =
document.documentElement.getAttribute("windowtype") === document.documentElement.getAttribute("windowtype") ===
"Places:Organizer"; "Places:Organizer";
const options = { const options = { autosave: isLibraryWindow, info: this._paneInfo };
autosave: isLibraryWindow,
info: this._paneInfo,
...extraOptions,
};
if (this._paneInfo.isBookmark) { if (this._paneInfo.isBookmark) {
options.tags = this._element("tagsField").value; options.tags = this._element("tagsField").value;
@ -681,24 +657,16 @@ var gEditItemOverlay = {
async _updateTags() { async _updateTags() {
this._tagsUpdatePromise = (async () => { this._tagsUpdatePromise = (async () => {
const inputTags = this._getTagsArrayFromTagsInputField(); const inputTags = this._getTagsArrayFromTagsInputField();
const isLibraryWindow =
document.documentElement.getAttribute("windowtype") ===
"Places:Organizer";
await this._bookmarkState._tagsChanged(inputTags); await this._bookmarkState._tagsChanged(inputTags);
delete this._paneInfo._cachedCommonTags;
if (isLibraryWindow) { // Ensure the tagsField is in sync, clean it up from empty tags
// Ensure the tagsField is in sync, clean it up from empty tags const currentTags = this._paneInfo.bulkTagging
delete this._paneInfo._cachedCommonTags; ? this._getCommonTags()
const currentTags = this._paneInfo.bulkTagging : PlacesUtils.tagging.getTagsForURI(this._paneInfo.uri);
? this._getCommonTags() this._initTextField(this._tagsField, currentTags.join(", "), false);
: PlacesUtils.tagging.getTagsForURI(this._paneInfo.uri);
this._initTextField(this._tagsField, currentTags.join(", "), false); await this._initAllTags();
await this._initAllTags();
} else {
// Autosave is disabled. Update _allTags in memory so that the selector
// list shows any new tags that haven't been saved yet.
inputTags.forEach(tag => this._allTags?.set(tag.toLowerCase(), tag));
}
await this._rebuildTagsSelectorList(); await this._rebuildTagsSelectorList();
})().catch(console.error); })().catch(console.error);
await this._tagsUpdatePromise; await this._tagsUpdatePromise;
@ -1104,19 +1072,6 @@ var gEditItemOverlay = {
} }
}, },
async handlePlacesEvents(events) {
for (const event of events) {
switch (event.type) {
case "bookmark-title-changed":
if (this._paneInfo.isItem || this._paneInfo.isTag) {
// This also updates titles of folders in the folder menu list.
this._onItemTitleChange(event.id, event.title, event.guid);
}
break;
}
}
},
toggleItemCheckbox(item) { toggleItemCheckbox(item) {
// Update the tags field when items are checked/unchecked in the listbox // Update the tags field when items are checked/unchecked in the listbox
let tags = this._getTagsArrayFromTagsInputField(); let tags = this._getTagsArrayFromTagsInputField();
@ -1153,30 +1108,6 @@ var gEditItemOverlay = {
this._initTextField(this._tagsField, tags.join(", ")); this._initTextField(this._tagsField, tags.join(", "));
}, },
_onItemTitleChange(aItemId, aNewTitle, aGuid) {
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.children) {
if ("folderGuid" in menuitem && menuitem.folderGuid == aGuid) {
menuitem.label = aNewTitle;
break;
}
}
}
// We need to also update title of recent folders.
if (this._recentFolders) {
for (let folder of this._recentFolders) {
if (folder.folderGuid == aGuid) {
folder.title = aNewTitle;
break;
}
}
}
},
/** /**
* Flag which signals to consumers that this script is loaded, thus delayed * Flag which signals to consumers that this script is loaded, thus delayed
* apply logic should be used. * apply logic should be used.

View file

@ -14,7 +14,6 @@ support-files =
[browser_addBookmarkForFrame.js] [browser_addBookmarkForFrame.js]
skip-if = (verify && debug) skip-if = (verify && debug)
[browser_autoshow_bookmarks_toolbar.js] [browser_autoshow_bookmarks_toolbar.js]
[browser_autoshow_bookmarks_toolbar_delayed_apply.js]
[browser_bookmark_add_tags.js] [browser_bookmark_add_tags.js]
https_first_disabled = true https_first_disabled = true
skip-if = skip-if =
@ -27,12 +26,6 @@ skip-if = os == 'linux' # times out on linux, Bug 1739081
[browser_bookmark_folder_moveability.js] [browser_bookmark_folder_moveability.js]
[browser_bookmark_menu_ctrl_click.js] [browser_bookmark_menu_ctrl_click.js]
[browser_bookmark_popup.js] [browser_bookmark_popup.js]
skip-if =
os == "linux" && asan # Bug 1712814
os == "linux" && tsan # Bug 1712814
os == "linux" && debug # mouseover not reliable on linux debug builds
verify && (os == 'win') # mouseover not reliable on linux debug builds
[browser_bookmark_popup_delayed_apply.js]
skip-if = skip-if =
os == "linux" && asan # Bug 1712814 os == "linux" && asan # Bug 1712814
os == "linux" && tsan # Bug 1712814 os == "linux" && tsan # Bug 1712814

View file

@ -12,10 +12,6 @@ add_setup(async function() {
Services.prefs.clearUserPref(LOCATION_PREF); Services.prefs.clearUserPref(LOCATION_PREF);
await PlacesUtils.bookmarks.eraseEverything(); await PlacesUtils.bookmarks.eraseEverything();
// Panel must be instant apply for tests to pass.
await SpecialPowers.pushPrefEnv({
set: [["browser.bookmarks.editDialog.delayedApply.enabled", false]],
});
win = await BrowserTestUtils.openNewBrowserWindow(); win = await BrowserTestUtils.openNewBrowserWindow();
let oldTimeout = win.StarUI._autoCloseTimeout; let oldTimeout = win.StarUI._autoCloseTimeout;

View file

@ -1,169 +0,0 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
const LOCATION_PREF = "browser.bookmarks.defaultLocation";
const TOOLBAR_VISIBILITY_PREF = "browser.toolbars.bookmarks.visibility";
let bookmarkPanel;
let win;
add_setup(async function() {
Services.prefs.clearUserPref(LOCATION_PREF);
await PlacesUtils.bookmarks.eraseEverything();
// Panel must be delayed apply for tests to pass.
await SpecialPowers.pushPrefEnv({
set: [["browser.bookmarks.editDialog.delayedApply.enabled", true]],
});
win = await BrowserTestUtils.openNewBrowserWindow();
let oldTimeout = win.StarUI._autoCloseTimeout;
// Make the timeout something big, so it doesn't interact badly with tests.
win.StarUI._autoCloseTimeout = 6000000;
win.StarUI._createPanelIfNeeded();
bookmarkPanel = win.document.getElementById("editBookmarkPanel");
bookmarkPanel.setAttribute("animate", false);
registerCleanupFunction(async () => {
bookmarkPanel = null;
win.StarUI._autoCloseTimeout = oldTimeout;
await BrowserTestUtils.closeWindow(win);
win = null;
await PlacesUtils.bookmarks.eraseEverything();
Services.prefs.clearUserPref(LOCATION_PREF);
});
});
/**
* Helper to check we've shown the toolbar
*
* @param {object} options
* Options for the test
* @param {boolean} options.showToolbar
* If the toolbar should be shown or not
* @param {string} options.expectedFolder
* The expected folder to be shown
* @param {string} options.reason
* The reason the toolbar should be shown
*/
async function checkResponse({ showToolbar, expectedFolder, reason }) {
// Check folder.
let menuList = win.document.getElementById("editBMPanel_folderMenuList");
Assert.equal(
menuList.label,
PlacesUtils.getString(expectedFolder),
`Should have ${expectedFolder} selected ${reason}.`
);
// Check toolbar:
let toolbar = win.document.getElementById("PersonalToolbar");
Assert.equal(
!toolbar.collapsed,
showToolbar,
`Toolbar should be ${showToolbar ? "visible" : "hidden"} ${reason}.`
);
// Confirm and close the dialog.
let hiddenPromise = promisePopupHidden(
win.document.getElementById("editBookmarkPanel")
);
win.document.getElementById("editBookmarkPanelRemoveButton").click();
await hiddenPromise;
}
/**
* Test that if we create a bookmark on the toolbar, we show the
* toolbar:
*/
add_task(async function test_new_on_toolbar() {
await BrowserTestUtils.withNewTab(
{ gBrowser: win.gBrowser, url: "https://example.com/1" },
async browser => {
let toolbar = win.document.getElementById("PersonalToolbar");
Assert.equal(
toolbar.collapsed,
true,
"Bookmarks toolbar should start out collapsed."
);
let shownPromise = promisePopupShown(
win.document.getElementById("editBookmarkPanel")
);
win.document.getElementById("Browser:AddBookmarkAs").doCommand();
await shownPromise;
await TestUtils.waitForCondition(
() => !toolbar.collapsed,
"Toolbar should be shown."
);
let expectedFolder = "BookmarksToolbarFolderTitle";
let reason = "when creating a bookmark there";
await checkResponse({ showToolbar: true, expectedFolder, reason });
}
);
});
/**
* Test that if we create a bookmark on the toolbar, we do not
* show the toolbar if toolbar should never be shown:
*/
add_task(async function test_new_on_toolbar_never_show_toolbar() {
await SpecialPowers.pushPrefEnv({
set: [[TOOLBAR_VISIBILITY_PREF, "never"]],
});
await BrowserTestUtils.withNewTab(
{ gBrowser: win.gBrowser, url: "https://example.com/1" },
async browser => {
let toolbar = win.document.getElementById("PersonalToolbar");
Assert.equal(
toolbar.collapsed,
true,
"Bookmarks toolbar should start out collapsed."
);
let shownPromise = promisePopupShown(
win.document.getElementById("editBookmarkPanel")
);
win.document.getElementById("Browser:AddBookmarkAs").doCommand();
await shownPromise;
let expectedFolder = "BookmarksToolbarFolderTitle";
let reason = "when the visibility pref is 'never'";
await checkResponse({ showToolbar: false, expectedFolder, reason });
}
);
await SpecialPowers.popPrefEnv();
});
/**
* Test that if we edit an existing bookmark, we don't show the toolbar.
*/
add_task(async function test_existing_on_toolbar() {
// Create the bookmark first:
await PlacesUtils.bookmarks.insert({
parentGuid: PlacesUtils.bookmarks.toolbarGuid,
title: "Test for editing",
url: "https://example.com/editing-test",
});
await BrowserTestUtils.withNewTab(
{ gBrowser: win.gBrowser, url: "https://example.com/editing-test" },
async browser => {
await TestUtils.waitForCondition(
() => win.BookmarkingUI.status == BookmarkingUI.STATUS_STARRED,
"Page should be starred."
);
let toolbar = win.document.getElementById("PersonalToolbar");
Assert.equal(
toolbar.collapsed,
true,
"Bookmarks toolbar should start out collapsed."
);
await clickBookmarkStar(win);
let expectedFolder = "BookmarksToolbarFolderTitle";
let reason = "when editing a bookmark there";
await checkResponse({ showToolbar: false, expectedFolder, reason });
}
);
});

View file

@ -1,10 +1,6 @@
"use strict"; "use strict";
async function add_folder_default_button(delayedApply) { add_task(async function() {
await SpecialPowers.pushPrefEnv({
set: [["browser.bookmarks.editDialog.delayedApply.enabled", delayedApply]],
});
info( info(
"Bug 475529 - Add is the default button for the new folder dialog + " + "Bug 475529 - Add is the default button for the new folder dialog + " +
"Bug 1206376 - Changing properties of a new bookmark while adding it " + "Bug 1206376 - Changing properties of a new bookmark while adding it " +
@ -37,25 +33,16 @@ async function add_folder_default_button(delayedApply) {
tree.controller.doCommand("placesCmd_new:folder"); tree.controller.doCommand("placesCmd_new:folder");
}, },
async function test(dialogWin) { async function test(dialogWin) {
const notifications = delayedApply let promiseTitleChangeNotification = PlacesTestUtils.waitForNotification(
? [ "bookmark-title-changed",
PlacesTestUtils.waitForNotification("bookmark-added", events => events => events.some(e => e.title === "n")
events.some(e => e.title === "n") );
),
PlacesTestUtils.waitForNotification("bookmark-moved", null),
]
: [
PlacesTestUtils.waitForNotification(
"bookmark-title-changed",
events => events.some(e => e.title === "n")
),
];
fillBookmarkTextField("editBMPanel_namePicker", "n", dialogWin, false); fillBookmarkTextField("editBMPanel_namePicker", "n", dialogWin, false);
// Confirm and close the dialog. // Confirm and close the dialog.
EventUtils.synthesizeKey("VK_RETURN", {}, dialogWin); EventUtils.synthesizeKey("VK_RETURN", {}, dialogWin);
await Promise.all(notifications); await promiseTitleChangeNotification;
let newFolder = await PlacesUtils.bookmarks.fetch({ let newFolder = await PlacesUtils.bookmarks.fetch({
parentGuid: PlacesUtils.bookmarks.unfiledGuid, parentGuid: PlacesUtils.bookmarks.unfiledGuid,
@ -76,12 +63,4 @@ async function add_folder_default_button(delayedApply) {
} }
); );
}); });
}
add_task(async function add_folder_default_button_instant_apply() {
await add_folder_default_button(false);
});
add_task(async function add_folder_default_button_delayed_apply() {
await add_folder_default_button(true);
}); });

View file

@ -3,12 +3,7 @@
const TEST_URL = const TEST_URL =
"http://mochi.test:8888/browser/browser/components/places/tests/browser/keyword_form.html"; "http://mochi.test:8888/browser/browser/components/places/tests/browser/keyword_form.html";
function closeHandler(dialogWin, delayedApply) { function closeHandler(dialogWin) {
if (delayedApply) {
// We are in delayed apply mode, thus cancelling dialog will not produce a
// bookmark-removed notification.
return PlacesUtils.bookmarks.eraseEverything();
}
let savedItemId = dialogWin.gEditItemOverlay.itemId; let savedItemId = dialogWin.gEditItemOverlay.itemId;
return PlacesTestUtils.waitForNotification("bookmark-removed", events => return PlacesTestUtils.waitForNotification("bookmark-removed", events =>
events.some(event => event.id === savedItemId) events.some(event => event.id === savedItemId)
@ -17,10 +12,7 @@ function closeHandler(dialogWin, delayedApply) {
let contentAreaContextMenu = document.getElementById("contentAreaContextMenu"); let contentAreaContextMenu = document.getElementById("contentAreaContextMenu");
async function add_keyword(delayedApply) { add_task(async function() {
await SpecialPowers.pushPrefEnv({
set: [["browser.bookmarks.editDialog.delayedApply.enabled", delayedApply]],
});
await BrowserTestUtils.withNewTab( await BrowserTestUtils.withNewTab(
{ {
gBrowser, gBrowser,
@ -34,7 +26,7 @@ async function add_keyword(delayedApply) {
); );
await withBookmarksDialog( await withBookmarksDialog(
!delayedApply, true,
function() { function() {
AddKeywordForSearchField(); AddKeywordForSearchField();
contentAreaContextMenu.hidePopup(); contentAreaContextMenu.hidePopup();
@ -54,9 +46,7 @@ async function add_keyword(delayedApply) {
Assert.ok(!acceptBtn.disabled, "Accept button is enabled"); Assert.ok(!acceptBtn.disabled, "Accept button is enabled");
if (delayedApply) { // The dialog is instant apply.
acceptBtn.click();
}
await promiseKeywordNotification; await promiseKeywordNotification;
// After the notification, the keywords cache will update asynchronously. // After the notification, the keywords cache will update asynchronously.
@ -73,7 +63,9 @@ async function add_keyword(delayedApply) {
"accenti%3D%E0%E8%EC%F2%F9&search%3D%25s", "accenti%3D%E0%E8%EC%F2%F9&search%3D%25s",
"POST data is correct" "POST data is correct"
); );
let bm = await PlacesUtils.bookmarks.fetch({ url: TEST_URL }); let savedItemId = dialogWin.gEditItemOverlay.itemId;
let savedItemGuid = await PlacesUtils.promiseItemGuid(savedItemId);
let bm = await PlacesUtils.bookmarks.fetch(savedItemGuid);
Assert.equal( Assert.equal(
bm.parentGuid, bm.parentGuid,
await PlacesUIUtils.defaultParentGuid, await PlacesUIUtils.defaultParentGuid,
@ -99,24 +91,13 @@ async function add_keyword(delayedApply) {
); );
Assert.equal(data.url, TEST_URL, "getShortcutOrURI URL is correct"); Assert.equal(data.url, TEST_URL, "getShortcutOrURI URL is correct");
}, },
dialogWin => closeHandler(dialogWin, delayedApply) closeHandler
); );
} }
); );
}
add_task(async function add_keyword_instant_apply() {
await add_keyword(false);
}); });
add_task(async function add_keyword_delayed_apply() { add_task(async function reopen_same_field() {
await add_keyword(true);
});
async function reopen_same_field(delayedApply) {
await SpecialPowers.pushPrefEnv({
set: [["browser.bookmarks.editDialog.delayedApply.enabled", delayedApply]],
});
await PlacesUtils.keywords.insert({ await PlacesUtils.keywords.insert({
url: TEST_URL, url: TEST_URL,
keyword: "kw", keyword: "kw",
@ -155,24 +136,13 @@ async function reopen_same_field(delayedApply) {
.getButton("accept"); .getButton("accept");
ok(!acceptBtn.disabled, "Accept button is enabled"); ok(!acceptBtn.disabled, "Accept button is enabled");
}, },
dialogWin => closeHandler(dialogWin, delayedApply) closeHandler
); );
} }
); );
}
add_task(async function reopen_same_field_instant_apply() {
await reopen_same_field(false);
}); });
add_task(async function reopen_same_field_delayed_apply() { add_task(async function open_other_field() {
await reopen_same_field(true);
});
async function open_other_field(delayedApply) {
await SpecialPowers.pushPrefEnv({
set: [["browser.bookmarks.editDialog.delayedApply.enabled", delayedApply]],
});
await PlacesUtils.keywords.insert({ await PlacesUtils.keywords.insert({
url: TEST_URL, url: TEST_URL,
keyword: "kw2", keyword: "kw2",
@ -212,18 +182,10 @@ async function open_other_field(delayedApply) {
); );
is(elt.value, ""); is(elt.value, "");
}, },
dialogWin => closeHandler(dialogWin, delayedApply) closeHandler
); );
} }
); );
}
add_task(async function open_other_field_instant_apply() {
await open_other_field(false);
});
add_task(async function open_other_field_delayed_apply() {
await open_other_field(true);
}); });
function getPostDataString(stream) { function getPostDataString(stream) {

View file

@ -31,10 +31,6 @@ add_setup(async function() {
}); });
add_task(async function test_newFolder() { add_task(async function test_newFolder() {
let newBookmarkObserver = PlacesTestUtils.waitForNotification(
"bookmark-added",
events => events.some(({ url }) => url === TEST_URL)
);
await clickBookmarkStar(); await clickBookmarkStar();
// Open folder selector. // Open folder selector.
@ -98,8 +94,6 @@ add_task(async function test_newFolder() {
"Should have the new folder title" "Should have the new folder title"
); );
await hideBookmarksPanel();
await newBookmarkObserver;
let bookmark = await PlacesUtils.bookmarks.fetch({ url: TEST_URL }); let bookmark = await PlacesUtils.bookmarks.fetch({ url: TEST_URL });
Assert.equal( Assert.equal(
@ -107,4 +101,6 @@ add_task(async function test_newFolder() {
newFolderGuid, newFolderGuid,
"The bookmark should be parented by the new folder" "The bookmark should be parented by the new folder"
); );
await hideBookmarksPanel();
}); });

View file

@ -7,8 +7,10 @@
/** /**
* Tests that multiple tags can be added to a bookmark using the star-shaped button, the library and the sidebar. * Tests that multiple tags can be added to a bookmark using the star-shaped button, the library and the sidebar.
*/ */
let bookmarkPanel;
let bookmarkStar; StarUI._createPanelIfNeeded();
const bookmarkPanel = document.getElementById("editBookmarkPanel");
const bookmarkStar = BookmarkingUI.star;
async function clickBookmarkStar() { async function clickBookmarkStar() {
let shownPromise = promisePopupShown(bookmarkPanel); let shownPromise = promisePopupShown(bookmarkPanel);
@ -22,39 +24,35 @@ async function hideBookmarksPanel(callback) {
await hiddenPromise; await hiddenPromise;
} }
registerCleanupFunction(async () => { add_setup(function() {
await PlacesUtils.bookmarks.eraseEverything(); let oldTimeout = StarUI._autoCloseTimeout;
bookmarkPanel.setAttribute("animate", false);
StarUI._autoCloseTimeout = 1000;
registerCleanupFunction(async () => {
StarUI._autoCloseTimeout = oldTimeout;
bookmarkPanel.removeAttribute("animate");
await PlacesUtils.bookmarks.eraseEverything();
});
}); });
add_task(async function test_add_bookmark_tags_from_bookmarkProperties() { add_task(async function test_add_bookmark_tags_from_bookmarkProperties() {
const TEST_URL = "about:robots"; const TEST_URL = "about:robots";
// Open a new window with delayed apply disabled.
await SpecialPowers.pushPrefEnv({
set: [["browser.bookmarks.editDialog.delayedApply.enabled", false]],
});
let win = await BrowserTestUtils.openNewBrowserWindow();
let tab = await BrowserTestUtils.openNewForegroundTab({ let tab = await BrowserTestUtils.openNewForegroundTab({
gBrowser: win.gBrowser, gBrowser,
opening: TEST_URL, opening: TEST_URL,
waitForStateStop: true, waitForStateStop: true,
}); });
win.StarUI._createPanelIfNeeded();
win.StarUI._autoCloseTimeout = 1000;
bookmarkPanel = win.document.getElementById("editBookmarkPanel");
bookmarkPanel.setAttribute("animate", false);
bookmarkStar = win.BookmarkingUI.star;
// Cleanup. // Cleanup.
registerCleanupFunction(async function() { registerCleanupFunction(async function() {
BrowserTestUtils.removeTab(tab); BrowserTestUtils.removeTab(tab);
BrowserTestUtils.closeWindow(win);
}); });
let bookmarkPanelTitle = win.document.getElementById( let bookmarkPanelTitle = document.getElementById("editBookmarkPanelTitle");
"editBookmarkPanelTitle"
);
// The bookmarks panel is expected to auto-close after this step. // The bookmarks panel is expected to auto-close after this step.
await hideBookmarksPanel(async () => { await hideBookmarksPanel(async () => {
@ -83,7 +81,7 @@ add_task(async function test_add_bookmark_tags_from_bookmarkProperties() {
"bookmark-added", "bookmark-added",
events => events.some(({ url }) => !url || url == TEST_URL) events => events.some(({ url }) => !url || url == TEST_URL)
); );
await fillBookmarkTextField("editBMPanel_tagsField", "tag1", win); await fillBookmarkTextField("editBMPanel_tagsField", "tag1", window);
await promiseNotification; await promiseNotification;
let bookmarks = []; let bookmarks = [];
await PlacesUtils.bookmarks.fetch({ url: TEST_URL }, bm => await PlacesUtils.bookmarks.fetch({ url: TEST_URL }, bm =>
@ -98,7 +96,7 @@ add_task(async function test_add_bookmark_tags_from_bookmarkProperties() {
PlacesUtils.tagging.getTagsForURI(Services.io.newURI(TEST_URL)), PlacesUtils.tagging.getTagsForURI(Services.io.newURI(TEST_URL)),
["tag1"] ["tag1"]
); );
let doneButton = win.document.getElementById("editBookmarkPanelDoneButton"); let doneButton = document.getElementById("editBookmarkPanelDoneButton");
await hideBookmarksPanel(() => doneButton.click()); await hideBookmarksPanel(() => doneButton.click());
// Click the bookmark star again, add more tags. // Click the bookmark star again, add more tags.
@ -106,7 +104,11 @@ add_task(async function test_add_bookmark_tags_from_bookmarkProperties() {
promiseNotification = PlacesTestUtils.waitForNotification( promiseNotification = PlacesTestUtils.waitForNotification(
"bookmark-tags-changed" "bookmark-tags-changed"
); );
await fillBookmarkTextField("editBMPanel_tagsField", "tag1, tag2, tag3", win); await fillBookmarkTextField(
"editBMPanel_tagsField",
"tag1, tag2, tag3",
window
);
await promiseNotification; await promiseNotification;
await hideBookmarksPanel(() => doneButton.click()); await hideBookmarksPanel(() => doneButton.click());

View file

@ -8,34 +8,24 @@
/** /**
* Test opening and closing the bookmarks panel. * Test opening and closing the bookmarks panel.
*/ */
let win;
let bookmarkPanel; StarUI._createPanelIfNeeded();
let bookmarkStar; let bookmarkPanel = document.getElementById("editBookmarkPanel");
let bookmarkPanelTitle; let bookmarkStar = BookmarkingUI.star;
let bookmarkRemoveButton; let bookmarkPanelTitle = document.getElementById("editBookmarkPanelTitle");
let bookmarkRemoveButton = document.getElementById(
"editBookmarkPanelRemoveButton"
);
let editBookmarkPanelRemoveButtonRect; let editBookmarkPanelRemoveButtonRect;
const TEST_URL = "data:text/html,<html><body></body></html>"; const TEST_URL = "data:text/html,<html><body></body></html>";
StarUI._closePanelQuickForTesting = true;
add_setup(async function() { add_setup(async function() {
// Panel must be instant apply for tests to pass.
await SpecialPowers.pushPrefEnv({
set: [["browser.bookmarks.editDialog.delayedApply.enabled", false]],
});
win = await BrowserTestUtils.openNewBrowserWindow();
win.StarUI._createPanelIfNeeded();
win.StarUI._closePanelQuickForTesting = true;
bookmarkPanel = win.document.getElementById("editBookmarkPanel");
bookmarkPanel.setAttribute("animate", false); bookmarkPanel.setAttribute("animate", false);
bookmarkStar = win.BookmarkingUI.star; registerCleanupFunction(() => {
bookmarkPanelTitle = win.document.getElementById("editBookmarkPanelTitle"); bookmarkPanel.removeAttribute("animate");
bookmarkRemoveButton = win.document.getElementById(
"editBookmarkPanelRemoveButton"
);
registerCleanupFunction(async () => {
await BrowserTestUtils.closeWindow(win);
}); });
}); });
@ -44,12 +34,8 @@ function mouseout() {
bookmarkPanel, bookmarkPanel,
"mouseout" "mouseout"
); );
EventUtils.synthesizeMouse(bookmarkPanel, 0, 0, { type: "mouseout" }, win); EventUtils.synthesizeMouse(bookmarkPanel, 0, 0, { type: "mouseout" });
EventUtils.synthesizeMouseAtCenter( EventUtils.synthesizeMouseAtCenter(gURLBar.textbox, { type: "mousemove" });
gURLBar.textbox,
{ type: "mousemove" },
win
);
info("Waiting for mouseout event"); info("Waiting for mouseout event");
return mouseOutPromise; return mouseOutPromise;
} }
@ -62,115 +48,114 @@ async function test_bookmarks_popup({
popupHideFn, popupHideFn,
isBookmarkRemoved, isBookmarkRemoved,
}) { }) {
await BrowserTestUtils.withNewTab( await BrowserTestUtils.withNewTab({ gBrowser, url: TEST_URL }, async function(
{ gBrowser: win.gBrowser, url: TEST_URL }, browser
async function(browser) { ) {
try { try {
if (!isNewBookmark) { if (!isNewBookmark) {
await PlacesUtils.bookmarks.insert({ await PlacesUtils.bookmarks.insert({
parentGuid: await PlacesUIUtils.defaultParentGuid, parentGuid: await PlacesUIUtils.defaultParentGuid,
url: TEST_URL, url: TEST_URL,
title: "Home Page", title: "Home Page",
}); });
} }
info(`BookmarkingUI.status is ${win.BookmarkingUI.status}`); info(`BookmarkingUI.status is ${BookmarkingUI.status}`);
await TestUtils.waitForCondition( await TestUtils.waitForCondition(
() => win.BookmarkingUI.status != win.BookmarkingUI.STATUS_UPDATING, () => BookmarkingUI.status != BookmarkingUI.STATUS_UPDATING,
"BookmarkingUI should not be updating" "BookmarkingUI should not be updating"
); );
Assert.equal( Assert.equal(
bookmarkStar.hasAttribute("starred"), bookmarkStar.hasAttribute("starred"),
!isNewBookmark, !isNewBookmark,
"Page should only be starred prior to popupshown if editing bookmark" "Page should only be starred prior to popupshown if editing bookmark"
); );
Assert.equal( Assert.equal(
bookmarkPanel.state, bookmarkPanel.state,
"closed", "closed",
"Panel should be 'closed' to start test" "Panel should be 'closed' to start test"
); );
let shownPromise = promisePopupShown(bookmarkPanel); let shownPromise = promisePopupShown(bookmarkPanel);
await popupShowFn(browser); await popupShowFn(browser);
await shownPromise; await shownPromise;
Assert.equal(
bookmarkPanel.state,
"open",
"Panel should be 'open' after shownPromise is resolved"
);
editBookmarkPanelRemoveButtonRect = bookmarkRemoveButton.getBoundingClientRect();
if (popupEditFn) {
await popupEditFn();
}
let bookmarks = [];
await PlacesUtils.bookmarks.fetch({ url: TEST_URL }, bm =>
bookmarks.push(bm)
);
Assert.equal(bookmarks.length, 1, "Only one bookmark should exist");
Assert.equal(
bookmarkStar.getAttribute("starred"),
"true",
"Page is starred"
);
Assert.equal(
bookmarkPanelTitle.dataset.l10nId,
isNewBookmark ? "bookmarks-add-bookmark" : "bookmarks-edit-bookmark",
"title should match isEditingBookmark state"
);
Assert.equal(
bookmarkRemoveButton.dataset.l10nId,
isNewBookmark ? "bookmark-panel-cancel" : "bookmark-panel-remove",
"remove/cancel button label should match isEditingBookmark state"
);
if (!shouldAutoClose) {
await new Promise(resolve => setTimeout(resolve, 400));
Assert.equal( Assert.equal(
bookmarkPanel.state, bookmarkPanel.state,
"open", "open",
"Panel should be 'open' after shownPromise is resolved" "Panel should still be 'open' for non-autoclose"
); );
}
editBookmarkPanelRemoveButtonRect = bookmarkRemoveButton.getBoundingClientRect(); let defaultLocation = await PlacesUIUtils.defaultParentGuid;
let bookmarkRemovedPromise = Promise.resolve();
if (isBookmarkRemoved) {
bookmarkRemovedPromise = PlacesTestUtils.waitForNotification(
"bookmark-removed",
events =>
events.some(
event =>
event.parentGuid == defaultLocation && TEST_URL == event.url
)
);
}
if (popupEditFn) { let hiddenPromise = promisePopupHidden(bookmarkPanel);
await popupEditFn(); if (popupHideFn) {
} await popupHideFn();
let bookmarks = []; }
await PlacesUtils.bookmarks.fetch({ url: TEST_URL }, bm => await Promise.all([hiddenPromise, bookmarkRemovedPromise]);
bookmarks.push(bm)
);
Assert.equal(bookmarks.length, 1, "Only one bookmark should exist");
Assert.equal(
bookmarkStar.getAttribute("starred"),
"true",
"Page is starred"
);
Assert.equal(
bookmarkPanelTitle.dataset.l10nId,
isNewBookmark ? "bookmarks-add-bookmark" : "bookmarks-edit-bookmark",
"title should match isEditingBookmark state"
);
Assert.equal(
bookmarkRemoveButton.dataset.l10nId,
isNewBookmark ? "bookmark-panel-cancel" : "bookmark-panel-remove",
"remove/cancel button label should match isEditingBookmark state"
);
if (!shouldAutoClose) { Assert.equal(
await new Promise(resolve => setTimeout(resolve, 400)); bookmarkStar.hasAttribute("starred"),
Assert.equal( !isBookmarkRemoved,
bookmarkPanel.state, "Page is starred after closing"
"open", );
"Panel should still be 'open' for non-autoclose" } finally {
); let bookmark = await PlacesUtils.bookmarks.fetch({ url: TEST_URL });
} Assert.equal(
!!bookmark,
let defaultLocation = await PlacesUIUtils.defaultParentGuid; !isBookmarkRemoved,
let bookmarkRemovedPromise = Promise.resolve(); "bookmark should not be present if a panel action should've removed it"
if (isBookmarkRemoved) { );
bookmarkRemovedPromise = PlacesTestUtils.waitForNotification( if (bookmark) {
"bookmark-removed", await PlacesUtils.bookmarks.remove(bookmark);
events =>
events.some(
event =>
event.parentGuid == defaultLocation && TEST_URL == event.url
)
);
}
let hiddenPromise = promisePopupHidden(bookmarkPanel);
if (popupHideFn) {
await popupHideFn();
}
await Promise.all([hiddenPromise, bookmarkRemovedPromise]);
Assert.equal(
bookmarkStar.hasAttribute("starred"),
!isBookmarkRemoved,
"Page is starred after closing"
);
} finally {
let bookmark = await PlacesUtils.bookmarks.fetch({ url: TEST_URL });
Assert.equal(
!!bookmark,
!isBookmarkRemoved,
"bookmark should not be present if a panel action should've removed it"
);
if (bookmark) {
await PlacesUtils.bookmarks.remove(bookmark);
}
} }
} }
); });
} }
add_task(async function panel_shown_for_new_bookmarks_and_autocloses() { add_task(async function panel_shown_for_new_bookmarks_and_autocloses() {
@ -194,7 +179,7 @@ add_task(
10, 10,
10, 10,
{ clickCount: 2 }, { clickCount: 2 },
win window
); );
}, },
shouldAutoClose: true, shouldAutoClose: true,
@ -231,7 +216,7 @@ add_task(
await test_bookmarks_popup({ await test_bookmarks_popup({
isNewBookmark: true, isNewBookmark: true,
popupShowFn() { popupShowFn() {
EventUtils.synthesizeKey("D", { accelKey: true }, win); EventUtils.synthesizeKey("D", { accelKey: true }, window);
}, },
shouldAutoClose: true, shouldAutoClose: true,
isBookmarkRemoved: false, isBookmarkRemoved: false,
@ -250,11 +235,7 @@ add_task(async function panel_shown_for_new_bookmarks_mousemove_mouseout() {
bookmarkPanel, bookmarkPanel,
"mousemove" "mousemove"
); );
EventUtils.synthesizeMouseAtCenter( EventUtils.synthesizeMouseAtCenter(bookmarkPanel, { type: "mousemove" });
bookmarkPanel,
{ type: "mousemove" },
win
);
info("Waiting for mousemove event"); info("Waiting for mousemove event");
await mouseMovePromise; await mouseMovePromise;
info("Got mousemove event"); info("Got mousemove event");
@ -283,7 +264,7 @@ add_task(async function panel_shown_for_new_bookmark_close_with_ESC() {
}, },
shouldAutoClose: true, shouldAutoClose: true,
popupHideFn() { popupHideFn() {
EventUtils.synthesizeKey("VK_ESCAPE", { accelKey: true }, win); EventUtils.synthesizeKey("VK_ESCAPE", { accelKey: true }, window);
}, },
isBookmarkRemoved: true, isBookmarkRemoved: true,
}); });
@ -297,7 +278,7 @@ add_task(async function panel_shown_for_editing_no_autoclose_close_with_ESC() {
}, },
shouldAutoClose: false, shouldAutoClose: false,
popupHideFn() { popupHideFn() {
EventUtils.synthesizeKey("VK_ESCAPE", { accelKey: true }, win); EventUtils.synthesizeKey("VK_ESCAPE", { accelKey: true }, window);
}, },
isBookmarkRemoved: false, isBookmarkRemoved: false,
}); });
@ -310,7 +291,7 @@ add_task(async function panel_shown_for_new_bookmark_keypress_no_autoclose() {
bookmarkStar.click(); bookmarkStar.click();
}, },
popupEditFn() { popupEditFn() {
EventUtils.sendChar("VK_TAB", win); EventUtils.sendChar("VK_TAB", window);
}, },
shouldAutoClose: false, shouldAutoClose: false,
popupHideFn() { popupHideFn() {
@ -327,7 +308,7 @@ add_task(async function bookmark_with_invalid_default_folder() {
isNewBookmark: true, isNewBookmark: true,
shouldAutoClose: true, shouldAutoClose: true,
async popupShowFn(browser) { async popupShowFn(browser) {
EventUtils.synthesizeKey("d", { accelKey: true }, win); EventUtils.synthesizeKey("d", { accelKey: true }, window);
}, },
}); });
}); });
@ -344,17 +325,14 @@ add_task(
bookmarkPanel, bookmarkPanel,
"compositionstart" "compositionstart"
); );
EventUtils.synthesizeComposition({ type: "compositionstart" }, win); EventUtils.synthesizeComposition({ type: "compositionstart" }, window);
info("Waiting for compositionstart event"); info("Waiting for compositionstart event");
await compositionStartPromise; await compositionStartPromise;
info("Got compositionstart event"); info("Got compositionstart event");
}, },
shouldAutoClose: false, shouldAutoClose: false,
popupHideFn() { popupHideFn() {
EventUtils.synthesizeComposition( EventUtils.synthesizeComposition({ type: "compositioncommitasis" });
{ type: "compositioncommitasis" },
win
);
bookmarkPanel.hidePopup(); bookmarkPanel.hidePopup();
}, },
isBookmarkRemoved: false, isBookmarkRemoved: false,
@ -374,13 +352,9 @@ add_task(
bookmarkPanel, bookmarkPanel,
"mousemove" "mousemove"
); );
EventUtils.synthesizeMouseAtCenter( EventUtils.synthesizeMouseAtCenter(bookmarkPanel, {
bookmarkPanel, type: "mousemove",
{ });
type: "mousemove",
},
win
);
info("Waiting for mousemove event"); info("Waiting for mousemove event");
await mouseMovePromise; await mouseMovePromise;
info("Got mousemove event"); info("Got mousemove event");
@ -389,7 +363,7 @@ add_task(
bookmarkPanel, bookmarkPanel,
"compositionstart" "compositionstart"
); );
EventUtils.synthesizeComposition({ type: "compositionstart" }, win); EventUtils.synthesizeComposition({ type: "compositionstart" }, window);
info("Waiting for compositionstart event"); info("Waiting for compositionstart event");
await compositionStartPromise; await compositionStartPromise;
info("Got compositionstart event"); info("Got compositionstart event");
@ -399,10 +373,7 @@ add_task(
}, },
shouldAutoClose: false, shouldAutoClose: false,
popupHideFn() { popupHideFn() {
EventUtils.synthesizeComposition( EventUtils.synthesizeComposition({ type: "compositioncommitasis" });
{ type: "compositioncommitasis" },
win
);
bookmarkPanel.hidePopup(); bookmarkPanel.hidePopup();
}, },
isBookmarkRemoved: false, isBookmarkRemoved: false,
@ -422,24 +393,17 @@ add_task(
bookmarkPanel, bookmarkPanel,
"mousemove" "mousemove"
); );
EventUtils.synthesizeMouseAtCenter( EventUtils.synthesizeMouseAtCenter(bookmarkPanel, {
bookmarkPanel, type: "mousemove",
{ });
type: "mousemove",
},
win
);
info("Waiting for mousemove event"); info("Waiting for mousemove event");
await mouseMovePromise; await mouseMovePromise;
info("Got mousemove event"); info("Got mousemove event");
EventUtils.synthesizeComposition( EventUtils.synthesizeComposition({
{ type: "compositioncommit",
type: "compositioncommit", data: "committed text",
data: "committed text", });
},
win
);
}, },
popupHideFn() { popupHideFn() {
bookmarkPanel.hidePopup(); bookmarkPanel.hidePopup();
@ -454,7 +418,7 @@ add_task(async function contextmenu_new_bookmark_keypress_no_autoclose() {
await test_bookmarks_popup({ await test_bookmarks_popup({
isNewBookmark: true, isNewBookmark: true,
async popupShowFn(browser) { async popupShowFn(browser) {
let contextMenu = win.document.getElementById("contentAreaContextMenu"); let contextMenu = document.getElementById("contentAreaContextMenu");
let awaitPopupShown = BrowserTestUtils.waitForEvent( let awaitPopupShown = BrowserTestUtils.waitForEvent(
contextMenu, contextMenu,
"popupshown" "popupshown"
@ -472,13 +436,11 @@ add_task(async function contextmenu_new_bookmark_keypress_no_autoclose() {
browser browser
); );
await awaitPopupShown; await awaitPopupShown;
contextMenu.activateItem( contextMenu.activateItem(document.getElementById("context-bookmarkpage"));
win.document.getElementById("context-bookmarkpage")
);
await awaitPopupHidden; await awaitPopupHidden;
}, },
popupEditFn() { popupEditFn() {
EventUtils.sendChar("VK_TAB", win); EventUtils.sendChar("VK_TAB", window);
}, },
shouldAutoClose: false, shouldAutoClose: false,
popupHideFn() { popupHideFn() {
@ -492,11 +454,11 @@ add_task(async function bookmarks_menu_new_bookmark_remove_bookmark() {
await test_bookmarks_popup({ await test_bookmarks_popup({
isNewBookmark: true, isNewBookmark: true,
popupShowFn(browser) { popupShowFn(browser) {
win.document.getElementById("menu_bookmarkThisPage").doCommand(); document.getElementById("menu_bookmarkThisPage").doCommand();
}, },
shouldAutoClose: true, shouldAutoClose: true,
popupHideFn() { popupHideFn() {
win.document.getElementById("editBookmarkPanelRemoveButton").click(); document.getElementById("editBookmarkPanelRemoveButton").click();
}, },
isBookmarkRemoved: true, isBookmarkRemoved: true,
}); });
@ -506,11 +468,11 @@ add_task(async function ctrl_d_edit_bookmark_remove_bookmark() {
await test_bookmarks_popup({ await test_bookmarks_popup({
isNewBookmark: false, isNewBookmark: false,
popupShowFn(browser) { popupShowFn(browser) {
EventUtils.synthesizeKey("D", { accelKey: true }, win); EventUtils.synthesizeKey("D", { accelKey: true }, window);
}, },
shouldAutoClose: true, shouldAutoClose: true,
popupHideFn() { popupHideFn() {
win.document.getElementById("editBookmarkPanelRemoveButton").click(); document.getElementById("editBookmarkPanelRemoveButton").click();
}, },
isBookmarkRemoved: true, isBookmarkRemoved: true,
}); });
@ -526,17 +488,17 @@ add_task(async function enter_on_remove_bookmark_should_remove_bookmark() {
await test_bookmarks_popup({ await test_bookmarks_popup({
isNewBookmark: true, isNewBookmark: true,
popupShowFn(browser) { popupShowFn(browser) {
EventUtils.synthesizeKey("D", { accelKey: true }, win); EventUtils.synthesizeKey("D", { accelKey: true }, window);
}, },
shouldAutoClose: true, shouldAutoClose: true,
popupHideFn() { popupHideFn() {
while ( while (
!win.document.activeElement || !document.activeElement ||
win.document.activeElement.id != "editBookmarkPanelRemoveButton" document.activeElement.id != "editBookmarkPanelRemoveButton"
) { ) {
EventUtils.sendChar("VK_TAB", win); EventUtils.sendChar("VK_TAB", window);
} }
EventUtils.sendChar("VK_RETURN", win); EventUtils.sendChar("VK_RETURN", window);
}, },
isBookmarkRemoved: true, isBookmarkRemoved: true,
}); });
@ -553,15 +515,15 @@ add_task(async function mouse_hovering_panel_should_prevent_autoclose() {
async popupShowFn() { async popupShowFn() {
await EventUtils.promiseNativeMouseEvent({ await EventUtils.promiseNativeMouseEvent({
type: "mousemove", type: "mousemove",
target: win.document.documentElement, target: document.documentElement,
offsetX: editBookmarkPanelRemoveButtonRect.left, offsetX: editBookmarkPanelRemoveButtonRect.left,
offsetY: editBookmarkPanelRemoveButtonRect.top, offsetY: editBookmarkPanelRemoveButtonRect.top,
}); });
EventUtils.synthesizeKey("D", { accelKey: true }, win); EventUtils.synthesizeKey("D", { accelKey: true }, window);
}, },
shouldAutoClose: false, shouldAutoClose: false,
popupHideFn() { popupHideFn() {
win.document.getElementById("editBookmarkPanelRemoveButton").click(); document.getElementById("editBookmarkPanelRemoveButton").click();
}, },
isBookmarkRemoved: true, isBookmarkRemoved: true,
}); });
@ -571,18 +533,14 @@ add_task(async function ctrl_d_new_bookmark_mousedown_mouseout_no_autoclose() {
await test_bookmarks_popup({ await test_bookmarks_popup({
isNewBookmark: true, isNewBookmark: true,
popupShowFn(browser) { popupShowFn(browser) {
EventUtils.synthesizeKey("D", { accelKey: true }, win); EventUtils.synthesizeKey("D", { accelKey: true }, window);
}, },
async popupEditFn() { async popupEditFn() {
let mouseMovePromise = BrowserTestUtils.waitForEvent( let mouseMovePromise = BrowserTestUtils.waitForEvent(
bookmarkPanel, bookmarkPanel,
"mousemove" "mousemove"
); );
EventUtils.synthesizeMouseAtCenter( EventUtils.synthesizeMouseAtCenter(bookmarkPanel, { type: "mousemove" });
bookmarkPanel,
{ type: "mousemove" },
win
);
info("Waiting for mousemove event"); info("Waiting for mousemove event");
await mouseMovePromise; await mouseMovePromise;
info("Got mousemove event"); info("Got mousemove event");
@ -594,20 +552,16 @@ add_task(async function ctrl_d_new_bookmark_mousedown_mouseout_no_autoclose() {
"Panel should still be open on mousemove" "Panel should still be open on mousemove"
); );
EventUtils.synthesizeMouseAtCenter( EventUtils.synthesizeMouseAtCenter(bookmarkPanelTitle, {
bookmarkPanelTitle, button: 1,
{ type: "mousedown",
button: 1, });
type: "mousedown",
},
win
);
await mouseout(); await mouseout();
}, },
shouldAutoClose: false, shouldAutoClose: false,
popupHideFn() { popupHideFn() {
win.document.getElementById("editBookmarkPanelRemoveButton").click(); document.getElementById("editBookmarkPanelRemoveButton").click();
}, },
isBookmarkRemoved: true, isBookmarkRemoved: true,
}); });
@ -617,31 +571,31 @@ add_task(async function enter_during_autocomplete_should_prevent_autoclose() {
await test_bookmarks_popup({ await test_bookmarks_popup({
isNewBookmark: true, isNewBookmark: true,
async popupShowFn(browser) { async popupShowFn(browser) {
EventUtils.synthesizeKey("d", { accelKey: true }, win); EventUtils.synthesizeKey("d", { accelKey: true }, window);
}, },
async popupEditFn() { async popupEditFn() {
let tagsField = win.document.getElementById("editBMPanel_tagsField"); let tagsField = document.getElementById("editBMPanel_tagsField");
tagsField.value = ""; tagsField.value = "";
tagsField.focus(); tagsField.focus();
// Register a tag into the DB. // Register a tag into the DB.
EventUtils.sendString("Abc", win); EventUtils.sendString("Abc", window);
tagsField.blur(); tagsField.blur();
// Start autocomplete with the registered tag. // Start autocomplete with the registered tag.
tagsField.value = ""; tagsField.value = "";
let popup = win.document.getElementById("editBMPanel_tagsAutocomplete"); let popup = document.getElementById("editBMPanel_tagsAutocomplete");
let promiseShown = BrowserTestUtils.waitForEvent(popup, "popupshown"); let promiseShown = BrowserTestUtils.waitForEvent(popup, "popupshown");
tagsField.focus(); tagsField.focus();
EventUtils.sendString("a", win); EventUtils.sendString("a", window);
await promiseShown; await promiseShown;
ok(promiseShown, "autocomplete shown"); ok(promiseShown, "autocomplete shown");
// Select first candidate. // Select first candidate.
EventUtils.synthesizeKey("KEY_ArrowDown", {}, win); EventUtils.synthesizeKey("KEY_ArrowDown", {}, window);
// Type Enter key to choose the item. // Type Enter key to choose the item.
EventUtils.synthesizeKey("KEY_Enter", {}, win); EventUtils.synthesizeKey("KEY_Enter", {}, window);
Assert.equal( Assert.equal(
tagsField.value, tagsField.value,
@ -651,7 +605,7 @@ add_task(async function enter_during_autocomplete_should_prevent_autoclose() {
}, },
shouldAutoClose: false, shouldAutoClose: false,
popupHideFn() { popupHideFn() {
EventUtils.synthesizeKey("KEY_Escape", {}, win); EventUtils.synthesizeKey("KEY_Escape", {}, window);
}, },
isBookmarkRemoved: true, isBookmarkRemoved: true,
}); });
@ -661,31 +615,31 @@ add_task(async function escape_during_autocomplete_should_prevent_autoclose() {
await test_bookmarks_popup({ await test_bookmarks_popup({
isNewBookmark: true, isNewBookmark: true,
async popupShowFn(browser) { async popupShowFn(browser) {
EventUtils.synthesizeKey("d", { accelKey: true }, win); EventUtils.synthesizeKey("d", { accelKey: true }, window);
}, },
async popupEditFn() { async popupEditFn() {
let tagsField = win.document.getElementById("editBMPanel_tagsField"); let tagsField = document.getElementById("editBMPanel_tagsField");
tagsField.value = ""; tagsField.value = "";
tagsField.focus(); tagsField.focus();
// Register a tag into the DB. // Register a tag into the DB.
EventUtils.sendString("Abc", win); EventUtils.sendString("Abc", window);
tagsField.blur(); tagsField.blur();
// Start autocomplete with the registered tag. // Start autocomplete with the registered tag.
tagsField.value = ""; tagsField.value = "";
let popup = win.document.getElementById("editBMPanel_tagsAutocomplete"); let popup = document.getElementById("editBMPanel_tagsAutocomplete");
let promiseShown = BrowserTestUtils.waitForEvent(popup, "popupshown"); let promiseShown = BrowserTestUtils.waitForEvent(popup, "popupshown");
tagsField.focus(); tagsField.focus();
EventUtils.sendString("a", win); EventUtils.sendString("a", window);
await promiseShown; await promiseShown;
ok(promiseShown, "autocomplete shown"); ok(promiseShown, "autocomplete shown");
// Select first candidate. // Select first candidate.
EventUtils.synthesizeKey("KEY_ArrowDown", {}, win); EventUtils.synthesizeKey("KEY_ArrowDown", {}, window);
// Type Escape key to close autocomplete. // Type Escape key to close autocomplete.
EventUtils.synthesizeKey("KEY_Escape", {}, win); EventUtils.synthesizeKey("KEY_Escape", {}, window);
// The text reverts to what was typed. // The text reverts to what was typed.
// Note, it's important that this is different from the previously // Note, it's important that this is different from the previously
@ -698,7 +652,7 @@ add_task(async function escape_during_autocomplete_should_prevent_autoclose() {
}, },
shouldAutoClose: false, shouldAutoClose: false,
popupHideFn() { popupHideFn() {
EventUtils.synthesizeKey("KEY_Escape", {}, win); EventUtils.synthesizeKey("KEY_Escape", {}, window);
}, },
isBookmarkRemoved: true, isBookmarkRemoved: true,
}); });

View file

@ -1,712 +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/. */
/* eslint-disable mozilla/no-arbitrary-setTimeout */
"use strict";
/**
* Test opening and closing the bookmarks panel.
*/
let win;
let bookmarkPanel;
let bookmarkStar;
let bookmarkPanelTitle;
let bookmarkRemoveButton;
let editBookmarkPanelRemoveButtonRect;
const TEST_URL = "data:text/html,<html><body></body></html>";
add_setup(async function() {
// Panel must be delayed apply for tests to pass.
await SpecialPowers.pushPrefEnv({
set: [["browser.bookmarks.editDialog.delayedApply.enabled", true]],
});
win = await BrowserTestUtils.openNewBrowserWindow();
win.StarUI._createPanelIfNeeded();
win.StarUI._closePanelQuickForTesting = true;
bookmarkPanel = win.document.getElementById("editBookmarkPanel");
bookmarkPanel.setAttribute("animate", false);
bookmarkStar = win.BookmarkingUI.star;
bookmarkPanelTitle = win.document.getElementById("editBookmarkPanelTitle");
bookmarkRemoveButton = win.document.getElementById(
"editBookmarkPanelRemoveButton"
);
registerCleanupFunction(async () => {
await BrowserTestUtils.closeWindow(win);
});
});
function mouseout() {
let mouseOutPromise = BrowserTestUtils.waitForEvent(
bookmarkPanel,
"mouseout"
);
EventUtils.synthesizeMouse(bookmarkPanel, 0, 0, { type: "mouseout" }, win);
EventUtils.synthesizeMouseAtCenter(
gURLBar.textbox,
{ type: "mousemove" },
win
);
info("Waiting for mouseout event");
return mouseOutPromise;
}
async function test_bookmarks_popup({
isNewBookmark,
popupShowFn,
popupEditFn,
shouldAutoClose,
popupHideFn,
isBookmarkRemoved,
}) {
await BrowserTestUtils.withNewTab(
{ gBrowser: win.gBrowser, url: TEST_URL },
async function(browser) {
try {
if (!isNewBookmark) {
await PlacesUtils.bookmarks.insert({
parentGuid: await PlacesUIUtils.defaultParentGuid,
url: TEST_URL,
title: "Home Page",
});
}
info(`BookmarkingUI.status is ${win.BookmarkingUI.status}`);
await TestUtils.waitForCondition(
() => win.BookmarkingUI.status != win.BookmarkingUI.STATUS_UPDATING,
"BookmarkingUI should not be updating"
);
Assert.equal(
bookmarkStar.hasAttribute("starred"),
!isNewBookmark,
"Page should only be starred prior to popupshown if editing bookmark"
);
Assert.equal(
bookmarkPanel.state,
"closed",
"Panel should be 'closed' to start test"
);
let shownPromise = promisePopupShown(bookmarkPanel);
await popupShowFn(browser);
await shownPromise;
Assert.equal(
bookmarkPanel.state,
"open",
"Panel should be 'open' after shownPromise is resolved"
);
editBookmarkPanelRemoveButtonRect = bookmarkRemoveButton.getBoundingClientRect();
if (popupEditFn) {
await popupEditFn();
}
Assert.equal(
bookmarkStar.getAttribute("starred"),
"true",
"Page is starred"
);
Assert.equal(
bookmarkPanelTitle.dataset.l10nId,
isNewBookmark ? "bookmarks-add-bookmark" : "bookmarks-edit-bookmark",
"title should match isEditingBookmark state"
);
Assert.equal(
bookmarkRemoveButton.dataset.l10nId,
isNewBookmark ? "bookmark-panel-cancel" : "bookmark-panel-remove",
"remove/cancel button label should match isEditingBookmark state"
);
if (!shouldAutoClose) {
await new Promise(resolve => setTimeout(resolve, 400));
Assert.equal(
bookmarkPanel.state,
"open",
"Panel should still be 'open' for non-autoclose"
);
}
let defaultLocation = await PlacesUIUtils.defaultParentGuid;
const promises = [];
if (isNewBookmark && !isBookmarkRemoved) {
// Expect new bookmark to be created.
promises.push(
PlacesTestUtils.waitForNotification("bookmark-added", events =>
events.some(
({ parentGuid, url }) =>
parentGuid == defaultLocation && TEST_URL == url
)
)
);
}
if (!isNewBookmark && isBookmarkRemoved) {
// Expect existing bookmark to be removed.
promises.push(
PlacesTestUtils.waitForNotification("bookmark-removed", events =>
events.some(
({ parentGuid, url }) =>
parentGuid == defaultLocation && TEST_URL == url
)
)
);
}
promises.push(promisePopupHidden(bookmarkPanel));
if (popupHideFn) {
await popupHideFn();
}
await Promise.all(promises);
Assert.equal(
bookmarkStar.hasAttribute("starred"),
!isBookmarkRemoved,
"Page is starred after closing"
);
// Count number of bookmarks.
let count = 0;
await PlacesUtils.bookmarks.fetch({ url: TEST_URL }, () => count++);
const message = isBookmarkRemoved
? "No bookmark should exist"
: "Only one bookmark should exist";
Assert.equal(count, isBookmarkRemoved ^ 1, message);
} finally {
let bookmark = await PlacesUtils.bookmarks.fetch({ url: TEST_URL });
Assert.equal(
!!bookmark,
!isBookmarkRemoved,
"bookmark should not be present if a panel action should've removed it"
);
if (bookmark) {
await PlacesUtils.bookmarks.remove(bookmark);
}
}
}
);
}
add_task(async function panel_shown_for_new_bookmarks_and_autocloses() {
await test_bookmarks_popup({
isNewBookmark: true,
popupShowFn() {
bookmarkStar.click();
},
shouldAutoClose: true,
isBookmarkRemoved: false,
});
});
add_task(
async function panel_shown_once_for_doubleclick_on_new_bookmark_star_and_autocloses() {
await test_bookmarks_popup({
isNewBookmark: true,
popupShowFn() {
EventUtils.synthesizeMouse(
bookmarkStar,
10,
10,
{ clickCount: 2 },
win
);
},
shouldAutoClose: true,
isBookmarkRemoved: false,
});
}
);
add_task(
async function panel_shown_once_for_slow_doubleclick_on_new_bookmark_star_and_autocloses() {
todo(
false,
"bug 1250267, may need to add some tracking state to " +
"browser-places.js for this."
);
/*
await test_bookmarks_popup({
isNewBookmark: true,
*popupShowFn() {
EventUtils.synthesizeMouse(bookmarkStar, 10, 10, window);
await new Promise(resolve => setTimeout(resolve, 300));
EventUtils.synthesizeMouse(bookmarkStar, 10, 10, window);
},
shouldAutoClose: true,
isBookmarkRemoved: false,
});
*/
}
);
add_task(
async function panel_shown_for_keyboardshortcut_on_new_bookmark_star_and_autocloses() {
await test_bookmarks_popup({
isNewBookmark: true,
popupShowFn() {
EventUtils.synthesizeKey("D", { accelKey: true }, win);
},
shouldAutoClose: true,
isBookmarkRemoved: false,
});
}
);
add_task(async function panel_shown_for_new_bookmarks_mousemove_mouseout() {
await test_bookmarks_popup({
isNewBookmark: true,
popupShowFn() {
bookmarkStar.click();
},
async popupEditFn() {
let mouseMovePromise = BrowserTestUtils.waitForEvent(
bookmarkPanel,
"mousemove"
);
EventUtils.synthesizeMouseAtCenter(
bookmarkPanel,
{ type: "mousemove" },
win
);
info("Waiting for mousemove event");
await mouseMovePromise;
info("Got mousemove event");
await new Promise(resolve => setTimeout(resolve, 400));
is(
bookmarkPanel.state,
"open",
"Panel should still be open on mousemove"
);
},
async popupHideFn() {
await mouseout();
info("Got mouseout event, should autoclose now");
},
shouldAutoClose: false,
isBookmarkRemoved: false,
});
});
add_task(async function panel_shown_for_new_bookmark_close_with_ESC() {
await test_bookmarks_popup({
isNewBookmark: true,
popupShowFn() {
bookmarkStar.click();
},
shouldAutoClose: true,
popupHideFn() {
EventUtils.synthesizeKey("VK_ESCAPE", { accelKey: true }, win);
},
isBookmarkRemoved: true,
});
});
add_task(async function panel_shown_for_editing_no_autoclose_close_with_ESC() {
await test_bookmarks_popup({
isNewBookmark: false,
popupShowFn() {
bookmarkStar.click();
},
shouldAutoClose: false,
popupHideFn() {
EventUtils.synthesizeKey("VK_ESCAPE", { accelKey: true }, win);
},
isBookmarkRemoved: false,
});
});
add_task(async function panel_shown_for_new_bookmark_keypress_no_autoclose() {
await test_bookmarks_popup({
isNewBookmark: true,
popupShowFn() {
bookmarkStar.click();
},
popupEditFn() {
EventUtils.sendChar("VK_TAB", win);
},
shouldAutoClose: false,
popupHideFn() {
bookmarkPanel.hidePopup();
},
isBookmarkRemoved: false,
});
});
add_task(async function bookmark_with_invalid_default_folder() {
await createAndRemoveDefaultFolder();
await test_bookmarks_popup({
isNewBookmark: true,
shouldAutoClose: true,
async popupShowFn(browser) {
EventUtils.synthesizeKey("d", { accelKey: true }, win);
},
});
});
add_task(
async function panel_shown_for_new_bookmark_compositionstart_no_autoclose() {
await test_bookmarks_popup({
isNewBookmark: true,
popupShowFn() {
bookmarkStar.click();
},
async popupEditFn() {
let compositionStartPromise = BrowserTestUtils.waitForEvent(
bookmarkPanel,
"compositionstart"
);
EventUtils.synthesizeComposition({ type: "compositionstart" }, win);
info("Waiting for compositionstart event");
await compositionStartPromise;
info("Got compositionstart event");
},
shouldAutoClose: false,
popupHideFn() {
EventUtils.synthesizeComposition(
{ type: "compositioncommitasis" },
win
);
bookmarkPanel.hidePopup();
},
isBookmarkRemoved: false,
});
}
);
add_task(
async function panel_shown_for_new_bookmark_compositionstart_mouseout_no_autoclose() {
await test_bookmarks_popup({
isNewBookmark: true,
popupShowFn() {
bookmarkStar.click();
},
async popupEditFn() {
let mouseMovePromise = BrowserTestUtils.waitForEvent(
bookmarkPanel,
"mousemove"
);
EventUtils.synthesizeMouseAtCenter(
bookmarkPanel,
{
type: "mousemove",
},
win
);
info("Waiting for mousemove event");
await mouseMovePromise;
info("Got mousemove event");
let compositionStartPromise = BrowserTestUtils.waitForEvent(
bookmarkPanel,
"compositionstart"
);
EventUtils.synthesizeComposition({ type: "compositionstart" }, win);
info("Waiting for compositionstart event");
await compositionStartPromise;
info("Got compositionstart event");
await mouseout();
info("Got mouseout event, but shouldn't run autoclose");
},
shouldAutoClose: false,
popupHideFn() {
EventUtils.synthesizeComposition(
{ type: "compositioncommitasis" },
win
);
bookmarkPanel.hidePopup();
},
isBookmarkRemoved: false,
});
}
);
add_task(
async function panel_shown_for_new_bookmark_compositionend_no_autoclose() {
await test_bookmarks_popup({
isNewBookmark: true,
popupShowFn() {
bookmarkStar.click();
},
async popupEditFn() {
let mouseMovePromise = BrowserTestUtils.waitForEvent(
bookmarkPanel,
"mousemove"
);
EventUtils.synthesizeMouseAtCenter(
bookmarkPanel,
{
type: "mousemove",
},
win
);
info("Waiting for mousemove event");
await mouseMovePromise;
info("Got mousemove event");
EventUtils.synthesizeComposition(
{
type: "compositioncommit",
data: "committed text",
},
win
);
},
popupHideFn() {
bookmarkPanel.hidePopup();
},
shouldAutoClose: false,
isBookmarkRemoved: false,
});
}
);
add_task(async function contextmenu_new_bookmark_keypress_no_autoclose() {
await test_bookmarks_popup({
isNewBookmark: true,
async popupShowFn(browser) {
let contextMenu = win.document.getElementById("contentAreaContextMenu");
let awaitPopupShown = BrowserTestUtils.waitForEvent(
contextMenu,
"popupshown"
);
let awaitPopupHidden = BrowserTestUtils.waitForEvent(
contextMenu,
"popuphidden"
);
await BrowserTestUtils.synthesizeMouseAtCenter(
"body",
{
type: "contextmenu",
button: 2,
},
browser
);
await awaitPopupShown;
contextMenu.activateItem(
win.document.getElementById("context-bookmarkpage")
);
await awaitPopupHidden;
},
popupEditFn() {
EventUtils.sendChar("VK_TAB", win);
},
shouldAutoClose: false,
popupHideFn() {
bookmarkPanel.hidePopup();
},
isBookmarkRemoved: false,
});
});
add_task(async function bookmarks_menu_new_bookmark_remove_bookmark() {
await test_bookmarks_popup({
isNewBookmark: true,
popupShowFn(browser) {
win.document.getElementById("menu_bookmarkThisPage").doCommand();
},
shouldAutoClose: true,
popupHideFn() {
win.document.getElementById("editBookmarkPanelRemoveButton").click();
},
isBookmarkRemoved: true,
});
});
add_task(async function ctrl_d_edit_bookmark_remove_bookmark() {
await test_bookmarks_popup({
isNewBookmark: false,
popupShowFn(browser) {
EventUtils.synthesizeKey("D", { accelKey: true }, win);
},
shouldAutoClose: true,
popupHideFn() {
win.document.getElementById("editBookmarkPanelRemoveButton").click();
},
isBookmarkRemoved: true,
});
});
add_task(async function enter_on_remove_bookmark_should_remove_bookmark() {
if (AppConstants.platform == "macosx") {
// "Full Keyboard Access" is disabled by default, and thus doesn't allow
// keyboard navigation to the "Remove Bookmarks" button by default.
return;
}
await test_bookmarks_popup({
isNewBookmark: true,
popupShowFn(browser) {
EventUtils.synthesizeKey("D", { accelKey: true }, win);
},
shouldAutoClose: true,
popupHideFn() {
while (
!win.document.activeElement ||
win.document.activeElement.id != "editBookmarkPanelRemoveButton"
) {
EventUtils.sendChar("VK_TAB", win);
}
EventUtils.sendChar("VK_RETURN", win);
},
isBookmarkRemoved: true,
});
});
add_task(async function mouse_hovering_panel_should_prevent_autoclose() {
if (AppConstants.platform != "win") {
// This test requires synthesizing native mouse movement which is
// best supported on Windows.
return;
}
await test_bookmarks_popup({
isNewBookmark: true,
async popupShowFn() {
await EventUtils.promiseNativeMouseEvent({
type: "mousemove",
target: win.document.documentElement,
offsetX: editBookmarkPanelRemoveButtonRect.left,
offsetY: editBookmarkPanelRemoveButtonRect.top,
});
EventUtils.synthesizeKey("D", { accelKey: true }, win);
},
shouldAutoClose: false,
popupHideFn() {
win.document.getElementById("editBookmarkPanelRemoveButton").click();
},
isBookmarkRemoved: true,
});
});
add_task(async function ctrl_d_new_bookmark_mousedown_mouseout_no_autoclose() {
await test_bookmarks_popup({
isNewBookmark: true,
popupShowFn(browser) {
EventUtils.synthesizeKey("D", { accelKey: true }, win);
},
async popupEditFn() {
let mouseMovePromise = BrowserTestUtils.waitForEvent(
bookmarkPanel,
"mousemove"
);
EventUtils.synthesizeMouseAtCenter(
bookmarkPanel,
{ type: "mousemove" },
win
);
info("Waiting for mousemove event");
await mouseMovePromise;
info("Got mousemove event");
await new Promise(resolve => setTimeout(resolve, 400));
is(
bookmarkPanel.state,
"open",
"Panel should still be open on mousemove"
);
EventUtils.synthesizeMouseAtCenter(
bookmarkPanelTitle,
{
button: 1,
type: "mousedown",
},
win
);
await mouseout();
},
shouldAutoClose: false,
popupHideFn() {
win.document.getElementById("editBookmarkPanelRemoveButton").click();
},
isBookmarkRemoved: true,
});
});
add_task(async function enter_during_autocomplete_should_prevent_autoclose() {
await test_bookmarks_popup({
isNewBookmark: false,
async popupShowFn(browser) {
PlacesUtils.tagging.tagURI(makeURI(TEST_URL), ["Abc"]);
EventUtils.synthesizeKey("d", { accelKey: true }, win);
},
async popupEditFn() {
// Start autocomplete with the registered tag.
let tagsField = win.document.getElementById("editBMPanel_tagsField");
tagsField.value = "";
let popup = win.document.getElementById("editBMPanel_tagsAutocomplete");
let promiseShown = BrowserTestUtils.waitForEvent(popup, "popupshown");
tagsField.focus();
EventUtils.sendString("a", win);
await promiseShown;
ok(promiseShown, "autocomplete shown");
// Select first candidate.
EventUtils.synthesizeKey("KEY_ArrowDown", {}, win);
// Type Enter key to choose the item.
EventUtils.synthesizeKey("KEY_Enter", {}, win);
Assert.equal(
tagsField.value,
"Abc",
"Autocomplete should've inserted the selected item"
);
},
shouldAutoClose: false,
popupHideFn() {
EventUtils.synthesizeKey("KEY_Escape", {}, win);
},
isBookmarkRemoved: false,
});
});
add_task(async function escape_during_autocomplete_should_prevent_autoclose() {
await test_bookmarks_popup({
isNewBookmark: false,
async popupShowFn(browser) {
PlacesUtils.tagging.tagURI(makeURI(TEST_URL), ["Abc"]);
EventUtils.synthesizeKey("d", { accelKey: true }, win);
},
async popupEditFn() {
// Start autocomplete with the registered tag.
let tagsField = win.document.getElementById("editBMPanel_tagsField");
tagsField.value = "";
let popup = win.document.getElementById("editBMPanel_tagsAutocomplete");
let promiseShown = BrowserTestUtils.waitForEvent(popup, "popupshown");
tagsField.focus();
EventUtils.sendString("a", win);
await promiseShown;
ok(promiseShown, "autocomplete shown");
// Select first candidate.
EventUtils.synthesizeKey("KEY_ArrowDown", {}, win);
// Type Escape key to close autocomplete.
EventUtils.synthesizeKey("KEY_Escape", {}, win);
// The text reverts to what was typed.
// Note, it's important that this is different from the previously
// inserted tag, since it will test an untag/tag undo condition.
Assert.equal(
tagsField.value,
"a",
"Autocomplete should revert to what was typed"
);
},
shouldAutoClose: false,
popupHideFn() {
EventUtils.synthesizeKey("KEY_Escape", {}, win);
},
isBookmarkRemoved: false,
});
});
registerCleanupFunction(function() {
delete StarUI._closePanelQuickForTesting;
});

View file

@ -27,10 +27,6 @@ add_task(async function test_add_bookmark_from_private_window() {
win.StarUI._createPanelIfNeeded(); win.StarUI._createPanelIfNeeded();
let bookmarkPanel = win.document.getElementById("editBookmarkPanel"); let bookmarkPanel = win.document.getElementById("editBookmarkPanel");
let shownPromise = promisePopupShown(bookmarkPanel); let shownPromise = promisePopupShown(bookmarkPanel);
let bookmarkAddedPromise = PlacesTestUtils.waitForNotification(
"bookmark-added",
events => events.some(({ url }) => url === TEST_URL)
);
let bookmarkStar = win.BookmarkingUI.star; let bookmarkStar = win.BookmarkingUI.star;
bookmarkStar.click(); bookmarkStar.click();
await shownPromise; await shownPromise;
@ -47,7 +43,6 @@ add_task(async function test_add_bookmark_from_private_window() {
let doneButton = win.document.getElementById("editBookmarkPanelDoneButton"); let doneButton = win.document.getElementById("editBookmarkPanelDoneButton");
doneButton.click(); doneButton.click();
await hiddenPromise; await hiddenPromise;
await bookmarkAddedPromise;
let bm = await PlacesUtils.bookmarks.fetch({ url: TEST_URL }); let bm = await PlacesUtils.bookmarks.fetch({ url: TEST_URL });
Assert.equal( Assert.equal(

View file

@ -33,7 +33,7 @@ add_task(async function test_remove_tags_from_BookmarkStar() {
url: TEST_URL, url: TEST_URL,
title: TEST_URL, title: TEST_URL,
}); });
PlacesUtils.tagging.tagURI(TEST_URI, ["tag1", "tag2", "tag3", "tag4"]); PlacesUtils.tagging.tagURI(TEST_URI, ["tag1, tag2, tag3, tag4"]);
let tab = await BrowserTestUtils.openNewForegroundTab({ let tab = await BrowserTestUtils.openNewForegroundTab({
gBrowser, gBrowser,

View file

@ -303,137 +303,119 @@ gTests.push({
// ------------------------------------------------------------------------------ // ------------------------------------------------------------------------------
// Bug 491269 - Test that editing folder name in bookmarks properties dialog does not accept the dialog // Bug 491269 - Test that editing folder name in bookmarks properties dialog does not accept the dialog
for (const delayedApply of [false, true]) { gTests.push({
const prefDesc = delayedApply ? "Delayed Apply" : "Instant Apply"; desc:
gTests.push({ " Bug 491269 - Test that editing folder name in bookmarks properties dialog does not accept the dialog",
desc: `Bug 491269 (${prefDesc}) - Test that editing folder name in bookmarks properties dialog does not accept the dialog`, sidebar: SIDEBAR_HISTORY_ID,
sidebar: SIDEBAR_HISTORY_ID, dialogUrl: DIALOG_URL,
dialogUrl: DIALOG_URL, action: ACTION_ADD,
action: ACTION_ADD, historyView: SIDEBAR_HISTORY_BYLASTVISITED_VIEW,
historyView: SIDEBAR_HISTORY_BYLASTVISITED_VIEW, window: null,
window: null,
async setup() { async setup() {
await SpecialPowers.pushPrefEnv({ // Add a visit.
set: [ await PlacesTestUtils.addVisits(TEST_URL);
["browser.bookmarks.editDialog.delayedApply.enabled", delayedApply],
],
});
// Add a visit. this._addObserver = PlacesTestUtils.waitForNotification("bookmark-added");
await PlacesTestUtils.addVisits(TEST_URL); },
if (!delayedApply) {
this._addObserver = PlacesTestUtils.waitForNotification(
"bookmark-added",
null
);
}
},
selectNode(tree) { selectNode(tree) {
var visitNode = tree.view.nodeForTreeIndex(0); var visitNode = tree.view.nodeForTreeIndex(0);
tree.selectNode(visitNode); tree.selectNode(visitNode);
Assert.equal( Assert.equal(
tree.selectedNode.uri, tree.selectedNode.uri,
TEST_URL, TEST_URL,
"The correct visit has been selected" "The correct visit has been selected"
); );
Assert.equal( Assert.equal(
tree.selectedNode.itemId, tree.selectedNode.itemId,
-1, -1,
"The selected node is not bookmarked" "The selected node is not bookmarked"
); );
}, },
async run() { async run() {
// Open folder selector. // Open folder selector.
var foldersExpander = this.window.document.getElementById( var foldersExpander = this.window.document.getElementById(
"editBMPanel_foldersExpander" "editBMPanel_foldersExpander"
); );
var folderTree = this.window.gEditItemOverlay._folderTree; var folderTree = this.window.gEditItemOverlay._folderTree;
var self = this; var self = this;
let unloadPromise = new Promise(resolve => { let unloadPromise = new Promise(resolve => {
this.window.addEventListener( this.window.addEventListener(
"unload", "unload",
event => { event => {
Assert.ok(
self._cleanShutdown,
"Dialog window should not be closed by pressing ESC in folder name textbox"
);
executeSoon(() => {
resolve();
});
},
{ capture: true, once: true }
);
});
folderTree.addEventListener("DOMAttrModified", function onDOMAttrModified(
event
) {
if (event.attrName != "place") {
return;
}
folderTree.removeEventListener("DOMAttrModified", onDOMAttrModified);
executeSoon(async function() {
if (!delayedApply) {
await self._addObserver;
let bookmark = await PlacesUtils.bookmarks.fetch({ url: TEST_URL });
self._bookmarkGuid = bookmark.guid;
}
// Create a new folder.
var newFolderButton = self.window.document.getElementById(
"editBMPanel_newFolderButton"
);
newFolderButton.doCommand();
// Wait for the folder to be created and for editing to start.
await TestUtils.waitForCondition(
() => folderTree.hasAttribute("editing"),
"We are editing new folder name in folder tree"
);
// Press Escape to discard editing new folder name.
EventUtils.synthesizeKey("VK_ESCAPE", {}, self.window);
Assert.ok( Assert.ok(
!folderTree.hasAttribute("editing"), self._cleanShutdown,
"We have finished editing folder name in folder tree" "Dialog window should not be closed by pressing ESC in folder name textbox"
); );
executeSoon(() => {
resolve();
});
},
{ capture: true, once: true }
);
});
self._cleanShutdown = true; folderTree.addEventListener("DOMAttrModified", function onDOMAttrModified(
if (!delayedApply) { event
self._removeObserver = PlacesTestUtils.waitForNotification( ) {
"bookmark-removed", if (event.attrName != "place") {
events => events.some(eve => eve.guid == self._bookmarkGuid) return;
);
}
self.window.document
.getElementById("bookmarkpropertiesdialog")
.cancelDialog();
});
});
foldersExpander.doCommand();
await unloadPromise;
},
finish() {
SidebarUI.hide();
},
async cleanup() {
if (!delayedApply) {
await this._removeObserver;
delete this._removeObserver;
} }
await PlacesTestUtils.promiseAsyncUpdates(); folderTree.removeEventListener("DOMAttrModified", onDOMAttrModified);
executeSoon(async function() {
await self._addObserver;
let bookmark = await PlacesUtils.bookmarks.fetch({ url: TEST_URL });
self._bookmarkGuid = bookmark.guid;
await PlacesUtils.history.clear(); // Create a new folder.
}, var newFolderButton = self.window.document.getElementById(
}); "editBMPanel_newFolderButton"
} );
newFolderButton.doCommand();
// Wait for the folder to be created and for editing to start.
await TestUtils.waitForCondition(
() => folderTree.hasAttribute("editing"),
"We are editing new folder name in folder tree"
);
// Press Escape to discard editing new folder name.
EventUtils.synthesizeKey("VK_ESCAPE", {}, self.window);
Assert.ok(
!folderTree.hasAttribute("editing"),
"We have finished editing folder name in folder tree"
);
self._cleanShutdown = true;
self._removeObserver = PlacesTestUtils.waitForNotification(
"bookmark-removed",
events => events.some(eve => eve.guid == self._bookmarkGuid)
);
self.window.document
.getElementById("bookmarkpropertiesdialog")
.cancelDialog();
});
});
foldersExpander.doCommand();
await unloadPromise;
},
finish() {
SidebarUI.hide();
},
async cleanup() {
await this._removeObserver;
delete this._removeObserver;
await PlacesTestUtils.promiseAsyncUpdates();
await PlacesUtils.history.clear();
},
});
// ------------------------------------------------------------------------------ // ------------------------------------------------------------------------------