Bug 1339440 use frameUrl to match context menus on frames
MozReview-Commit-ID: LIlAZIP4HNx
--- a/browser/components/extensions/ext-contextMenus.js
+++ b/browser/components/extensions/ext-contextMenus.js
@@ -512,17 +512,17 @@ MenuItem.prototype = {
enabledForContext(contextData) {
let contexts = getContexts(contextData);
if (!this.contexts.some(n => contexts.has(n))) {
return false;
}
let docPattern = this.documentUrlMatchPattern;
- let pageURI = Services.io.newURI(contextData.pageUrl);
+ let pageURI = Services.io.newURI(contextData[contextData.inFrame ? "frameUrl" : "pageUrl"]);
if (docPattern && !docPattern.matches(pageURI)) {
return false;
}
let targetPattern = this.targetUrlMatchPattern;
if (targetPattern) {
let targetUrls = [];
if (contextData.onImage || contextData.onAudio || contextData.onVideo) {
--- a/browser/components/extensions/test/browser/browser-common.ini
+++ b/browser/components/extensions/test/browser/browser-common.ini
@@ -1,14 +1,15 @@
[DEFAULT]
support-files =
head.js
head_pageAction.js
head_sessions.js
context.html
+ context_frame.html
ctxmenu-image.png
context_tabs_onUpdated_page.html
context_tabs_onUpdated_iframe.html
file_clearplugindata.html
file_popup_api_injection_a.html
file_popup_api_injection_b.html
file_iframe_document.html
file_iframe_document.sjs
--- a/browser/components/extensions/test/browser/browser_ext_contextMenus_urlPatterns.js
+++ b/browser/components/extensions/test/browser/browser_ext_contextMenus_urlPatterns.js
@@ -47,21 +47,27 @@ add_task(function* () {
title: "targetUrlPatterns-patternDoesNotMatch-contextLink",
targetUrlPatterns: ["*://*/does-not-match"],
contexts: ["link"],
});
// Test menu items using documentUrlPatterns.
browser.contextMenus.create({
title: "documentUrlPatterns-patternMatches-contextAll",
- documentUrlPatterns: ["*://*/*context.html"],
+ documentUrlPatterns: ["*://*/*context*.html"],
contexts: ["all"],
});
browser.contextMenus.create({
+ title: "documentUrlPatterns-patternMatches-contextFrame",
+ documentUrlPatterns: ["*://*/*context_frame.html"],
+ contexts: ["frame"],
+ });
+
+ browser.contextMenus.create({
title: "documentUrlPatterns-patternMatches-contextImage",
documentUrlPatterns: ["*://*/*context.html", "http://*/url-that-does-not-match"],
contexts: ["image"],
});
browser.contextMenus.create({
title: "documentUrlPatterns-patternMatches-contextLink",
documentUrlPatterns: ["*://*/*context.html", "*://*/does-not-match"],
@@ -244,11 +250,19 @@ add_task(function* () {
["documentUrlPatterns-patternMatches-contextLink", true],
["documentUrlPatterns-patternDoesNotMatch-contextAll", false],
["documentUrlPatterns-patternDoesNotMatch-contextImage", false],
["documentUrlPatterns-patternDoesNotMatch-contextLink", false],
];
yield confirmContextMenuItems(contextMenu, expected);
yield closeContextMenu();
+ contextMenu = yield openContextMenuInFrame("frame");
+ expected = [
+ ["documentUrlPatterns-patternMatches-contextAll", true],
+ ["documentUrlPatterns-patternMatches-contextFrame", true],
+ ];
+ yield confirmContextMenuItems(contextMenu, expected);
+ yield closeContextMenu();
+
yield extension.unload();
yield BrowserTestUtils.removeTab(tab1);
});
--- a/browser/components/extensions/test/browser/context.html
+++ b/browser/components/extensions/test/browser/context.html
@@ -15,10 +15,11 @@
<img src="ctxmenu-image.png" id="img-wrapped-in-link">
</a>
</p>
<p>
<input type="text" id="edit-me"><br>
<input type="password" id="password">
</p>
+ <iframe id="frame" src="context_frame.html"/>
</body>
</html>
new file mode 100644
--- /dev/null
+++ b/browser/components/extensions/test/browser/context_frame.html
@@ -0,0 +1,8 @@
+<html>
+ <head>
+ <meta charset="utf-8">
+ </head>
+ <body>
+ Just some text
+ </body>
+</html>
--- a/browser/components/extensions/test/browser/head.js
+++ b/browser/components/extensions/test/browser/head.js
@@ -11,17 +11,17 @@
* openContextMenu closeContextMenu
* openExtensionContextMenu closeExtensionContextMenu
* openActionContextMenu openSubmenu closeActionContextMenu
* openTabContextMenu closeTabContextMenu
* imageBuffer imageBufferFromDataURI
* getListStyleImage getPanelForNode
* awaitExtensionPanel awaitPopupResize
* promiseContentDimensions alterContent
- * promisePrefChangeObserved
+ * promisePrefChangeObserved openContextMenuInFrame
*/
const {AppConstants} = Cu.import("resource://gre/modules/AppConstants.jsm", {});
const {CustomizableUI} = Cu.import("resource:///modules/CustomizableUI.jsm", {});
// We run tests under two different configurations, from browser.ini and
// browser-remote.ini. When running from browser-remote.ini, the tests are
// copied to the sub-directory "test-oop-extensions", which we detect here, and
@@ -227,16 +227,26 @@ function closeBrowserAction(extension, w
let group = getBrowserActionWidget(extension);
let node = win.document.getElementById(group.viewId);
CustomizableUI.hidePanelForNode(node);
return Promise.resolve();
}
+async function openContextMenuInFrame(frameId) {
+ let contentAreaContextMenu = document.getElementById("contentAreaContextMenu");
+ let popupShownPromise = BrowserTestUtils.waitForEvent(contentAreaContextMenu, "popupshown");
+ let doc = gBrowser.selectedBrowser.contentDocument;
+ let frame = doc.getElementById(frameId);
+ EventUtils.synthesizeMouseAtCenter(frame.contentDocument.body, {type: "contextmenu"}, frame.contentWindow);
+ await popupShownPromise;
+ return contentAreaContextMenu;
+}
+
async function openContextMenu(selector = "#img1") {
let contentAreaContextMenu = document.getElementById("contentAreaContextMenu");
let popupShownPromise = BrowserTestUtils.waitForEvent(contentAreaContextMenu, "popupshown");
await BrowserTestUtils.synthesizeMouseAtCenter(selector, {type: "contextmenu"}, gBrowser.selectedBrowser);
await popupShownPromise;
return contentAreaContextMenu;
}