mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-08 10:44:56 +00:00
Bug 1067255 - Disallow cut and copy in password fields. r=ehsan
This commit is contained in:
parent
f19ff988ec
commit
87c112ff47
@ -642,10 +642,10 @@ function runTest(testNum) {
|
|||||||
// Context menu for selected text in input[type="password"]
|
// Context menu for selected text in input[type="password"]
|
||||||
checkContextMenu(["context-undo", false,
|
checkContextMenu(["context-undo", false,
|
||||||
"---", null,
|
"---", null,
|
||||||
"context-cut", true,
|
"context-cut", false,
|
||||||
"context-copy", true,
|
"context-copy", false,
|
||||||
"context-paste", null, // ignore clipboard state
|
"context-paste", null, // ignore clipboard state
|
||||||
"context-delete", true,
|
"context-delete", false,
|
||||||
"---", null,
|
"---", null,
|
||||||
"context-selectall", true,
|
"context-selectall", true,
|
||||||
"---", null,
|
"---", null,
|
||||||
|
@ -92,17 +92,7 @@ function dispatchTest(e) {
|
|||||||
stateMeaning = " (test: <input type=text>)";
|
stateMeaning = " (test: <input type=text>)";
|
||||||
focusScript = "var elt=content.document.getElementById('text');elt.focus();elt.select();";
|
focusScript = "var elt=content.document.getElementById('text');elt.focus();elt.select();";
|
||||||
break;
|
break;
|
||||||
case 2: // test for input password
|
case 2: // test for input number
|
||||||
defaultData = "Test for selection change event";
|
|
||||||
pasteData = "from parent ";
|
|
||||||
iframe.src = "data:text/html,<html><body>" +
|
|
||||||
"<input type='password' id='text' value='" + defaultData + "'>" +
|
|
||||||
"</body>" +
|
|
||||||
"</html>";
|
|
||||||
stateMeaning = " (test: <input type=password>)";
|
|
||||||
focusScript = "var elt=content.document.getElementById('text');elt.focus();elt.select();";
|
|
||||||
break;
|
|
||||||
case 3: // test for input number
|
|
||||||
defaultData = "12345";
|
defaultData = "12345";
|
||||||
pasteData = "67890";
|
pasteData = "67890";
|
||||||
iframe.src = "data:text/html,<html><body>" +
|
iframe.src = "data:text/html,<html><body>" +
|
||||||
@ -112,7 +102,7 @@ function dispatchTest(e) {
|
|||||||
stateMeaning = " (test: <input type=number>)";
|
stateMeaning = " (test: <input type=number>)";
|
||||||
focusScript = "var elt=content.document.getElementById('text');elt.focus();elt.select();";
|
focusScript = "var elt=content.document.getElementById('text');elt.focus();elt.select();";
|
||||||
break;
|
break;
|
||||||
case 4: // test for div contenteditable
|
case 3: // test for div contenteditable
|
||||||
defaultData = "Test for selection change event";
|
defaultData = "Test for selection change event";
|
||||||
pasteData = "from parent ";
|
pasteData = "from parent ";
|
||||||
iframe.src = "data:text/html,<html><body>" +
|
iframe.src = "data:text/html,<html><body>" +
|
||||||
@ -122,7 +112,7 @@ function dispatchTest(e) {
|
|||||||
stateMeaning = " (test: content editable div)";
|
stateMeaning = " (test: content editable div)";
|
||||||
focusScript = "var elt=content.document.getElementById('text');elt.focus();";
|
focusScript = "var elt=content.document.getElementById('text');elt.focus();";
|
||||||
break;
|
break;
|
||||||
case 5: // test for normal div
|
case 4: // test for normal div
|
||||||
SimpleTest.finish();
|
SimpleTest.finish();
|
||||||
return;
|
return;
|
||||||
defaultData = "Test for selection change event";
|
defaultData = "Test for selection change event";
|
||||||
@ -134,7 +124,7 @@ function dispatchTest(e) {
|
|||||||
stateMeaning = " (test: normal div)";
|
stateMeaning = " (test: normal div)";
|
||||||
focusScript = "var elt=content.document.getElementById('text');elt.focus();";
|
focusScript = "var elt=content.document.getElementById('text');elt.focus();";
|
||||||
break;
|
break;
|
||||||
case 6: // test for normal div with designMode:on
|
case 5: // test for normal div with designMode:on
|
||||||
defaultData = "Test for selection change event";
|
defaultData = "Test for selection change event";
|
||||||
pasteData = "from parent ";
|
pasteData = "from parent ";
|
||||||
iframe.src = "data:text/html,<html><body id='text'>" +
|
iframe.src = "data:text/html,<html><body id='text'>" +
|
||||||
@ -192,14 +182,6 @@ function testCopy1(e) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let compareData = defaultData;
|
let compareData = defaultData;
|
||||||
if (state == 2) {
|
|
||||||
// In password case, we just check length of text at clipboard is equal
|
|
||||||
// to length of defaultData
|
|
||||||
compareData = function(clipboardText) {
|
|
||||||
return clipboardText.length == defaultData.length;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
SimpleTest.waitForClipboard(compareData, setup, success, fail);
|
SimpleTest.waitForClipboard(compareData, setup, success, fail);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -215,10 +197,10 @@ function testPaste1(e) {
|
|||||||
function testPaste2(e) {
|
function testPaste2(e) {
|
||||||
mm.addMessageListener('content-text', function messageforpaste(msg) {
|
mm.addMessageListener('content-text', function messageforpaste(msg) {
|
||||||
mm.removeMessageListener('content-text', messageforpaste);
|
mm.removeMessageListener('content-text', messageforpaste);
|
||||||
if (state == 5) {
|
if (state == 4) {
|
||||||
// normal div cannot paste, so the content remain unchange
|
// normal div cannot paste, so the content remain unchange
|
||||||
ok(SpecialPowers.wrap(msg).json === defaultData, "paste command works" + stateMeaning);
|
ok(SpecialPowers.wrap(msg).json === defaultData, "paste command works" + stateMeaning);
|
||||||
} else if (state == 4 && browserElementTestHelpers.getOOPByDefaultPref()) {
|
} else if (state == 3 && browserElementTestHelpers.getOOPByDefaultPref()) {
|
||||||
// Something weird when we doCommand with content editable element in OOP. Mark this case as todo
|
// Something weird when we doCommand with content editable element in OOP. Mark this case as todo
|
||||||
todo(false, "paste command works" + stateMeaning);
|
todo(false, "paste command works" + stateMeaning);
|
||||||
} else {
|
} else {
|
||||||
@ -239,7 +221,7 @@ function testCut1(e) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let nextTest = function(success) {
|
let nextTest = function(success) {
|
||||||
if (state == 4 && browserElementTestHelpers.getOOPByDefaultPref()) {
|
if (state == 3 && browserElementTestHelpers.getOOPByDefaultPref()) {
|
||||||
// Something weird when we doCommand with content editable element in OOP.
|
// Something weird when we doCommand with content editable element in OOP.
|
||||||
todo(false, "cut function works" + stateMeaning);
|
todo(false, "cut function works" + stateMeaning);
|
||||||
} else {
|
} else {
|
||||||
@ -257,13 +239,7 @@ function testCut1(e) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let compareData = pasteData;
|
let compareData = pasteData;
|
||||||
if (state == 2) {
|
if (state == 3 && browserElementTestHelpers.getOOPByDefaultPref()) {
|
||||||
// In password case, we just check length of text at clipboard is equal
|
|
||||||
// to length of pasteData
|
|
||||||
compareData = function(clipboardText) {
|
|
||||||
return clipboardText.length == pasteData.length;
|
|
||||||
};
|
|
||||||
} else if (state == 4 && browserElementTestHelpers.getOOPByDefaultPref()) {
|
|
||||||
// Something weird when we doCommand with content editable element in OOP.
|
// Something weird when we doCommand with content editable element in OOP.
|
||||||
// Always true in this case
|
// Always true in this case
|
||||||
compareData = function() { return true; }
|
compareData = function() { return true; }
|
||||||
@ -276,9 +252,9 @@ function testCut2(e) {
|
|||||||
mm.addMessageListener('content-text', function messageforcut(msg) {
|
mm.addMessageListener('content-text', function messageforcut(msg) {
|
||||||
mm.removeMessageListener('content-text', messageforcut);
|
mm.removeMessageListener('content-text', messageforcut);
|
||||||
// normal div cannot cut
|
// normal div cannot cut
|
||||||
if (state == 5) {
|
if (state == 4) {
|
||||||
ok(SpecialPowers.wrap(msg).json !== "", "cut command works" + stateMeaning);
|
ok(SpecialPowers.wrap(msg).json !== "", "cut command works" + stateMeaning);
|
||||||
} else if (state == 4 && browserElementTestHelpers.getOOPByDefaultPref()) {
|
} else if (state == 3 && browserElementTestHelpers.getOOPByDefaultPref()) {
|
||||||
// Something weird when we doCommand with content editable element in OOP. Mark this case as todo
|
// Something weird when we doCommand with content editable element in OOP. Mark this case as todo
|
||||||
todo(false, "cut command works" + stateMeaning);
|
todo(false, "cut command works" + stateMeaning);
|
||||||
} else {
|
} else {
|
||||||
|
@ -1163,6 +1163,9 @@ nsPlaintextEditor::CanCutOrCopy()
|
|||||||
if (NS_FAILED(GetSelection(getter_AddRefs(selection))))
|
if (NS_FAILED(GetSelection(getter_AddRefs(selection))))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
if (IsPasswordEditor())
|
||||||
|
return false;
|
||||||
|
|
||||||
return !selection->Collapsed();
|
return !selection->Collapsed();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -138,6 +138,7 @@ skip-if = os != "win"
|
|||||||
skip-if = os != "win"
|
skip-if = os != "win"
|
||||||
[test_bug998188.html]
|
[test_bug998188.html]
|
||||||
[test_bug1026397.html]
|
[test_bug1026397.html]
|
||||||
|
[test_bug1067255.html]
|
||||||
skip-if = e10s
|
skip-if = e10s
|
||||||
[test_CF_HTML_clipboard.html]
|
[test_CF_HTML_clipboard.html]
|
||||||
[test_contenteditable_focus.html]
|
[test_contenteditable_focus.html]
|
||||||
|
52
editor/libeditor/tests/test_bug1067255.html
Normal file
52
editor/libeditor/tests/test_bug1067255.html
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
<!DOCTYPE HTML>
|
||||||
|
<!-- 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/. -->
|
||||||
|
<html>
|
||||||
|
<!--
|
||||||
|
https://bugzilla.mozilla.org/show_bug.cgi?id=1067255
|
||||||
|
-->
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<title>Test for Bug 1067255</title>
|
||||||
|
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||||
|
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||||
|
<script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body onload="doTest();">
|
||||||
|
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1067255">Mozilla Bug 1067255</a>
|
||||||
|
|
||||||
|
<pre id="test">
|
||||||
|
<script type="application/javascript">
|
||||||
|
/** Test for Bug 1067255 **/
|
||||||
|
SimpleTest.waitForExplicitFinish();
|
||||||
|
|
||||||
|
function doTest() {
|
||||||
|
var text = $("text-field");
|
||||||
|
var password = $("password-field");
|
||||||
|
|
||||||
|
var editor1 = SpecialPowers.wrap(text).editor;
|
||||||
|
var editor2 = SpecialPowers.wrap(password).editor;
|
||||||
|
|
||||||
|
text.focus();
|
||||||
|
text.select();
|
||||||
|
|
||||||
|
ok(editor1.canCopy(), "can copy, text");
|
||||||
|
ok(editor1.canCut(), "can cut, text");
|
||||||
|
|
||||||
|
password.focus();
|
||||||
|
password.select();
|
||||||
|
|
||||||
|
ok(!editor2.canCopy(), "can copy, password");
|
||||||
|
ok(!editor2.canCut(), "can cut, password");
|
||||||
|
|
||||||
|
SimpleTest.finish();
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<input type="text" value="Gonzo says hi" id="text-field" />
|
||||||
|
<input type="password" value="Jan also" id="password-field" />
|
||||||
|
</body>
|
||||||
|
</html>
|
Loading…
Reference in New Issue
Block a user