From: <rb...@us...> - 2013-12-23 15:28:42
|
Revision: 8905 http://sourceforge.net/p/htmlunit/code/8905 Author: rbri Date: 2013-12-23 15:28:37 +0000 (Mon, 23 Dec 2013) Log Message: ----------- more IE11/FF24/Chrome fixes (Frank Danek) Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Document.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Element.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Event.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/EventListenersContainer.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/EventNode.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/MouseEvent.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Node.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Window.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/dom/DOMParser.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLDocument.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLElement.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/ClickableElementTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/DomNodeListTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HTMLParserTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlAttrTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlElementTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlInput2Test.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlPageTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/MalformedHtmlTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/NamedAttrNodeMapImplTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/ElementTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/Event2Test.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/EventNodeTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/EventTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/WindowConcurrencyTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLElement2Test.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLOptionElement2Test.java Added Paths: ----------- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HTMLParser4Test.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Document.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Document.java 2013-12-23 15:24:01 UTC (rev 8904) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Document.java 2013-12-23 15:28:37 UTC (rev 8905) @@ -15,7 +15,9 @@ package com.gargoylesoftware.htmlunit.javascript.host; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_DOCUMENT_CREATE_ELEMENT_EXTENDED_SYNTAX; +import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_DOCUMENT_DESIGN_MODE_CAPITAL_FIRST; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_DOCUMENT_DESIGN_MODE_INHERIT; +import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_DOCUMENT_DESIGN_MODE_ONLY_FOR_FRAMES; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_GET_ELEMENTS_BY_TAG_NAME_NOT_SUPPORTS_NAMESPACES; import static com.gargoylesoftware.htmlunit.javascript.configuration.BrowserName.CHROME; import static com.gargoylesoftware.htmlunit.javascript.configuration.BrowserName.FF; @@ -28,6 +30,7 @@ import net.sourceforge.htmlunit.corejs.javascript.Context; import net.sourceforge.htmlunit.corejs.javascript.NativeFunction; +import org.apache.commons.lang3.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.xml.utils.PrefixResolver; @@ -167,16 +170,14 @@ public String getDesignMode() { if (designMode_ == null) { if (getBrowserVersion().hasFeature(JS_DOCUMENT_DESIGN_MODE_INHERIT)) { - if (getWindow().getWebWindow() instanceof FrameWindow) { - designMode_ = "Inherit"; - } - else { - designMode_ = "Off"; - } + designMode_ = "inherit"; } else { designMode_ = "off"; } + if (getBrowserVersion().hasFeature(JS_DOCUMENT_DESIGN_MODE_CAPITAL_FIRST)) { + designMode_ = StringUtils.capitalize(designMode_); + } } return designMode_; } @@ -192,20 +193,24 @@ if (!"on".equalsIgnoreCase(mode) && !"off".equalsIgnoreCase(mode) && !"inherit".equalsIgnoreCase(mode)) { throw Context.reportRuntimeError("Invalid document.designMode value '" + mode + "'."); } - if (!(getWindow().getWebWindow() instanceof FrameWindow)) { - // IE ignores designMode changes for documents that aren't in frames. - return; + if (!(getWindow().getWebWindow() instanceof FrameWindow) + && getBrowserVersion().hasFeature(JS_DOCUMENT_DESIGN_MODE_ONLY_FOR_FRAMES)) { + // IE evaluates all designMode changes for documents that aren't in frames as Off + designMode_ = "off"; } - - if ("on".equalsIgnoreCase(mode)) { - designMode_ = "On"; + else if ("on".equalsIgnoreCase(mode)) { + designMode_ = "on"; } else if ("off".equalsIgnoreCase(mode)) { - designMode_ = "Off"; + designMode_ = "off"; } else if ("inherit".equalsIgnoreCase(mode)) { - designMode_ = "Inherit"; + designMode_ = "inherit"; } + + if (getBrowserVersion().hasFeature(JS_DOCUMENT_DESIGN_MODE_CAPITAL_FIRST)) { + designMode_ = StringUtils.capitalize(designMode_); + } } else { if ("on".equalsIgnoreCase(mode)) { @@ -236,7 +241,7 @@ * Gets the window in which this document is contained. * @return the window */ - @JsxGetter(@WebBrowser(FF)) + @JsxGetter({ @WebBrowser(CHROME), @WebBrowser(FF), @WebBrowser(value = IE, minVersion = 11) }) public Object getDefaultView() { return getWindow(); } @@ -315,7 +320,7 @@ * @param type the type of events to capture * @see Window#captureEvents(String) */ - @JsxFunction(@WebBrowser(FF)) + @JsxFunction({ @WebBrowser(CHROME), @WebBrowser(FF), @WebBrowser(value = IE, minVersion = 11) }) public void captureEvents(final String type) { // Empty. } 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 2013-12-23 15:24:01 UTC (rev 8904) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Element.java 2013-12-23 15:28:37 UTC (rev 8905) @@ -127,7 +127,7 @@ * Returns the Base URI as a string. * @return the Base URI as a string */ - @JsxGetter(@WebBrowser(FF)) + @JsxGetter({ @WebBrowser(CHROME), @WebBrowser(FF) }) public String getBaseURI() { return getDomNodeOrDie().getPage().getUrl().toExternalForm(); } @@ -303,7 +303,7 @@ * which matches all elements. * @return a live NodeList of found elements in the order they appear in the tree */ - @JsxFunction({ @WebBrowser(FF), @WebBrowser(value = IE, minVersion = 11) }) + @JsxFunction({ @WebBrowser(CHROME), @WebBrowser(FF), @WebBrowser(value = IE, minVersion = 11) }) public Object getElementsByTagNameNS(final Object namespaceURI, final String localName) { final String description = "Element.getElementsByTagNameNS('" + namespaceURI + "', '" + localName + "')"; @@ -324,7 +324,7 @@ * @param name the name of the attribute to look for * @return true if an attribute with the given name is specified on this element or has a default value */ - @JsxFunction({ @WebBrowser(FF), @WebBrowser(value = IE, minVersion = 11) }) + @JsxFunction({ @WebBrowser(CHROME), @WebBrowser(FF), @WebBrowser(value = IE, minVersion = 11) }) public boolean hasAttribute(final String name) { return getDomNodeOrDie().hasAttribute(name); } @@ -364,7 +364,7 @@ * Returns the current number of child elements. * @return the child element count */ - @JsxGetter({ @WebBrowser(FF), @WebBrowser(value = IE, minVersion = 11) }) + @JsxGetter({ @WebBrowser(CHROME), @WebBrowser(FF), @WebBrowser(value = IE, minVersion = 11) }) public int getChildElementCount() { return getDomNodeOrDie().getChildElementCount(); } @@ -373,7 +373,7 @@ * Returns the first element child. * @return the first element child */ - @JsxGetter({ @WebBrowser(FF), @WebBrowser(value = IE, minVersion = 11) }) + @JsxGetter({ @WebBrowser(CHROME), @WebBrowser(FF), @WebBrowser(value = IE, minVersion = 11) }) public Element getFirstElementChild() { final DomElement child = getDomNodeOrDie().getFirstElementChild(); if (child != null) { @@ -386,7 +386,7 @@ * Returns the last element child. * @return the last element child */ - @JsxGetter({ @WebBrowser(FF), @WebBrowser(value = IE, minVersion = 11) }) + @JsxGetter({ @WebBrowser(CHROME), @WebBrowser(FF), @WebBrowser(value = IE, minVersion = 11) }) public Element getLastElementChild() { final DomElement child = getDomNodeOrDie().getLastElementChild(); if (child != null) { @@ -399,7 +399,7 @@ * Returns the next element sibling. * @return the next element sibling */ - @JsxGetter({ @WebBrowser(FF), @WebBrowser(value = IE, minVersion = 11) }) + @JsxGetter({ @WebBrowser(CHROME), @WebBrowser(FF), @WebBrowser(value = IE, minVersion = 11) }) public Element getNextElementSibling() { final DomElement child = getDomNodeOrDie().getNextElementSibling(); if (child != null) { @@ -412,7 +412,7 @@ * Returns the previous element sibling. * @return the previous element sibling */ - @JsxGetter({ @WebBrowser(FF), @WebBrowser(value = IE, minVersion = 11) }) + @JsxGetter({ @WebBrowser(CHROME), @WebBrowser(FF), @WebBrowser(value = IE, minVersion = 11) }) public Element getPreviousElementSibling() { final DomElement child = getDomNodeOrDie().getPreviousElementSibling(); if (child != null) { @@ -452,7 +452,7 @@ * @see <a href="http://msdn.microsoft.com/en-us/library/ms537446.aspx">MSDN documentation</a> * @return the child at the given position */ - @JsxGetter(@WebBrowser(FF)) + @JsxGetter({ @WebBrowser(CHROME), @WebBrowser(FF) }) public HTMLCollection getChildren() { final DomElement node = getDomNodeOrDie(); final HTMLCollection collection = new HTMLCollection(node, false, "Element.children") { @@ -468,7 +468,7 @@ * Gets the token list of class attribute. * @return the token list of class attribute */ - @JsxGetter({ @WebBrowser(FF), @WebBrowser(value = IE, minVersion = 11) }) + @JsxGetter({ @WebBrowser(CHROME), @WebBrowser(FF) }) public DOMTokenList getClassList() { return null; } Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Event.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Event.java 2013-12-23 15:24:01 UTC (rev 8904) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Event.java 2013-12-23 15:28:37 UTC (rev 8905) @@ -394,7 +394,7 @@ * Returns the object that fired the event. This is an IE-only property. * @return the object that fired the event */ - @JsxGetter(@WebBrowser(IE)) + @JsxGetter({ @WebBrowser(IE), @WebBrowser(CHROME) }) public Object getSrcElement() { return srcElement_; } @@ -412,7 +412,7 @@ * Returns the event target to which the event was originally dispatched. * @return the event target to which the event was originally dispatched */ - @JsxGetter({ @WebBrowser(FF), @WebBrowser(value = IE, minVersion = 11) }) + @JsxGetter({ @WebBrowser(FF), @WebBrowser(value = IE, minVersion = 11), @WebBrowser(CHROME) }) public Object getTarget() { return target_; } @@ -430,7 +430,7 @@ * is useful during event capturing and event bubbling. * @return the current event target */ - @JsxGetter({ @WebBrowser(FF), @WebBrowser(value = IE, minVersion = 11) }) + @JsxGetter({ @WebBrowser(FF), @WebBrowser(value = IE, minVersion = 11), @WebBrowser(CHROME) }) public Object getCurrentTarget() { return currentTarget_; } @@ -473,7 +473,7 @@ * Returns the time at which this event was created. * @return the time at which this event was created */ - @JsxGetter({ @WebBrowser(FF), @WebBrowser(value = IE, minVersion = 11) }) + @JsxGetter({ @WebBrowser(FF), @WebBrowser(value = IE, minVersion = 11), @WebBrowser(CHROME) }) public long getTimeStamp() { return timeStamp_; } @@ -660,7 +660,7 @@ * @param bubbles whether or not the event should bubble * @param cancelable whether or not the event the event should be cancelable */ - @JsxFunction({ @WebBrowser(FF), @WebBrowser(value = IE, minVersion = 11) }) + @JsxFunction({ @WebBrowser(FF), @WebBrowser(value = IE, minVersion = 11), @WebBrowser(CHROME) }) public void initEvent(final String type, final boolean bubbles, final boolean cancelable) { type_ = type; bubbles_ = bubbles; Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/EventListenersContainer.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/EventListenersContainer.java 2013-12-23 15:24:01 UTC (rev 8904) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/EventListenersContainer.java 2013-12-23 15:28:37 UTC (rev 8905) @@ -42,6 +42,7 @@ * @author Marc Guillemot * @author Daniel Gredler * @author Ahmed Ashour + * @author Frank Danek */ public class EventListenersContainer implements Serializable { @@ -88,7 +89,7 @@ if (accept) { return true; } - throw new EvaluatorException("Could not convert JavaScript argument (Listner was null)."); + throw new EvaluatorException("Could not convert JavaScript argument (Listener was null)."); } final List<Function> listeners = getHandlersOrCreateIt(type).getHandlers(useCapture); Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/EventNode.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/EventNode.java 2013-12-23 15:24:01 UTC (rev 8904) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/EventNode.java 2013-12-23 15:28:37 UTC (rev 8905) @@ -34,6 +34,7 @@ * @version $Revision$ * @author Daniel Gredler * @author Ahmed Ashour + * @author Frank Danek */ @JsxClass public class EventNode extends Node { @@ -370,7 +371,7 @@ * @param event specifies the event object from which to obtain event object properties. * @return <tt>true</tt> if the event fired successfully, <tt>false</tt> if it was canceled */ - @JsxFunction(@WebBrowser(IE)) + @JsxFunction(@WebBrowser(value = IE, maxVersion = 9)) public boolean fireEvent(final String type, Event event) { if (event == null) { event = new MouseEvent(); Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/MouseEvent.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/MouseEvent.java 2013-12-23 15:24:01 UTC (rev 8904) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/MouseEvent.java 2013-12-23 15:28:37 UTC (rev 8905) @@ -275,7 +275,7 @@ * @see <a href="http://unixpapa.com/js/mouse.html">Javascript Madness: Mouse Events</a> * @return the button code */ - @JsxGetter({ @WebBrowser(FF), @WebBrowser(value = IE, minVersion = 11) }) + @JsxGetter({ @WebBrowser(FF), @WebBrowser(value = IE, minVersion = 11), @WebBrowser(CHROME) }) public int getWhich() { return button_ + 1; } Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Node.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Node.java 2013-12-23 15:24:01 UTC (rev 8904) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Node.java 2013-12-23 15:28:37 UTC (rev 8905) @@ -897,7 +897,7 @@ * Returns the namespace prefix. * @return the namespace prefix */ - @JsxGetter({ @WebBrowser(FF), @WebBrowser(value = IE, minVersion = 11) }) + @JsxGetter({ @WebBrowser(CHROME), @WebBrowser(FF), @WebBrowser(value = IE, minVersion = 11) }) public String getPrefix() { final DomNode domNode = getDomNodeOrDie(); final String prefix = domNode.getPrefix(); @@ -912,7 +912,7 @@ * Returns the local name of this element. * @return the local name of this element */ - @JsxGetter({ @WebBrowser(FF), @WebBrowser(value = IE, minVersion = 11) }) + @JsxGetter({ @WebBrowser(CHROME), @WebBrowser(FF), @WebBrowser(value = IE, minVersion = 11) }) public String getLocalName() { return getDomNodeOrDie().getLocalName(); } @@ -921,7 +921,7 @@ * Returns The URI that identifies an XML namespace. * @return the URI that identifies an XML namespace */ - @JsxGetter({ @WebBrowser(FF), @WebBrowser(value = IE, minVersion = 11) }) + @JsxGetter({ @WebBrowser(CHROME), @WebBrowser(FF), @WebBrowser(value = IE, minVersion = 11) }) public String getNamespaceURI() { final String namespaceURI = getDomNodeOrDie().getNamespaceURI(); return namespaceURI; @@ -931,7 +931,7 @@ * Returns the base name of this element. * @return the base name of this element */ - @JsxGetter(@WebBrowser(IE)) + @JsxGetter(@WebBrowser(value = IE, maxVersion = 9)) public Object getBaseName() { final DomElement domElem = getDomNodeOrDie(); final boolean isXmlPage = domElem.getOwnerDocument() instanceof XmlPage; 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 2013-12-23 15:24:01 UTC (rev 8904) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Window.java 2013-12-23 15:28:37 UTC (rev 8905) @@ -307,7 +307,7 @@ * Returns the current event (used by JavaScript only when emulating IE). * @return the current event, or <tt>null</tt> if no event is currently available */ - @JsxGetter(@WebBrowser(IE)) + @JsxGetter({ @WebBrowser(IE), @WebBrowser(CHROME) }) public Object getEvent() { return currentEvent_; } @@ -1140,7 +1140,7 @@ * @see <a href="http://msdn.microsoft.com/en-us/library/ms536343.aspx">MSDN documentation</a> * @return <code>true</code> if the listener has been added */ - @JsxFunction(@WebBrowser(IE)) + @JsxFunction(@WebBrowser(value = IE, maxVersion = 9)) public boolean attachEvent(final String type, final Function listener) { return getEventListenersContainer().addEventListener(StringUtils.substring(type, 2), listener, false); } Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/dom/DOMParser.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/dom/DOMParser.java 2013-12-23 15:24:01 UTC (rev 8904) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/dom/DOMParser.java 2013-12-23 15:28:37 UTC (rev 8905) @@ -14,6 +14,7 @@ */ package com.gargoylesoftware.htmlunit.javascript.host.dom; +import static com.gargoylesoftware.htmlunit.javascript.configuration.BrowserName.CHROME; 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; @@ -35,7 +36,7 @@ * * @see <a href="http://www.xulplanet.com/references/objref/DOMParser.html">XUL Planet</a> */ -@JsxClass(browsers = { @WebBrowser(FF), @WebBrowser(value = IE, minVersion = 11) }) +@JsxClass(browsers = { @WebBrowser(CHROME), @WebBrowser(FF), @WebBrowser(value = IE, minVersion = 11) }) public class DOMParser extends SimpleScriptable { /** 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 2013-12-23 15:24:01 UTC (rev 8904) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLDocument.java 2013-12-23 15:28:37 UTC (rev 8905) @@ -20,16 +20,17 @@ import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.EVENT_TYPE_EVENTS; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.EVENT_TYPE_KEY_EVENTS; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.EXECCOMMAND_THROWS_ON_WRONG_COMMAND; -import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.GENERATED_160; -import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.GENERATED_161; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.GENERATED_164; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.GENERATED_51; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.GENERATED_53; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.GENERATED_55; -import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.GENERATED_60; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.HTMLCOLLECTION_OBJECT_DETECTION; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.HTMLDOCUMENT_CHARSET_LOWERCASE; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.HTMLDOCUMENT_COLOR; +import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.HTMLDOCUMENT_GET_ALSO_FRAMES; +import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.HTMLDOCUMENT_GET_FOR_ID_AND_OR_NAME; +import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.HTMLDOCUMENT_GET_FOR_NAME; +import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.HTMLDOCUMENT_GET_PREFERS_STANDARD_FUNCTIONS; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_ANCHORS_REQUIRES_NAME_OR_ID; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_DOCUMENT_APPEND_CHILD_SUPPORTED; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_DOCUMENT_CLASS_NAME; @@ -1418,7 +1419,7 @@ @Override protected Object getWithPreemption(final String name) { final HtmlPage page = (HtmlPage) getDomNodeOrNull(); - if (page == null || getBrowserVersion().hasFeature(GENERATED_160)) { + if (page == null || getBrowserVersion().hasFeature(HTMLDOCUMENT_GET_PREFERS_STANDARD_FUNCTIONS)) { return NOT_FOUND; } return getIt(name); @@ -1427,12 +1428,13 @@ private Object getIt(final String name) { final HtmlPage page = (HtmlPage) getDomNodeOrNull(); - final boolean isIE = getBrowserVersion().hasFeature(GENERATED_60); + final boolean forIDAndOrName = getBrowserVersion().hasFeature(HTMLDOCUMENT_GET_FOR_ID_AND_OR_NAME); + final boolean alsoFrames = getBrowserVersion().hasFeature(HTMLDOCUMENT_GET_ALSO_FRAMES); final HTMLCollection collection = new HTMLCollection(page, true, "HTMLDocument." + name) { @Override protected List<Object> computeElements() { final List<DomElement> elements; - if (isIE) { + if (forIDAndOrName) { elements = page.getElementsByIdAndOrName(name); } else { @@ -1441,7 +1443,7 @@ final List<Object> matchingElements = new ArrayList<Object>(); for (final DomElement elt : elements) { if (elt instanceof HtmlForm || elt instanceof HtmlImage || elt instanceof HtmlApplet - || (isIE && elt instanceof BaseFrameElement)) { + || (alsoFrames && elt instanceof BaseFrameElement)) { matchingElements.add(elt); } } @@ -1454,7 +1456,7 @@ if ("name".equals(attributeName)) { return EffectOnCache.RESET; } - else if (isIE && "id".equals(attributeName)) { + else if (forIDAndOrName && "id".equals(attributeName)) { return EffectOnCache.RESET; } @@ -1463,7 +1465,7 @@ @Override protected SimpleScriptable getScriptableFor(final Object object) { - if (isIE && object instanceof BaseFrameElement) { + if (alsoFrames && object instanceof BaseFrameElement) { return (SimpleScriptable) ((BaseFrameElement) object).getEnclosedWindow().getScriptObject(); } return super.getScriptableFor(object); @@ -1486,7 +1488,8 @@ * {@inheritDoc} */ public Object getWithFallback(final String name) { - if (getBrowserVersion().hasFeature(GENERATED_161)) { + if (getBrowserVersion().hasFeature(HTMLDOCUMENT_GET_FOR_NAME) + || getBrowserVersion().hasFeature(HTMLDOCUMENT_GET_FOR_ID_AND_OR_NAME)) { return getIt(name); } return NOT_FOUND; @@ -1673,7 +1676,7 @@ * @see DomNode#READY_STATE_INTERACTIVE * @see DomNode#READY_STATE_COMPLETE */ - @JsxGetter({ @WebBrowser(IE), @WebBrowser(FF) }) + @JsxGetter({ @WebBrowser(CHROME), @WebBrowser(IE), @WebBrowser(FF) }) public String getReadyState() { final DomNode node = getDomNodeOrDie(); return node.getReadyState(); @@ -1777,7 +1780,7 @@ * Returns the value of the JavaScript attribute <tt>scripts</tt>. * @return the value of the JavaScript attribute <tt>scripts</tt> */ - @JsxGetter({ @WebBrowser(IE), @WebBrowser(value = FF, minVersion = 10) }) + @JsxGetter({ @WebBrowser(CHROME), @WebBrowser(IE), @WebBrowser(value = FF, minVersion = 10) }) public Object getScripts() { if (scripts_ == null) { scripts_ = new HTMLCollection(getDomNodeOrDie(), false, "HTMLDocument.scripts") { @@ -1880,7 +1883,7 @@ * @see <a href="http://msdn2.microsoft.com/en-us/library/ms536390.aspx">MSDN Documentation</a> * @return an uninitialized event object */ - @JsxFunction(@WebBrowser(IE)) + @JsxFunction(@WebBrowser(value = IE, maxVersion = 9)) public Event createEventObject() { final Event event = new MouseEvent(); event.setParentScope(getWindow()); @@ -2047,7 +2050,7 @@ * @see <a href="http://msdn.microsoft.com/en-us/library/ms533065.aspx">MSDN documentation</a> * @return the value of the "activeElement" property */ - @JsxGetter({ @WebBrowser(IE), @WebBrowser(FF) }) + @JsxGetter public Object getActiveElement() { if (activeElement_ == null) { final HtmlElement body = getHtmlPage().getBody(); 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 2013-12-23 15:24:01 UTC (rev 8904) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLElement.java 2013-12-23 15:28:37 UTC (rev 8905) @@ -14,7 +14,6 @@ */ package com.gargoylesoftware.htmlunit.javascript.host.html; -import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.GENERATED_65; 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; @@ -534,33 +533,18 @@ * {@inheritDoc} */ @Override - public String getNamespaceURI() { - final HtmlElement domNode = getDomNodeOrDie(); - if (getBrowserVersion().hasFeature(GENERATED_65)) { - return domNode.getNamespaceURI(); - } - if (domNode.getHtmlPageOrNull() != null) { - return null; - } - return domNode.getNamespaceURI(); - } - - /** - * {@inheritDoc} - */ - @Override public String getLocalName() { final DomNode domNode = getDomNodeOrDie(); if (domNode.getHtmlPageOrNull() != null) { final String prefix = domNode.getPrefix(); if (prefix != null) { // create string builder only if needed (performance) - final StringBuilder localName = new StringBuilder(prefix.toUpperCase(Locale.ENGLISH)); + final StringBuilder localName = new StringBuilder(prefix.toLowerCase(Locale.ENGLISH)); localName.append(':'); - localName.append(domNode.getLocalName().toUpperCase(Locale.ENGLISH)); + localName.append(domNode.getLocalName().toLowerCase(Locale.ENGLISH)); return localName.toString(); } - return domNode.getLocalName().toUpperCase(Locale.ENGLISH); + return domNode.getLocalName().toLowerCase(Locale.ENGLISH); } return domNode.getLocalName(); } @@ -1136,7 +1120,7 @@ * @param append append or no */ public ProxyDomNode(final SgmlPage page, final DomNode target, final boolean append) { - super(null, HtmlDivision.TAG_NAME, page, null); + super(HtmlDivision.TAG_NAME, page, null); target_ = target; append_ = append; } @@ -1851,6 +1835,9 @@ @JsxGetter(@WebBrowser(value = IE, maxVersion = 9)) public String getTagUrn() { final String urn = getDomNodeOrDie().getNamespaceURI(); + if (HTMLParser.XHTML_NAMESPACE.equals(urn)) { + return ""; + } return urn != null ? urn : ""; } @@ -2797,7 +2784,7 @@ * Gets the token list of class attribute. * @return the token list of class attribute */ - @Override + @JsxGetter({ @WebBrowser(CHROME), @WebBrowser(FF), @WebBrowser(value = IE, minVersion = 11) }) public DOMTokenList getClassList() { return new DOMTokenList(this, "class"); } @@ -2833,7 +2820,7 @@ * {@inheritDoc} Overridden to modify browser configurations. */ @Override - @JsxGetter(@WebBrowser(IE)) + @JsxGetter({ @WebBrowser(CHROME), @WebBrowser(IE) }) public HTMLCollection getChildren() { return super.getChildren(); } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/ClickableElementTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/ClickableElementTest.java 2013-12-23 15:24:01 UTC (rev 8904) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/ClickableElementTest.java 2013-12-23 15:28:37 UTC (rev 8905) @@ -14,6 +14,8 @@ */ package com.gargoylesoftware.htmlunit.html; +import static com.gargoylesoftware.htmlunit.BrowserRunner.Browser.CHROME; + import java.util.ArrayList; import java.util.List; @@ -22,6 +24,7 @@ import com.gargoylesoftware.htmlunit.BrowserRunner; import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; +import com.gargoylesoftware.htmlunit.BrowserRunner.BuggyWebDriver; import com.gargoylesoftware.htmlunit.CollectingAlertHandler; import com.gargoylesoftware.htmlunit.MockWebConnection; import com.gargoylesoftware.htmlunit.SimpleWebTestCase; @@ -35,6 +38,7 @@ * @author Chris Erskine * @author Marc Guillemot * @author Ahmed Ashour + * @author Frank Danek */ @RunWith(BrowserRunner.class) public class ClickableElementTest extends SimpleWebTestCase { @@ -636,10 +640,13 @@ * @throws Exception if the test fails */ @Test - @Alerts(FF = { "foo", "foo" }, IE8 = { "foo", "foo" }, IE = "foo") + @Alerts(DEFAULT = "foo", + IE = "") + @BuggyWebDriver(CHROME) + // ChromeDriver does not generate a "foo" but it occurs manually public void option_onClick() throws Exception { final String htmlContent = "<html><head><title>foo</title></head>\n" - + "<body><form><select><option id='clickId' onClick='alert(\"foo\")'>\n" + + "<body><form><select size='2'><option id='clickId' onClick='alert(\"foo\")'>\n" + "Option</option></select></form></body>\n" + "</html>"; Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/DomNodeListTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/DomNodeListTest.java 2013-12-23 15:24:01 UTC (rev 8904) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/DomNodeListTest.java 2013-12-23 15:28:37 UTC (rev 8905) @@ -28,6 +28,7 @@ * * @version $Revision$ * @author <a href="mailto:tom...@un...">Tom Anderson</a> + * @author Frank Danek */ @RunWith(BrowserRunner.class) public class DomNodeListTest extends SimpleWebTestCase { @@ -51,7 +52,7 @@ assertEquals(3, divs.getLength()); validateDomNodeList(divs); - final HtmlDivision newDiv = new HtmlDivision(null, HtmlDivision.TAG_NAME, page, null); + final HtmlDivision newDiv = new HtmlDivision(HtmlDivision.TAG_NAME, page, null); page.getBody().appendChild(newDiv); assertEquals(4, divs.getLength()); validateDomNodeList(divs); Added: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HTMLParser4Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HTMLParser4Test.java (rev 0) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HTMLParser4Test.java 2013-12-23 15:28:37 UTC (rev 8905) @@ -0,0 +1,441 @@ +/* + * Copyright (c) 2002-2013 Gargoyle Software Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.gargoylesoftware.htmlunit.html; + +import static com.gargoylesoftware.htmlunit.BrowserRunner.Browser.CHROME; +import static com.gargoylesoftware.htmlunit.BrowserRunner.Browser.FF; +import static com.gargoylesoftware.htmlunit.BrowserRunner.Browser.IE11; + +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.BuggyWebDriver; +import com.gargoylesoftware.htmlunit.BrowserRunner.NotYetImplemented; +import com.gargoylesoftware.htmlunit.WebDriverTestCase; + +/** + * Test class for {@link HTMLParser}. + * + * @version $Revision$ + * @author <a href="mailto:cs...@dy...">Christian Sell</a> + * @author Marc Guillemot + * @author Ahmed Ashour + * @author Sudhan Moghe + * @author Frank Danek + */ +@RunWith(BrowserRunner.class) +public class HTMLParser4Test extends WebDriverTestCase { + + /** + * Tests that inserted TBODY and TFOOT don't conflict. + * @throws Exception failure + */ + @Test + @Alerts("TABLE") + public void table_tfoot() throws Exception { + final String html = "<html><body>" + + "<table><tr><td>hello</td></tr>\n" + + "<tfoot id='tf'><tr><td>foot</td></tr></tfoot>" + + "</table>\n" + + "<script>\n" + + "alert(document.getElementById('tf').parentNode.nodeName)\n" + + "</script>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } + + /** + * Test for the condition when there is a <tt><form></tt> inside of a <tt><table></tt> and before + * a <tt><tr></tt>. + * @throws Exception failure + */ + @Test + @Alerts("myForm") + public void badlyFormedHTML() throws Exception { + final String html + = "<html><head><title>first</title>\n" + + " <script>\n" + + " function test(){\n" + + " alert(document.getElementById('myInput').form.id);\n" + + " }\n" + + " </script>\n" + + "</head>\n" + + "<body onload='test()'>\n" + + " <table>\n" + + " <form name='myForm' action='foo' id='myForm'>\n" + + " <tr><td>\n" + + " <input type='text' name='myInput' id='myInput'/>\n" + + " </td></tr>\n" + + " </form>\n" + + " </table>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } + + /** + * Test when an illegal tag is found in head as some websites do. + * @throws Exception failure + */ + @Test + @Alerts("first") + public void unknownTagInHead() throws Exception { + // Note: the <meta> tag in this test is quite important because + // I could adapt the TagBalancer to make it work except with this <meta http-equiv... + // (it worked with <meta name=...) + final String html + = "<html><head><mainA3>\n" + + " <meta http-equiv='Content-Type' content='text/html; charset=ISO-8859-1'>\n" + + " <title>first</title>\n" + + " <script>\n" + + " function test(){\n" + + " alert(document.title);\n" + + " }\n" + + " </script>\n" + + "</head>\n" + + "<body onload='test()'>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } + + /** + * @throws Exception failure + */ + @Test + @Alerts({"false", "true" }) + public void duplicatedAttribute() throws Exception { + final String html + = "<html><head>\n" + + "</head>\n" + + " <script>\n" + + " function test() {\n" + + " alert(document.getElementById('foo') == null);\n" + + " alert(document.getElementById('bla') == null);\n" + + " }\n" + + " </script>\n" + + "</head>\n" + + "<body onload='test()'>\n" + + " <span id='foo' id='bla'></span>" + + "</body></html>"; + + loadPageWithAlerts2(html); + } + + /** + * @throws Exception failure + */ + @Test + @Alerts(DEFAULT = { "1", "3", "[object HTMLScriptElement]", + "[object HTMLUnknownElement]", "[object HTMLUnknownElement]", "[object HTMLFormElement]" }, + IE8 = { "1", "3", "[object HTMLScriptElement]", + "[object HTMLGenericElement]", "[object HTMLGenericElement]", "[object HTMLFormElement]" }) + public void namespace() throws Exception { + final String html + = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">\n" + + "<html xmlns='http://www.w3.org/1999/xhtml' xmlns:app='http://www.appcelerator.org'>\n" + + "<head>\n" + + "<script>\n" + + " function test() {\n" + + " alert(document.getElementById('script1'));\n" + + " alert(document.getElementById('script2'));\n" + + " alert(document.getElementById('message1'));\n" + + " alert(document.getElementById('form1'));\n" + + " }\n" + + "</script>\n" + + "</head>\n" + + "<body onload='test()'>\n" + + "<script id='script1'>alert(1)</script>\n" + + "<app:script id='script2'>alert(2)</app:script>\n" + + "<script>alert(3)</script>\n" + + "<app:message name='r:tasks.request' id='message1'>hello</app:message>\n" + + "<form id='form1' xmlns='http://org.pentaho'/>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } + + /** + * @throws Exception failure + */ + @Test + @Alerts(DEFAULT = { "1", + "[object Element]", "app:script,app:script,http://www.appcelerator.org,app,script", + "[object HTMLScriptElement]", "SCRIPT,SCRIPT,http://www.w3.org/1999/xhtml,null,script", + "[object HTMLUnknownElement]", "APP:SCRIPT,APP:SCRIPT,http://www.w3.org/1999/xhtml,null,app:script" }, + IE8 = { "1", + "createElementNS() is not defined", + "[object]", "SCRIPT,SCRIPT,undefined,undefined,undefined", + "[object]", "script,script,undefined,undefined,undefined" }) + public void namespace2() throws Exception { + final String html + = "<html xmlns='http://www.w3.org/1999/xhtml' xmlns:app='http://www.appcelerator.org'>\n" + + "<head>\n" + + "<script>\n" + + " function test() {\n" + + " try {\n" + + " div = document.createElementNS('http://www.appcelerator.org', 'app:script');\n" + + " debug(div);\n" + + " } catch (e) {alert('createElementNS() is not defined')}\n" + + " debug(document.getElementById('script1'));\n" + + " debug(document.getElementById('script2'));\n" + + " }\n" + + " function debug(e) {\n" + + " alert(e);\n" + + " alert(e.nodeName + ',' + e.tagName + ',' + e.namespaceURI + ',' + e.prefix + ',' + e.localName);\n" + + " }\n" + + "</script>\n" + + "</head>\n" + + "<body onload='test()'>\n" + + "<script id='script1'>alert(1)</script>\n" + + "<app:script id='script2'>alert(2)</app:script>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } + + /** + * Test for a case where complete HTML page is present inside DIV tag. + * IE8 ignores the HTML tag, BODY tag and complete HEAD along with content inside HEAD. + * Others ignores only HTML, HEAD and BODY tags. Contents of HEAD and BODY are added to + * the current node (DIV tag in test case). + * + * @throws Exception failure + */ + @Test + @Alerts(DEFAULT = { "titles", "HEAD", "Outer Html", "DIV", "Inner Html", + "bodyTitles", "DIV", "Inner Html", + "innerDiv", "outerDiv" }, + IE8 = { "titles", "HEAD", "Outer Html", + "bodyTitles", + "innerDiv", "outerDiv" }) + @BuggyWebDriver(IE11) + // The correct values for IE11 are: + // IE11 = { "titles", "HEAD", "Outer Html", "DIV", "", + // "bodyTitles", "DIV", "", + // "innerDiv", "outerDiv" }) + // This is pretty mysterious because the second title HAS the text 'Inner Html' inside. + // Currently I do not know why it behaves this way so I take the default behavior. + public void completeHtmlInsideDiv() throws Exception { + final String html + = "<html><head>\n" + + " <title>Outer Html</title>\n" + + " <script>\n" + + " function test() {\n" + + " alert('titles');\n" + + " var titles = document.getElementsByTagName('title');\n" + + " for(var i=0; i < titles.length; ++i) {\n" + + " alert(titles[i].parentNode.nodeName);\n" + + " alert(titles[i].text);\n" + + " }\n" + + " alert('bodyTitles');\n" + + " var bodyTitles = document.body.getElementsByTagName('title');\n" + + " for(var i=0; i < bodyTitles.length; ++i) {\n" + + " alert(bodyTitles[i].parentNode.nodeName);\n" + + " alert(bodyTitles[i].text);\n" + + " }\n" + + " alert('innerDiv');\n" + + " var innerDiv = document.getElementById('innerDiv');\n" + + " alert(innerDiv.parentNode.id);\n" + + " }\n" + + " </script>\n" + + "</head>\n" + + "<body onload='test()'>\n" + + " <DIV id=outerDiv>\n" + + " Outer DIV\n" + + " <html>\n" + + " <head><title>Inner Html</title></head>\n" + + " <body>\n" + + " <DIV id=innerDiv>Inner DIV</DIV>\n" + + " </body>\n" + + " </html>\n" + + " </DIV>\n" + + "</body>\n" + + "</html>\n"; + + loadPageWithAlerts2(html); + } + + /** + * Test for a case where complete HTML page is added using document.write() inside DIV tag. + * IE8 ignores the HTML tag, BODY tag and complete HEAD along with content inside HEAD. + * Others ignores only HTML, HEAD and BODY tags. Contents of HEAD and BODY are added to + * the current node (DIV tag in test case). + * + * @throws Exception failure + */ + @Test + @Alerts(DEFAULT = { "titles", "HEAD", "Outer Html", "DIV", "Inner Html", + "bodyTitles", "DIV", "Inner Html", + "innerDiv", "outerDiv" }, + IE8 = { "titles", "HEAD", "Outer Html", + "bodyTitles", + "innerDiv", "outerDiv" }) + @BuggyWebDriver(IE11) + // The correct values for IE11 are: + // IE11 = { "titles", "HEAD", "Outer Html", "DIV", "", + // "bodyTitles", "DIV", "", + // "innerDiv", "outerDiv" }) + // This is pretty mysterious because the second title HAS the text 'Inner Html' inside. + // Currently I do not know why it behaves this way so I take the default behavior. + public void writeCompleteHtmlInsideDIV() throws Exception { + final String html + = "<html><head>\n" + + " <title>Outer Html</title>\n" + + " <script>\n" + + " function test() {\n" + + " alert('titles');\n" + + " var titles = document.getElementsByTagName('title');\n" + + " for(var i=0; i < titles.length; ++i) {\n" + + " alert(titles[i].parentNode.nodeName);\n" + + " alert(titles[i].text);\n" + + " }\n" + + " alert('bodyTitles');\n" + + " var bodyTitles = document.body.getElementsByTagName('title');\n" + + " for(var i=0; i < bodyTitles.length; ++i) {\n" + + " alert(bodyTitles[i].parentNode.nodeName);\n" + + " alert(bodyTitles[i].text);\n" + + " }\n" + + " alert('innerDiv');\n" + + " var innerDiv = document.getElementById('innerDiv');\n" + + " alert(innerDiv.parentNode.id);\n" + + " }\n" + + " </script>\n" + + "</head>\n" + + "<body onload='test()'>\n" + + " <DIV id=outerDiv>\n" + + " Outer DIV\n" + + " <script>\n" + + " document.write('<html><head><title>Inner Html</title></head>" + + " <body><DIV id=innerDiv>Inner DIV</DIV></body></html>');\n" + + " </script>\n" + + " </DIV>\n" + + "</body>\n" + + "</html>\n"; + + loadPageWithAlerts2(html); + } + + /** + * Test for a case where complete HTML page is set in innerHTML of DIV tag. + * Behavior is same for any TAG inside body including BODY tag. + * IE8 ignores the HTML tag, BODY tag and complete HEAD along with content inside HEAD. + * Others ignores only HTML, HEAD and BODY tags. Contents of HEAD and BODY are added to + * the current node (DIV tag in test case). + * + * @throws Exception failure + */ + @Test + @Alerts(DEFAULT = { "titles", "HEAD", "Outer Html", "DIV", "Inner Html", + "bodyTitles", "DIV", "Inner Html", + "innerDiv", "outerDiv" }, + IE8 = { "titles", "HEAD", "Outer Html", + "bodyTitles", + "innerDiv", "outerDiv" }) + public void setCompleteHtmlToDIV_innerHTML() throws Exception { + final String html + = "<html><head>\n" + + " <title>Outer Html</title>\n" + + " <script>\n" + + " function test() {\n" + + " alert('titles');\n" + + " var titles = document.getElementsByTagName('title');\n" + + " for(var i=0; i < titles.length; ++i) {\n" + + " alert(titles[i].parentNode.nodeName);\n" + + " alert(titles[i].text);\n" + + " }\n" + + " alert('bodyTitles');\n" + + " var bodyTitles = document.body.getElementsByTagName('title');\n" + + " for(var i=0; i < bodyTitles.length; ++i) {\n" + + " alert(bodyTitles[i].parentNode.nodeName);\n" + + " alert(bodyTitles[i].text);\n" + + " }\n" + + " alert('innerDiv');\n" + + " var innerDiv = document.getElementById('innerDiv');\n" + + " alert(innerDiv.parentNode.id);\n" + + " }\n" + + " </script>\n" + + "</head>\n" + + "<body onload='test()'>\n" + + " <DIV id=outerDiv>\n" + + " Outer DIV\n" + + " </DIV>\n" + + " <script>\n" + + " document.getElementById('outerDiv').innerHTML =" + + " '<html><head><title>Inner Html</title></head>" + + " <body><DIV id=innerDiv>Inner DIV</DIV></body></html>';\n" + + " </script>\n" + + "</body>\n" + + "</html>\n"; + + loadPageWithAlerts2(html); + } + + /** + * Test for a case where complete HTML page is set in innerHTML of HTML tag. + * IE8 throws JavaScript error as innerHTML of HTML is read only. + * Others replace the current content of the HTML node by the new one. + * + * @throws Exception failure + */ + @Test + @Alerts(DEFAULT = { "titles", "HEAD", "Inner Html", + "misc", "true", "BODY" }, + IE8 = { "exception", + "titles", "HEAD", "Outer Html", + "misc", "true" }) + @NotYetImplemented({ CHROME, FF, IE11 }) + // currently the content of HEAD and BODY are added directly to HTML + public void setCompleteHtmlToHTML_innerHTML() throws Exception { + final String html + = "<html><head>\n" + + " <title>Outer Html</title>\n" + + " <script>\n" + + " function test() {\n" + + " alert('titles');\n" + + " var titles = document.getElementsByTagName('title');\n" + + " for(var i=0; i < titles.length; ++i) {\n" + + " alert(titles[i].parentNode.nodeName);\n" + + " alert(titles[i].text);\n" + + " }\n" + + " alert('misc');\n" + + " alert(document.body != null);\n" + + " var innerDiv = document.getElementById('innerDiv');\n" + + " if (innerDiv != null) {\n" + + " alert(innerDiv.parentNode.nodeName);\n" + + " }\n" + + " }\n" + + " </script>\n" + + "</head>\n" + + "<body onload='test()'>\n" + + " <DIV id=outerDiv>\n" + + " Outer DIV\n" + + " </DIV>\n" + + "<script>\n" + + " try {\n" + + " document.getElementsByTagName('html')[0].innerHTML =" + + " '<html><head><title>Inner Html</title></head>" + + " <body><DIV id=innerDiv>Inner DIV</DIV></body></html>';\n" + + " } catch(e) { alert('exception') }\n" + + "</script>\n" + + "</body>\n" + + "</html>\n"; + + loadPageWithAlerts2(html); + } +} Property changes on: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HTMLParser4Test.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/html/HTMLParserTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HTMLParserTest.java 2013-12-23 15:24:01 UTC (rev 8904) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HTMLParserTest.java 2013-12-23 15:28:37 UTC (rev 8905) @@ -14,7 +14,6 @@ */ package com.gargoylesoftware.htmlunit.html; -import static com.gargoylesoftware.htmlunit.BrowserRunner.Browser.IE; import static org.junit.Assert.assertNotNull; import java.net.URL; @@ -23,8 +22,6 @@ 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.SimpleWebTestCase; import com.gargoylesoftware.htmlunit.StringWebResponse; import com.gargoylesoftware.htmlunit.WebClient; @@ -38,6 +35,7 @@ * @author Marc Guillemot * @author Ahmed Ashour * @author Sudhan Moghe + * @author Frank Danek */ @RunWith(BrowserRunner.class) public class HTMLParserTest extends SimpleWebTestCase { @@ -62,80 +60,6 @@ } /** - * Tests that inserted TBODY and TFOOT don't conflict. - * @throws Exception failure - */ - @Test - @Alerts("TABLE") - public void table_tfoot() throws Exception { - final String html = "<html><body>" - + "<table><tr><td>hello</td></tr>\n" - + "<tfoot id='tf'><tr><td>foot</td></tr></tfoot>" - + "</table>\n" - + "<script>\n" - + "alert(document.getElementById('tf').parentNode.nodeName)\n" - + "</script>\n" - + "</body></html>"; - - loadPageWithAlerts(html); - } - - /** - * Test for the condition when there is a <tt><form></tt> inside of a <tt><table></tt> and before - * a <tt><tr></tt>. - * @throws Exception failure - */ - @Test - @Alerts("myForm") - public void badlyFormedHTML() throws Exception { - final String html - = "<html><head><title>first</title>\n" - + " <script>\n" - + " function test(){\n" - + " alert(document.getElementById('myInput').form.id);\n" - + " }\n" - + " </script>\n" - + "</head>\n" - + "<body onload='test()'>\n" - + " <table>\n" - + " <form name='myForm' action='foo' id='myForm'>\n" - + " <tr><td>\n" - + " <input type='text' name='myInput' id='myInput'/>\n" - + " </td></tr>\n" - + " </form>\n" - + " </table>\n" - + "</body></html>"; - - loadPageWithAlerts(html); - } - - /** - * Test when an illegal tag is found in head as some websites do. - * @throws Exception failure - */ - @Test - @Alerts("first") - public void unknownTagInHead() throws Exception { - // Note: the <meta> tag in this test is quite important because - // I could adapt the TagBalancer to make it work except with this <meta http-equiv... - // (it worked with <meta name=...) - final String html - = "<html><head><mainA3>\n" - + " <meta http-equiv='Content-Type' content='text/html; charset=ISO-8859-1'>\n" - + " <title>first</title>\n" - + " <script>\n" - + " function test(){\n" - + " alert(document.title);\n" - + " }\n" - + " </script>\n" - + "</head>\n" - + "<body onload='test()'>\n" - + "</body></html>"; - - loadPageWithAlerts(html); - } - - /** * Works since NekoHtml 0.9.5. * @exception Exception If the test fails */ @@ -149,290 +73,6 @@ } /** - * @throws Exception failure - */ - @Test - @Alerts({"false", "true" }) - public void duplicatedAttribute() throws Exception { - final String html - = "<html><head>\n" - + "</head>\n" - + " <script>\n" - + " function test() {\n" - + " alert(document.getElementById('foo') == null);\n" - + " alert(document.getElementById('bla') == null);\n" - + " }\n" - + " </script>\n" - + "</head>\n" - + "<body onload='test()'>\n" - + " <span id='foo' id='bla'></span>" - + "</body></html>"; - - loadPageWithAlerts(html); - } - - /** - * @throws Exception failure - */ - @Test - @Alerts(IE = {"1", "3", "[object HTMLScriptElement]", - "[object HTMLGenericElement]", "[object HTMLGenericElement]", "[object HTM... [truncated message content] |