From: <rb...@us...> - 2013-04-18 18:03:44
|
Revision: 8228 http://sourceforge.net/p/htmlunit/code/8228 Author: rbri Date: 2013-04-18 18:03:39 +0000 (Thu, 18 Apr 2013) Log Message: ----------- Fix the mousedown/mouseup events triggered when clicking on an option. Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlOption.java Added Paths: ----------- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlOption2Test.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2013-04-17 17:38:32 UTC (rev 8227) +++ trunk/htmlunit/src/changes/changes.xml 2013-04-18 18:03:39 UTC (rev 8228) @@ -9,6 +9,9 @@ <body> <release version="2.13" date="???" description="Bugfixes"> <action type="fix" dev="rbri"> + JavaScript: Fix the mousedown/mouseup events triggered when clicking on an option. + </action> + <action type="fix" dev="rbri"> JavaScript: Starting with IE8 the radio button checked state is reseted to false when adding to page. </action> Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2013-04-17 17:38:32 UTC (rev 8227) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2013-04-18 18:03:39 UTC (rev 8228) @@ -183,6 +183,26 @@ @BrowserFeature({ @WebBrowser(FF), @WebBrowser(CHROME) }) EVENT_ONLOAD_IFRAME_CREATED_BY_JAVASCRIPT, + /** Does not trigger "onmousedown" event handler for the select options. */ + @BrowserFeature({ @WebBrowser(value = FF, minVersion = 10), @WebBrowser(IE) }) + EVENT_ONMOUSEDOWN_FOR_SELECT_OPTION_TRIGGERS_ADDITIONAL_DOWN_FOR_SELECT, + + /** Does not trigger "onmousedown" event handler for the select options. */ + @BrowserFeature({ @WebBrowser(value = FF, minVersion = 10) }) + EVENT_ONMOUSEDOWN_FOR_SELECT_OPTION_TRIGGERS_ADDITIONAL_UP_FOR_SELECT, + + /** Does not trigger "onmousedown" event handler for the select options. */ + @BrowserFeature({ @WebBrowser(IE), @WebBrowser(CHROME), @WebBrowser(value = FF, maxVersion = 3.6f) }) + EVENT_ONMOUSEDOWN_NOT_FOR_SELECT_OPTION, + + /** Does not trigger "onmousedown" event handler for the select options. */ + @BrowserFeature({ @WebBrowser(value = FF, maxVersion = 3.6f), @WebBrowser(IE), @WebBrowser(CHROME) }) + EVENT_ONMOUSEUP_FOR_SELECT_OPTION_TRIGGERS_ADDITIONAL_UP_FOR_SELECT, + + /** Does not trigger "onmouseup" event handler for the select options. */ + @BrowserFeature({ @WebBrowser(IE), @WebBrowser(CHROME) }) + EVENT_ONMOUSEUP_NOT_FOR_SELECT_OPTION, + /** Triggers "onreadystatechange" event. */ @BrowserFeature(@WebBrowser(IE)) EVENT_ONREADY_STATE_CHANGE, Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlOption.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlOption.java 2013-04-17 17:38:32 UTC (rev 8227) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlOption.java 2013-04-18 18:03:39 UTC (rev 8228) @@ -16,6 +16,14 @@ import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.CONTROL_UPDATE_DONE_BEFORE_CLICK_EVENT_FIRED; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.EVENT_ONCLICK_FOR_SELECT_OPTION_ALSO; +import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.EVENT_ONMOUSEDOWN_NOT_FOR_SELECT_OPTION; +import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures. + EVENT_ONMOUSEDOWN_FOR_SELECT_OPTION_TRIGGERS_ADDITIONAL_DOWN_FOR_SELECT; +import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures. + EVENT_ONMOUSEDOWN_FOR_SELECT_OPTION_TRIGGERS_ADDITIONAL_UP_FOR_SELECT; +import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.EVENT_ONMOUSEUP_NOT_FOR_SELECT_OPTION; +import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures. + EVENT_ONMOUSEUP_FOR_SELECT_OPTION_TRIGGERS_ADDITIONAL_UP_FOR_SELECT; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.HTMLOPTION_EMPTY_TEXT_IS_NO_CHILDREN; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.HTMLOPTION_PREVENT_DISABLED; @@ -239,6 +247,42 @@ * {@inheritDoc} */ @Override + public Page mouseDown(final boolean shiftKey, final boolean ctrlKey, final boolean altKey, final int button) { + Page page = null; + if (hasFeature(EVENT_ONMOUSEDOWN_FOR_SELECT_OPTION_TRIGGERS_ADDITIONAL_DOWN_FOR_SELECT)) { + page = getEnclosingSelect().mouseDown(shiftKey, ctrlKey, altKey, button); + } + if (hasFeature(EVENT_ONMOUSEDOWN_FOR_SELECT_OPTION_TRIGGERS_ADDITIONAL_UP_FOR_SELECT)) { + page = getEnclosingSelect().mouseUp(shiftKey, ctrlKey, altKey, button); + } + + if (hasFeature(EVENT_ONMOUSEDOWN_NOT_FOR_SELECT_OPTION)) { + return page; + } + return super.mouseDown(shiftKey, ctrlKey, altKey, button); + } + + /** + * Selects the option if it's not already selected. + * {@inheritDoc} + */ + @Override + public Page mouseUp(final boolean shiftKey, final boolean ctrlKey, final boolean altKey, final int button) { + Page page = null; + if (hasFeature(EVENT_ONMOUSEUP_FOR_SELECT_OPTION_TRIGGERS_ADDITIONAL_UP_FOR_SELECT)) { + page = getEnclosingSelect().mouseUp(shiftKey, ctrlKey, altKey, button); + } + if (hasFeature(EVENT_ONMOUSEUP_NOT_FOR_SELECT_OPTION)) { + return page; + } + return super.mouseUp(shiftKey, ctrlKey, altKey, button); + } + + /** + * Selects the option if it's not already selected. + * {@inheritDoc} + */ + @Override protected boolean doClickStateUpdate() throws IOException { boolean changed = false; if (!isSelected()) { Added: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlOption2Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlOption2Test.java (rev 0) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlOption2Test.java 2013-04-18 18:03:39 UTC (rev 8228) @@ -0,0 +1,73 @@ +/* + * 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.html; + +import java.util.Arrays; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; + +import com.gargoylesoftware.htmlunit.BrowserRunner; +import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; +import com.gargoylesoftware.htmlunit.WebDriverTestCase; + +/** + * Tests for {@link HtmlOption}. + * + * @version $Revision$ + * @author Ronald Brill + */ +@RunWith(BrowserRunner.class) +public class HtmlOption2Test extends WebDriverTestCase { + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = "sDown,mousedown,sUp,mouseup,oDown,mousedown,sDown,mousedown,oUp,mouseup,sUp,mouseup,", + FF3_6 = "sUp,mouseup,oUp,mouseup,sUp,mouseup,", + IE = "sDown,mousedown,sUp,mouseup,", + CHROME = "sUp,mouseup,") + public void onMouse() throws Exception { + final String html = "<html><head><title>foo</title>\n" + + "<script>\n" + + " function debug(string) {\n" + + " document.getElementById('myTextarea').value += string + ',';\n" + + " }\n" + + "</script>\n" + + "</head><body>\n" + + " <form>\n" + + " <select name='select1' size='4'" + + " onMouseDown='debug(\"sDown\");debug(event.type);'" + + " onMouseUp='debug(\"sUp\");debug(event.type);'>\n" + + " <option id='opt1' value='option1'>Option1</option>\n" + + " <option id='opt2' value='option2' selected='selected'>Option2</option>\n" + + " <option id='opt3' value='option3'" + + " onMouseDown='debug(\"oDown\");debug(event.type);'" + + " onMouseUp='debug(\"oUp\");debug(event.type);'>Option3</option>\n" + + " </select>\n" + + " </form>\n" + + " <textarea id='myTextarea'></textarea>\n" + + "</body></html>"; + + final WebDriver driver = loadPage2(html); + driver.findElement(By.id("opt3")).click(); + + assertEquals(Arrays.asList(getExpectedAlerts()).toString(), + '[' + driver.findElement(By.id("myTextarea")).getAttribute("value") + ']'); + } +} Property changes on: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlOption2Test.java ___________________________________________________________________ Added: svn:keywords ## -0,0 +1 ## +Author Date Id Revision \ No newline at end of property Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property |