]> source.dussan.org Git - gwtquery.git/commitdiff
change empty method in order to handle iframe documents.
authorManolo Carrasco <manolo@apache.org>
Sun, 18 Jul 2010 07:50:32 +0000 (07:50 +0000)
committerManolo Carrasco <manolo@apache.org>
Sun, 18 Jul 2010 07:50:32 +0000 (07:50 +0000)
gwtquery-core/src/main/java/com/google/gwt/query/client/GQuery.java
gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryCoreTest.java

index ed146b12c8a9119ff231f22f2ee9a3466e20e752..49a15b9009f209a5a2b2b9cc7aa06d616bdb1b69 100644 (file)
@@ -62,11 +62,11 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
       this.left = left;\r
       this.top = top;\r
     }\r
-    \r
+\r
     public Offset add(int left, int top) {\r
       return new Offset(this.left + left, this.top + top);\r
     }\r
-    \r
+\r
     public String toString() {\r
       return top + "+" + left;\r
     }\r
@@ -148,10 +148,10 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
   }\r
 \r
   public static final BodyElement body = Document.get().getBody();\r
-  \r
+\r
   public static final Document document = Document.get();\r
   public static boolean fxOff = false;\r
-  \r
+\r
   public static Class<GQuery> GQUERY = GQuery.class;\r
 \r
   public static final Element window = window();\r
@@ -164,7 +164,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
       FUNC_BEFORE = 3;\r
 \r
   private static final String OLD_DATA_PREFIX = "old-";\r
-  \r
+\r
   private static JsMap<Class<? extends GQuery>, Plugin<? extends GQuery>>\r
       plugins;;\r
 \r
@@ -236,7 +236,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
    * This function accepts a string containing a CSS selector which is then used\r
    * to match a set of elements, or it accepts raw HTML creating a GQuery\r
    * element containing those elements.\r
-   * The second parameter is the context to use for the selector, or \r
+   * The second parameter is the context to use for the selector, or\r
    * the document where the new elements will be created.\r
    */\r
   public static GQuery $(String selectorOrHtml, Node ctx) {\r
@@ -249,7 +249,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
     }\r
     return new GQuery(select(selectorOrHtml, ctx));\r
   }\r
-  \r
+\r
   /**\r
    * This function accepts a string containing a CSS selector which is then used\r
    * to match a set of elements, or it accepts raw HTML creating a GQuery\r
@@ -372,7 +372,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
     }\r
     return name != null ? d.getObject(name) : id;\r
   }\r
-  \r
+\r
   protected static String[] jsArrayToString(JsArrayString array) {\r
     if (GWT.isScript()) {\r
       return jsArrayToString0(array);\r
@@ -393,8 +393,14 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
     return res;\r
   }\r
 \r
+  private native static Document getContentDocument(Node n) /*-{\r
+    var d =  n.contentDocument || n.contentWindow.document;\r
+    if (!d.body) @com.google.gwt.query.client.GQuery::emptyDocument(Lcom/google/gwt/dom/client/Document;)(d);\r
+    return d;\r
+  }-*/;\r
+\r
   private static boolean hasClass(Element e, String clz) {\r
-    return ((" " + e.getClassName() + " ").matches(".*\\s" + clz + "\\s.*"));\r
+    return e.getClassName().matches("(^|.*\\s)" + clz + "(\\s.*|$)");\r
   }\r
 \r
   private static GQuery innerHtml(String html) {\r
@@ -404,11 +410,15 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
   private static native String[] jsArrayToString0(JsArrayString array) /*-{\r
     return array;\r
   }-*/;\r
-  \r
+\r
   private static native <T extends Node> T[] reinterpretCast(NodeList<T> nl) /*-{\r
     return nl;\r
   }-*/;\r
 \r
+  private static native void emptyDocument(Document d) /*-{\r
+    d.open(); d.write("<head/><body/>"); d.close();\r
+  }-*/;\r
+\r
   private static NodeList<Element> select(String selector, Node context) {\r
     if (engine == null) {\r
       engine = new SelectorEngine();\r
@@ -450,7 +460,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
 \r
   /**\r
    * Add elements to the set of matched elements if they are not included yet.\r
-   * It also update the selector appending the new one. \r
+   * It also update the selector appending the new one.\r
    */\r
   public GQuery add(GQuery previousObject) {\r
     return pushStack(unique(merge(elements, previousObject.elements)), "add",\r
@@ -541,9 +551,9 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
   }\r
 \r
   /**\r
-   * All of the matched set of elements will be inserted at the end \r
+   * All of the matched set of elements will be inserted at the end\r
    * of the element(s) specified by the parameter other.\r
-   * \r
+   *\r
    * The operation $(A).appendTo(B) is, essentially, the reverse of doing a regular\r
    * $(A).append(B), instead of appending B to A, you're appending A to B.\r
    */\r
@@ -553,9 +563,9 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
   }\r
 \r
   /**\r
-   * All of the matched set of elements will be inserted at the end \r
+   * All of the matched set of elements will be inserted at the end\r
    * of the element(s) specified by the parameter other.\r
-   * \r
+   *\r
    * The operation $(A).appendTo(B) is, essentially, the reverse of doing a regular\r
    * $(A).append(B), instead of appending B to A, you're appending A to B.\r
    */\r
@@ -565,9 +575,9 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
   }\r
 \r
   /**\r
-   * All of the matched set of elements will be inserted at the end \r
+   * All of the matched set of elements will be inserted at the end\r
    * of the element(s) specified by the parameter other.\r
-   * \r
+   *\r
    * The operation $(A).appendTo(B) is, essentially, the reverse of doing a regular\r
    * $(A).append(B), instead of appending B to A, you're appending A to B.\r
    */\r
@@ -666,14 +676,14 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
 \r
   /**\r
    * Binds a set of handlers to a particular Event for each matched element.\r
-   * \r
+   *\r
    * The event handlers are passed as Functions that you can use to prevent\r
    * default behavior. To stop both default action and event bubbling, the\r
    * function event handler has to return false.\r
-   * \r
+   *\r
    * You can pass an additional Object data to your Function as the second\r
    * parameter\r
-   * \r
+   *\r
    */\r
   public GQuery bind(int eventbits, final Object data, final Function...funcs) {\r
     return as(Events).bind(eventbits, data, funcs);\r
@@ -694,7 +704,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
   public GQuery change(Function...f) {\r
     return bindOrFire(Event.ONCHANGE, null, f);\r
   }\r
-  \r
+\r
   /**\r
    * Get a set of elements containing all of the unique immediate children of\r
    * each of the matched set of elements. Also note: while parents() will look\r
@@ -726,7 +736,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
   }\r
 \r
   /**\r
-   * Returns the inner height of the first matched element, including padding \r
+   * Returns the inner height of the first matched element, including padding\r
    * but not the vertical scrollbar height, border, or margin.\r
    */\r
   public int clientHeight() {\r
@@ -734,7 +744,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
   }\r
 \r
   /**\r
-   * Returns the inner width of the first matched element, including padding \r
+   * Returns the inner width of the first matched element, including padding\r
    * but not the vertical scrollbar width, border, or margin.\r
    */\r
   public int clientWidth() {\r
@@ -810,18 +820,18 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
   public String css(String name) {\r
     return styleImpl.curCSS(get(0), name, false);\r
   }\r
-  \r
+\r
   /**\r
    * Return a style property on the first matched element.\r
-   * \r
+   *\r
    * The parameter force has a special meaning here:\r
    * - When force is false, returns the value of the css property defined\r
-   *   in the style attribute of the element. \r
+   *   in the style attribute of the element.\r
    * - Otherwise it returns the real computed value.\r
-   * \r
+   *\r
    * For instance if you define 'display=none' not in the element style\r
    * but in the css stylesheet, it returns an empty string unless you\r
-   * pass the parameter force=true.   \r
+   * pass the parameter force=true.\r
    */\r
   public String css(String name, boolean force) {\r
     return styleImpl.curCSS(get(0), name, force);\r
@@ -846,7 +856,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
     }\r
     return this;\r
   }\r
-  \r
+\r
   /**\r
    * Set CSS property on every matched element using type-safe enumerations.\r
    */\r
@@ -919,8 +929,8 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
       }\r
     }\r
     return this;\r
-  }  \r
-  \r
+  }\r
+\r
   /**\r
    * Returns the working set of nodes as a Java array. <b>Do NOT</b attempt to\r
    * modify this array, e.g. assign to its elements, or call Arrays.sort()\r
@@ -931,13 +941,20 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
 \r
   /**\r
    * Remove all child nodes from the set of matched elements.\r
+   * In the case of a document element, it removes all the content.\r
+   * You should call empty() when you create a new iframe and you\r
+   * want to add dynamic content to it.\r
    */\r
   public GQuery empty() {\r
-    // TODO: add memory leak cleanup, remove event handlers, and \r
+    // TODO: add memory leak cleanup, remove event handlers, and\r
     // data caches\r
     for (Element e : elements()) {\r
-      while (e.getFirstChild() != null) {\r
-        e.removeChild(e.getFirstChild());\r
+      if (e.getNodeType() == Element.DOCUMENT_NODE) {\r
+        emptyDocument(e.<Document>cast());\r
+      } else {\r
+        while (e.getFirstChild() != null) {\r
+          e.removeChild(e.getFirstChild());\r
+        }\r
       }\r
     }\r
     return this;\r
@@ -987,8 +1004,8 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
    */\r
   public GQuery fadeOut(Function... f) {\r
     return $(as(Effects).fadeOut(f));\r
-  }  \r
-  \r
+  }\r
+\r
   /**\r
    * Fade out all matched elements by adjusting their opacity.\r
    */\r
@@ -1101,7 +1118,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
   public GQuery gt(int pos) {\r
     return $(slice(pos + 1, -1));\r
   }\r
-  \r
+\r
   /**\r
    * Returns true any of the specified classes are present on any of the matched\r
    * elements.\r
@@ -1237,7 +1254,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
   public GQuery insertBefore(Element item) {\r
     return insertBefore($(item));\r
   }\r
-  \r
+\r
   /**\r
    * Insert all of the matched elements before another, specified, set of\r
    * elements.\r
@@ -1250,7 +1267,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
       query.before(e);\r
     }\r
     return this;\r
-  }  \r
+  }\r
 \r
   /**\r
    * Insert all of the matched elements before another, specified, set of\r
@@ -1270,7 +1287,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
    */\r
   public boolean is(String... filters) {\r
     return filter(filters).size() > 0;\r
-  }  \r
+  }\r
 \r
   /**\r
    * Bind a set of functions to the keydown event of each matched element.\r
@@ -1285,7 +1302,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
    */\r
   public GQuery keydown(int key) {\r
     return trigger(Event.ONKEYDOWN, key);\r
-  }  \r
+  }\r
 \r
   /**\r
    * Bind a set of functions to the keypress event of each matched element.\r
@@ -1293,7 +1310,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
    */\r
   public GQuery keypress(Function...f) {\r
     return bindOrFire(Event.ONKEYPRESS, null, f);\r
-  }  \r
+  }\r
 \r
   /**\r
    * Trigger a keypress event passing the key pushed.\r
@@ -1316,28 +1333,28 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
   public GQuery keyup(int key) {\r
     return trigger(Event.ONKEYUP, key);\r
   }\r
-  \r
+\r
   /**\r
    * Returns the computed left position of the first element matched.\r
    */\r
   public int left() {\r
     return (int) GQUtils.cur(get(0), "left", true);\r
-  }  \r
-  \r
+  }\r
+\r
   /**\r
    * Returns the number of elements currently matched. The size function will\r
    * return the same value.\r
    */\r
   public int length() {\r
     return size();\r
-  }  \r
\r
+  }\r
+\r
   /**\r
    * Bind a function to the load event of each matched element.\r
    */\r
   public GQuery load(Function f) {\r
     return bind(Event.ONLOAD, null, f);\r
-  }  \r
+  }\r
 \r
   /**\r
    * Reduce the set of matched elements to all elements before a given position.\r
@@ -1346,7 +1363,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
    */\r
   public GQuery lt(int pos) {\r
     return $(slice(0, pos));\r
-  }  \r
+  }\r
 \r
   /**\r
    * Bind a set of functions to the mousedown event of each matched element.\r
@@ -1354,15 +1371,15 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
    */\r
   public GQuery mousedown(Function...f) {\r
     return bindOrFire(Event.ONMOUSEDOWN, null, f);\r
-  }  \r
-  \r
+  }\r
+\r
   /**\r
    * Bind a set of functions to the mousemove event of each matched element.\r
    * Or trigger the event if no functions are provided.\r
    */\r
   public GQuery mousemove(Function...f) {\r
     return bindOrFire(Event.ONMOUSEMOVE, null, f);\r
-  }    \r
+  }\r
 \r
   /**\r
    * Bind a set of functions to the mouseout event of each matched element.\r
@@ -1486,9 +1503,9 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
    */\r
   public GQuery offsetParent() {\r
     Element offParent = GQUtils.or(elements.getItem(0).getOffsetParent(), body);\r
-    while (offParent != null \r
+    while (offParent != null\r
         && !"body".equalsIgnoreCase(offParent.getTagName())\r
-        && !"html".equalsIgnoreCase(offParent.getTagName()) \r
+        && !"html".equalsIgnoreCase(offParent.getTagName())\r
         && "static".equals(styleImpl.curCSS(offParent, "position", true))) {\r
       offParent = offParent.getOffsetParent();\r
     }\r
@@ -1595,11 +1612,11 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
   public GQuery prepend(String html) {\r
     return domManip(html, document, FUNC_PREPEND);\r
   }\r
-  \r
+\r
   /**\r
-   * All of the matched set of elements will be inserted at the beginning \r
+   * All of the matched set of elements will be inserted at the beginning\r
    * of the element(s) specified by the parameter other.\r
-   * \r
+   *\r
    * The operation $(A).prependTo(B) is, essentially, the reverse of doing a regular\r
    * $(A).prepend(B), instead of prepending B to A, you're prepending A to B.\r
    */\r
@@ -1609,9 +1626,9 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
   }\r
 \r
   /**\r
-   * All of the matched set of elements will be inserted at the beginning \r
+   * All of the matched set of elements will be inserted at the beginning\r
    * of the element(s) specified by the parameter other.\r
-   * \r
+   *\r
    * The operation $(A).prependTo(B) is, essentially, the reverse of doing a regular\r
    * $(A).prepend(B), instead of prepending B to A, you're prepending A to B.\r
    */\r
@@ -1621,9 +1638,9 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
   }\r
 \r
   /**\r
-   * All of the matched set of elements will be inserted at the beginning \r
+   * All of the matched set of elements will be inserted at the beginning\r
    * of the element(s) specified by the parameter other.\r
-   * \r
+   *\r
    * The operation $(A).prependTo(B) is, essentially, the reverse of doing a regular\r
    * $(A).prepend(B), instead of prepending B to A, you're prepending A to B.\r
    */\r
@@ -1720,7 +1737,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
     }\r
     return this;\r
   }\r
-  \r
+\r
   /**\r
    * Replaces the elements matched by the specified selector with the matched\r
    * elements. This function is the complement to replaceWith() which does the\r
@@ -1758,8 +1775,8 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
    */\r
   public GQuery replaceWith(Element elem) {\r
     return replaceWith($(elem));\r
-  }    \r
-  \r
+  }\r
+\r
   /**\r
    * Replaces all matched elements with the specified HTML or DOM elements. This\r
    * returns the GQuery element that was just replaced, which has been removed\r
@@ -1788,7 +1805,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
       }\r
     }\r
   }\r
-  \r
+\r
   /**\r
    * Restore a set of previously saved Css properties in every matched element.\r
    */\r
@@ -1921,7 +1938,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
    */\r
   public GQuery show() {\r
     for (Element e : elements()) {\r
-      styleImpl.setStyleProperty(e, "display", \r
+      styleImpl.setStyleProperty(e, "display",\r
           GQUtils.or((String) data(e, "oldDisplay", null), ""));\r
       // When the display=none is in the stylesheet.\r
       if (!styleImpl.isVisible(e)) {\r
@@ -2020,7 +2037,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
     return click(new Function() {\r
       int click = 0;\r
       public boolean f(Event e) {\r
-        int n = fn.length == 1 ? 0 : (click++ % fn.length); \r
+        int n = fn.length == 1 ? 0 : (click++ % fn.length);\r
         return fn[n].f(e);\r
       }\r
     });\r
@@ -2046,7 +2063,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
   /**\r
    * Adds or removes the specified classes to each matched element\r
    * depending on the value of the switch argument.\r
-   * \r
+   *\r
    * if addOrRemove is true, the class is added and in the case of\r
    * false it is removed.\r
    */\r
@@ -2058,13 +2075,13 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
     }\r
     return this;\r
   }\r
-  \r
+\r
   /**\r
    * Returns the computed left position of the first element matched.\r
    */\r
   public int top() {\r
     return (int) GQUtils.cur(get(0), "top", true);\r
-  }  \r
+  }\r
 \r
   /**\r
    * Produces a string representation of the matched elements.\r
@@ -2089,10 +2106,10 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
 \r
   /**\r
    * Trigger a set of events on each matched element.\r
-   * \r
-   * For keyboard events you can pass a second parameter which represents \r
-   * the key-code of the pushed key. \r
-   * \r
+   *\r
+   * For keyboard events you can pass a second parameter which represents\r
+   * the key-code of the pushed key.\r
+   *\r
    * Example: fire(Event.ONCLICK | Event.ONFOCUS)\r
    * Example: fire(Event.ONKEYDOWN. 'a');\r
    */\r
@@ -2154,7 +2171,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
       } else if ("input".equalsIgnoreCase(name)) {\r
         InputElement ie = InputElement.as(e);\r
         String type = ie.getType();\r
-        if ("radio".equalsIgnoreCase((type)) \r
+        if ("radio".equalsIgnoreCase((type))\r
             || "checkbox".equalsIgnoreCase(type)) {\r
           if ("checkbox".equalsIgnoreCase(type)) {\r
             for (String val : values) {\r
@@ -2429,7 +2446,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
   }\r
 \r
   /**\r
-   * Bind Handlers or fire Events for each matched element. \r
+   * Bind Handlers or fire Events for each matched element.\r
    */\r
   private GQuery bindOrFire(int eventbits, final Object data, final Function...funcs) {\r
     if (funcs.length == 0) {\r
@@ -2438,28 +2455,13 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
       return bind(eventbits, data, funcs);\r
     }\r
   }\r
-  \r
-  private GQuery domManip(String htmlString, int func) {\r
-    GQuery ret = $();\r
-    HashMap<Document, GQuery> cache = new HashMap<Document, GQuery>();\r
-    for (Element e: elements()) {\r
-      Document d = e.getNodeType() == Node.DOCUMENT_NODE ? e.<Document>cast() : e.getOwnerDocument();\r
-      GQuery g = cache.get(d);\r
-      if (g == null) {\r
-        g = cleanHtmlString(htmlString, d);\r
-        cache.put(d, g);\r
-      }\r
-      ret.add(domManip(g, func));\r
-    }\r
-    return ret;\r
-  }\r
 \r
   private GQuery domManip(GQuery g, int func) {\r
     JSArray newNodes = JSArray.create();\r
     for (int i = 0; i < elements().length; i++) {\r
       Element e = elements()[i];\r
       e.getOwnerDocument();\r
-      if (e.getNodeType() == Node.DOCUMENT_NODE) { \r
+      if (e.getNodeType() == Node.DOCUMENT_NODE) {\r
         e = e.<Document>cast().getBody();\r
       }\r
       for (int j = 0; j < g.size(); j++) {\r
@@ -2493,12 +2495,21 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
     return domManip(html, func);\r
   }\r
 \r
-  private native Document getContentDocument(Node n) /*-{\r
-    var d =  n.contentDocument || n.contentWindow.document;\r
-    if (!d.body) d.write("<body/>");\r
-    return d;\r
-  }-*/;\r
-  \r
+  private GQuery domManip(String htmlString, int func) {\r
+    GQuery ret = $();\r
+    HashMap<Document, GQuery> cache = new HashMap<Document, GQuery>();\r
+    for (Element e: elements()) {\r
+      Document d = e.getNodeType() == Node.DOCUMENT_NODE ? e.<Document>cast() : e.getOwnerDocument();\r
+      GQuery g = cache.get(d);\r
+      if (g == null) {\r
+        g = cleanHtmlString(htmlString, d);\r
+        cache.put(d, g);\r
+      }\r
+      ret.add(domManip(g, func));\r
+    }\r
+    return ret;\r
+  }\r
+\r
   private native Element getPreviousSiblingElement(Element elem)  /*-{\r
     var sib = elem.previousSibling;\r
     while (sib && sib.nodeType != 1)\r
@@ -2513,7 +2524,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
     }\r
     return res;\r
   }\r
-  \r
+\r
   private void removeData(Element item, String name) {\r
     if (dataCache == null) {\r
       windowData = JavaScriptObject.createObject().cast();\r
@@ -2532,5 +2543,5 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
       dataCache.delete(id);\r
     }\r
   }\r
-  \r
+\r
 }\r
index 8ebc67def9bbfbf612815caa242a15db8f58c5d6..5c7d1ac8a8763d48ad9c0618d12db4bb40d59aaf 100644 (file)
@@ -193,7 +193,9 @@ public class GQueryCoreTest extends GWTTestCase {
 
   public void testIFrameManipulation() {
     $(e).html("<iframe name='miframe' id='miframe' src=\"javascript:''\">");
-    Document d = $("#miframe").contents().get(0).cast();
+    // FF has to call empty to open and close the document before 
+    // accessing the recently created iframe content
+    Document d = $("#miframe").contents().empty().get(0).cast();
     assertNotNull(d);
     assertNotNull(d.getBody());
     assertEquals(1, $("#miframe").contents().size());