Fixed #1264. If you read the bug there were many proposed changes. As it turned...
authorDavid Serduke <davidserduke@gmail.com>
Wed, 5 Dec 2007 00:26:13 +0000 (00:26 +0000)
committerDavid Serduke <davidserduke@gmail.com>
Wed, 5 Dec 2007 00:26:13 +0000 (00:26 +0000)
In addition "submit.gif" was removed from the test suite index.html since it didn't exist.

src/core.js
test/data/iframe.html [new file with mode: 0644]
test/index.html
test/unit/core.js

index ce487a1..0f27425 100644 (file)
@@ -202,7 +202,7 @@ jQuery.fn = jQuery.prototype = {
 
        text: function( text ) {
                if ( typeof text != "object" && text != null )
-                       return this.empty().append( document.createTextNode( text ) );
+                       return this.empty().append( (this[0] && this[0].ownerDocument || document).createTextNode( text ) );
 
                var ret = "";
 
@@ -468,7 +468,7 @@ jQuery.fn = jQuery.prototype = {
                        var obj = this;
 
                        if ( table && jQuery.nodeName( this, "table" ) && jQuery.nodeName( elems[0], "tr" ) )
-                               obj = this.getElementsByTagName("tbody")[0] || this.appendChild( document.createElement("tbody") );
+                               obj = this.getElementsByTagName("tbody")[0] || this.appendChild( this.ownerDocument.createElement("tbody") );
 
                        var scripts = jQuery( [] );
 
diff --git a/test/data/iframe.html b/test/data/iframe.html
new file mode 100644 (file)
index 0000000..3ff26e1
--- /dev/null
@@ -0,0 +1,8 @@
+<html>
+  <head>
+    <title>iframe</title>
+  </head>
+  <body>
+    <div><span>span text</span></div>
+  </body>
+</html>
index 2b0b685..4f68639 100644 (file)
@@ -21,6 +21,8 @@
        
        <!-- Test HTML -->
        <div id="nothiddendiv" style="height:1px;background:white;"></div>
+       <!-- this iframe is outside the #main so it won't reload constantly wasting time, but it means the tests must be "safe" and clean up after themselves -->
+       <iframe id="loadediframe" name="loadediframe" style="display:none;" src="data/iframe.html"></iframe>
        <dl id="dl" style="display:none;">
        <div id="main" style="display: none;">
                <p id="firstp">See <a id="simon1" href="http://simon.incutio.com/archive/2003/03/25/#getElementsBySelector" rel="bookmark">this blog entry</a> for more information.</p>
@@ -151,7 +153,7 @@ Z</textarea>
                        </select>
                        <input type="submit" name="sub1" value="NO" />
                        <input type="submit" name="sub2" value="NO" />
-                       <input type="image" name="sub3" value="NO" src="submit.gif" />
+                       <input type="image" name="sub3" value="NO" />
                        <button name="sub4" type="submit" value="NO">NO</button>
                        <input name="D1" type="text" value="NO" disabled="disabled" />
                        <input type="checkbox" checked="checked" disabled="disabled" name="D2" value="NO" />
index f3a3aa3..d69696a 100644 (file)
@@ -551,7 +551,7 @@ test("append(String|Element|Array&lt;Element&gt;|jQuery)", function() {
        reset();
        var pass = true;
        try {
-               $( $("iframe")[0].contentWindow.document.body ).append("<div>test</div>");
+               $( $("#iframe")[0].contentWindow.document.body ).append("<div>test</div>");
        } catch(e) {
                pass = false;
        }
@@ -1188,9 +1188,28 @@ test("map()", function() {
 });
 
 test("contents()", function() {
-       expect(2);
+       expect(10);
        equals( $("#ap").contents().length, 9, "Check element contents" );
        ok( $("#iframe").contents()[0], "Check existance of IFrame document" );
-       // Disabled, randomly fails
-       //ok( $("#iframe").contents()[0].body, "Check existance of IFrame body" );
+       var ibody = $("#loadediframe").contents()[0].body;
+       ok( ibody, "Check existance of IFrame body" );
+
+       equals( $("span", ibody).text(), "span text", "Find span in IFrame and check its text" );
+
+       $(ibody).append("<div>init text</div>");
+       equals( $("div", ibody).length, 2, "Check the original div and the new div are in IFrame" );
+
+       equals( $("div:last", ibody).text(), "init text", "Add text to div in IFrame" );
+
+       $("div:last", ibody).text("div text");
+       equals( $("div:last", ibody).text(), "div text", "Add text to div in IFrame" );
+
+       $("div:last", ibody).remove();
+       equals( $("div", ibody).length, 1, "Delete the div and check only one div left in IFrame" );
+
+       equals( $("div", ibody).text(), "span text", "Make sure the correct div is still left after deletion in IFrame" );
+
+       $("<table/>", ibody).append("<tr><td>cell</td></tr>").appendTo(ibody);
+       $("table", ibody).remove();
+       equals( $("div", ibody).length, 1, "Check for JS error on add and delete of a table in IFrame" );
 });