LayoutTests:
authoraliceli1 <aliceli1@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 28 Aug 2006 20:43:36 +0000 (20:43 +0000)
committeraliceli1 <aliceli1@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 28 Aug 2006 20:43:36 +0000 (20:43 +0000)
        Reviewed by Geoff.

       Added tests for <rdar://problem/4548537> Document.domain and other attributes are blank for an iframe created with document.write

        * http/tests/misc/iframe-domain-test-expected.txt: Added.
        * http/tests/misc/iframe-domain-test.html: Added.

WebCore:

        Reviewed by Geoff.

        Fixed <rdar://problem/4548537> Document.domain and other attributes are blank for an iframe created with document.write

        * dom/Document.cpp:
        (WebCore::Document::open):
        set the document's url to the parent's url and re-located the code that does this to occur before calling the frame's didExplicitOpen()
        * page/Frame.cpp:
        (WebCore::Frame::didExplicitOpen):
        set the frame's url to the document's url

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@16081 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/http/tests/misc/iframe-domain-test-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/misc/iframe-domain-test.html [new file with mode: 0644]
WebCore/ChangeLog
WebCore/dom/Document.cpp
WebCore/page/Frame.cpp

index 28595e0c15389b088192fb46d0e732f68cd95a85..0b547bdca2a5fbd2ce08cdffc709ccf3d81e3b11 100644 (file)
@@ -1,3 +1,12 @@
+2006-08-28  Alice Liu  <alice.liu@apple.com>
+
+        Reviewed by Geoff.
+
+       Added tests for <rdar://problem/4548537> Document.domain and other attributes are blank for an iframe created with document.write
+
+        * http/tests/misc/iframe-domain-test-expected.txt: Added.
+        * http/tests/misc/iframe-domain-test.html: Added.
+
 2006-08-27  Rob Buis  <buis@kde.org>
 
         Reviewed by Eric.
diff --git a/LayoutTests/http/tests/misc/iframe-domain-test-expected.txt b/LayoutTests/http/tests/misc/iframe-domain-test-expected.txt
new file mode 100644 (file)
index 0000000..f7f0fa5
--- /dev/null
@@ -0,0 +1,3 @@
+PASS
+PASS
+
diff --git a/LayoutTests/http/tests/misc/iframe-domain-test.html b/LayoutTests/http/tests/misc/iframe-domain-test.html
new file mode 100644 (file)
index 0000000..a95cb00
--- /dev/null
@@ -0,0 +1,95 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org\tR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+<title>iFrame Test</title>
+<script>
+function run()
+{
+    window.frames['test1'].document.open("text/html","replace");
+    window.frames['test1'].document.close();
+                        
+    var src = "<html>\n<head>\n<script>\nfunction fill()\n{\n    document.getElementById(\"domain\").innerHTML = document.domain;\n    document.getElementById(\"URL\").innerHTML = document.URL;\n    document.getElementById(\"wlh\").innerHTML = window.location.href;\n    document.getElementById(\"plh\").innerHTML = parent.location.href;\n}\n<\/script>\n<\/head>\n<body onload=\"fill();\">\nThis iframe's src was set with document.write.\n<br><br>\ndocument.domain: <span id=\"domain\"><\/span>\n<br><br>\ndocument.URL: <span id=\"URL\"><\/span>\n<br><br>\nwindow.location.href: <span id=\"wlh\"><\/span>\n<br><br>\nparent.location.href: <span id=\"plh\"><\/span>\n<\/body>\n<\/html>\n";
+    window.frames['test2'].document.open("text/html","replace");
+    window.frames['test2'].document.write(src);
+    window.frames['test2'].document.close();
+
+    var oSpan1 = document.getElementById("result1");
+    var pass = true;
+    var str = "";
+    if (window.frames['test1'].document.domain != document.domain) {
+        pass = false;
+        str = "document.domain is " + window.frames['test1'].document.domain + " but should be " + document.domain + "<br>";
+    }
+        
+    if (window.frames['test1'].document.URL != document.URL) {
+        pass = false;
+        str += "document.URL is " + window.frames['test1'].document.URL + " but should be " + document.URL + "<br>";
+    }
+
+    if (window.frames['test1'].window.location.href != window.location.href) {
+        pass = false;
+        str += "window.location.href is " + window.frames['test1'].window.location.href + " but should be " + window.location.href + "<br>";
+    }
+
+    if (window.frames['test1'].parent.location.href != parent.location.href) {
+        pass = false;
+        str += "parent.location.href is " + window.frames['test1'].parent.location.href + " but should be " + parent.location.href + "<br>";
+    }
+    
+    if (pass)
+    {
+        oSpan1.setAttribute("style", "color: green;");
+        oSpan1.innerHTML = "PASS";
+    }
+    else
+    {
+        oSpan1.setAttribute("style", "color: red;");
+        oSpan1.innerHTML = "FAIL<br>" + str;
+    }
+        
+    var oSpan2 = document.getElementById("result2");
+    pass = true;
+    str = "";
+    if (window.frames['test2'].document.domain != document.domain) {
+        pass = false;
+        str = "document.domain is " + window.frames['test2'].document.domain + " but should be " + document.domain + "<br>";
+    }
+        
+    if (window.frames['test2'].document.URL != document.URL) {
+        pass = false;
+        str += "document.URL is " + window.frames['test2'].document.URL + " but should be " + document.URL + "<br>";
+    }
+
+    if (window.frames['test2'].window.location.href != window.location.href) {
+        pass = false;
+        str += "window.location.href is " + window.frames['test2'].window.location.href + " but should be " + window.location.href + "<br>";
+    }
+
+    if (window.frames['test2'].parent.location.href != parent.location.href) {
+        pass = false;
+        str += "parent.location.href is " + window.frames['test2'].parent.location.href + " but should be " + parent.location.href + "<br>";
+    }
+    
+    if (pass)
+    {
+        oSpan2.setAttribute("style", "color: green;");
+        oSpan2.innerHTML = "PASS";
+    }
+    else
+    {
+        oSpan2.setAttribute("style", "color: red;");
+        oSpan2.innerHTML = "FAIL<br>" + str;
+    }    
+
+    if (window.layoutTestController)
+        layoutTestController.dumpAsText();
+}
+
+</script>
+</head>
+
+<body onload="run();">
+<iframe name="test1" style="border: 1px solid black;"></iframe><span id="result1"></span><br>
+<iframe name="test2" style="width: 500px; height: 200px; border: 1px solid black;"></iframe><span id="result2"></span><br>
+</body>
+</html>
index 2579849c801f4ad0b32610b2c0604380a824474d..7ecf9bbec7e7b07806914ce945724a04053a2ba2 100644 (file)
@@ -1,3 +1,16 @@
+2006-08-28  Alice Liu  <alice.liu@apple.com>
+
+        Reviewed by Geoff.
+
+        Fixed <rdar://problem/4548537> Document.domain and other attributes are blank for an iframe created with document.write
+
+        * dom/Document.cpp:
+        (WebCore::Document::open):
+        set the document's url to the parent's url and re-located the code that does this to occur before calling the frame's didExplicitOpen()
+        * page/Frame.cpp:
+        (WebCore::Frame::didExplicitOpen):
+        set the frame's url to the document's url
+
 2006-08-28  Brady Eidson  <beidson@apple.com>
 
         Reviewed by Adele and Adam
index 80b71f3f38c4d29c3c0a3d0ed78761767fe7dc53..88ea6592c35ee2915ed523e2f3ab47082ea2149c 100644 (file)
@@ -1108,6 +1108,16 @@ Tokenizer *Document::createTokenizer()
 
 void Document::open()
 {
+    // This is work that we should probably do in clear(), but we can't have it
+    // happen when implicitOpen() is called unless we reorganize Frame code.
+    if (Document *parent = parentDocument()) {
+        setURL(parent->baseURL());
+        setBaseURL(parent->baseURL());
+    }
+    else
+        setURL(DeprecatedString());
+        
+
     if ((frame() && frame()->isLoadingMainResource()) || (tokenizer() && tokenizer()->executingScript()))
         return;
 
@@ -1115,12 +1125,6 @@ void Document::open()
 
     if (frame())
         frame()->didExplicitOpen();
-
-    // This is work that we should probably do in clear(), but we can't have it
-    // happen when implicitOpen() is called unless we reorganize Frame code.
-    setURL(DeprecatedString());
-    if (Document *parent = parentDocument())
-        setBaseURL(parent->baseURL());
 }
 
 void Document::cancelParsing()
index 4c037977d9c48b5d3c2c998510b69689dfe78bbc..d7322fedfb4b77d109ae436a0da144ccdc825796 100644 (file)
@@ -271,6 +271,7 @@ void Frame::didExplicitOpen()
   // Cancelling redirection here works for all cases because document.open 
   // implicitly precedes document.write.
   cancelRedirection(); 
+  d->m_url = d->m_doc->URL();
 }
 
 void Frame::stopLoading(bool sendUnload)