Bug 1716976 - Add compose_body context and also add composer to editable context. r=darktrojan
Differential Revision: https://phabricator.services.mozilla.com/D166893 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
24553d737b
Коммит
1fe3afca99
|
@ -1955,7 +1955,10 @@ function msgComposeContextOnShowing(event) {
|
|||
// Set up early the right flags for editable / not editable.
|
||||
let editFlags = SpellCheckHelper.isEditable(target, window);
|
||||
let onTextInput = (editFlags & SpellCheckHelper.TEXTINPUT) !== 0;
|
||||
let onEditable = (editFlags & SpellCheckHelper.EDITABLE) !== 0;
|
||||
let onEditable =
|
||||
(editFlags &
|
||||
(SpellCheckHelper.EDITABLE | SpellCheckHelper.CONTENTEDITABLE)) !==
|
||||
0;
|
||||
|
||||
let onImage = false;
|
||||
let srcUrl = undefined;
|
||||
|
@ -1997,6 +2000,7 @@ function msgComposeContextOnShowing(event) {
|
|||
linkUrl,
|
||||
selectionText: isTextSelected ? selectionInfo.fullText : undefined,
|
||||
pageUrl: target.ownerGlobal.top.location.href,
|
||||
onComposeBody: true,
|
||||
};
|
||||
subject.context = subject;
|
||||
subject.wrappedJSObject = subject;
|
||||
|
|
|
@ -630,6 +630,7 @@ const contextsMap = {
|
|||
onBrowserAction: "browser_action",
|
||||
onComposeAction: "compose_action",
|
||||
onMessageDisplayAction: "message_display_action",
|
||||
onComposeBody: "compose_body",
|
||||
onTab: "tab",
|
||||
inToolsMenu: "tools_menu",
|
||||
selectedMessages: "message_list",
|
||||
|
|
|
@ -49,24 +49,25 @@
|
|||
"type": "string",
|
||||
"enum": [
|
||||
"all",
|
||||
"page",
|
||||
"frame",
|
||||
"selection",
|
||||
"link",
|
||||
"editable",
|
||||
"password",
|
||||
"image",
|
||||
"video",
|
||||
"all_message_attachments",
|
||||
"audio",
|
||||
"compose_action",
|
||||
"message_display_action",
|
||||
"tab",
|
||||
"message_list",
|
||||
"folder_pane",
|
||||
"compose_attachments",
|
||||
"compose_body",
|
||||
"editable",
|
||||
"folder_pane",
|
||||
"frame",
|
||||
"image",
|
||||
"link",
|
||||
"message_attachments",
|
||||
"all_message_attachments",
|
||||
"tools_menu"
|
||||
"message_display_action",
|
||||
"message_list",
|
||||
"page",
|
||||
"password",
|
||||
"selection",
|
||||
"tab",
|
||||
"tools_menu",
|
||||
"video"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
|
|
@ -689,7 +689,7 @@ async function subtest_compose(manifest) {
|
|||
|
||||
let messagePane = composeWindow.GetCurrentEditorElement();
|
||||
|
||||
await subtest_content(
|
||||
await subtest_compose_body(
|
||||
extension,
|
||||
manifest.permissions?.includes("compose"),
|
||||
messagePane,
|
||||
|
|
|
@ -225,6 +225,7 @@ async function getMenuExtension(manifest) {
|
|||
"message_list",
|
||||
"folder_pane",
|
||||
"compose_attachments",
|
||||
"compose_body",
|
||||
"tools_menu",
|
||||
];
|
||||
if (browser.runtime.getManifest().manifest_version > 2) {
|
||||
|
@ -442,6 +443,212 @@ async function subtest_content(
|
|||
await new Promise(r => setTimeout(r, 250));
|
||||
}
|
||||
|
||||
async function openExtensionSubMenu(menu) {
|
||||
// The extension submenu ends with a number, which increases over time, but it
|
||||
// does not have a underscore.
|
||||
let submenu;
|
||||
for (let item of menu.querySelectorAll("[id^=menus_mochi_test-menuitem-]")) {
|
||||
if (!item.id.includes("-_")) {
|
||||
submenu = item;
|
||||
break;
|
||||
}
|
||||
}
|
||||
Assert.ok(submenu, `Found submenu: ${submenu.id}`);
|
||||
|
||||
// Open submenu.
|
||||
let submenuPromise = BrowserTestUtils.waitForEvent(menu, "popupshown");
|
||||
submenu.openMenu(true);
|
||||
await submenuPromise;
|
||||
|
||||
return submenu;
|
||||
}
|
||||
|
||||
async function subtest_compose_body(
|
||||
extension,
|
||||
extensionHasPermission,
|
||||
browser,
|
||||
pageUrl,
|
||||
tab
|
||||
) {
|
||||
if (
|
||||
browser.webProgress?.isLoadingDocument ||
|
||||
!browser.currentURI ||
|
||||
browser.currentURI?.spec == "about:blank"
|
||||
) {
|
||||
await BrowserTestUtils.browserLoaded(
|
||||
browser,
|
||||
undefined,
|
||||
url => url != "about:blank"
|
||||
);
|
||||
}
|
||||
|
||||
let ownerDocument = browser.ownerDocument;
|
||||
let menu = ownerDocument.getElementById(browser.getAttribute("context"));
|
||||
|
||||
await BrowserTestUtils.synthesizeMouseAtCenter("body", {}, browser);
|
||||
|
||||
info("Test a part of the page with no content.");
|
||||
{
|
||||
await rightClickOnContent(menu, "body", browser);
|
||||
Assert.ok(menu.querySelector(`#menus_mochi_test-menuitem-_compose_body`));
|
||||
Assert.ok(menu.querySelector(`#menus_mochi_test-menuitem-_editable`));
|
||||
let hiddenPromise = BrowserTestUtils.waitForEvent(menu, "popuphidden");
|
||||
menu.hidePopup();
|
||||
await hiddenPromise;
|
||||
// Sometimes, the popup will open then instantly disappear. It seems to
|
||||
// still be hiding after the previous appearance. If we wait a little bit,
|
||||
// this doesn't happen.
|
||||
// eslint-disable-next-line mozilla/no-arbitrary-setTimeout
|
||||
await new Promise(r => setTimeout(r, 250));
|
||||
|
||||
await checkShownEvent(
|
||||
extension,
|
||||
{
|
||||
menuIds: ["editable", "compose_body"],
|
||||
contexts: ["editable", "compose_body", "all"],
|
||||
pageUrl: extensionHasPermission ? pageUrl : undefined,
|
||||
},
|
||||
tab
|
||||
);
|
||||
}
|
||||
|
||||
info("Test selection.");
|
||||
{
|
||||
await SpecialPowers.spawn(browser, [], () => {
|
||||
let text = content.document.querySelector("p");
|
||||
content.getSelection().selectAllChildren(text);
|
||||
});
|
||||
|
||||
await rightClickOnContent(menu, "p", browser);
|
||||
let submenu = await openExtensionSubMenu(menu);
|
||||
|
||||
await checkShownEvent(
|
||||
extension,
|
||||
{
|
||||
pageUrl: extensionHasPermission ? pageUrl : undefined,
|
||||
selectionText: extensionHasPermission ? "This is text." : undefined,
|
||||
menuIds: ["editable", "selection", "compose_body"],
|
||||
contexts: ["editable", "selection", "compose_body", "all"],
|
||||
},
|
||||
tab
|
||||
);
|
||||
Assert.ok(submenu.querySelector("#menus_mochi_test-menuitem-_selection"));
|
||||
Assert.ok(
|
||||
submenu.querySelector("#menus_mochi_test-menuitem-_compose_body")
|
||||
);
|
||||
Assert.ok(submenu.querySelector("#menus_mochi_test-menuitem-_editable"));
|
||||
|
||||
let hiddenPromise = BrowserTestUtils.waitForEvent(submenu, "popuphidden");
|
||||
let clickedPromise = checkClickedEvent(
|
||||
extension,
|
||||
{
|
||||
pageUrl,
|
||||
selectionText: "This is text.",
|
||||
},
|
||||
tab
|
||||
);
|
||||
menu.activateItem(
|
||||
submenu.querySelector("#menus_mochi_test-menuitem-_selection")
|
||||
);
|
||||
await clickedPromise;
|
||||
await hiddenPromise;
|
||||
|
||||
// Sometimes, the popup will open then instantly disappear. It seems to
|
||||
// still be hiding after the previous appearance. If we wait a little bit,
|
||||
// this doesn't happen.
|
||||
// eslint-disable-next-line mozilla/no-arbitrary-setTimeout
|
||||
await new Promise(r => setTimeout(r, 250));
|
||||
await BrowserTestUtils.synthesizeMouseAtCenter("body", {}, browser); // Select nothing.
|
||||
}
|
||||
|
||||
info("Test link.");
|
||||
{
|
||||
await rightClickOnContent(menu, "a", browser);
|
||||
let submenu = await openExtensionSubMenu(menu);
|
||||
|
||||
await checkShownEvent(
|
||||
extension,
|
||||
{
|
||||
pageUrl: extensionHasPermission ? pageUrl : undefined,
|
||||
menuIds: ["editable", "link", "compose_body"],
|
||||
contexts: ["editable", "link", "compose_body", "all"],
|
||||
},
|
||||
tab
|
||||
);
|
||||
Assert.ok(submenu.querySelector("#menus_mochi_test-menuitem-_link"));
|
||||
Assert.ok(submenu.querySelector("#menus_mochi_test-menuitem-_editable"));
|
||||
Assert.ok(
|
||||
submenu.querySelector("#menus_mochi_test-menuitem-_compose_body")
|
||||
);
|
||||
|
||||
let hiddenPromise = BrowserTestUtils.waitForEvent(submenu, "popuphidden");
|
||||
let clickedPromise = checkClickedEvent(
|
||||
extension,
|
||||
{
|
||||
pageUrl,
|
||||
linkUrl: "http://mochi.test:8888/",
|
||||
linkText: "This is a link with text.",
|
||||
},
|
||||
tab
|
||||
);
|
||||
menu.activateItem(
|
||||
submenu.querySelector("#menus_mochi_test-menuitem-_link")
|
||||
);
|
||||
await clickedPromise;
|
||||
await hiddenPromise;
|
||||
|
||||
// Sometimes, the popup will open then instantly disappear. It seems to
|
||||
// still be hiding after the previous appearance. If we wait a little bit,
|
||||
// this doesn't happen.
|
||||
// eslint-disable-next-line mozilla/no-arbitrary-setTimeout
|
||||
await new Promise(r => setTimeout(r, 250));
|
||||
await BrowserTestUtils.synthesizeMouseAtCenter("body", {}, browser); // Select nothing.
|
||||
}
|
||||
|
||||
info("Test image.");
|
||||
{
|
||||
await rightClickOnContent(menu, "img", browser);
|
||||
let submenu = await openExtensionSubMenu(menu);
|
||||
|
||||
await checkShownEvent(
|
||||
extension,
|
||||
{
|
||||
pageUrl: extensionHasPermission ? pageUrl : undefined,
|
||||
menuIds: ["editable", "image", "compose_body"],
|
||||
contexts: ["editable", "image", "compose_body", "all"],
|
||||
},
|
||||
tab
|
||||
);
|
||||
Assert.ok(submenu.querySelector("#menus_mochi_test-menuitem-_image"));
|
||||
Assert.ok(submenu.querySelector("#menus_mochi_test-menuitem-_editable"));
|
||||
Assert.ok(
|
||||
submenu.querySelector("#menus_mochi_test-menuitem-_compose_body")
|
||||
);
|
||||
|
||||
let hiddenPromise = BrowserTestUtils.waitForEvent(menu, "popuphidden");
|
||||
let clickedPromise = checkClickedEvent(
|
||||
extension,
|
||||
{
|
||||
pageUrl,
|
||||
srcUrl: `${URL_BASE}/tb-logo.png`,
|
||||
},
|
||||
tab
|
||||
);
|
||||
menu.activateItem(
|
||||
submenu.querySelector("#menus_mochi_test-menuitem-_image")
|
||||
);
|
||||
await clickedPromise;
|
||||
await hiddenPromise;
|
||||
|
||||
// Sometimes, the popup will open then instantly disappear. It seems to
|
||||
// still be hiding after the previous appearance. If we wait a little bit,
|
||||
// this doesn't happen.
|
||||
// eslint-disable-next-line mozilla/no-arbitrary-setTimeout
|
||||
await new Promise(r => setTimeout(r, 250));
|
||||
await BrowserTestUtils.synthesizeMouseAtCenter("body", {}, browser); // Select nothing.
|
||||
}
|
||||
}
|
||||
|
||||
// Test UI elements which have been made accessible for the menus API.
|
||||
// Assumed to be run after subtest_content, so we know everything has finished
|
||||
// loading.
|
||||
|
|
Загрузка…
Ссылка в новой задаче