forked from mirrors/gecko-dev
Bug 1812083 - Enable delayed apply bookmarks in Firefox Nightly r=mak
As expected, the try job flagged a bunch of test failures when flipping the default `delayedApply` pref to `true`. Some of these failures are legitimate issues: - When creating a new folder in the tree under "Location", renaming the folder doesn't update its name in the Location field. - When right clicking a bookmark in the sidebar, and creating a new folder, the folder doesn't get placed before the bookmark, i.e. the insertion point is ignored. And as you pointed out, tags were being wiped out on blur in the Star/Toolbar panels. These issues have been fixed. The rest of the failures have been fixed in one of these ways: - Update the test to pass regardless of `delayedApply` setting. This was the preferred method. - Force the test to use instant apply. This was only done for tests that have an existing delayed apply counterpart. - Force the entire test suite to use instant apply. This was only done for one file, namely `browser_bookmark_popup.js`. I'll file a bug to spin off a delayed apply version of this suite. try job with `delayedApply` enabled: https://treeherder.mozilla.org/jobs?repo=try&revision=50e9cdb65feaec07c9519e928caf62042c3df9a4 try job with `delayedApply` disabled: https://treeherder.mozilla.org/jobs?repo=try&revision=1102b5076a79bf08a0e4b073fdf369af97a16ef7 Differential Revision: https://phabricator.services.mozilla.com/D168690
This commit is contained in:
parent
eac3550f79
commit
1f02cc1ca2
18 changed files with 1533 additions and 410 deletions
|
|
@ -1269,7 +1269,11 @@ pref("browser.bookmarks.editDialog.maxRecentFolders", 7);
|
|||
|
||||
// By default the Edit Bookmark dialog is instant-apply. This feature pref will allow to
|
||||
// just save on Accept, once the project is complete.
|
||||
pref("browser.bookmarks.editDialog.delayedApply.enabled", false);
|
||||
#ifdef NIGHTLY_BUILD
|
||||
pref("browser.bookmarks.editDialog.delayedApply.enabled", true);
|
||||
#else
|
||||
pref("browser.bookmarks.editDialog.delayedApply.enabled", false);
|
||||
#endif
|
||||
|
||||
#if defined(XP_WIN) && defined(MOZ_SANDBOX)
|
||||
// This controls the strength of the Windows content process sandbox for
|
||||
|
|
|
|||
|
|
@ -204,11 +204,11 @@ var StarUI = {
|
|||
return;
|
||||
}
|
||||
|
||||
await this._storeRecentlyUsedFolder(selectedFolderGuid, didChangeFolder);
|
||||
await bookmarkState.save();
|
||||
if (this._isNewBookmark) {
|
||||
this.showConfirmation();
|
||||
}
|
||||
await this._storeRecentlyUsedFolder(selectedFolderGuid, didChangeFolder);
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -30,86 +30,107 @@ add_task(async function bookmark() {
|
|||
// Open a unique page.
|
||||
// eslint-disable-next-line @microsoft/sdl/no-insecure-url
|
||||
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"));
|
||||
|
||||
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(
|
||||
() => 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;
|
||||
// Open a new window with delayed apply mode disabled. In the new window,
|
||||
// opening the star panel should instantly create a new bookmark.
|
||||
await SpecialPowers.pushPrefEnv({
|
||||
set: [["browser.bookmarks.editDialog.delayedApply.enabled", false]],
|
||||
});
|
||||
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() {
|
||||
|
|
|
|||
|
|
@ -282,6 +282,8 @@ class BookmarkState {
|
|||
* If changes to bookmark fields should be saved immediately after calling
|
||||
* its respective "changed" method, rather than waiting for save() to be
|
||||
* called.
|
||||
* @param {number} [options.index]
|
||||
* The insertion point index of the bookmark.
|
||||
*/
|
||||
constructor({
|
||||
info,
|
||||
|
|
@ -290,6 +292,7 @@ class BookmarkState {
|
|||
isFolder = false,
|
||||
children = [],
|
||||
autosave = false,
|
||||
index,
|
||||
}) {
|
||||
this._guid = info.itemGuid;
|
||||
this._postData = info.postData;
|
||||
|
|
@ -309,6 +312,7 @@ class BookmarkState {
|
|||
.filter(tag => !!tag.length),
|
||||
keyword,
|
||||
parentGuid: info.parentGuid,
|
||||
index,
|
||||
};
|
||||
|
||||
// Edited bookmark
|
||||
|
|
@ -391,6 +395,7 @@ class BookmarkState {
|
|||
tags: this._newState.tags,
|
||||
title: this._newState.title ?? this._originalState.title,
|
||||
url: this._newState.uri ?? this._originalState.uri,
|
||||
index: this._originalState.index,
|
||||
}).transact();
|
||||
if (this._newState.keyword) {
|
||||
await lazy.PlacesTransactions.EditKeyword({
|
||||
|
|
@ -416,6 +421,7 @@ class BookmarkState {
|
|||
url: item.uri,
|
||||
title: item.title,
|
||||
})),
|
||||
index: this._originalState.index,
|
||||
}).transact();
|
||||
return this._guid;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -508,6 +508,7 @@ var BookmarkPropertiesPanel = {
|
|||
? undefined
|
||||
: await PlacesUtils.promiseItemId(parentGuid);
|
||||
return Object.freeze({
|
||||
index,
|
||||
itemId,
|
||||
bookmarkGuid: itemGuid,
|
||||
title: this._title,
|
||||
|
|
|
|||
|
|
@ -378,6 +378,17 @@ 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 = () => {
|
||||
// The focusedElement possible values are:
|
||||
// * preferred: focus the field that the user touched first the last
|
||||
|
|
@ -412,7 +423,7 @@ var gEditItemOverlay = {
|
|||
await this._tagsUpdatePromise;
|
||||
}
|
||||
|
||||
this._bookmarkState = this.makeNewStateObject();
|
||||
this._bookmarkState = this.makeNewStateObject({ index: aInfo.node?.index });
|
||||
if (isBookmark || bulkTagging) {
|
||||
await this._initAllTags();
|
||||
await this._rebuildTagsSelectorList();
|
||||
|
|
@ -584,6 +595,15 @@ var gEditItemOverlay = {
|
|||
}
|
||||
}
|
||||
|
||||
if (this._observersAdded) {
|
||||
PlacesUtils.observers.removeListener(
|
||||
["bookmark-title-changed"],
|
||||
this.handlePlacesEvents
|
||||
);
|
||||
window.removeEventListener("unload", this);
|
||||
this._observersAdded = false;
|
||||
}
|
||||
|
||||
if (this._folderMenuListListenerAdded) {
|
||||
this._folderMenuList.removeEventListener("select", this);
|
||||
this._folderMenuListListenerAdded = false;
|
||||
|
|
@ -604,7 +624,7 @@ var gEditItemOverlay = {
|
|||
);
|
||||
},
|
||||
|
||||
makeNewStateObject() {
|
||||
makeNewStateObject(extraOptions) {
|
||||
if (
|
||||
this._paneInfo.isItem ||
|
||||
this._paneInfo.isTag ||
|
||||
|
|
@ -613,7 +633,11 @@ var gEditItemOverlay = {
|
|||
const isLibraryWindow =
|
||||
document.documentElement.getAttribute("windowtype") ===
|
||||
"Places:Organizer";
|
||||
const options = { autosave: isLibraryWindow, info: this._paneInfo };
|
||||
const options = {
|
||||
autosave: isLibraryWindow,
|
||||
info: this._paneInfo,
|
||||
...extraOptions,
|
||||
};
|
||||
|
||||
if (this._paneInfo.isBookmark) {
|
||||
options.tags = this._element("tagsField").value;
|
||||
|
|
@ -657,16 +681,24 @@ var gEditItemOverlay = {
|
|||
async _updateTags() {
|
||||
this._tagsUpdatePromise = (async () => {
|
||||
const inputTags = this._getTagsArrayFromTagsInputField();
|
||||
const isLibraryWindow =
|
||||
document.documentElement.getAttribute("windowtype") ===
|
||||
"Places:Organizer";
|
||||
await this._bookmarkState._tagsChanged(inputTags);
|
||||
delete this._paneInfo._cachedCommonTags;
|
||||
|
||||
// Ensure the tagsField is in sync, clean it up from empty tags
|
||||
const currentTags = this._paneInfo.bulkTagging
|
||||
? this._getCommonTags()
|
||||
: PlacesUtils.tagging.getTagsForURI(this._paneInfo.uri);
|
||||
this._initTextField(this._tagsField, currentTags.join(", "), false);
|
||||
|
||||
await this._initAllTags();
|
||||
if (isLibraryWindow) {
|
||||
// Ensure the tagsField is in sync, clean it up from empty tags
|
||||
delete this._paneInfo._cachedCommonTags;
|
||||
const currentTags = this._paneInfo.bulkTagging
|
||||
? this._getCommonTags()
|
||||
: PlacesUtils.tagging.getTagsForURI(this._paneInfo.uri);
|
||||
this._initTextField(this._tagsField, currentTags.join(", "), false);
|
||||
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();
|
||||
})().catch(console.error);
|
||||
await this._tagsUpdatePromise;
|
||||
|
|
@ -1072,6 +1104,19 @@ 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) {
|
||||
// Update the tags field when items are checked/unchecked in the listbox
|
||||
let tags = this._getTagsArrayFromTagsInputField();
|
||||
|
|
@ -1108,6 +1153,30 @@ var gEditItemOverlay = {
|
|||
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
|
||||
* apply logic should be used.
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ support-files =
|
|||
[browser_addBookmarkForFrame.js]
|
||||
skip-if = (verify && debug)
|
||||
[browser_autoshow_bookmarks_toolbar.js]
|
||||
[browser_autoshow_bookmarks_toolbar_delayed_apply.js]
|
||||
[browser_bookmark_add_tags.js]
|
||||
https_first_disabled = true
|
||||
skip-if =
|
||||
|
|
@ -26,6 +27,12 @@ skip-if = os == 'linux' # times out on linux, Bug 1739081
|
|||
[browser_bookmark_folder_moveability.js]
|
||||
[browser_bookmark_menu_ctrl_click.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 =
|
||||
os == "linux" && asan # Bug 1712814
|
||||
os == "linux" && tsan # Bug 1712814
|
||||
|
|
|
|||
|
|
@ -12,6 +12,10 @@ add_setup(async function() {
|
|||
Services.prefs.clearUserPref(LOCATION_PREF);
|
||||
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();
|
||||
|
||||
let oldTimeout = win.StarUI._autoCloseTimeout;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,169 @@
|
|||
/* 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 });
|
||||
}
|
||||
);
|
||||
});
|
||||
|
|
@ -1,6 +1,10 @@
|
|||
"use strict";
|
||||
|
||||
add_task(async function() {
|
||||
async function add_folder_default_button(delayedApply) {
|
||||
await SpecialPowers.pushPrefEnv({
|
||||
set: [["browser.bookmarks.editDialog.delayedApply.enabled", delayedApply]],
|
||||
});
|
||||
|
||||
info(
|
||||
"Bug 475529 - Add is the default button for the new folder dialog + " +
|
||||
"Bug 1206376 - Changing properties of a new bookmark while adding it " +
|
||||
|
|
@ -33,16 +37,25 @@ add_task(async function() {
|
|||
tree.controller.doCommand("placesCmd_new:folder");
|
||||
},
|
||||
async function test(dialogWin) {
|
||||
let promiseTitleChangeNotification = PlacesTestUtils.waitForNotification(
|
||||
"bookmark-title-changed",
|
||||
events => events.some(e => e.title === "n")
|
||||
);
|
||||
const notifications = delayedApply
|
||||
? [
|
||||
PlacesTestUtils.waitForNotification("bookmark-added", events =>
|
||||
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);
|
||||
|
||||
// Confirm and close the dialog.
|
||||
EventUtils.synthesizeKey("VK_RETURN", {}, dialogWin);
|
||||
await promiseTitleChangeNotification;
|
||||
await Promise.all(notifications);
|
||||
|
||||
let newFolder = await PlacesUtils.bookmarks.fetch({
|
||||
parentGuid: PlacesUtils.bookmarks.unfiledGuid,
|
||||
|
|
@ -63,4 +76,12 @@ add_task(async function() {
|
|||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
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);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -3,7 +3,12 @@
|
|||
const TEST_URL =
|
||||
"http://mochi.test:8888/browser/browser/components/places/tests/browser/keyword_form.html";
|
||||
|
||||
function closeHandler(dialogWin) {
|
||||
function closeHandler(dialogWin, delayedApply) {
|
||||
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;
|
||||
return PlacesTestUtils.waitForNotification("bookmark-removed", events =>
|
||||
events.some(event => event.id === savedItemId)
|
||||
|
|
@ -12,7 +17,10 @@ function closeHandler(dialogWin) {
|
|||
|
||||
let contentAreaContextMenu = document.getElementById("contentAreaContextMenu");
|
||||
|
||||
add_task(async function() {
|
||||
async function add_keyword(delayedApply) {
|
||||
await SpecialPowers.pushPrefEnv({
|
||||
set: [["browser.bookmarks.editDialog.delayedApply.enabled", delayedApply]],
|
||||
});
|
||||
await BrowserTestUtils.withNewTab(
|
||||
{
|
||||
gBrowser,
|
||||
|
|
@ -26,7 +34,7 @@ add_task(async function() {
|
|||
);
|
||||
|
||||
await withBookmarksDialog(
|
||||
true,
|
||||
!delayedApply,
|
||||
function() {
|
||||
AddKeywordForSearchField();
|
||||
contentAreaContextMenu.hidePopup();
|
||||
|
|
@ -46,7 +54,9 @@ add_task(async function() {
|
|||
|
||||
Assert.ok(!acceptBtn.disabled, "Accept button is enabled");
|
||||
|
||||
// The dialog is instant apply.
|
||||
if (delayedApply) {
|
||||
acceptBtn.click();
|
||||
}
|
||||
await promiseKeywordNotification;
|
||||
|
||||
// After the notification, the keywords cache will update asynchronously.
|
||||
|
|
@ -63,9 +73,7 @@ add_task(async function() {
|
|||
"accenti%3D%E0%E8%EC%F2%F9&search%3D%25s",
|
||||
"POST data is correct"
|
||||
);
|
||||
let savedItemId = dialogWin.gEditItemOverlay.itemId;
|
||||
let savedItemGuid = await PlacesUtils.promiseItemGuid(savedItemId);
|
||||
let bm = await PlacesUtils.bookmarks.fetch(savedItemGuid);
|
||||
let bm = await PlacesUtils.bookmarks.fetch({ url: TEST_URL });
|
||||
Assert.equal(
|
||||
bm.parentGuid,
|
||||
await PlacesUIUtils.defaultParentGuid,
|
||||
|
|
@ -91,13 +99,24 @@ add_task(async function() {
|
|||
);
|
||||
Assert.equal(data.url, TEST_URL, "getShortcutOrURI URL is correct");
|
||||
},
|
||||
closeHandler
|
||||
dialogWin => closeHandler(dialogWin, delayedApply)
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
add_task(async function add_keyword_instant_apply() {
|
||||
await add_keyword(false);
|
||||
});
|
||||
|
||||
add_task(async function reopen_same_field() {
|
||||
add_task(async function add_keyword_delayed_apply() {
|
||||
await add_keyword(true);
|
||||
});
|
||||
|
||||
async function reopen_same_field(delayedApply) {
|
||||
await SpecialPowers.pushPrefEnv({
|
||||
set: [["browser.bookmarks.editDialog.delayedApply.enabled", delayedApply]],
|
||||
});
|
||||
await PlacesUtils.keywords.insert({
|
||||
url: TEST_URL,
|
||||
keyword: "kw",
|
||||
|
|
@ -136,13 +155,24 @@ add_task(async function reopen_same_field() {
|
|||
.getButton("accept");
|
||||
ok(!acceptBtn.disabled, "Accept button is enabled");
|
||||
},
|
||||
closeHandler
|
||||
dialogWin => closeHandler(dialogWin, delayedApply)
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
add_task(async function reopen_same_field_instant_apply() {
|
||||
await reopen_same_field(false);
|
||||
});
|
||||
|
||||
add_task(async function open_other_field() {
|
||||
add_task(async function reopen_same_field_delayed_apply() {
|
||||
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({
|
||||
url: TEST_URL,
|
||||
keyword: "kw2",
|
||||
|
|
@ -182,10 +212,18 @@ add_task(async function open_other_field() {
|
|||
);
|
||||
is(elt.value, "");
|
||||
},
|
||||
closeHandler
|
||||
dialogWin => closeHandler(dialogWin, delayedApply)
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
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) {
|
||||
|
|
|
|||
|
|
@ -31,6 +31,10 @@ add_setup(async function() {
|
|||
});
|
||||
|
||||
add_task(async function test_newFolder() {
|
||||
let newBookmarkObserver = PlacesTestUtils.waitForNotification(
|
||||
"bookmark-added",
|
||||
events => events.some(({ url }) => url === TEST_URL)
|
||||
);
|
||||
await clickBookmarkStar();
|
||||
|
||||
// Open folder selector.
|
||||
|
|
@ -94,6 +98,8 @@ add_task(async function test_newFolder() {
|
|||
"Should have the new folder title"
|
||||
);
|
||||
|
||||
await hideBookmarksPanel();
|
||||
await newBookmarkObserver;
|
||||
let bookmark = await PlacesUtils.bookmarks.fetch({ url: TEST_URL });
|
||||
|
||||
Assert.equal(
|
||||
|
|
@ -101,6 +107,4 @@ add_task(async function test_newFolder() {
|
|||
newFolderGuid,
|
||||
"The bookmark should be parented by the new folder"
|
||||
);
|
||||
|
||||
await hideBookmarksPanel();
|
||||
});
|
||||
|
|
|
|||
|
|
@ -7,10 +7,8 @@
|
|||
/**
|
||||
* Tests that multiple tags can be added to a bookmark using the star-shaped button, the library and the sidebar.
|
||||
*/
|
||||
|
||||
StarUI._createPanelIfNeeded();
|
||||
const bookmarkPanel = document.getElementById("editBookmarkPanel");
|
||||
const bookmarkStar = BookmarkingUI.star;
|
||||
let bookmarkPanel;
|
||||
let bookmarkStar;
|
||||
|
||||
async function clickBookmarkStar() {
|
||||
let shownPromise = promisePopupShown(bookmarkPanel);
|
||||
|
|
@ -24,35 +22,39 @@ async function hideBookmarksPanel(callback) {
|
|||
await hiddenPromise;
|
||||
}
|
||||
|
||||
add_setup(function() {
|
||||
let oldTimeout = StarUI._autoCloseTimeout;
|
||||
|
||||
bookmarkPanel.setAttribute("animate", false);
|
||||
|
||||
StarUI._autoCloseTimeout = 1000;
|
||||
|
||||
registerCleanupFunction(async () => {
|
||||
StarUI._autoCloseTimeout = oldTimeout;
|
||||
bookmarkPanel.removeAttribute("animate");
|
||||
await PlacesUtils.bookmarks.eraseEverything();
|
||||
});
|
||||
registerCleanupFunction(async () => {
|
||||
await PlacesUtils.bookmarks.eraseEverything();
|
||||
});
|
||||
|
||||
add_task(async function test_add_bookmark_tags_from_bookmarkProperties() {
|
||||
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({
|
||||
gBrowser,
|
||||
gBrowser: win.gBrowser,
|
||||
opening: TEST_URL,
|
||||
waitForStateStop: true,
|
||||
});
|
||||
|
||||
win.StarUI._createPanelIfNeeded();
|
||||
win.StarUI._autoCloseTimeout = 1000;
|
||||
bookmarkPanel = win.document.getElementById("editBookmarkPanel");
|
||||
bookmarkPanel.setAttribute("animate", false);
|
||||
bookmarkStar = win.BookmarkingUI.star;
|
||||
|
||||
// Cleanup.
|
||||
registerCleanupFunction(async function() {
|
||||
BrowserTestUtils.removeTab(tab);
|
||||
BrowserTestUtils.closeWindow(win);
|
||||
});
|
||||
|
||||
let bookmarkPanelTitle = document.getElementById("editBookmarkPanelTitle");
|
||||
let bookmarkPanelTitle = win.document.getElementById(
|
||||
"editBookmarkPanelTitle"
|
||||
);
|
||||
|
||||
// The bookmarks panel is expected to auto-close after this step.
|
||||
await hideBookmarksPanel(async () => {
|
||||
|
|
@ -81,7 +83,7 @@ add_task(async function test_add_bookmark_tags_from_bookmarkProperties() {
|
|||
"bookmark-added",
|
||||
events => events.some(({ url }) => !url || url == TEST_URL)
|
||||
);
|
||||
await fillBookmarkTextField("editBMPanel_tagsField", "tag1", window);
|
||||
await fillBookmarkTextField("editBMPanel_tagsField", "tag1", win);
|
||||
await promiseNotification;
|
||||
let bookmarks = [];
|
||||
await PlacesUtils.bookmarks.fetch({ url: TEST_URL }, bm =>
|
||||
|
|
@ -96,7 +98,7 @@ add_task(async function test_add_bookmark_tags_from_bookmarkProperties() {
|
|||
PlacesUtils.tagging.getTagsForURI(Services.io.newURI(TEST_URL)),
|
||||
["tag1"]
|
||||
);
|
||||
let doneButton = document.getElementById("editBookmarkPanelDoneButton");
|
||||
let doneButton = win.document.getElementById("editBookmarkPanelDoneButton");
|
||||
await hideBookmarksPanel(() => doneButton.click());
|
||||
|
||||
// Click the bookmark star again, add more tags.
|
||||
|
|
@ -104,11 +106,7 @@ add_task(async function test_add_bookmark_tags_from_bookmarkProperties() {
|
|||
promiseNotification = PlacesTestUtils.waitForNotification(
|
||||
"bookmark-tags-changed"
|
||||
);
|
||||
await fillBookmarkTextField(
|
||||
"editBMPanel_tagsField",
|
||||
"tag1, tag2, tag3",
|
||||
window
|
||||
);
|
||||
await fillBookmarkTextField("editBMPanel_tagsField", "tag1, tag2, tag3", win);
|
||||
await promiseNotification;
|
||||
await hideBookmarksPanel(() => doneButton.click());
|
||||
|
||||
|
|
|
|||
|
|
@ -8,24 +8,34 @@
|
|||
/**
|
||||
* Test opening and closing the bookmarks panel.
|
||||
*/
|
||||
|
||||
StarUI._createPanelIfNeeded();
|
||||
let bookmarkPanel = document.getElementById("editBookmarkPanel");
|
||||
let bookmarkStar = BookmarkingUI.star;
|
||||
let bookmarkPanelTitle = document.getElementById("editBookmarkPanelTitle");
|
||||
let bookmarkRemoveButton = document.getElementById(
|
||||
"editBookmarkPanelRemoveButton"
|
||||
);
|
||||
let win;
|
||||
let bookmarkPanel;
|
||||
let bookmarkStar;
|
||||
let bookmarkPanelTitle;
|
||||
let bookmarkRemoveButton;
|
||||
let editBookmarkPanelRemoveButtonRect;
|
||||
|
||||
const TEST_URL = "data:text/html,<html><body></body></html>";
|
||||
|
||||
StarUI._closePanelQuickForTesting = true;
|
||||
|
||||
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);
|
||||
registerCleanupFunction(() => {
|
||||
bookmarkPanel.removeAttribute("animate");
|
||||
bookmarkStar = win.BookmarkingUI.star;
|
||||
bookmarkPanelTitle = win.document.getElementById("editBookmarkPanelTitle");
|
||||
bookmarkRemoveButton = win.document.getElementById(
|
||||
"editBookmarkPanelRemoveButton"
|
||||
);
|
||||
|
||||
registerCleanupFunction(async () => {
|
||||
await BrowserTestUtils.closeWindow(win);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
@ -34,8 +44,12 @@ function mouseout() {
|
|||
bookmarkPanel,
|
||||
"mouseout"
|
||||
);
|
||||
EventUtils.synthesizeMouse(bookmarkPanel, 0, 0, { type: "mouseout" });
|
||||
EventUtils.synthesizeMouseAtCenter(gURLBar.textbox, { type: "mousemove" });
|
||||
EventUtils.synthesizeMouse(bookmarkPanel, 0, 0, { type: "mouseout" }, win);
|
||||
EventUtils.synthesizeMouseAtCenter(
|
||||
gURLBar.textbox,
|
||||
{ type: "mousemove" },
|
||||
win
|
||||
);
|
||||
info("Waiting for mouseout event");
|
||||
return mouseOutPromise;
|
||||
}
|
||||
|
|
@ -48,114 +62,115 @@ async function test_bookmarks_popup({
|
|||
popupHideFn,
|
||||
isBookmarkRemoved,
|
||||
}) {
|
||||
await BrowserTestUtils.withNewTab({ gBrowser, url: TEST_URL }, async function(
|
||||
browser
|
||||
) {
|
||||
try {
|
||||
if (!isNewBookmark) {
|
||||
await PlacesUtils.bookmarks.insert({
|
||||
parentGuid: await PlacesUIUtils.defaultParentGuid,
|
||||
url: TEST_URL,
|
||||
title: "Home Page",
|
||||
});
|
||||
}
|
||||
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 ${BookmarkingUI.status}`);
|
||||
await TestUtils.waitForCondition(
|
||||
() => BookmarkingUI.status != BookmarkingUI.STATUS_UPDATING,
|
||||
"BookmarkingUI should not be updating"
|
||||
);
|
||||
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();
|
||||
}
|
||||
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(
|
||||
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 still be 'open' for non-autoclose"
|
||||
"Panel should be 'open' after shownPromise is resolved"
|
||||
);
|
||||
}
|
||||
|
||||
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
|
||||
)
|
||||
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"
|
||||
);
|
||||
}
|
||||
|
||||
let hiddenPromise = promisePopupHidden(bookmarkPanel);
|
||||
if (popupHideFn) {
|
||||
await popupHideFn();
|
||||
}
|
||||
await Promise.all([hiddenPromise, bookmarkRemovedPromise]);
|
||||
if (!shouldAutoClose) {
|
||||
await new Promise(resolve => setTimeout(resolve, 400));
|
||||
Assert.equal(
|
||||
bookmarkPanel.state,
|
||||
"open",
|
||||
"Panel should still be 'open' for non-autoclose"
|
||||
);
|
||||
}
|
||||
|
||||
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);
|
||||
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
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
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() {
|
||||
|
|
@ -179,7 +194,7 @@ add_task(
|
|||
10,
|
||||
10,
|
||||
{ clickCount: 2 },
|
||||
window
|
||||
win
|
||||
);
|
||||
},
|
||||
shouldAutoClose: true,
|
||||
|
|
@ -216,7 +231,7 @@ add_task(
|
|||
await test_bookmarks_popup({
|
||||
isNewBookmark: true,
|
||||
popupShowFn() {
|
||||
EventUtils.synthesizeKey("D", { accelKey: true }, window);
|
||||
EventUtils.synthesizeKey("D", { accelKey: true }, win);
|
||||
},
|
||||
shouldAutoClose: true,
|
||||
isBookmarkRemoved: false,
|
||||
|
|
@ -235,7 +250,11 @@ add_task(async function panel_shown_for_new_bookmarks_mousemove_mouseout() {
|
|||
bookmarkPanel,
|
||||
"mousemove"
|
||||
);
|
||||
EventUtils.synthesizeMouseAtCenter(bookmarkPanel, { type: "mousemove" });
|
||||
EventUtils.synthesizeMouseAtCenter(
|
||||
bookmarkPanel,
|
||||
{ type: "mousemove" },
|
||||
win
|
||||
);
|
||||
info("Waiting for mousemove event");
|
||||
await mouseMovePromise;
|
||||
info("Got mousemove event");
|
||||
|
|
@ -264,7 +283,7 @@ add_task(async function panel_shown_for_new_bookmark_close_with_ESC() {
|
|||
},
|
||||
shouldAutoClose: true,
|
||||
popupHideFn() {
|
||||
EventUtils.synthesizeKey("VK_ESCAPE", { accelKey: true }, window);
|
||||
EventUtils.synthesizeKey("VK_ESCAPE", { accelKey: true }, win);
|
||||
},
|
||||
isBookmarkRemoved: true,
|
||||
});
|
||||
|
|
@ -278,7 +297,7 @@ add_task(async function panel_shown_for_editing_no_autoclose_close_with_ESC() {
|
|||
},
|
||||
shouldAutoClose: false,
|
||||
popupHideFn() {
|
||||
EventUtils.synthesizeKey("VK_ESCAPE", { accelKey: true }, window);
|
||||
EventUtils.synthesizeKey("VK_ESCAPE", { accelKey: true }, win);
|
||||
},
|
||||
isBookmarkRemoved: false,
|
||||
});
|
||||
|
|
@ -291,7 +310,7 @@ add_task(async function panel_shown_for_new_bookmark_keypress_no_autoclose() {
|
|||
bookmarkStar.click();
|
||||
},
|
||||
popupEditFn() {
|
||||
EventUtils.sendChar("VK_TAB", window);
|
||||
EventUtils.sendChar("VK_TAB", win);
|
||||
},
|
||||
shouldAutoClose: false,
|
||||
popupHideFn() {
|
||||
|
|
@ -308,7 +327,7 @@ add_task(async function bookmark_with_invalid_default_folder() {
|
|||
isNewBookmark: true,
|
||||
shouldAutoClose: true,
|
||||
async popupShowFn(browser) {
|
||||
EventUtils.synthesizeKey("d", { accelKey: true }, window);
|
||||
EventUtils.synthesizeKey("d", { accelKey: true }, win);
|
||||
},
|
||||
});
|
||||
});
|
||||
|
|
@ -325,14 +344,17 @@ add_task(
|
|||
bookmarkPanel,
|
||||
"compositionstart"
|
||||
);
|
||||
EventUtils.synthesizeComposition({ type: "compositionstart" }, window);
|
||||
EventUtils.synthesizeComposition({ type: "compositionstart" }, win);
|
||||
info("Waiting for compositionstart event");
|
||||
await compositionStartPromise;
|
||||
info("Got compositionstart event");
|
||||
},
|
||||
shouldAutoClose: false,
|
||||
popupHideFn() {
|
||||
EventUtils.synthesizeComposition({ type: "compositioncommitasis" });
|
||||
EventUtils.synthesizeComposition(
|
||||
{ type: "compositioncommitasis" },
|
||||
win
|
||||
);
|
||||
bookmarkPanel.hidePopup();
|
||||
},
|
||||
isBookmarkRemoved: false,
|
||||
|
|
@ -352,9 +374,13 @@ add_task(
|
|||
bookmarkPanel,
|
||||
"mousemove"
|
||||
);
|
||||
EventUtils.synthesizeMouseAtCenter(bookmarkPanel, {
|
||||
type: "mousemove",
|
||||
});
|
||||
EventUtils.synthesizeMouseAtCenter(
|
||||
bookmarkPanel,
|
||||
{
|
||||
type: "mousemove",
|
||||
},
|
||||
win
|
||||
);
|
||||
info("Waiting for mousemove event");
|
||||
await mouseMovePromise;
|
||||
info("Got mousemove event");
|
||||
|
|
@ -363,7 +389,7 @@ add_task(
|
|||
bookmarkPanel,
|
||||
"compositionstart"
|
||||
);
|
||||
EventUtils.synthesizeComposition({ type: "compositionstart" }, window);
|
||||
EventUtils.synthesizeComposition({ type: "compositionstart" }, win);
|
||||
info("Waiting for compositionstart event");
|
||||
await compositionStartPromise;
|
||||
info("Got compositionstart event");
|
||||
|
|
@ -373,7 +399,10 @@ add_task(
|
|||
},
|
||||
shouldAutoClose: false,
|
||||
popupHideFn() {
|
||||
EventUtils.synthesizeComposition({ type: "compositioncommitasis" });
|
||||
EventUtils.synthesizeComposition(
|
||||
{ type: "compositioncommitasis" },
|
||||
win
|
||||
);
|
||||
bookmarkPanel.hidePopup();
|
||||
},
|
||||
isBookmarkRemoved: false,
|
||||
|
|
@ -393,17 +422,24 @@ add_task(
|
|||
bookmarkPanel,
|
||||
"mousemove"
|
||||
);
|
||||
EventUtils.synthesizeMouseAtCenter(bookmarkPanel, {
|
||||
type: "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",
|
||||
});
|
||||
EventUtils.synthesizeComposition(
|
||||
{
|
||||
type: "compositioncommit",
|
||||
data: "committed text",
|
||||
},
|
||||
win
|
||||
);
|
||||
},
|
||||
popupHideFn() {
|
||||
bookmarkPanel.hidePopup();
|
||||
|
|
@ -418,7 +454,7 @@ add_task(async function contextmenu_new_bookmark_keypress_no_autoclose() {
|
|||
await test_bookmarks_popup({
|
||||
isNewBookmark: true,
|
||||
async popupShowFn(browser) {
|
||||
let contextMenu = document.getElementById("contentAreaContextMenu");
|
||||
let contextMenu = win.document.getElementById("contentAreaContextMenu");
|
||||
let awaitPopupShown = BrowserTestUtils.waitForEvent(
|
||||
contextMenu,
|
||||
"popupshown"
|
||||
|
|
@ -436,11 +472,13 @@ add_task(async function contextmenu_new_bookmark_keypress_no_autoclose() {
|
|||
browser
|
||||
);
|
||||
await awaitPopupShown;
|
||||
contextMenu.activateItem(document.getElementById("context-bookmarkpage"));
|
||||
contextMenu.activateItem(
|
||||
win.document.getElementById("context-bookmarkpage")
|
||||
);
|
||||
await awaitPopupHidden;
|
||||
},
|
||||
popupEditFn() {
|
||||
EventUtils.sendChar("VK_TAB", window);
|
||||
EventUtils.sendChar("VK_TAB", win);
|
||||
},
|
||||
shouldAutoClose: false,
|
||||
popupHideFn() {
|
||||
|
|
@ -454,11 +492,11 @@ add_task(async function bookmarks_menu_new_bookmark_remove_bookmark() {
|
|||
await test_bookmarks_popup({
|
||||
isNewBookmark: true,
|
||||
popupShowFn(browser) {
|
||||
document.getElementById("menu_bookmarkThisPage").doCommand();
|
||||
win.document.getElementById("menu_bookmarkThisPage").doCommand();
|
||||
},
|
||||
shouldAutoClose: true,
|
||||
popupHideFn() {
|
||||
document.getElementById("editBookmarkPanelRemoveButton").click();
|
||||
win.document.getElementById("editBookmarkPanelRemoveButton").click();
|
||||
},
|
||||
isBookmarkRemoved: true,
|
||||
});
|
||||
|
|
@ -468,11 +506,11 @@ add_task(async function ctrl_d_edit_bookmark_remove_bookmark() {
|
|||
await test_bookmarks_popup({
|
||||
isNewBookmark: false,
|
||||
popupShowFn(browser) {
|
||||
EventUtils.synthesizeKey("D", { accelKey: true }, window);
|
||||
EventUtils.synthesizeKey("D", { accelKey: true }, win);
|
||||
},
|
||||
shouldAutoClose: true,
|
||||
popupHideFn() {
|
||||
document.getElementById("editBookmarkPanelRemoveButton").click();
|
||||
win.document.getElementById("editBookmarkPanelRemoveButton").click();
|
||||
},
|
||||
isBookmarkRemoved: true,
|
||||
});
|
||||
|
|
@ -488,7 +526,7 @@ add_task(async function enter_on_remove_bookmark_should_remove_bookmark() {
|
|||
await test_bookmarks_popup({
|
||||
isNewBookmark: true,
|
||||
popupShowFn(browser) {
|
||||
EventUtils.synthesizeKey("D", { accelKey: true }, window);
|
||||
EventUtils.synthesizeKey("D", { accelKey: true }, win);
|
||||
},
|
||||
shouldAutoClose: true,
|
||||
popupHideFn() {
|
||||
|
|
@ -496,9 +534,9 @@ add_task(async function enter_on_remove_bookmark_should_remove_bookmark() {
|
|||
!document.activeElement ||
|
||||
document.activeElement.id != "editBookmarkPanelRemoveButton"
|
||||
) {
|
||||
EventUtils.sendChar("VK_TAB", window);
|
||||
EventUtils.sendChar("VK_TAB", win);
|
||||
}
|
||||
EventUtils.sendChar("VK_RETURN", window);
|
||||
EventUtils.sendChar("VK_RETURN", win);
|
||||
},
|
||||
isBookmarkRemoved: true,
|
||||
});
|
||||
|
|
@ -519,7 +557,7 @@ add_task(async function mouse_hovering_panel_should_prevent_autoclose() {
|
|||
offsetX: editBookmarkPanelRemoveButtonRect.left,
|
||||
offsetY: editBookmarkPanelRemoveButtonRect.top,
|
||||
});
|
||||
EventUtils.synthesizeKey("D", { accelKey: true }, window);
|
||||
EventUtils.synthesizeKey("D", { accelKey: true }, win);
|
||||
},
|
||||
shouldAutoClose: false,
|
||||
popupHideFn() {
|
||||
|
|
@ -533,14 +571,18 @@ 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 }, window);
|
||||
EventUtils.synthesizeKey("D", { accelKey: true }, win);
|
||||
},
|
||||
async popupEditFn() {
|
||||
let mouseMovePromise = BrowserTestUtils.waitForEvent(
|
||||
bookmarkPanel,
|
||||
"mousemove"
|
||||
);
|
||||
EventUtils.synthesizeMouseAtCenter(bookmarkPanel, { type: "mousemove" });
|
||||
EventUtils.synthesizeMouseAtCenter(
|
||||
bookmarkPanel,
|
||||
{ type: "mousemove" },
|
||||
win
|
||||
);
|
||||
info("Waiting for mousemove event");
|
||||
await mouseMovePromise;
|
||||
info("Got mousemove event");
|
||||
|
|
@ -552,16 +594,20 @@ add_task(async function ctrl_d_new_bookmark_mousedown_mouseout_no_autoclose() {
|
|||
"Panel should still be open on mousemove"
|
||||
);
|
||||
|
||||
EventUtils.synthesizeMouseAtCenter(bookmarkPanelTitle, {
|
||||
button: 1,
|
||||
type: "mousedown",
|
||||
});
|
||||
EventUtils.synthesizeMouseAtCenter(
|
||||
bookmarkPanelTitle,
|
||||
{
|
||||
button: 1,
|
||||
type: "mousedown",
|
||||
},
|
||||
win
|
||||
);
|
||||
|
||||
await mouseout();
|
||||
},
|
||||
shouldAutoClose: false,
|
||||
popupHideFn() {
|
||||
document.getElementById("editBookmarkPanelRemoveButton").click();
|
||||
win.document.getElementById("editBookmarkPanelRemoveButton").click();
|
||||
},
|
||||
isBookmarkRemoved: true,
|
||||
});
|
||||
|
|
@ -571,31 +617,31 @@ add_task(async function enter_during_autocomplete_should_prevent_autoclose() {
|
|||
await test_bookmarks_popup({
|
||||
isNewBookmark: true,
|
||||
async popupShowFn(browser) {
|
||||
EventUtils.synthesizeKey("d", { accelKey: true }, window);
|
||||
EventUtils.synthesizeKey("d", { accelKey: true }, win);
|
||||
},
|
||||
async popupEditFn() {
|
||||
let tagsField = document.getElementById("editBMPanel_tagsField");
|
||||
let tagsField = win.document.getElementById("editBMPanel_tagsField");
|
||||
tagsField.value = "";
|
||||
tagsField.focus();
|
||||
|
||||
// Register a tag into the DB.
|
||||
EventUtils.sendString("Abc", window);
|
||||
EventUtils.sendString("Abc", win);
|
||||
tagsField.blur();
|
||||
|
||||
// Start autocomplete with the registered tag.
|
||||
tagsField.value = "";
|
||||
let popup = document.getElementById("editBMPanel_tagsAutocomplete");
|
||||
let popup = win.document.getElementById("editBMPanel_tagsAutocomplete");
|
||||
let promiseShown = BrowserTestUtils.waitForEvent(popup, "popupshown");
|
||||
tagsField.focus();
|
||||
EventUtils.sendString("a", window);
|
||||
EventUtils.sendString("a", win);
|
||||
await promiseShown;
|
||||
ok(promiseShown, "autocomplete shown");
|
||||
|
||||
// Select first candidate.
|
||||
EventUtils.synthesizeKey("KEY_ArrowDown", {}, window);
|
||||
EventUtils.synthesizeKey("KEY_ArrowDown", {}, win);
|
||||
|
||||
// Type Enter key to choose the item.
|
||||
EventUtils.synthesizeKey("KEY_Enter", {}, window);
|
||||
EventUtils.synthesizeKey("KEY_Enter", {}, win);
|
||||
|
||||
Assert.equal(
|
||||
tagsField.value,
|
||||
|
|
@ -605,7 +651,7 @@ add_task(async function enter_during_autocomplete_should_prevent_autoclose() {
|
|||
},
|
||||
shouldAutoClose: false,
|
||||
popupHideFn() {
|
||||
EventUtils.synthesizeKey("KEY_Escape", {}, window);
|
||||
EventUtils.synthesizeKey("KEY_Escape", {}, win);
|
||||
},
|
||||
isBookmarkRemoved: true,
|
||||
});
|
||||
|
|
@ -615,31 +661,31 @@ add_task(async function escape_during_autocomplete_should_prevent_autoclose() {
|
|||
await test_bookmarks_popup({
|
||||
isNewBookmark: true,
|
||||
async popupShowFn(browser) {
|
||||
EventUtils.synthesizeKey("d", { accelKey: true }, window);
|
||||
EventUtils.synthesizeKey("d", { accelKey: true }, win);
|
||||
},
|
||||
async popupEditFn() {
|
||||
let tagsField = document.getElementById("editBMPanel_tagsField");
|
||||
let tagsField = win.document.getElementById("editBMPanel_tagsField");
|
||||
tagsField.value = "";
|
||||
tagsField.focus();
|
||||
|
||||
// Register a tag into the DB.
|
||||
EventUtils.sendString("Abc", window);
|
||||
EventUtils.sendString("Abc", win);
|
||||
tagsField.blur();
|
||||
|
||||
// Start autocomplete with the registered tag.
|
||||
tagsField.value = "";
|
||||
let popup = document.getElementById("editBMPanel_tagsAutocomplete");
|
||||
let popup = win.document.getElementById("editBMPanel_tagsAutocomplete");
|
||||
let promiseShown = BrowserTestUtils.waitForEvent(popup, "popupshown");
|
||||
tagsField.focus();
|
||||
EventUtils.sendString("a", window);
|
||||
EventUtils.sendString("a", win);
|
||||
await promiseShown;
|
||||
ok(promiseShown, "autocomplete shown");
|
||||
|
||||
// Select first candidate.
|
||||
EventUtils.synthesizeKey("KEY_ArrowDown", {}, window);
|
||||
EventUtils.synthesizeKey("KEY_ArrowDown", {}, win);
|
||||
|
||||
// Type Escape key to close autocomplete.
|
||||
EventUtils.synthesizeKey("KEY_Escape", {}, window);
|
||||
EventUtils.synthesizeKey("KEY_Escape", {}, win);
|
||||
|
||||
// The text reverts to what was typed.
|
||||
// Note, it's important that this is different from the previously
|
||||
|
|
@ -652,7 +698,7 @@ add_task(async function escape_during_autocomplete_should_prevent_autoclose() {
|
|||
},
|
||||
shouldAutoClose: false,
|
||||
popupHideFn() {
|
||||
EventUtils.synthesizeKey("KEY_Escape", {}, window);
|
||||
EventUtils.synthesizeKey("KEY_Escape", {}, win);
|
||||
},
|
||||
isBookmarkRemoved: true,
|
||||
});
|
||||
|
|
|
|||
|
|
@ -0,0 +1,712 @@
|
|||
/* 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 (
|
||||
!document.activeElement ||
|
||||
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: document.documentElement,
|
||||
offsetX: editBookmarkPanelRemoveButtonRect.left,
|
||||
offsetY: editBookmarkPanelRemoveButtonRect.top,
|
||||
});
|
||||
EventUtils.synthesizeKey("D", { accelKey: true }, win);
|
||||
},
|
||||
shouldAutoClose: false,
|
||||
popupHideFn() {
|
||||
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;
|
||||
});
|
||||
|
|
@ -27,6 +27,10 @@ add_task(async function test_add_bookmark_from_private_window() {
|
|||
win.StarUI._createPanelIfNeeded();
|
||||
let bookmarkPanel = win.document.getElementById("editBookmarkPanel");
|
||||
let shownPromise = promisePopupShown(bookmarkPanel);
|
||||
let bookmarkAddedPromise = PlacesTestUtils.waitForNotification(
|
||||
"bookmark-added",
|
||||
events => events.some(({ url }) => url === TEST_URL)
|
||||
);
|
||||
let bookmarkStar = win.BookmarkingUI.star;
|
||||
bookmarkStar.click();
|
||||
await shownPromise;
|
||||
|
|
@ -43,6 +47,7 @@ add_task(async function test_add_bookmark_from_private_window() {
|
|||
let doneButton = win.document.getElementById("editBookmarkPanelDoneButton");
|
||||
doneButton.click();
|
||||
await hiddenPromise;
|
||||
await bookmarkAddedPromise;
|
||||
|
||||
let bm = await PlacesUtils.bookmarks.fetch({ url: TEST_URL });
|
||||
Assert.equal(
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ add_task(async function test_remove_tags_from_BookmarkStar() {
|
|||
url: 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({
|
||||
gBrowser,
|
||||
|
|
|
|||
|
|
@ -303,119 +303,137 @@ gTests.push({
|
|||
// ------------------------------------------------------------------------------
|
||||
// Bug 491269 - Test that editing folder name in bookmarks properties dialog does not accept the dialog
|
||||
|
||||
gTests.push({
|
||||
desc:
|
||||
" Bug 491269 - Test that editing folder name in bookmarks properties dialog does not accept the dialog",
|
||||
sidebar: SIDEBAR_HISTORY_ID,
|
||||
dialogUrl: DIALOG_URL,
|
||||
action: ACTION_ADD,
|
||||
historyView: SIDEBAR_HISTORY_BYLASTVISITED_VIEW,
|
||||
window: null,
|
||||
for (const delayedApply of [false, true]) {
|
||||
const prefDesc = delayedApply ? "Delayed Apply" : "Instant Apply";
|
||||
gTests.push({
|
||||
desc: `Bug 491269 (${prefDesc}) - Test that editing folder name in bookmarks properties dialog does not accept the dialog`,
|
||||
sidebar: SIDEBAR_HISTORY_ID,
|
||||
dialogUrl: DIALOG_URL,
|
||||
action: ACTION_ADD,
|
||||
historyView: SIDEBAR_HISTORY_BYLASTVISITED_VIEW,
|
||||
window: null,
|
||||
|
||||
async setup() {
|
||||
// Add a visit.
|
||||
await PlacesTestUtils.addVisits(TEST_URL);
|
||||
|
||||
this._addObserver = PlacesTestUtils.waitForNotification("bookmark-added");
|
||||
},
|
||||
|
||||
selectNode(tree) {
|
||||
var visitNode = tree.view.nodeForTreeIndex(0);
|
||||
tree.selectNode(visitNode);
|
||||
Assert.equal(
|
||||
tree.selectedNode.uri,
|
||||
TEST_URL,
|
||||
"The correct visit has been selected"
|
||||
);
|
||||
Assert.equal(
|
||||
tree.selectedNode.itemId,
|
||||
-1,
|
||||
"The selected node is not bookmarked"
|
||||
);
|
||||
},
|
||||
|
||||
async run() {
|
||||
// Open folder selector.
|
||||
var foldersExpander = this.window.document.getElementById(
|
||||
"editBMPanel_foldersExpander"
|
||||
);
|
||||
var folderTree = this.window.gEditItemOverlay._folderTree;
|
||||
var self = this;
|
||||
|
||||
let unloadPromise = new Promise(resolve => {
|
||||
this.window.addEventListener(
|
||||
"unload",
|
||||
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() {
|
||||
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(
|
||||
!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();
|
||||
async setup() {
|
||||
await SpecialPowers.pushPrefEnv({
|
||||
set: [
|
||||
["browser.bookmarks.editDialog.delayedApply.enabled", delayedApply],
|
||||
],
|
||||
});
|
||||
});
|
||||
foldersExpander.doCommand();
|
||||
await unloadPromise;
|
||||
},
|
||||
|
||||
finish() {
|
||||
SidebarUI.hide();
|
||||
},
|
||||
// Add a visit.
|
||||
await PlacesTestUtils.addVisits(TEST_URL);
|
||||
if (!delayedApply) {
|
||||
this._addObserver = PlacesTestUtils.waitForNotification(
|
||||
"bookmark-added",
|
||||
null
|
||||
);
|
||||
}
|
||||
},
|
||||
|
||||
async cleanup() {
|
||||
await this._removeObserver;
|
||||
delete this._removeObserver;
|
||||
await PlacesTestUtils.promiseAsyncUpdates();
|
||||
selectNode(tree) {
|
||||
var visitNode = tree.view.nodeForTreeIndex(0);
|
||||
tree.selectNode(visitNode);
|
||||
Assert.equal(
|
||||
tree.selectedNode.uri,
|
||||
TEST_URL,
|
||||
"The correct visit has been selected"
|
||||
);
|
||||
Assert.equal(
|
||||
tree.selectedNode.itemId,
|
||||
-1,
|
||||
"The selected node is not bookmarked"
|
||||
);
|
||||
},
|
||||
|
||||
await PlacesUtils.history.clear();
|
||||
},
|
||||
});
|
||||
async run() {
|
||||
// Open folder selector.
|
||||
var foldersExpander = this.window.document.getElementById(
|
||||
"editBMPanel_foldersExpander"
|
||||
);
|
||||
var folderTree = this.window.gEditItemOverlay._folderTree;
|
||||
var self = this;
|
||||
|
||||
let unloadPromise = new Promise(resolve => {
|
||||
this.window.addEventListener(
|
||||
"unload",
|
||||
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(
|
||||
!folderTree.hasAttribute("editing"),
|
||||
"We have finished editing folder name in folder tree"
|
||||
);
|
||||
|
||||
self._cleanShutdown = true;
|
||||
if (!delayedApply) {
|
||||
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() {
|
||||
if (!delayedApply) {
|
||||
await this._removeObserver;
|
||||
delete this._removeObserver;
|
||||
}
|
||||
await PlacesTestUtils.promiseAsyncUpdates();
|
||||
|
||||
await PlacesUtils.history.clear();
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue