Bug 511639 - Login manager should ignore untrusted events. r=gavin, sr=mconnor

This commit is contained in:
Justin Dolske 2009-09-22 23:23:58 -07:00
parent 03467114a9
commit 34a657bd23
2 changed files with 27 additions and 14 deletions

View File

@ -349,6 +349,9 @@ LoginManager.prototype = {
handleEvent : function (event) { handleEvent : function (event) {
if (!event.isTrusted)
return;
this._pwmgr.log("domEventListener: got event " + event.type); this._pwmgr.log("domEventListener: got event " + event.type);
switch (event.type) { switch (event.type) {

View File

@ -183,6 +183,12 @@ function checkACForm(expectedUsername, expectedPassword) {
} }
function sendFakeAutocompleteEvent(element) {
var acEvent = document.createEvent("HTMLEvents");
acEvent.initEvent("DOMAutoComplete", true, false);
element.dispatchEvent(acEvent);
}
/* /*
* Main section of test... * Main section of test...
@ -194,7 +200,11 @@ function checkACForm(expectedUsername, expectedPassword) {
*/ */
function runTest(testNum) { function runTest(testNum) {
// Seems we need to enable this again, or sendKeyEvent() complaints. // Seems we need to enable this again, or sendKeyEvent() complaints.
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect'); // But don't for test 14, or else dispatchEvent will send it as a trusted
// event (we're testing to see if we ignore untrusted events, so don't want
// that).
if (testNum != 14)
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
ok(true, "Starting test #" + testNum); ok(true, "Starting test #" + testNum);
switch(testNum) { switch(testNum) {
@ -356,6 +366,19 @@ function runTest(testNum) {
doKey("page_down"); doKey("page_down");
doKey("return"); doKey("return");
checkACForm("zzzuser4", "zzzpass4"); checkACForm("zzzuser4", "zzzpass4");
restoreForm();
break;
case 14:
// Send a fake (untrusted) event.
checkACForm("", "");
uname.value = "zzzuser4";
sendFakeAutocompleteEvent(uname);
checkACForm("zzzuser4", "");
break;
case 15:
checkACForm("zzzuser4", "");
// Trigger autocomplete popup // Trigger autocomplete popup
restoreForm(); restoreForm();
@ -363,19 +386,6 @@ function runTest(testNum) {
testNum = 49; testNum = 49;
break; break;
case 14:
// Abort with ESC
// XXX This isn't working in the test suite, seems to fubar any later tests.
// doKey("down");
// doKey("down");
// doKey("escape");
// checkACForm("", "");
// Trigger autocomplete popup
// restoreForm();
// doKey("down");
break;
// XXX tried sending character "t" before/during dropdown to test // XXX tried sending character "t" before/during dropdown to test
// filtering, but had no luck. Seemed like the character was getting lost. // filtering, but had no luck. Seemed like the character was getting lost.
// Setting uname.value didn't seem to work either. This works with a human // Setting uname.value didn't seem to work either. This works with a human