Bug 961702 - "Copy" context menu action doesn't copy rich content while document in design mode (or inside container that allows to edit its content). r=sfoster

--HG--
rename : browser/metro/base/tests/mochitest/browser_context_menu_tests_04.html => browser/metro/base/tests/mochitest/browser_context_menu_tests_05.html
This commit is contained in:
Aleh Zasypkin 2014-01-21 20:04:04 +01:00
Родитель 9ad450b900
Коммит 9e840cbd3c
4 изменённых файлов: 113 добавлений и 3 удалений

Просмотреть файл

@ -165,6 +165,13 @@ var ContextMenuHandler = {
} else {
Util.dumpLn("error: target element does not support nsIDOMNSEditableElement");
}
} else if (Util.isEditableContent(this._target)) {
try {
this._target.ownerDocument.execCommand("copy", false);
} catch (ex) {
dump("ContextMenuHandler: exception copying from contentEditable: " +
ex.message + "\n");
}
} else {
let selectionText = this._previousState.string;

Просмотреть файл

@ -744,7 +744,7 @@ gTests.push({
// Case #2: Document isn't in design mode and text is selected.
tabWindow.getSelection().selectAllChildren(testSpan);
let promise = waitForEvent(tabWindow.document, "popupshown");
let promise = waitForEvent(document, "popupshown");
sendContextMenuClickToSelection(tabWindow);
yield promise;
@ -758,7 +758,7 @@ gTests.push({
tabWindow.document.designMode = "on";
tabWindow.getSelection().removeAllRanges();
promise = waitForEvent(tabWindow.document, "popupshown");
promise = waitForEvent(document, "popupshown");
sendContextMenuClickToElement(tabWindow, testSpan);
yield promise;
@ -771,7 +771,7 @@ gTests.push({
// Case #4: Document is in design mode and text is selected.
tabWindow.getSelection().selectAllChildren(testSpan);
promise = waitForEvent(tabWindow.document, "popupshown");
promise = waitForEvent(document, "popupshown");
sendContextMenuClickToSelection(tabWindow);
yield promise;
@ -787,6 +787,93 @@ gTests.push({
}
});
gTests.push({
desc: "Bug 961702 - 'Copy' context menu action does not copy rich content " +
"while document in design mode (or inside container that allows to " +
"edit its content)",
run: function test() {
info(chromeRoot + "browser_context_menu_tests_05.html");
yield addTab(chromeRoot + "browser_context_menu_tests_05.html");
purgeEventQueue();
emptyClipboard();
ContextUI.dismiss();
yield waitForCondition(() => !ContextUI.navbarVisible);
let tabWindow = Browser.selectedTab.browser.contentWindow;
let testDiv = tabWindow.document.getElementById("div1");
// Case #1: Document is in design mode.
tabWindow.document.designMode = "on";
let promise = waitForEvent(document, "popupshown");
sendContextMenuClickToElement(tabWindow, testDiv);
yield promise;
let selectAllMenuItem = document.getElementById("context-select-all");
promise = waitForEvent(document, "popuphidden");
sendNativeTap(selectAllMenuItem);
yield promise;
promise = waitForEvent(document, "popupshown");
sendContextMenuClickToSelection(tabWindow);
yield promise;
let copyMenuItem = document.getElementById("context-copy");
promise = waitForEvent(document, "popuphidden");
sendNativeTap(copyMenuItem);
yield promise;
// The wait is needed to give time to populate the clipboard.
let clipboardContent = "";
let contentToCopy = tabWindow.document.body.innerHTML;
yield waitForCondition(function () {
clipboardContent = SpecialPowers.getClipboardData("text/html");
return clipboardContent == contentToCopy;
});
ok(clipboardContent == contentToCopy, "Rich content copied.");
// Case #2: Container with editable content.
emptyClipboard();
tabWindow.document.designMode = "off";
tabWindow.getSelection().removeAllRanges();
promise = waitForEvent(tabWindow.document.body, "focus");
sendNativeTap(testDiv);
yield promise;
promise = waitForEvent(document, "popupshown");
sendContextMenuClickToElement(tabWindow, testDiv);
yield promise;
selectAllMenuItem = document.getElementById("context-select-all");
promise = waitForEvent(document, "popuphidden");
sendNativeTap(selectAllMenuItem);
yield promise;
promise = waitForEvent(document, "popupshown");
sendContextMenuClickToSelection(tabWindow);
yield promise;
copyMenuItem = document.getElementById("context-copy");
promise = waitForEvent(document, "popuphidden");
sendNativeTap(copyMenuItem);
yield promise;
// The wait is needed to give time to populate the clipboard.
clipboardContent = "";
contentToCopy = testDiv.innerHTML;
yield waitForCondition(function () {
clipboardContent = SpecialPowers.getClipboardData("text/html");
return clipboardContent == contentToCopy;
});
ok(clipboardContent == contentToCopy, "Rich content copied.");
Browser.closeTab(Browser.selectedTab, { forceClose: true });
}
});
function test() {
setDevPixelEqualToPx();
runTests();

Просмотреть файл

@ -0,0 +1,15 @@
<!DOCTYPE html>
<html>
<head>
<style>
</style>
</head>
<body style="padding: 10px; margin: 10px;">
<span id="text1">Test text</span>
<div contenteditable="true" id="div1" style="border: 2px solid blue; width: 200px; height: 200px;">
<table>
<tr><td>Test content</td></tr>
</table>
</div>
</body>
</html>

Просмотреть файл

@ -4,6 +4,7 @@ support-files =
browser_context_menu_tests_02.html
browser_context_menu_tests_03.html
browser_context_menu_tests_04.html
browser_context_menu_tests_05.html
browser_findbar.html
browser_form_auto_complete.html
browser_form_selects.html