patch for 2407470

Adam Heath <[email protected]> Wed, 18 Mar 2009 22:38:09 -0500
Newsgroups gmane.comp.web.httpunit.devel
Message-ID <[email protected]>
In httpunit 1.6.2, I had a document with a <form> that had an id.  My
test case then looked that up, with getFormWithID, and all was right
in the world.

This fails with httpunit 1.7.

I'm thinking this failure is the same one as 2407470.  From my
debugging of the issue, when the document is being parsed, any/all
script tags are run, and/or the scripting engine(s) are started.  The
javascript engine tries to get a list of forms.  Since this happens
'early', there are no proxies around the raw dom, so those get
created.  However, now once javascript is loaded, the dom walking
continues processing.  When it gets to the form element, it is already
in the ElementRegistry, so never gets added to the map/list internal
look variables.

Anyways, the attached patch fixes my problem for me, and seems rather
small.  It also makes the public getFoo functions more similiar.

http://sourceforge.net/tracker/index.php?func=detail&aid=2407470&group_id=6550&atid=106550

ps: I am not subscribed, please cc me

------------------------------------------------------------------------------
Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are
powering Web 2.0 with engaging, cross-platform capabilities. Quickly and
easily build your RIAs with Flex Builder, the Eclipse(TM)based development
software that enables intelligent coding and step-through debugging.
Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com

_______________________________________________
Httpunit-develop mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/httpunit-develop
register-elements-earlier.patch (text/x-diff, 3 KB)
=== src/com/meterware/httpunit/ParsedHTML.java
==================================================================
--- src/com/meterware/httpunit/ParsedHTML.java	(revision 981)
+++ src/com/meterware/httpunit/ParsedHTML.java	(local)
@@ -96,6 +96,7 @@
      * @return an array of objects representing the forms in the page or portion of a page.
      **/
     public WebForm[] getForms() {
+        loadElements();
         HTMLCollection forms = ((HTMLContainerElement) _rootNode).getForms();
         WebForm[] result = new WebForm[ forms.getLength() ];
         for (int i = 0; i < result.length; i++) {
@@ -115,6 +116,7 @@
      * Returns the links found in the page in the order in which they appear.
      **/
     public WebLink[] getLinks() {
+        loadElements();
         HTMLCollection links = ((HTMLContainerElement) _rootNode).getLinks();
         WebLink[] result = new WebLink[ links.getLength() ];
         for (int i = 0; i < result.length; i++) {
@@ -132,6 +134,7 @@
      * Returns a proxy for each applet found embedded in this page.
      */
     public WebApplet[] getApplets() {
+        loadElements();
         HTMLCollection applets = ((HTMLContainerElement) _rootNode).getApplets();
         WebApplet[] result = new WebApplet[ applets.getLength() ];
         for (int i = 0; i < result.length; i++) {
@@ -149,6 +152,7 @@
      * Returns the images found in the page in the order in which they appear.
      */
     public WebImage[] getImages() {
+        loadElements();
         HTMLCollection images = ((HTMLContainerElement) _rootNode).getImages();
         WebImage[] result = new WebImage[ images.getLength() ];
         for (int i = 0; i < result.length; i++) {
@@ -166,6 +170,7 @@
      * Returns the top-level block elements found in the page in the order in which they appear.
      */
     public TextBlock[] getTextBlocks() {
+        loadElements();
         if (_blocks == null) {
             loadElements();
             _blocks = (TextBlock[]) _blocksList.toArray( new TextBlock[ _blocksList.size() ] );
@@ -178,6 +183,7 @@
      * Returns the first text block found in the page which matches the specified predicate and value.
      */
     public TextBlock getFirstMatchingTextBlock( HTMLElementPredicate predicate, Object criteria ) {
+        loadElements();
         TextBlock[] blocks = getTextBlocks();
         for (int i = 0; i < blocks.length; i++) {
             if (predicate.matchesCriteria( blocks[i], criteria )) return blocks[i];
@@ -187,6 +193,7 @@
 
 
     public TextBlock getNextTextBlock( TextBlock block ) {
+        loadElements();
         int index = _blocksList.indexOf( block );
         if (index < 0 || index == _blocksList.size() - 1) return null;
         return (TextBlock) _blocksList.get( index+1 );
@@ -197,6 +204,7 @@
      * Returns the top-level tables found in the page in the order in which they appear.
      **/
     public WebTable[] getTables() {
+        loadElements();
         if (_tables == null) {
             loadElements();
             _tables = (WebTable[]) _tableList.toArray( new WebTable[ _tableList.size() ] );