test_password_paste.html (2095B)
1 <!DOCTYPE HTML> 2 <html> 3 <head> 4 <title>Test for masking password</title> 5 <script src="/tests/SimpleTest/SimpleTest.js"></script> 6 <script src="/tests/SimpleTest/WindowSnapshot.js"></script> 7 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 8 </head> 9 <body> 10 <p id="display"></p> 11 <div id="content" style="display: none;"> 12 13 </div> 14 15 <input type="password" id="input1" value="abcdef"> 16 17 <pre id="test"> 18 <script class="testbody" type="application/javascript"> 19 function getEditor() { 20 return SpecialPowers.wrap(document.getElementById("input1")).editor; 21 } 22 23 function getLoadContext() { 24 return SpecialPowers.wrap(window).docShell.QueryInterface( 25 SpecialPowers.Ci.nsILoadContext); 26 } 27 28 function pasteText(str) { 29 const Cc = SpecialPowers.Cc; 30 const Ci = SpecialPowers.Ci; 31 let trans = Cc["@mozilla.org/widget/transferable;1"]. 32 createInstance(Ci.nsITransferable); 33 trans.init(getLoadContext()); 34 let s = Cc["@mozilla.org/supports-string;1"]. 35 createInstance(Ci.nsISupportsString); 36 s.data = str; 37 trans.setTransferData("text/plain", s); 38 let inputEvent = null; 39 window.addEventListener("input", aEvent => { inputEvent = aEvent; }, {once: true}); 40 getEditor().pasteTransferable(trans); 41 is(inputEvent.type, "input", "input event should be fired"); 42 is(inputEvent.inputType, "insertFromPaste", "inputType should be insertFromPaste"); 43 is(inputEvent.data, str, `data should be "${str}"`); 44 is(inputEvent.dataTransfer, null, "dataTransfer should be null on password field"); 45 } 46 47 SimpleTest.waitForFocus(async () => { 48 let input1 = document.getElementById("input1"); 49 input1.focus(); 50 let reference = snapshotWindow(window, false); 51 52 // Bug 1501376 - Password should be masked immediately when pasting text 53 input1.value = ""; 54 pasteText("abcdef"); 55 assertSnapshots(reference, snapshotWindow(window), true, null, 56 "Password should be masked immediately when pasting text", 57 "reference is masked"); 58 SimpleTest.finish(); 59 }); 60 61 SimpleTest.waitForExplicitFinish(); 62 </script> 63 </pre> 64 </body> 65 </html>