Donate Share

httpunit

Tracker: Bugs

5 Order of events in button.click() is wrong - ID: 1289151
Last Update: Comment added ( wolfgang_fahl )

The button.click() implementation first triggers the
onclick event, then checks if the button is disabled,
and then fires the action. For forms where the onclick
event disables the button to keep this form from being
resubmitted, the action fails because the button is
disabled after the onclick event has been fired. The
order of events should be the same as it would be in a
browser - the button should be checked for disabled
first, then the onclick event should be triggered and
the form action submitted.


Al Lofus ( dchoc ) - 2005-09-12 22:20

5

Closed

Fixed

Wolfgang Fahl

None

None

Public


Comments ( 2 )

Date: 2008-04-01 15:05
Sender: wolfgang_fahl


The change is now in the subversion repository and will be in the next
build


Date: 2008-04-01 15:05
Sender: wolfgang_fahl


Dear Al,

excellent bug description.
It's a bit tricky to get this right.
Version 871 for the upcoming 1.7 release has a fix that is tested with the
following test in FormSubmitTest.java:
You might want to get that version from the subversion repository trunk.
/**
* test self disabling submit Buttons
* test for bug report [ 1289151 ] Order of events in button.click()
is wrong
*/
public void testSelfDisablingSubmitButton() throws Exception {
defineWebPage( "Default", "<form method=GET action =
\"Default.html\">" +
"<Input type=submit name='update'
onclick='javascript:this.disabled=true;'></form>" +
"</form>" );
WebResponse page = _wc.getResponse( getHostPath() + "/Default.html"
);
WebForm form = page.getForms()[0];
SubmitButton[] buttons = form.getSubmitButtons();
assertEquals( "num detected submit buttons", 1, buttons.length );
SubmitButton sb = form.getSubmitButton( "update" );
assertNotNull( "Failed to find update button", sb );
sb.click();
assertTrue( "Disabled button not marked as disabled", sb.isDisabled()
);
try {
form.getRequest( sb );
fail( "Allowed to create a request for a disabled button" );
} catch (IllegalStateException e) {}
try {
sb.click();
fail( "Allowed to click a disabled button" );
} catch (IllegalStateException e) {}
}


Yours
Wolfgang


Attached File

No Files Currently Attached

Changes ( 4 )

Field Old Value Date By
status_id Open 2008-04-01 15:05 wolfgang_fahl
resolution_id None 2008-04-01 15:05 wolfgang_fahl
assigned_to nobody 2008-04-01 15:05 wolfgang_fahl
close_date - 2008-04-01 15:05 wolfgang_fahl