aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/core.js4
-rw-r--r--test/data/iframe.html8
-rw-r--r--test/index.html4
-rw-r--r--test/unit/core.js27
4 files changed, 36 insertions, 7 deletions
diff --git a/src/core.js b/src/core.js
index ce487a10f..0f274255f 100644
--- a/src/core.js
+++ b/src/core.js
@@ -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
index 000000000..3ff26e161
--- /dev/null
+++ b/test/data/iframe.html
@@ -0,0 +1,8 @@
+<html>
+ <head>
+ <title>iframe</title>
+ </head>
+ <body>
+ <div><span>span text</span></div>
+ </body>
+</html>
diff --git a/test/index.html b/test/index.html
index 2b0b685fc..4f6863968 100644
--- a/test/index.html
+++ b/test/index.html
@@ -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" />
diff --git a/test/unit/core.js b/test/unit/core.js
index f3a3aa3db..d69696a1e 100644
--- a/test/unit/core.js
+++ b/test/unit/core.js
@@ -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" );
});