Unit test for jQuery Bug #6593
HTML
<script src="http://github.com/jquery/qunit/raw/master/qunit/qunit.js"></script>
<link rel="stylesheet" href="http://github.com/jquery/qunit/raw/master/qunit/qunit.css">
<script src="http://jqueryjs.googlecode.com/svn-history/r6163/trunk/plugins/simulate/jquery.simulate.js"></script>
<h1 id="qunit-header">JQuery bugs identified/fixed by BPA</h1>
<h2 id="qunit-banner"></h2>
<div id="qunit-testrunner-toolbar"></div>
<h2 id="qunit-userAgent"></h2>
<ol id="qunit-tests"></ol>
<div id="qunit-fixture"></div>
CSS
#qunit-fixture.Visible
{
position: absolute;
left: 10px;
top: 10px;
border: 5px solid black;
background: #fff;
color: #000;
padding: 10px;
z-index: 10;
}
JavaScript
(function(j$) {
j$(document).ready(function() {
module("JQuery BPA Bugs");
test("BPA-7595: Live Change Events fire element events multiple times", function() {
var fixture$ = j$('#qunit-fixture');
fixture$.append('Testing onchange events<br /><hr />');
// create some change event handlers to tally up the events
var counts = {
"inline": 0,
"attached": 0,
"live": 0
};
var userInteractionCounts = j$.extend({}, counts);
var inlineChange = function() {
counts.inline++;
};
var attachedChange = function() {
counts.attached++;
};
var liveChange = function() {
counts.live++;
};
// create the input and bind them
window.inlineChange = inlineChange;
var input1 = j$('<input type="text" value="starts focused" />').appendTo(fixture$).focus();
var input = j$('<input id="testinput" type="text" value="startvalue" onchange="inlineChange()" />').appendTo(fixture$).bind("change", attachedChange);
fixture$.delegate("#testinput", "change", liveChange);
// Give the input the focus
input[0].focus(); // call the DOM focus() method, not the jQuery one, to work around bugs in jQuery not triggering beforeactivate event in IE
// "edit" the value
if (j$.browser.msie) {
// IE will not update the input box from simulated key events
// so, we instead of simulating key events, we'll just simulate the change event for ie
input.val("c");
}
else {
// Firefox will "do the right thing" if we send a simulated keypress to the input box followed by a blur
input.val("");
input.simulate("keypress", {
...