Bug 1067255 - Disallow cut and copy in password fields. r=ehsan

This commit is contained in:
Jan Jongboom 2014-10-08 16:27:31 -07:00
Родитель f19ff988ec
Коммит 87c112ff47
5 изменённых файлов: 69 добавлений и 37 удалений

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

@ -642,10 +642,10 @@ function runTest(testNum) {
// Context menu for selected text in input[type="password"]
checkContextMenu(["context-undo", false,
"---", null,
"context-cut", true,
"context-copy", true,
"context-cut", false,
"context-copy", false,
"context-paste", null, // ignore clipboard state
"context-delete", true,
"context-delete", false,
"---", null,
"context-selectall", true,
"---", null,

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

@ -92,17 +92,7 @@ function dispatchTest(e) {
stateMeaning = " (test: <input type=text>)";
focusScript = "var elt=content.document.getElementById('text');elt.focus();elt.select();";
break;
case 2: // test for input password
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
case 2: // test for input number
defaultData = "12345";
pasteData = "67890";
iframe.src = "data:text/html,<html><body>" +
@ -112,7 +102,7 @@ function dispatchTest(e) {
stateMeaning = " (test: <input type=number>)";
focusScript = "var elt=content.document.getElementById('text');elt.focus();elt.select();";
break;
case 4: // test for div contenteditable
case 3: // test for div contenteditable
defaultData = "Test for selection change event";
pasteData = "from parent ";
iframe.src = "data:text/html,<html><body>" +
@ -122,7 +112,7 @@ function dispatchTest(e) {
stateMeaning = " (test: content editable div)";
focusScript = "var elt=content.document.getElementById('text');elt.focus();";
break;
case 5: // test for normal div
case 4: // test for normal div
SimpleTest.finish();
return;
defaultData = "Test for selection change event";
@ -134,7 +124,7 @@ function dispatchTest(e) {
stateMeaning = " (test: normal div)";
focusScript = "var elt=content.document.getElementById('text');elt.focus();";
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";
pasteData = "from parent ";
iframe.src = "data:text/html,<html><body id='text'>" +
@ -192,14 +182,6 @@ function testCopy1(e) {
}
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);
}
@ -215,10 +197,10 @@ function testPaste1(e) {
function testPaste2(e) {
mm.addMessageListener('content-text', function messageforpaste(msg) {
mm.removeMessageListener('content-text', messageforpaste);
if (state == 5) {
if (state == 4) {
// normal div cannot paste, so the content remain unchange
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
todo(false, "paste command works" + stateMeaning);
} else {
@ -239,7 +221,7 @@ function testCut1(e) {
};
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.
todo(false, "cut function works" + stateMeaning);
} else {
@ -257,13 +239,7 @@ function testCut1(e) {
}
let compareData = pasteData;
if (state == 2) {
// 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()) {
if (state == 3 && browserElementTestHelpers.getOOPByDefaultPref()) {
// Something weird when we doCommand with content editable element in OOP.
// Always true in this case
compareData = function() { return true; }
@ -276,9 +252,9 @@ function testCut2(e) {
mm.addMessageListener('content-text', function messageforcut(msg) {
mm.removeMessageListener('content-text', messageforcut);
// normal div cannot cut
if (state == 5) {
if (state == 4) {
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
todo(false, "cut command works" + stateMeaning);
} else {

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

@ -1163,6 +1163,9 @@ nsPlaintextEditor::CanCutOrCopy()
if (NS_FAILED(GetSelection(getter_AddRefs(selection))))
return false;
if (IsPasswordEditor())
return false;
return !selection->Collapsed();
}

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

@ -138,6 +138,7 @@ skip-if = os != "win"
skip-if = os != "win"
[test_bug998188.html]
[test_bug1026397.html]
[test_bug1067255.html]
skip-if = e10s
[test_CF_HTML_clipboard.html]
[test_contenteditable_focus.html]

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

@ -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>