Files
firefox/editor/libeditor/tests/test_password_paste.html
Neil Deakin 21426e24f4 Bug 1776879, replace text/unicode for clipboard and drag and drop and use text/plain directly, r=edgar,mak,stransky,geckoview-reviewers,extension-reviewers,zombie,m_kato
Most usage is a straight replacement but gtk needs extra changes as it transfers plain text in UTF8 natively and needs to be converted into UTF16, and Windows uses single-byte characters for RTF and CF_HTML formats so we preserve this.

Differential Revision: https://phabricator.services.mozilla.com/D158587
2023-02-01 23:30:55 +00:00

66 lines
2.0 KiB
HTML

<!DOCTYPE HTML>
<html>
<head>
<title>Test for masking password</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<script src="/tests/SimpleTest/WindowSnapshot.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<p id="display"></p>
<div id="content" style="display: none;">
</div>
<input type="password" id="input1" value="abcdef">
<pre id="test">
<script class="testbody" type="application/javascript">
function getEditor() {
return SpecialPowers.wrap(document.getElementById("input1")).editor;
}
function getLoadContext() {
return SpecialPowers.wrap(window).docShell.QueryInterface(
SpecialPowers.Ci.nsILoadContext);
}
function pasteText(str) {
const Cc = SpecialPowers.Cc;
const Ci = SpecialPowers.Ci;
let trans = Cc["@mozilla.org/widget/transferable;1"].
createInstance(Ci.nsITransferable);
trans.init(getLoadContext());
let s = Cc["@mozilla.org/supports-string;1"].
createInstance(Ci.nsISupportsString);
s.data = str;
trans.setTransferData("text/plain", s);
let inputEvent = null;
window.addEventListener("input", aEvent => { inputEvent = aEvent; }, {once: true});
getEditor().pasteTransferable(trans);
is(inputEvent.type, "input", "input event should be fired");
is(inputEvent.inputType, "insertFromPaste", "inputType should be insertFromPaste");
is(inputEvent.data, str, `data should be "${str}"`);
is(inputEvent.dataTransfer, null, "dataTransfer should be null on password field");
}
SimpleTest.waitForFocus(async () => {
let input1 = document.getElementById("input1");
input1.focus();
let reference = snapshotWindow(window, false);
// Bug 1501376 - Password should be masked immediately when pasting text
input1.value = "";
pasteText("abcdef");
assertSnapshots(reference, snapshotWindow(window), true, null,
"Password should be masked immediately when pasting text",
"reference is masked");
SimpleTest.finish();
});
SimpleTest.waitForExplicitFinish();
</script>
</pre>
</body>
</html>