SF.net SVN: htmlunit: [1249] trunk/htmlunit/src

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

SF.net SVN: htmlunit: [1249] trunk/htmlunit/src

mguillem
Revision: 1249
          http://svn.sourceforge.net/htmlunit/?rev=1249&view=rev
Author:   mguillem
Date:     2006-10-26 21:57:07 -0700 (Thu, 26 Oct 2006)

Log Message:
-----------
style's behavior property only for IE

Modified Paths:
--------------
    trunk/htmlunit/src/java/com/gargoylesoftware/htmlunit/javascript/configuration/JavaScriptConfiguration.xml
    trunk/htmlunit/src/java/com/gargoylesoftware/htmlunit/javascript/host/Style.java
    trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/StyleTest.java

Modified: trunk/htmlunit/src/java/com/gargoylesoftware/htmlunit/javascript/configuration/JavaScriptConfiguration.xml
===================================================================
--- trunk/htmlunit/src/java/com/gargoylesoftware/htmlunit/javascript/configuration/JavaScriptConfiguration.xml 2006-10-27 02:39:24 UTC (rev 1248)
+++ trunk/htmlunit/src/java/com/gargoylesoftware/htmlunit/javascript/configuration/JavaScriptConfiguration.xml 2006-10-27 04:57:07 UTC (rev 1249)
@@ -402,10 +402,6 @@
         <property name="sourceIndex" notImplemented="true" readable="true" writable="false">
             <browser name="Microsoft Internet Explorer" min-version="4"/>
         </property>
-        <property name="style" notImplemented="true" readable="true" writable="true">
-            <browser name="Microsoft Internet Explorer" min-version="4"/>
-            <browser name="Netscape" min-version="6"/>
-        </property>
         <property name="style" readable="true" writable="false">
             <browser name="Microsoft Internet Explorer" min-version="4"/>
             <browser name="Netscape" min-version="6"/>
@@ -527,14 +523,15 @@
         <property name="language" readable="true" writable="false">
             <browser name="Netscape"/>
         </property>
+        <property name="mimeTypes" readable="true" writable="false"/>
         <property name="onLine" readable="true" writable="false"/>
         <property name="platform" readable="true" writable="false"/>
+        <property name="plugins" readable="true" writable="false"/>
         <property name="systemLanguage" readable="true" writable="false"/>
         <property name="userAgent" readable="true" writable="false"/>
         <property name="userLanguage" readable="true" writable="false"/>
     
         <function name="javaEnabled"/>
-        <function name="plugins"/>
         <function name="taintEnabled"/>
     </class>
 
@@ -675,6 +672,9 @@
 
     <class name="Style" classname="com.gargoylesoftware.htmlunit.javascript.host.Style"
         JSObject="true">
+        <property name="behavior" readable="true" writable="true">
+            <browser name="Microsoft Internet Explorer"/>
+        </property>
     </class>
 
     <class name="Submit" extends="Input" classname="com.gargoylesoftware.htmlunit.javascript.host.Input"

Modified: trunk/htmlunit/src/java/com/gargoylesoftware/htmlunit/javascript/host/Style.java
===================================================================
--- trunk/htmlunit/src/java/com/gargoylesoftware/htmlunit/javascript/host/Style.java 2006-10-27 02:39:24 UTC (rev 1248)
+++ trunk/htmlunit/src/java/com/gargoylesoftware/htmlunit/javascript/host/Style.java 2006-10-27 04:57:07 UTC (rev 1249)
@@ -37,9 +37,6 @@
  */
 package com.gargoylesoftware.htmlunit.javascript.host;
 
-import com.gargoylesoftware.htmlunit.Assert;
-import com.gargoylesoftware.htmlunit.javascript.SimpleScriptable;
-
 import java.text.MessageFormat;
 import java.text.ParseException;
 import java.util.Collections;
@@ -54,6 +51,9 @@
 import org.apache.commons.collections.CollectionUtils;
 import org.mozilla.javascript.Scriptable;
 
+import com.gargoylesoftware.htmlunit.Assert;
+import com.gargoylesoftware.htmlunit.javascript.SimpleScriptable;
+
 /**
  * A javascript object for a Style
  *
@@ -75,7 +75,7 @@
      * These are IE properties, this should be configured per browser
      */
     private static final String[] STYLE_PROPERTIES = { "backgroundColor",
-            "behavior", "bottom", "clear", "clip", "color", "direction",
+            "bottom", "clear", "clip", "color", "direction",
             "display", "font", "fontFamily", "fontSize", "fontStyle",
             "fontWeight", "fontWeight", "hasLayout", "height", "layoutFlow",
             "layoutGrid", "layoutGridMode", "left", "letterSpacing",
@@ -108,9 +108,7 @@
     /**
      * Create an instance and set its parent scope to the one of the provided
      * element
-     *
-     * @param htmlElement
-     *            the element to which this style is bound
+     * @param htmlElement the element to which this style is bound
      */
     Style(final HTMLElement htmlElement) {
         setParentScope(htmlElement.getParentScope());
@@ -127,6 +125,7 @@
         // Initialize.
         Assert.notNull("htmlElement", htmlElement);
         jsElement_ = htmlElement;
+        setDomNode(htmlElement.getDomNodeOrNull(), false);
 
         if (htmlElement.getHtmlElementOrDie().getPage().getWebClient()
                 .getBrowserVersion().isIE()) {
@@ -163,20 +162,25 @@
      * @return The property.
      */
     public Object get(final String name, final Scriptable start) {
-        final Object result = super.get(name, start);
 
-        if (!STYLE_ALLOWED_PROPERTIES.contains(name)) {
-            return super.get(name, start);
+        final Object result;
+        if (STYLE_ALLOWED_PROPERTIES.contains(name)) {
+            result = getStyleAttribute(name);
         }
-
-        // We only handle the logic here if 1) we have been fully initialized
-        // and 2) the
-        // superclass wasn't able to find anything with the matching name.
-        if (jsElement_ == null || result != NOT_FOUND) {
-            return result;
+        else {
+            result = super.get(name, start);
         }
 
-        final Object value = getStyleMap().get(name);
+        return result;
+    }
+
+    /**
+     * Gets the style attribute value
+     * @param name the style attribute name
+     * @return empty string if noting found
+     */
+    protected String getStyleAttribute(final String name) {
+        final String value = (String) getStyleMap().get(name);
         if (value == null) {
             return "";
         }
@@ -188,13 +192,9 @@
     /**
      * Set the specified property
      *
-     * @param name
-     *            The name of the property
-     * @param start
-     *            The scriptable object that was originally invoked for this
-     *            property
-     * @param newValue
-     *            The new value
+     * @param name The name of the property
+     * @param start The scriptable object that was originally invoked for this property
+     * @param newValue The new value
      */
     public void put(final String name, final Scriptable start,
             final Object newValue) {
@@ -208,6 +208,10 @@
             return;
         }
 
+        setStyleAttribute(name, (String) newValue);
+    }
+
+    protected void setStyleAttribute(final String name, final String newValue) {
         final Map styleMap = getStyleMap();
         styleMap.put(name, newValue);
 
@@ -216,13 +220,14 @@
         final Iterator iterator = styleMap.entrySet().iterator();
         while (iterator.hasNext()) {
             final Map.Entry entry = (Map.Entry) iterator.next();
+            buffer.append(" ");
             buffer.append(entry.getKey());
             buffer.append(": ");
             buffer.append(entry.getValue());
-            buffer.append("; ");
+            buffer.append(";");
         }
-        jsElement_.getHtmlElementOrDie().setAttributeValue("style",
-                buffer.toString());
+        buffer.deleteCharAt(0);
+        jsElement_.getHtmlElementOrDie().setAttributeValue("style", buffer.toString());
     }
 
     private Map getStyleMap() {
@@ -246,4 +251,19 @@
 
         return styleMap;
     }
+
+    /**
+     * Gets the object's behavior
+     * @return the behavior.
+     */
+    public String jsxGet_behavior() {
+        return getStyleAttribute("behavior");
+    }
+
+    /**
+     * Sets the object's behavior
+     */
+    public void jsxSet_behavior(final String newValue) {
+        setStyleAttribute("behavior", newValue);
+    }
 }

Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/StyleTest.java
===================================================================
--- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/StyleTest.java 2006-10-27 02:39:24 UTC (rev 1248)
+++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/StyleTest.java 2006-10-27 04:57:07 UTC (rev 1249)
@@ -47,7 +47,7 @@
 import com.gargoylesoftware.htmlunit.html.HtmlPage;
 
 /**
- * Tests for Style.
+ * Tests for {@link Style}.
  *
  * @version  $Revision$
  * @author  <a href="mailto:[hidden email]">Mike Bowler</a>
@@ -71,20 +71,24 @@
         final String firstContent
             = "<html><head><title>First</title><script>\n"
             + "function doTest() {\n"
-            + "    var style = document.getElementById('div1').style;\n"
+            + "    var node = document.getElementById('div1');\n"
+            + "    var style = node.style;\n"
             + "    alert(style.color);\n"
             + "    style.color = 'pink';\n"
             + "    alert(style.color);\n"
+            + "    alert(node.getAttribute('style'));\n"
             + "}\n</script></head>"
             + "<body onload='doTest()'><div id='div1' style='color: black'>foo</div></body></html>";
 
+        final String[] expectedAlerts = {"black", "pink", "color: pink;"};
+        createTestPageForRealBrowserIfNeeded(firstContent, expectedAlerts);
+
         final List collectedAlerts = new ArrayList();
         final HtmlPage page = loadPage(firstContent, collectedAlerts);
 
-        final List expectedAlerts = Arrays.asList( new String[]{"black", "pink"} );
         assertEquals( expectedAlerts, collectedAlerts );
 
-        assertEquals("color: pink; ", page.getHtmlElementById("div1").getAttributeValue("style") );
+        assertEquals("color: pink;", page.getHtmlElementById("div1").getAttributeValue("style") );
     }
 
 
@@ -110,7 +114,7 @@
         assertEquals( expectedAlerts, collectedAlerts );
 
         assertEquals(
-            "background: blue; color: pink; foo: bar; ",
+            "background: blue; color: pink; foo: bar;",
             page.getHtmlElementById("div1").getAttributeValue("style") );
     }
 
@@ -136,7 +140,7 @@
 
         assertEquals( expectedAlerts, collectedAlerts );
 
-        assertEquals("color: pink; ", page.getHtmlElementById("div1").getAttributeValue("style") );
+        assertEquals("color: pink;", page.getHtmlElementById("div1").getAttributeValue("style") );
     }
 
     /**
@@ -152,16 +156,40 @@
             + "    alert(oDiv.style.visibility);\n"
             + "    oDiv.style.visibility = 'hidden';\n"
             + "    alert(oDiv.style.visibility);\n"
+            + "    alert(oDiv.style.behavior);\n"
             + "}\n</script></head>"
             + "<body onload='doTest()'>"
             + "<div id='div1'>foo</div></body></html>";
 
-        final List expectedAlerts = Arrays.asList( new String[]{"", "hidden"} );
+        final String[] expectedAlerts = {"", "hidden", "undefined"};
         createTestPageForRealBrowserIfNeeded(content, expectedAlerts);
 
         final List collectedAlerts = new ArrayList();
         loadPage(BrowserVersion.MOZILLA_1_0, content, collectedAlerts);
 
+        assertEquals(expectedAlerts, collectedAlerts);
+    }
+
+    /**
+     * @throws Exception if the test fails
+     */
+    public void testIEStyle() throws Exception {
+        final String content
+            = "<html><head><title>First</title><script>\n"
+            + "function doTest() {\n"
+            + "    var oDiv = document.getElementById('div1');\n"
+            + "    alert(oDiv.style.behavior);\n"
+            + "}\n"
+            + "</script></head>"
+            + "<body onload='doTest()'>"
+            + "<div id='div1'>foo</div></body></html>";
+
+        final String[] expectedAlerts = {""};
+        createTestPageForRealBrowserIfNeeded(content, expectedAlerts);
+
+        final List collectedAlerts = new ArrayList();
+        loadPage(BrowserVersion.INTERNET_EXPLORER_6_0, content, collectedAlerts);
+
         assertEquals( expectedAlerts, collectedAlerts );
     }
 


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
HtmlUnit-develop mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/htmlunit-develop