From: <rb...@us...> - 2013-07-16 20:27:41
|
Revision: 8395 http://sourceforge.net/p/htmlunit/code/8395 Author: rbri Date: 2013-07-16 20:27:37 +0000 (Tue, 16 Jul 2013) Log Message: ----------- Support for the label property added to the optgroup element. Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLOptGroupElement.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLOptionElement2Test.java Added Paths: ----------- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLOptGroupElementTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLPreElementTest.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2013-07-16 18:37:03 UTC (rev 8394) +++ trunk/htmlunit/src/changes/changes.xml 2013-07-16 20:27:37 UTC (rev 8395) @@ -8,6 +8,9 @@ <body> <release version="2.13" date="???" description="Bugfixes"> + <action type="fix" dev="rbri"> + Support for the label property added to the optgroup element. + </action> <action type="update" dev="mguillem" issue="1518"> Ensure that onchange event isn't called at focus lost after usage of HtmlInput.setValueAttribute. </action> Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLOptGroupElement.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLOptGroupElement.java 2013-07-16 18:37:03 UTC (rev 8394) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLOptGroupElement.java 2013-07-16 20:27:37 UTC (rev 8395) @@ -16,6 +16,7 @@ import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.CSS_DISPLAY_DEFAULT; +import com.gargoylesoftware.htmlunit.html.DomElement; import com.gargoylesoftware.htmlunit.html.HtmlOptionGroup; import com.gargoylesoftware.htmlunit.javascript.configuration.JsxClass; import com.gargoylesoftware.htmlunit.javascript.configuration.JsxGetter; @@ -50,6 +51,28 @@ } /** + * Returns the value of the "label" property. + * @return the value of the "label" property + */ + @JsxGetter + public String getLabel() { + final String label = getDomNodeOrDie().getAttribute("label"); + if (DomElement.ATTRIBUTE_NOT_DEFINED == label) { + return ""; + } + return label; + } + + /** + * Updates the value of the "label" property. + * @param newLabel the new value + */ + @JsxSetter + public void setLabel(final String newLabel) { + getDomNodeOrDie().setAttribute("label", newLabel); + } + + /** * <span style="color:red">INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.</span><br/> * {@inheritDoc} */ Added: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLOptGroupElementTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLOptGroupElementTest.java (rev 0) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLOptGroupElementTest.java 2013-07-16 20:27:37 UTC (rev 8395) @@ -0,0 +1,110 @@ +/* + * Copyright (c) 2002-2013 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.javascript.host.html; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import com.gargoylesoftware.htmlunit.BrowserRunner; +import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; +import com.gargoylesoftware.htmlunit.WebDriverTestCase; + +/** + * Unit tests for {@link HTMLOptGroupElement}. + * + * @version $Revision: 7931 $ + * @author Ronald Brill + */ +@RunWith(BrowserRunner.class) +public class HTMLOptGroupElementTest extends WebDriverTestCase { + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts({ "false", "true", "true", "false", "true" }) + public void disabledAttribute() throws Exception { + final String html = + "<html>\n" + + " <head>\n" + + " <script>\n" + + " function test() {\n" + + " var test1 = document.getElementById('test1');\n" + + " alert(test1.disabled);\n" + + " test1.disabled = true;\n" + + " alert(test1.disabled);\n" + + " test1.disabled = true;\n" + + " alert(test1.disabled);\n" + + " test1.disabled = false;\n" + + " alert(test1.disabled);\n" + + + " var test2 = document.getElementById('test2');\n" + + " alert(test2.disabled);\n" + + " }\n" + + " </script>\n" + + " </head>\n" + + " <body onload='test()'>\n" + + " <form name='form1'>\n" + + " <select>\n" + + " <optgroup id='test1'>\n" + + " <option value='group1'>Group1</option>\n" + + " </optgroup>\n" + + " <optgroup id='test2' disabled>\n" + + " <option value='group2'>Group2</option>\n" + + " </optgroup>\n" + + " </select>\n" + + " </form>\n" + + "</body></html>"; + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts({ "", "newLabel", "", "label" }) + public void labelAttribute() throws Exception { + final String html = + "<html>\n" + + " <head>\n" + + " <script>\n" + + " function test() {\n" + + " var test1 = document.getElementById('test1');\n" + + " alert(test1.label);\n" + + " test1.label = 'newLabel';\n" + + " alert(test1.label);\n" + + " test1.label = '';\n" + + " alert(test1.label);\n" + + + " var test2 = document.getElementById('test2');\n" + + " alert(test2.label);\n" + + " }\n" + + " </script>\n" + + " </head>\n" + + " <body onload='test()'>\n" + + " <form name='form1'>\n" + + " <select>\n" + + " <optgroup id='test1'>\n" + + " <option value='group1'>Group1</option>\n" + + " </optgroup>\n" + + " <optgroup id='test2' label='label'>\n" + + " <option value='group2'>Group2</option>\n" + + " </optgroup>\n" + + " </select>\n" + + " </form>\n" + + "</body></html>"; + loadPageWithAlerts2(html); + } +} Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLOptionElement2Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLOptionElement2Test.java 2013-07-16 18:37:03 UTC (rev 8394) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLOptionElement2Test.java 2013-07-16 20:27:37 UTC (rev 8395) @@ -363,4 +363,40 @@ loadPageWithAlerts2(html); } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts({ "false", "true", "true", "false", "true" }) + public void disabledAttribute() throws Exception { + final String html = + "<html>\n" + + " <head>\n" + + " <script>\n" + + " function test() {\n" + + " var test1 = document.getElementById('test1');\n" + + " alert(test1.disabled);\n" + + " test1.disabled = true;\n" + + " alert(test1.disabled);\n" + + " test1.disabled = true;\n" + + " alert(test1.disabled);\n" + + " test1.disabled = false;\n" + + " alert(test1.disabled);\n" + + + " var test2 = document.getElementById('test2');\n" + + " alert(test2.disabled);\n" + + " }\n" + + " </script>\n" + + " </head>\n" + + " <body onload='test()'>\n" + + " <form name='form1'>\n" + + " <select>\n" + + " <option id='test1' value='option1'>Option1</option>\n" + + " <option id='test2' value='option2' disabled>Option2</option>\n" + + " </select>\n" + + " </form>\n" + + "</body></html>"; + loadPageWithAlerts2(html); + } } Added: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLPreElementTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLPreElementTest.java (rev 0) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLPreElementTest.java 2013-07-16 20:27:37 UTC (rev 8395) @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2002-2013 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.javascript.host.html; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import com.gargoylesoftware.htmlunit.BrowserRunner; +import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; +import com.gargoylesoftware.htmlunit.BrowserRunner.NotYetImplemented; +import com.gargoylesoftware.htmlunit.WebDriverTestCase; + +/** + * Unit tests for {@link HTMLPreElement}. + * + * @version $Revision: 7931 $ + * @author Ronald Brill + */ +@RunWith(BrowserRunner.class) +public class HTMLPreElementTest extends WebDriverTestCase { + + /** + * @throws Exception if an error occurs + */ + @Test + @Alerts(FF = { "0", "number", "100", "77", "number", "123" }, + IE = { "", "string", "100", "77", "string", "123" }) + @NotYetImplemented + public void testWidth() throws Exception { + final String html = + "<html>\n" + + " <head>\n" + + " <script>\n" + + " function test() {\n" + + " var testPre = document.getElementById('testPre');\n" + + " alert(testPre.width);\n" + + " alert(typeof testPre.width);\n" + + " testPre.width = 100;\n" + + " alert(testPre.width);\n" + + + " var testPre = document.getElementById('testPreWidth');\n" + + " alert(testPreWidth.width);\n" + + " alert(typeof testPreWidth.width);\n" + + " testPreWidth.width = 123;\n" + + " alert(testPreWidth.width);\n" + + " }\n" + + " </script>\n" + + " </head>\n" + + " <body onload='test()'>\n" + + " <pre id='testPre'>pre content</pre>\n" + + " <pre id='testPreWidth' width='77'>pre content</pre>\n" + + " </body>\n" + + "</html>"; + loadPageWithAlerts2(html); + } +} |