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

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

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

mguillem
Revision: 1231
          http://svn.sourceforge.net/htmlunit/?rev=1231&view=rev
Author:   mguillem
Date:     2006-09-08 09:07:19 -0700 (Fri, 08 Sep 2006)

Log Message:
-----------
- JavaScript: window.eval now evaluates in the right window scope.
- JavaScript: added basic support for addEventListener on DOM nodes (Mozilla).
- JavaScript: added support for window.createPopup (Internet Explorer).
- Added FrameWindow.getFrameElement and support for Javascript's frameElement property on windows.

Modified Paths:
--------------
    trunk/htmlunit/src/java/com/gargoylesoftware/htmlunit/html/FrameWindow.java
    trunk/htmlunit/src/java/com/gargoylesoftware/htmlunit/javascript/configuration/JavaScriptConfiguration.xml
    trunk/htmlunit/src/java/com/gargoylesoftware/htmlunit/javascript/host/NodeImpl.java
    trunk/htmlunit/src/java/com/gargoylesoftware/htmlunit/javascript/host/Window.java
    trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/SimpleScriptableTest.java
    trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/DocumentTest.java
    trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/IFrameTest.java
    trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/WindowTest.java
    trunk/htmlunit/src/xdocs/changes.xml

Added Paths:
-----------
    trunk/htmlunit/src/java/com/gargoylesoftware/htmlunit/javascript/host/Popup.java
    trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/PopupTest.java

Modified: trunk/htmlunit/src/java/com/gargoylesoftware/htmlunit/html/FrameWindow.java
===================================================================
--- trunk/htmlunit/src/java/com/gargoylesoftware/htmlunit/html/FrameWindow.java 2006-09-08 14:17:17 UTC (rev 1230)
+++ trunk/htmlunit/src/java/com/gargoylesoftware/htmlunit/html/FrameWindow.java 2006-09-08 16:07:19 UTC (rev 1231)
@@ -96,6 +96,14 @@
     public HtmlPage getEnclosingPage() {
         return frame_.getPage();
     }
+    
+    /**
+     * Gets the DOM node of the (i)frame containing this window.
+     * @return the dom node
+     */
+    public BaseFrame getFrameElement() {
+        return frame_;
+    }
 
     /**
      * Gives a basic representation for debugging purposes

Modified: trunk/htmlunit/src/java/com/gargoylesoftware/htmlunit/javascript/configuration/JavaScriptConfiguration.xml
===================================================================
--- trunk/htmlunit/src/java/com/gargoylesoftware/htmlunit/javascript/configuration/JavaScriptConfiguration.xml 2006-09-08 14:17:17 UTC (rev 1230)
+++ trunk/htmlunit/src/java/com/gargoylesoftware/htmlunit/javascript/configuration/JavaScriptConfiguration.xml 2006-09-08 16:07:19 UTC (rev 1231)
@@ -550,6 +550,11 @@
         <property name="parentNode" readable="true" writable="false"/>
         <property name="previousSibling" readable="true" writable="false"/>
 
+        <function name="addEventListener">
+            <doclink url="http://developer.mozilla.org/en/docs/DOM:element.addEventListener"
+                    descr="Mozilla documenation"/>
+            <browser name="Netscape"/>
+        </function>
         <function name="appendChild"/>
         <function name="cloneNode"/>
         <function name="hasChildNodes"/>        
@@ -571,6 +576,15 @@
         <!-- NOT FINISHED -->
     </class>
 
+    <class name="Popup" classname="com.gargoylesoftware.htmlunit.javascript.host.Popup" JSObject="true">
+      <doclink url="http://msdn.microsoft.com/workshop/author/dhtml/reference/objects/popup.asp" descr="MSDN documenation"/>
+      <browser name="Microsoft Internet Explorer"/>
+      <property name="document" readable="true" writable="false"/>
+      <property name="isOpen" readable="true" writable="false"/>
+      <function name="hide"/>
+      <function name="show"/>
+    </class>
+
     <class name="Radio" extends="Input" classname="com.gargoylesoftware.htmlunit.javascript.host.Input"
         JSObject="false" htmlClass="com.gargoylesoftware.htmlunit.html.HtmlRadioButtonInput">
         <!-- NOT FINISHED -->
@@ -784,6 +798,7 @@
         <property name="event" readable="true" writable="false">
             <browser name="Microsoft Internet Explorer"/>
         </property>
+        <property name="frameElement" readable="true" writable="false"/>
         <property name="frames" readable="true" writable="false"/>
         <property name="history" readable="true" writable="false"/>
         <property name="innerHeight" readable="true" writable="false">
@@ -836,6 +851,11 @@
         <function name="clearTimeout"/>
         <function name="close"/>
         <function name="confirm"/>
+        <function name="createPopup">
+            <doclink url="http://msdn.microsoft.com/workshop/author/dhtml/reference/methods/createpopup.asp"
+                    descr="MSDN documenation"/>
+            <browser name="Microsoft Internet Explorer"/>
+        </function>
         <function name="detachEvent">
             <doclink url="http://msdn.microsoft.com/workshop/author/dhtml/reference/methods/detachevent.asp"
                     descr="MSDN documenation"/>
@@ -846,6 +866,7 @@
                     descr="MSDN documenation"/>
             <browser name="Microsoft Internet Explorer"/>
         </function>
+        <function name="eval"/>
         <function name="focus"/>
         <function name="moveBy"/>
         <function name="moveTo"/>

Modified: trunk/htmlunit/src/java/com/gargoylesoftware/htmlunit/javascript/host/NodeImpl.java
===================================================================
--- trunk/htmlunit/src/java/com/gargoylesoftware/htmlunit/javascript/host/NodeImpl.java 2006-09-08 14:17:17 UTC (rev 1230)
+++ trunk/htmlunit/src/java/com/gargoylesoftware/htmlunit/javascript/host/NodeImpl.java 2006-09-08 16:07:19 UTC (rev 1231)
@@ -39,6 +39,7 @@
 
 import org.jaxen.JaxenException;
 import org.mozilla.javascript.Context;
+import org.mozilla.javascript.Function;
 
 import com.gargoylesoftware.htmlunit.html.DomNode;
 import com.gargoylesoftware.htmlunit.html.HtmlElement;
@@ -339,4 +340,17 @@
         }
         return getScriptableFor( domNode );
     }
+
+
+    /**
+     * Allows the registration of event listeners on the event target.<br>
+     * <b>Note</b: does currently nothing, only a placeholder.
+     * @param type the event type to listen for (like "onclick")
+     * @param listener the event listener
+     * @param useCapture If <code>true</code>, indicates that the user wishes to initiate capture (not yet implemented)
+     * @see <a href="http://developer.mozilla.org/en/docs/DOM:element.addEventListener">Mozilla documentation</a>
+     */
+    public void jsxFunction_addEventListener(final String type, final Function listener, final boolean useCapture) {
+        getLog().warn("addEventListener for \"" + type + "\" not implemented, no event will be triggered");
+    }
 }

Added: trunk/htmlunit/src/java/com/gargoylesoftware/htmlunit/javascript/host/Popup.java
===================================================================
--- trunk/htmlunit/src/java/com/gargoylesoftware/htmlunit/javascript/host/Popup.java                        (rev 0)
+++ trunk/htmlunit/src/java/com/gargoylesoftware/htmlunit/javascript/host/Popup.java 2006-09-08 16:07:19 UTC (rev 1231)
@@ -0,0 +1,199 @@
+/*
+ * Copyright (c) 2002-2006 Gargoyle Software Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ *    this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ *    this list of conditions and the following disclaimer in the documentation
+ *    and/or other materials provided with the distribution.
+ * 3. The end-user documentation included with the redistribution, if any, must
+ *    include the following acknowledgment:
+ *
+ *       "This product includes software developed by Gargoyle Software Inc.
+ *        (http://www.GargoyleSoftware.com/)."
+ *
+ *    Alternately, this acknowledgment may appear in the software itself, if
+ *    and wherever such third-party acknowledgments normally appear.
+ * 4. The name "Gargoyle Software" must not be used to endorse or promote
+ *    products derived from this software without prior written permission.
+ *    For written permission, please contact [hidden email].
+ * 5. Products derived from this software may not be called "HtmlUnit", nor may
+ *    "HtmlUnit" appear in their name, without prior written permission of
+ *    Gargoyle Software Inc.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GARGOYLE
+ * SOFTWARE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package com.gargoylesoftware.htmlunit.javascript.host;
+
+import java.util.Collections;
+
+import com.gargoylesoftware.htmlunit.Page;
+import com.gargoylesoftware.htmlunit.ThreadManager;
+import com.gargoylesoftware.htmlunit.WebClient;
+import com.gargoylesoftware.htmlunit.WebWindow;
+import com.gargoylesoftware.htmlunit.html.HtmlBody;
+import com.gargoylesoftware.htmlunit.html.HtmlHtml;
+import com.gargoylesoftware.htmlunit.html.HtmlPage;
+import com.gargoylesoftware.htmlunit.javascript.SimpleScriptable;
+
+/**
+ * A JavaScript object for IE's Popu.
+ *
+ * @author Marc Guillemot
+ * @version $Revision: 1223 $
+ * @see <a href="http://msdn.microsoft.com/workshop/author/dhtml/reference/objects/popup.asp">MSDN documentation</a>
+ */
+public class Popup extends SimpleScriptable {
+
+    private boolean opened_;
+    private Document document_;
+
+    /**
+     * Creates a new instance. JavaScript objects must have a default constructor.
+     */
+    public Popup() {
+        opened_ = false;
+    }
+    
+    void init(final WebClient webClient) {
+        // build document
+        document_ = (Document) makeJavaScriptObject("Document");
+
+        // create the "page" associated to the document
+        final WebWindow popupPseudoWindow = new PopupPseudoWebWindow(webClient);
+        final HtmlPage popupPage = new HtmlPage(null, null, popupPseudoWindow);
+        popupPseudoWindow.setEnclosedPage(popupPage);
+        final HtmlHtml html = new HtmlHtml(popupPage, Collections.EMPTY_MAP);
+        popupPage.appendChild(html);
+        final HtmlBody body = new HtmlBody(popupPage, Collections.EMPTY_MAP);
+        html.appendChild(body);
+
+        document_.setDomNode(popupPage);
+    }
+
+    /**
+     * Returns the HTML document element in the popup.
+     * @return HTML document.
+     */
+    public Object jsxGet_document() {
+        return document_;
+    }
+
+
+    /**
+     * Indicates if the popup is opened.
+     * @return <code>true</code> if opened
+     */
+    public boolean jsxGet_isOpen() {
+        return opened_;
+    }
+
+    /**
+     * Hides the popup.
+     */
+    public void jsxFunction_hide() {
+        opened_ = false;
+    }
+
+    /**
+     * Shows the popup.
+     */
+    public void jsxFunction_show() {
+        opened_ = true;
+    }
+}
+
+/**
+ * Simple implementation of {@link WebWindow} to allow the construction of the {@link HtmlPage} associated
+ * with a {@link Popup}
+ */
+class PopupPseudoWebWindow implements WebWindow {
+    private final WebClient webClient_;
+    private Object scriptObject_;
+    private Page enclosedPage_;
+    
+    PopupPseudoWebWindow(final WebClient webClient) {
+        webClient_ = webClient;
+    }
+    /**
+     * @see com.gargoylesoftware.htmlunit.WebWindow#getEnclosedPage()
+     */
+    public Page getEnclosedPage() {
+        return enclosedPage_;
+    }
+
+    /**
+     * @see com.gargoylesoftware.htmlunit.WebWindow#getName()
+     */
+    public String getName() {
+        throw new RuntimeException("Not supported");
+    }
+
+    /**
+     * @see com.gargoylesoftware.htmlunit.WebWindow#getParentWindow()
+     */
+    public WebWindow getParentWindow() {
+        throw new RuntimeException("Not supported");
+    }
+
+    /**
+     * @see com.gargoylesoftware.htmlunit.WebWindow#getScriptObject()
+     */
+    public Object getScriptObject() {
+        return scriptObject_;
+    }
+
+    /**
+     * @see com.gargoylesoftware.htmlunit.WebWindow#getThreadManager()
+     */
+    public ThreadManager getThreadManager() {
+        throw new RuntimeException("Not supported");
+    }
+
+    /**
+     * @see com.gargoylesoftware.htmlunit.WebWindow#getTopWindow()
+     */
+    public WebWindow getTopWindow() {
+        throw new RuntimeException("Not supported");
+    }
+
+    /**
+     * @see com.gargoylesoftware.htmlunit.WebWindow#getWebClient()
+     */
+    public WebClient getWebClient() {
+        return webClient_;
+    }
+
+    /**
+     * @see com.gargoylesoftware.htmlunit.WebWindow#setEnclosedPage(com.gargoylesoftware.htmlunit.Page)
+     */
+    public void setEnclosedPage(final Page page) {
+        enclosedPage_ = page;
+    }
+
+    /**
+     * @see com.gargoylesoftware.htmlunit.WebWindow#setName(java.lang.String)
+     */
+    public void setName(final String name) {
+        throw new RuntimeException("Not supported");
+    }
+
+    /**
+     * @see com.gargoylesoftware.htmlunit.WebWindow#setScriptObject(java.lang.Object)
+     */
+    public void setScriptObject(final Object scriptObject) {
+        scriptObject_ = scriptObject;
+    }
+}

Modified: trunk/htmlunit/src/java/com/gargoylesoftware/htmlunit/javascript/host/Window.java
===================================================================
--- trunk/htmlunit/src/java/com/gargoylesoftware/htmlunit/javascript/host/Window.java 2006-09-08 14:17:17 UTC (rev 1230)
+++ trunk/htmlunit/src/java/com/gargoylesoftware/htmlunit/javascript/host/Window.java 2006-09-08 16:07:19 UTC (rev 1231)
@@ -68,6 +68,7 @@
 import com.gargoylesoftware.htmlunit.WebWindow;
 import com.gargoylesoftware.htmlunit.html.BaseFrame;
 import com.gargoylesoftware.htmlunit.html.DomNode;
+import com.gargoylesoftware.htmlunit.html.FrameWindow;
 import com.gargoylesoftware.htmlunit.html.HtmlElement;
 import com.gargoylesoftware.htmlunit.html.HtmlPage;
 import com.gargoylesoftware.htmlunit.html.xpath.HtmlUnitXPath;
@@ -233,6 +234,27 @@
     }
 
 
+    /**
+     * Creates a popup window Open a new window
+     * @see <a href="http://msdn.microsoft.com/workshop/author/dhtml/reference/methods/createpopup.asp">
+     * MSDN documentation</a>
+     * @param context The javascript Context
+     * @param scriptable The object that the function was called on.
+     * @param args The arguments passed to the function.
+     * @param function The function object that was invoked.
+     * @return The created popup
+     */
+    public static Popup jsxFunction_createPopup(
+        final Context context, final Scriptable scriptable, final Object[] args, final Function function ) {
+
+        final Window thisWindow = (Window) scriptable;
+
+        final Popup popup = (Popup) thisWindow.makeJavaScriptObject("Popup");
+        popup.init(thisWindow.getWebWindow().getWebClient());
+        
+        return popup;
+    }
+
     private URL makeUrlForOpenWindow(final String urlString) {
         if (urlString.length() == 0) {
             // IE handles "" as "about:blank" in window.open
@@ -467,6 +489,20 @@
 
 
     /**
+     * Return the (i)frame in which the window is contained.
+     * @return <code>null</code> for a top level window
+     */
+    public Object jsxGet_frameElement() {
+        final WebWindow window = getWebWindow();
+        if (window instanceof FrameWindow) {
+            return ((FrameWindow) window).getFrameElement().getScriptObject();
+        }
+        else {
+            return null;
+        }
+    }
+
+    /**
      * Return the value of the frames property.
      * @return The live collection of frames
      */
@@ -823,9 +859,7 @@
      */
     public Object jsxFunction_execScript(final String script, final String language) {
         if ("javascript".equalsIgnoreCase(language) || "jscript".equalsIgnoreCase(language)) {
-            final HtmlPage htmlPage = document_.getHtmlPage();
-            final HtmlElement doc = htmlPage.getDocumentElement();
-            htmlPage.executeJavaScriptIfPossible(script, "Window.execScript()", true, doc);
+            jsxFunction_eval(script);
         }
         else if ("vbscript".equalsIgnoreCase(language)) {
             getLog().warn("VBScript not supported in Window.execScript().");
@@ -838,6 +872,16 @@
     }
 
     /**
+     * Executes the specified script code in the scope of this window.
+     * @param script some javascript code
+     * @return the evaluation result
+     */
+    public Object jsxFunction_eval(final String script) {
+        final HtmlPage htmlPage = document_.getHtmlPage();
+        return htmlPage.executeJavaScriptIfPossible(script, "Window.eval()", false, null).getJavaScriptResult();
+    }
+
+    /**
      * Return the text from the status line.
      * @return the status line text
      */

Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/SimpleScriptableTest.java
===================================================================
--- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/SimpleScriptableTest.java 2006-09-08 14:17:17 UTC (rev 1230)
+++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/SimpleScriptableTest.java 2006-09-08 16:07:19 UTC (rev 1231)
@@ -143,6 +143,7 @@
         names.remove("RowContainer");
         names.remove("FormField");
         names.remove("JavaScriptBackgroundJob");
+        names.remove("Popup");
 
         final Transformer class2ShortName = new Transformer() {
             public Object transform(final Object obj) {

Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/DocumentTest.java
===================================================================
--- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/DocumentTest.java 2006-09-08 14:17:17 UTC (rev 1230)
+++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/DocumentTest.java 2006-09-08 16:07:19 UTC (rev 1231)
@@ -110,10 +110,7 @@
         final HtmlPage page = loadPage(content, collectedAlerts);
         assertEquals("foo", page.getTitleText());
 
-        final List expectedAlerts = Arrays.asList( new String[]{
-            "2", "form1", "form2"
-        } );
-
+        final String[] expectedAlerts = { "2", "form1", "form2" };
         assertEquals( expectedAlerts, collectedAlerts );
     }
 
@@ -139,7 +136,6 @@
         assertEquals("foo", page.getTitleText());
 
         final List expectedAlerts = Collections.singletonList("1");
-
         assertEquals( expectedAlerts, collectedAlerts );
     }
 
@@ -163,10 +159,7 @@
         final HtmlPage page = loadPage(content, collectedAlerts);
         assertEquals("foo", page.getTitleText());
 
-        final List expectedAlerts = Arrays.asList( new String[]{
-            "0"
-        } );
-
+        final String[] expectedAlerts = { "0" };
         assertEquals( expectedAlerts, collectedAlerts );
     }
 
@@ -259,9 +252,7 @@
 
 
         final List collectedAlerts = new ArrayList();
-        final List expectedAlerts = Arrays.asList( new String[]{
-            "0", "1", "1", "true"
-        } );
+        final String[] expectedAlerts = { "0", "1", "1", "true" };
         createTestPageForRealBrowserIfNeeded(content, expectedAlerts);
         loadPage(content, collectedAlerts);
 
@@ -347,9 +338,7 @@
             + "</html>";
 
         final List collectedAlerts = new ArrayList();
-        final List expectedAlerts = Arrays.asList( new String[]{
-            "0", "3", "3", "true", "firstLink"
-        } );
+        final String[] expectedAlerts = { "0", "3", "3", "true", "firstLink" };
         createTestPageForRealBrowserIfNeeded(content, expectedAlerts);
         loadPage(content, collectedAlerts);
 
@@ -398,8 +387,7 @@
             + "  </body>\n"
             + "</html>\n";
 
-        final List expectedAlerts = Arrays.asList(
-                new String[]{ "DIV", "1", "null", "DIV", "button1value", "text1value", "text" } );
+        final String[] expectedAlerts = { "DIV", "1", "null", "DIV", "button1value", "text1value", "text" };
         createTestPageForRealBrowserIfNeeded(htmlContent, expectedAlerts);
 
         final List collectedAlerts = new ArrayList();
@@ -446,9 +434,7 @@
         assertEquals("Some Text", div1.getNodeValue());
         assertEquals("#text", div1.getNodeName());
 
-        final List expectedAlerts = Arrays.asList( new String[]{
-            "Some Text", "9", "3", "Some Text", "#text"
-        } );
+        final String[] expectedAlerts = { "Some Text", "9", "3", "Some Text", "#text" };
         assertEquals( expectedAlerts, collectedAlerts );
     }
 
@@ -476,9 +462,7 @@
         final HtmlPage page = loadPage(content, collectedAlerts);
         assertEquals("foo", page.getTitleText());
 
-        final List expectedAlerts = Arrays.asList( new String[]{
-            "1"
-        } );
+        final String[] expectedAlerts = { "1" };
 
         assertEquals( expectedAlerts, collectedAlerts );
     }
@@ -506,10 +490,7 @@
         final HtmlPage page = loadPage(content, collectedAlerts);
         assertEquals("foo", page.getTitleText());
 
-        final List expectedAlerts = Arrays.asList( new String[]{
-            "Some Text"
-        } );
-
+        final String[] expectedAlerts = { "Some Text" };
         assertEquals( expectedAlerts, collectedAlerts );
     }
 
@@ -539,9 +520,7 @@
         final HtmlPage page = loadPage(content, collectedAlerts);
         assertEquals("foo", page.getTitleText());
 
-        final List expectedAlerts = Arrays.asList( new String[]{
-            "true", "true", "true", "true"
-        } );
+        final String[] expectedAlerts = { "true", "true", "true", "true" };
 
         assertEquals( expectedAlerts, collectedAlerts );
     }
@@ -567,9 +546,7 @@
         final HtmlPage page = loadPage(content, collectedAlerts);
         assertEquals("foo", page.getTitleText());
 
-        final List expectedAlerts = Arrays.asList( new String[]{
-            "true"
-        } );
+        final String[] expectedAlerts = { "true" };
 
         assertEquals( expectedAlerts, collectedAlerts );
     }
@@ -595,7 +572,7 @@
         final HtmlPage page = loadPage(content, collectedAlerts);
         assertEquals( "First", page.getTitleText() );
 
-        final List expectedAlerts = Arrays.asList(new String[] {"bar", "null", "null"});
+        final String[] expectedAlerts = {"bar", "null", "null"};
         createTestPageForRealBrowserIfNeeded(content, expectedAlerts);
         assertEquals( expectedAlerts, collectedAlerts );
     }
@@ -622,8 +599,7 @@
         final HtmlPage page = loadPage(content, collectedAlerts);
         assertEquals( "First", page.getTitleText() );
 
-        final List expectedAlerts = Arrays.asList( new String[] {
-            "bar", "null"} );
+        final String[] expectedAlerts = { "bar", "null" };
         assertEquals( expectedAlerts, collectedAlerts );
     }
 
@@ -771,7 +747,7 @@
         assertEquals("parentDiv",
             ((HtmlElement) div1.getParentNode()).getAttributeValue("id"));
 
-        final List expectedAlerts = Collections.singletonList("parentDiv");
+        final String[] expectedAlerts = {"parentDiv"};
         assertEquals( expectedAlerts, collectedAlerts );
     }
 
@@ -814,7 +790,7 @@
         final HtmlPage firstPage = loadPage(firstContent, collectedAlerts);
         assertEquals( "First", firstPage.getTitleText() );
 
-        final List expectedAlerts = Collections.singletonList("true");
+        final String[] expectedAlerts = {"true"};
         assertEquals( expectedAlerts, collectedAlerts );
     }
 
@@ -843,7 +819,7 @@
         assertEquals("parentDiv",
             ((HtmlElement) childDiv.getParentNode()).getAttributeValue("id"));
 
-        final List expectedAlerts = Collections.singletonList("parentDiv");
+        final String[] expectedAlerts = {"parentDiv"};
         assertEquals( expectedAlerts, collectedAlerts );
     }
 
@@ -866,8 +842,7 @@
         final HtmlPage firstPage = loadPage(firstContent, collectedAlerts);
         assertEquals( "First", firstPage.getTitleText() );
 
-        final List expectedAlerts = Arrays.asList( new String[] {
-            "true", "HTML", "true"} );
+        final String[] expectedAlerts = { "true", "HTML", "true"};
         assertEquals( expectedAlerts, collectedAlerts );
     }
 
@@ -894,7 +869,7 @@
         assertEquals("childDiv",
             ((HtmlElement) div1.getFirstChild()).getAttributeValue("id"));
 
-        final List expectedAlerts = Collections.singletonList("childDiv");
+        final String[] expectedAlerts = {"childDiv"};
         assertEquals( expectedAlerts, collectedAlerts );
     }
 
@@ -926,7 +901,7 @@
         assertEquals("childDiv",
             ((HtmlElement) parentDiv.getFirstChild()).getAttributeValue("id"));
 
-        final List expectedAlerts = Collections.singletonList("childDiv");
+        final String[] expectedAlerts = {"childDiv"};
         assertEquals( expectedAlerts, collectedAlerts );
     }
 
@@ -953,7 +928,7 @@
         assertEquals("childDiv",
             ((HtmlElement) parentDiv.getLastChild()).getAttributeValue("id"));
 
-        final List expectedAlerts = Collections.singletonList("childDiv");
+        final String[] expectedAlerts = {"childDiv"};
         assertEquals( expectedAlerts, collectedAlerts );
     }
 
@@ -1349,7 +1324,7 @@
             + "<form><input type='button' name='button1' value='pushme'></form>"
             + "</body></html>";
 
-        final List expectedAlerts = Arrays.asList(new String[]{"button", "button", "true"});
+        final String[] expectedAlerts = {"button", "button", "true"};
         createTestPageForRealBrowserIfNeeded(firstContent, expectedAlerts);
 
         final List collectedAlerts = new ArrayList();
@@ -1443,8 +1418,7 @@
         final HtmlPage firstPage = loadPage(firstContent, collectedAlerts);
         assertEquals( "First", firstPage.getTitleText() );
 
-        final List expectedAlerts = Arrays.asList( new String[] {
-            "HTML", "HEAD", "TITLE", "SCRIPT", "BODY"} );
+        final String[] expectedAlerts = { "HTML", "HEAD", "TITLE", "SCRIPT", "BODY"};
         assertEquals( expectedAlerts, collectedAlerts );
     }
 
@@ -1467,8 +1441,7 @@
         final HtmlPage firstPage = loadPage(firstContent, collectedAlerts);
         assertEquals( "First", firstPage.getTitleText() );
 
-        final List expectedAlerts = Arrays.asList( new String[] {
-            "HTML", "HEAD", "TITLE", "SCRIPT", "BODY"} );
+        final String[] expectedAlerts = { "HTML", "HEAD", "TITLE", "SCRIPT", "BODY"};
         assertEquals( expectedAlerts, collectedAlerts );
     }
 
@@ -1514,7 +1487,7 @@
         final HtmlPage firstPage = loadPage(firstContent, collectedAlerts);
         assertEquals( "First", firstPage.getTitleText() );
 
-        final List expectedAlerts = Arrays.asList( new String[] {"form1", "form2", "2"} );
+        final String[] expectedAlerts = {"form1", "form2", "2"};
         assertEquals( expectedAlerts, collectedAlerts );
     }
 
@@ -1545,8 +1518,7 @@
         final HtmlPage firstPage = loadPage(firstContent, collectedAlerts);
         assertEquals( "First", firstPage.getTitleText() );
 
-        final List expectedAlerts = Arrays.asList( new String[] {
-            "a", "b", "a", "b", "0"} );
+        final String[] expectedAlerts = { "a", "b", "a", "b", "0"};
         assertEquals( expectedAlerts, collectedAlerts );
     }
 
@@ -1609,8 +1581,7 @@
         final HtmlPage firstPage = ( HtmlPage )webClient.getPage( URL_FIRST );
         assertEquals( "First", firstPage.getTitleText() );
 
-        final List expectedAlerts = Arrays.asList( new String[] {
-            "one", "two", "three", "four"} );
+        final String[] expectedAlerts = { "one", "two", "three", "four" };
         assertEquals( expectedAlerts, collectedAlerts );
     }
 
@@ -1635,8 +1606,7 @@
             + "</form>"
             + "</body></html>";
 
-        final List expectedAlerts = Arrays.asList(
-                new String[] { "value1", "value1", "value2", "value2" });
+        final String[] expectedAlerts = { "value1", "value1", "value2", "value2" };
         createTestPageForRealBrowserIfNeeded(firstContent, expectedAlerts);
 
         final List collectedAlerts = new ArrayList();
@@ -1702,7 +1672,7 @@
         final HtmlPage firstPage = loadPage(firstContent, collectedAlerts);
         assertEquals( "First", firstPage.getTitleText() );
 
-        final List expectedAlerts = Arrays.asList(new String[] { "1", "2", "2", "true" });
+        final String[] expectedAlerts = { "1", "2", "2", "true" };
         createTestPageForRealBrowserIfNeeded(firstContent, expectedAlerts);
         assertEquals(expectedAlerts, collectedAlerts);
     }
@@ -1861,9 +1831,7 @@
         client.setAlertHandler( new CollectingAlertHandler(collectedAlerts) );
         client.getPage(URL_FIRST);
 
-        final List expectedAlerts = Arrays.asList( new String[]{
-            "loading", "complete"
-        } );
+        final String[] expectedAlerts = { "loading", "complete" };
 
         assertEquals( expectedAlerts, collectedAlerts );
     }
@@ -1903,9 +1871,7 @@
         final List collectedAlerts = new ArrayList();
         loadPage(content, collectedAlerts);
 
-        final List expectedAlerts = Arrays.asList( new String[]{
-            "findMe", "byId"
-        } );
+        final String[] expectedAlerts = { "findMe", "byId" };
         assertEquals( expectedAlerts, collectedAlerts );
     }
 
@@ -1933,9 +1899,7 @@
 
         client.getPage(URL_FIRST);
 
-        final List expectedAlerts = Arrays.asList( new String[]{
-            "null", "byId"
-        } );
+        final String[] expectedAlerts = { "null", "byId" };
         assertEquals( expectedAlerts, collectedAlerts );
     }
 
@@ -2005,9 +1969,8 @@
             + "</form>\n"
             + "</body></html>";
 
-        final List expectedAlerts = Arrays.asList( new String[]{
-            "myImageId", "2", "FORM", "undefined", "undefined", "undefined", "undefined"
-        } );
+        final String[] expectedAlerts
+            = { "myImageId", "2", "FORM", "undefined", "undefined", "undefined", "undefined" };
         createTestPageForRealBrowserIfNeeded(content, expectedAlerts);
 
         final List collectedAlerts = new ArrayList();
@@ -2033,9 +1996,7 @@
             + "</script>\n"
             + "</body></html>";
 
-        final List expectedAlerts = Arrays.asList( new String[]{
-            "outer"
-        } );
+        final String[] expectedAlerts = { "outer" };
         createTestPageForRealBrowserIfNeeded(content, expectedAlerts);
 
         final List collectedAlerts = new ArrayList();
@@ -2126,11 +2087,7 @@
 
         client.getPage(urlGargoyleUpperCase);
 
-
-
-        final List expectedAlerts = Arrays.asList(new String[] {
-            "www.gargoylesoftware.com", "gargoylesoftware.com"
-        });
+        final String[] expectedAlerts = { "www.gargoylesoftware.com", "gargoylesoftware.com" };
         assertEquals( expectedAlerts, collectedAlerts );
     }
 
@@ -2150,9 +2107,7 @@
 
         final List collectedAlerts = new ArrayList();
         loadPage(content, collectedAlerts);
-        final List expectedAlerts = Arrays.asList(new String[] {
-            "www.gargoylesoftware.com", "GaRgOyLeSoFtWaRe.CoM"
-        });
+        final String[] expectedAlerts = { "www.gargoylesoftware.com", "GaRgOyLeSoFtWaRe.CoM" };
         assertEquals( expectedAlerts, collectedAlerts );
     }
 
@@ -2173,12 +2128,11 @@
             + "<body onload='doTest()'>\n"
             + "</body></html>";
 
-        final List expectedAlerts = Arrays.asList( new String[]{
-            "d4.d3.d2.d1.gargoylesoftware.com", "d4.d3.d2.d1.gargoylesoftware.com","d1.gargoylesoftware.com"
-        } );
+        final String[] expectedAlerts =
+            { "d4.d3.d2.d1.gargoylesoftware.com", "d4.d3.d2.d1.gargoylesoftware.com", "d1.gargoylesoftware.com" };
 
         final List collectedAlerts = new ArrayList();
-        loadPage(content, collectedAlerts,new URL("http://d4.d3.d2.d1.gargoylesoftware.com"));
+        loadPage(content, collectedAlerts, new URL("http://d4.d3.d2.d1.gargoylesoftware.com"));
         assertEquals( expectedAlerts, collectedAlerts );
     }
 
@@ -2196,12 +2150,10 @@
             + "<body onload='doTest()'>\n"
             + "</body></html>";
 
-        final List expectedAlerts = Arrays.asList( new String[]{
-            "localhost", "localhost"
-        } );
+        final String[] expectedAlerts = { "localhost", "localhost" };
 
         final List collectedAlerts = new ArrayList();
-        loadPage(content, collectedAlerts,new URL("http://localhost"));
+        loadPage(content, collectedAlerts, new URL("http://localhost"));
         assertEquals( expectedAlerts, collectedAlerts );
     }
 
@@ -2318,8 +2270,7 @@
         final List collectedAlerts = new ArrayList();
 
         // test for IE
-        final List expectedAlerts = Arrays.asList( new String[]{
-            "true", "1", "about:blank", "about:blank"} );
+        final String[] expectedAlerts = { "true", "1", "about:blank", "about:blank"};
         createTestPageForRealBrowserIfNeeded(html, expectedAlerts);
         loadPage(BrowserVersion.INTERNET_EXPLORER_6_0, html, collectedAlerts);
         assertEquals(expectedAlerts, collectedAlerts);
@@ -2357,4 +2308,25 @@
         loadPage(BrowserVersion.INTERNET_EXPLORER_6_0, html, collectedAlerts);
         assertEquals(expectedAlertsIE, collectedAlerts);
     }
+
+    /**
+     * Just test that addEventListener does't break.
+     * TODO: improve addEventListener to make it really handle the event
+     * @throws Exception if the test fails
+     */
+    public void testAddEventListenerDoesntBreak() throws Exception {
+        final String content = "<html><body>"
+            + "<script>"
+            + "function test()"
+            + "{"
+            + "  alert('in test');"
+            + "}"
+            + "window.document.addEventListener('click', test, false);"
+            + "</script>"
+            + "</body></html>";
+
+        final List collectedAlerts = new ArrayList();
+        loadPage(BrowserVersion.MOZILLA_1_0, content, collectedAlerts);
+    }
+
 }

Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/IFrameTest.java
===================================================================
--- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/IFrameTest.java 2006-09-08 14:17:17 UTC (rev 1230)
+++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/IFrameTest.java 2006-09-08 16:07:19 UTC (rev 1231)
@@ -160,4 +160,29 @@
 
         assertEquals(expectedAlerts, collectedAlerts);
     }
+
+
+    /**
+     * @throws Exception if the test fails
+     */
+    public void testFrameElement() throws Exception {
+        final String content
+            = "<html><head><title>first</title>"
+                + "<script>"
+                + "function test()\n"
+                + "{\n"
+                + "  alert(document.getElementById('myFrame') == frames.foo.frameElement);\n"
+                + "}\n"
+                + "</script></head>"
+                + "<body onload='test()'>"
+                + "<iframe name='foo' id='myFrame' src='about:blank'></iframe>"
+                + "</body></html>";
+        final List expectedAlerts = Arrays.asList( new String[]{"true"} );
+        createTestPageForRealBrowserIfNeeded(content, expectedAlerts);
+
+        final List collectedAlerts = new ArrayList();
+        loadPage(content, collectedAlerts);
+
+        assertEquals(expectedAlerts, collectedAlerts);
+    }
 }

Added: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/PopupTest.java
===================================================================
--- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/PopupTest.java                        (rev 0)
+++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/PopupTest.java 2006-09-08 16:07:19 UTC (rev 1231)
@@ -0,0 +1,81 @@
+/*
+ * Copyright (c) 2002-2006 Gargoyle Software Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ *    this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ *    this list of conditions and the following disclaimer in the documentation
+ *    and/or other materials provided with the distribution.
+ * 3. The end-user documentation included with the redistribution, if any, must
+ *    include the following acknowledgment:
+ *
+ *       "This product includes software developed by Gargoyle Software Inc.
+ *        (http://www.GargoyleSoftware.com/)."
+ *
+ *    Alternately, this acknowledgment may appear in the software itself, if
+ *    and wherever such third-party acknowledgments normally appear.
+ * 4. The name "Gargoyle Software" must not be used to endorse or promote
+ *    products derived from this software without prior written permission.
+ *    For written permission, please contact [hidden email].
+ * 5. Products derived from this software may not be called "HtmlUnit", nor may
+ *    "HtmlUnit" appear in their name, without prior written permission of
+ *    Gargoyle Software Inc.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GARGOYLE
+ * SOFTWARE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package com.gargoylesoftware.htmlunit.javascript.host;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import com.gargoylesoftware.htmlunit.BrowserVersion;
+import com.gargoylesoftware.htmlunit.WebTestCase;
+
+/**
+ * Tests for {@link Popup}.
+ *
+ * @version  $Revision: 1129 $
+ * @author Marc Guillemot
+ */
+public class PopupTest extends WebTestCase {
+
+    /**
+     * Create an instance
+     * @param name The name of the test
+     */
+    public PopupTest( final String name ) {
+        super(name);
+    }
+
+
+    /**
+     * Just test that a standard use of popup works without exception
+     * @throws Exception if the test fails
+     */
+    public void testPopup() throws Exception {
+        final String content = "<html><head><title>First</title><body>\n"
+            + "<script>\n"
+            + "var oPopup = window.createPopup();"
+            + "var oPopupBody = oPopup.document.body;"
+            + "oPopupBody.innerHTML = 'bla bla';"
+            + "oPopup.show(100, 100, 200, 50, document.body);"
+            + "</script>"
+            + "</body></html>";
+
+        final List collectedAlerts = new ArrayList();
+        loadPage(BrowserVersion.INTERNET_EXPLORER_6_0, content, collectedAlerts);
+    }
+
+}

Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/WindowTest.java
===================================================================
--- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/WindowTest.java 2006-09-08 14:17:17 UTC (rev 1230)
+++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/WindowTest.java 2006-09-08 16:07:19 UTC (rev 1231)
@@ -1886,4 +1886,34 @@
         assertTrue("threads did not stop in time", page.getEnclosingWindow().getThreadManager().joinAll(1000));
         assertEquals(Collections.nCopies(max, "ping"), collectedAlerts);
     }
+
+    /**
+     * Tests that nested setTimeouts that are deeper than Thread.MAX_PRIORITY
+     * do not cause an exception.
+     * @throws Exception If the test fails
+     */
+    public void testEvalScope() throws Exception {
+        final String content = "<html><body>"
+            + "<iframe src='iframe.html'></iframe>"
+            + "</body></html>";
+        final String iframe = "<html><body>"
+            + "<script>"
+            + "window.parent.eval('var foo = 1');"
+            + "alert(window.parent.foo)"
+            + "</script>"
+            + "</body></html>";
+
+        final WebClient webClient = new WebClient();
+        final List collectedAlerts = new ArrayList();
+        webClient.setAlertHandler( new CollectingAlertHandler(collectedAlerts) );
+
+        final MockWebConnection webConnection = new MockWebConnection( webClient );
+        webConnection.setResponse(URL_FIRST, content);
+        webConnection.setDefaultResponse(iframe);
+        webClient.setWebConnection( webConnection );
+
+        webClient.getPage(URL_FIRST);
+        final String[] expectedAlersts = { "1" };
+        assertEquals(expectedAlersts, collectedAlerts);
+    }
 }

Modified: trunk/htmlunit/src/xdocs/changes.xml
===================================================================
--- trunk/htmlunit/src/xdocs/changes.xml 2006-09-08 14:17:17 UTC (rev 1230)
+++ trunk/htmlunit/src/xdocs/changes.xml 2006-09-08 16:07:19 UTC (rev 1231)
@@ -8,6 +8,18 @@
     <body>
         <release version="next">
             <action type="update" dev="mguillem">
+                JavaScript: window.eval now evaluates in the right window scope.
+            </action>
+            <action type="update" dev="mguillem">
+                JavaScript: added basic support for addEventListener on DOM nodes (Mozilla).
+            </action>
+            <action type="update" dev="mguillem">
+                JavaScript: added support for window.createPopup (Internet Explorer).
+            </action>
+            <action type="update" dev="mguillem">
+                Added FrameWindow.getFrameElement and support for Javascript's frameElement property on windows.
+            </action>
+            <action type="update" dev="mguillem">
                 Parser: automatically add an &lt;head&gt; element if none present in html source
                 (as done by Internet Explorer and Firefox).
             </action>


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