From: <rb...@us...> - 2018-03-22 19:35:48
|
Revision: 15180 http://sourceforge.net/p/htmlunit/code/15180 Author: rbri Date: 2018-03-22 19:35:43 +0000 (Thu, 22 Mar 2018) Log Message: ----------- Improved clone implementation to take care of references Issue 1959 Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DomText.java 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/HtmlPasswordInput2Test.java Added Paths: ----------- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlNumberInput2Test.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlTelInput2Test.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-03-21 20:35:01 UTC (rev 15179) +++ trunk/htmlunit/src/changes/changes.xml 2018-03-22 19:35:43 UTC (rev 15180) @@ -8,6 +8,9 @@ <body> <release version="2.30" date="xx, 2018" description="Bugfixes, URLSearchParams implemented, start adding support of user defined iterators, CHROME 64"> + <action type="fix" dev="rbri" issue="1959"> + Improved clone implementation to take care of references. + </action> <action type="fix" dev="rbri" issue="1956"> Setting the Map size property is now ignored (or throws a Type error in strict mode). </action> Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DomText.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DomText.java 2018-03-21 20:35:01 UTC (rev 15179) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DomText.java 2018-03-22 19:35:43 UTC (rev 15180) @@ -33,6 +33,7 @@ * @author Ahmed Ashour * @author Sudhan Moghe * @author Philip Graf + * @author Ronald Brill */ public class DomText extends DomCharacterData implements Text { @@ -215,4 +216,15 @@ return (c < '\uE000' || c > '\uF8FF') && (c == ' ' || !Character.isWhitespace(c)); } + /** + * {@inheritDoc} + */ + @Override + public DomNode cloneNode(final boolean deep) { + final DomText newnode = (DomText) super.cloneNode(deep); + selectionDelegate_ = new SimpleSelectionDelegate(); + doTypeProcessor_ = new DoTypeProcessor(this); + + return newnode; + } } Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlEmailInput.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlEmailInput.java 2018-03-21 20:35:01 UTC (rev 15179) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlEmailInput.java 2018-03-22 19:35:43 UTC (rev 15180) @@ -28,12 +28,13 @@ * Wrapper for the HTML element "input" where type is "email". * * @author Ahmed Ashour + * @author Ronald Brill */ public class HtmlEmailInput extends HtmlInput implements SelectableTextInput { private final SelectableTextSelectionDelegate selectionDelegate_ = new SelectableTextSelectionDelegate(this); - private final DoTypeProcessor doTypeProcessor_ = new DoTypeProcessor(this); + private DoTypeProcessor doTypeProcessor_ = new DoTypeProcessor(this); /** * Creates an instance. @@ -154,4 +155,14 @@ } } + /** + * {@inheritDoc} + */ + @Override + public DomNode cloneNode(final boolean deep) { + final HtmlEmailInput newnode = (HtmlEmailInput) super.cloneNode(deep); + newnode.doTypeProcessor_ = new DoTypeProcessor(newnode); + + return 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-03-21 20:35:01 UTC (rev 15179) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlNumberInput.java 2018-03-22 19:35:43 UTC (rev 15180) @@ -30,10 +30,9 @@ */ public class HtmlNumberInput extends HtmlInput implements SelectableTextInput { - private final SelectableTextSelectionDelegate selectionDelegate_ = new SelectableTextSelectionDelegate(this); + private SelectableTextSelectionDelegate selectionDelegate_ = new SelectableTextSelectionDelegate(this); + private DoTypeProcessor doTypeProcessor_ = new DoTypeProcessor(this); - private final DoTypeProcessor doTypeProcessor_ = new DoTypeProcessor(this); - /** * Creates an instance. * @@ -203,4 +202,16 @@ // ignore } } + + /** + * {@inheritDoc} + */ + @Override + public DomNode cloneNode(final boolean deep) { + final HtmlNumberInput newnode = (HtmlNumberInput) super.cloneNode(deep); + newnode.selectionDelegate_ = new SelectableTextSelectionDelegate(newnode); + newnode.doTypeProcessor_ = new DoTypeProcessor(newnode); + + return 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-03-21 20:35:01 UTC (rev 15179) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPasswordInput.java 2018-03-22 19:35:43 UTC (rev 15180) @@ -35,10 +35,9 @@ */ public class HtmlPasswordInput extends HtmlInput implements SelectableTextInput { - private final SelectableTextSelectionDelegate selectionDelegate_ = new SelectableTextSelectionDelegate(this); + private SelectableTextSelectionDelegate selectionDelegate_ = new SelectableTextSelectionDelegate(this); + private DoTypeProcessor doTypeProcessor_ = new DoTypeProcessor(this); - private final DoTypeProcessor doTypeProcessor_ = new DoTypeProcessor(this); - /** * Creates an instance. * @@ -192,4 +191,16 @@ final boolean modifyValue = getValueAttribute().equals(getDefaultValue()); setDefaultValue(defaultValue, modifyValue); } + + /** + * {@inheritDoc} + */ + @Override + public DomNode cloneNode(final boolean deep) { + final HtmlPasswordInput newnode = (HtmlPasswordInput) super.cloneNode(deep); + newnode.selectionDelegate_ = new SelectableTextSelectionDelegate(newnode); + newnode.doTypeProcessor_ = new DoTypeProcessor(newnode); + + return 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-03-21 20:35:01 UTC (rev 15179) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlTelInput.java 2018-03-22 19:35:43 UTC (rev 15180) @@ -24,13 +24,13 @@ * Wrapper for the HTML element "input" where type is "tel". * * @author Ahmed Ashour + * @author Ronald Brill */ public class HtmlTelInput extends HtmlInput implements SelectableTextInput { - private final SelectableTextSelectionDelegate selectionDelegate_ = new SelectableTextSelectionDelegate(this); + private SelectableTextSelectionDelegate selectionDelegate_ = new SelectableTextSelectionDelegate(this); + private DoTypeProcessor doTypeProcessor_ = new DoTypeProcessor(this); - private final DoTypeProcessor doTypeProcessor_ = new DoTypeProcessor(this); - /** * Creates an instance. * @@ -139,4 +139,15 @@ } } + /** + * {@inheritDoc} + */ + @Override + public DomNode cloneNode(final boolean deep) { + final HtmlTelInput newnode = (HtmlTelInput) super.cloneNode(deep); + newnode.selectionDelegate_ = new SelectableTextSelectionDelegate(newnode); + newnode.doTypeProcessor_ = new DoTypeProcessor(newnode); + + return newnode; + } } Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlTextArea.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlTextArea.java 2018-03-21 20:35:01 UTC (rev 15179) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlTextArea.java 2018-03-22 19:35:43 UTC (rev 15180) @@ -61,10 +61,9 @@ private String originalName_; private Collection<String> newNames_ = Collections.emptySet(); - private final SelectableTextSelectionDelegate selectionDelegate_ = new SelectableTextSelectionDelegate(this); + private SelectableTextSelectionDelegate selectionDelegate_ = new SelectableTextSelectionDelegate(this); + private DoTypeProcessor doTypeProcessor_ = new DoTypeProcessor(this); - private final DoTypeProcessor doTypeProcessor_ = new DoTypeProcessor(this); - /** * Creates an instance. * @@ -626,4 +625,17 @@ protected boolean isRequiredSupported() { return true; } + + /** + * {@inheritDoc} + */ + @Override + public DomNode cloneNode(final boolean deep) { + final HtmlTextArea newnode = (HtmlTextArea) super.cloneNode(deep); + newnode.selectionDelegate_ = new SelectableTextSelectionDelegate(newnode); + newnode.doTypeProcessor_ = new DoTypeProcessor(newnode); + newnode.newNames_ = new HashSet<>(newNames_); + + return newnode; + } } Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlTextInput.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlTextInput.java 2018-03-21 20:35:01 UTC (rev 15179) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlTextInput.java 2018-03-22 19:35:43 UTC (rev 15180) @@ -36,10 +36,9 @@ */ public class HtmlTextInput extends HtmlInput implements SelectableTextInput { - private final SelectableTextSelectionDelegate selectionDelegate_ = new SelectableTextSelectionDelegate(this); + private SelectableTextSelectionDelegate selectionDelegate_ = new SelectableTextSelectionDelegate(this); + private DoTypeProcessor doTypeProcessor_ = new DoTypeProcessor(this); - private final DoTypeProcessor doTypeProcessor_ = new DoTypeProcessor(this); - /** * Creates an instance. * @@ -193,4 +192,16 @@ final boolean modifyValue = getValueAttribute().equals(getDefaultValue()); setDefaultValue(defaultValue, modifyValue); } + + /** + * {@inheritDoc} + */ + @Override + public DomNode cloneNode(final boolean deep) { + final HtmlTextInput newnode = (HtmlTextInput) super.cloneNode(deep); + newnode.selectionDelegate_ = new SelectableTextSelectionDelegate(newnode); + newnode.doTypeProcessor_ = new DoTypeProcessor(newnode); + + return newnode; + } } Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlUrlInput.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlUrlInput.java 2018-03-21 20:35:01 UTC (rev 15179) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlUrlInput.java 2018-03-22 19:35:43 UTC (rev 15180) @@ -28,13 +28,13 @@ * Wrapper for the HTML element "input" where type is "url". * * @author Ahmed Ashour + * @author Ronald Brill */ public class HtmlUrlInput extends HtmlInput implements SelectableTextInput { - private final SelectableTextSelectionDelegate selectionDelegate_ = new SelectableTextSelectionDelegate(this); + private SelectableTextSelectionDelegate selectionDelegate_ = new SelectableTextSelectionDelegate(this); + private DoTypeProcessor doTypeProcessor_ = new DoTypeProcessor(this); - private final DoTypeProcessor doTypeProcessor_ = new DoTypeProcessor(this); - /** * Creates an instance. * @@ -154,4 +154,15 @@ } } + /** + * {@inheritDoc} + */ + @Override + public DomNode cloneNode(final boolean deep) { + final HtmlUrlInput newnode = (HtmlUrlInput) super.cloneNode(deep); + newnode.selectionDelegate_ = new SelectableTextSelectionDelegate(newnode); + newnode.doTypeProcessor_ = new DoTypeProcessor(newnode); + + return 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-03-21 20:35:01 UTC (rev 15179) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlEmailInput2Test.java 2018-03-22 19:35:43 UTC (rev 15180) @@ -32,7 +32,7 @@ * @throws Exception if the test fails */ @Test - public void typing() throws Exception { + public void typingAndClone() throws Exception { final String htmlContent = "<html>\n" + "<head></head>\n" @@ -39,27 +39,14 @@ + "<body>\n" + "<form id='form1'>\n" + " <input type='email' id='foo'>\n" - + " <input type='email' id='foo2' value='x...@em...' >\n" + "</form>\n" + "</body></html>"; final HtmlPage page = loadPage(htmlContent); - HtmlEmailInput emailInput = (HtmlEmailInput) page.getElementById("foo"); - emailInput.focus(); - emailInput.type("my...@em..."); - - emailInput = (HtmlEmailInput) page.getElementById("foo2"); - emailInput.focus(); - emailInput.type("abc"); - assertEquals("ab...@em...", emailInput.getValueAttribute()); - - emailInput.setSelectionStart(4); - emailInput.type("xx"); - assertEquals("ab...@em...", emailInput.getValueAttribute()); - - emailInput.setSelectionStart(1); - emailInput.type("y"); - assertEquals("ay...@em...", emailInput.getValueAttribute()); + HtmlEmailInput input = (HtmlEmailInput) page.getElementById("foo"); + input = (HtmlEmailInput) input.cloneNode(true); + input.type("ab...@em..."); + assertEquals("ab...@em...", input.getValueAttribute()); } } Added: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlNumberInput2Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlNumberInput2Test.java (rev 0) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlNumberInput2Test.java 2018-03-22 19:35:43 UTC (rev 15180) @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2002-2018 Gargoyle Software Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.gargoylesoftware.htmlunit.html; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import com.gargoylesoftware.htmlunit.BrowserRunner; +import com.gargoylesoftware.htmlunit.SimpleWebTestCase; + +/** + * Tests for {@link HtmlNumberInput}. + * + * @author Ronald Brill + */ +@RunWith(BrowserRunner.class) +public class HtmlNumberInput2Test extends SimpleWebTestCase { + + /** + * @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 type='number' id='foo'>\n" + + "</form>\n" + + "</body></html>"; + + final HtmlPage page = loadPage(htmlContent); + + HtmlNumberInput input = (HtmlNumberInput) page.getElementById("foo"); + input = (HtmlNumberInput) input.cloneNode(true); + input.type("4711"); + assertEquals("4711", input.getValueAttribute()); + } +} Property changes on: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlNumberInput2Test.java ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlPasswordInput2Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlPasswordInput2Test.java 2018-03-21 20:35:01 UTC (rev 15179) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlPasswordInput2Test.java 2018-03-22 19:35:43 UTC (rev 15180) @@ -85,4 +85,26 @@ t.type(KeyboardEvent.DOM_VK_DELETE); assertEquals("tt", t.getValueAttribute()); } + + /** + * @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 type='password' id='foo'>\n" + + "</form>\n" + + "</body></html>"; + + final HtmlPage page = loadPage(htmlContent); + + HtmlPasswordInput input = (HtmlPasswordInput) page.getElementById("foo"); + input = (HtmlPasswordInput) input.cloneNode(true); + input.type("4711"); + assertEquals("4711", input.getValueAttribute()); + } } Added: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlTelInput2Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlTelInput2Test.java (rev 0) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlTelInput2Test.java 2018-03-22 19:35:43 UTC (rev 15180) @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2002-2018 Gargoyle Software Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.gargoylesoftware.htmlunit.html; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import com.gargoylesoftware.htmlunit.BrowserRunner; +import com.gargoylesoftware.htmlunit.SimpleWebTestCase; + +/** + * Tests for {@link HtmlTelInput}. + * + * @author Ronald Brill + */ +@RunWith(BrowserRunner.class) +public class HtmlTelInput2Test extends SimpleWebTestCase { + + /** + * @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 type='tel' id='foo'>\n" + + "</form>\n" + + "</body></html>"; + + final HtmlPage page = loadPage(htmlContent); + + HtmlTelInput input = (HtmlTelInput) page.getElementById("foo"); + input = (HtmlTelInput) input.cloneNode(true); + input.type("4711"); + assertEquals("4711", input.getValueAttribute()); + } +} Property changes on: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlTelInput2Test.java ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlUrlInput2Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlUrlInput2Test.java (rev 0) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlUrlInput2Test.java 2018-03-22 19:35:43 UTC (rev 15180) @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2002-2018 Gargoyle Software Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.gargoylesoftware.htmlunit.html; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import com.gargoylesoftware.htmlunit.BrowserRunner; +import com.gargoylesoftware.htmlunit.SimpleWebTestCase; + +/** + * Tests for {@link HtmlUrlInput}. + * + * @author Ronald Brill + */ +@RunWith(BrowserRunner.class) +public class HtmlUrlInput2Test extends SimpleWebTestCase { + + /** + * @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 type='url' id='foo'>\n" + + "</form>\n" + + "</body></html>"; + + final HtmlPage page = loadPage(htmlContent); + + HtmlUrlInput input = (HtmlUrlInput) page.getElementById("foo"); + input = (HtmlUrlInput) input.cloneNode(true); + input.type("4711"); + assertEquals("4711", input.getValueAttribute()); + } +} Property changes on: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlUrlInput2Test.java ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property |