SF.net SVN: htmlunit: [3143] trunk/htmlunit/src

View: New views
1 Messages — Rating Filter:   Alert me  

SF.net SVN: htmlunit: [3143] trunk/htmlunit/src

by asashour :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Revision: 3143
          http://htmlunit.svn.sourceforge.net/htmlunit/?rev=3143&view=rev
Author:   asashour
Date:     2008-07-02 03:48:12 -0700 (Wed, 02 Jul 2008)

Log Message:
-----------
Ensure to focus element calling HtmlElement.type() and ClickableElement.click() (#1985241)

Modified Paths:
--------------
    trunk/htmlunit/src/changes/changes.xml
    trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/ClickableElement.java
    trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlElement.java
    trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/ClickableElementTest.java
    trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlElementTest.java

Modified: trunk/htmlunit/src/changes/changes.xml
===================================================================
--- trunk/htmlunit/src/changes/changes.xml 2008-07-01 14:09:11 UTC (rev 3142)
+++ trunk/htmlunit/src/changes/changes.xml 2008-07-02 10:48:12 UTC (rev 3143)
@@ -7,6 +7,9 @@
 
     <body>
         <release version="2.2-SNAPSHOT" description="Bugfixes (handling of ill formed HTML code, document.write, ...), speed improvements, and move to HtmlUnit-core-js (Rhino fork)">
+            <action type="update" dev="asashour" id="1985241">
+                Ensure to focus element calling HtmlElement.type() and ClickableElement.click().
+            </action>
             <action type="add" dev="asashour" id="2005930">
                 JavaScript: add support for script.text.
             </action>

Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/ClickableElement.java
===================================================================
--- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/ClickableElement.java 2008-07-01 14:09:11 UTC (rev 3142)
+++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/ClickableElement.java 2008-07-02 10:48:12 UTC (rev 3143)
@@ -89,6 +89,7 @@
         if (this instanceof DisabledElement && ((DisabledElement) this).isDisabled()) {
             return getPage();
         }
+        focus();
         final Event event = new MouseEvent(this, MouseEvent.TYPE_CLICK, shiftKey, ctrlKey, altKey,
                 MouseEvent.BUTTON_LEFT);
         return click(event);
@@ -163,6 +164,7 @@
         if (this instanceof DisabledElement && ((DisabledElement) this).isDisabled()) {
             return getPage();
         }
+        focus();
 
         //call click event first
         final Page clickPage = click(shiftKey, ctrlKey, altKey);

Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlElement.java
===================================================================
--- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlElement.java 2008-07-01 14:09:11 UTC (rev 3142)
+++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlElement.java 2008-07-02 10:48:12 UTC (rev 3143)
@@ -709,9 +709,7 @@
         if (owningForm_ != null) {
             return owningForm_;
         }
-        else {
-            return (HtmlForm) getEnclosingElement("form");
-        }
+        return (HtmlForm) getEnclosingElement("form");
     }
 
     /**
@@ -789,6 +787,7 @@
             return getPage();
         }
 
+        focus();
         fireEvent(new Event(this, Event.TYPE_KEY_DOWN, c, shiftKey, ctrlKey, altKey));
         fireEvent(new Event(this, Event.TYPE_KEY_PRESS, c, shiftKey, ctrlKey, altKey));
         doType(c, shiftKey, ctrlKey, altKey);

Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/ClickableElementTest.java
===================================================================
--- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/ClickableElementTest.java 2008-07-01 14:09:11 UTC (rev 3142)
+++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/ClickableElementTest.java 2008-07-02 10:48:12 UTC (rev 3143)
@@ -998,4 +998,23 @@
         assertEquals("click-dblclick-", textArea.getText());
     }
 
+    /**
+     * @throws Exception if the test fails
+     */
+    @Test
+    public void clickOnFocus() throws Exception {
+        final String content
+            = "<html><head><title>foo</title></head><body>\n"
+            + "<form>\n"
+            + "    <input type='button' id='textfield1' onfocus='alert(1)'>\n"
+            + "</form>\n"
+            + "</body></html>";
+        final String[] expectedAlerts = {"1"};
+        final List<String> collectedAlerts = new ArrayList<String>();
+        final HtmlPage page = loadPage(content, collectedAlerts);
+
+        ((ClickableElement) page.getHtmlElementById("textfield1")).click();
+        assertEquals(expectedAlerts, collectedAlerts);
+    }
+
 }

Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlElementTest.java
===================================================================
--- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlElementTest.java 2008-07-01 14:09:11 UTC (rev 3142)
+++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlElementTest.java 2008-07-02 10:48:12 UTC (rev 3143)
@@ -987,4 +987,23 @@
         loadPage(BrowserVersion.INTERNET_EXPLORER_7_0, html, collectedAlerts);
         assertEquals(expectedAlerts, collectedAlerts);
     }
+
+    /**
+     * @throws Exception if the test fails
+     */
+    @Test
+    public void typeOnFocus() throws Exception {
+        final String html
+            = "<html><head><title>foo</title></head><body>\n"
+            + "<form>\n"
+            + "    <input type='text' id='textfield1' onfocus='alert(1)'>\n"
+            + "</form>\n"
+            + "</body></html>";
+        final String[] expectedAlerts = {"1"};
+        final List<String> collectedAlerts = new ArrayList<String>();
+        final HtmlPage page = loadPage(html, collectedAlerts);
+
+        ((ClickableElement) page.getHtmlElementById("textfield1")).type('a');
+        assertEquals(expectedAlerts, collectedAlerts);
+    }
 }


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.

-------------------------------------------------------------------------
Sponsored by: SourceForge.net Community Choice Awards: VOTE NOW!
Studies have shown that voting for your favorite open source project,
along with a healthy diet, reduces your potential for chronic lameness
and boredom. Vote Now at http://www.sourceforge.net/community/cca08
_______________________________________________
HtmlUnit-develop mailing list
HtmlUnit-develop@...
https://lists.sourceforge.net/lists/listinfo/htmlunit-develop
LightInTheBox - Buy quality products at wholesale price