Bug 500885 - DOMActivate is fired twice for input[type=file] if user clicks on browse button, r=Olli.Pettay sr=jonas

This commit is contained in:
Geoff Lankow 2009-11-24 18:12:00 -08:00
parent 834cd77057
commit ca0d92aff0
3 changed files with 115 additions and 0 deletions

View File

@ -1748,6 +1748,22 @@ nsHTMLInputElement::PostHandleEvent(nsEventChainPostVisitor& aVisitor)
if (!aVisitor.mPresContext) {
return NS_OK;
}
// ignore the activate event fired by the "Browse..." button
// (file input controls fire their own) (bug 500885)
if (mType == NS_FORM_INPUT_FILE) {
nsCOMPtr<nsIContent> maybeButton =
do_QueryInterface(aVisitor.mEvent->originalTarget);
if (maybeButton &&
maybeButton->IsRootOfNativeAnonymousSubtree() &&
maybeButton->AttrValueIs(kNameSpaceID_None,
nsGkAtoms::type,
nsGkAtoms::button,
eCaseMatters)) {
return NS_OK;
}
}
nsresult rv = NS_OK;
PRBool outerActivateEvent = !!(aVisitor.mItemFlags & NS_OUTER_ACTIVATE_EVENT);
PRBool originalCheckedValue =

View File

@ -136,6 +136,7 @@ _TEST_FILES = test_bug589.html \
347174transformable.xml \
347174transform.xsl \
test_bug481335.xhtml \
test_bug500885.html \
test_bug514856.html \
bug514856_iframe.html \
test_bug519987.html \

View File

@ -0,0 +1,98 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=500885
-->
<head>
<title>Test for Bug 500885</title>
<script type="text/javascript" src="/MochiKit/packed.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=500885">Mozilla Bug 500885</a>
<div>
<input id="file" type="file" />
</div>
<script type="text/javascript">
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
const Cc = Components.classes;
const Ci = Components.interfaces;
const Cu = Components.utils;
const Cm = Components.manager;
Cc["@mozilla.org/moz/jssubscript-loader;1"]
.getService(Ci.mozIJSSubScriptLoader)
.loadSubScript("chrome://mochikit/content/browser/toolkit/content/tests/browser/common/mockObjects.js", this);
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
function MockFilePicker() { };
MockFilePicker.prototype = {
QueryInterface: XPCOMUtils.generateQI([Ci.nsIFilePicker]),
init: function(aParent, aTitle, aMode) { },
appendFilters: function(aFilterMask) { },
appendFilter: function(aTitle, aFilter) { },
defaultString: "",
defaultExtension: "",
filterIndex: 0,
displayDirectory: null,
file: null,
get fileURL() {
throw Cr.NS_ERROR_NOT_IMPLEMENTED;
},
get files() {
throw Cr.NS_ERROR_NOT_IMPLEMENTED;
},
show: function MFP_show() {
return Ci.nsIFilePicker.returnOK;
}
};
var mockFilePickerRegisterer =
new MockObjectRegisterer("@mozilla.org/filepicker;1",MockFilePicker);
function test() {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var wu = window.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindowUtils);
mockFilePickerRegisterer.register();
try {
var domActivateEvents;
var fileInput = document.getElementById("file");
var rect = fileInput.getBoundingClientRect();
fileInput.addEventListener ("DOMActivate", function () {
domActivateEvents++;
}, false);
domActivateEvents = 0;
wu.sendMouseEvent("mousedown", rect.left + 5, rect.top + 5, 0, 1, 0);
wu.sendMouseEvent("mouseup", rect.left + 5, rect.top + 5, 0, 1, 0);
is(domActivateEvents, 1, "click on text field should only fire 1 DOMActivate event");
domActivateEvents = 0;
wu.sendMouseEvent("mousedown", rect.right - 5, rect.top + 5, 0, 1, 0);
wu.sendMouseEvent("mouseup", rect.right - 5, rect.top + 5, 0, 1, 0);
is(domActivateEvents, 1, "click on button should only fire 1 DOMActivate event");
} finally {
mockFilePickerRegisterer.unregister();
}
SimpleTest.finish();
}
window.onload = function() {
SimpleTest.waitForExplicitFinish();
setTimeout(test, 0);
};
</script>
</body>
</html>