[HtmlUnit] SVN: [15490] trunk/htmlunit/src

rbri--- via HtmlUnit-develop <[email protected]> Sat, 21 Jul 2018 12:09:21 +0000
Newsgroups gmane.comp.java.htmlunit.devel
Message-ID <[email protected]>
Revision: 15490
          http://sourceforge.net/p/htmlunit/code/15490
Author:   rbri
Date:     2018-07-21 12:09:18 +0000 (Sat, 21 Jul 2018)
Log Message:
-----------
HTMLxxxInput.reset() results in a wrong state of the selection delegate
Issue 1969

Modified Paths:
--------------
    trunk/htmlunit/src/changes/changes.xml
    trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlEmailInput.java
    trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlNumberInput.java
    trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPasswordInput.java
    trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlTelInput.java
    trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlTextArea.java
    trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlTextInput.java
    trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlUrlInput.java
    trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlEmailInput2Test.java
    trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlNumberInput2Test.java
    trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlPasswordInput2Test.java
    trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlTelInput2Test.java
    trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlTextAreaTest.java
    trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlTextInput2Test.java
    trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlUrlInput2Test.java

Modified: trunk/htmlunit/src/changes/changes.xml
===================================================================
--- trunk/htmlunit/src/changes/changes.xml	2018-07-19 19:07:50 UTC (rev 15489)
+++ trunk/htmlunit/src/changes/changes.xml	2018-07-21 12:09:18 UTC (rev 15490)
@@ -8,6 +8,9 @@
 
     <body>
         <release version="2.32" date="xx 2018" description="Bugfixes, FIREFOX_45 removed, FIREFOX_60 added">
+            <action type="fix" dev="rbri" issue="1969">
+                HTMLxxxInput.reset() results in a wrong state of the selection delegate.
+            </action>
             <action type="add" dev="rbri">
                 FF60 ESR support.
             </action>

Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlEmailInput.java
===================================================================
--- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlEmailInput.java	2018-07-19 19:07:50 UTC (rev 15489)
+++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlEmailInput.java	2018-07-21 12:09:18 UTC (rev 15490)
@@ -156,8 +156,18 @@
 
     /**
      * {@inheritDoc}
+     * @see HtmlInput#reset()
      */
     @Override
+    public void reset() {
+        super.reset();
+        setSelectionEnd(0);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
     public DomNode cloneNode(final boolean deep) {
         final HtmlEmailInput newnode = (HtmlEmailInput) super.cloneNode(deep);
         newnode.selectionDelegate_ = new SelectableTextSelectionDelegate(newnode);

Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlNumberInput.java
===================================================================
--- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlNumberInput.java	2018-07-19 19:07:50 UTC (rev 15489)
+++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlNumberInput.java	2018-07-21 12:09:18 UTC (rev 15490)
@@ -174,14 +174,6 @@
      * {@inheritDoc}
      */
     @Override
-    protected Object clone() throws CloneNotSupportedException {
-        return new HtmlNumberInput(getQualifiedName(), getPage(), getAttributesMap());
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
     public void setDefaultValue(final String defaultValue) {
         final boolean modifyValue = getValueAttribute().equals(getDefaultValue());
         setDefaultValue(defaultValue, modifyValue);
@@ -205,8 +197,18 @@
 
     /**
      * {@inheritDoc}
+     * @see HtmlInput#reset()
      */
     @Override
+    public void reset() {
+        super.reset();
+        setSelectionEnd(0);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
     public DomNode cloneNode(final boolean deep) {
         final HtmlNumberInput newnode = (HtmlNumberInput) super.cloneNode(deep);
         newnode.selectionDelegate_ = new SelectableTextSelectionDelegate(newnode);

Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPasswordInput.java
===================================================================
--- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPasswordInput.java	2018-07-19 19:07:50 UTC (rev 15489)
+++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPasswordInput.java	2018-07-21 12:09:18 UTC (rev 15490)
@@ -158,14 +158,6 @@
      * {@inheritDoc}
      */
     @Override
-    protected Object clone() throws CloneNotSupportedException {
-        return new HtmlPasswordInput(getQualifiedName(), getPage(), getAttributesMap());
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
     protected void setAttributeNS(final String namespaceURI, final String qualifiedName, final String attributeValue,
             final boolean notifyAttributeChangeListeners, final boolean notifyMutationObservers) {
         super.setAttributeNS(namespaceURI, qualifiedName, attributeValue, notifyAttributeChangeListeners,
@@ -194,8 +186,18 @@
 
     /**
      * {@inheritDoc}
+     * @see HtmlInput#reset()
      */
     @Override
+    public void reset() {
+        super.reset();
+        setSelectionEnd(0);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
     public DomNode cloneNode(final boolean deep) {
         final HtmlPasswordInput newnode = (HtmlPasswordInput) super.cloneNode(deep);
         newnode.selectionDelegate_ = new SelectableTextSelectionDelegate(newnode);

Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlTelInput.java
===================================================================
--- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlTelInput.java	2018-07-19 19:07:50 UTC (rev 15489)
+++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlTelInput.java	2018-07-21 12:09:18 UTC (rev 15490)
@@ -150,4 +150,14 @@
 
         return newnode;
     }
+
+    /**
+     * {@inheritDoc}
+     * @see HtmlInput#reset()
+     */
+    @Override
+    public void reset() {
+        super.reset();
+        setSelectionEnd(0);
+    }
 }

Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlTextArea.java
===================================================================
--- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlTextArea.java	2018-07-19 19:07:50 UTC (rev 15489)
+++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlTextArea.java	2018-07-21 12:09:18 UTC (rev 15490)
@@ -544,14 +544,6 @@
      * {@inheritDoc}
      */
     @Override
-    protected Object clone() throws CloneNotSupportedException {
-        return new HtmlTextArea(getQualifiedName(), getPage(), getAttributesMap());
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
     protected void setAttributeNS(final String namespaceURI, final String qualifiedName, final String attributeValue,
             final boolean notifyAttributeChangeListeners, final boolean notifyMutationObservers) {
         if ("name".equals(qualifiedName)) {

Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlTextInput.java
===================================================================
--- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlTextInput.java	2018-07-19 19:07:50 UTC (rev 15489)
+++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlTextInput.java	2018-07-21 12:09:18 UTC (rev 15490)
@@ -180,17 +180,19 @@
      * {@inheritDoc}
      */
     @Override
-    protected Object clone() throws CloneNotSupportedException {
-        return new HtmlTextInput(getQualifiedName(), getPage(), getAttributesMap());
+    public void setDefaultValue(final String defaultValue) {
+        final boolean modifyValue = getValueAttribute().equals(getDefaultValue());
+        setDefaultValue(defaultValue, modifyValue);
     }
 
     /**
      * {@inheritDoc}
+     * @see HtmlInput#reset()
      */
     @Override
-    public void setDefaultValue(final String defaultValue) {
-        final boolean modifyValue = getValueAttribute().equals(getDefaultValue());
-        setDefaultValue(defaultValue, modifyValue);
+    public void reset() {
+        super.reset();
+        setSelectionEnd(0);
     }
 
     /**

Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlUrlInput.java
===================================================================
--- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlUrlInput.java	2018-07-19 19:07:50 UTC (rev 15489)
+++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlUrlInput.java	2018-07-21 12:09:18 UTC (rev 15490)
@@ -156,8 +156,18 @@
 
     /**
      * {@inheritDoc}
+     * @see HtmlInput#reset()
      */
     @Override
+    public void reset() {
+        super.reset();
+        setSelectionEnd(0);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
     public DomNode cloneNode(final boolean deep) {
         final HtmlUrlInput newnode = (HtmlUrlInput) super.cloneNode(deep);
         newnode.selectionDelegate_ = new SelectableTextSelectionDelegate(newnode);

Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlEmailInput2Test.java
===================================================================
--- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlEmailInput2Test.java	2018-07-19 19:07:50 UTC (rev 15489)
+++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlEmailInput2Test.java	2018-07-21 12:09:18 UTC (rev 15490)
@@ -49,4 +49,29 @@
         input.type("[email protected]");
         assertEquals("[email protected]", input.getValueAttribute());
     }
+
+    /**
+     * @throws Exception if the test fails
+     */
+    @Test
+    public void typingAndReset() throws Exception {
+        final String htmlContent
+            = "<html>\n"
+            + "<head></head>\n"
+            + "<body>\n"
+            + "<form id='form1'>\n"
+            + "  <input type='email' id='foo'>\n"
+            + "</form>\n"
+            + "</body></html>";
+
+        final HtmlPage page = loadPage(htmlContent);
+
+        final HtmlEmailInput input = (HtmlEmailInput) page.getElementById("foo");
+
+        input.type("[email protected]");
+        input.reset();
+        input.type("[email protected]");
+
+        assertEquals("[email protected]", input.getValueAttribute());
+    }
 }

Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlNumberInput2Test.java
===================================================================
--- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlNumberInput2Test.java	2018-07-19 19:07:50 UTC (rev 15489)
+++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlNumberInput2Test.java	2018-07-21 12:09:18 UTC (rev 15490)
@@ -49,4 +49,29 @@
         input.type("4711");
         assertEquals("4711", input.getValueAttribute());
     }
+
+    /**
+     * @throws Exception if the test fails
+     */
+    @Test
+    public void typingAndReset() throws Exception {
+        final String htmlContent
+            = "<html>\n"
+            + "<head></head>\n"
+            + "<body>\n"
+            + "<form id='form1'>\n"
+            + "  <input type='number' id='foo'>\n"
+            + "</form>\n"
+            + "</body></html>";
+
+        final HtmlPage page = loadPage(htmlContent);
+
+        final HtmlNumberInput input = (HtmlNumberInput) page.getElementById("foo");
+
+        input.type("4711");
+        input.reset();
+        input.type("0815");
+
+        assertEquals("0815", input.getValueAttribute());
+    }
 }

Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlPasswordInput2Test.java
===================================================================
--- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlPasswordInput2Test.java	2018-07-19 19:07:50 UTC (rev 15489)
+++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlPasswordInput2Test.java	2018-07-21 12:09:18 UTC (rev 15490)
@@ -107,4 +107,29 @@
         input.type("4711");
         assertEquals("4711", input.getValueAttribute());
     }
+
+    /**
+     * @throws Exception if the test fails
+     */
+    @Test
+    public void typingAndReset() throws Exception {
+        final String htmlContent
+            = "<html>\n"
+            + "<head></head>\n"
+            + "<body>\n"
+            + "<form id='form1'>\n"
+            + "  <input type='password' id='foo'>\n"
+            + "</form>\n"
+            + "</body></html>";
+
+        final HtmlPage page = loadPage(htmlContent);
+
+        final HtmlPasswordInput input = (HtmlPasswordInput) page.getElementById("foo");
+
+        input.type("4711");
+        input.reset();
+        input.type("0815");
+
+        assertEquals("0815", input.getValueAttribute());
+    }
 }

Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlTelInput2Test.java
===================================================================
--- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlTelInput2Test.java	2018-07-19 19:07:50 UTC (rev 15489)
+++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlTelInput2Test.java	2018-07-21 12:09:18 UTC (rev 15490)
@@ -49,4 +49,29 @@
         input.type("4711");
         assertEquals("4711", input.getValueAttribute());
     }
+
+    /**
+     * @throws Exception if the test fails
+     */
+    @Test
+    public void typingAndReset() throws Exception {
+        final String htmlContent
+            = "<html>\n"
+            + "<head></head>\n"
+            + "<body>\n"
+            + "<form id='form1'>\n"
+            + "  <input type='tel' id='foo'>\n"
+            + "</form>\n"
+            + "</body></html>";
+
+        final HtmlPage page = loadPage(htmlContent);
+
+        final HtmlTelInput input = (HtmlTelInput) page.getElementById("foo");
+
+        input.type("4711");
+        input.reset();
+        input.type("0815");
+
+        assertEquals("0815", input.getValueAttribute());
+    }
 }

Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlTextAreaTest.java
===================================================================
--- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlTextAreaTest.java	2018-07-19 19:07:50 UTC (rev 15489)
+++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlTextAreaTest.java	2018-07-21 12:09:18 UTC (rev 15490)
@@ -292,4 +292,51 @@
         final HtmlTextArea t = page.getHtmlElementById("t");
         t.removeFocus();
     }
+
+    /**
+     * @throws Exception if the test fails
+     */
+    @Test
+    public void typingAndClone() throws Exception {
+        final String htmlContent
+            = "<html>\n"
+            + "<head></head>\n"
+            + "<body>\n"
+            + "<form id='form1'>\n"
+            + "  <textarea id='foo'></textarea>\n"
+            + "</form>\n"
+            + "</body></html>";
+
+        final HtmlPage page = loadPage(htmlContent);
+
+        HtmlTextArea input = (HtmlTextArea) page.getElementById("foo");
+        input = (HtmlTextArea) input.cloneNode(true);
+        input.type("4711");
+        assertEquals("4711", input.getTextContent());
+    }
+
+    /**
+     * @throws Exception if the test fails
+     */
+    @Test
+    public void typingAndReset() throws Exception {
+        final String htmlContent
+            = "<html>\n"
+            + "<head></head>\n"
+            + "<body>\n"
+            + "<form id='form1'>\n"
+            + "  <textarea id='foo'></textarea>\n"
+            + "</form>\n"
+            + "</body></html>";
+
+        final HtmlPage page = loadPage(htmlContent);
+
+        final HtmlTextArea input = (HtmlTextArea) page.getElementById("foo");
+
+        input.type("4711");
+        input.reset();
+        input.type("0815");
+
+        assertEquals("0815", input.getTextContent());
+    }
 }

Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlTextInput2Test.java
===================================================================
--- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlTextInput2Test.java	2018-07-19 19:07:50 UTC (rev 15489)
+++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlTextInput2Test.java	2018-07-21 12:09:18 UTC (rev 15490)
@@ -360,4 +360,51 @@
 
         assertEquals(1, getMockWebConnection().getRequestCount());
     }
+
+    /**
+     * @throws Exception if the test fails
+     */
+    @Test
+    public void typingAndClone() throws Exception {
+        final String htmlContent
+            = "<html>\n"
+            + "<head></head>\n"
+            + "<body>\n"
+            + "<form id='form1'>\n"
+            + "  <input id='foo'>\n"
+            + "</form>\n"
+            + "</body></html>";
+
+        final HtmlPage page = loadPage(htmlContent);
+
+        HtmlTextInput input = (HtmlTextInput) page.getElementById("foo");
+        input = (HtmlTextInput) input.cloneNode(true);
+        input.type("4711");
+        assertEquals("4711", input.getValueAttribute());
+    }
+
+    /**
+     * @throws Exception if the test fails
+     */
+    @Test
+    public void typingAndReset() throws Exception {
+        final String htmlContent
+            = "<html>\n"
+            + "<head></head>\n"
+            + "<body>\n"
+            + "<form id='form1'>\n"
+            + "  <input id='foo'>\n"
+            + "</form>\n"
+            + "</body></html>";
+
+        final HtmlPage page = loadPage(htmlContent);
+
+        final HtmlTextInput input = (HtmlTextInput) page.getElementById("foo");
+
+        input.type("4711");
+        input.reset();
+        input.type("0815");
+
+        assertEquals("0815", input.getValueAttribute());
+    }
 }

Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlUrlInput2Test.java
===================================================================
--- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlUrlInput2Test.java	2018-07-19 19:07:50 UTC (rev 15489)
+++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlUrlInput2Test.java	2018-07-21 12:09:18 UTC (rev 15490)
@@ -49,4 +49,29 @@
         input.type("4711");
         assertEquals("4711", input.getValueAttribute());
     }
+
+    /**
+     * @throws Exception if the test fails
+     */
+    @Test
+    public void typingAndReset() throws Exception {
+        final String htmlContent
+            = "<html>\n"
+            + "<head></head>\n"
+            + "<body>\n"
+            + "<form id='form1'>\n"
+            + "  <input type='url' id='foo'>\n"
+            + "</form>\n"
+            + "</body></html>";
+
+        final HtmlPage page = loadPage(htmlContent);
+
+        final HtmlUrlInput input = (HtmlUrlInput) page.getElementById("foo");
+
+        input.type("4711");
+        input.reset();
+        input.type("0815");
+
+        assertEquals("0815", input.getValueAttribute());
+    }
 }


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot