From: <rb...@us...> - 2013-12-12 18:55:32
|
Revision: 8838 http://sourceforge.net/p/htmlunit/code/8838 Author: rbri Date: 2013-12-12 18:55:29 +0000 (Thu, 12 Dec 2013) Log Message: ----------- first huge implementation step forward to support IE11 [Frank Danek] this introduces a completely separate implementation of the MSXMLActiveXObject (IE11 supports this AND a build in one) Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLDocument.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLHttpRequest.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLSerializer.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLDocument2Test.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLDocumentTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLHttpRequest2Test.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLHttpRequestCORSTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLHttpRequestTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLSerializerTest.java Added Paths: ----------- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/activex/javascript/msxml/MSXMLActiveXObjectFactoryTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/activex/javascript/msxml/MSXMLTestUtil.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/activex/javascript/msxml/XMLDOMAttributeTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/activex/javascript/msxml/XMLDOMCDATASectionTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/activex/javascript/msxml/XMLDOMCommentTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/activex/javascript/msxml/XMLDOMDocument2Test.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/activex/javascript/msxml/XMLDOMDocument3Test.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/activex/javascript/msxml/XMLDOMDocumentFragmentTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/activex/javascript/msxml/XMLDOMDocumentTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/activex/javascript/msxml/XMLDOMDocumentTypeTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/activex/javascript/msxml/XMLDOMElementTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/activex/javascript/msxml/XMLDOMImplementationTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/activex/javascript/msxml/XMLDOMNamedNodeMapTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/activex/javascript/msxml/XMLDOMNodeListTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/activex/javascript/msxml/XMLDOMParseErrorTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/activex/javascript/msxml/XMLDOMProcessingInstructionTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/activex/javascript/msxml/XMLDOMTextTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/activex/javascript/msxml/XMLHTTPRequestTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/activex/javascript/msxml/XMLSerializerTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/activex/javascript/msxml/XSLProcessorTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/activex/javascript/msxml/package.html Removed Paths: ------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLAttr.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLDOMParseError.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLDomParserErrorTest.java Deleted: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLAttr.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLAttr.java 2013-12-12 18:54:25 UTC (rev 8837) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLAttr.java 2013-12-12 18:55:29 UTC (rev 8838) @@ -1,80 +0,0 @@ -/* - * Copyright (c) 2002-2013 Gargoyle Software Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.gargoylesoftware.htmlunit.javascript.host.xml; - -import static com.gargoylesoftware.htmlunit.javascript.configuration.BrowserName.IE; - -import com.gargoylesoftware.htmlunit.javascript.configuration.JsxClass; -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.Attr; -import com.gargoylesoftware.htmlunit.util.StringUtils; - -/** - * A JavaScript object for an Attribute of XMLElement. - * - * @see <a href="http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#ID-63764602">W3C DOM Level 2</a> - * @see <a href="http://msdn.microsoft.com/en-us/library/ms762738.aspx">MSDN documentation</a> - * @version $Revision$ - * @author Sudhan Moghe - */ -@JsxClass -public class XMLAttr extends Attr { - - /** - * Creates an instance. JavaScript objects must have a default constructor. - */ - public XMLAttr() { } - - /** - * Returns the text of this attribute. - * @return the value of this attribute - */ - @JsxGetter(@WebBrowser(IE)) - public String getText() { - return getValue(); - } - - /** - * Sets the text of this attribute. - * @param value the new value of this attribute - */ - @JsxSetter(@WebBrowser(IE)) - public void setText(final String value) { - setValue(value); - } - - /** - * Returns the base name of this element. - * @return the base name of this element - */ - @JsxGetter(@WebBrowser(IE)) - public Object getBaseName() { - return getDomNodeOrDie().getLocalName(); - } - - /** - * {@inheritDoc} - */ - @Override - public String getXml() { - final StringBuilder sb = new StringBuilder(getName()); - sb.append('=').append('"'); - sb.append(StringUtils.escapeXmlAttributeValue(getValue())); - sb.append('"'); - return sb.toString(); - } -} Deleted: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLDOMParseError.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLDOMParseError.java 2013-12-12 18:54:25 UTC (rev 8837) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLDOMParseError.java 2013-12-12 18:55:29 UTC (rev 8838) @@ -1,132 +0,0 @@ -/* - * Copyright (c) 2002-2013 Gargoyle Software Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.gargoylesoftware.htmlunit.javascript.host.xml; - -import static com.gargoylesoftware.htmlunit.javascript.configuration.BrowserName.IE; - -import com.gargoylesoftware.htmlunit.javascript.SimpleScriptable; -import com.gargoylesoftware.htmlunit.javascript.configuration.JsxClass; -import com.gargoylesoftware.htmlunit.javascript.configuration.JsxGetter; -import com.gargoylesoftware.htmlunit.javascript.configuration.WebBrowser; - -/** - * A JavaScript object for XMLDOMParseError. - * @see <a href="http://msdn2.microsoft.com/en-us/library/ms757019.aspx">MSDN documentation</a> - * - * @version $Revision$ - * @author Ahmed Ashour - */ -@JsxClass(browsers = @WebBrowser(IE)) -public class XMLDOMParseError extends SimpleScriptable { - - private int errorCode_; - private int filepos_; - private int line_; - private int linepos_; - private String reason_ = ""; - private String srcText_ = ""; - private String url_ = ""; - - /** - * Returns the error code of the last parse error. - * @return the error code of the last parse error - */ - @JsxGetter - public int getErrorCode() { - return errorCode_; - } - - /** - * Returns the absolute file position where the error occurred. - * @return the absolute file position where the error occurred - */ - @JsxGetter - public int getFilepos() { - return filepos_; - } - - /** - * Returns the line number that contains the error. - * @return the line number that contains the error - */ - @JsxGetter - public int getLine() { - return line_; - } - - /** - * Returns the character position within the line where the error occurred. - * @return the character position within the line where the error occurred - */ - @JsxGetter - public int getLinepos() { - return linepos_; - } - - /** - * Returns the reason for the error. - * @return the reason for the error - */ - @JsxGetter - public String getReason() { - return reason_; - } - - /** - * Returns the full text of the line containing the error. - * @return the full text of the line containing the error - */ - @JsxGetter - public String getSrcText() { - return srcText_; - } - - /** - * Returns the URL of the XML document containing the last error. - * @return the URL of the XML document containing the last error - */ - @JsxGetter - public String getUrl() { - return url_; - } - - void setErrorCode(final int errorCode) { - errorCode_ = errorCode; - } - - void setFilepos(final int filepos) { - filepos_ = filepos; - } - - void setLine(final int line) { - line_ = line; - } - - void setLinepos(final int linepos) { - linepos_ = linepos; - } - - void setReason(final String reason) { - reason_ = reason; - } - - void setSrcText(final String srcText) { - srcText_ = srcText; - } - - void setUrl(final String url) { - url_ = url; - } -} Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLDocument.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLDocument.java 2013-12-12 18:54:25 UTC (rev 8837) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLDocument.java 2013-12-12 18:55:29 UTC (rev 8838) @@ -14,24 +14,18 @@ */ package com.gargoylesoftware.htmlunit.javascript.host.xml; -import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_XML_ATTRIBUTE_HAS_TEXT_PROPERTY; +import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_DOCUMENT_CLASS_NAME; 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 java.io.IOException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; import net.sourceforge.htmlunit.corejs.javascript.Context; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.w3c.dom.Node; -import com.gargoylesoftware.htmlunit.SgmlPage; import com.gargoylesoftware.htmlunit.StringWebResponse; import com.gargoylesoftware.htmlunit.WebRequest; import com.gargoylesoftware.htmlunit.WebResponse; @@ -65,15 +59,12 @@ * @author Chuck Dumont * @author Frank Danek */ -@JsxClass(browsers = { @WebBrowser(FF), @WebBrowser(value = IE, minVersion = 10) }) +@JsxClass(browsers = { @WebBrowser(CHROME), @WebBrowser(FF), @WebBrowser(value = IE, minVersion = 11) }) public class XMLDocument extends Document { private static final Log LOG = LogFactory.getLog(XMLDocument.class); private boolean async_ = true; - private boolean preserveWhiteSpace_; - private XMLDOMParseError parseError_; - private Map<String, String> properties_ = new HashMap<String, String>(); /** * Creates a new instance. JavaScript objects must have a default constructor. @@ -99,10 +90,23 @@ } /** + * {@inheritDoc} + */ + @Override + public String getClassName() { + if (getWindow().getWebWindow() != null) { + if (getBrowserVersion().hasFeature(JS_DOCUMENT_CLASS_NAME)) { + return "Document"; + } + } + return super.getClassName(); + } + + /** * Sets the <tt>async</tt> attribute. * @param async Whether or not to send the request to the server asynchronously */ - @JsxSetter + @JsxSetter(@WebBrowser(FF)) public void setAsync(final boolean async) { async_ = async; } @@ -111,7 +115,7 @@ * Returns Whether or not to send the request to the server asynchronously. * @return the <tt>async</tt> attribute */ - @JsxGetter + @JsxGetter(@WebBrowser(FF)) public boolean getAsync() { return async_; } @@ -122,7 +126,7 @@ * @param xmlSource a string containing a URL that specifies the location of the XML file * @return true if the load succeeded; false if the load failed */ - @JsxFunction + @JsxFunction(@WebBrowser(FF)) public boolean load(final String xmlSource) { if (async_) { if (LOG.isDebugEnabled()) { @@ -138,14 +142,6 @@ return true; } catch (final IOException e) { - final XMLDOMParseError parseError = getParseError(); - parseError.setErrorCode(-1); - parseError.setFilepos(1); - parseError.setLine(1); - parseError.setLinepos(1); - parseError.setReason(e.getMessage()); - parseError.setSrcText("xml"); - parseError.setUrl(xmlSource); if (LOG.isDebugEnabled()) { LOG.debug("Error parsing XML from '" + xmlSource + "'", e); } @@ -160,7 +156,6 @@ * This string can contain an entire XML document or a well-formed fragment. * @return true if the load succeeded; false if the load failed */ - @JsxFunction({ @WebBrowser(IE), @WebBrowser(CHROME) }) public boolean loadXML(final String strXML) { try { final WebWindow webWindow = getWindow().getWebWindow(); @@ -191,12 +186,7 @@ scriptable = new Element(); } else if (domNode instanceof DomAttr) { - if (getPage().getWebClient().getBrowserVersion().hasFeature(JS_XML_ATTRIBUTE_HAS_TEXT_PROPERTY)) { - scriptable = new XMLAttr(); - } - else { - scriptable = new Attr(); - } + scriptable = new Attr(); } else { return super.makeScriptableFor(domNode); @@ -217,115 +207,10 @@ } /** - * Gets the JavaScript property "parseError" for the document. - * @return the ParserError object for the document - */ - @JsxGetter({ @WebBrowser(IE), @WebBrowser(CHROME) }) - public XMLDOMParseError getParseError() { - if (parseError_ == null) { - parseError_ = new XMLDOMParseError(); - parseError_.setPrototype(getPrototype(parseError_.getClass())); - parseError_.setParentScope(getParentScope()); - } - return parseError_; - } - - /** - * Contains the XML representation of the node and all its descendants. - * @return an XML representation of this node and all its descendants - */ - @Override - @JsxGetter({ @WebBrowser(IE), @WebBrowser(CHROME) }) - public String getXml() { - final XMLSerializer seralizer = new XMLSerializer(); - seralizer.setParentScope(getWindow()); - seralizer.setPrototype(getPrototype(seralizer.getClass())); - return seralizer.serializeToString(getDocumentElement()); - } - - /** - * Gets the current white space handling. - * @return the current white space handling - */ - @JsxGetter({ @WebBrowser(IE), @WebBrowser(CHROME) }) - public boolean getPreserveWhiteSpace() { - return preserveWhiteSpace_; - } - - /** - * Specifies the white space handling. - * @param preserveWhiteSpace white space handling - */ - @JsxSetter({ @WebBrowser(IE), @WebBrowser(CHROME) }) - public void setPreserveWhiteSpace(final boolean preserveWhiteSpace) { - preserveWhiteSpace_ = preserveWhiteSpace; - } - - /** - * This method is used to set - * <a href="http://msdn2.microsoft.com/en-us/library/ms766391.aspx">second-level properties</a> - * on the DOM object. - * - * @param name the name of the property to be set - * @param value the value of the specified property - */ - @JsxFunction({ @WebBrowser(IE), @WebBrowser(CHROME) }) - public void setProperty(final String name, final String value) { - properties_.put(name, value); - } - - /** - * Returns the value of the property set by {@link #setProperty(String, String)}. - * - * @param name the name of the property to get - * @return the property value - */ - @JsxFunction({ @WebBrowser(IE), @WebBrowser(CHROME) }) - public String getProperty(final String name) { - return properties_.get(name); - } - - /** - * Applies the specified XPath expression to this node's context and returns the generated list of matching nodes. - * @param expression a string specifying an XPath expression - * @return list of the found elements - */ - @JsxFunction({ @WebBrowser(IE), @WebBrowser(CHROME) }) - public HTMLCollection selectNodes(final String expression) { - final boolean attributeChangeSensitive = expression.contains("@"); - final String description = "XMLDocument.selectNodes('" + expression + "')"; - final SgmlPage page = getPage(); - final HTMLCollection collection = new HTMLCollection(page.getDocumentElement(), - attributeChangeSensitive, description) { - @Override - protected List<Object> computeElements() { - final List<Object> list = new ArrayList<Object>(page.getByXPath(expression)); - return list; - } - }; - return collection; - } - - /** - * Applies the specified pattern-matching operation to this node's context and returns the first matching node. - * @param expression a string specifying an XPath expression - * @return the first node that matches the given pattern-matching operation - * If no nodes match the expression, returns a null value. - */ - @JsxFunction({ @WebBrowser(IE), @WebBrowser(CHROME) }) - public Object selectSingleNode(final String expression) { - final HTMLCollection collection = selectNodes(expression); - if (collection.getLength() > 0) { - return collection.get(0, collection); - } - return null; - } - - /** * {@inheritDoc} */ @Override - @JsxFunction({ @WebBrowser(IE), @WebBrowser(CHROME) }) + @JsxFunction public HTMLCollection getElementsByTagName(final String tagName) { final DomNode firstChild = getDomNodeOrDie().getFirstChild(); if (firstChild == null) { @@ -366,16 +251,6 @@ } /** - * Since we are not processing DTD, this method always returns null. - * @param id the ID to search for - * @return null - */ - @JsxFunction({ @WebBrowser(IE), @WebBrowser(CHROME) }) - public Object nodeFromID(final String id) { - return null; - } - - /** * Creates a new ProcessingInstruction. * @param target the target * @param data the data @@ -397,28 +272,4 @@ final DomCDataSection node = ((XmlPage) getPage()).createCDATASection(data); return getScriptableFor(node); } - - /** - * Creates a node using the supplied type, name, and namespace. - * @param type a value that uniquely identifies the node type - * @param name the value for the new node's nodeName property - * @param namespaceURI A string defining the namespace URI. - * If specified, the node is created in the context of the namespaceURI parameter - * with the prefix specified on the node name. - * If the name parameter does not have a prefix, this is treated as the default namespace. - * @return the newly created node - */ - @JsxFunction({ @WebBrowser(IE), @WebBrowser(CHROME) }) - public Object createNode(final Object type, final String name, final Object namespaceURI) { - switch((short) Context.toNumber(type)) { - case Node.ELEMENT_NODE: - return createElementNS((String) namespaceURI, name); - case Node.ATTRIBUTE_NODE: - return createAttribute(name); - - default: - throw Context.reportRuntimeError("xmlDoc.createNode(): Unsupported type " - + (short) Context.toNumber(type)); - } - } } Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLHttpRequest.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLHttpRequest.java 2013-12-12 18:54:25 UTC (rev 8837) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLHttpRequest.java 2013-12-12 18:55:29 UTC (rev 8838) @@ -14,7 +14,6 @@ */ package com.gargoylesoftware.htmlunit.javascript.host.xml; -import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_XML_SUPPORT_VIA_ACTIVEXOBJECT; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.XHR_ERRORHANDLER_NOT_SUPPORTED; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.XHR_IGNORE_SAME_ORIGIN; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.XHR_IGNORE_SAME_ORIGIN_TO_ABOUT; @@ -23,6 +22,7 @@ import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.XHR_ONREADYSTATECHANGE_WITH_EVENT_PARAM; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.XHR_OPEN_ALLOW_EMTPY_URL; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.XHR_ORIGIN_HEADER; +import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.XHR_RESPONSE_XML_IS_ACTIVEXOBJECT; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.XHR_STATUS_THROWS_EXCEPTION_WHEN_UNSET; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.XHR_TRIGGER_ONLOAD_ON_COMPLETED; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.XHR_WITHCREDENTIALS_ALLOW_ORIGIN_ALL; @@ -61,6 +61,9 @@ import com.gargoylesoftware.htmlunit.WebClient; import com.gargoylesoftware.htmlunit.WebRequest; import com.gargoylesoftware.htmlunit.WebResponse; +import com.gargoylesoftware.htmlunit.WebWindow; +import com.gargoylesoftware.htmlunit.activex.javascript.msxml.MSXMLActiveXObjectFactory; +import com.gargoylesoftware.htmlunit.activex.javascript.msxml.XMLDOMDocument; import com.gargoylesoftware.htmlunit.html.HtmlPage; import com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine; import com.gargoylesoftware.htmlunit.javascript.SimpleScriptable; @@ -72,7 +75,6 @@ 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.ActiveXObject; import com.gargoylesoftware.htmlunit.javascript.host.Event; import com.gargoylesoftware.htmlunit.util.NameValuePair; import com.gargoylesoftware.htmlunit.util.WebResponseWrapper; @@ -88,6 +90,7 @@ * @author Stuart Begg * @author Ronald Brill * @author Sebastian Cato + * @author Frank Danek * * @see <a href="http://www.w3.org/TR/XMLHttpRequest/">W3C XMLHttpRequest</a> * @see <a href="http://developer.apple.com/internet/webcontent/xmlhttpreq.html">Safari documentation</a> @@ -237,7 +240,7 @@ * Returns the event handler that fires on load. * @return the event handler that fires on load */ - @JsxGetter({ @WebBrowser(value = IE, maxVersion = 6), @WebBrowser(FF) }) + @JsxGetter({ @WebBrowser(value = IE, minVersion = 11), @WebBrowser(FF) }) public Function getOnload() { return loadHandler_; } @@ -246,7 +249,7 @@ * Sets the event handler that fires on load. * @param loadHandler the event handler that fires on load */ - @JsxSetter({ @WebBrowser(value = IE, maxVersion = 6), @WebBrowser(FF) }) + @JsxSetter({ @WebBrowser(value = IE, minVersion = 11), @WebBrowser(FF) }) public void setOnload(final Function loadHandler) { loadHandler_ = loadHandler; } @@ -255,7 +258,7 @@ * Returns the event handler that fires on error. * @return the event handler that fires on error */ - @JsxGetter + @JsxGetter({ @WebBrowser(value = IE, minVersion = 11), @WebBrowser(FF) }) public Function getOnerror() { return errorHandler_; } @@ -264,7 +267,7 @@ * Sets the event handler that fires on error. * @param errorHandler the event handler that fires on error */ - @JsxSetter + @JsxSetter({ @WebBrowser(value = IE, minVersion = 11), @WebBrowser(FF) }) public void setOnerror(final Function errorHandler) { errorHandler_ = errorHandler; } @@ -341,19 +344,21 @@ } final String contentType = webResponse_.getContentType(); if (contentType.isEmpty() || contentType.contains("xml")) { + final WebWindow webWindow = getWindow().getWebWindow(); try { - final XmlPage page = new XmlPage(webResponse_, getWindow().getWebWindow()); - final XMLDocument doc; - if (getBrowserVersion().hasFeature(JS_XML_SUPPORT_VIA_ACTIVEXOBJECT)) { - doc = ActiveXObject.buildXMLDocument(getWindow().getWebWindow()); + if (getBrowserVersion().hasFeature(XHR_RESPONSE_XML_IS_ACTIVEXOBJECT)) { + final XmlPage page = new XmlPage(webResponse_, webWindow, true, false); + final MSXMLActiveXObjectFactory factory = webWindow.getWebClient().getMSXMLActiveXObjectFactory(); + final XMLDOMDocument document = (XMLDOMDocument) factory.create("Microsoft.XMLDOM", webWindow); + document.setDomNode(page); + return document; } - else { - doc = new XMLDocument(); - doc.setPrototype(getPrototype(doc.getClass())); - } - doc.setParentScope(getWindow()); - doc.setDomNode(page); - return doc; + final XmlPage page = new XmlPage(webResponse_, webWindow); + final XMLDocument document = new XMLDocument(); + document.setPrototype(getPrototype(document.getClass())); + document.setParentScope(getWindow()); + document.setDomNode(page); + return document; } catch (final IOException e) { LOG.warn("Failed parsing XML document " + webResponse_.getWebRequest().getUrl() + ": " @@ -851,7 +856,7 @@ * @param mimeType the type used to override that returned by the server (if any) * @see <a href="http://xulplanet.com/references/objref/XMLHttpRequest.html#method_overrideMimeType">XUL Planet</a> */ - @JsxFunction({ @WebBrowser(value = IE, maxVersion = 6), @WebBrowser(FF) }) + @JsxFunction(@WebBrowser(FF)) public void overrideMimeType(final String mimeType) { overriddenMimeType_ = mimeType; } @@ -869,7 +874,7 @@ * Sets the "withCredentials" property. * @param withCredentials the "withCredentials" property. */ - @JsxSetter + @JsxSetter({ @WebBrowser(value = IE, minVersion = 9), @WebBrowser(FF) }) public void setWithCredentials(final boolean withCredentials) { if (!async_ && state_ != STATE_UNSENT) { if (getBrowserVersion().hasFeature(XHR_WITHCREDENTIALS_SYNC_NOT_WRITEABLE_EXCEPTION)) { Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLSerializer.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLSerializer.java 2013-12-12 18:54:25 UTC (rev 8837) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLSerializer.java 2013-12-12 18:55:29 UTC (rev 8838) @@ -49,7 +49,7 @@ * @author Ronald Brill * @author Frank Danek */ -@JsxClass(browsers = { @WebBrowser(FF), @WebBrowser(value = IE, minVersion = 10) }) +@JsxClass(browsers = { @WebBrowser(FF), @WebBrowser(value = IE, minVersion = 11) }) public class XMLSerializer extends SimpleScriptable { // this is a bit strange but it is the way FF works Added: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/activex/javascript/msxml/MSXMLActiveXObjectFactoryTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/activex/javascript/msxml/MSXMLActiveXObjectFactoryTest.java (rev 0) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/activex/javascript/msxml/MSXMLActiveXObjectFactoryTest.java 2013-12-12 18:55:29 UTC (rev 8838) @@ -0,0 +1,78 @@ +/* + * 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.activex.javascript.msxml; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +/** + * Tests for {@link MSXMLActiveXObjectFactory}. + * + * @version $Revision$ + * @author Frank Danek + */ +public class MSXMLActiveXObjectFactoryTest { + + /** + * @throws Exception if the test fails + */ + @Test + public void supportsXMLDOMDocument() throws Exception { + assertFalse(MSXMLActiveXObjectFactory.isXMLDOMDocument(null)); + assertFalse(MSXMLActiveXObjectFactory.isXMLDOMDocument("foo")); + assertTrue(MSXMLActiveXObjectFactory.isXMLDOMDocument("Microsoft.XmlDom")); + assertTrue(MSXMLActiveXObjectFactory.isXMLDOMDocument("MSXML2.DOMDocument")); + assertTrue(MSXMLActiveXObjectFactory.isXMLDOMDocument("Msxml2.DOMDocument.3.0")); + assertTrue(MSXMLActiveXObjectFactory.isXMLDOMDocument("Msxml2.DOMDocument.4.0")); + assertTrue(MSXMLActiveXObjectFactory.isXMLDOMDocument("Msxml2.DOMDocument.5.0")); + assertTrue(MSXMLActiveXObjectFactory.isXMLDOMDocument("Msxml2.DOMDocument.6.0")); + assertTrue(MSXMLActiveXObjectFactory.isXMLDOMDocument("MSXML2.FreeThreadedDOMDocument")); + assertTrue(MSXMLActiveXObjectFactory.isXMLDOMDocument("Msxml2.FreeThreadedDOMDocument.3.0")); + assertTrue(MSXMLActiveXObjectFactory.isXMLDOMDocument("Msxml2.FreeThreadedDOMDocument.4.0")); + assertTrue(MSXMLActiveXObjectFactory.isXMLDOMDocument("Msxml2.FreeThreadedDOMDocument.5.0")); + assertTrue(MSXMLActiveXObjectFactory.isXMLDOMDocument("Msxml2.FreeThreadedDOMDocument.6.0")); + } + + /** + * @throws Exception if the test fails + */ + @Test + public void supportsXMLHTTPRequest() throws Exception { + assertFalse(MSXMLActiveXObjectFactory.isXMLHTTPRequest(null)); + assertFalse(MSXMLActiveXObjectFactory.isXMLHTTPRequest("foo")); + assertTrue(MSXMLActiveXObjectFactory.isXMLHTTPRequest("Microsoft.XMLHTTP")); + assertTrue(MSXMLActiveXObjectFactory.isXMLHTTPRequest("Msxml2.XMLHTTP")); + assertTrue(MSXMLActiveXObjectFactory.isXMLHTTPRequest("Msxml2.XMLHTTP.3.0")); + assertTrue(MSXMLActiveXObjectFactory.isXMLHTTPRequest("Msxml2.XMLHTTP.4.0")); + assertTrue(MSXMLActiveXObjectFactory.isXMLHTTPRequest("Msxml2.XMLHTTP.5.0")); + assertTrue(MSXMLActiveXObjectFactory.isXMLHTTPRequest("Msxml2.XMLHTTP.6.0")); + } + + /** + * @throws Exception if the test fails + */ + @Test + public void supportsXSLTemplate() throws Exception { + assertFalse(MSXMLActiveXObjectFactory.isXSLTemplate(null)); + assertFalse(MSXMLActiveXObjectFactory.isXSLTemplate("foo")); + assertTrue(MSXMLActiveXObjectFactory.isXSLTemplate("Msxml2.XSLTemplate")); + assertTrue(MSXMLActiveXObjectFactory.isXSLTemplate("Msxml2.XSLTemplate.3.0")); + assertTrue(MSXMLActiveXObjectFactory.isXSLTemplate("Msxml2.XSLTemplate.4.0")); + assertTrue(MSXMLActiveXObjectFactory.isXSLTemplate("Msxml2.XSLTemplate.5.0")); + assertTrue(MSXMLActiveXObjectFactory.isXSLTemplate("Msxml2.XSLTemplate.6.0")); + } +} Property changes on: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/activex/javascript/msxml/MSXMLActiveXObjectFactoryTest.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 Added: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/activex/javascript/msxml/MSXMLTestUtil.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/activex/javascript/msxml/MSXMLTestUtil.java (rev 0) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/activex/javascript/msxml/MSXMLTestUtil.java 2013-12-12 18:55:29 UTC (rev 8838) @@ -0,0 +1,157 @@ +/* + * 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.activex.javascript.msxml; + +import com.gargoylesoftware.htmlunit.html.HtmlPageTest; + +/** + * Test utility stuff for MSXML tests. + * + * @version $Revision$ + * @author Frank Danek + */ +public final class MSXMLTestUtil { + + /** Helper. */ + public static final String CREATE_XMLDOMDOCUMENT_FUNCTION_NAME = "createXMLDOMDocument"; + + /** Helper. **/ + public static final String CREATE_XMLDOMDOCUMENT_FUNCTION = "" + + " function " + CREATE_XMLDOMDOCUMENT_FUNCTION_NAME + "() {\n" + + " return new ActiveXObject('Microsoft.XMLDOM');\n" + + " }\n"; + + /** + * Helper. + * @return xml helper + **/ + public static String callCreateXMLDOMDocument() { + return CREATE_XMLDOMDOCUMENT_FUNCTION_NAME + "()"; + } + + /** Helper. */ + public static final String LOAD_XMLDOMDOCUMENT_FROM_STRING_FUNCTION_NAME = "loadXMLDOMDocumentFromString"; + + /** Helper. **/ + public static final String LOAD_XMLDOMDOCUMENT_FROM_STRING_FUNCTION = "" + + " function " + LOAD_XMLDOMDOCUMENT_FROM_STRING_FUNCTION_NAME + "(xml) {\n" + + " xmlDoc = new ActiveXObject(\"Microsoft.XMLDOM\");\n" + + " xmlDoc.async = false;\n" + + " xmlDoc.loadXML(xml);\n" + + " return xmlDoc;\n" + + " }\n"; + + /** + * Helper. + * @param string the parameter + * @return xml helper + **/ + public static String callLoadXMLDOMDocumentFromString(final String string) { + return LOAD_XMLDOMDOCUMENT_FROM_STRING_FUNCTION_NAME + "(" + string + ")"; + } + + /** Helper. */ + public static final String LOAD_XMLDOMDOCUMENT_FROM_URL_FUNCTION_NAME = "loadXMLDOMDocumentFromURL"; + + /** Helper. **/ + public static final String LOAD_XMLDOMDOCUMENT_FROM_URL_FUNCTION = "" + + " function " + LOAD_XMLDOMDOCUMENT_FROM_URL_FUNCTION_NAME + "(url) {\n" + + " xmlDoc = new ActiveXObject(\"Microsoft.XMLDOM\");\n" + + " xmlDoc.async = false;\n" + + " xmlDoc.load(url);\n" + + " return xmlDoc;\n" + + " }\n"; + + /** + * Helper. + * @param url the parameter + * @return xml helper + **/ + public static String callLoadXMLDOMDocumentFromURL(final String url) { + return LOAD_XMLDOMDOCUMENT_FROM_URL_FUNCTION_NAME + "(" + url + ")"; + } + + /** Helper. */ + public static final String CREATE_XMLHTTPREQUEST_FUNCTION_NAME = "createXMLHTTPRequest"; + + /** Helper. */ + public static final String CREATE_XMLHTTPREQUEST_FUNCTION = "" + + " function " + CREATE_XMLHTTPREQUEST_FUNCTION_NAME + "() {\n" + + " return new ActiveXObject(\"Microsoft.XMLHTTP\");\n" + + " }\n"; + + /** + * Helper. + * @return xml helper + **/ + public static String callCreateXMLHTTPRequest() { + return CREATE_XMLHTTPREQUEST_FUNCTION_NAME + "()"; + } + + /** Helper. */ + public static final String LOAD_XMLHTTPREQUEST_FROM_URL_FUNCTION_NAME = "loadXMLHTTPRequestFromURL"; + + /** Helper. **/ + public static final String LOAD_XMLHTTPREQUEST_FROM_URL_FUNCTION = "" + + " function " + LOAD_XMLHTTPREQUEST_FROM_URL_FUNCTION_NAME + "(url) {\n" + + " xhr = new ActiveXObject(\"Microsoft.XMLHTTP\");\n" + + " xhr.open(\"GET\", url, false);\n" + + " xhr.send();\n" + + " return xhr;\n" + + " }\n"; + + /** + * Helper. + * @param url the parameter + * @return xml helper + **/ + public static String callLoadXMLHTTPRequestFromURL(final String url) { + return LOAD_XMLHTTPREQUEST_FROM_URL_FUNCTION_NAME + "(" + url + ")"; + } + + /** Helper. */ + public static final String SERIALIZE_XMLDOMDOCUMENT_TO_STRING_FUNCTION_NAME = "serializeXMLDOMDocumentToString"; + + /** Helper. **/ + public static final String SERIALIZE_XMLDOMDOCUMENT_TO_STRING_FUNCTION = "" + + " function " + SERIALIZE_XMLDOMDOCUMENT_TO_STRING_FUNCTION_NAME + "(doc) {\n" + + " return doc.xml;\n" + + " }\n"; + + /** + * Helper. + * @param doc the doc parameter + * @return xml helper + **/ + public static String callSerializeXMLDOMDocumentToString(final String doc) { + return SERIALIZE_XMLDOMDOCUMENT_TO_STRING_FUNCTION_NAME + "(" + doc + ")"; + } + + /** + * @param scriptContent the header script content to test + * @return the HTML page + */ + public static String createTestHTML(final String scriptContent) { + return HtmlPageTest.STANDARDS_MODE_PREFIX_ + + "<html><head><title>foo</title><script>\n" + + scriptContent + + "</script></head><body onload='test()'>\n" + + "</body></html>"; + } + + private MSXMLTestUtil() { + super(); + } +} Property changes on: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/activex/javascript/msxml/MSXMLTestUtil.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 Added: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/activex/javascript/msxml/XMLDOMAttributeTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/activex/javascript/msxml/XMLDOMAttributeTest.java (rev 0) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/activex/javascript/msxml/XMLDOMAttributeTest.java 2013-12-12 18:55:29 UTC (rev 8838) @@ -0,0 +1,481 @@ +/* + * 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.activex.javascript.msxml; + +import static com.gargoylesoftware.htmlunit.BrowserRunner.Browser.IE; +import static com.gargoylesoftware.htmlunit.activex.javascript.msxml.MSXMLTestUtil.CREATE_XMLDOMDOCUMENT_FUNCTION; +import static com.gargoylesoftware.htmlunit.activex.javascript.msxml.MSXMLTestUtil. + LOAD_XMLDOMDOCUMENT_FROM_URL_FUNCTION; +import static com.gargoylesoftware.htmlunit.activex.javascript.msxml.MSXMLTestUtil.callCreateXMLDOMDocument; +import static com.gargoylesoftware.htmlunit.activex.javascript.msxml.MSXMLTestUtil.callLoadXMLDOMDocumentFromURL; +import static com.gargoylesoftware.htmlunit.activex.javascript.msxml.MSXMLTestUtil.createTestHTML; + +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.WebDriverTestCase; + +/** + * Tests for {@link XMLDOMAttribute}. + * + * @version $Revision$ + * @author Marc Guillemot + * @author Ahmed Ashour + * @author Daniel Gredler + * @author Ronald Brill + * @author Frank Danek + */ +@RunWith(BrowserRunner.class) +public class XMLDOMAttributeTest extends WebDriverTestCase { + + /** + * @throws Exception if the test fails + */ + @Test + @Browsers(IE) + @Alerts("[object Object]") + public void scriptableToString() throws Exception { + tester("alert(Object.prototype.toString.call(att));\n"); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Browsers(IE) + @Alerts("null") + public void attributes() throws Exception { + property("attributes"); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Browsers(IE) + @Alerts("testAttr") + public void baseName() throws Exception { + property("baseName"); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Browsers(IE) + @Alerts({ "1", "#text", "test", "true", "true" }) + public void childNodes() throws Exception { + final String test = "" + + "alert(att.childNodes.length);\n" + + "alert(att.childNodes.item(0).nodeName);\n" + + "alert(att.childNodes.item(0).text);\n" + + "alert(att.childNodes.item(0).parentNode === att);\n" + + "alert(att.childNodes.item(0).ownerDocument === doc);\n"; + + tester(test); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Browsers(IE) + @Alerts("0") + public void childNodes_empty() throws Exception { + final String xml = "" + + "<root>" + + "<elem testAttr=''/>" + + "</root>"; + + tester("alert(att.childNodes.length);\n", xml); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Browsers(IE) + @Alerts("null") + public void dataType() throws Exception { + property("dataType"); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Browsers(IE) + @Alerts("null") + public void definition() throws Exception { + property("definition"); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Browsers(IE) + @Alerts({ "true", "#text", "test", "true", "true" }) + public void firstChild() throws Exception { + final String test = "" + + "alert(att.firstChild != null);\n" + + "alert(att.firstChild.nodeName);\n" + + "alert(att.firstChild.text);\n" + + "alert(att.firstChild.parentNode === att);\n" + + "alert(att.firstChild.ownerDocument === doc);\n"; + + tester(test); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Browsers(IE) + @Alerts("false") + public void firstChild_empty() throws Exception { + final String xml = "" + + "<root>" + + "<elem testAttr=''/>" + + "</root>"; + + tester("alert(att.firstChild != null);\n", xml); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Browsers(IE) + @Alerts({ "true", "#text", "test", "true", "true" }) + public void lastChild() throws Exception { + final String test = "" + + "alert(att.lastChild != null);\n" + + "alert(att.lastChild.nodeName);\n" + + "alert(att.lastChild.text);\n" + + "alert(att.firstChild.parentNode === att);\n" + + "alert(att.firstChild.ownerDocument === doc);\n"; + + tester(test); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Browsers(IE) + @Alerts("false") + public void lastChild_empty() throws Exception { + final String xml = "" + + "<root>" + + "<elem testAttr=''/>" + + "</root>"; + + tester("alert(att.lastChild != null);\n", xml); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Browsers(IE) + @Alerts({ "testAttr", "exception-write" }) + public void name() throws Exception { + final String test = "" + + "try {\n" + + " alert(att.name);\n" + + "} catch(e) { alert('exception-read'); }\n" + + "try {\n" + + " att.name = 'other';\n" + + "} catch(e) { alert('exception-write'); }\n"; + + tester(test); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Browsers(IE) + @Alerts("") + public void namespaceURI() throws Exception { + property("namespaceURI"); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Browsers(IE) + @Alerts("testAttr") + public void nodeName() throws Exception { + property("nodeName"); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Browsers(IE) + @Alerts("2") + public void nodeType() throws Exception { + property("nodeType"); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Browsers(IE) + @Alerts({ "test", "other", "other", "other", "1" }) + public void nodeValue() throws Exception { + final String test = "" + + "try {\n" + + " alert(att.nodeValue);\n" + + "} catch(e) { alert('exception-read'); }\n" + + "try {\n" + + " att.nodeValue = 'other';\n" + + " alert(att.nodeValue);\n" + + " alert(att.text);\n" + + " alert(att.value);\n" + + " alert(att.childNodes.length);\n" + + "} catch(e) { alert('exception-write'); }\n"; + + tester(test); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Browsers(IE) + @Alerts("true") + public void ownerDocument() throws Exception { + tester("alert(att.ownerDocument === doc);\n"); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Browsers(IE) + @Alerts("true") + public void ownerDocument_created() throws Exception { + final String html = "" + + " function test() {\n" + + " var doc = " + callCreateXMLDOMDocument() + ";\n" + + " var att = doc.createAttribute('something');\n" + + " try {\n" + + " alert(att.ownerDocument === doc);\n" + + " } catch(e) { alert('exception'); }\n" + + " }\n" + + CREATE_XMLDOMDOCUMENT_FUNCTION; + + loadPageWithAlerts2(createTestHTML(html)); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Browsers(IE) + @Alerts("true") + public void parentNode() throws Exception { + tester("alert(att.parentNode == null);\n"); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Browsers(IE) + @Alerts("") + public void prefix() throws Exception { + property("prefix"); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Browsers(IE) + @Alerts("true") + public void specified() throws Exception { + property("specified"); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Browsers(IE) + @Alerts("false") + public void specified_inDTD() throws Exception { + final String xml = "" + + "<!DOCTYPE root [ " + + "<!ELEMENT root (elem+)> <!ELEMENT elem (#PCDATA)> <!ATTLIST elem testAttr CDATA \"0\">" + + " ]>\n" + + "<root>" + + "<elem/>" + + "</root>"; + + property("specified", xml); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Browsers(IE) + @Alerts({ "test", "other", "other", "other", "1" }) + public void text() throws Exception { + final String test = "" + + "try {\n" + + " alert(att.text);\n" + + "} catch(e) { alert('exception-read'); }\n" + + "try {\n" + + " att.text = 'other';\n" + + " alert(att.text);\n" + + " alert(att.nodeValue);\n" + + " alert(att.value);\n" + + " alert(att.childNodes.length);\n" + + "} catch(e) { alert('exception-write'); }\n"; + + tester(test); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Browsers(IE) + @Alerts({ "test", "other", "other", "other", "1" }) + public void value() throws Exception { + final String test = "" + + "try {\n" + + " alert(att.value);\n" + + "} catch(e) { alert('exception-read'); }\n" + + "try {\n" + + " att.value = 'other';\n" + + " alert(att.value);\n" + + " alert(att.nodeValue);\n" + + " alert(att.text);\n" + + " alert(att.childNodes.length);\n" + + "} catch(e) { alert('exception-write'); }\n"; + + tester(test); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Browsers(IE) + @Alerts("testAttr=\"test\"") + public void xml() throws Exception { + property("xml"); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Browsers(IE) + @Alerts("testAttr=\"\"") + public void xml_empty() throws Exception { + final String xml = "" + + "<root>" + + "<elem testAttr=''/>" + + "</root>"; + + property("xml", xml); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Browsers(IE) + @Alerts("undefined") + public void not_baseURI() throws Exception { + property("baseURI"); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Browsers(IE) + @Alerts("undefined") + public void not_expando() throws Exception { + property("expando"); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Browsers(IE) + @Alerts("undefined") + public void not_localName() throws Exception { + property("localName"); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Browsers(IE) + @Alerts("undefined") + public void not_textContent() throws Exception { + property("textContent"); + } + + private void property(final String property) throws Exception { + tester("alert(att." + property + ");\n"); + } + + private void property(final String property, final String xml) throws Exception { + tester("alert(att." + property + ");\n", xml); + } + + private void tester(final String test) throws Exception { + final String xml = "" + + "<root>" + + "<elem testAttr='test'/>" + + "</root>"; + + tester(test, xml); + } + + private void tester(final String test, final String xml) throws Exception { + final String html = "" + + " function test() {\n" + + " var doc = " + callLoadXMLDOMDocumentFromURL("'" + URL_SECOND + "'") + ";\n" + + " try {\n" + + " var elem = doc.documentElement.firstChild;\n" + + " var att = elem.getAttributeNode('testAttr');\n" + + test + + " } catch(e) { alert('exception'); }\n" + + " }\n" + + LOAD_XMLDOMDOCUMENT_FROM_URL_FUNCTION; + + getMockWebConnection().setResponse(URL_SECOND, xml, "text/xml"); + loadPageWithAlerts2(createTestHTML(html)); + } +} Property changes on: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/activex/javascript/msxml/XMLDOMAttributeTest.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 Added: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/activex/javascript/msxml/XMLDOMCDATASectionTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/activex/javascript/msxml/XMLDOMCDATASectionTest.java (rev 0) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/activex/javascript/msxml/XMLDOMCDATASectionTest.java 2013-12-12 18:55:29 UTC (rev 8838) @@ -0,0 +1,767 @@ +/* + * 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.activex.javascript.msxml; + +import static com.gargoylesoftware.htmlunit.BrowserRunner.Browser.IE; +import static com.gargoylesoftware.htmlunit.activex.javascript.msxml.MSXMLTestUtil.CREATE_XMLDOMDOCUMENT_FUNCTION; +import static com.gargoylesoftware.htmlunit.activex.javascript.msxml.MSXMLTestUtil. + LOAD_XMLDOMDOCUMENT_FROM_URL_FUNCTION; +import static com.gargoylesoftware.htmlunit.activex.javascript.msxml.MSXMLTestUtil.callCreateXMLDOMDocument; +import static com.gargoylesoftware.htmlunit.activex.javascript.msxml.MSXMLTestUtil.callLoadXMLDOMDocumentFromURL; +import static com.gargoylesoftware.htmlunit.activex.javascript.msxml.MSXMLTestUtil.createTestHTML; + +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.WebDriverTestCase; + +/** + * Tests for {@link XMLDOMCDATASection}. + * + * @version $Revision$ + * @author Mirko Friedenhagen + * @author Ahmed Ashour + * @author Frank Danek + */ +@RunWith(BrowserRunner.class) +public class XMLDOMCDATASectionTest extends WebDriverTestCase { + + /** + * @throws Exception if the test fails + */ + @Test + @Browsers(IE) + @Alerts("[object Object]") + public void scriptableToString() throws Exception { + tester("alert(Object.prototype.toString.call(cdata));\n"); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Browsers(IE) + @Alerts("null") + public void attributes() throws Exception { + property("attributes"); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Browsers(IE) + @Alerts("") + public void baseName() throws Exception { + property("baseName"); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Browsers(IE) + @Alerts("0") + public void childNodes() throws Exception { + tester("alert(cdata.childNodes.length);\n"); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Browsers(IE) + @Alerts({ " ", " ", " ", + "exception-setNull", + "", "", "", + "test", "test", "test", + "test\ntest", "test\ntest", "test\ntest", + "<tag/>", "<tag/>", "<tag/>" }) + public void data() throws Exception { + final String test = "" + + "alert(cdata.data);\n" + + "alert(cdata.nodeValue);\n" + + "alert(cdata.text);\n" + // null + + "try {\n" + + " cdata.data = null;\n" + + "} catch(e) { alert('exception-setNull'); }\n" + // empty + + "cdata.data = '';\n" + + "alert(cdata.data);\n" + + "alert(cdata.nodeValue);\n" + + "alert(cdata.text);\n" + // normal + + "cdata.data = 'test';\n" + + "alert(cdata.data);\n" + + "alert(cdata.nodeValue);\n" + + "alert(cdata.text);\n" + // linebreak + + "cdata.data = 'test\\ntest';\n" + + "alert(cdata.data);\n" + + "alert(cdata.nodeValue);\n" + + "alert(cdata.text);\n" + // xml + + "cdata.data = '<tag/>';\n" + + "alert(cdata.data);\n" + + "alert(cdata.nodeValue);\n" + + "alert(cdata... [truncated message content] |