зеркало из https://github.com/mozilla/gecko-dev.git
bug 1274809
- Add missing properties to OnClicked data, r=aswan
MozReview-Commit-ID: 4BodpIuKCz2 --HG-- extra : rebase_source : 981fe298e821c872898f503707ccd59fcb85b869
This commit is contained in:
Родитель
33dd807e8a
Коммит
6c44e70416
|
@ -174,6 +174,7 @@ var gMenuBuilder = {
|
|||
if (event.target !== event.currentTarget) {
|
||||
return;
|
||||
}
|
||||
const wasChecked = item.checked;
|
||||
if (item.type == "checkbox") {
|
||||
item.checked = !item.checked;
|
||||
} else if (item.type == "radio") {
|
||||
|
@ -190,7 +191,7 @@ var gMenuBuilder = {
|
|||
item.tabManager.addActiveTabPermission();
|
||||
|
||||
let tab = item.tabManager.convert(contextData.tab);
|
||||
let info = item.getClickInfo(contextData, event);
|
||||
let info = item.getClickInfo(contextData, wasChecked);
|
||||
item.extension.emit("webext-contextmenu-menuitem-click", info, tab);
|
||||
if (item.onclick) {
|
||||
runSafe(item.extContext, item.onclick, info, tab);
|
||||
|
@ -399,7 +400,7 @@ MenuItem.prototype = {
|
|||
}
|
||||
},
|
||||
|
||||
getClickInfo(contextData, event) {
|
||||
getClickInfo(contextData, wasChecked) {
|
||||
let mediaType;
|
||||
if (contextData.onVideo) {
|
||||
mediaType = "video";
|
||||
|
@ -413,10 +414,11 @@ MenuItem.prototype = {
|
|||
|
||||
let info = {
|
||||
menuItemId: this.id,
|
||||
editable: contextData.onEditableArea,
|
||||
};
|
||||
|
||||
function setIfDefined(argName, value) {
|
||||
if (value) {
|
||||
if (value !== undefined) {
|
||||
info[argName] = value;
|
||||
}
|
||||
}
|
||||
|
@ -428,7 +430,11 @@ MenuItem.prototype = {
|
|||
setIfDefined("pageUrl", contextData.pageUrl);
|
||||
setIfDefined("frameUrl", contextData.frameUrl);
|
||||
setIfDefined("selectionText", contextData.selectionText);
|
||||
setIfDefined("editable", contextData.onEditableArea);
|
||||
|
||||
if ((this.type === "checkbox") || (this.type === "radio")) {
|
||||
info.checked = this.checked;
|
||||
info.wasChecked = wasChecked;
|
||||
}
|
||||
|
||||
return info;
|
||||
},
|
||||
|
|
|
@ -70,7 +70,7 @@ add_task(function* () {
|
|||
type: "separator",
|
||||
});
|
||||
|
||||
let contexts = ["page", "selection", "image"];
|
||||
let contexts = ["page", "selection", "image", "editable"];
|
||||
for (let i = 0; i < contexts.length; i++) {
|
||||
let context = contexts[i];
|
||||
let title = context;
|
||||
|
@ -144,12 +144,13 @@ add_task(function* () {
|
|||
mediaType: "image",
|
||||
srcUrl: "http://mochi.test:8888/browser/browser/components/extensions/test/browser/ctxmenu-image.png",
|
||||
pageUrl: "http://mochi.test:8888/browser/browser/components/extensions/test/browser/context.html",
|
||||
editable: false,
|
||||
};
|
||||
|
||||
function checkClickInfo(result) {
|
||||
for (let i of Object.keys(expectedClickInfo)) {
|
||||
is(result.info[i], expectedClickInfo[i],
|
||||
"click info " + i + " expected to be: " + expectedClickInfo[i] + " but was: " + info[i]);
|
||||
"click info " + i + " expected to be: " + expectedClickInfo[i] + " but was: " + result.info[i]);
|
||||
}
|
||||
is(expectedClickInfo.pageSrc, result.tab.url);
|
||||
}
|
||||
|
@ -180,6 +181,30 @@ add_task(function* () {
|
|||
result = yield extension.awaitMessage("browser.contextMenus.onClicked");
|
||||
checkClickInfo(result);
|
||||
|
||||
|
||||
// Test "editable" context and OnClick data property.
|
||||
extensionMenuRoot = yield openExtensionContextMenu("#edit-me");
|
||||
|
||||
// Check some menu items.
|
||||
items = extensionMenuRoot.getElementsByAttribute("label", "editable");
|
||||
is(items.length, 1, "contextMenu item for text input element was found (context=editable)");
|
||||
let editable = items[0];
|
||||
|
||||
// Click on ext-editable item and check the click results.
|
||||
yield closeExtensionContextMenu(editable);
|
||||
|
||||
expectedClickInfo = {
|
||||
menuItemId: "ext-editable",
|
||||
pageUrl: "http://mochi.test:8888/browser/browser/components/extensions/test/browser/context.html",
|
||||
editable: true,
|
||||
};
|
||||
|
||||
result = yield extension.awaitMessage("onclick");
|
||||
checkClickInfo(result);
|
||||
result = yield extension.awaitMessage("browser.contextMenus.onClicked");
|
||||
checkClickInfo(result);
|
||||
|
||||
|
||||
// Select some text
|
||||
yield ContentTask.spawn(gBrowser.selectedBrowser, { }, function* (arg) {
|
||||
let doc = content.document;
|
||||
|
|
|
@ -14,6 +14,11 @@ add_task(function* () {
|
|||
},
|
||||
|
||||
background: function() {
|
||||
// Report onClickData info back.
|
||||
browser.contextMenus.onClicked.addListener(info => {
|
||||
browser.test.sendMessage("contextmenus-click", info);
|
||||
});
|
||||
|
||||
browser.contextMenus.create({
|
||||
title: "Checkbox",
|
||||
type: "checkbox",
|
||||
|
@ -53,22 +58,39 @@ add_task(function* () {
|
|||
return extensionMenuRoot.getElementsByAttribute("type", "checkbox");
|
||||
}
|
||||
|
||||
function confirmOnClickData(onClickData, id, was, checked) {
|
||||
is(onClickData.wasChecked, was, `checkbox item ${id} was ${was ? "" : "not "}checked before the click`);
|
||||
is(onClickData.checked, checked, `checkbox item ${id} is ${checked ? "" : "not "}checked after the click`);
|
||||
}
|
||||
|
||||
let extensionMenuRoot = yield openExtensionContextMenu();
|
||||
let items = confirmCheckboxStates(extensionMenuRoot, [false, true, false]);
|
||||
yield closeExtensionContextMenu(items[0]);
|
||||
|
||||
let result = yield extension.awaitMessage("contextmenus-click");
|
||||
confirmOnClickData(result, 1, false, true);
|
||||
|
||||
extensionMenuRoot = yield openExtensionContextMenu();
|
||||
items = confirmCheckboxStates(extensionMenuRoot, [true, true, false]);
|
||||
yield closeExtensionContextMenu(items[2]);
|
||||
|
||||
result = yield extension.awaitMessage("contextmenus-click");
|
||||
confirmOnClickData(result, 3, false, true);
|
||||
|
||||
extensionMenuRoot = yield openExtensionContextMenu();
|
||||
items = confirmCheckboxStates(extensionMenuRoot, [true, true, true]);
|
||||
yield closeExtensionContextMenu(items[0]);
|
||||
|
||||
result = yield extension.awaitMessage("contextmenus-click");
|
||||
confirmOnClickData(result, 1, true, false);
|
||||
|
||||
extensionMenuRoot = yield openExtensionContextMenu();
|
||||
items = confirmCheckboxStates(extensionMenuRoot, [false, true, true]);
|
||||
yield closeExtensionContextMenu(items[2]);
|
||||
|
||||
result = yield extension.awaitMessage("contextmenus-click");
|
||||
confirmOnClickData(result, 3, true, false);
|
||||
|
||||
yield extension.unload();
|
||||
yield BrowserTestUtils.removeTab(tab1);
|
||||
});
|
||||
|
|
|
@ -14,6 +14,11 @@ add_task(function* () {
|
|||
},
|
||||
|
||||
background: function() {
|
||||
// Report onClickData info back.
|
||||
browser.contextMenus.onClicked.addListener(info => {
|
||||
browser.test.sendMessage("contextmenus-click", info);
|
||||
});
|
||||
|
||||
browser.contextMenus.create({
|
||||
title: "radio-group-1",
|
||||
type: "radio",
|
||||
|
@ -57,22 +62,39 @@ add_task(function* () {
|
|||
return extensionMenuRoot.getElementsByAttribute("type", "radio");
|
||||
}
|
||||
|
||||
function confirmOnClickData(onClickData, id, was, checked) {
|
||||
is(onClickData.wasChecked, was, `radio item ${id} was ${was ? "" : "not "}checked before the click`);
|
||||
is(onClickData.checked, checked, `radio item ${id} is ${checked ? "" : "not "}checked after the click`);
|
||||
}
|
||||
|
||||
let extensionMenuRoot = yield openExtensionContextMenu();
|
||||
let items = confirmRadioGroupStates(extensionMenuRoot, [true, false, false]);
|
||||
yield closeExtensionContextMenu(items[1]);
|
||||
|
||||
let result = yield extension.awaitMessage("contextmenus-click");
|
||||
confirmOnClickData(result, 2, false, true);
|
||||
|
||||
extensionMenuRoot = yield openExtensionContextMenu();
|
||||
items = confirmRadioGroupStates(extensionMenuRoot, [true, true, false]);
|
||||
yield closeExtensionContextMenu(items[2]);
|
||||
|
||||
extensionMenuRoot = yield openExtensionContextMenu();
|
||||
items = confirmRadioGroupStates(extensionMenuRoot, [true, false, true]);
|
||||
yield closeExtensionContextMenu(items[0]);
|
||||
result = yield extension.awaitMessage("contextmenus-click");
|
||||
confirmOnClickData(result, 3, false, true);
|
||||
|
||||
extensionMenuRoot = yield openExtensionContextMenu();
|
||||
items = confirmRadioGroupStates(extensionMenuRoot, [true, false, true]);
|
||||
yield closeExtensionContextMenu(items[0]);
|
||||
|
||||
result = yield extension.awaitMessage("contextmenus-click");
|
||||
confirmOnClickData(result, 1, true, true);
|
||||
|
||||
extensionMenuRoot = yield openExtensionContextMenu();
|
||||
items = confirmRadioGroupStates(extensionMenuRoot, [true, false, true]);
|
||||
yield closeExtensionContextMenu(items[0]);
|
||||
|
||||
result = yield extension.awaitMessage("contextmenus-click");
|
||||
confirmOnClickData(result, 1, true, true);
|
||||
|
||||
yield extension.unload();
|
||||
yield BrowserTestUtils.removeTab(tab1);
|
||||
});
|
||||
|
|
|
@ -14,5 +14,9 @@
|
|||
<img src="ctxmenu-image.png" id="img-wrapped-in-link">
|
||||
</a>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<input type="text" id="edit-me">
|
||||
</p>
|
||||
</body>
|
||||
</html>
|
||||
|
|
Загрузка…
Ссылка в новой задаче