From: <rb...@us...> - 2014-03-30 13:52:19
|
Revision: 9217 http://sourceforge.net/p/htmlunit/code/9217 Author: rbri Date: 2014-03-30 13:52:14 +0000 (Sun, 30 Mar 2014) Log Message: ----------- Cookies: Different path interpretation done by IE11 fixed. Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/CookieManager.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebClient.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLDocument.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/CookieManager2Test.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/CookieManagerTest.java Added Paths: ----------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HtmlUnitBrowserCompatCookieSpec.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2014-03-30 12:18:39 UTC (rev 9216) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2014-03-30 13:52:14 UTC (rev 9217) @@ -649,6 +649,12 @@ @BrowserFeature({ @WebBrowser(FF), @WebBrowser(CHROME) }) HTTP_HEADER_HOST_FIRST, + /** Indicates that the pas is extracted from the location (IE11). + * Sample: from the location /foo/boo only /foo is used. + */ + @BrowserFeature(@WebBrowser(value = IE, minVersion = 11)) + HTTP_COOKIE_EXTRACT_PATH_FROM_LOCATION, + /** Indicates that the browser should ignore contents of inner head elements. */ @BrowserFeature(@WebBrowser(value = IE, maxVersion = 9)) IGNORE_CONTENTS_OF_INNER_HEAD, Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/CookieManager.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/CookieManager.java 2014-03-30 12:18:39 UTC (rev 9216) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/CookieManager.java 2014-03-30 13:52:14 UTC (rev 9217) @@ -19,13 +19,11 @@ import java.util.ArrayList; import java.util.Collections; import java.util.Date; -import java.util.HashSet; import java.util.Iterator; import java.util.LinkedHashSet; import java.util.List; import java.util.Set; -import org.apache.commons.collections.set.ListOrderedSet; import org.apache.commons.lang3.StringUtils; import org.apache.http.cookie.CookieOrigin; import org.apache.http.cookie.CookieSpec; @@ -51,8 +49,7 @@ private boolean cookiesEnabled_; /** The cookies added to this cookie manager. */ - @SuppressWarnings("unchecked") - private final Set<Cookie> cookies_ = new ListOrderedSet(); + private final Set<Cookie> cookies_ = new LinkedHashSet<Cookie>(); private final transient CookieSpec cookieSpec_ = new BrowserCompatSpecFactory().create(null); @@ -89,7 +86,8 @@ return Collections.<Cookie>emptySet(); } - final Set<Cookie> copy = new HashSet<Cookie>(cookies_); + final Set<Cookie> copy = new LinkedHashSet<Cookie>(); + copy.addAll(cookies_); return Collections.unmodifiableSet(copy); } @@ -98,7 +96,10 @@ * If disabled, this returns an empty set. * @param url the URL on which to filter the returned cookies * @return the currently configured cookies applicable to the specified URL, in an unmodifiable set + * + * @deprecated as of 2.13 use {@link WebClient#getCookies(URL)} */ + @Deprecated public synchronized Set<Cookie> getCookies(final URL url) { if (!isCookiesEnabled()) { return Collections.<Cookie>emptySet(); @@ -236,5 +237,4 @@ cookies_.clear(); } - } Added: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HtmlUnitBrowserCompatCookieSpec.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HtmlUnitBrowserCompatCookieSpec.java (rev 0) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HtmlUnitBrowserCompatCookieSpec.java 2014-03-30 13:52:14 UTC (rev 9217) @@ -0,0 +1,197 @@ +/* + * Copyright (c) 2002-2014 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; + +import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.HTTP_COOKIE_EXTENDED_DATE_PATTERNS; +import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.HTTP_COOKIE_START_DATE_1970; +import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.HTTP_COOKIE_EXTRACT_PATH_FROM_LOCATION; + +import java.util.Calendar; +import java.util.Collections; +import java.util.Comparator; +import java.util.Date; +import java.util.List; + +import org.apache.http.Header; +import org.apache.http.client.utils.DateUtils; +import org.apache.http.cookie.ClientCookie; +import org.apache.http.cookie.Cookie; +import org.apache.http.cookie.CookieAttributeHandler; +import org.apache.http.cookie.CookieOrigin; +import org.apache.http.cookie.CookiePathComparator; +import org.apache.http.cookie.MalformedCookieException; +import org.apache.http.cookie.SetCookie; +import org.apache.http.impl.cookie.BasicClientCookie; +import org.apache.http.impl.cookie.BasicPathHandler; +import org.apache.http.impl.cookie.BrowserCompatSpec; + +/** + * Customized BrowserCompatSpec for HtmlUnit. + * + * Workaround for <a href="https://issues.apache.org/jira/browse/HTTPCLIENT-1006">HttpClient bug 1006</a>: + * quotes are wrongly removed in cookie's values. + * + * @version $Revision$ + * @author <a href="mailto:mb...@Ga...">Mike Bowler</a> + * @author Noboru Sinohara + * @author David D. Kilzer + * @author Marc Guillemot + * @author Brad Clarke + * @author Ahmed Ashour + * @author Nicolas Belisle + * @author Ronald Brill + * @author John J Murdoch + */ +public class HtmlUnitBrowserCompatCookieSpec extends BrowserCompatSpec { + /** + * Comparator for sending cookies in right order. + * See specification: + * - RFC2109 (#4.3.4) http://www.ietf.org/rfc/rfc2109.txt + * - RFC2965 (#3.3.4) http://www.ietf.org/rfc/rfc2965.txt http://www.ietf.org/rfc/rfc2109.txt + */ + private static final Comparator<Cookie> COOKIE_COMPARATOR = new CookiePathComparator(); + + private static final Date DATE_1_1_1970; + + static { + final Calendar calendar = Calendar.getInstance(); + calendar.setTimeZone(DateUtils.GMT); + calendar.set(1970, Calendar.JANUARY, 1, 0, 0, 0); + calendar.set(Calendar.MILLISECOND, 0); + DATE_1_1_1970 = calendar.getTime(); + } + + // simplified patterns from BrowserCompatSpec, with yy patterns before similar yyyy patterns + private static final String[] DEFAULT_DATE_PATTERNS = new String[] { + "EEE dd MMM yy HH mm ss zzz", + "EEE dd MMM yyyy HH mm ss zzz", + "EEE MMM d HH mm ss yyyy", + "EEE dd MMM yy HH mm ss z ", + "EEE dd MMM yyyy HH mm ss z ", + "EEE dd MM yy HH mm ss z ", + "EEE dd MM yyyy HH mm ss z ", + }; + private static final String[] EXTENDED_DATE_PATTERNS = new String[] { + "EEE dd MMM yy HH mm ss zzz", + "EEE dd MMM yyyy HH mm ss zzz", + "EEE MMM d HH mm ss yyyy", + "EEE dd MMM yy HH mm ss z ", + "EEE dd MMM yyyy HH mm ss z ", + "EEE dd MM yy HH mm ss z ", + "EEE dd MM yyyy HH mm ss z ", + "d/M/yyyy", + }; + + /** + * Constructor. + * + * @param browserVersion the {@link BrowserVersion} to simulate + */ + public HtmlUnitBrowserCompatCookieSpec(final BrowserVersion browserVersion) { + super(); + final BasicPathHandler pathHandler = new BasicPathHandler() { + @Override + public void validate(final Cookie cookie, final CookieOrigin origin) throws MalformedCookieException { + // nothing, browsers seem not to perform any validation + } + + @Override + public boolean match(final Cookie cookie, final CookieOrigin origin) { + String targetpath = origin.getPath(); + if (browserVersion.hasFeature(HTTP_COOKIE_EXTRACT_PATH_FROM_LOCATION) && targetpath.length() > 0) { + final int lastSlashPos = targetpath.lastIndexOf('/'); + if (lastSlashPos > 1 && lastSlashPos < targetpath.length()) { + targetpath = targetpath.substring(0, lastSlashPos); + } + } + + final CookieOrigin newOrigin = new CookieOrigin(origin.getHost(), + origin.getPort(), targetpath, origin.isSecure()); + + return super.match(cookie, newOrigin); + } + }; + registerAttribHandler(ClientCookie.PATH_ATTR, pathHandler); + + final CookieAttributeHandler originalExpiresHandler = getAttribHandler(ClientCookie.EXPIRES_ATTR); + final CookieAttributeHandler wrapperExpiresHandler = new CookieAttributeHandler() { + + public void validate(final Cookie cookie, final CookieOrigin origin) throws MalformedCookieException { + originalExpiresHandler.validate(cookie, origin); + } + + public void parse(final SetCookie cookie, String value) throws MalformedCookieException { + if (value.startsWith("\"") && value.endsWith("\"")) { + value = value.substring(1, value.length() - 1); + } + value = value.replaceAll("[ ,:-]+", " "); + + Date startDate = null; + if (browserVersion.hasFeature(HTTP_COOKIE_START_DATE_1970)) { + startDate = DATE_1_1_1970; + } + + String[] datePatterns = DEFAULT_DATE_PATTERNS; + if (browserVersion.hasFeature(HTTP_COOKIE_EXTENDED_DATE_PATTERNS)) { + datePatterns = EXTENDED_DATE_PATTERNS; + } + + cookie.setExpiryDate(DateUtils.parseDate(value, datePatterns, startDate)); + } + + public boolean match(final Cookie cookie, final CookieOrigin origin) { + return originalExpiresHandler.match(cookie, origin); + } + }; + registerAttribHandler(ClientCookie.EXPIRES_ATTR, wrapperExpiresHandler); + + final CookieAttributeHandler httpOnlyHandler = new CookieAttributeHandler() { + public void validate(final Cookie cookie, final CookieOrigin origin) throws MalformedCookieException { + // nothing + } + + public void parse(final SetCookie cookie, final String value) throws MalformedCookieException { + ((BasicClientCookie) cookie).setAttribute("httponly", "true"); + } + + public boolean match(final Cookie cookie, final CookieOrigin origin) { + return true; + } + }; + registerAttribHandler("httponly", httpOnlyHandler); + } + + /** + * {@inheritDoc} + */ + @Override + public List<Cookie> parse(final Header header, final CookieOrigin origin) throws MalformedCookieException { + final List<Cookie> cookies = super.parse(header, origin); + for (final Cookie c : cookies) { + // re-add quotes around value if parsing as incorrectly trimmed them + if (header.getValue().contains(c.getName() + "=\"" + c.getValue())) { + ((BasicClientCookie) c).setValue('"' + c.getValue() + '"'); + } + } + return cookies; + } + + @Override + public List<Header> formatCookies(final List<Cookie> cookies) { + Collections.sort(cookies, COOKIE_COMPARATOR); + + return super.formatCookies(cookies); + } +} Property changes on: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HtmlUnitBrowserCompatCookieSpec.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 Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java 2014-03-30 12:18:39 UTC (rev 9216) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java 2014-03-30 13:52:14 UTC (rev 9217) @@ -15,8 +15,6 @@ package com.gargoylesoftware.htmlunit; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.HEADER_CONTENT_DISPOSITION_ABSOLUTE_PATH; -import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.HTTP_COOKIE_EXTENDED_DATE_PATTERNS; -import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.HTTP_COOKIE_START_DATE_1970; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.HTTP_HEADER_HOST_FIRST; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.URL_AUTH_CREDENTIALS; @@ -34,9 +32,7 @@ import java.nio.charset.Charset; import java.util.ArrayList; import java.util.Arrays; -import java.util.Calendar; import java.util.Collections; -import java.util.Comparator; import java.util.Date; import java.util.List; import java.util.Map; @@ -70,7 +66,6 @@ import org.apache.http.client.methods.HttpTrace; import org.apache.http.client.methods.HttpUriRequest; import org.apache.http.client.protocol.HttpClientContext; -import org.apache.http.client.utils.DateUtils; import org.apache.http.client.utils.URIUtils; import org.apache.http.client.utils.URLEncodedUtils; import org.apache.http.config.ConnectionConfig; @@ -81,15 +76,9 @@ import org.apache.http.conn.ssl.SSLConnectionSocketFactory; import org.apache.http.conn.ssl.SSLContexts; import org.apache.http.conn.ssl.X509HostnameVerifier; -import org.apache.http.cookie.ClientCookie; import org.apache.http.cookie.Cookie; -import org.apache.http.cookie.CookieAttributeHandler; -import org.apache.http.cookie.CookieOrigin; -import org.apache.http.cookie.CookiePathComparator; import org.apache.http.cookie.CookieSpec; import org.apache.http.cookie.CookieSpecProvider; -import org.apache.http.cookie.MalformedCookieException; -import org.apache.http.cookie.SetCookie; import org.apache.http.entity.ContentType; import org.apache.http.entity.StringEntity; import org.apache.http.entity.mime.MultipartEntityBuilder; @@ -97,10 +86,7 @@ import org.apache.http.impl.client.DefaultRedirectStrategy; import org.apache.http.impl.client.HttpClientBuilder; import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; -import org.apache.http.impl.cookie.BasicClientCookie; -import org.apache.http.impl.cookie.BasicPathHandler; import org.apache.http.impl.cookie.BestMatchSpecFactory; -import org.apache.http.impl.cookie.BrowserCompatSpec; import org.apache.http.impl.cookie.BrowserCompatSpecFactory; import org.apache.http.impl.cookie.IgnoreSpecFactory; import org.apache.http.impl.cookie.NetscapeDraftSpecFactory; @@ -150,8 +136,7 @@ htmlUnitCookieSpecProvider_ = new CookieSpecProvider() { @Override public CookieSpec create(final HttpContext context) { - return new HtmlUnitBrowserCompatCookieSpec(webClient.getBrowserVersion(), - webClient_.getIncorrectnessListener()); + return new HtmlUnitBrowserCompatCookieSpec(webClient.getBrowserVersion()); } }; httpContext_ = new HttpClientContext(); @@ -237,19 +222,6 @@ return new HttpHost(url.getHost(), url.getPort(), url.getProtocol()); } -// private static void setProxy(final HttpUriRequest httpUriRequest, final WebRequest webRequest) { -// if (webRequest.getProxyHost() != null) { -// final HttpHost proxy = new HttpHost(webRequest.getProxyHost(), webRequest.getProxyPort()); -// final HttpParams httpRequestParams = httpUriRequest.getParams(); -// if (webRequest.isSocksProxy()) { -// SocksSocketFactory.setSocksProxy(httpRequestParams, proxy); -// } -// else { -// httpRequestParams.setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy); -// } -// } -// } - private void setProxy(final HttpRequestBase httpRequest, final WebRequest webRequest) { final RequestConfig.Builder requestBuilder = createRequestConfig(); configureTimeout(requestBuilder, webClient_.getOptions().getTimeout()); @@ -367,7 +339,6 @@ } writeRequestHeadersToHttpMethod(httpMethod, webRequest.getAdditionalHeaders()); -// getHttpClient().getParams().setParameter(ClientPNames.HANDLE_REDIRECTS, true); final HttpClientBuilder httpClient = getHttpClientBuilder(); @@ -761,132 +732,6 @@ } /** - * Workaround for <a href="https://issues.apache.org/jira/browse/HTTPCLIENT-1006">HttpClient bug 1006</a>: - * quotes are wrongly removed in cookie's values. - */ -class HtmlUnitBrowserCompatCookieSpec extends BrowserCompatSpec { - /** - * Comparator for sending cookies in right order. - * See specification: - * - RFC2109 (#4.3.4) http://www.ietf.org/rfc/rfc2109.txt - * - RFC2965 (#3.3.4) http://www.ietf.org/rfc/rfc2965.txt http://www.ietf.org/rfc/rfc2109.txt - */ - private static final Comparator<Cookie> COOKIE_COMPARATOR = new CookiePathComparator(); - - private static final Date DATE_1_1_1970; - - static { - final Calendar calendar = Calendar.getInstance(); - calendar.setTimeZone(DateUtils.GMT); - calendar.set(1970, Calendar.JANUARY, 1, 0, 0, 0); - calendar.set(Calendar.MILLISECOND, 0); - DATE_1_1_1970 = calendar.getTime(); - } - - // simplified patterns from BrowserCompatSpec, with yy patterns before similar yyyy patterns - private static final String[] DEFAULT_DATE_PATTERNS = new String[] { - "EEE dd MMM yy HH mm ss zzz", - "EEE dd MMM yyyy HH mm ss zzz", - "EEE MMM d HH mm ss yyyy", - "EEE dd MMM yy HH mm ss z ", - "EEE dd MMM yyyy HH mm ss z ", - "EEE dd MM yy HH mm ss z ", - "EEE dd MM yyyy HH mm ss z ", - }; - private static final String[] EXTENDED_DATE_PATTERNS = new String[] { - "EEE dd MMM yy HH mm ss zzz", - "EEE dd MMM yyyy HH mm ss zzz", - "EEE MMM d HH mm ss yyyy", - "EEE dd MMM yy HH mm ss z ", - "EEE dd MMM yyyy HH mm ss z ", - "EEE dd MM yy HH mm ss z ", - "EEE dd MM yyyy HH mm ss z ", - "d/M/yyyy", - }; - - HtmlUnitBrowserCompatCookieSpec(final BrowserVersion browserVersion, - final IncorrectnessListener incorrectnessListener) { - super(); - final BasicPathHandler pathHandler = new BasicPathHandler() { - @Override - public void validate(final Cookie cookie, final CookieOrigin origin) throws MalformedCookieException { - // nothing, browsers seem not to perform any validation - } - }; - registerAttribHandler(ClientCookie.PATH_ATTR, pathHandler); - - final CookieAttributeHandler originalExpiresHandler = getAttribHandler(ClientCookie.EXPIRES_ATTR); - final CookieAttributeHandler wrapperExpiresHandler = new CookieAttributeHandler() { - - public void validate(final Cookie cookie, final CookieOrigin origin) throws MalformedCookieException { - originalExpiresHandler.validate(cookie, origin); - } - - public void parse(final SetCookie cookie, String value) throws MalformedCookieException { - if (value.startsWith("\"") && value.endsWith("\"")) { - value = value.substring(1, value.length() - 1); - } - value = value.replaceAll("[ ,:-]+", " "); - - Date startDate = null; - if (browserVersion.hasFeature(HTTP_COOKIE_START_DATE_1970)) { - startDate = DATE_1_1_1970; - } - - String[] datePatterns = DEFAULT_DATE_PATTERNS; - if (browserVersion.hasFeature(HTTP_COOKIE_EXTENDED_DATE_PATTERNS)) { - datePatterns = EXTENDED_DATE_PATTERNS; - } - - cookie.setExpiryDate(DateUtils.parseDate(value, datePatterns, startDate)); - } - - public boolean match(final Cookie cookie, final CookieOrigin origin) { - return originalExpiresHandler.match(cookie, origin); - } - }; - registerAttribHandler(ClientCookie.EXPIRES_ATTR, wrapperExpiresHandler); - - final CookieAttributeHandler httpOnlyHandler = new CookieAttributeHandler() { - public void validate(final Cookie cookie, final CookieOrigin origin) throws MalformedCookieException { - // nothing - } - - public void parse(final SetCookie cookie, final String value) throws MalformedCookieException { - ((BasicClientCookie) cookie).setAttribute("httponly", "true"); - } - - public boolean match(final Cookie cookie, final CookieOrigin origin) { - return true; - } - }; - registerAttribHandler("httponly", httpOnlyHandler); - } - - /** - * {@inheritDoc} - */ - @Override - public List<Cookie> parse(final Header header, final CookieOrigin origin) throws MalformedCookieException { - final List<Cookie> cookies = super.parse(header, origin); - for (final Cookie c : cookies) { - // re-add quotes around value if parsing as incorrectly trimmed them - if (header.getValue().contains(c.getName() + "=\"" + c.getValue())) { - ((BasicClientCookie) c).setValue('"' + c.getValue() + '"'); - } - } - return cookies; - } - - @Override - public List<Header> formatCookies(final List<Cookie> cookies) { - Collections.sort(cookies, COOKIE_COMPARATOR); - - return super.formatCookies(cookies); - } -} - -/** * Implementation of {@link CookieStore} like {@link org.apache.http.impl.client.BasicCookieStore} * BUT storing cookies in the order of addition. * @author Marc Guillemot Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebClient.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebClient.java 2014-03-30 12:18:39 UTC (rev 9216) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebClient.java 2014-03-30 13:52:14 UTC (rev 9217) @@ -34,9 +34,11 @@ import java.util.ArrayList; import java.util.Collections; import java.util.ConcurrentModificationException; +import java.util.Date; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; +import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Set; @@ -50,6 +52,7 @@ import org.apache.http.HttpStatus; import org.apache.http.NoHttpResponseException; import org.apache.http.client.CredentialsProvider; +import org.apache.http.cookie.CookieOrigin; import org.w3c.css.sac.ErrorHandler; import com.gargoylesoftware.htmlunit.activex.javascript.msxml.MSXMLActiveXObjectFactory; @@ -75,6 +78,7 @@ import com.gargoylesoftware.htmlunit.javascript.host.html.HTMLDocument; import com.gargoylesoftware.htmlunit.javascript.host.html.HTMLElement; import com.gargoylesoftware.htmlunit.protocol.data.DataUrlDecoder; +import com.gargoylesoftware.htmlunit.util.Cookie; import com.gargoylesoftware.htmlunit.util.NameValuePair; import com.gargoylesoftware.htmlunit.util.UrlUtils; @@ -2103,4 +2107,47 @@ public StorageHolder getStorageHolder() { return storageHolder_; } + + /** + * Returns the currently configured cookies applicable to the specified URL, in an unmodifiable set. + * If disabled, this returns an empty set. + * @param url the URL on which to filter the returned cookies + * @return the currently configured cookies applicable to the specified URL, in an unmodifiable set + */ + public synchronized Set<Cookie> getCookies(final URL url) { + final CookieManager cookieManager = getCookieManager(); + + if (!cookieManager.isCookiesEnabled()) { + return Collections.<Cookie>emptySet(); + } + + final String host = url.getHost(); + // URLs like "about:blank" don't have cookies and we need to catch these + // cases here before HttpClient complains + if (host.isEmpty()) { + return Collections.emptySet(); + } + + final String path = url.getPath(); + final String protocol = url.getProtocol(); + final boolean secure = "https".equals(protocol); + + final int port = cookieManager.getPort(url); + + // discard expired cookies + cookieManager.clearExpired(new Date()); + + final org.apache.http.cookie.Cookie[] all = Cookie.toHttpClient(cookieManager.getCookies()); + final CookieOrigin cookieOrigin = new CookieOrigin(host, port, path, secure); + final List<org.apache.http.cookie.Cookie> matches = new ArrayList<org.apache.http.cookie.Cookie>(); + for (final org.apache.http.cookie.Cookie cookie : all) { + if (new HtmlUnitBrowserCompatCookieSpec(getBrowserVersion()).match(cookie, cookieOrigin)) { + matches.add(cookie); + } + } + + final Set<Cookie> cookies = new LinkedHashSet<Cookie>(); + cookies.addAll(Cookie.fromHttpClient(matches)); + return Collections.unmodifiableSet(cookies); + } } Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLDocument.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLDocument.java 2014-03-30 12:18:39 UTC (rev 9216) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLDocument.java 2014-03-30 13:52:14 UTC (rev 9217) @@ -816,7 +816,7 @@ url = replaceForCookieIfNecessary(url); final StringBuilder buffer = new StringBuilder(); - final Set<Cookie> cookies = page.getWebClient().getCookieManager().getCookies(url); + final Set<Cookie> cookies = page.getWebClient().getCookies(url); for (final Cookie cookie : cookies) { if (cookie.isHttpOnly()) { continue; Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/CookieManager2Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/CookieManager2Test.java 2014-03-30 12:18:39 UTC (rev 9216) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/CookieManager2Test.java 2014-03-30 13:52:14 UTC (rev 9217) @@ -119,7 +119,7 @@ final WebClient webClient = getWebClient(); final HtmlPage htmlPage = webClient.getPage("about:blank"); - final Set<Cookie> cookies = webClient.getCookieManager().getCookies(htmlPage.getUrl()); + final Set<Cookie> cookies = webClient.getCookies(htmlPage.getUrl()); assertTrue(cookies.toString(), cookies.isEmpty()); } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/CookieManagerTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/CookieManagerTest.java 2014-03-30 12:18:39 UTC (rev 9216) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/CookieManagerTest.java 2014-03-30 13:52:14 UTC (rev 9217) @@ -501,6 +501,27 @@ } /** + * Response to /a/b sets cookie to /foo/blah. + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = "first=1; second=2") + public void setCookieDifferentPathSlashAtEnd() throws Exception { + final List<NameValuePair> responseHeader1 = new ArrayList<NameValuePair>(); + responseHeader1.add(new NameValuePair("Set-Cookie", "first=1; path=/foo")); + responseHeader1.add(new NameValuePair("Set-Cookie", "second=2; path=/foo/")); + responseHeader1.add(new NameValuePair("Set-Cookie", "third=3; path=/foo/other")); + responseHeader1.add(new NameValuePair("Set-Cookie", "fourth=4; path=/other/path")); + responseHeader1.add(new NameValuePair("Location", "/foo/")); + + getMockWebConnection().setDefaultResponse(HTML_ALERT_COOKIE); + final URL firstUrl = new URL(getDefaultUrl(), "/a/b"); + getMockWebConnection().setResponse(firstUrl, "", 302, "Moved", "text/html", responseHeader1); + + loadPageWithAlerts2(firstUrl); + } + + /** * Test for document.cookie for cookies expiered after the page was loaded. * @throws Exception if the test fails */ @@ -508,7 +529,7 @@ @Alerts(DEFAULT = {"cookies: first=1", "cookies: " }) public void setCookieTimeout() throws Exception { final List<NameValuePair> responseHeader1 = new ArrayList<NameValuePair>(); - final String expires = DateUtils.formatDate(new Date(System.currentTimeMillis() + 10000)); + final String expires = DateUtils.formatDate(new Date(System.currentTimeMillis() + 1000)); responseHeader1.add(new NameValuePair("Set-Cookie", "first=1; expires=" + expires + "; path=/foo")); responseHeader1.add(new NameValuePair("Location", "/foo/content.html")); @@ -523,7 +544,7 @@ + "<body>\n" + "<script>\n" + " alertCookies();\n" - + " window.setTimeout(alertCookies, 11000);\n" + + " window.setTimeout(alertCookies, 1100);\n" + "</script>" + "</body>\n" + "</html>"; |
From: <rb...@us...> - 2014-03-30 17:38:00
|
Revision: 9221 http://sourceforge.net/p/htmlunit/code/9221 Author: rbri Date: 2014-03-30 17:37:55 +0000 (Sun, 30 Mar 2014) Log Message: ----------- add support for the bgColor attribute on thead and tfoot element Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLTableSectionElement.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLTableSectionElementTest.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2014-03-30 15:09:16 UTC (rev 9220) +++ trunk/htmlunit/src/changes/changes.xml 2014-03-30 17:37:55 UTC (rev 9221) @@ -8,6 +8,9 @@ <body> <release version="2.15" date="???" description="Bugfixes"> + <action type="add" dev="rbri"> + JavaScript: add support for the bgColor attribute on thead and tfoot element. + </action> <action type="update" dev="rbri"> CookieManager: deprecate getCookies(URL). </action> Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLTableSectionElement.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLTableSectionElement.java 2014-03-30 15:09:16 UTC (rev 9220) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLTableSectionElement.java 2014-03-30 17:37:55 UTC (rev 9221) @@ -17,6 +17,7 @@ import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_INNER_HTML_READONLY_FOR_SOME_TAGS; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_INNER_TEXT_READONLY_FOR_TABLE; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_TABLE_VALIGN_SUPPORTS_IE_VALUES; +import static com.gargoylesoftware.htmlunit.javascript.configuration.BrowserName.IE; import net.sourceforge.htmlunit.corejs.javascript.Context; import com.gargoylesoftware.htmlunit.html.HtmlTableBody; @@ -26,6 +27,7 @@ import com.gargoylesoftware.htmlunit.javascript.configuration.JsxClasses; import com.gargoylesoftware.htmlunit.javascript.configuration.JsxGetter; import com.gargoylesoftware.htmlunit.javascript.configuration.JsxSetter; +import com.gargoylesoftware.htmlunit.javascript.configuration.WebBrowser; import com.gargoylesoftware.htmlunit.javascript.host.RowContainer; /** @@ -124,6 +126,26 @@ } /** + * Returns the value of the <tt>bgColor</tt> attribute. + * @return the value of the <tt>bgColor</tt> attribute + * @see <a href="http://msdn.microsoft.com/en-us/library/ms533505.aspx">MSDN Documentation</a> + */ + @JsxGetter(@WebBrowser(value = IE)) + public String getBgColor() { + return getDomNodeOrDie().getAttribute("bgColor"); + } + + /** + * Sets the value of the <tt>bgColor</tt> attribute. + * @param bgColor the value of the <tt>bgColor</tt> attribute + * @see <a href="http://msdn.microsoft.com/en-us/library/ms533505.aspx">MSDN Documentation</a> + */ + @JsxSetter(@WebBrowser(value = IE)) + public void setBgColor(final String bgColor) { + setColorAttribute("bgColor", bgColor); + } + + /** * Overwritten to throw an exception in IE8/9. * @param value the new value for replacing this node */ Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLTableSectionElementTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLTableSectionElementTest.java 2014-03-30 15:09:16 UTC (rev 9220) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLTableSectionElementTest.java 2014-03-30 17:37:55 UTC (rev 9221) @@ -456,4 +456,62 @@ + "</script></body></html>"; loadPageWithAlerts2(html); } + + /** + * @throws Exception if an error occurs + */ + @Test + @Alerts(FF = { "undefined", "#0000aa", "x" }, + IE = { "", "#0000aa", "#000000" }, + IE11 = { "", "#0000aa", "#0" }) + public void bgColorFooter() throws Exception { + final String html = + "<html>\n" + + " <head>\n" + + " <script>\n" + + " function test() {\n" + + " var tfoot = document.getElementById('tfoot');\n" + + " alert(tfoot.bgColor);\n" + + " tfoot.bgColor = '#0000aa';\n" + + " alert(tfoot.bgColor);\n" + + " tfoot.bgColor = 'x';\n" + + " alert(tfoot.bgColor);\n" + + " }\n" + + " </script>\n" + + " </head>\n" + + " <body onload='test()'>\n" + + " <table><tfoot id='tfoot'><tr><td>cell1</td></tr></tfoot></table>\n" + + " </body>\n" + + "</html>"; + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if an error occurs + */ + @Test + @Alerts(FF = { "undefined", "#0000aa", "x" }, + IE = { "", "#0000aa", "#000000" }, + IE11 = { "", "#0000aa", "#0" }) + public void bgColorHeader() throws Exception { + final String html = + "<html>\n" + + " <head>\n" + + " <script>\n" + + " function test() {\n" + + " var thead = document.getElementById('thead');\n" + + " alert(thead.bgColor);\n" + + " thead.bgColor = '#0000aa';\n" + + " alert(thead.bgColor);\n" + + " thead.bgColor = 'x';\n" + + " alert(thead.bgColor);\n" + + " }\n" + + " </script>\n" + + " </head>\n" + + " <body onload='test()'>\n" + + " <table><thead id='thead'><tr><td>cell1</td></tr></thead></table>\n" + + " </body>\n" + + "</html>"; + loadPageWithAlerts2(html); + } } |
From: <rb...@us...> - 2014-04-02 17:21:11
|
Revision: 9227 http://sourceforge.net/p/htmlunit/code/9227 Author: rbri Date: 2014-04-02 17:21:06 +0000 (Wed, 02 Apr 2014) Log Message: ----------- more fixes for the image twins; improved test (both donated by Frank Danek) Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlImage.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLElement.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/Window3Test.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLElementTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLImageElementTest.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlImage.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlImage.java 2014-04-01 16:39:02 UTC (rev 9226) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlImage.java 2014-04-02 17:21:06 UTC (rev 9227) @@ -75,9 +75,17 @@ */ HtmlImage(final String qualifiedName, final SgmlPage page, final Map<String, DomAttr> attributes) { - super(qualifiedName, page, attributes); + super(unifyLocalName(qualifiedName), page, attributes); } + private static String unifyLocalName(final String qualifiedName) { + if (qualifiedName != null && qualifiedName.endsWith(TAG_NAME2)) { + final int pos = qualifiedName.lastIndexOf(TAG_NAME2); + return qualifiedName.substring(0, pos) + TAG_NAME; + } + return qualifiedName; + } + /** * {@inheritDoc} */ Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLElement.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLElement.java 2014-04-01 16:39:02 UTC (rev 9226) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLElement.java 2014-04-02 17:21:06 UTC (rev 9227) @@ -2850,24 +2850,6 @@ * {@inheritDoc} Overridden to modify browser configurations. */ @Override - @JsxFunction - public Object getAttribute(final String attributeName, final Integer flags) { - return super.getAttribute(attributeName, flags); - } - - /** - * {@inheritDoc} Overridden to modify browser configurations. - */ - @Override - @JsxGetter - public final String getTagName() { - return super.getTagName(); - } - - /** - * {@inheritDoc} Overridden to modify browser configurations. - */ - @Override @JsxGetter({ @WebBrowser(CHROME), @WebBrowser(IE) }) public HTMLCollection getChildren() { return super.getChildren(); Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/Window3Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/Window3Test.java 2014-04-01 16:39:02 UTC (rev 9226) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/Window3Test.java 2014-04-02 17:21:06 UTC (rev 9227) @@ -15,7 +15,6 @@ package com.gargoylesoftware.htmlunit.javascript.host; import static com.gargoylesoftware.htmlunit.BrowserRunner.Browser.CHROME; -import static com.gargoylesoftware.htmlunit.BrowserRunner.Browser.FF; import static com.gargoylesoftware.htmlunit.BrowserRunner.Browser.FF17; import static com.gargoylesoftware.htmlunit.BrowserRunner.Browser.FF24; import static com.gargoylesoftware.htmlunit.BrowserRunner.Browser.IE; @@ -504,7 +503,6 @@ IE = { "frame1", "frame1", "2", "2" }, IE8 = { "frame1", "frame1", "exception:w.f2", "exception:f2" }) @NotYetImplemented(IE) - // TODO [IE11] HTMLCollection problem public void frameByName() throws Exception { final String html = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Frameset//EN\"" + "\"http://www.w3.org/TR/html4/frameset.dtd\">\n" @@ -564,140 +562,184 @@ + " <iframe name='frame1'></iframe>\n" + " <iframe name='frame2'></iframe>\n" + " <iframe name='frame2'></iframe>\n" + // iframes are treated as frames and as such have priority over other elements + + " <form name='frame2'></form>\n" + "</body></html>"; loadPageWithAlerts2(html); } - /** - * @throws Exception if the test fails - */ - @Test - @Alerts(DEFAULT = { "exception:w.i1", "exception:i1", "exception:w.i2", "exception:i2" }, - IE = { "input1", "input1", "2", "2" }) - @NotYetImplemented(FF) - // TODO [IE11] HTMLCollection problem - public void inputByName() throws Exception { - final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ - + "<html><head><title>foo</title><script>\n" - + " function test() {\n" - + " try {\n" - + " alert(window.input1.name);\n" - + " } catch (e) { alert('exception:w.i1') }\n" - + " try {\n" - + " alert(input1.name);\n" - + " } catch (e) { alert('exception:i1') }\n" - + " try {\n" - + " alert(window.input2.length);\n" - + " } catch (e) { alert('exception:w.i2') }\n" - + " try {\n" - + " alert(input2.length);\n" - + " } catch (e) { alert('exception:i2') }\n" - + " }\n" - + "</script></head><body onload='test()'>\n" - + " <input type='text' name='input1' value='1'/>\n" - + " <input type='text' name='input2' value='2'/>\n" - + " <input type='text' name='input2' value='3'/>\n" - + "</body></html>"; - - loadPageWithAlerts2(html); - } - /** * @throws Exception if the test fails */ @Test - @Alerts(DEFAULT = { "exception:w.a1", "exception:a1", "exception:w.a2", "exception:a2" }, - IE = { "anchor1", "anchor1", "2", "2" }) - @NotYetImplemented(FF) - // TODO [IE11] HTMLCollection problem - public void anchorByName() throws Exception { - final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ - + "<html><head><title>foo</title><script>\n" - + " function test() {\n" - + " try {\n" - + " alert(window.anchor1.name);\n" - + " } catch (e) { alert('exception:w.a1') }\n" - + " try {\n" - + " alert(anchor1.name);\n" - + " } catch (e) { alert('exception:a1') }\n" - + " try {\n" - + " alert(window.anchor2.length);\n" - + " } catch (e) { alert('exception:w.a2') }\n" - + " try {\n" - + " alert(anchor2.length);\n" - + " } catch (e) { alert('exception:a2') }\n" - + " }\n" - + "</script></head><body onload='test()'>\n" - + " <a name='anchor1'></a>\n" - + " <a name='anchor2'></a>\n" - + " <a name='anchor2'></a>\n" - + "</body></html>"; - - loadPageWithAlerts2(html); - } - - /** - * @throws Exception if the test fails - */ - @Test - @Alerts(DEFAULT = { "image1", "image1", "2", "2" }, - FF17 = { "exception:w.i1", "image1", "exception:w.i2", "2" }) - @NotYetImplemented(FF17) - public void imageByName() throws Exception { - final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ - + "<html><head><title>foo</title><script>\n" - + " function test() {\n" - + " try {\n" - + " alert(window.image1.name);\n" - + " } catch (e) { alert('exception:w.i1') }\n" - + " try {\n" - + " alert(image1.name);\n" - + " } catch (e) { alert('exception:i1') }\n" - + " try {\n" - + " alert(window.image2.length);\n" - + " } catch (e) { alert('exception:w.i2') }\n" - + " try {\n" - + " alert(image2.length);\n" - + " } catch (e) { alert('exception:i2') }\n" - + " }\n" - + "</script></head><body onload='test()'>\n" - + " <img name='image1'>\n" - + " <img name='image2'>\n" - + " <img name='image2'>\n" - + "</body></html>"; - - loadPageWithAlerts2(html); - } - - /** - * @throws Exception if the test fails - */ - @Test - @Alerts({ "exception:w.e1", "exception:e1", "exception:w.e2", "exception:e2" }) + @Alerts(DEFAULT = { "5", "EMBED", "FORM", "IMG", "IMG", "OBJECT", "5", "EMBED", "FORM", "IMG", "IMG", "OBJECT" }, + FF17 = { "exception:w.e1", "5", "EMBED", "FORM", "IMG", "IMG", "OBJECT" }, + IE = { "11", "A", "BUTTON", "EMBED", "FORM", "IMG", "IMG", "INPUT", "MAP", "OBJECT", "SELECT", "TEXTAREA", + "11", "A", "BUTTON", "EMBED", "FORM", "IMG", "IMG", "INPUT", "MAP", "OBJECT", "SELECT", "TEXTAREA" }) @NotYetImplemented - // TODO [IE11] HTMLCollection problem - public void elementByName() throws Exception { + // The following tags cause problems with WebDriver: + // applet, body, frame, frameset, head, html, isindex, meta, plaintext, title + // The iframe tag is treated as frame and as such has priority over the other tags, which would make the test + // useless. + public void elementsByName() throws Exception { final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html><head><title>foo</title><script>\n" + " function test() {\n" + " try {\n" - + " alert(window.element1.name);\n" + + " dump(window.element1);\n" + " } catch (e) { alert('exception:w.e1') }\n" + " try {\n" - + " alert(element1.name);\n" + + " dump(element1);\n" + " } catch (e) { alert('exception:e1') }\n" - + " try {\n" - + " alert(window.element2.length);\n" - + " } catch (e) { alert('exception:w.e2') }\n" - + " try {\n" - + " alert(element2.length);\n" - + " } catch (e) { alert('exception:e2') }\n" + " }\n" + + " function dump(c) {\n" + + " alert(c.length);\n" + + " for (i = 0; i < c.length; i++) {\n" + + " alert(c.item(i).nodeName);\n" + + " }\n" + + " }\n" + "</script></head><body onload='test()'>\n" - + " <div name='element1'></table>\n" - + " <div name='element2'></div>\n" - + " <div name='element2'></div>\n" + + " <abbr name='element1'></abbr>\n" + + " <acronym name='element1'></acronym>\n" + + " <a name='element1'></a>\n" + + " <address name='element1'></address>\n" + // + " <applet name='element1'></applet>\n" + + " <article name='element1'></article>\n" + + " <audio name='element1'></audio>\n" + + " <bgsound name='element1'>\n" + + " <base name='element1'>\n" + + " <basefont name='element1'>\n" + + " <bdo name='element1'></bdo>\n" + + " <big name='element1'></big>\n" + + " <blink name='element1'></blink>\n" + + " <blockquote name='element1'></blockquote>\n" + // + " <body name='element1'></body>\n" + + " <b name='element1'></b>\n" + + " <br name='element1'>\n" + + " <button name='element1'></button>\n" + + " <canvas name='element1'></canvas>\n" + + " <caption name='element1'></caption>\n" + + " <center name='element1'></center>\n" + + " <cite name='element1'></cite>\n" + + " <code name='element1'></code>\n" + + " <datalist name='element1'></datalist>\n" + + " <dfn name='element1'></dfn>\n" + + " <del name='element1'></del>\n" + + " <dir name='element1'></dir>\n" + + " <div name='element1'></div>\n" + + " <dl name='element1'>\n" + + " <dt name='element1'></dt>\n" + + " <dd name='element1'></dd>\n" + + " </dl>\n" + + " <embed name='element1'>\n" + + " <em name='element1'></em>\n" + + " <fieldset name='element1'></fieldset>\n" + + " <figcaption name='element1'></figcaption>\n" + + " <figure name='element1'></figure>\n" + + " <font name='element1'></font>\n" + + " <form name='element1'></form>\n" + + " <footer name='element1'></footer>\n" + // + " <frame name='element1'>\n" + // + " <frameset name='element1'></frameset>\n" + + " <h1 name='element1'></h1>\n" + + " <h2 name='element1'></h2>\n" + + " <h3 name='element1'></h3>\n" + + " <h4 name='element1'></h4>\n" + + " <h5 name='element1'></h5>\n" + + " <h6 name='element1'></h6>\n" + // + " <head name='element1'></head>\n" + + " <header name='element1'></header>\n" + + " <hr name='element1'>\n" + // + " <html name='element1'></html>\n" + // + " <iframe name='element1'></iframe>\n" + + " <q name='element1'></q>\n" + + " <ruby name='element1'>\n" + + " <rt name='element1'></rt>\n" + + " <rp name='element1'></rp>\n" + + " </ruby>\n" + + " <image name='element1'></image>\n" + + " <img name='element1'>\n" + + " <input name='element1'>\n" + + " <ins name='element1'></ins>\n" + // + " <isindex name='element1'></isindex>\n" + + " <i name='element1'></i>\n" + + " <kbd name='element1'></kbd>\n" + + " <keygen name='element1'>\n" + + " <label name='element1'></label>\n" + + " <legend name='element1'></legend>\n" + + " <listing name='element1'></listing>\n" + + " <link name='element1'>\n" + + " <map name='element1'>\n" + + " <area name='element1'>\n" + + " </map>\n" + + " <marquee name='element1'></marquee>\n" + + " <mark name='element1'></mark>\n" + + " <menu name='element1'></menu>\n" + // + " <meta name='element1'>\n" + + " <meter name='element1'></meter>\n" + + " <multicol name='element1'></multicol>\n" + + " <nav name='element1'></nav>\n" + + " <nextid name='element1'></nextid>\n" + + " <nobr name='element1'></nobr>\n" + + " <noembed name='element1'></noembed>\n" + + " <noframes name='element1'></noframes>\n" + + " <noscript name='element1'></noscript>\n" + + " <object name='element1'>\n" + + " <param name='element1'>\n" + + " </object>\n" + + " <ol name='element1'>\n" + + " <li name='element1'></li>\n" + + " </ol>\n" + + " <output name='element1'></output>\n" + + " <p name='element1'></p>\n" + // + " <plaintext name='element1'></plaintext>\n" + + " <pre name='element1'></pre>\n" + + " <progress name='element1'></progress>\n" + + " <s name='element1'></s>\n" + + " <samp name='element1'></samp>\n" + + " <script name='element1'></script>\n" + + " <section name='element1'></section>\n" + + " <select name='element1'>\n" + + " <optgroup name='element1'>\n" + + " <option name='element1'></option>\n" + + " </optgroup>\n" + + " </select>\n" + + " <small name='element1'></small>\n" + + " <source name='element1'>\n" + + " <spacer name='element1'></spacer>\n" + + " <span name='element1'></span>\n" + + " <strike name='element1'></strike>\n" + + " <strong name='element1'></strong>\n" + + " <style name='element1'></style>\n" + + " <sub name='element1'></sub>\n" + + " <sup name='element1'></sup>\n" + + " <table name='element1'>\n" + + " <colgroup name='element1'>\n" + + " <col name='element1'></col>\n" + + " </colgroup>\n" + + " <thead name='element1'>\n" + + " <tr name='element1'>\n" + + " <th name='element1'></th>\n" + + " </tr>\n" + + " </thead>\n" + + " <tbody name='element1'>\n" + + " <tr name='element1'>\n" + + " <td name='element1'></td>\n" + + " </tr>\n" + + " </tbody>\n" + + " <tfoot name='element1'></tfoot>\n" + + " </table>\n" + + " <textarea name='element1'></textarea>\n" + + " <tt name='element1'></tt>\n" + + " <time name='element1'></time>\n" + // + " <title name='element1'></title>\n" + + " <u name='element1'></u>\n" + + " <ul name='element1'></ul>\n" + + " <var name='element1'></var>\n" + + " <video name='element1'></video>\n" + + " <wbr name='element1'>\n" + + " <xmp name='element1'></xmp>\n" + "</body></html>"; loadPageWithAlerts2(html); Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLElementTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLElementTest.java 2014-04-01 16:39:02 UTC (rev 9226) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLElementTest.java 2014-04-02 17:21:06 UTC (rev 9227) @@ -4039,9 +4039,10 @@ */ @Test @Alerts(DEFAULT = "<image></image>", + CHROME = "<image>", IE8 = "<IMG>", IE11 = "<img>") - @NotYetImplemented(IE8) + @NotYetImplemented({ CHROME, FF }) public void outerHTML_image() throws Exception { loadPageWithAlerts2(outerHTML("image")); } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLImageElementTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLImageElementTest.java 2014-04-01 16:39:02 UTC (rev 9226) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLImageElementTest.java 2014-04-02 17:21:06 UTC (rev 9227) @@ -53,17 +53,19 @@ * @throws Exception if the test fails */ @Test - @Alerts(DEFAULT = "[object HTMLImageElement]", - IE8 = "[object]") + @Alerts(DEFAULT = { "[object HTMLImageElement]", "[object HTMLImageElement]" }, + IE8 = { "[object]", "[object]" }) public void simpleScriptable() throws Exception { final String html = "<html><head>\n" + "<script>\n" + " function test() {\n" - + " alert(document.getElementById('myId'));\n" + + " alert(document.getElementById('myId1'));\n" + + " alert(document.getElementById('myId2'));\n" + " }\n" + "</script>\n" + "</head><body onload='test()'>\n" - + " <img id='myId'>\n" + + " <img id='myId1'>\n" + + " <image id='myId2'>\n" + "</body></html>"; loadPageWithAlerts2(html); @@ -73,23 +75,45 @@ * @throws Exception if the test fails */ @Test - @Alerts(DEFAULT = "[object HTMLImageElement]", - IE8 = "[object]") - public void simpleScriptable2() throws Exception { + @Alerts({ "IMG", "IMG" }) + public void nodeName() throws Exception { final String html = "<html><head>\n" + "<script>\n" + " function test() {\n" - + " alert(document.getElementById('myId'));\n" + + " alert(document.getElementById('myId1').nodeName);\n" + + " alert(document.getElementById('myId2').nodeName);\n" + " }\n" + "</script>\n" + "</head><body onload='test()'>\n" - + " <image id='myId'>\n" + + " <img id='myId1'>\n" + + " <image id='myId2'>\n" + "</body></html>"; loadPageWithAlerts2(html); } /** + * @throws Exception if the test fails + */ + @Test + @Alerts({ "IMG", "IMG" }) + public void tagName() throws Exception { + final String html = "<html><head>\n" + + "<script>\n" + + " function test() {\n" + + " alert(document.getElementById('myId1').tagName);\n" + + " alert(document.getElementById('myId2').tagName);\n" + + " }\n" + + "</script>\n" + + "</head><body onload='test()'>\n" + + " <img id='myId1'>\n" + + " <image id='myId2'>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } + + /** * This test verifies that JavaScript can be used to get the <tt>src</tt> attribute of an <tt><img></tt> tag. * @throws Exception if the test fails */ @@ -232,7 +256,9 @@ */ @Test @Alerts(DEFAULT = { "left", "right", "middle", "justify", "bottom", "middle", - "top", "absbottom", "absmiddle", "bottom", "texttop", "wrong", "" }, + "top", "absbottom", "absmiddle", "bottom", "texttop", "wrong", "" }, + CHROME = { "left", "right", "center", "justify", "bottom", "middle", + "top", "absbottom", "absmiddle", "baseline", "texttop", "wrong", "" }, IE = { "left", "right", "center", "", "bottom", "middle", "top", "absBottom", "absMiddle", "baseline", "textTop", "", "" }) @NotYetImplemented({ FF17, FF24 }) @@ -268,6 +294,8 @@ @Test @Alerts(DEFAULT = { "CenTer", "8", "foo", "left", "right", "middle", "justify", "bottom", "middle", "top", "absbottom", "absmiddle", "bottom", "texttop" }, + CHROME = { "CenTer", "8", "foo", "left", "right", "center", "justify", + "bottom", "middle", "top", "absbottom", "absmiddle", "baseline", "texttop" }, IE = { "center", "error", "center", "error", "center", "left", "right", "center", "error", "center", "bottom", "middle", "top", "absBottom", "absMiddle", "baseline", "textTop" }) |
From: <rb...@us...> - 2014-04-03 18:48:54
|
Revision: 9228 http://sourceforge.net/p/htmlunit/code/9228 Author: rbri Date: 2014-04-03 18:48:51 +0000 (Thu, 03 Apr 2014) Log Message: ----------- missing anchor text property added Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLAnchorElement.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlAnchor2Test.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLElementTest.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLAnchorElement.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLAnchorElement.java 2014-04-02 17:21:06 UTC (rev 9227) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLAnchorElement.java 2014-04-03 18:48:51 UTC (rev 9228) @@ -21,6 +21,7 @@ import com.gargoylesoftware.htmlunit.SgmlPage; import com.gargoylesoftware.htmlunit.html.DomElement; +import com.gargoylesoftware.htmlunit.html.DomNode; import com.gargoylesoftware.htmlunit.html.HtmlAnchor; import com.gargoylesoftware.htmlunit.html.HtmlElement; import com.gargoylesoftware.htmlunit.html.HtmlPage; @@ -401,4 +402,25 @@ return href; } } + + /** + * Returns the <tt>text</tt> attribute. + * @return the <tt>text</tt> attribute + */ + @Override + @JsxGetter + public String getText() { + final DomNode htmlElement = getDomNodeOrDie(); + return htmlElement.asText(); + } + + /** + * Sets the <tt>text</tt> attribute. + * @param text the <tt>text</tt> attribute + */ + @JsxSetter + public void setText(final String text) { + final DomNode htmlElement = getDomNodeOrDie(); + htmlElement.setTextContent(text); + } } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlAnchor2Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlAnchor2Test.java 2014-04-02 17:21:06 UTC (rev 9227) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlAnchor2Test.java 2014-04-03 18:48:51 UTC (rev 9228) @@ -24,6 +24,7 @@ import com.gargoylesoftware.htmlunit.BrowserRunner; import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; +import com.gargoylesoftware.htmlunit.BrowserRunner.NotYetImplemented; import com.gargoylesoftware.htmlunit.WebDriverTestCase; /** @@ -290,4 +291,64 @@ tester.click(); assertEquals(2, driver.getWindowHandles().size()); } + + /** + * @throws Exception if an error occurs + */ + @Test + @Alerts({ "My Link", "", "abcd" }) + public void getText() throws Exception { + final String html = + "<html><head><script>\n" + + " function test() {\n" + + " alert(document.getElementById('myAnchor').text);\n" + + " alert(document.getElementById('myImgAnchor').text);\n" + + " alert(document.getElementById('myImgTxtAnchor').text);\n" + + " }\n" + + "</script></head>\n" + + "<body onload=test()>\n" + + " <a id='myAnchor'>My Link</a>\n" + + " <a id='myImgAnchor'><img src='test.png' /></a>\n" + + " <a id='myImgTxtAnchor'>ab<img src='test.png' />cd</a>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if an error occurs + */ + @Test + @Alerts({ "My Link 0", "Hello 0", " 1", "Hello 0", "a 2", "Hello 0" }) + @NotYetImplemented + public void setText() throws Exception { + final String html = + "<html><head><script>\n" + + " function test() {\n" + + " try {\n" + + " var anchor = document.getElementById('myAnchor');\n" + + " alert(anchor.text + ' ' + anchor.children.length);\n" + + " anchor.text = 'Hello';\n" + + " alert(anchor.text + ' ' + anchor.children.length);\n" + + + " anchor = document.getElementById('myImgAnchor');\n" + + " alert(anchor.text + ' ' + anchor.children.length);\n" + + " anchor.text = 'Hello';\n" + + " alert(anchor.text + ' ' + anchor.children.length);\n" + + + " anchor = document.getElementById('myImgTxtAnchor');\n" + + " alert(anchor.text + ' ' + anchor.children.length);\n" + + " anchor.text = 'Hello';\n" + + " alert(anchor.text + ' ' + anchor.children.length);\n" + + " } catch (e) { alert('exception' + e) }\n" + + " }\n" + + "</script></head>\n" + + "<body onload=test()>\n" + + " <a id='myAnchor'>My Link</a>\n" + + " <a id='myImgAnchor'><img src='test.png' /></a>\n" + + " <a id='myImgTxtAnchor'><img src='test.png' />a<img src='test.png' /></a>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLElementTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLElementTest.java 2014-04-02 17:21:06 UTC (rev 9227) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLElementTest.java 2014-04-03 18:48:51 UTC (rev 9228) @@ -1716,6 +1716,29 @@ * @throws Exception if the test fails */ @Test + @Alerts({ "1", "0" }) + @NotYetImplemented + public void childrenDoesNotCountTextNodes() throws Exception { + final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + + "<html><head><title>foo</title><script>\n" + + "function test() {\n" + + " children = document.getElementById('myBody').children;\n" + + " alert(children.length);\n" + + + " children = document.getElementById('myId').children;\n" + + " alert(children.length);\n" + + "}\n" + + "</script></head><body id='myBody' onload='test()'>\n" + + " <div id='myId'>abcd</div>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if the test fails + */ + @Test @Alerts(DEFAULT = { "2", "exception" }, IE = { "2", "BR" }) @NotYetImplemented(FF) |
From: <rb...@us...> - 2014-04-04 18:43:22
|
Revision: 9230 http://sourceforge.net/p/htmlunit/code/9230 Author: rbri Date: 2014-04-04 18:43:17 +0000 (Fri, 04 Apr 2014) Log Message: ----------- fix for children collection Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Element.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlAnchor2Test.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/ElementTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLElementTest.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Element.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Element.java 2014-04-04 17:47:05 UTC (rev 9229) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Element.java 2014-04-04 18:43:17 UTC (rev 9230) @@ -22,6 +22,7 @@ import java.util.ArrayList; import java.util.HashMap; +import java.util.LinkedList; import java.util.List; import java.util.Locale; import java.util.Map; @@ -458,7 +459,13 @@ final HTMLCollection collection = new HTMLCollection(node, false, "Element.children") { @Override protected List<Object> computeElements() { - return new ArrayList<Object>(node.getChildNodes()); + final List<Object> children = new LinkedList<Object>(); + for (DomNode domNode : node.getChildNodes()) { + if (domNode instanceof DomElement) { + children.add(domNode); + } + } + return children; } }; return collection; Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlAnchor2Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlAnchor2Test.java 2014-04-04 17:47:05 UTC (rev 9229) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlAnchor2Test.java 2014-04-04 18:43:17 UTC (rev 9230) @@ -24,7 +24,6 @@ import com.gargoylesoftware.htmlunit.BrowserRunner; import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; -import com.gargoylesoftware.htmlunit.BrowserRunner.NotYetImplemented; import com.gargoylesoftware.htmlunit.WebDriverTestCase; /** @@ -320,7 +319,6 @@ */ @Test @Alerts({ "My Link 0", "Hello 0", " 1", "Hello 0", "a 2", "Hello 0" }) - @NotYetImplemented public void setText() throws Exception { final String html = "<html><head><script>\n" Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/ElementTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/ElementTest.java 2014-04-04 17:47:05 UTC (rev 9229) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/ElementTest.java 2014-04-04 18:43:17 UTC (rev 9230) @@ -976,15 +976,28 @@ * @throws Exception if the test fails */ @Test - @Alerts(DEFAULT = { "[object HTMLCollection]", "[object HTMLCollection]" }, - IE = { "undefined", "[object HTMLCollection]" }) + @Alerts(DEFAULT = { "[object HTMLCollection] 1", "[object HTMLCollection] 2", "[object HTMLCollection] 0" }, + IE = { "exception", "[object HTMLCollection] 2", "[object HTMLCollection] 0" }) public void children() throws Exception { final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html><head><title>foo</title><script>\n" + "function test() {\n" + " var text = '<hello><child></child></hello>';\n" + " var doc = " + XMLDocumentTest.callLoadXMLDocumentFromString("text") + ";\n" - + " alert(doc.documentElement.children);\n" - + " alert(document.documentElement.children);\n" + + + " try {\n" + + " var children = doc.documentElement.children;\n" + + " alert(children + ' ' + children.length);\n" + + " } catch (e) { alert('exception'); }\n" + + + " try {\n" + + " children = document.documentElement.children;\n" + + " alert(children + ' ' + children.length);\n" + + " } catch (e) { alert('exception'); }\n" + + + " try {\n" + + " children = document.getElementById('myId').children;\n" + + " alert(children + ' ' + children.length);\n" + + " } catch (e) { alert('exception'); }\n" + "}\n" + XMLDocumentTest.LOAD_XML_DOCUMENT_FROM_STRING_FUNCTION + "</script></head><body onload='test()'>\n" Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLElementTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLElementTest.java 2014-04-04 17:47:05 UTC (rev 9229) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLElementTest.java 2014-04-04 18:43:17 UTC (rev 9230) @@ -1717,7 +1717,6 @@ */ @Test @Alerts({ "1", "0" }) - @NotYetImplemented public void childrenDoesNotCountTextNodes() throws Exception { final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html><head><title>foo</title><script>\n" |
From: <rb...@us...> - 2014-04-05 10:51:29
|
Revision: 9231 http://sourceforge.net/p/htmlunit/code/9231 Author: rbri Date: 2014-04-05 10:51:22 +0000 (Sat, 05 Apr 2014) Log Message: ----------- Window.name implementation fixed for IE11 (Frank Danek) 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/javascript/host/Window.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/Window3Test.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2014-04-04 18:43:17 UTC (rev 9230) +++ trunk/htmlunit/src/changes/changes.xml 2014-04-05 10:51:22 UTC (rev 9231) @@ -8,6 +8,9 @@ <body> <release version="2.15" date="???" description="Bugfixes"> + <action type="add" dev="rbri" due-to="Frank Danek"> + JavaScript: Window.name implementation fixed for IE11. + </action> <action type="add" dev="rbri"> JavaScript: add support for the bgColor attribute on thead and tfoot element. </action> Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2014-04-04 18:43:17 UTC (rev 9230) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2014-04-05 10:51:22 UTC (rev 9231) @@ -1418,6 +1418,10 @@ @BrowserFeature(@WebBrowser(value = IE, minVersion = 11)) JS_WINDOW_CHANGE_OPENER_ONLY_WINDOW_OBJECT, + /** <code>window.name</code> returns also form fields (e.g. input, textarea). */ + @BrowserFeature(@WebBrowser(IE)) + JS_WINDOW_FORMFIELDS_ACCESSIBLE_BY_NAME, + /** Support for accessing the frame of a window by id additionally * to using the name (FF). */ Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Window.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Window.java 2014-04-04 18:43:17 UTC (rev 9230) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Window.java 2014-04-05 10:51:22 UTC (rev 9231) @@ -19,6 +19,7 @@ import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_EVENT_HANDLER_AS_PROPERTY_DONT_RECEIVE_EVENT; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_WINDOW_CHANGE_OPENER_NOT_ALLOWED; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_WINDOW_CHANGE_OPENER_ONLY_WINDOW_OBJECT; +import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_WINDOW_FORMFIELDS_ACCESSIBLE_BY_NAME; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_WINDOW_FRAMES_ACCESSIBLE_BY_ID; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_WINDOW_IS_A_FUNCTION; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_WINDOW_ONERROR_COLUMN_ARGUMENT; @@ -34,6 +35,7 @@ import java.io.ObjectInputStream; import java.net.MalformedURLException; import java.net.URL; +import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; @@ -53,6 +55,8 @@ import net.sourceforge.htmlunit.corejs.javascript.Undefined; import org.apache.commons.codec.binary.Base64; +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.collections.Predicate; import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.logging.Log; @@ -82,12 +86,22 @@ import com.gargoylesoftware.htmlunit.html.DomElement; import com.gargoylesoftware.htmlunit.html.DomNode; import com.gargoylesoftware.htmlunit.html.FrameWindow; +import com.gargoylesoftware.htmlunit.html.HtmlAnchor; import com.gargoylesoftware.htmlunit.html.HtmlAttributeChangeEvent; import com.gargoylesoftware.htmlunit.html.HtmlAttributeChangeListener; +import com.gargoylesoftware.htmlunit.html.HtmlButton; import com.gargoylesoftware.htmlunit.html.HtmlElement; +import com.gargoylesoftware.htmlunit.html.HtmlEmbed; +import com.gargoylesoftware.htmlunit.html.HtmlForm; +import com.gargoylesoftware.htmlunit.html.HtmlImage; +import com.gargoylesoftware.htmlunit.html.HtmlInput; import com.gargoylesoftware.htmlunit.html.HtmlLink; +import com.gargoylesoftware.htmlunit.html.HtmlMap; +import com.gargoylesoftware.htmlunit.html.HtmlObject; import com.gargoylesoftware.htmlunit.html.HtmlPage; +import com.gargoylesoftware.htmlunit.html.HtmlSelect; import com.gargoylesoftware.htmlunit.html.HtmlStyle; +import com.gargoylesoftware.htmlunit.html.HtmlTextArea; import com.gargoylesoftware.htmlunit.javascript.PostponedAction; import com.gargoylesoftware.htmlunit.javascript.ScriptableWithFallbackGetter; import com.gargoylesoftware.htmlunit.javascript.SimpleScriptable; @@ -1335,19 +1349,9 @@ result = getFrameWindowByName(page, name); if (result == NOT_FOUND) { - // May be attempting to retrieve element(s) by name. IMPORTANT: We're using map-backed operations - // like getHtmlElementsByName() and getHtmlElementById() as much as possible, so as to avoid XPath - // overhead. We only use an XPath-based operation when we have to (where there is more than one - // matching element). This optimization appears to improve performance in certain situations by ~15% - // vs using XPath-based operations throughout. - final List<DomElement> elements = page.getElementsByName(name); - if (elements.size() == 1) { - result = getScriptableFor(elements.get(0)); - } - else if (elements.size() > 1) { - result = ((HTMLDocument) document_).getElementsByName(name); - } - else { + result = getElementsByName(page, name); + + if (result == NOT_FOUND) { // May be attempting to retrieve element by ID (try map-backed operation again instead of XPath). try { final HtmlElement htmlElement = page.getHtmlElementById(name); @@ -1418,6 +1422,69 @@ } } + private Object getElementsByName(final HtmlPage page, final String name) { + Object result = NOT_FOUND; + + // May be attempting to retrieve element(s) by name. IMPORTANT: We're using map-backed operations + // like getHtmlElementsByName() and getHtmlElementById() as much as possible, so as to avoid XPath + // overhead. We only use an XPath-based operation when we have to (where there is more than one + // matching element). This optimization appears to improve performance in certain situations by ~15% + // vs using XPath-based operations throughout. + final List<DomElement> elements = page.getElementsByName(name); + + final boolean includeFormFields = getBrowserVersion().hasFeature(JS_WINDOW_FORMFIELDS_ACCESSIBLE_BY_NAME); + final Predicate filter = new Predicate() { + @Override + public boolean evaluate(final Object object) { + if (object instanceof HtmlEmbed + || object instanceof HtmlForm + || object instanceof HtmlImage + || object instanceof HtmlObject) { + return true; + } + if (includeFormFields && ( + object instanceof HtmlAnchor + || object instanceof HtmlButton + || object instanceof HtmlInput + || object instanceof HtmlMap + || object instanceof HtmlSelect + || object instanceof HtmlTextArea)) { + return true; + } + return false; + } + }; + CollectionUtils.filter(elements, filter); + + if (elements.size() == 1) { + result = getScriptableFor(elements.get(0)); + } + else if (elements.size() > 1) { + // Null must be changed to '' for proper collection initialization. + final String expElementName = "null".equals(name) ? "" : name; + + result = new HTMLCollection(page, true, "Window.getElementsByName('" + name + "')") { + @Override + protected List<Object> computeElements() { + final List<DomElement> elements = page.getElementsByName(expElementName); + CollectionUtils.filter(elements, filter); + + return new ArrayList<Object>(elements); + } + + @Override + protected EffectOnCache getEffectOnCache(final HtmlAttributeChangeEvent event) { + if ("name".equals(event.getName())) { + return EffectOnCache.RESET; + } + return EffectOnCache.NONE; + } + }; + } + + return result; + } + /** * Returns the proxy for the specified window. * @param w the window whose proxy is to be returned Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/Window3Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/Window3Test.java 2014-04-04 18:43:17 UTC (rev 9230) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/Window3Test.java 2014-04-05 10:51:22 UTC (rev 9231) @@ -577,7 +577,6 @@ FF17 = { "exception:w.e1", "5", "EMBED", "FORM", "IMG", "IMG", "OBJECT" }, IE = { "11", "A", "BUTTON", "EMBED", "FORM", "IMG", "IMG", "INPUT", "MAP", "OBJECT", "SELECT", "TEXTAREA", "11", "A", "BUTTON", "EMBED", "FORM", "IMG", "IMG", "INPUT", "MAP", "OBJECT", "SELECT", "TEXTAREA" }) - @NotYetImplemented // The following tags cause problems with WebDriver: // applet, body, frame, frameset, head, html, isindex, meta, plaintext, title // The iframe tag is treated as frame and as such has priority over the other tags, which would make the test |
From: <rb...@us...> - 2014-04-05 18:01:34
|
Revision: 9232 http://sourceforge.net/p/htmlunit/code/9232 Author: rbri Date: 2014-04-05 18:01:31 +0000 (Sat, 05 Apr 2014) Log Message: ----------- table.insertRow was broken when trying to insert a row directly before the last one Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/RowContainer.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLTableElementTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLTableRowElementTest.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2014-04-05 10:51:22 UTC (rev 9231) +++ trunk/htmlunit/src/changes/changes.xml 2014-04-05 18:01:31 UTC (rev 9232) @@ -8,6 +8,10 @@ <body> <release version="2.15" date="???" description="Bugfixes"> + <action type="fix" dev="rbri"> + JavaScript: table.insertRow was broken when trying to insert a row + directly before the last one. + </action> <action type="add" dev="rbri" due-to="Frank Danek"> JavaScript: Window.name implementation fixed for IE11. </action> Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/RowContainer.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/RowContainer.java 2014-04-05 10:51:22 UTC (rev 9231) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/RowContainer.java 2014-04-05 18:01:31 UTC (rev 9232) @@ -118,7 +118,7 @@ final int rowCount = rows.getLength(); final int r; if (rowIndex == -1 || rowIndex == rowCount) { - r = Math.max(0, rowCount - 1); + r = Math.max(0, rowCount); } else { r = rowIndex; @@ -134,7 +134,7 @@ /** * Inserts a new row at the given position. - * @param index the index where the row should be inserted (0 <= index < nbRows) + * @param index the index where the row should be inserted (0 <= index <= nbRows) * @return the inserted row */ public Object insertRow(final int index) { @@ -144,10 +144,14 @@ if (rowCount == 0) { getDomNodeOrDie().appendChild(newRow); } + else if (index == rowCount) { + final SimpleScriptable row = (SimpleScriptable) rows.item(Integer.valueOf(index - 1)); + row.getDomNodeOrDie().getParentNode().appendChild(newRow); + } else { final SimpleScriptable row = (SimpleScriptable) rows.item(Integer.valueOf(index)); // if at the end, then in the same "sub-container" as the last existing row - if (index >= rowCount - 1) { + if (index > rowCount - 1) { row.getDomNodeOrDie().getParentNode().appendChild(newRow); } else { Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLTableElementTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLTableElementTest.java 2014-04-05 10:51:22 UTC (rev 9231) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLTableElementTest.java 2014-04-05 18:01:31 UTC (rev 9232) @@ -321,29 +321,21 @@ loadPageWithAlerts2(html); } - /** - * @throws Exception if the test fails - */ - @Test - @Alerts({ "1", "2", "1", "0", "TD", "1", "2" }) - public void insertRow() throws Exception { + private void insertRow(final String rowIndex) throws Exception { final String html = "<html><head><title>foo</title></head><body>\n" + " <table id='table_1'>\n" - + " <tr><td>foo</td></tr>\n" + + " <tr><td>first</td></tr>\n" + + " <tr><td>second</td></tr>\n" + " </table>\n" - + " <script type='text/javascript' language='JavaScript'>\n" + + " <script>\n" + " var table = document.getElementById('table_1');\n" + " alert(table.rows.length);\n" - + " var newRow = table.insertRow(-1);\n" - + " alert(table.rows.length);\n" - + " alert(newRow.rowIndex);\n" - + " alert(newRow.cells.length);\n" - + " var newCell = newRow.insertCell(-1);\n" - + " alert(newCell.tagName);\n" - + " alert(newRow.cells.length);\n" - + " newRow.insertCell(newRow.cells.length);\n" - + " alert(newRow.cells.length);\n" + + " try {\n" + + " var newRow = table.insertRow(" + rowIndex + ");\n" + + " alert(table.rows.length);\n" + + " alert(newRow.rowIndex);\n" + + " } catch (e) { alert('exception'); }\n" + " </script>\n" + "</body></html>"; @@ -351,6 +343,69 @@ } /** + * @throws Exception if the test fails + */ + @Test + @Alerts({ "2", "3", "2" }) + public void insertRowEmpty() throws Exception { + insertRow(""); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts({ "2", "exception" }) + public void insertRow_MinusTen() throws Exception { + insertRow("-2"); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts({ "2", "3", "2" }) + public void insertRow_MinusOne() throws Exception { + insertRow("-1"); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts({ "2", "3", "0" }) + public void insertRow_Zero() throws Exception { + insertRow("0"); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts({ "2", "3", "1" }) + public void insertRow_One() throws Exception { + insertRow("1"); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts({ "2", "3", "2" }) + public void insertRow_Two() throws Exception { + insertRow("2"); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts({ "2", "exception" }) + public void insertRow_Three() throws Exception { + insertRow("3"); + } + + /** * Regression test for bug 1244839. * @throws Exception if the test fails */ Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLTableRowElementTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLTableRowElementTest.java 2014-04-05 10:51:22 UTC (rev 9231) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLTableRowElementTest.java 2014-04-05 18:01:31 UTC (rev 9232) @@ -378,4 +378,91 @@ + "</script></body></html>"; loadPageWithAlerts2(html); } + + private void insertCell(final String cellIndex) throws Exception { + final String html + = "<html><head><title>foo</title></head><body>\n" + + " <table>\n" + + " <tr id='myRow'>\n" + + " <td>first</td>\n" + + " <td>second</td>\n" + + " </tr>\n" + + " </table>\n" + + " <script>\n" + + " var row = document.getElementById('myRow');\n" + + " alert(row.cells.length);\n" + + " try {\n" + + " var newCell = row.insertCell(" + cellIndex + ");\n" + + " alert(row.cells.length);\n" + + " alert(newCell.cellIndex);\n" + + " } catch (e) { alert('exception'); }\n" + + " </script>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = { "2", "3", "2" }, + FF17 = { "2", "exception" }) + public void insertCellEmpty() throws Exception { + insertCell(""); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts({ "2", "exception" }) + public void insertCell_MinusTen() throws Exception { + insertCell("-2"); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts({ "2", "3", "2" }) + public void insertCell_MinusOne() throws Exception { + insertCell("-1"); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts({ "2", "3", "0" }) + public void insertCell_Zero() throws Exception { + insertCell("0"); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts({ "2", "3", "1" }) + public void insertCell_One() throws Exception { + insertCell("1"); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts({ "2", "3", "2" }) + public void insertCell_Two() throws Exception { + insertCell("2"); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts({ "2", "exception" }) + public void insertCell_Three() throws Exception { + insertCell("3"); + } } |
From: <rb...@us...> - 2014-04-11 18:07:24
|
Revision: 9244 http://sourceforge.net/p/htmlunit/code/9244 Author: rbri Date: 2014-04-11 18:07:19 +0000 (Fri, 11 Apr 2014) Log Message: ----------- tests migrated, expectations and impl fixed Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLOptionElement.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLOptionsCollection.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLImageElement2Test.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLOptionElement2Test.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLOptionElementTest.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2014-04-10 18:53:39 UTC (rev 9243) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2014-04-11 18:07:19 UTC (rev 9244) @@ -535,7 +535,7 @@ HTMLOPTIONGROUP_NO_DISABLED, /** */ - @BrowserFeature(@WebBrowser(IE)) + @BrowserFeature({ @WebBrowser(FF), @WebBrowser(IE) }) HTMLOPTION_EMPTY_TEXT_IS_NO_CHILDREN, /** */ @@ -1153,6 +1153,10 @@ @BrowserFeature(@WebBrowser(value = IE, maxVersion = 9)) JS_OPACITY_ACCEPTS_ARBITRARY_VALUES, + /** Indicates that new option(..) does not update the label property (IE8). */ + @BrowserFeature(@WebBrowser(value = IE, maxVersion = 10)) + JS_OPTION_CONSTRUCTOR_IGNORES_LABEL, + /** Was originally .isFirefox(). */ @BrowserFeature({ @WebBrowser(FF), @WebBrowser(CHROME), @WebBrowser(value = IE, minVersion = 11) }) JS_OPTION_USE_TEXT_AS_VALUE_IF_NOT_DEFINED, @@ -1253,10 +1257,22 @@ @BrowserFeature(@WebBrowser(value = IE, maxVersion = 9)) JS_SELECT_ITEM_THROWS_IF_NEGATIVE, + /** Indicates that select.options throws an exception if the requested index is neagtive (IE8). */ + @BrowserFeature(@WebBrowser(value = IE, maxVersion = 10)) + JS_SELECT_OPTIONS_EXCEPTION_FOR_NEGATIVE, + /** Indicates that select.options.childNodes is a valid property (IE). */ @BrowserFeature(@WebBrowser(IE)) JS_SELECT_OPTIONS_HAS_CHILDNODES_PROPERTY, + /** Indicates that select.options has a wong class name (IE11). */ + @BrowserFeature(@WebBrowser(value = IE, minVersion = 11)) + JS_SELECT_OPTIONS_HAS_SELECT_CLASS_NAME, + + /** Indicates that select.options returns null if requested index is outside (IE). */ + @BrowserFeature(@WebBrowser(IE)) + JS_SELECT_OPTIONS_NULL_FOR_OUTSIDE, + /** Indicates that the set attribute method is able to update the event handlers also. * e.g. element.setAttribute("onclick", "test(1);"); */ @BrowserFeature({ @WebBrowser(FF), @WebBrowser(CHROME), @WebBrowser(value = IE, minVersion = 11) }) Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLOptionElement.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLOptionElement.java 2014-04-10 18:53:39 UTC (rev 9243) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLOptionElement.java 2014-04-11 18:07:19 UTC (rev 9244) @@ -15,6 +15,7 @@ package com.gargoylesoftware.htmlunit.javascript.host.html; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.HTMLOPTION_UNSELECT_SELECTS_FIRST; +import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_OPTION_CONSTRUCTOR_IGNORES_LABEL; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_OPTION_USE_TEXT_AS_VALUE_IF_NOT_DEFINED; import org.xml.sax.helpers.AttributesImpl; @@ -70,6 +71,9 @@ if (!"undefined".equals(newText)) { htmlOption.appendChild(new DomText(page, newText)); + if (!getBrowserVersion().hasFeature(JS_OPTION_CONSTRUCTOR_IGNORES_LABEL)) { + htmlOption.setLabelAttribute(newText); + } } if (!"undefined".equals(newValue)) { htmlOption.setValueAttribute(newValue); Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLOptionsCollection.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLOptionsCollection.java 2014-04-10 18:53:39 UTC (rev 9243) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLOptionsCollection.java 2014-04-11 18:07:19 UTC (rev 9244) @@ -15,7 +15,10 @@ package com.gargoylesoftware.htmlunit.javascript.host.html; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.GENERATED_88; +import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_SELECT_OPTIONS_EXCEPTION_FOR_NEGATIVE; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_SELECT_OPTIONS_HAS_CHILDNODES_PROPERTY; +import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_SELECT_OPTIONS_HAS_SELECT_CLASS_NAME; +import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_SELECT_OPTIONS_NULL_FOR_OUTSIDE; import static com.gargoylesoftware.htmlunit.javascript.configuration.BrowserName.FF; import static com.gargoylesoftware.htmlunit.javascript.configuration.BrowserName.IE; import net.sourceforge.htmlunit.corejs.javascript.Context; @@ -68,6 +71,18 @@ } /** + * {@inheritDoc} + */ + @Override + public String getClassName() { + if (getWindow().getWebWindow() != null + && getBrowserVersion().hasFeature(JS_SELECT_OPTIONS_HAS_SELECT_CLASS_NAME)) { + return "HTMLSelectElement"; + } + return super.getClassName(); + } + + /** * Initializes this object. * @param select the HtmlSelect that this object will retrieve elements from */ @@ -85,18 +100,21 @@ */ @Override public Object get(final int index, final Scriptable start) { - final Object response; if (index < 0) { - throw Context.reportRuntimeError("Index or size is negative"); + if (getBrowserVersion().hasFeature(JS_SELECT_OPTIONS_EXCEPTION_FOR_NEGATIVE)) { + throw Context.reportRuntimeError("Index is negative"); + } + return Context.getUndefinedValue(); } - else if (index >= htmlSelect_.getOptionSize()) { - response = Context.getUndefinedValue(); + + if (index >= htmlSelect_.getOptionSize()) { + if (getBrowserVersion().hasFeature(JS_SELECT_OPTIONS_NULL_FOR_OUTSIDE)) { + return null; + } + return Context.getUndefinedValue(); } - else { - response = getScriptableFor(htmlSelect_.getOption(index)); - } - return response; + return getScriptableFor(htmlSelect_.getOption(index)); } /** Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLImageElement2Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLImageElement2Test.java 2014-04-10 18:53:39 UTC (rev 9243) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLImageElement2Test.java 2014-04-11 18:07:19 UTC (rev 9244) @@ -49,11 +49,11 @@ public void onLoad_calledWhenImageDownloaded_static() throws Exception { final String html = "<html><body><img src='foo.png' onload='test()'>\n" + "<script>\n" - + " alert(0)\n" // first script to be sure that img onload doesn't get executed after first JS execution + + " alert(0);\n" // first script to be sure that img onload doesn't get executed after first JS execution + "</script>\n" + "<script>\n" + "function test() {\n" - + " alert(1)\n" + + " alert(1);\n" + "}\n" + "</script>\n" + "</body></html>"; @@ -74,11 +74,12 @@ @Test @Alerts("1") public void onLoad_calledWhenImageDownloaded_dynamic() throws Exception { - final String html = "<html><body><script>\n" - + "var i = document.createElement('img');\n" - + "i.src = '" + URL_SECOND + "';\n" - + "i.src = '" + URL_THIRD + "';\n" - + "i.onload = function(){alert(1);};\n" + final String html = "<html><body>\n" + + "<script>\n" + + " var i = document.createElement('img');\n" + + " i.src = '" + URL_SECOND + "';\n" + + " i.src = '" + URL_THIRD + "';\n" + + " i.onload = function(){ alert(1); };\n" + "</script></body></html>"; final MockWebConnection conn = getMockWebConnection(); 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 2014-04-10 18:53:39 UTC (rev 9243) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLOptionElement2Test.java 2014-04-11 18:07:19 UTC (rev 9244) @@ -15,7 +15,7 @@ package com.gargoylesoftware.htmlunit.javascript.host.html; import static com.gargoylesoftware.htmlunit.BrowserRunner.Browser.FF; -import static com.gargoylesoftware.htmlunit.BrowserRunner.Browser.IE; +import static com.gargoylesoftware.htmlunit.BrowserRunner.Browser.IE11; import java.util.LinkedList; import java.util.List; @@ -36,6 +36,7 @@ * Tests for {@link HTMLOptionElement}. * * @version $Revision$ + * @author Marc Guillemot * @author Ahmed Ashour * @author Ronald Brill * @author Frank Danek @@ -48,8 +49,6 @@ */ @Test @Alerts("SELECT;") - @BuggyWebDriver(IE) - //TODO: WebDriver tests passes even with HtmlUnit direct usage fails! public void clickSelect() throws Exception { final String html = "<html><head><title>foo</title><script>\n" @@ -104,7 +103,7 @@ @BuggyWebDriver @NotYetImplemented //TODO: Needs further investigation of clicking an option without clicking the select - //See the first comment in http://code.google.com/p/selenium/issues/detail?id=2131#c1 + // See the first comment in http://code.google.com/p/selenium/issues/detail?id=2131#c1 // Additionally, FF and Chrome drivers look buggy as they don't allow to capture // what happens when running the test manually in the browser. public void click2() throws Exception { @@ -115,7 +114,7 @@ + " }\n" + " function init() {\n" - + " var s = document.getElementById('s');\n" + + " s = document.getElementById('s');\n" + " if (s.addEventListener) {\n" + " s.addEventListener('click', handle, false);\n" + " } else if (s.attachEvent) {\n" @@ -158,7 +157,6 @@ @Alerts(DEFAULT = "onchange-select; onclick-option; onclick-select;", IE = "onchange-select; onclick-select;") @BuggyWebDriver(FF) - @NotYetImplemented public void clickOptionEventSequence1() throws Exception { final String html = "<html><head>\n" + "<script>\n" @@ -167,7 +165,7 @@ + " }\n" + "</script></head>\n" - + "<body onload='init()'>\n" + + "<body>\n" + "<form>\n" + " <textarea id='log_' rows='4' cols='50'></textarea>\n" + " <select id='s' size='2' onclick=\"log('onclick-select')\"" @@ -402,4 +400,415 @@ + "</body></html>"; loadPageWithAlerts2(html); } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts({ "some text", "some value", "false", "some other text", "some other value", "true" }) + public void readPropsBeforeAdding() throws Exception { + final String html + = "<html><head><title>foo</title><script>\n" + + "function doTest() {\n" + + " var oOption = new Option('some text', 'some value');\n" + + " alert(oOption.text);\n" + + " alert(oOption.value);\n" + + " alert(oOption.selected);\n" + + " oOption.text = 'some other text';\n" + + " oOption.value = 'some other value';\n" + + " oOption.selected = true;\n" + + " alert(oOption.text);\n" + + " alert(oOption.value);\n" + + " alert(oOption.selected);\n" + + "}</script></head><body onload='doTest()'>\n" + + "<p>hello world</p>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } + + /** + * Regression test for bug 313. + * See http://sourceforge.net/p/htmlunit/bugs/313/. + * @throws Exception if the test fails + */ + @Test + public void selectingOrphanedOptionCreatedByDocument() throws Exception { + final String html = "<html>\n" + + "<body>\n" + + "<form name='myform'/>\n" + + "<script language='javascript'>\n" + + "var select = document.createElement('select');\n" + + "var opt = document.createElement('option');\n" + + "opt.value = 'x';\n" + + "opt.selected = true;\n" + + "select.appendChild(opt);\n" + + "document.myform.appendChild(select);\n" + + "</script>\n" + + "</body></html>"; + loadPageWithAlerts2(html); + } + + /** + * Regression test for 1592728. + * @throws Exception if the test fails + */ + @Test + @Alerts({ "2", "2" }) + public void setSelected() throws Exception { + final String html + = "<html><head><title>foo</title><script>\n" + + "function doTest() {\n" + + " var sel = document.form1.select1;\n" + + " alert(sel.selectedIndex);\n" + + " sel.options[0].selected = false;\n" + + " alert(sel.selectedIndex);\n" + + "}</script></head><body onload='doTest()'>\n" + + "<form name='form1'>\n" + + " <select name='select1' onchange='this.form.submit()'>\n" + + " <option value='option1' name='option1'>One</option>\n" + + " <option value='option2' name='option2'>Two</option>\n" + + " <option value='option3' name='option3' selected>Three</option>\n" + + " </select>\n" + + "</form>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } + + /** + * Regression test for 1672048. + * @throws Exception if the test fails + */ + @Test + public void setAttribute() throws Exception { + final String html + = "<html><head><title>foo</title><script>\n" + + "function doTest() {\n" + + " document.getElementById('option1').setAttribute('class', 'bla bla');\n" + + " var o = new Option('some text', 'some value');\n" + + " o.setAttribute('class', 'myClass');\n" + + "}</script></head><body onload='doTest()'>\n" + + "<form name='form1'>\n" + + " <select name='select1'>\n" + + " <option value='option1' id='option1' name='option1'>One</option>\n" + + " </select>\n" + + "</form>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = { "undefined", "undefined" }, + IE11 = { "null", "undefined" }, + IE8 = { "null", "exception" }) + public void optionIndexOutOfBound() throws Exception { + final String html + = "<html><head><title>foo</title><script>\n" + + "function doTest() {\n" + + " var options = document.getElementById('testSelect').options;\n" + + " alert(options[55]);\n" + + " try {\n" + + " alert(options[-55]);\n" + + " } catch (e) { alert('exception'); }\n" + + "}\n" + + "</script></head><body onload='doTest()'>\n" + + "<form name='form1'>\n" + + " <select name='select1' id='testSelect'>\n" + + " <option value='option1' name='option1'>One</option>\n" + + " </select>\n" + + "</form>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = { "o2: text: Option 2, label: Option 2, value: 2, defaultSelected: false, selected: false", + "o3: text: Option 3, label: Option 3, value: 3, defaultSelected: true, selected: false", + "0", "1" }, + IE8 = { "o2: text: Option 2, label: , value: 2, defaultSelected: false, selected: false", + "o3: text: Option 3, label: , value: 3, defaultSelected: true, selected: false", + "0", "1" }) + public void constructor() throws Exception { + final String html + = "<html><head><title>foo</title><script>\n" + + "function dumpOption(_o) {\n" + + " return 'text: ' + _o.text\n" + + " + ', label: ' + _o.label\n" + + " + ', value: ' + _o.value\n" + + " + ', defaultSelected: ' + _o.defaultSelected\n" + + " + ', selected: ' + _o.selected;\n" + + "}\n" + + "function doTest() {\n" + + " var o2 = new Option('Option 2', '2');\n" + + " alert('o2: ' + dumpOption(o2));\n" + + " var o3 = new Option('Option 3', '3', true, false);\n" + + " alert('o3: ' + dumpOption(o3));\n" + + " document.form1.select1.appendChild(o3);\n" + + " alert(document.form1.select1.options.selectedIndex);\n" + + " document.form1.reset();\n" + + " alert(document.form1.select1.options.selectedIndex);\n" + + "}\n" + + "</script></head><body onload='doTest()'>\n" + + "<form name='form1'>\n" + + " <select name='select1' id='testSelect'>\n" + + " <option value='option1' name='option1'>One</option>\n" + + " </select>\n" + + "</form>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts("0") + public void insideBold() throws Exception { + final String html + = "<html><head><title>foo</title><script>\n" + + "function test() {\n" + + " var sel = document.form1.select1;\n" + + " sel.options[0] = null;\n" + + " alert(sel.options.length);\n" + + "}</script></head><body onload='test()'>\n" + + "<form name='form1'>\n" + + " <b>\n" + + " <select name='select1'>\n" + + " <option>One</option>\n" + + " </select>\n" + + " </b>\n" + + "</form>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = { "null", "[object Attr]", "null", "null", "null", + "null", "null", "null", "null", "null" }, + IE8 = { "[object]", "[object]", "[object]", "[object]", "null", + "[object]", "null", "[object]", "[object]", "null" }) + public void getAttributeNode() throws Exception { + final String html + = "<html><head><title>foo</title><script>\n" + + "function doTest() {\n" + + " var s = document.getElementById('testSelect');\n" + + " var o1 = s.options[0];\n" + + " alert(o1.getAttributeNode('id'));\n" + + " alert(o1.getAttributeNode('name'));\n" + + " alert(o1.getAttributeNode('value'));\n" + + " alert(o1.getAttributeNode('selected'));\n" + + " alert(o1.getAttributeNode('foo'));\n" + + " var o2 = s.options[1];\n" + + " alert(o2.getAttributeNode('id'));\n" + + " alert(o2.getAttributeNode('name'));\n" + + " alert(o2.getAttributeNode('value'));\n" + + " alert(o2.getAttributeNode('selected'));\n" + + " alert(o2.getAttributeNode('foo'));\n" + + "}\n" + + "</script></head>\n" + + "<body onload='doTest()'>\n" + + "<form name='form1'>\n" + + " <select name='select1' id='testSelect'>\n" + + " <option name='option1'>One</option>\n" + + " <option>Two</option>\n" + + " </select>\n" + + "</form>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = { "[object HTMLOptionsCollection]", "0", "1" }, + IE11 = { "[object HTMLSelectElement]", "0", "1" }, + IE8 = { "[object]", "0", "1" }) + public void with_new() throws Exception { + final String html + = "<html><head><title>foo</title><script>\n" + + "function doTest() {\n" + + " var s = document.getElementById('testSelect');\n" + + " alert(s.options);\n" + + " alert(s.length);\n" + + " try {\n" + + " s.options[0] = new Option('one', 'two');\n" + + " } catch (e) { alert(e) };\n" + + " alert(s.length);\n" + + "}\n" + + "</script></head>\n" + + "<body onload='doTest()'>\n" + + " <select id='testSelect'>\n" + + " </select>\n" + + "</form>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = { "[object HTMLOptionsCollection]", "0", "1" }, + CHROME = { "[object HTMLOptionsCollection]", "0", "exception", "0" }, + IE11 = { "[object HTMLSelectElement]", "0", "1" }, + IE8 = { "[object]", "0", "exception", "0" }) + @NotYetImplemented({ FF, IE11 }) + public void without_new() throws Exception { + final String html + = "<html><head><title>foo</title><script>\n" + + "function doTest() {\n" + + " var s = document.getElementById('testSelect');\n" + + " alert(s.options);\n" + + " alert(s.length);\n" + + " try {\n" + + " s.options[0] = Option('one', 'two');\n" + + " } catch (e) { alert('exception') };\n" + + " alert(s.length);\n" + + "}\n" + + "</script></head>\n" + + "<body onload='doTest()'>\n" + + " <select id='testSelect'>\n" + + " </select>\n" + + "</form>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = { "[object Text]", "[object Text]", "null" }, + CHROME = { "null", "[object Text]", "[object Text]" }, + IE8 = { "null", "[object]", "null" }, + IE11 = { "null", "[object Text]", "null" }) + public void text() throws Exception { + final String html + = "<html><head><title>foo</title><script>\n" + + "function test() {\n" + + " var s = document.getElementById('testSelect');\n" + + " var lastIndex = s.length;\n" + + " s.length += 1;\n" + + " alert(s[lastIndex].firstChild);\n" + + " s[lastIndex].text = 'text2';\n" + + " alert(s[lastIndex].firstChild);\n" + + " s[lastIndex].text = '';\n" + + " alert(s[lastIndex].firstChild);\n" + + "}\n" + + "</script></head><body onload='test()'>\n" + + " <select id='testSelect'>\n" + + " <option value='value1' label='label1'>text1</option>\n" + + " </select>\n" + + "</form>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } + + /** + * Visibility of elements should not impact the determination of the value of option + * without value attribute or the text of options. This tests for one part a regression + * introduced in rev. 4367 as well probably as a problem that exists since a long time. + * @throws Exception if the test fails + */ + @Test + @Alerts({ "text1", "text1b", "text2" }) + public void text_when_not_displayed() throws Exception { + final String html + = "<html><head><title>foo</title><script>\n" + + "function test() {\n" + + " var s = document.getElementById('testSelect1');\n" + + " alert(s.options[0].text);\n" + + " alert(s.options[1].text);\n" + + " var s2 = document.getElementById('testSelect2');\n" + + " alert(s2.options[0].text);\n" + + "}\n" + + "</script></head><body onload='test()'>\n" + + " <div style='display: none'>\n" + + " <select id='testSelect1'>\n" + + " <option>text1</option>\n" + + " <option><strong>text1b</strong></option>\n" + + " </select>\n" + + " </div>\n" + + " <div style='visibility: hidden'>\n" + + " <select id='testSelect2'>\n" + + " <option>text2</option>\n" + + " </select>\n" + + " </div>\n" + + "</form>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } + + /** + * For IE nested nodes aren't used as default value attribute. + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = { "text0", "text1", "text1b", "text2" }, + IE8 = { "", "", "", "" }) + public void defaultValueFromNestedNodes() throws Exception { + final String html + = "<html><head><title>foo</title><script>\n" + + "function test() {\n" + + " var s0 = document.getElementById('testSelect0');\n" + + " alert(s0.options[0].value);\n" + + " var s = document.getElementById('testSelect1');\n" + + " alert(s.options[0].value);\n" + + " alert(s.options[1].value);\n" + + " var s2 = document.getElementById('testSelect2');\n" + + " alert(s2.options[0].value);\n" + + "}\n" + + "</script></head><body onload='test()'>\n" + + " <select id='testSelect0'>\n" + + " <option>text0</option>\n" + + " </select>\n" + + " <div style='display: none'>\n" + + " <select id='testSelect1'>\n" + + " <option>text1</option>\n" + + " <option><strong>text1b</strong></option>\n" + + " </select>\n" + + " </div>\n" + + " <div style='visibility: hidden'>\n" + + " <select id='testSelect2'>\n" + + " <option>text2</option>\n" + + " </select>\n" + + " </div>\n" + + "</form>\n" + + "</body></html>"; + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = "[object HTMLFormElement]", + IE8 = "[object]") + public void form() throws Exception { + final String html + = "<html><body><form><select id='s'><option>a</option></select></form><script>\n" + + "alert(document.getElementById('s').options[0].form);\n" + + "</script></body></html>"; + loadPageWithAlerts2(html); + } } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLOptionElementTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLOptionElementTest.java 2014-04-10 18:53:39 UTC (rev 9243) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLOptionElementTest.java 2014-04-11 18:07:19 UTC (rev 9244) @@ -14,15 +14,11 @@ */ package com.gargoylesoftware.htmlunit.javascript.host.html; -import static com.gargoylesoftware.htmlunit.BrowserRunner.Browser.IE; - 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.Browsers; -import com.gargoylesoftware.htmlunit.BrowserRunner.NotYetImplemented; import com.gargoylesoftware.htmlunit.SimpleWebTestCase; import com.gargoylesoftware.htmlunit.html.HtmlPage; import com.gargoylesoftware.htmlunit.html.HtmlSelect; @@ -34,268 +30,14 @@ * @author Marc Guillemot * @author Ahmed Ashour * @author Frank Danek - */ + * @author Ronald Brill +*/ @RunWith(BrowserRunner.class) public class HTMLOptionElementTest extends SimpleWebTestCase { - /** * @throws Exception if the test fails */ @Test - @Alerts({ "some text", "some value", "false", "some other text", "some other value", "true" }) - public void readPropsBeforeAdding() throws Exception { - final String html - = "<html><head><title>foo</title><script>\n" - + "function doTest() {\n" - + " var oOption = new Option('some text', 'some value');\n" - + " alert(oOption.text);\n" - + " alert(oOption.value);\n" - + " alert(oOption.selected);\n" - + " oOption.text = 'some other text';\n" - + " oOption.value = 'some other value';\n" - + " oOption.selected = true;\n" - + " alert(oOption.text);\n" - + " alert(oOption.value);\n" - + " alert(oOption.selected);\n" - + "}</script></head><body onload='doTest()'>\n" - + "<p>hello world</p>\n" - + "</body></html>"; - - loadPageWithAlerts(html); - } - - /** - * Regression test for bug 313. - * See http://sourceforge.net/p/htmlunit/bugs/313/. - * @throws Exception if the test fails - */ - @Test - public void selectingOrphanedOptionCreatedByDocument() throws Exception { - final String html = "<html>\n" - + "<body>\n" - + "<form name='myform'/>\n" - + "<script language='javascript'>\n" - + "var select = document.createElement('select');\n" - + "var opt = document.createElement('option');\n" - + "opt.value = 'x';\n" - + "opt.selected = true;\n" - + "select.appendChild(opt);\n" - + "document.myform.appendChild(select);\n" - + "</script>\n" - + "</body></html>"; - loadPageWithAlerts(html); - } - - /** - * Regression test for 1592728. - * @throws Exception if the test fails - */ - @Test - @Alerts({ "2", "2" }) - public void setSelected() throws Exception { - final String html - = "<html><head><title>foo</title><script>\n" - + "function doTest() {\n" - + " var sel = document.form1.select1;\n" - + " alert(sel.selectedIndex);\n" - + " sel.options[0].selected = false;\n" - + " alert(sel.selectedIndex);\n" - + "}</script></head><body onload='doTest()'>\n" - + "<form name='form1'>\n" - + " <select name='select1' onchange='this.form.submit()'>\n" - + " <option value='option1' name='option1'>One</option>\n" - + " <option value='option2' name='option2'>Two</option>\n" - + " <option value='option3' name='option3' selected>Three</option>\n" - + " </select>\n" - + "</form>\n" - + "</body></html>"; - - loadPageWithAlerts(html); - } - - /** - * Regression test for 1672048. - * @throws Exception if the test fails - */ - @Test - public void setAttribute() throws Exception { - final String html - = "<html><head><title>foo</title><script>\n" - + "function doTest() {\n" - + " document.getElementById('option1').setAttribute('class', 'bla bla');\n" - + " var o = new Option('some text', 'some value');\n" - + " o.setAttribute('class', 'myClass');\n" - + "}</script></head><body onload='doTest()'>\n" - + "<form name='form1'>\n" - + " <select name='select1'>\n" - + " <option value='option1' id='option1' name='option1'>One</option>\n" - + " </select>\n" - + "</form>\n" - + "</body></html>"; - - loadPageWithAlerts(html); - } - - /** - * @throws Exception if the test fails - */ - @Test - @Alerts({ "undefined", "caught exception for negative index" }) - public void optionIndexOutOfBound() throws Exception { - final String html - = "<html><head><title>foo</title><script>\n" - + "function doTest() {\n" - + " var options = document.getElementById('testSelect').options;\n" - + " alert(options[55]);\n" - + " try\n" - + " {\n" - + " alert(options[-55]);\n" - + " }\n" - + " catch (e)\n" - + " {\n" - + " alert('caught exception for negative index');\n" - + " }\n" - + "}\n" - + "</script></head><body onload='doTest()'>\n" - + "<form name='form1'>\n" - + " <select name='select1' id='testSelect'>\n" - + " <option value='option1' name='option1'>One</option>\n" - + " </select>\n" - + "</form>\n" - + "</body></html>"; - - loadPageWithAlerts(html); - } - - /** - * @throws Exception if the test fails - */ - @Test - @Alerts({ "o2: text: Option 2, label: , value: 2, defaultSelected: false, selected: false", - "o3: text: Option 3, label: , value: 3, defaultSelected: true, selected: false", - "0", "1" }) - public void constructor() throws Exception { - final String html - = "<html><head><title>foo</title><script>\n" - + "function dumpOption(_o) {\n" - + " return 'text: ' + _o.text\n" - + " + ', label: ' + _o.label\n" - + " + ', value: ' + _o.value\n" - + " + ', defaultSelected: ' + _o.defaultSelected\n" - + " + ', selected: ' + _o.selected;\n" - + "}\n" - + "function doTest() {\n" - + " var o2 = new Option('Option 2', '2');\n" - + " alert('o2: ' + dumpOption(o2));\n" - + " var o3 = new Option('Option 3', '3', true, false);\n" - + " alert('o3: ' + dumpOption(o3));\n" - + " document.form1.select1.appendChild(o3);\n" - + " alert(document.form1.select1.options.selectedIndex);\n" - + " document.form1.reset();\n" - + " alert(document.form1.select1.options.selectedIndex);\n" - + "}\n" - + "</script></head><body onload='doTest()'>\n" - + "<form name='form1'>\n" - + " <select name='select1' id='testSelect'>\n" - + " <option value='option1' name='option1'>One</option>\n" - + " </select>\n" - + "</form>\n" - + "</body></html>"; - - loadPageWithAlerts(html); - } - - /** - * @throws Exception if the test fails - */ - @Test - @Alerts("0") - public void insideBold() throws Exception { - final String html - = "<html><head><title>foo</title><script>\n" - + "function test() {\n" - + " var sel = document.form1.select1;\n" - + " sel.options[0] = null;\n" - + " alert(sel.options.length);\n" - + "}</script></head><body onload='test()'>\n" - + "<form name='form1'>\n" - + " <b>\n" - + " <select name='select1'>\n" - + " <option>One</option>\n" - + " </select>\n" - + " </b>\n" - + "</form>\n" - + "</body></html>"; - - loadPageWithAlerts(html); - } - - /** - * @throws Exception if the test fails - */ - @Test - @Alerts(DEFAULT = { "null", "[object Attr]", "null", "null", "null", - "null", "null", "null", "null", "null" }, - IE8 = { "[object]", "[object]", "[object]", "[object]", "null", - "[object]", "null", "[object]", "[object]", "null" }) - public void getAttributeNode() throws Exception { - final String html - = "<html><head><title>foo</title><script>\n" - + "function doTest() {\n" - + " var s = document.getElementById('testSelect');\n" - + " var o1 = s.options[0];\n" - + " alert(o1.getAttributeNode('id'))\n" - + " alert(o1.getAttributeNode('name'))\n" - + " alert(o1.getAttributeNode('value'))\n" - + " alert(o1.getAttributeNode('selected'))\n" - + " alert(o1.getAttributeNode('foo'))\n" - + " var o2 = s.options[1];\n" - + " alert(o2.getAttributeNode('id'))\n" - + " alert(o2.getAttributeNode('name'))\n" - + " alert(o2.getAttributeNode('value'))\n" - + " alert(o2.getAttributeNode('selected'))\n" - + " alert(o2.getAttributeNode('foo'))\n" - + "}\n" - + "</script></head><body onload='doTest()'>\n" - + "<form name='form1'>\n" - + " <select name='select1' id='testSelect'>\n" - + " <option name='option1'>One</option>\n" - + " <option>Two</option>\n" - + " </select>\n" - + "</form>\n" - + "</body></html>"; - - loadPageWithAlerts(html); - } - - /** - * @throws Exception if the test fails - */ - @Test - @Browsers(IE) - @Alerts("1") - @NotYetImplemented - public void without_new() throws Exception { - final String html - = "<html><head><title>foo</title><script>\n" - + "function doTest() {\n" - + " var s = document.getElementById('testSelect');\n" - + " s.options[0] = Option('one', 'two');\n" - + " alert(s.length);\n" - + "}\n" - + "</script></head><body onload='doTest()'>\n" - + " <select id='testSelect'>\n" - + " </select>\n" - + "</form>\n" - + "</body></html>"; - - loadPageWithAlerts(html); - } - - /** - * @throws Exception if the test fails - */ - @Test @Alerts({ "value1", "text1", "label1", "value2", "text2", "" }) public void label() throws Exception { final String html @@ -329,124 +71,4 @@ assertEquals("text2", select.getOption(1).getTextContent()); assertEquals("", select.getOption(1).getLabelAttribute()); } - - /** - * @throws Exception if the test fails - */ - @Test - @Alerts(FF = { "[object Text]", "[object Text]", "[object Text]" }, - IE = { "null", "[object]", "null" }, - IE11 = { "null", "[object Text]", "null" }) - public void text() throws Exception { - final String html - = "<html><head><title>foo</title><script>\n" - + "function test() {\n" - + " var s = document.getElementById('testSelect');\n" - + " var lastIndex = s.length;\n" - + " s.length += 1;\n" - + " alert(s[lastIndex].firstChild);\n" - + " s[lastIndex].text = 'text2';\n" - + " alert(s[lastIndex].firstChild);\n" - + " s[lastIndex].text = '';\n" - + " alert(s[lastIndex].firstChild);\n" - + "}\n" - + "</script></head><body onload='test()'>\n" - + " <select id='testSelect'>\n" - + " <option value='value1' label='label1'>text1</option>\n" - + " </select>\n" - + "</form>\n" - + "</body></html>"; - - loadPageWithAlerts(html); - } - - /** - * Visibility of elements should not impact the determination of the value of option - * without value attribute or the text of options. This tests for one part a regression - * introduced in rev. 4367 as well probably as a problem that exists since a long time. - * @throws Exception if the test fails - */ - @Test - @Alerts({ "text1", "text1b", "text2" }) - public void text_when_not_displayed() throws Exception { - final String html - = "<html><head><title>foo</title><script>\n" - + "function test() {\n" - + " var s = document.getElementById('testSelect1');\n" - + " alert(s.options[0].text);\n" - + " alert(s.options[1].text);\n" - + " var s2 = document.getElementById('testSelect2');\n" - + " alert(s2.options[0].text);\n" - + "}\n" - + "</script></head><body onload='test()'>\n" - + " <div style='display: none'>\n" - + " <select id='testSelect1'>\n" - + " <option>text1</option>\n" - + " <option><strong>text1b</strong></option>\n" - + " </select>\n" - + " </div>\n" - + " <div style='visibility: hidden'>\n" - + " <select id='testSelect2'>\n" - + " <option>text2</option>\n" - + " </select>\n" - + " </div>\n" - + "</form>\n" - + "</body></html>"; - - loadPageWithAlerts(html); - } - - /** - * For IE nested nodes aren't used as default value attribute. - * @throws Exception if the test fails - */ - @Test - @Alerts(DEFAULT = { "text0", "text1", "text1b", "text2" }, - IE8 = { "", "", "", "" }) - public void defaultValueFromNestedNodes() throws Exception { - final String html - = "<html><head><title>foo</title><script>\n" - + "function test() {\n" - + " var s0 = document.getElementById('testSelect0');\n" - + " alert(s0.options[0].value);\n" - + " var s = document.getElementById('testSelect1');\n" - + " alert(s.options[0].value);\n" - + " alert(s.options[1].value);\n" - + " var s2 = document.getElementById('testSelect2');\n" - + " alert(s2.options[0].value);\n" - + "}\n" - + "</script></head><body onload='test()'>\n" - + " <select id='testSelect0'>\n" - + " <option>text0</option>\n" - + " </select>\n" - + " <div style='display: none'>\n" - + " <select id='testSelect1'>\n" - + " <option>text1</option>\n" - + " <option><strong>text1b</strong></option>\n" - + " </select>\n" - + " </div>\n" - + " <div style='visibility: hidden'>\n" - + " <select id='testSelect2'>\n" - + " <option>text2</option>\n" - + " </select>\n" - + " </div>\n" - + "</form>\n" - + "</body></html>"; - loadPageWithAlerts(html); - } - - /** - * @throws Exception if the test fails - */ - @Test - @Alerts(DEFAULT = "[object HTMLFormElement]", - IE8 = "[object]") - public void form() throws Exception { - final String html - = "<html><body><form><select id='s'><option>a</option></select></form><script>\n" - + "alert(document.getElementById('s').options[0].form);\n" - + "</script></body></html>"; - loadPageWithAlerts(html); - } - } |
From: <rb...@us...> - 2014-04-12 12:56:12
|
Revision: 9247 http://sourceforge.net/p/htmlunit/code/9247 Author: rbri Date: 2014-04-12 12:56:07 +0000 (Sat, 12 Apr 2014) Log Message: ----------- the usual process; try to fix naming of one option, found missing tests, add the tests, found broken impl, fix the impl and finally fix the name of the option Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLOptionsCollection.java Added Paths: ----------- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLOptionsCollectionTest.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2014-04-11 19:28:17 UTC (rev 9246) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2014-04-12 12:56:07 UTC (rev 9247) @@ -392,10 +392,6 @@ /** Was originally .isIE(). */ @BrowserFeature(@WebBrowser(IE)) - GENERATED_88, - - /** Was originally .isIE(). */ - @BrowserFeature(@WebBrowser(IE)) GENERATED_90, /** If the class name is [object GeoGeolocation]. */ @@ -1269,6 +1265,15 @@ @BrowserFeature(@WebBrowser(value = IE, minVersion = 11)) JS_SELECT_OPTIONS_HAS_SELECT_CLASS_NAME, + /** Ignore negative value when setting the length (FF24). */ + @BrowserFeature(@WebBrowser(value = FF, minVersion = 24)) + JS_SELECT_OPTIONS_IGNORE_NEGATIVE_LENGTH, + + /** When expanding the collection by setting the length don't add + * a empty text node. */ + @BrowserFeature(@WebBrowser(IE)) + JS_SELECT_OPTIONS_DONT_ADD_EMPTY_TEXT_CHILD_WHEN_EXPANDING, + /** Indicates that select.options returns null if requested index is outside (IE). */ @BrowserFeature(@WebBrowser(IE)) JS_SELECT_OPTIONS_NULL_FOR_OUTSIDE, Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLOptionsCollection.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLOptionsCollection.java 2014-04-11 19:28:17 UTC (rev 9246) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLOptionsCollection.java 2014-04-12 12:56:07 UTC (rev 9247) @@ -14,10 +14,12 @@ */ package com.gargoylesoftware.htmlunit.javascript.host.html; -import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.GENERATED_88; +import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures. + JS_SELECT_OPTIONS_DONT_ADD_EMPTY_TEXT_CHILD_WHEN_EXPANDING; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_SELECT_OPTIONS_EXCEPTION_FOR_NEGATIVE; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_SELECT_OPTIONS_HAS_CHILDNODES_PROPERTY; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_SELECT_OPTIONS_HAS_SELECT_CLASS_NAME; +import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_SELECT_OPTIONS_IGNORE_NEGATIVE_LENGTH; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_SELECT_OPTIONS_NULL_FOR_OUTSIDE; import static com.gargoylesoftware.htmlunit.javascript.configuration.BrowserName.FF; import static com.gargoylesoftware.htmlunit.javascript.configuration.BrowserName.IE; @@ -224,6 +226,13 @@ */ @JsxSetter public void setLength(final int newLength) { + if (newLength < 0) { + if (getBrowserVersion().hasFeature(JS_SELECT_OPTIONS_IGNORE_NEGATIVE_LENGTH)) { + return; + } + throw Context.reportRuntimeError("Length is negative"); + } + final int currentLength = htmlSelect_.getOptionSize(); if (currentLength > newLength) { htmlSelect_.setOptionSize(newLength); @@ -233,7 +242,7 @@ final HtmlOption option = (HtmlOption) HTMLParser.getFactory(HtmlOption.TAG_NAME).createElement( htmlSelect_.getPage(), HtmlOption.TAG_NAME, null); htmlSelect_.appendOption(option); - if (!getBrowserVersion().hasFeature(GENERATED_88)) { + if (!getBrowserVersion().hasFeature(JS_SELECT_OPTIONS_DONT_ADD_EMPTY_TEXT_CHILD_WHEN_EXPANDING)) { option.appendChild(new DomText(option.getPage(), "")); } } Added: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLOptionsCollectionTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLOptionsCollectionTest.java (rev 0) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLOptionsCollectionTest.java 2014-04-12 12:56:07 UTC (rev 9247) @@ -0,0 +1,184 @@ +/* + * Copyright (c) 2002-2014 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; + +/** + * Tests for {@link HTMLOptionsCollection}. + * + * @version $Revision:$ + * @author Ronald Brill + */ +@RunWith(BrowserRunner.class) +public class HTMLOptionsCollectionTest extends WebDriverTestCase { + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts({ "0", "1", "4" }) + public void length() throws Exception { + final String html + = "<html><head><title>foo</title><script>\n" + + "function test() {\n" + + " var sel = document.form1.select0;\n" + + " alert(sel.options.length);\n" + + " sel = document.form1.select1;\n" + + " alert(sel.options.length);\n" + + " sel = document.form1.select4;\n" + + " alert(sel.options.length);\n" + + "}</script></head>\n" + + + "<body onload='test()'>\n" + + "<form name='form1'>\n" + + " <select name='select0'>\n" + + " </select>\n" + + " <select name='select1'>\n" + + " <option>One</option>\n" + + " </select>\n" + + " <select name='select4'>\n" + + " <option>One</option>\n" + + " <option>Two</option>\n" + + " <option>Three</option>\n" + + " <option>Four</option>\n" + + " </select>\n" + + "</form>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = { "exception", "exception" }, + FF24 = { "1", "4" }) + public void setLength_negative() throws Exception { + final String html + = "<html><head><title>foo</title><script>\n" + + "function test() {\n" + + " var sel = document.form1.select1;\n" + + " try {\n" + + " sel.options.length = -1;\n" + + " alert(sel.options.length);\n" + + " } catch (e) { alert('exception'); }\n" + + + " var sel = document.form1.select4;\n" + + " try {\n" + + " sel.options.length = -1;\n" + + " alert(sel.options.length);\n" + + " } catch (e) { alert('exception'); }\n" + + "}</script></head>\n" + + + "<body onload='test()'>\n" + + "<form name='form1'>\n" + + " <select name='select1'>\n" + + " <option>One</option>\n" + + " </select>\n" + + " <select name='select4'>\n" + + " <option>One</option>\n" + + " <option>Two</option>\n" + + " <option>Three</option>\n" + + " <option>Four</option>\n" + + " </select>\n" + + "</form>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts({ "0", "0" }) + public void setLength_zero() throws Exception { + final String html + = "<html><head><title>foo</title><script>\n" + + "function test() {\n" + + " var sel = document.form1.select0;\n" + + " try {\n" + + " sel.options.length = 0;\n" + + " alert(sel.options.length);\n" + + " } catch (e) { alert(e); }\n" + + + " sel = document.form1.select1;\n" + + " try {\n" + + " sel.options.length = 0;\n" + + " alert(sel.options.length);\n" + + " } catch (e) { alert(e); }\n" + + "}</script></head>\n" + + + "<body onload='test()'>\n" + + "<form name='form1'>\n" + + " <select name='select0'>\n" + + " </select>\n" + + " <select name='select1'>\n" + + " <option>One</option>\n" + + " </select>\n" + + "</form>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = { "1", "", "4", "One", "1", "", "1" }, + IE = { "1", "", "4", "One", "1", "", "0" }) + public void setLength_increase() throws Exception { + final String html + = "<html><head><title>foo</title><script>\n" + + "function test() {\n" + + " var sel = document.form1.select0;\n" + + " try {\n" + + " sel.options.length = 1;\n" + + " alert(sel.options.length);\n" + + " alert(sel.options[0].text);\n" + + " } catch (e) { alert(e); }\n" + + + " sel = document.form1.select1;\n" + + " try {\n" + + " sel.options.length = 4;\n" + + " alert(sel.options.length);\n" + + " alert(sel.options[0].text);\n" + + " alert(sel.options[0].childNodes.length);\n" + + " alert(sel.options[1].text);\n" + + " alert(sel.options[1].childNodes.length);\n" + + " } catch (e) { alert(e); }\n" + + "}</script></head>\n" + + + "<body onload='test()'>\n" + + "<form name='form1'>\n" + + " <select name='select0'>\n" + + " </select>\n" + + " <select name='select1'>\n" + + " <option>One</option>\n" + + " </select>\n" + + "</form>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } +} Property changes on: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLOptionsCollectionTest.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 |
From: <rb...@us...> - 2014-04-12 17:02:51
|
Revision: 9249 http://sourceforge.net/p/htmlunit/code/9249 Author: rbri Date: 2014-04-12 17:02:47 +0000 (Sat, 12 Apr 2014) Log Message: ----------- one more fix Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Window.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/WindowConcurrencyTest.java Added Paths: ----------- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/WindowConcurrency2Test.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2014-04-12 15:34:35 UTC (rev 9248) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2014-04-12 17:02:47 UTC (rev 9249) @@ -324,10 +324,6 @@ /** Was originally .isIE(). */ @BrowserFeature(@WebBrowser(IE)) - GENERATED_133, - - /** Was originally .isIE(). */ - @BrowserFeature(@WebBrowser(IE)) GENERATED_150, /** Was originally .isFirefox(). */ @@ -1279,6 +1275,13 @@ @BrowserFeature({ @WebBrowser(FF), @WebBrowser(CHROME), @WebBrowser(value = IE, minVersion = 11) }) JS_SET_ATTRIBUTE_SUPPORTS_EVENT_HANDLERS, + /** + * When <tt>setInterval()</tt> is called with a 0 millisecond delay, Internet Explorer turns it + * into a <tt>setTimeout()</tt> call. + */ + @BrowserFeature(@WebBrowser(value = IE, maxVersion = 8)) + JS_SET_INTERVAL_ZERO_TIMEOUT_FORCES_SET_TIMEOUT, + /** When addressing an item in a stylesheet list using a negative index an exception is thrown. */ @BrowserFeature({ @WebBrowser(FF), @WebBrowser(value = IE, maxVersion = 9) }) JS_STYLESHEETLIST_EXCEPTION_FOR_NEGATIVE_INDEX, Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Window.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Window.java 2014-04-12 15:34:35 UTC (rev 9248) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Window.java 2014-04-12 17:02:47 UTC (rev 9249) @@ -15,8 +15,8 @@ package com.gargoylesoftware.htmlunit.javascript.host; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.EVENT_ONLOAD_UNDEFINED_THROWS_ERROR; -import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.GENERATED_133; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_EVENT_HANDLER_AS_PROPERTY_DONT_RECEIVE_EVENT; +import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_SET_INTERVAL_ZERO_TIMEOUT_FORCES_SET_TIMEOUT; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_WINDOW_CHANGE_OPENER_NOT_ALLOWED; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_WINDOW_CHANGE_OPENER_ONLY_WINDOW_OBJECT; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_WINDOW_FORMFIELDS_ACCESSIBLE_BY_NAME; @@ -1551,7 +1551,7 @@ */ @JsxFunction public int setInterval(final Object code, int timeout, final Object language) { - if (timeout == 0 && getBrowserVersion().hasFeature(GENERATED_133)) { + if (timeout == 0 && getBrowserVersion().hasFeature(JS_SET_INTERVAL_ZERO_TIMEOUT_FORCES_SET_TIMEOUT)) { return setTimeout(code, timeout, language); } Added: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/WindowConcurrency2Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/WindowConcurrency2Test.java (rev 0) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/WindowConcurrency2Test.java 2014-04-12 17:02:47 UTC (rev 9249) @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2002-2014 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; + +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 Window} that use background jobs. + * + * @version $Revision$ + * @author Ronald Brill + */ +@RunWith(BrowserRunner.class) +public class WindowConcurrency2Test extends WebDriverTestCase { + + /** + * When <tt>setInterval()</tt> is called with a 0 millisecond delay, Internet Explorer turns it + * into a <tt>setTimeout()</tt> call, and Firefox imposes a minimum timer restriction. + * + * @throws Exception if an error occurs + */ + @Test + @Alerts(DEFAULT = "xxx", + IE8 = "x") + public void setIntervalZeroDelay() throws Exception { + final String html + = "<html><body><div id='d'></div>\n" + + "<script>\n" + + " var count=0;\n" + + + " function doTimeout() {\n" + + " document.getElementById('d').innerHTML += 'x';\n" + + " count += 1;\n" + + " if (count>2) {;\n" + + " clearInterval(id);\n" + + " };\n" + + " }\n" + + + " var id = setInterval(doTimeout, 0);\n" + + "</script>\n" + + "</body></html>"; + + final WebDriver driver = loadPage2(html); + Thread.sleep(100); + final String info = driver.findElement(By.id("d")).getText(); + assertEquals(getExpectedAlerts()[0], info); + } +} Property changes on: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/WindowConcurrency2Test.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 Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/WindowConcurrencyTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/WindowConcurrencyTest.java 2014-04-12 15:34:35 UTC (rev 9248) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/WindowConcurrencyTest.java 2014-04-12 17:02:47 UTC (rev 9249) @@ -176,42 +176,6 @@ } /** - * When <tt>setInterval()</tt> is called with a 0 millisecond delay, Internet Explorer turns it - * into a <tt>setTimeout()</tt> call, and Firefox imposes a minimum timer restriction. - * - * @throws Exception if an error occurs - */ - @Test - public void setIntervalZeroDelay() throws Exception { - final String html - = "<html><body><div id='d'></div>\n" - + "<script>var id = setInterval('document.getElementById(\"d\").innerHTML += \"x\"', 0);</script>\n" - + "</body></html>"; - - WebClient client = new WebClient(BrowserVersion.FIREFOX_24); - try { - final HtmlPage page1 = loadPage(client, html, new ArrayList<String>()); - Thread.sleep(1000); - page1.executeJavaScript("clearInterval(id)"); - client.waitForBackgroundJavaScript(1000); - assertTrue(page1.getElementById("d").asText().length() > 1); - } - finally { - client.closeAllWindows(); - } - - client = new WebClient(BrowserVersion.INTERNET_EXPLORER_11); - try { - final HtmlPage page2 = loadPage(client, html, new ArrayList<String>()); - client.waitForBackgroundJavaScript(1000); - assertEquals(1, page2.getElementById("d").asText().length()); - } - finally { - client.closeAllWindows(); - } - } - - /** * @throws Exception if the test fails */ @Test |
From: <rb...@us...> - 2014-04-14 19:14:40
|
Revision: 9257 http://sourceforge.net/p/htmlunit/code/9257 Author: rbri Date: 2014-04-14 19:14:35 +0000 (Mon, 14 Apr 2014) Log Message: ----------- Function evaluate now returns the correct result when called with XPathResult.BOOLEAN_TYPE as result type Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/XPathResult.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/XPathResultTest.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2014-04-13 10:28:19 UTC (rev 9256) +++ trunk/htmlunit/src/changes/changes.xml 2014-04-14 19:14:35 UTC (rev 9257) @@ -9,6 +9,10 @@ <body> <release version="2.15" date="???" description="Bugfixes"> <action type="fix" dev="rbri"> + JavaScript: Function evaluate now returns the correct result when + called with XPathResult.BOOLEAN_TYPE as result type. + </action> + <action type="fix" dev="rbri"> JavaScript: table.insertRow was broken when trying to insert a row directly before the last one. </action> Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/XPathResult.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/XPathResult.java 2014-04-13 10:28:19 UTC (rev 9256) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/XPathResult.java 2014-04-14 19:14:35 UTC (rev 9257) @@ -245,7 +245,7 @@ if (resultType_ != BOOLEAN_TYPE) { throw Context.reportRuntimeError("Cannot get booleanValue for type: " + resultType_); } - return Boolean.parseBoolean(asString()); + return result_.size() > 0; } /** Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/XPathResultTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/XPathResultTest.java 2014-04-13 10:28:19 UTC (rev 9256) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/XPathResultTest.java 2014-04-14 19:14:35 UTC (rev 9257) @@ -14,14 +14,11 @@ */ package com.gargoylesoftware.htmlunit.javascript.host; -import static com.gargoylesoftware.htmlunit.BrowserRunner.Browser.FF; - 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; /** @@ -296,17 +293,31 @@ * @throws Exception if the test fails */ @Test - @Alerts(DEFAULT = { "false", "true", "true" }, + @Alerts(DEFAULT = { "true", "true", "true", "true", "true", "true" }, IE = "evaluate not supported") - @NotYetImplemented(FF) public void booleanType() throws Exception { - final String html = "<html><head><title>foo</title><span attr=\"true\">true</span><script>\n" + final String html = "<html>\n" + + "<head>\n" + + "<title>foo</title>\n" + + "<script>\n" + " function test() {\n" + " if (document.evaluate && XPathResult) {\n" + " try {\n" + + " var result = document.evaluate('//unknown', document, null, " + + "XPathResult.BOOLEAN_TYPE, null);\n" + + " alert(result.booleanValue === false);\n" + + " var result = document.evaluate('//title', document, null, " + "XPathResult.BOOLEAN_TYPE, null);\n" - + " alert(result.booleanValue === false);\n" + + " alert(result.booleanValue === true);\n" + + + " result = document.evaluate('//div', document, null, " + + "XPathResult.BOOLEAN_TYPE, null);\n" + + " alert(result.booleanValue === true);\n" + + " result = document.evaluate('//div/@attr', document, null, " + + "XPathResult.BOOLEAN_TYPE, null);\n" + + " alert(result.booleanValue === true);\n" + + " result = document.evaluate('//span', document, null, " + "XPathResult.BOOLEAN_TYPE, null);\n" + " alert(result.booleanValue === true);\n" @@ -318,7 +329,11 @@ + " alert('evaluate not supported');\n" + " }\n" + " }\n" - + "</script></head><body onload='test()'>\n" + + "</script>\n" + + "</head>\n" + + "<body onload='test()'>\n" + + " <div attr=\"false\">false</span>" + + " <span attr=\"true\">true</span>" + "</body></html>"; loadPageWithAlerts2(html); |
From: <rb...@us...> - 2014-04-17 12:15:19
|
Revision: 9263 http://sourceforge.net/p/htmlunit/code/9263 Author: rbri Date: 2014-04-17 12:15:16 +0000 (Thu, 17 Apr 2014) Log Message: ----------- more tests migrated to webdriver; IE11 fixed Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlElementTest.java Added Paths: ----------- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlElement2Test.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2014-04-17 12:14:12 UTC (rev 9262) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2014-04-17 12:15:16 UTC (rev 9263) @@ -259,7 +259,7 @@ EVENT_ONREADY_STATE_CHANGE, /** Triggers "propertychange" event. */ - @BrowserFeature(@WebBrowser(IE)) + @BrowserFeature(@WebBrowser(value = IE, maxVersion = 8)) EVENT_PROPERTY_CHANGE, /** Supports event type 'BeforeUnloadEvent'. */ Added: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlElement2Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlElement2Test.java (rev 0) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlElement2Test.java 2014-04-17 12:15:16 UTC (rev 9263) @@ -0,0 +1,109 @@ +/* + * Copyright (c) 2002-2014 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 static com.gargoylesoftware.htmlunit.BrowserRunner.Browser.IE8; + +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 HtmlElement}. + * + * @version $Revision: 8931 $ + * @author <a href="mailto:mb...@Ga...">Mike Bowler</a> + * @author Denis N. Antonioli + * @author Daniel Gredler + * @author Ahmed Ashour + * @author Sudhan Moghe + * @author Frank Danek + * @author Ronald Brill + */ +@RunWith(BrowserRunner.class) +public class HtmlElement2Test extends WebDriverTestCase { + + /** + * @throws Exception if an error occurs + */ + @Test + @Alerts(IE8 = "value") + public void onpropertychange() throws Exception { + final String html = "<html><head><script>\n" + + " function test() {\n" + + " document.getElementById('input1').value = 'New Value';\n" + + " }\n" + + " function handler() {\n" + + " alert(event.propertyName);\n" + + " }\n" + + "</script></head>\n" + + "<body onload='test()'>\n" + + " <input id='input1' onpropertychange='handler()'>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts({ "true", "true" }) + public void duplicateId() throws Exception { + final String html + = "<html>\n" + + "<script>\n" + + " function test() {\n" + + " var value = document.getElementById('duplicateID').innerHTML;\n" + + " alert(value.length > 10);\n" + + " document.getElementById('duplicateID').style.display = 'block';\n" + + " alert(value === document.getElementById('duplicateID').innerHTML);\n" + + " }\n" + + "</script>\n" + + "</head>\n" + + "<body onload='test()'>\n" + + " <fieldset id='duplicateID'><span id='duplicateID'></span></fieldset>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if an error occurs + */ + @Test + @NotYetImplemented(IE8) + @Alerts(IE8 = { "1", "1" }) + public void onpropertychange2() throws Exception { + final String html = "<html><head><script>\n" + + " function test() {\n" + + " document.getElementById('input1').value = 'New Value';\n" + + " }\n" + + " function handler() {\n" + + " alert(1);\n" + + " document.getElementById('input1').dir='rtl';" + + " }\n" + + "</script></head>\n" + + "<body onload='test()'>\n" + + " <input id='input1' onpropertychange='handler()'>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } +} Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlElementTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlElementTest.java 2014-04-17 12:14:12 UTC (rev 9262) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlElementTest.java 2014-04-17 12:15:16 UTC (rev 9263) @@ -14,7 +14,6 @@ */ package com.gargoylesoftware.htmlunit.html; -import static com.gargoylesoftware.htmlunit.BrowserRunner.Browser.IE; import static org.junit.Assert.assertSame; import java.util.ArrayList; @@ -27,7 +26,6 @@ import com.gargoylesoftware.htmlunit.BrowserRunner; import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; -import com.gargoylesoftware.htmlunit.BrowserRunner.NotYetImplemented; import com.gargoylesoftware.htmlunit.SimpleWebTestCase; /** @@ -934,27 +932,6 @@ } /** - * @throws Exception if an error occurs - */ - @Test - @Alerts(IE = "value") - public void onpropertychange() throws Exception { - final String html = "<html><head><script>\n" - + " function test() {\n" - + " document.getElementById('input1').value = 'New Value';\n" - + " }\n" - + " function handler() {\n" - + " alert(event.propertyName);\n" - + " }\n" - + "</script></head>\n" - + "<body onload='test()'>\n" - + " <input id='input1' onpropertychange='handler()'>\n" - + "</body></html>"; - - loadPageWithAlerts(html); - } - - /** * @throws Exception if the test fails */ @Test @@ -1164,30 +1141,6 @@ } /** - * @throws Exception if the test fails - */ - @Test - @Alerts({ "true", "true" }) - public void duplicateId() throws Exception { - final String html - = "<html>\n" - + "<script>\n" - + " function test() {\n" - + " var value = document.getElementById('duplicateID').innerHTML;\n" - + " alert(value.length > 10);\n" - + " document.getElementById('duplicateID').style.display = 'block';\n" - + " alert(value === document.getElementById('duplicateID').innerHTML);\n" - + " }\n" - + "</script>\n" - + "</head>\n" - + "<body onload='test()'>\n" - + " <fieldset id='duplicateID'><span id='duplicateID'></span></fieldset>\n" - + "</body></html>"; - - loadPageWithAlerts(html); - } - - /** * @throws Exception if an error occurs */ @Test @@ -1200,29 +1153,6 @@ } /** - * @throws Exception if an error occurs - */ - @Test - @NotYetImplemented(IE) - @Alerts(IE = { "1", "1" }) - public void onpropertychange2() throws Exception { - final String html = "<html><head><script>\n" - + " function test() {\n" - + " document.getElementById('input1').value = 'New Value';\n" - + " }\n" - + " function handler() {\n" - + " alert(1);\n" - + " document.getElementById('input1').dir='rtl';" - + " }\n" - + "</script></head>\n" - + "<body onload='test()'>\n" - + " <input id='input1' onpropertychange='handler()'>\n" - + "</body></html>"; - - loadPageWithAlerts(html); - } - - /** * Ensure that we don't escape when not needed. * @throws Exception on test failure */ |
From: <rb...@us...> - 2014-04-17 19:21:21
|
Revision: 9265 http://sourceforge.net/p/htmlunit/code/9265 Author: rbri Date: 2014-04-17 19:21:14 +0000 (Thu, 17 Apr 2014) Log Message: ----------- more tests migrated to webdriver and fixed Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPasswordInput.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/impl/SelectionDelegate.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLInputElement.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlPasswordInputTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlTextArea2Test.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlTextInput2Test.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlTextInputTest.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2014-04-17 16:25:34 UTC (rev 9264) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2014-04-17 19:21:14 UTC (rev 9265) @@ -1074,6 +1074,11 @@ @BrowserFeature(@WebBrowser(CHROME)) JS_INNER_TEXT_READONLY_FOR_TABLE, + /** Setting the value of an Input Text/Password/TextArea does not change the + * selection. */ + @BrowserFeature(@WebBrowser(value = IE, minVersion = 11)) + JS_INPUT_SET_VALUE_DOES_NOT_CHANGE_SELECTION, + /** Javascript function returning a length (e.g. getWidth) without 'px' at the end. */ @BrowserFeature(@WebBrowser(value = IE, maxVersion = 10)) JS_LENGTH_WITHOUT_PX, Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPasswordInput.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPasswordInput.java 2014-04-17 16:25:34 UTC (rev 9264) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPasswordInput.java 2014-04-17 19:21:14 UTC (rev 9265) @@ -15,6 +15,7 @@ package com.gargoylesoftware.htmlunit.html; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.HTMLINPUT_SET_DEFAULT_VALUE_UPDATES_VALUE; +import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_INPUT_SET_VALUE_DOES_NOT_CHANGE_SELECTION; import java.util.Map; @@ -149,9 +150,12 @@ @Override public void setAttributeNS(final String namespaceURI, final String qualifiedName, final String attributeValue) { super.setAttributeNS(namespaceURI, qualifiedName, attributeValue); - if (null != getHtmlPageOrNull() && "value".equals(qualifiedName)) { - setSelectionStart(attributeValue.length()); - setSelectionEnd(attributeValue.length()); + if ("value".equals(qualifiedName)) { + final SgmlPage page = getPage(); + if (page != null && page.isHtmlPage() && !hasFeature(JS_INPUT_SET_VALUE_DOES_NOT_CHANGE_SELECTION)) { + setSelectionStart(attributeValue.length()); + setSelectionEnd(attributeValue.length()); + } } } Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlTextArea.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlTextArea.java 2014-04-17 16:25:34 UTC (rev 9264) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlTextArea.java 2014-04-17 19:21:14 UTC (rev 9265) @@ -16,6 +16,7 @@ import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.CSS_DISPLAY_DEFAULT; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.HTMLTEXTAREA_SET_DEFAULT_VALUE_UPDATES_VALUE; +import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_INPUT_SET_VALUE_DOES_NOT_CHANGE_SELECTION; import java.io.PrintWriter; import java.util.Collection; @@ -144,8 +145,10 @@ child.setData(newValue); } - setSelectionStart(newValue.length()); - setSelectionEnd(newValue.length()); + if (!hasFeature(JS_INPUT_SET_VALUE_DOES_NOT_CHANGE_SELECTION)) { + setSelectionStart(newValue.length()); + setSelectionEnd(newValue.length()); + } } /** @@ -394,7 +397,7 @@ printOpeningTagContentAsXml(printWriter); printWriter.print(">"); - printWriter.print(StringEscapeUtils.escapeXml(getText())); + printWriter.print(StringEscapeUtils.escapeXml10(getText())); printWriter.print("</textarea>"); } Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlTextInput.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlTextInput.java 2014-04-17 16:25:34 UTC (rev 9264) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlTextInput.java 2014-04-17 19:21:14 UTC (rev 9265) @@ -15,6 +15,7 @@ package com.gargoylesoftware.htmlunit.html; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.HTMLINPUT_SET_DEFAULT_VALUE_UPDATES_VALUE; +import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_INPUT_SET_VALUE_DOES_NOT_CHANGE_SELECTION; import java.util.Map; @@ -144,7 +145,7 @@ super.setAttributeNS(namespaceURI, qualifiedName, attributeValue); if ("value".equals(qualifiedName)) { final SgmlPage page = getPage(); - if (page != null && page.isHtmlPage()) { + if (page != null && page.isHtmlPage() && !hasFeature(JS_INPUT_SET_VALUE_DOES_NOT_CHANGE_SELECTION)) { setSelectionStart(attributeValue.length()); setSelectionEnd(attributeValue.length()); } Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/impl/SelectionDelegate.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/impl/SelectionDelegate.java 2014-04-17 16:25:34 UTC (rev 9264) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/impl/SelectionDelegate.java 2014-04-17 19:21:14 UTC (rev 9265) @@ -49,7 +49,7 @@ */ public SelectionDelegate(final SelectableTextInput element) { element_ = element; - selection_ = new SimpleRange(element, element.getText().length()); + selection_ = new SimpleRange(element, 0); } /** Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLInputElement.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLInputElement.java 2014-04-17 16:25:34 UTC (rev 9264) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLInputElement.java 2014-04-17 19:21:14 UTC (rev 9265) @@ -208,7 +208,7 @@ * Gets the value of "selectionStart" attribute. * @return the selection start */ - @JsxGetter(@WebBrowser(FF)) + @JsxGetter({ @WebBrowser(FF), @WebBrowser(value = IE, minVersion = 11) }) public int getSelectionStart() { return ((SelectableTextInput) getDomNodeOrDie()).getSelectionStart(); } @@ -217,7 +217,7 @@ * Sets the value of "selectionStart" attribute. * @param start selection start */ - @JsxSetter(@WebBrowser(FF)) + @JsxSetter({ @WebBrowser(FF), @WebBrowser(value = IE, minVersion = 11) }) public void setSelectionStart(final int start) { ((SelectableTextInput) getDomNodeOrDie()).setSelectionStart(start); } @@ -226,7 +226,7 @@ * Gets the value of "selectionEnd" attribute. * @return the selection end */ - @JsxGetter(@WebBrowser(FF)) + @JsxGetter({ @WebBrowser(FF), @WebBrowser(value = IE, minVersion = 11) }) public int getSelectionEnd() { return ((SelectableTextInput) getDomNodeOrDie()).getSelectionEnd(); } @@ -235,7 +235,7 @@ * Sets the value of "selectionEnd" attribute. * @param end selection end */ - @JsxSetter(@WebBrowser(FF)) + @JsxSetter({ @WebBrowser(FF), @WebBrowser(value = IE, minVersion = 11) }) public void setSelectionEnd(final int end) { ((SelectableTextInput) getDomNodeOrDie()).setSelectionEnd(end); } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlPasswordInputTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlPasswordInputTest.java 2014-04-17 16:25:34 UTC (rev 9264) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlPasswordInputTest.java 2014-04-17 19:21:14 UTC (rev 9265) @@ -33,6 +33,7 @@ * * @version $Revision$ * @author Ahmed Ashour + * @author Ronald Brill */ @RunWith(BrowserRunner.class) public class HtmlPasswordInputTest extends WebDriverTestCase { @@ -336,4 +337,108 @@ loadPageWithAlerts2(html); } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = { "7" }, + IE = { "textLength not available" }) + public void textLength() throws Exception { + final String html = "<html><head><title>foo</title>\n" + + "<script>\n" + + " function test() {\n" + + " var text = document.getElementById('testId');\n" + + " if(text.textLength) {\n" + + " alert(text.textLength);\n" + + " } else {\n" + + " alert('textLength not available');\n" + + " }\n" + + " }\n" + + "</script>\n" + + "</head><body onload='test()'>\n" + + "<form>\n" + + " <input type='password' id='testId' value='initial'>\n" + + "</form>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if an error occurs + */ + @Test + @Alerts("0") + public void selection() throws Exception { + final String html = + "<html><head><script>\n" + + " function test() {\n" + + " alert(getSelection(document.getElementById('text1')).length);\n" + + " }\n" + + " function getSelection(element) {\n" + + " if (typeof element.selectionStart == 'number') {\n" + + " return element.value.substring(element.selectionStart, element.selectionEnd);\n" + + " } else if (document.selection && document.selection.createRange) {\n" + + " return document.selection.createRange().text;\n" + + " }\n" + + " }\n" + + "</script></head>\n" + + "<body onload='test()'>\n" + + " <input type='password' id='text1'/>\n" + + "</body></html>"; + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if test fails + */ + @Test + @Alerts(DEFAULT = { "0,0", "11,11", "3,11", "3,10" }, + IE11 = { "0,0", "0,0", "3,3", "3,10" }, + IE8 = { "undefined,undefined", "undefined,undefined", "3,undefined", "3,10" }) + public void selection2_1() throws Exception { + selection2(3, 10); + } + + /** + * @throws Exception if test fails + */ + @Test + @Alerts(DEFAULT = { "0,0", "11,11", "0,11", "0,11" }, + IE11 = { "0,0", "0,0", "0,0", "0,11" }, + IE8 = { "undefined,undefined", "undefined,undefined", "-3,undefined", "-3,15" }) + public void selection2_2() throws Exception { + selection2(-3, 15); + } + + /** + * @throws Exception if test fails + */ + @Test + @Alerts(DEFAULT = { "0,0", "11,11", "10,11", "5,5" }, + IE11 = { "0,0", "0,0", "10,10", "5,5" }, + IE = { "undefined,undefined", "undefined,undefined", "10,undefined", "10,5" }) + public void selection2_3() throws Exception { + selection2(10, 5); + } + + private void selection2(final int selectionStart, final int selectionEnd) throws Exception { + final String html = "<html>\n" + + "<body>\n" + + "<input id='myTextInput' value='Bonjour' type='password'>\n" + + "<script>\n" + + " var input = document.getElementById('myTextInput');\n" + + " alert(input.selectionStart + ',' + input.selectionEnd);\n" + + " input.value = 'Hello there';\n" + + " alert(input.selectionStart + ',' + input.selectionEnd);\n" + + " input.selectionStart = " + selectionStart + ";\n" + + " alert(input.selectionStart + ',' + input.selectionEnd);\n" + + " input.selectionEnd = " + selectionEnd + ";\n" + + " alert(input.selectionStart + ',' + input.selectionEnd);\n" + + "</script>\n" + + "</body>\n" + + "</html>"; + loadPageWithAlerts2(html); + } } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlTextArea2Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlTextArea2Test.java 2014-04-17 16:25:34 UTC (rev 9264) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlTextArea2Test.java 2014-04-17 19:21:14 UTC (rev 9265) @@ -135,4 +135,108 @@ loadPageWithAlerts2(html); } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = { "7" }, + IE = { "textLength not available" }) + public void textLength() throws Exception { + final String html = "<html><head><title>foo</title>\n" + + "<script>\n" + + " function test() {\n" + + " var text = document.getElementById('testId');\n" + + " if(text.textLength) {\n" + + " alert(text.textLength);\n" + + " } else {\n" + + " alert('textLength not available');\n" + + " }\n" + + " }\n" + + "</script>\n" + + "</head><body onload='test()'>\n" + + "<form>\n" + + " <textarea id='testId'>initial</textarea>\n" + + "</form>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if an error occurs + */ + @Test + @Alerts("0") + public void selection() throws Exception { + final String html = + "<html><head><script>\n" + + " function test() {\n" + + " alert(getSelection(document.getElementById('text1')).length);\n" + + " }\n" + + " function getSelection(element) {\n" + + " if (typeof element.selectionStart == 'number') {\n" + + " return element.value.substring(element.selectionStart, element.selectionEnd);\n" + + " } else if (document.selection && document.selection.createRange) {\n" + + " return document.selection.createRange().text;\n" + + " }\n" + + " }\n" + + "</script></head>\n" + + "<body onload='test()'>\n" + + " <textarea id='text1'></textarea>\n" + + "</body></html>"; + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if test fails + */ + @Test + @Alerts(DEFAULT = { "0,0", "11,11", "3,11", "3,10" }, + IE11 = { "0,0", "0,0", "3,3", "3,10" }, + IE8 = { "undefined,undefined", "undefined,undefined", "3,undefined", "3,10" }) + public void selection2_1() throws Exception { + selection2(3, 10); + } + + /** + * @throws Exception if test fails + */ + @Test + @Alerts(DEFAULT = { "0,0", "11,11", "0,11", "0,11" }, + IE11 = { "0,0", "0,0", "0,0", "0,11" }, + IE8 = { "undefined,undefined", "undefined,undefined", "-3,undefined", "-3,15" }) + public void selection2_2() throws Exception { + selection2(-3, 15); + } + + /** + * @throws Exception if test fails + */ + @Test + @Alerts(DEFAULT = { "0,0", "11,11", "10,11", "5,5" }, + IE11 = { "0,0", "0,0", "10,10", "5,5" }, + IE = { "undefined,undefined", "undefined,undefined", "10,undefined", "10,5" }) + public void selection2_3() throws Exception { + selection2(10, 5); + } + + private void selection2(final int selectionStart, final int selectionEnd) throws Exception { + final String html = "<html>\n" + + "<body>\n" + + "<textarea id='myTextInput'>Bonjour</textarea>\n" + + "<script>\n" + + " var input = document.getElementById('myTextInput');\n" + + " alert(input.selectionStart + ',' + input.selectionEnd);\n" + + " input.value = 'Hello there';\n" + + " alert(input.selectionStart + ',' + input.selectionEnd);\n" + + " input.selectionStart = " + selectionStart + ";\n" + + " alert(input.selectionStart + ',' + input.selectionEnd);\n" + + " input.selectionEnd = " + selectionEnd + ";\n" + + " alert(input.selectionStart + ',' + input.selectionEnd);\n" + + "</script>\n" + + "</body>\n" + + "</html>"; + loadPageWithAlerts2(html); + } } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlTextInput2Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlTextInput2Test.java 2014-04-17 16:25:34 UTC (rev 9264) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlTextInput2Test.java 2014-04-17 19:21:14 UTC (rev 9265) @@ -202,4 +202,108 @@ loadPageWithAlerts2(html); } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = { "7" }, + IE = { "textLength not available" }) + public void textLength() throws Exception { + final String html = "<html><head><title>foo</title>\n" + + "<script>\n" + + " function test() {\n" + + " var text = document.getElementById('testId');\n" + + " if(text.textLength) {\n" + + " alert(text.textLength);\n" + + " } else {\n" + + " alert('textLength not available');\n" + + " }\n" + + " }\n" + + "</script>\n" + + "</head><body onload='test()'>\n" + + "<form>\n" + + " <input type='text' id='testId' value='initial'>\n" + + "</form>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if an error occurs + */ + @Test + @Alerts("0") + public void selection() throws Exception { + final String html = + "<html><head><script>\n" + + " function test() {\n" + + " alert(getSelection(document.getElementById('text1')).length);\n" + + " }\n" + + " function getSelection(element) {\n" + + " if (typeof element.selectionStart == 'number') {\n" + + " return element.value.substring(element.selectionStart, element.selectionEnd);\n" + + " } else if (document.selection && document.selection.createRange) {\n" + + " return document.selection.createRange().text;\n" + + " }\n" + + " }\n" + + "</script></head>\n" + + "<body onload='test()'>\n" + + " <input type='text' id='text1'/>\n" + + "</body></html>"; + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if test fails + */ + @Test + @Alerts(DEFAULT = { "0,0", "11,11", "3,11", "3,10" }, + IE11 = { "0,0", "0,0", "3,3", "3,10" }, + IE8 = { "undefined,undefined", "undefined,undefined", "3,undefined", "3,10" }) + public void selection2_1() throws Exception { + selection2(3, 10); + } + + /** + * @throws Exception if test fails + */ + @Test + @Alerts(DEFAULT = { "0,0", "11,11", "0,11", "0,11" }, + IE11 = { "0,0", "0,0", "0,0", "0,11" }, + IE8 = { "undefined,undefined", "undefined,undefined", "-3,undefined", "-3,15" }) + public void selection2_2() throws Exception { + selection2(-3, 15); + } + + /** + * @throws Exception if test fails + */ + @Test + @Alerts(DEFAULT = { "0,0", "11,11", "10,11", "5,5" }, + IE11 = { "0,0", "0,0", "10,10", "5,5" }, + IE = { "undefined,undefined", "undefined,undefined", "10,undefined", "10,5" }) + public void selection2_3() throws Exception { + selection2(10, 5); + } + + private void selection2(final int selectionStart, final int selectionEnd) throws Exception { + final String html = "<html>\n" + + "<body>\n" + + "<input id='myTextInput' value='Bonjour' type='text'>\n" + + "<script>\n" + + " var input = document.getElementById('myTextInput');\n" + + " alert(input.selectionStart + ',' + input.selectionEnd);\n" + + " input.value = 'Hello there';\n" + + " alert(input.selectionStart + ',' + input.selectionEnd);\n" + + " input.selectionStart = " + selectionStart + ";\n" + + " alert(input.selectionStart + ',' + input.selectionEnd);\n" + + " input.selectionEnd = " + selectionEnd + ";\n" + + " alert(input.selectionStart + ',' + input.selectionEnd);\n" + + "</script>\n" + + "</body>\n" + + "</html>"; + loadPageWithAlerts2(html); + } } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlTextInputTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlTextInputTest.java 2014-04-17 16:25:34 UTC (rev 9264) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlTextInputTest.java 2014-04-17 19:21:14 UTC (rev 9265) @@ -21,7 +21,6 @@ import org.junit.runner.RunWith; import com.gargoylesoftware.htmlunit.BrowserRunner; -import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; import com.gargoylesoftware.htmlunit.BrowserRunner.Browsers; import com.gargoylesoftware.htmlunit.MockWebConnection; import com.gargoylesoftware.htmlunit.SimpleWebTestCase; @@ -34,7 +33,8 @@ * @author Ahmed Ashour * @author Marc Guillemot * @author Sudhan Moghe - */ + * @author Ronald Brill +*/ @RunWith(BrowserRunner.class) public class HtmlTextInputTest extends SimpleWebTestCase { @@ -163,83 +163,6 @@ * @throws Exception if an error occurs */ @Test - @Alerts("0") - public void selection() throws Exception { - final String html = - "<html><head><script>\n" - + " function test() {\n" - + " alert(getSelection(document.getElementById('text1')).length);\n" - + " }\n" - + " function getSelection(element) {\n" - + " if (typeof element.selectionStart == 'number') {\n" - + " return element.value.substring(element.selectionStart, element.selectionEnd);\n" - + " } else if (document.selection && document.selection.createRange) {\n" - + " return document.selection.createRange().text;\n" - + " }\n" - + " }\n" - + "</script></head>\n" - + "<body onload='test()'>\n" - + "<input id='text1'/>\n" - + "</body></html>"; - loadPageWithAlerts(html); - } - - /** - * @throws Exception if test fails - */ - @Test - @Alerts(IE = { "undefined,undefined", "undefined,undefined", "3,undefined", "3,10" }, - FF = { "7,7", "11,11", "3,11", "3,10" }) - public void selection2_1() throws Exception { - selection2("text", 3, 10); - selection2("password", 3, 10); - } - - /** - * @throws Exception if test fails - */ - @Test - @Alerts(IE = { "undefined,undefined", "undefined,undefined", "-3,undefined", "-3,15" }, - FF = { "7,7", "11,11", "0,11", "0,11" }) - public void selection2_2() throws Exception { - selection2("text", -3, 15); - selection2("password", -3, 15); - } - - /** - * @throws Exception if test fails - */ - @Test - @Alerts(IE = { "undefined,undefined", "undefined,undefined", "10,undefined", "10,5" }, - FF = { "7,7", "11,11", "10,11", "5,5" }) - public void selection2_3() throws Exception { - selection2("text", 10, 5); - selection2("password", 10, 5); - } - - private void selection2(final String type, final int selectionStart, final int selectionEnd) throws Exception { - final String html = "<html>\n" - + "<body>\n" - + "<input id='myTextInput' value='Bonjour' type='" + type + "'>\n" - + "<script>\n" - + " var input = document.getElementById('myTextInput');\n" - + " alert(input.selectionStart + ',' + input.selectionEnd);\n" - + " input.value = 'Hello there';\n" - + " alert(input.selectionStart + ',' + input.selectionEnd);\n" - + " input.selectionStart = " + selectionStart + ";\n" - + " alert(input.selectionStart + ',' + input.selectionEnd);\n" - + " input.selectionEnd = " + selectionEnd + ";\n" - + " alert(input.selectionStart + ',' + input.selectionEnd);\n" - + "</script>\n" - + "</body>\n" - + "</html>"; - loadPageWithAlerts(html); - } - - /** - * @throws Exception if an error occurs - */ - @Test @Browsers(IE) public void setSelectionText() throws Exception { final String html = |
From: <rb...@us...> - 2014-04-18 09:09:03
|
Revision: 9267 http://sourceforge.net/p/htmlunit/code/9267 Author: rbri Date: 2014-04-18 09:08:58 +0000 (Fri, 18 Apr 2014) Log Message: ----------- one more selection test and fix Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPasswordInput.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/test/java/com/gargoylesoftware/htmlunit/html/HtmlPasswordInputTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlTextArea2Test.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlTextInput2Test.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2014-04-18 08:41:17 UTC (rev 9266) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2014-04-18 09:08:58 UTC (rev 9267) @@ -1074,10 +1074,9 @@ @BrowserFeature(@WebBrowser(CHROME)) JS_INNER_TEXT_READONLY_FOR_TABLE, - /** Setting the value of an Input Text/Password/TextArea does not change the - * selection. */ + /** Setting the value of an Input Text/Password/TextArea resets the selection. */ @BrowserFeature(@WebBrowser(value = IE, minVersion = 11)) - JS_INPUT_SET_VALUE_DOES_NOT_CHANGE_SELECTION, + JS_INPUT_SET_VALUE_MOVE_SELECTION_TO_START, /** Javascript function returning a length (e.g. getWidth) without 'px' at the end. */ @BrowserFeature(@WebBrowser(value = IE, maxVersion = 10)) Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPasswordInput.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPasswordInput.java 2014-04-18 08:41:17 UTC (rev 9266) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPasswordInput.java 2014-04-18 09:08:58 UTC (rev 9267) @@ -15,7 +15,7 @@ package com.gargoylesoftware.htmlunit.html; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.HTMLINPUT_SET_DEFAULT_VALUE_UPDATES_VALUE; -import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_INPUT_SET_VALUE_DOES_NOT_CHANGE_SELECTION; +import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_INPUT_SET_VALUE_MOVE_SELECTION_TO_START; import java.util.Map; @@ -152,9 +152,13 @@ super.setAttributeNS(namespaceURI, qualifiedName, attributeValue); if ("value".equals(qualifiedName)) { final SgmlPage page = getPage(); - if (page != null && page.isHtmlPage() && !hasFeature(JS_INPUT_SET_VALUE_DOES_NOT_CHANGE_SELECTION)) { - setSelectionStart(attributeValue.length()); - setSelectionEnd(attributeValue.length()); + if (page != null && page.isHtmlPage()) { + int pos = 0; + if (!hasFeature(JS_INPUT_SET_VALUE_MOVE_SELECTION_TO_START)) { + pos = attributeValue.length(); + } + setSelectionStart(pos); + setSelectionEnd(pos); } } } Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlTextArea.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlTextArea.java 2014-04-18 08:41:17 UTC (rev 9266) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlTextArea.java 2014-04-18 09:08:58 UTC (rev 9267) @@ -16,7 +16,7 @@ import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.CSS_DISPLAY_DEFAULT; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.HTMLTEXTAREA_SET_DEFAULT_VALUE_UPDATES_VALUE; -import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_INPUT_SET_VALUE_DOES_NOT_CHANGE_SELECTION; +import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_INPUT_SET_VALUE_MOVE_SELECTION_TO_START; import java.io.PrintWriter; import java.util.Collection; @@ -145,10 +145,12 @@ child.setData(newValue); } - if (!hasFeature(JS_INPUT_SET_VALUE_DOES_NOT_CHANGE_SELECTION)) { - setSelectionStart(newValue.length()); - setSelectionEnd(newValue.length()); + int pos = 0; + if (!hasFeature(JS_INPUT_SET_VALUE_MOVE_SELECTION_TO_START)) { + pos = newValue.length(); } + setSelectionStart(pos); + setSelectionEnd(pos); } /** Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlTextInput.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlTextInput.java 2014-04-18 08:41:17 UTC (rev 9266) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlTextInput.java 2014-04-18 09:08:58 UTC (rev 9267) @@ -15,7 +15,7 @@ package com.gargoylesoftware.htmlunit.html; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.HTMLINPUT_SET_DEFAULT_VALUE_UPDATES_VALUE; -import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_INPUT_SET_VALUE_DOES_NOT_CHANGE_SELECTION; +import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_INPUT_SET_VALUE_MOVE_SELECTION_TO_START; import java.util.Map; @@ -145,9 +145,13 @@ super.setAttributeNS(namespaceURI, qualifiedName, attributeValue); if ("value".equals(qualifiedName)) { final SgmlPage page = getPage(); - if (page != null && page.isHtmlPage() && !hasFeature(JS_INPUT_SET_VALUE_DOES_NOT_CHANGE_SELECTION)) { - setSelectionStart(attributeValue.length()); - setSelectionEnd(attributeValue.length()); + if (page != null && page.isHtmlPage()) { + int pos = 0; + if (!hasFeature(JS_INPUT_SET_VALUE_MOVE_SELECTION_TO_START)) { + pos = attributeValue.length(); + } + setSelectionStart(pos); + setSelectionEnd(pos); } } } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlPasswordInputTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlPasswordInputTest.java 2014-04-18 08:41:17 UTC (rev 9266) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlPasswordInputTest.java 2014-04-18 09:08:58 UTC (rev 9267) @@ -441,4 +441,39 @@ + "</html>"; loadPageWithAlerts2(html); } + + /** + * @throws Exception if test fails + */ + @Test + @Alerts(DEFAULT = { "0,0", "4,5", "10,10", "4,4", "1,1" }, + IE11 = { "0,0", "4,5", "0,0", "0,0", "0,0" }, + IE8 = { "undefined,undefined", "4,5", "4,5", "4,5", "0,4" }) + public void selectionOnUpdate() throws Exception { + final String html = "<html>\n" + + "<body>\n" + + "<input id='myTextInput' value='Hello' type='password'>\n" + + "<script>\n" + + " var input = document.getElementById('myTextInput');\n" + + " alert(input.selectionStart + ',' + input.selectionEnd);\n" + + + " input.selectionStart = 4;\n" + + " input.selectionEnd = 5;\n" + + " alert(input.selectionStart + ',' + input.selectionEnd);\n" + + " input.value = 'abcdefghif';\n" + + " alert(input.selectionStart + ',' + input.selectionEnd);\n" + + + " input.value = 'abcd';\n" + + " alert(input.selectionStart + ',' + input.selectionEnd);\n" + + + " input.selectionStart = 0;\n" + + " input.selectionEnd = 4;\n" + + + " input.value = 'a';\n" + + " alert(input.selectionStart + ',' + input.selectionEnd);\n" + + "</script>\n" + + "</body>\n" + + "</html>"; + loadPageWithAlerts2(html); + } } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlTextArea2Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlTextArea2Test.java 2014-04-18 08:41:17 UTC (rev 9266) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlTextArea2Test.java 2014-04-18 09:08:58 UTC (rev 9267) @@ -239,4 +239,39 @@ + "</html>"; loadPageWithAlerts2(html); } + + /** + * @throws Exception if test fails + */ + @Test + @Alerts(DEFAULT = { "0,0", "4,5", "10,10", "4,4", "1,1" }, + IE11 = { "0,0", "4,5", "0,0", "0,0", "0,0" }, + IE8 = { "undefined,undefined", "4,5", "4,5", "4,5", "0,4" }) + public void selectionOnUpdate() throws Exception { + final String html = "<html>\n" + + "<body>\n" + + "<textarea id='myTextInput'>Hello</textarea>\n" + + "<script>\n" + + " var input = document.getElementById('myTextInput');\n" + + " alert(input.selectionStart + ',' + input.selectionEnd);\n" + + + " input.selectionStart = 4;\n" + + " input.selectionEnd = 5;\n" + + " alert(input.selectionStart + ',' + input.selectionEnd);\n" + + " input.value = 'abcdefghif';\n" + + " alert(input.selectionStart + ',' + input.selectionEnd);\n" + + + " input.value = 'abcd';\n" + + " alert(input.selectionStart + ',' + input.selectionEnd);\n" + + + " input.selectionStart = 0;\n" + + " input.selectionEnd = 4;\n" + + + " input.value = 'a';\n" + + " alert(input.selectionStart + ',' + input.selectionEnd);\n" + + "</script>\n" + + "</body>\n" + + "</html>"; + loadPageWithAlerts2(html); + } } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlTextInput2Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlTextInput2Test.java 2014-04-18 08:41:17 UTC (rev 9266) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlTextInput2Test.java 2014-04-18 09:08:58 UTC (rev 9267) @@ -306,4 +306,39 @@ + "</html>"; loadPageWithAlerts2(html); } + + /** + * @throws Exception if test fails + */ + @Test + @Alerts(DEFAULT = { "0,0", "4,5", "10,10", "4,4", "1,1" }, + IE11 = { "0,0", "4,5", "0,0", "0,0", "0,0" }, + IE8 = { "undefined,undefined", "4,5", "4,5", "4,5", "0,4" }) + public void selectionOnUpdate() throws Exception { + final String html = "<html>\n" + + "<body>\n" + + "<input id='myTextInput' value='Hello' type='text'>\n" + + "<script>\n" + + " var input = document.getElementById('myTextInput');\n" + + " alert(input.selectionStart + ',' + input.selectionEnd);\n" + + + " input.selectionStart = 4;\n" + + " input.selectionEnd = 5;\n" + + " alert(input.selectionStart + ',' + input.selectionEnd);\n" + + " input.value = 'abcdefghif';\n" + + " alert(input.selectionStart + ',' + input.selectionEnd);\n" + + + " input.value = 'abcd';\n" + + " alert(input.selectionStart + ',' + input.selectionEnd);\n" + + + " input.selectionStart = 0;\n" + + " input.selectionEnd = 4;\n" + + + " input.value = 'a';\n" + + " alert(input.selectionStart + ',' + input.selectionEnd);\n" + + "</script>\n" + + "</body>\n" + + "</html>"; + loadPageWithAlerts2(html); + } } |
From: <rb...@us...> - 2014-04-18 13:15:48
|
Revision: 9269 http://sourceforge.net/p/htmlunit/code/9269 Author: rbri Date: 2014-04-18 13:15:43 +0000 (Fri, 18 Apr 2014) Log Message: ----------- test migrated to webdriver; fixed and a new test added Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Enumerator.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/EnumeratorTest.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2014-04-18 09:26:05 UTC (rev 9268) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2014-04-18 13:15:43 UTC (rev 9269) @@ -926,6 +926,11 @@ @BrowserFeature(@WebBrowser(value = IE, maxVersion = 9)) JS_ELEMENT_REMOVE_ATTRIBUTE_REMOVES_PROPERTY, + /** The Enumerator constructor throws an exception if called with HtmlCollections + * as parameter. */ + @BrowserFeature(@WebBrowser(value = IE, minVersion = 11)) + JS_ENUMERATOR_CONSTRUCTOR_THROWS, + /** Indicates that for(x in y) should enumerate the numbers first. */ @BrowserFeature({ @WebBrowser(value = FF, minVersion = 24), @WebBrowser(CHROME), @WebBrowser(value = IE, minVersion = 9) }) Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Enumerator.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Enumerator.java 2014-04-18 09:26:05 UTC (rev 9268) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Enumerator.java 2014-04-18 13:15:43 UTC (rev 9269) @@ -14,7 +14,9 @@ */ package com.gargoylesoftware.htmlunit.javascript.host; +import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_ENUMERATOR_CONSTRUCTOR_THROWS; import static com.gargoylesoftware.htmlunit.javascript.configuration.BrowserName.IE; +import net.sourceforge.htmlunit.corejs.javascript.Context; import net.sourceforge.htmlunit.corejs.javascript.Undefined; import com.gargoylesoftware.htmlunit.javascript.SimpleScriptable; @@ -52,14 +54,20 @@ */ @JsxConstructor public void jsConstructor(final Object o) { - if (o instanceof HTMLCollection) { + if (Undefined.instance == o) { + collection_ = HTMLCollection.emptyCollection(getWindow()); + } + else if (getBrowserVersion().hasFeature(JS_ENUMERATOR_CONSTRUCTOR_THROWS)) { + throw Context.reportRuntimeError("TypeError: object is not enumerable"); + } + else if (o instanceof HTMLCollection) { collection_ = (HTMLCollection) o; } else if (o instanceof HTMLFormElement) { collection_ = ((HTMLFormElement) o).getElements(); } else { - throw new IllegalArgumentException(String.valueOf(o)); + throw Context.reportRuntimeError("TypeError: object is not enumerable (" + String.valueOf(o) + ")"); } } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/EnumeratorTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/EnumeratorTest.java 2014-04-18 09:26:05 UTC (rev 9268) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/EnumeratorTest.java 2014-04-18 13:15:43 UTC (rev 9269) @@ -14,15 +14,12 @@ */ package com.gargoylesoftware.htmlunit.javascript.host; -import static com.gargoylesoftware.htmlunit.BrowserRunner.Browser.IE; - 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.Browsers; -import com.gargoylesoftware.htmlunit.SimpleWebTestCase; +import com.gargoylesoftware.htmlunit.WebDriverTestCase; /** * Tests for {@link Enumerator}. @@ -30,73 +27,161 @@ * @version $Revision$ * @author Ahmed Ashour * @author Frank Danek + * @author Ronald Brill */ @RunWith(BrowserRunner.class) -public class EnumeratorTest extends SimpleWebTestCase { +public class EnumeratorTest extends WebDriverTestCase { /** * @throws Exception if the test fails */ @Test - @Browsers(IE) - @Alerts(IE = { "false", "[object]", "undefined", "undefined", "true" }, - IE11 = { "false", "[object HTMLFormElement]", "undefined", "undefined", "true" }) + @Alerts(DEFAULT = "Enumerator not supported", + IE = { "true", "undefined", "undefined", "undefined", "true" }) + public void basicEmptyEnumerator() throws Exception { + final String html + = "<html><head><script>\n" + + "function test() {\n" + + " if (typeof(Enumerator) != 'undefined') {\n" + + " try {\n" + + " var en = new Enumerator();\n" + + " alert(en.atEnd());\n" + + " alert(en.item());\n" + + " alert(en.moveNext());\n" + + " alert(en.item());\n" + + " alert(en.atEnd());\n" + + " } catch(e) { alert('exception'); }" + + " } else {\n" + + " alert('Enumerator not supported');\n" + + " }\n" + + "}\n" + + "</script></head>\n" + + "<body onload='test()'>\n" + + " <form/>\n" + + "</body></html>"; + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = "Enumerator not supported", + IE = { "false", "[object]", "undefined", "undefined", "true" }, + IE11 = { "exception" }) public void basicEnumerator() throws Exception { final String html = "<html><head><script>\n" + "function test() {\n" - + " var en = new Enumerator(document.forms);\n" - + " alert(en.atEnd());\n" - + " alert(en.item());\n" - + " alert(en.moveNext());\n" - + " alert(en.item());\n" - + " alert(en.atEnd());\n" + + " if (typeof(Enumerator) != 'undefined') {\n" + + " try {\n" + + " var en = new Enumerator(document.forms);\n" + + " alert(en.atEnd());\n" + + " alert(en.item());\n" + + " alert(en.moveNext());\n" + + " alert(en.item());\n" + + " alert(en.atEnd());\n" + + " } catch(e) { alert('exception'); }" + + " } else {\n" + + " alert('Enumerator not supported');\n" + + " }\n" + "}\n" - + "</script></head><body onload='test()'>\n" + + "</script></head>\n" + + "<body onload='test()'>\n" + " <form/>\n" + "</body></html>"; - loadPageWithAlerts(html); + loadPageWithAlerts2(html); } /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = "Enumerator not supported", + IE = { "exception" }) + public void basicEnumeratorWrongType() throws Exception { + final String html + = "<html><head><script>\n" + + "function test() {\n" + + " if (typeof(Enumerator) != 'undefined') {\n" + + " try {\n" + + " var en = new Enumerator(window);\n" + + " } catch(e) { alert('exception'); }" + + " } else {\n" + + " alert('Enumerator not supported');\n" + + " }\n" + + "}\n" + + "</script></head>\n" + + "<body onload='test()'>\n" + + " <form/>\n" + + "</body></html>"; + loadPageWithAlerts2(html); + } + + /** * Verifies that the enumerator constructor can take a form argument and then enumerate over the * form's input elements (bug 2645480). * @throws Exception if an error occurs */ @Test - @Browsers(IE) - @Alerts({ "f t1 t2", "t1", "t2" }) + @Alerts(DEFAULT = { "f t1 t2", "Enumerator not supported" }, + IE = { "f t1 t2", "t1", "t2" }, + IE11 = { "f t1 t2", "exception" }) public void formEnumerator() throws Exception { final String html - = "<html><body><form id='f'><input type='text' name='t1' id='t1' />\n" - + "<input type='text' name='t2' id='t2' /><div id='d'>d</div></form><script>\n" - + "var f = document.forms.f, t1 = document.all.t1, t2 = document.all.t2;\n" - + "alert(f.id + ' ' + t1.id + ' ' + t2.id);\n" - + "var e = new Enumerator(f);\n" - + "for( ; !e.atEnd(); e.moveNext()) alert(e.item().id);\n" - + "</script></body></html>"; - loadPageWithAlerts(html); + = "<html>\n" + + "<body>\n" + + " <form id='f'>\n" + + " <input type='text' name='t1' id='t1' />\n" + + " <input type='text' name='t2' id='t2' />\n" + + " <div id='d'>d</div>\n" + + " </form>\n" + + "<script>\n" + + " var f = document.forms.f, t1 = document.all.t1, t2 = document.all.t2;\n" + + " alert(f.id + ' ' + t1.id + ' ' + t2.id);\n" + + " if (typeof(Enumerator) != 'undefined') {\n" + + " try {\n" + + " var e = new Enumerator(f);\n" + + " for( ; !e.atEnd(); e.moveNext()) {\n" + + " alert(e.item().id);\n" + + " }\n" + + " } catch(e) { alert('exception'); }" + + " } else {\n" + + " alert('Enumerator not supported');\n" + + " }\n" + + "</script>\n" + + "</body></html>"; + loadPageWithAlerts2(html); } /** * @throws Exception if the test fails */ @Test - @Browsers(IE) - @Alerts({ "undefined", "text" }) + @Alerts(DEFAULT = { "undefined", "Enumerator not supported" }, + IE = { "undefined", "text" }, + IE11 = { "undefined", "exception" }) public void item() throws Exception { final String html - = "<html><head><script>\n" + = "<html><head>\n" + + "<script>\n" + "function test() {\n" + " var form = document.forms.myForm;\n" + " alert(form.elements.item(0).TyPe);\n" - + " alert(new Enumerator(form).item().TyPe);\n" + + " if (typeof(Enumerator) != 'undefined') {\n" + + " try {\n" + + " alert(new Enumerator(form).item().TyPe);\n" + + " } catch(e) { alert('exception'); }" + + " } else {\n" + + " alert('Enumerator not supported');\n" + + " }\n" + "}\n" - + "</script></head><body onload='test()'>\n" + + "</script></head>\n" + + "<body onload='test()'>\n" + " <form name='myForm'>\n" + " <input name='myInput'>\n" + " </form>\n" + "</body></html>"; - loadPageWithAlerts(html); + loadPageWithAlerts2(html); } } |
From: <rb...@us...> - 2014-04-20 08:07:08
|
Revision: 9294 http://sourceforge.net/p/htmlunit/code/9294 Author: rbri Date: 2014-04-20 08:07:01 +0000 (Sun, 20 Apr 2014) Log Message: ----------- HtmlButton.getAttribute("type") now returns the correct value if no type was specified; test migrated and fixed Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlButton.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlButton2Test.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlButtonTest.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2014-04-19 19:50:46 UTC (rev 9293) +++ trunk/htmlunit/src/changes/changes.xml 2014-04-20 08:07:01 UTC (rev 9294) @@ -9,6 +9,9 @@ <body> <release version="2.15" date="???" description="Bugfixes"> <action type="fix" dev="rbri"> + HtmlButton.getAttribute("type") now returns the correct value if no type was specified. + </action> + <action type="fix" dev="rbri"> JavaScript: Function evaluate now returns the correct result when called with XPathResult.BOOLEAN_TYPE as result type. </action> Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlButton.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlButton.java 2014-04-19 19:50:46 UTC (rev 9293) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlButton.java 2014-04-20 08:07:01 UTC (rev 9294) @@ -201,17 +201,18 @@ } /** - * Returns the value of the attribute "type". Refer to the - * <a href='http://www.w3.org/TR/html401/'>HTML 4.01</a> - * documentation for details on the use of this attribute. Note that Internet - * Explorer doesn't follow the spec when the type isn't specified. It will return - * "button" rather than the "submit" specified in the spec. + * Overwritten, because Internet Explorer doesn't follow the spec + * when the type isn't specified. It will return + * button" rather than the "submit" specified in the spec. * - * @return the value of the attribute "type" or the default value if that attribute isn't defined + * @param attributeName the name of the attribute + * @return the value of the attribute or {@link #ATTRIBUTE_NOT_DEFINED} or {@link #ATTRIBUTE_VALUE_EMPTY} */ - public final String getTypeAttribute() { - String type = getAttribute("type"); - if (type == DomElement.ATTRIBUTE_NOT_DEFINED) { + @Override + public String getAttribute(final String attributeName) { + String type = super.getAttribute(attributeName); + + if (type == DomElement.ATTRIBUTE_NOT_DEFINED && "type".equalsIgnoreCase(attributeName)) { if (hasFeature(BUTTON_EMPTY_TYPE_BUTTON)) { type = "button"; } @@ -223,6 +224,17 @@ } /** + * Returns the value of the attribute "type". Refer to the + * <a href='http://www.w3.org/TR/html401/'>HTML 4.01</a> + * documentation for details on the use of this attribute. + * + * @return the value of the attribute "type" or the default value if that attribute isn't defined + */ + public final String getTypeAttribute() { + return getAttribute("type"); + } + + /** * Returns the value of the attribute "disabled". Refer to the * <a href='http://www.w3.org/TR/html401/'>HTML 4.01</a> * documentation for details on the use of this attribute. Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlButton2Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlButton2Test.java 2014-04-19 19:50:46 UTC (rev 9293) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlButton2Test.java 2014-04-20 08:07:01 UTC (rev 9294) @@ -16,15 +16,20 @@ import static com.gargoylesoftware.htmlunit.BrowserRunner.Browser.IE8; +import java.util.List; + import org.junit.Test; import org.junit.runner.RunWith; +import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; import org.openqa.selenium.htmlunit.HtmlUnitDriver; import com.gargoylesoftware.htmlunit.BrowserRunner; import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; import com.gargoylesoftware.htmlunit.BrowserRunner.NotYetImplemented; import com.gargoylesoftware.htmlunit.WebDriverTestCase; +import com.gargoylesoftware.htmlunit.util.NameValuePair; /** * Tests for {@link HtmlButton}. @@ -324,4 +329,40 @@ loadPageWithAlerts2(html); } + + /** + * According to the HTML spec, the default type for a button is "submit". + * IE is different than the HTML spec and has a default type of "button". + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = { "submit", "1", "button-pushme", "Second" }, + IE8 = { "button", "0", "", "First" }) + public void defaultButtonType_StandardsCompliantBrowser() throws Exception { + final String firstContent + = "<html><head><title>First</title></head><body>\n" + + "<form id='form1' action='" + URL_SECOND + "' method='post'>\n" + + " <button name='button' id='button' value='pushme'>PushMe</button>\n" + + "</form></body></html>"; + final String secondContent + = "<html><head><title>Second</title></head><body'></body></html>"; + + getMockWebConnection().setResponse(URL_FIRST, firstContent); + getMockWebConnection().setResponse(URL_SECOND, secondContent); + + final WebDriver driver = loadPage2(firstContent); + final WebElement button = driver.findElement(By.id("button")); + + assertEquals(getExpectedAlerts()[0], button.getAttribute("type")); + + button.click(); + + final List<NameValuePair> params = getMockWebConnection().getLastParameters(); + assertEquals(getExpectedAlerts()[1], "" + params.size()); + + if (params.size() > 0) { + assertEquals(getExpectedAlerts()[2], params.get(0).getName() + "-" + params.get(0).getValue()); + } + assertEquals(getExpectedAlerts()[3], driver.getTitle()); + } } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlButtonTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlButtonTest.java 2014-04-19 19:50:46 UTC (rev 9293) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlButtonTest.java 2014-04-20 08:07:01 UTC (rev 9294) @@ -19,16 +19,14 @@ import java.util.ArrayList; import java.util.Arrays; -import java.util.Collections; import java.util.List; import org.junit.Test; import org.junit.runner.RunWith; import com.gargoylesoftware.htmlunit.BrowserRunner; -import com.gargoylesoftware.htmlunit.MockWebConnection; +import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; import com.gargoylesoftware.htmlunit.SimpleWebTestCase; -import com.gargoylesoftware.htmlunit.WebClient; import com.gargoylesoftware.htmlunit.util.NameValuePair; /** @@ -126,39 +124,17 @@ * @throws Exception if the test fails */ @Test + @Alerts(DEFAULT = "submit", IE8 = "button") public void defaultButtonType_StandardsCompliantBrowser() throws Exception { - final String expectedType = getBrowserVersion().isFirefox() ? "submit" : "button"; - final String firstContent + final String html = "<html><head><title>First</title></head><body>\n" + "<form id='form1' action='" + URL_SECOND + "' method='post'>\n" + " <button name='button' id='button' value='pushme'>PushMe</button>\n" + "</form></body></html>"; - final String secondContent - = "<html><head><title>Second</title></head><body'></body></html>"; - final WebClient client = getWebClient(); - final MockWebConnection webConnection = new MockWebConnection(); - webConnection.setResponse(URL_FIRST, firstContent); - webConnection.setResponse(URL_SECOND, secondContent); - client.setWebConnection(webConnection); - - final HtmlPage page = client.getPage(URL_FIRST); + final HtmlPage page = loadPage(html); final HtmlButton button = page.getHtmlElementById("button"); - assertEquals(expectedType, button.getTypeAttribute()); - - final HtmlPage page2 = button.click(); - final List<NameValuePair> expectedParameters; - final String expectedSecondPageTitle; - if ("submit".equals(expectedType)) { - expectedParameters = Collections.singletonList(new NameValuePair("button", "pushme")); - expectedSecondPageTitle = "Second"; - } - else { - expectedParameters = Collections.emptyList(); - expectedSecondPageTitle = "First"; - } - assertEquals(expectedParameters, webConnection.getLastParameters()); - assertEquals(expectedSecondPageTitle, page2.getTitleText()); + assertEquals(getExpectedAlerts()[0], button.getTypeAttribute()); + assertEquals(getExpectedAlerts()[0], button.getAttribute("type")); } - } |
From: <rb...@us...> - 2014-04-20 13:15:16
|
Revision: 9295 http://sourceforge.net/p/htmlunit/code/9295 Author: rbri Date: 2014-04-20 13:15:12 +0000 (Sun, 20 Apr 2014) Log Message: ----------- HttpWebConnection: set socket timeout also Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2014-04-20 08:07:01 UTC (rev 9294) +++ trunk/htmlunit/src/changes/changes.xml 2014-04-20 13:15:12 UTC (rev 9295) @@ -8,6 +8,9 @@ <body> <release version="2.15" date="???" description="Bugfixes"> + <action type="fix" dev="rbri" issue="1593"> + HttpWebConnection: set socket timeout also (regression in 2.14). + </action> <action type="fix" dev="rbri"> HtmlButton.getAttribute("type") now returns the correct value if no type was specified. </action> Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java 2014-04-20 08:07:01 UTC (rev 9294) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java 2014-04-20 13:15:12 UTC (rev 9295) @@ -555,8 +555,10 @@ private void configureTimeout(final HttpClientBuilder builder, final int timeout) { final RequestConfig.Builder requestBuilder = createRequestConfigBuilder(timeout); + builder.setDefaultRequestConfig(requestBuilder.build()); - builder.setDefaultRequestConfig(requestBuilder.build()); + builder.setDefaultSocketConfig(createSocketConfigBuilder(timeout).build()); + httpContext_.removeAttribute(HttpClientContext.REQUEST_CONFIG); usedOptions_.setTimeout(timeout); } @@ -573,6 +575,13 @@ return requestBuilder; } + private SocketConfig.Builder createSocketConfigBuilder(final int timeout) { + final SocketConfig.Builder socketBuilder = SocketConfig.custom() + // timeout + .setSoTimeout(timeout); + return socketBuilder; + } + /** * React on changes that may have occurred on the WebClient settings. * Registering as a listener would be probably better. |
From: <rb...@us...> - 2014-04-21 17:35:33
|
Revision: 9304 http://sourceforge.net/p/htmlunit/code/9304 Author: rbri Date: 2014-04-21 17:35:29 +0000 (Mon, 21 Apr 2014) Log Message: ----------- IE11 progress Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLElement.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLElementTest.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLElement.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLElement.java 2014-04-21 15:34:51 UTC (rev 9303) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLElement.java 2014-04-21 17:35:29 UTC (rev 9304) @@ -851,6 +851,15 @@ */ @JsxGetter public String getInnerHTML() { + final DomNode domNode; + try { + domNode = getDomNodeOrDie(); + } + catch (final IllegalStateException e) { + Context.throwAsScriptRuntimeEx(e); + return ""; + } + final StringBuilder buf = new StringBuilder(); final String tagName = getTagName(); @@ -862,7 +871,7 @@ isPlain = isPlain || "STYLE".equals(tagName); // we can't rely on DomNode.asXml because it adds indentation and new lines - printChildren(buf, getDomNodeOrDie(), !isPlain); + printChildren(buf, domNode, !isPlain); return buf.toString(); } @@ -975,7 +984,14 @@ */ @JsxSetter public void setInnerHTML(final Object value) { - final DomNode domNode = getDomNodeOrDie(); + final DomNode domNode; + try { + domNode = getDomNodeOrDie(); + } + catch (final IllegalStateException e) { + Context.throwAsScriptRuntimeEx(e); + return; + } domNode.removeAllChildren(); Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLElementTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLElementTest.java 2014-04-21 15:34:51 UTC (rev 9303) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLElementTest.java 2014-04-21 17:35:29 UTC (rev 9304) @@ -3191,18 +3191,19 @@ * @throws Exception if the test fails */ @Test - @Alerts(DEFAULT = "exception", + @Alerts(DEFAULT = { "exception call", "exception set" }, CHROME = { "undefined", "true" }) - @NotYetImplemented(FF) public void prototype_innerHTML() throws Exception { final String html = "<html><body>\n" + "<script>\n" + "try {\n" + " alert(HTMLElement.prototype.innerHTML);\n" + + "} catch (e) { alert('exception call') }\n" + + "try {\n" + " var myFunc = function() {};\n" + " HTMLElement.prototype.innerHTML = myFunc;\n" + " alert(HTMLElement.prototype.innerHTML == myFunc);\n" - + "} catch (e) { alert('exception') }\n" + + "} catch (e) { alert('exception set') }\n" + "</script>\n" + "</body></html>"; loadPageWithAlerts2(html); |
From: <asa...@us...> - 2014-04-23 05:26:33
|
Revision: 9305 http://sourceforge.net/p/htmlunit/code/9305 Author: asashour Date: 2014-04-23 05:26:26 +0000 (Wed, 23 Apr 2014) Log Message: ----------- KeyDataPair: marked as internal API. Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/util/KeyDataPair.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2014-04-21 17:35:29 UTC (rev 9304) +++ trunk/htmlunit/src/changes/changes.xml 2014-04-23 05:26:26 UTC (rev 9305) @@ -8,6 +8,9 @@ <body> <release version="2.15" date="???" description="Bugfixes"> + <action type="update" dev="asashour"> + KeyDataPair: marked as internal API. + </action> <action type="fix" dev="rbri" issue="1593"> HttpWebConnection: set socket timeout also (regression in 2.14). </action> Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/util/KeyDataPair.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/util/KeyDataPair.java 2014-04-21 17:35:29 UTC (rev 9304) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/util/KeyDataPair.java 2014-04-23 05:26:26 UTC (rev 9305) @@ -17,6 +17,8 @@ import java.io.File; /** + * <span style="color:red">INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.</span><br/> + * * A holder for a key/value pair that represents a file to upload. * * @version $Revision$ @@ -24,10 +26,7 @@ * @author David D. Kilzer * @author Mike Bowler * @author Ahmed Ashour - * @deprecated as of 2.13, with no replacement */ -@Deprecated -// to be package private or 'use at your own risk' (referenced by HttpWebConnection and HtmlFileInput) public class KeyDataPair extends NameValuePair { private final File fileObject_; |
From: <rb...@us...> - 2014-04-23 20:46:12
|
Revision: 9309 http://sourceforge.net/p/htmlunit/code/9309 Author: rbri Date: 2014-04-23 20:46:09 +0000 (Wed, 23 Apr 2014) Log Message: ----------- more detailed and robust test, code cleanup Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLFormElement.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLFormElementTest.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2014-04-23 17:40:10 UTC (rev 9308) +++ trunk/htmlunit/src/changes/changes.xml 2014-04-23 20:46:09 UTC (rev 9309) @@ -7,7 +7,7 @@ </properties> <body> - <release version="2.15" date="???" description="Bugfixes"> + <release version="2.15" date="???" description="Bugfixes, IE11 progress"> <action type="update" dev="asashour"> KeyDataPair: marked as internal API. </action> Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLFormElement.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLFormElement.java 2014-04-23 17:40:10 UTC (rev 9308) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLFormElement.java 2014-04-23 20:46:09 UTC (rev 9309) @@ -444,13 +444,12 @@ return true; } - if (!getBrowserVersion().hasFeature(FORMFIELD_REACHABLE_BY_NEW_NAMES)) { - return false; + if (getBrowserVersion().hasFeature(FORMFIELD_REACHABLE_BY_NEW_NAMES)) { + if (name.equals(element.getAttribute("name")) + || elementWithNames.getPreviousNames().contains(name)) { + return true; + } } - else if (name.equals(element.getAttribute("name")) - || elementWithNames.getPreviousNames().contains(name)) { - return true; - } } return false; } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLFormElementTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLFormElementTest.java 2014-04-23 17:40:10 UTC (rev 9308) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLFormElementTest.java 2014-04-23 20:46:09 UTC (rev 9309) @@ -1189,19 +1189,32 @@ */ @Test @Alerts(DEFAULT = { "[object HTMLInputElement]", "undefined", - "[object HTMLInputElement]", "[object HTMLInputElement]" }, - IE = { "[object]", "undefined", "[object]", "undefined" }, - IE11 = { "[object HTMLInputElement]", "undefined", "undefined", "[object HTMLInputElement]" }) + "[object HTMLInputElement]", "[object HTMLInputElement]", + "[object HTMLInputElement]", "[object HTMLInputElement]", "[object HTMLInputElement]" }, + IE = { "[object]", "undefined", + "[object]", "undefined", + "[object]", "undefined", "undefined" }, + IE11 = { "[object HTMLInputElement]", "undefined", + "undefined", "[object HTMLInputElement]", + "undefined", "undefined", "[object HTMLInputElement]" }) public void accessByNameAfterNameChange() throws Exception { final String html = "<html><head><title>foo</title><script>\n" + "function go() {\n" + + " var field = document.simple_form.originalName;\n" + " alert(document.simple_form.originalName);\n" + " alert(document.simple_form.newName);\n" - + " document.simple_form.originalName.name = 'newName';\n" + + + " field.name = 'newName';\n" + " alert(document.simple_form.originalName);\n" + " alert(document.simple_form.newName);\n" - + "}</script></head>\n" + + + " field.name = 'brandNewName';\n" + + " alert(document.simple_form.originalName);\n" + + " alert(document.simple_form.newName);\n" + + " alert(document.simple_form.brandNewName);\n" + + "}\n" + + "</script></head>\n" + "<body onload='go()'>\n" + "<form name='simple_form'>\n" + " <input name='originalName'>\n" |
From: <rb...@us...> - 2014-04-26 20:01:45
|
Revision: 9313 http://sourceforge.net/p/htmlunit/code/9313 Author: rbri Date: 2014-04-26 20:01:42 +0000 (Sat, 26 Apr 2014) Log Message: ----------- IE11 progress Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/KeyboardEvent.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/Event2Test.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/Event3Test.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/KeyboardEvent.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/KeyboardEvent.java 2014-04-26 18:00:14 UTC (rev 9312) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/KeyboardEvent.java 2014-04-26 20:01:42 UTC (rev 9313) @@ -671,4 +671,27 @@ public Object getKeyCode() { return super.getKeyCode(); } + /** + * @return whether SHIFT has been pressed during this event or not + */ + @JsxGetter(@WebBrowser(value = IE, minVersion = 11)) + public boolean getShiftKey() { + return super.getShiftKey(); + } + + /** + * @return whether CTRL has been pressed during this event or not + */ + @JsxGetter(@WebBrowser(value = IE, minVersion = 11)) + public boolean getCtrlKey() { + return super.getCtrlKey(); + } + + /** + * @return whether ALT has been pressed during this event or not + */ + @JsxGetter(@WebBrowser(value = IE, minVersion = 11)) + public boolean getAltKey() { + return super.getAltKey(); + } } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/Event2Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/Event2Test.java 2014-04-26 18:00:14 UTC (rev 9312) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/Event2Test.java 2014-04-26 20:01:42 UTC (rev 9313) @@ -22,6 +22,7 @@ import org.junit.runner.RunWith; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; import com.gargoylesoftware.htmlunit.BrowserRunner; import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; @@ -304,4 +305,101 @@ driver.findElement(By.id("clickMe")).click(); assertEquals(getExpectedAlerts(), getCollectedAlerts(driver)); } + + /** + * Tests that event fires on key press. + * @throws Exception if the test fails + */ + @Test + @Alerts({ "pass", "fail:66", "fail:undefined" }) + public void testEventOnKeyDown() throws Exception { + final String html + = "<html><head></head>\n" + + "<body>\n" + + " <button type='button' id='clickId'>Click Me</button>\n" + + " <script>\n" + + " function handler(_e) {\n" + + " var e = _e ? _e : window.event;\n" + + " if (e.keyCode == 65)\n" + + " alert('pass');\n" + + " else\n" + + " alert('fail:' + e.keyCode);\n" + + " }\n" + + " document.getElementById('clickId').onkeydown = handler;\n" + + " document.getElementById('clickId').onclick = handler;\n" + + " </script>\n" + + "</body></html>"; + + final WebDriver driver = loadPage2(html); + final WebElement element = driver.findElement(By.id("clickId")); + element.sendKeys("a"); + element.sendKeys("b"); + element.click(); + + assertEquals(getExpectedAlerts(), getCollectedAlerts(driver)); + } + + /** + * Verifies that in IE, the <tt>shiftKey</tt>, <tt>ctrlKey</tt> and <tt>altKey</tt> + * event attributes are defined for all events, but <tt>metaKey</tt> is not defined + * for any events.<br/> + * Verifies that in FF, the <tt>shiftKey</tt>, <tt>ctrlKey</tt>, <tt>altKey</tt> and + * <tt>metaKey</tt> attributes are defined for mouse events only. + * @throws Exception if an error occurs + */ + @Test + @Alerts(DEFAULT = {"object", "undefined", "undefined", "undefined", "undefined", + "object", "false", "false", "false", "false" }, + IE8 = {"object", "false", "false", "false", "undefined", + "object", "false", "false", "false", "undefined" }) + public void testKeys() throws Exception { + final String html = + "<html><body onload='test(event)'><script>\n" + + " function test(e) {\n" + + " alert(typeof e);\n" + + " alert(e.shiftKey);\n" + + " alert(e.ctrlKey);\n" + + " alert(e.altKey);\n" + + " alert(e.metaKey);\n" + + " }\n" + + "</script>\n" + + "<div id='div' onclick='test(event)'>abc</div>\n" + + "</body></html>"; + + final WebDriver driver = loadPage2(html); + final WebElement element = driver.findElement(By.id("div")); + element.click(); + + assertEquals(getExpectedAlerts(), getCollectedAlerts(driver)); + } + + /** + * @throws Exception if an error occurs + */ + @Test + public void preventDefault() throws Exception { + final String html = + "<html><head><title>First</title>\n" + + "<script>\n" + + "function block(e) {\n" + + " if (e && e.preventDefault)\n" + + " e.preventDefault();\n" + + " else\n" + + " return false;\n" + + "}\n" + + "\n" + + "function test() {\n" + + " document.getElementById('myForm').onsubmit = block;\n" + + "}\n" + + "</script>\n" + + "</head><body onload='test()'>\n" + + "<form id='myForm' action='doesnt_exist.html'>\n" + + " <input type='submit' id='mySubmit' value='Continue'></p>\n" + + "</form>" + + "</body></html>"; + + final WebDriver driver = loadPageWithAlerts2(html); + driver.findElement(By.id("mySubmit")); + assertEquals(getDefaultUrl().toExternalForm(), driver.getCurrentUrl()); + } } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/Event3Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/Event3Test.java 2014-04-26 18:00:14 UTC (rev 9312) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/Event3Test.java 2014-04-26 20:01:42 UTC (rev 9313) @@ -21,7 +21,6 @@ import static org.junit.Assert.assertSame; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import org.junit.Test; @@ -38,8 +37,6 @@ import com.gargoylesoftware.htmlunit.html.HtmlAnchor; import com.gargoylesoftware.htmlunit.html.HtmlButton; import com.gargoylesoftware.htmlunit.html.HtmlButtonInput; -import com.gargoylesoftware.htmlunit.html.HtmlDivision; -import com.gargoylesoftware.htmlunit.html.HtmlElement; import com.gargoylesoftware.htmlunit.html.HtmlPage; /** @@ -57,40 +54,9 @@ public class Event3Test extends SimpleWebTestCase { /** - * Tests that event fires on key press. * @throws Exception if the test fails */ @Test - public void testEventOnKeyDown() throws Exception { - final String html - = "<html><head></head><body>\n" - + "<button type='button' id='clickId'>Click Me</button>\n" - + "<script>\n" - + "function handler(_e) {\n" - + " var e = _e ? _e : window.event;\n" - + " if (e.keyCode == 65)\n" - + " alert('pass');\n" - + " else\n" - + " alert('fail:' + e.keyCode);\n" - + "}\n" - + "document.getElementById('clickId').onkeydown = handler;\n" - + "document.getElementById('clickId').onclick = handler;</script>\n" - + "</body></html>"; - - final List<String> collectedAlerts = new ArrayList<String>(); - final HtmlPage page = loadPage(getBrowserVersion(), html, collectedAlerts); - final HtmlElement element = page.getHtmlElementById("clickId"); - element.type('A'); - element.type('B'); - element.click(); - final String[] expectedAlerts = {"pass", "fail:66", "fail:undefined"}; - assertEquals(expectedAlerts, collectedAlerts); - } - - /** - * @throws Exception if the test fails - */ - @Test public void testEventOnKeyDown_Shift_Ctrl_Alt() throws Exception { testEventOnKeyDown_Shift_Ctrl_Alt(false, false, false, new String[] {"false,false,false"}); testEventOnKeyDown_Shift_Ctrl_Alt(true, false, false, new String[] {"true,false,false"}); @@ -102,15 +68,17 @@ private void testEventOnKeyDown_Shift_Ctrl_Alt(final boolean shiftKey, final boolean ctrlKey, final boolean altKey, final String[] expectedAlerts) throws Exception { final String content - = "<html><head></head><body>\n" - + "<button type='button' id='clickId'/>\n" - + "<script>\n" - + "function handler(_e) {\n" - + " var e = _e ? _e : window.event;\n" - + " alert(e.shiftKey + ',' + e.ctrlKey + ',' + e.altKey);\n" - + "}\n" - + "document.getElementById('clickId').onkeydown = handler;\n" - + "</script>\n" + = "<html>\n" + + "<head></head>\n" + + "<body>\n" + + " <button type='button' id='clickId'/>\n" + + " <script>\n" + + " function handler(_e) {\n" + + " var e = _e ? _e : window.event;\n" + + " alert(e.shiftKey + ',' + e.ctrlKey + ',' + e.altKey);\n" + + " }\n" + + " document.getElementById('clickId').onkeydown = handler;\n" + + " </script>\n" + "</body></html>"; final List<String> collectedAlerts = new ArrayList<String>(); @@ -365,42 +333,9 @@ } /** - * Verifies that in IE, the <tt>shiftKey</tt>, <tt>ctrlKey</tt> and <tt>altKey</tt> - * event attributes are defined for all events, but <tt>metaKey</tt> is not defined - * for any events.<br/> - * Verifies that in FF, the <tt>shiftKey</tt>, <tt>ctrlKey</tt>, <tt>altKey</tt> and - * <tt>metaKey</tt> attributes are defined for mouse events only. * @throws Exception if an error occurs */ @Test - @Alerts(FF = {"object", "undefined", "undefined", "undefined", "undefined", - "object", "false", "false", "false", "false" }, - IE = {"object", "false", "false", "false", "undefined", - "object", "false", "false", "false", "undefined" }) - public void testKeys() throws Exception { - final String html = - "<html><body onload='test(event)'><script>\n" - + " function test(e) {\n" - + " alert(typeof e);\n" - + " alert(e.shiftKey);\n" - + " alert(e.ctrlKey);\n" - + " alert(e.altKey);\n" - + " alert(e.metaKey);\n" - + " }\n" - + "</script>\n" - + "<div id='div' onclick='test(event)'>abc</div>\n" - + "</body></html>"; - final List<String> actual = new ArrayList<String>(); - final HtmlPage page = loadPage(getBrowserVersion(), html, actual); - final HtmlDivision div = page.getHtmlElementById("div"); - div.click(); - assertEquals(Arrays.toString(getExpectedAlerts()), actual.toString()); - } - - /** - * @throws Exception if an error occurs - */ - @Test @Browsers(FF) @Alerts({ "capturing", "at target", "bubbling" }) public void testEventPhase() throws Exception { @@ -520,34 +455,4 @@ } } - /** - * @throws Exception if an error occurs - */ - @Test - public void preventDefault() throws Exception { - final String html = - "<html><head><title>First</title>\n" - + "<script>\n" - + "function block(e) {\n" - + " if (e && e.preventDefault)\n" - + " e.preventDefault();\n" - + " else\n" - + " return false;\n" - + "}\n" - + "\n" - + "function test() {\n" - + " document.getElementById('myForm').onsubmit = block;\n" - + "}\n" - + "</script>\n" - + "</head><body onload='test()'>\n" - + "<form id='myForm' action='doesnt_exist.html'>\n" - + " <input type='submit' id='mySubmit' value='Continue'></p>\n" - + "</form>" - + "</body></html>"; - - final HtmlPage page = loadPageWithAlerts(html); - final HtmlPage page2 = page.getHtmlElementById("mySubmit").click(); - assertEquals(getDefaultUrl(), page2.getUrl()); - } - } |
From: <rb...@us...> - 2014-05-02 17:58:46
|
Revision: 9321 http://sourceforge.net/p/htmlunit/code/9321 Author: rbri Date: 2014-05-02 17:58:42 +0000 (Fri, 02 May 2014) Log Message: ----------- IE11 progress Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/JavaScriptEngine2Test.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2014-05-02 17:32:42 UTC (rev 9320) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2014-05-02 17:58:42 UTC (rev 9321) @@ -1009,7 +1009,7 @@ * Indicates that function can be defined as * <code>function object.property() {}</code> instead of <code>object.property = function() {}</code>. */ - @BrowserFeature(@WebBrowser(IE)) + @BrowserFeature(@WebBrowser(value = IE, maxVersion = 10)) JS_FUNCTION_OBJECT_METHOD, /** Indicates if the method toSource exists on the native objects. */ Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/JavaScriptEngine2Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/JavaScriptEngine2Test.java 2014-05-02 17:32:42 UTC (rev 9320) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/JavaScriptEngine2Test.java 2014-05-02 17:58:42 UTC (rev 9321) @@ -14,6 +14,7 @@ */ package com.gargoylesoftware.htmlunit.javascript; +import static com.gargoylesoftware.htmlunit.BrowserRunner.Browser.FF17; import static com.gargoylesoftware.htmlunit.BrowserRunner.Browser.FF24; import static com.gargoylesoftware.htmlunit.BrowserRunner.Browser.IE; @@ -25,7 +26,7 @@ import com.gargoylesoftware.htmlunit.BrowserRunner; import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; -import com.gargoylesoftware.htmlunit.BrowserRunner.Browsers; +import com.gargoylesoftware.htmlunit.BrowserRunner.Browser; import com.gargoylesoftware.htmlunit.BrowserRunner.NotYetImplemented; import com.gargoylesoftware.htmlunit.WebDriverTestCase; @@ -331,8 +332,8 @@ * @throws Exception if the test fails */ @Test - @Browsers(IE) @Alerts(IE8 = { "1", "2" }) + @NotYetImplemented({ FF17, FF24, Browser.IE11 }) public void function_object_method() throws Exception { final String html = "<html><head><title>foo</title><script>\n" + " try {\n" @@ -342,7 +343,8 @@ + " }\n" + " alert('2');\n" + " } catch(e) {alert(e)}\n" - + "</script></head><body>\n" + + "</script></head>\n" + + "<body>\n" + " <div id='myDiv'>Hello there</div>\n" + "</body></html>"; |
From: <rb...@us...> - 2014-05-02 19:08:10
|
Revision: 9322 http://sourceforge.net/p/htmlunit/code/9322 Author: rbri Date: 2014-05-02 19:08:07 +0000 (Fri, 02 May 2014) Log Message: ----------- IE11 progress Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/NodeList.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLCollection.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLCollectionTest.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2014-05-02 17:58:42 UTC (rev 9321) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2014-05-02 19:08:07 UTC (rev 9322) @@ -415,9 +415,13 @@ HTMLCOLLECTION_COMMENT_IS_ELEMENT, /** HtmlCollection returns null instead of undefined if an element was not found. */ - @BrowserFeature(@WebBrowser(IE)) + @BrowserFeature(@WebBrowser(value = IE, maxVersion = 10)) HTMLCOLLECTION_NULL_IF_NOT_FOUND, + /** HtmlCollection.item returns null instead of undefined if an element was not found. */ + @BrowserFeature(@WebBrowser(IE)) + HTMLCOLLECTION_NULL_IF_ITEM_NOT_FOUND, + /** Allow detection of object type for collection elements. */ @BrowserFeature(@WebBrowser(value = IE, maxVersion = 9)) HTMLCOLLECTION_OBJECT_DETECTION, Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/NodeList.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/NodeList.java 2014-05-02 17:58:42 UTC (rev 9321) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/NodeList.java 2014-05-02 19:08:07 UTC (rev 9322) @@ -17,6 +17,7 @@ import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.GENERATED_49; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.GENERATED_50; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.HTMLCOLLECTION_COMMENT_IS_ELEMENT; +import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.HTMLCOLLECTION_NULL_IF_ITEM_NOT_FOUND; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.HTMLCOLLECTION_NULL_IF_NOT_FOUND; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.HTMLCOLLECTION_OBJECT_DETECTION; @@ -166,7 +167,14 @@ if (args.length == 0) { throw Context.reportRuntimeError("Zero arguments; need an index or a key."); } - return nullIfNotFound(getIt(args[0])); + final Object object = getIt(args[0]); + if (object == NOT_FOUND) { + if (getBrowserVersion().hasFeature(HTMLCOLLECTION_NULL_IF_NOT_FOUND)) { + return null; + } + return Context.getUndefinedValue(); + } + return object; } /** @@ -372,19 +380,9 @@ */ @JsxFunction public final Object item(final Object index) { - return nullIfNotFound(getIt(index)); - } - - /** - * Returns the specified object, unless it is the <tt>NOT_FOUND</tt> constant, in which case <tt>null</tt> - * is returned for IE. - * @param object the object to return - * @return the specified object, unless it is the <tt>NOT_FOUND</tt> constant, in which case <tt>null</tt> - * is returned for IE. - */ - private Object nullIfNotFound(final Object object) { + final Object object = getIt(index); if (object == NOT_FOUND) { - if (getBrowserVersion().hasFeature(HTMLCOLLECTION_NULL_IF_NOT_FOUND)) { + if (getBrowserVersion().hasFeature(HTMLCOLLECTION_NULL_IF_ITEM_NOT_FOUND)) { return null; } return Context.getUndefinedValue(); Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLCollection.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLCollection.java 2014-05-02 17:58:42 UTC (rev 9321) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLCollection.java 2014-05-02 19:08:07 UTC (rev 9322) @@ -14,9 +14,9 @@ */ package com.gargoylesoftware.htmlunit.javascript.host.html; -import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.HTMLCOLLECTION_NULL_IF_NOT_FOUND; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.GENERATED_50; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.HTMLCOLLECTION_COMMENT_IS_ELEMENT; +import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.HTMLCOLLECTION_NULL_IF_ITEM_NOT_FOUND; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.HTMLCOLLECTION_OBJECT_DETECTION; import static com.gargoylesoftware.htmlunit.javascript.configuration.BrowserName.CHROME; import static com.gargoylesoftware.htmlunit.javascript.configuration.BrowserName.IE; @@ -249,7 +249,7 @@ */ private Object nullIfNotFound(final Object object) { if (object == NOT_FOUND) { - if (getBrowserVersion().hasFeature(HTMLCOLLECTION_NULL_IF_NOT_FOUND)) { + if (getBrowserVersion().hasFeature(HTMLCOLLECTION_NULL_IF_ITEM_NOT_FOUND)) { return null; } return Context.getUndefinedValue(); Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLCollectionTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLCollectionTest.java 2014-05-02 17:58:42 UTC (rev 9321) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLCollectionTest.java 2014-05-02 19:08:07 UTC (rev 9322) @@ -18,6 +18,7 @@ import static com.gargoylesoftware.htmlunit.BrowserRunner.Browser.FF17; import static com.gargoylesoftware.htmlunit.BrowserRunner.Browser.FF24; import static com.gargoylesoftware.htmlunit.BrowserRunner.Browser.IE; +import static com.gargoylesoftware.htmlunit.BrowserRunner.Browser.IE11; import static com.gargoylesoftware.htmlunit.BrowserRunner.Browser.IE8; import org.junit.Test; @@ -110,7 +111,7 @@ "string myForm", "string namedItem" }, IE = { "string length", "string myForm" }, IE11 = { "string item", "string length", "string myForm", "string namedItem" }) - @NotYetImplemented({ FF17, FF24 }) + @NotYetImplemented({ FF17, FF24, IE11 }) public void testFor_in() throws Exception { final String html = "<html><head><title>foo</title><script>\n" + " function test() {\n" @@ -146,7 +147,7 @@ IE11 = { "string 1", "string action", "string first_submit", "string item", "string length", "string namedItem", "string second_submit", "string val1", "string val2" }) - @NotYetImplemented({ FF17, FF24 }) + @NotYetImplemented({ FF17, FF24, IE11 }) public void testFor_in2() throws Exception { final String html = "<html><head><title>foo</title><script>\n" + " function test() {\n" |
From: <rb...@us...> - 2014-05-03 16:41:20
|
Revision: 9325 http://sourceforge.net/p/htmlunit/code/9325 Author: rbri Date: 2014-05-03 16:41:07 +0000 (Sat, 03 May 2014) Log Message: ----------- IE11 progress Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLElement.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLElementTest.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2014-05-03 14:56:25 UTC (rev 9324) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2014-05-03 16:41:07 UTC (rev 9325) @@ -1091,6 +1091,10 @@ @BrowserFeature(@WebBrowser(value = IE, maxVersion = 9)) JS_INNER_HTML_REDUCE_WHITESPACES, + /** the inner html of a script tag start always with a \r\n. */ + @BrowserFeature(@WebBrowser(value = IE, maxVersion = 10)) + JS_INNER_HTML_SCRIPT_STARTSWITH_NEW_LINE, + /** Indicates that innerText is readonly for tables. */ @BrowserFeature(@WebBrowser(CHROME)) JS_INNER_TEXT_READONLY_FOR_TABLE, Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLElement.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLElement.java 2014-05-03 14:56:25 UTC (rev 9324) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLElement.java 2014-05-03 16:41:07 UTC (rev 9325) @@ -32,7 +32,7 @@ import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_INNER_HTML_ADD_CHILD_FOR_NULL_VALUE; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_INNER_HTML_CREATES_DOC_FRAGMENT_AS_PARENT; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_INNER_HTML_REDUCE_WHITESPACES; -import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_NATIVE_FUNCTION_TOSTRING_NEW_LINE; +import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_INNER_HTML_SCRIPT_STARTSWITH_NEW_LINE; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_OFFSET_PARENT_THROWS_NOT_ATTACHED; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_OUTER_HTML_NULL_AS_STRING; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_OUTER_HTML_REMOVES_CHILDS_FOR_DETACHED; @@ -864,7 +864,7 @@ final String tagName = getTagName(); boolean isPlain = "SCRIPT".equals(tagName); - if (isPlain && getBrowserVersion().hasFeature(JS_NATIVE_FUNCTION_TOSTRING_NEW_LINE)) { + if (isPlain && getBrowserVersion().hasFeature(JS_INNER_HTML_SCRIPT_STARTSWITH_NEW_LINE)) { buf.append("\r\n"); } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLElementTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLElementTest.java 2014-05-03 14:56:25 UTC (rev 9324) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLElementTest.java 2014-05-03 16:41:07 UTC (rev 9325) @@ -1097,7 +1097,7 @@ @Alerts(FF = { "Outer = <p id=\"myNode\">New cell value\n\n</p>" }, IE8 = { "Outer = <P id=myNode>New cell value\n</P>" }, IE11 = { "Outer = <p id=\"myNode\">New cell value\n\n" }) - @NotYetImplemented({ FF17, FF24 }) + @NotYetImplemented({ FF17, FF24, IE11 }) public void getOuterHTMLFromUnclosedParagraph() throws Exception { final String html = createPageForGetOuterHTML("p", "New cell value", true); loadPageWithAlerts2(html); |
From: <rb...@us...> - 2014-05-03 18:51:26
|
Revision: 9326 http://sourceforge.net/p/htmlunit/code/9326 Author: rbri Date: 2014-05-03 18:51:22 +0000 (Sat, 03 May 2014) Log Message: ----------- IE11 progress Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLElement.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLElementTest.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2014-05-03 16:41:07 UTC (rev 9325) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2014-05-03 18:51:22 UTC (rev 9326) @@ -364,10 +364,6 @@ /** Was originally .isIE(). */ @BrowserFeature(@WebBrowser(IE)) - GENERATED_72, - - /** Was originally .isIE(). */ - @BrowserFeature(@WebBrowser(IE)) GENERATED_80, /** Was originally .isIE(). */ @@ -1162,12 +1158,21 @@ @BrowserFeature(@WebBrowser(value = IE, maxVersion = 8)) JS_OBJECT_IN_QUIRKS_MODE, + /** Indicates that someObj.offsetParent returns null, it someObj has fixed style. + */ + @BrowserFeature(@WebBrowser(value = IE, minVersion = 11)) + JS_OFFSET_PARENT_NULL_IF_FIXED, + /** Indicates that someObj.offsetParent throws an exception when called on an object that is not yet attached * to the page's DOM. */ @BrowserFeature(@WebBrowser(value = IE, maxVersion = 9)) JS_OFFSET_PARENT_THROWS_NOT_ATTACHED, + /** Was originally .isIE(). */ + @BrowserFeature(@WebBrowser(value = IE, maxVersion = 10)) + JS_OFFSET_PARENT_USE_TABLES_IF_FIXED, + /** Setting the property opacity of an css style declaration to arbitrary values is allowed. * FF accepts only valid floats. */ Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLElement.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLElement.java 2014-05-03 16:41:07 UTC (rev 9325) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLElement.java 2014-05-03 18:51:22 UTC (rev 9326) @@ -14,7 +14,6 @@ */ package com.gargoylesoftware.htmlunit.javascript.host.html; -import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.GENERATED_72; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.HTMLELEMENT_ATTRIBUTE_FIX_IN_QUIRKS_MODE; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.HTMLELEMENT_OUTER_HTML_UPPER_CASE; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.HTMLELEMENT_OUTER_INNER_HTML_QUOTE_ATTRIBUTES; @@ -33,7 +32,9 @@ import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_INNER_HTML_CREATES_DOC_FRAGMENT_AS_PARENT; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_INNER_HTML_REDUCE_WHITESPACES; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_INNER_HTML_SCRIPT_STARTSWITH_NEW_LINE; +import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_OFFSET_PARENT_NULL_IF_FIXED; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_OFFSET_PARENT_THROWS_NOT_ATTACHED; +import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_OFFSET_PARENT_USE_TABLES_IF_FIXED; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_OUTER_HTML_NULL_AS_STRING; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_OUTER_HTML_REMOVES_CHILDS_FOR_DETACHED; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_OUTER_HTML_THROWS_FOR_DETACHED; @@ -2775,12 +2776,18 @@ Object offsetParent = null; final HTMLElement htmlElement = (HTMLElement) currentElement.getScriptObject(); + if (getBrowserVersion().hasFeature(JS_OFFSET_PARENT_NULL_IF_FIXED) + && "fixed".equals(htmlElement.getStyle().getPosition())) { + return null; + } + final ComputedCSSStyleDeclaration style = htmlElement.getWindow().getComputedStyle(htmlElement, null); final String position = style.getPositionWithInheritance(); - final boolean ie = getBrowserVersion().hasFeature(GENERATED_72); + final boolean useTablesIfFixed = getBrowserVersion().hasFeature(JS_OFFSET_PARENT_USE_TABLES_IF_FIXED); final boolean staticPos = "static".equals(position); + final boolean fixedPos = "fixed".equals(position); - final boolean useTables = ((ie && (staticPos || fixedPos)) || (!ie && staticPos)); + final boolean useTables = ((useTablesIfFixed && (staticPos || fixedPos)) || (!useTablesIfFixed && staticPos)); while (currentElement != null) { @@ -2799,7 +2806,7 @@ final String parentPosition = parentStyle.getPositionWithInheritance(); final boolean parentIsStatic = "static".equals(parentPosition); final boolean parentIsFixed = "fixed".equals(parentPosition); - if ((ie && !parentIsStatic && !parentIsFixed) || (!ie && !parentIsStatic)) { + if ((useTablesIfFixed && !parentIsStatic && !parentIsFixed) || (!useTablesIfFixed && !parentIsStatic)) { offsetParent = parentNode.getScriptObject(); break; } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLElementTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLElementTest.java 2014-05-03 16:41:07 UTC (rev 9325) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLElementTest.java 2014-05-03 18:51:22 UTC (rev 9326) @@ -1378,7 +1378,7 @@ CHROME = { "Old = <span id=\"innerNode\">Old outerHTML</span>", "New = <div></div><div></div>", "Childs: 1" }, IE8 = { "Old = <SPAN id=innerNode>Old outerHTML</SPAN>", "New = <DIV></DIV><DIV></DIV>", "Childs: 1" }) - @NotYetImplemented({ FF17, FF24, IE8 }) + @NotYetImplemented({ FF17, FF24, IE8, IE11 }) public void setOuterHTMLAddMultipleSelfClosingBlock() throws Exception { final String html = createPageForSetOuterHTML("div", "<div/><div>"); loadPageWithAlerts2(html); @@ -2144,7 +2144,8 @@ * @throws Exception if an error occurs */ @Test - @Alerts(DEFAULT = { "null", "body", "exception" }, + @Alerts(DEFAULT = { "null", "body", "exception", "body", "body", "body", + "f1", "body", "h1", "i1", "td", "exception", "td", "body", "body" }, FF = { "null", "body", "body", "body", "body", "body", "f1", "body", "h1", "i1", "td", "body", "td", "body", "body" }, IE8 = { "null", "body", "body", "body", "body", "body", @@ -2173,25 +2174,28 @@ + " </tr>\n" + " </table>\n" + " <script>\n" + + " function alertOffsetParentId(id) {\n" + + " try {\n" + + " alert(document.getElementById(id).offsetParent.id);\n" + + " } catch (e) { alert('exception'); }\n" + + " }\n" + " function test() {\n" - + " try {\n" - + " // FF IE \n" + + " // FF IE \n" + " alert(document.getElementById('body').offsetParent); // null null \n" - + " alert(document.getElementById('a2').offsetParent.id); // body body \n" - + " alert(document.getElementById('b2').offsetParent.id); // body body \n" - + " alert(document.getElementById('c2').offsetParent.id); // body body \n" - + " alert(document.getElementById('d2').offsetParent.id); // body body \n" - + " alert(document.getElementById('e2').offsetParent.id); // body body \n" - + " alert(document.getElementById('f2').offsetParent.id); // f1 body \n" - + " alert(document.getElementById('g2').offsetParent.id); // body body \n" - + " alert(document.getElementById('h2').offsetParent.id); // h1 h1 \n" - + " alert(document.getElementById('i2').offsetParent.id); // i1 i1 \n" - + " alert(document.getElementById('j2').offsetParent.id); // td td \n" - + " alert(document.getElementById('k2').offsetParent.id); // body td \n" - + " alert(document.getElementById('l2').offsetParent.id); // td td \n" - + " alert(document.getElementById('m2').offsetParent.id); // body body \n" - + " alert(document.getElementById('n2').offsetParent.id); // body body \n" - + " } catch (e) { alert('exception'); }\n" + + " alertOffsetParentId('a2'); // body body \n" + + " alertOffsetParentId('b2'); // body body \n" + + " alertOffsetParentId('c2'); // body body \n" + + " alertOffsetParentId('d2'); // body body \n" + + " alertOffsetParentId('e2'); // body body \n" + + " alertOffsetParentId('f2'); // f1 body \n" + + " alertOffsetParentId('g2'); // body body \n" + + " alertOffsetParentId('h2'); // h1 h1 \n" + + " alertOffsetParentId('i2'); // i1 i1 \n" + + " alertOffsetParentId('j2'); // td td \n" + + " alertOffsetParentId('k2'); // body td \n" + + " alertOffsetParentId('l2'); // td td \n" + + " alertOffsetParentId('m2'); // body body \n" + + " alertOffsetParentId('n2'); // body body \n" + " }\n" + " </script>\n" + " </body>\n" @@ -3187,18 +3191,18 @@ + "<input type='text' id='i2' name='i2' style='color:red' onclick='alert(1)' custom1='a' />\n" + "<script>\n" + "function u(o) { return typeof o == 'undefined'; }\n" - + "var i = document.getElementById('i');\n" - + "var i2 = document.getElementById('i2');\n" - + "i2.custom2 = 'b';\n" - + "alert([u(i.type), u(i.id), u(i.name), u(i.style), u(i.onclick)," - + " u(i.custom1), u(i.custom2)].join(','));\n" - + "alert(i.id);\n" - + "alert(i.name);\n" - + "i.mergeAttributes(" + params + ");\n" - + "alert([u(i.type), u(i.id), u(i.name), u(i.style), u(i.onclick)," - + " u(i.custom1), u(i.custom2)].join(','));\n" - + "alert(i.id);\n" - + "alert(i.name);\n" + + " var i = document.getElementById('i');\n" + + " var i2 = document.getElementById('i2');\n" + + " i2.custom2 = 'b';\n" + + " alert([u(i.type), u(i.id), u(i.name), u(i.style), u(i.onclick)," + + " u(i.custom1), u(i.custom2)].join(','));\n" + + " alert(i.id);\n" + + " alert(i.name);\n" + + " i.mergeAttributes(" + params + ");\n" + + " alert([u(i.type), u(i.id), u(i.name), u(i.style), u(i.onclick)," + + " u(i.custom1), u(i.custom2)].join(','));\n" + + " alert(i.id);\n" + + " alert(i.name);\n" + "</script>"; setExpectedAlerts(expectedAlerts); |