2011-03-29 Gavin Peters <gavinp@chromium.org>
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 29 Mar 2011 22:53:03 +0000 (22:53 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 29 Mar 2011 22:53:03 +0000 (22:53 +0000)
        Reviewed by Tony Gentilcore.

        Add beforeload to icon and prefetch link rel types
        https://bugs.webkit.org/show_bug.cgi?id=56424

        Unfortunately, there's lots of skipped tests, and a chrome failure
        expectation here, in a strange disjoint set.  On the chromium
        port, favicon loads don't occur in DRT, so the favicon changes are
        expected to fail.  On the ports without prefetching, we expect the
        prefetching test to fail.

        * fast/dom/HTMLLinkElement/prefetch-beforeload-expected.txt: Added.
        * fast/dom/HTMLLinkElement/prefetch-beforeload.html: Added.
        * http/tests/misc/link-rel-icon-beforeload-expected.txt: Added.
        * http/tests/misc/link-rel-icon-beforeload.html: Added.
        * platform/chromium/test_expectations.txt:
        * platform/gtk/Skipped:
        * platform/mac/Skipped:
        * platform/qt/Skipped:
        * platform/win/Skipped:
        * webarchive/test-link-rel-icon-beforeload-expected.webarchive: Added.
        * webarchive/test-link-rel-icon-beforeload.html: Added.
2011-03-29  Gavin Peters  <gavinp@chromium.org>

        Reviewed by Tony Gentilcore.

        Add beforeload to icon and prefetch link rel types
        https://bugs.webkit.org/show_bug.cgi?id=56424

        Over in https://lists.webkit.org/pipermail/webkit-dev/2011-February/016034.html , a webkit-dev
        thread, I've discussed my hopes for the link element, and adding the link header.  This
        change helps improve the link header by making it participate in the beforeload event in
        two more important cases.

        Tests: fast/dom/HTMLLinkElement/prefetch-beforeload.html
               http/tests/misc/link-rel-icon-beforeload.html
               webarchive/test-link-rel-icon-beforeload.html

        * html/HTMLLinkElement.cpp:
        (WebCore::HTMLLinkElement::checkBeforeLoadEvent):
        (WebCore::HTMLLinkElement::process):
        * html/HTMLLinkElement.h:

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

15 files changed:
LayoutTests/ChangeLog
LayoutTests/fast/dom/HTMLLinkElement/prefetch-beforeload-expected.txt [new file with mode: 0644]
LayoutTests/fast/dom/HTMLLinkElement/prefetch-beforeload.html [new file with mode: 0644]
LayoutTests/http/tests/misc/link-rel-icon-beforeload-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/misc/link-rel-icon-beforeload.html [new file with mode: 0644]
LayoutTests/platform/chromium/test_expectations.txt
LayoutTests/platform/gtk/Skipped
LayoutTests/platform/mac/Skipped
LayoutTests/platform/qt/Skipped
LayoutTests/platform/win/Skipped
LayoutTests/webarchive/test-link-rel-icon-beforeload-expected.webarchive [new file with mode: 0644]
LayoutTests/webarchive/test-link-rel-icon-beforeload.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/html/HTMLLinkElement.cpp
Source/WebCore/html/HTMLLinkElement.h

index 9192ca8..c00fb9d 100644 (file)
@@ -1,3 +1,28 @@
+2011-03-29  Gavin Peters  <gavinp@chromium.org>
+
+        Reviewed by Tony Gentilcore.
+
+        Add beforeload to icon and prefetch link rel types
+        https://bugs.webkit.org/show_bug.cgi?id=56424
+
+        Unfortunately, there's lots of skipped tests, and a chrome failure
+        expectation here, in a strange disjoint set.  On the chromium
+        port, favicon loads don't occur in DRT, so the favicon changes are
+        expected to fail.  On the ports without prefetching, we expect the
+        prefetching test to fail.
+
+        * fast/dom/HTMLLinkElement/prefetch-beforeload-expected.txt: Added.
+        * fast/dom/HTMLLinkElement/prefetch-beforeload.html: Added.
+        * http/tests/misc/link-rel-icon-beforeload-expected.txt: Added.
+        * http/tests/misc/link-rel-icon-beforeload.html: Added.
+        * platform/chromium/test_expectations.txt:
+        * platform/gtk/Skipped:
+        * platform/mac/Skipped:
+        * platform/qt/Skipped:
+        * platform/win/Skipped:
+        * webarchive/test-link-rel-icon-beforeload-expected.webarchive: Added.
+        * webarchive/test-link-rel-icon-beforeload.html: Added.
+
 2011-03-29  Adam Barth  <abarth@webkit.org>
 
         Moar pixel expectations.
diff --git a/LayoutTests/fast/dom/HTMLLinkElement/prefetch-beforeload-expected.txt b/LayoutTests/fast/dom/HTMLLinkElement/prefetch-beforeload-expected.txt
new file mode 100644 (file)
index 0000000..c7fb018
--- /dev/null
@@ -0,0 +1,2 @@
+PASS beforeload called
+This test will only print "PASS" or "FAIL" if link prefetches are enabled, otherwise it will show nothing below.
diff --git a/LayoutTests/fast/dom/HTMLLinkElement/prefetch-beforeload.html b/LayoutTests/fast/dom/HTMLLinkElement/prefetch-beforeload.html
new file mode 100644 (file)
index 0000000..27a62af
--- /dev/null
@@ -0,0 +1,14 @@
+<body>
+<div id="console"></div>
+<script src="../../js/resources/js-test-pre.js"></script>
+<script>
+if (window.layoutTestController) {
+    layoutTestController.dumpAsText();
+}
+</script>
+<html>
+<p>This test will only print "PASS" or "FAIL" if link prefetches are
+enabled, otherwise it will show nothing below.</p>
+<link href="prefetch.link" rel="prefetch" onbeforeload="testPassed('beforeload called');return false" onload="testFailed('onload')" onerror="testFailed('onerror')" />
+</html>
+
diff --git a/LayoutTests/http/tests/misc/link-rel-icon-beforeload-expected.txt b/LayoutTests/http/tests/misc/link-rel-icon-beforeload-expected.txt
new file mode 100644 (file)
index 0000000..2c7d533
--- /dev/null
@@ -0,0 +1,7 @@
+<unknown> - didFinishLoading
+http://127.0.0.1:8000/misc/link-rel-icon-beforeload.html - willSendRequest <NSURLRequest URL http://127.0.0.1:8000/misc/link-rel-icon-beforeload.html, main document URL http://127.0.0.1:8000/misc/link-rel-icon-beforeload.html, http method GET> redirectResponse (null)
+http://127.0.0.1:8000/misc/link-rel-icon-beforeload.html - didReceiveResponse <NSURLResponse http://127.0.0.1:8000/misc/link-rel-icon-beforeload.html, http status code 200>
+http://127.0.0.1:8000/favicon.ico - willSendRequest <NSURLRequest URL http://127.0.0.1:8000/favicon.ico, main document URL http://127.0.0.1:8000/misc/link-rel-icon-beforeload.html, http method GET> redirectResponse (null)
+http://127.0.0.1:8000/misc/link-rel-icon-beforeload.html - didFinishLoading
+http://127.0.0.1:8000/favicon.ico - didReceiveResponse <NSURLResponse http://127.0.0.1:8000/favicon.ico, http status code 200>
+This test should not show a request for the favicon dont-load-this.ico, since the beforeload handler on the favicon link returns false. Therefore, if the resource request list below shows a request for dont-load-this.ico, then this test has failed.
diff --git a/LayoutTests/http/tests/misc/link-rel-icon-beforeload.html b/LayoutTests/http/tests/misc/link-rel-icon-beforeload.html
new file mode 100644 (file)
index 0000000..685bfef
--- /dev/null
@@ -0,0 +1,22 @@
+<html>
+<head>
+<script>
+function runTest()
+{
+    if (window.layoutTestController) {
+        layoutTestController.dumpAsText();
+        layoutTestController.dumpResourceLoadCallbacks();
+        layoutTestController.setIconDatabaseEnabled(true);
+        layoutTestController.queueReload();
+    }
+}
+</script>
+</head>
+<body onload="runTest()">
+<link rel="icon" onbeforeload="return false" href="dont-load-this.ico">
+<p>This test should not show a request for the favicon
+dont-load-this.ico, since the beforeload handler on the favicon link
+returns false.  Therefore, if the resource request list below shows a
+request for dont-load-this.ico, then this test has failed.
+</body>
+</html>
index 98db30e..afbdefc 100755 (executable)
@@ -3353,3 +3353,6 @@ BUGXXX GPU MAC SNOWLEOPARD : compositing/overflow/overflow-compositing-descendan
 BUGXXX GPU MAC SNOWLEOPARD : compositing/overflow/scroll-ancestor-update.html = FAIL
 BUGXXX GPU MAC SNOWLEOPARD : compositing/reflections/load-video-in-reflection.html = FAIL
 BUGXXX GPU MAC SNOWLEOPARD : compositing/self-painting-layers.html = FAIL
+
+// Chrome doesn't load favicons in DRT tests.
+BUGWK57259 : http/tests/misc/link-rel-icon-beforeload.html = FAIL PASS
index 500ec5b..7fc6f59 100644 (file)
@@ -921,6 +921,7 @@ fast/dom/HTMLLinkElement/link-and-subresource-test.html
 fast/dom/HTMLLinkElement/prefetch.html
 fast/dom/HTMLLinkElement/prefetch-onerror.html
 fast/dom/HTMLLinkElement/prefetch-onload.html
+fast/dom/HTMLLinkElement/prefetch-beforeload.html
 
 # Tests failing because the context menu is grabbing mouse events.
 # https://bugs.webkit.org/show_bug.cgi?id=40601
index 2962c19..be63842 100644 (file)
@@ -182,6 +182,7 @@ fast/dom/Window/window-properties-device-orientation.html
 # Link prefetch is disabled by default
 fast/dom/HTMLLinkElement/link-and-subresource-test.html
 fast/dom/HTMLLinkElement/prefetch.html
+fast/dom/HTMLLinkElement/prefetch-beforeload.html
 fast/dom/HTMLLinkElement/prefetch-onerror.html
 fast/dom/HTMLLinkElement/prefetch-onload.html
 http/tests/misc/prefetch-purpose.html
index 1f1e038..f95ada2 100644 (file)
@@ -2980,6 +2980,7 @@ media/video-delay-load-event.html
 # Link prefetch is disabled by default
 fast/dom/HTMLLinkElement/link-and-subresource-test.html
 fast/dom/HTMLLinkElement/prefetch.html
+fast/dom/HTMLLinkElement/prefetch-beforeload.html
 fast/dom/HTMLLinkElement/prefetch-onerror.html
 fast/dom/HTMLLinkElement/prefetch-onload.html
 http/tests/misc/prefetch-purpose.html
index 3c4f883..08f0e4e 100644 (file)
@@ -990,6 +990,7 @@ fast/dom/Window/window-properties-device-orientation.html
 # Link prefetch is disabled by default
 fast/dom/HTMLLinkElement/link-and-subresource-test.html
 fast/dom/HTMLLinkElement/prefetch.html
+fast/dom/HTMLLinkElement/prefetch-beforeload.html
 fast/dom/HTMLLinkElement/prefetch-onerror.html
 fast/dom/HTMLLinkElement/prefetch-onload.html
 http/tests/misc/prefetch-purpose.html
diff --git a/LayoutTests/webarchive/test-link-rel-icon-beforeload-expected.webarchive b/LayoutTests/webarchive/test-link-rel-icon-beforeload-expected.webarchive
new file mode 100644 (file)
index 0000000..73c885f
--- /dev/null
@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+       <key>WebMainResource</key>
+       <dict>
+               <key>WebResourceData</key>
+               <string>&lt;html&gt;&lt;head&gt;
+&lt;script&gt;
+function runTest()
+{
+    if (window.layoutTestController) {
+        layoutTestController.setIconDatabaseEnabled(true);
+        layoutTestController.dumpDOMAsWebArchive();
+        layoutTestController.queueReload();
+    }
+}
+&lt;/script&gt;
+&lt;/head&gt;
+&lt;body onload="runTest()"&gt;
+&lt;div id="console"&gt;&lt;div style="font-family: monospace; color: green; "&gt;PASS&lt;/div&gt;&lt;/div&gt;
+&lt;script&gt;
+function print(message, color) 
+{
+    var paragraph = document.createElement("div");
+    paragraph.appendChild(document.createTextNode(message));
+    paragraph.style.fontFamily = "monospace";
+    if (color)
+        paragraph.style.color = color;
+    document.getElementById("console").appendChild(paragraph);
+}
+&lt;/script&gt;
+&lt;p&gt;This test should have a green 'PASS' just above this line.  If it doesn't, you failed.
+&lt;link rel="icon" onbeforeload="print('PASS','green');return false" href="resources/favicon.ico" type="image/x-icon"&gt;
+
+
+&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
+               <key>WebResourceFrameName</key>
+               <string></string>
+               <key>WebResourceMIMEType</key>
+               <string>text/html</string>
+               <key>WebResourceTextEncodingName</key>
+               <string>UTF-8</string>
+               <key>WebResourceURL</key>
+               <string>file:///LayoutTests/webarchive/test-link-rel-icon-beforeload.html</string>
+       </dict>
+</dict>
+</plist>
diff --git a/LayoutTests/webarchive/test-link-rel-icon-beforeload.html b/LayoutTests/webarchive/test-link-rel-icon-beforeload.html
new file mode 100644 (file)
index 0000000..5c0bb84
--- /dev/null
@@ -0,0 +1,30 @@
+<html>
+<head>
+<script>
+function runTest()
+{
+    if (window.layoutTestController) {
+        layoutTestController.setIconDatabaseEnabled(true);
+        layoutTestController.dumpDOMAsWebArchive();
+        layoutTestController.queueReload();
+    }
+}
+</script>
+</head>
+<body onload="runTest()">
+<div id="console"></div>
+<script>
+function print(message, color) 
+{
+    var paragraph = document.createElement("div");
+    paragraph.appendChild(document.createTextNode(message));
+    paragraph.style.fontFamily = "monospace";
+    if (color)
+        paragraph.style.color = color;
+    document.getElementById("console").appendChild(paragraph);
+}
+</script>
+<p>This test should have a green 'PASS' just above this line.  If it doesn't, you failed.
+<link rel="icon" onbeforeload="print('PASS','green');return false" href="resources/favicon.ico" type="image/x-icon">
+</body>
+</html>
index be73e87..4a995f6 100644 (file)
@@ -1,3 +1,24 @@
+2011-03-29  Gavin Peters  <gavinp@chromium.org>
+
+        Reviewed by Tony Gentilcore.
+
+        Add beforeload to icon and prefetch link rel types
+        https://bugs.webkit.org/show_bug.cgi?id=56424
+
+        Over in https://lists.webkit.org/pipermail/webkit-dev/2011-February/016034.html , a webkit-dev
+        thread, I've discussed my hopes for the link element, and adding the link header.  This
+        change helps improve the link header by making it participate in the beforeload event in
+        two more important cases.
+
+        Tests: fast/dom/HTMLLinkElement/prefetch-beforeload.html
+               http/tests/misc/link-rel-icon-beforeload.html
+               webarchive/test-link-rel-icon-beforeload.html
+
+        * html/HTMLLinkElement.cpp:
+        (WebCore::HTMLLinkElement::checkBeforeLoadEvent):
+        (WebCore::HTMLLinkElement::process):
+        * html/HTMLLinkElement.h:
+
 2011-03-29  Eric Seidel  <eric@webkit.org>
 
         Reviewed by Dimitri Glazkov.
index 08b98b1..bc608af 100644 (file)
@@ -195,6 +195,17 @@ void HTMLLinkElement::tokenizeRelAttribute(const AtomicString& rel, RelAttribute
     }
 }
 
+bool HTMLLinkElement::checkBeforeLoadEvent()
+{
+    RefPtr<Document> originalDocument = document();
+    if (!dispatchBeforeLoadEvent(m_url))
+        return false;
+    // A beforeload handler might have removed us from the document or changed the document.
+    if (!inDocument() || document() != originalDocument)
+        return false;
+    return true;
+}
+
 void HTMLLinkElement::process()
 {
     if (!inDocument() || m_isInShadowTree) {
@@ -206,8 +217,11 @@ void HTMLLinkElement::process()
 
     // IE extension: location of small icon for locationbar / bookmarks
     // We'll record this URL per document, even if we later only use it in top level frames
-    if (m_relAttribute.m_isIcon && m_url.isValid() && !m_url.isEmpty())
+    if (m_relAttribute.m_isIcon && m_url.isValid() && !m_url.isEmpty()) {
+        if (!checkBeforeLoadEvent()) 
+            return;
         document()->setIconURL(m_url.string(), type);
+    }
 
     if (m_relAttribute.m_isDNSPrefetch) {
         Settings* settings = document()->settings();
@@ -219,6 +233,8 @@ void HTMLLinkElement::process()
 
 #if ENABLE(LINK_PREFETCH)
     if (m_relAttribute.m_isLinkPrefetch && m_url.isValid() && document()->frame()) {
+        if (!checkBeforeLoadEvent())
+            return;
         m_cachedLinkPrefetch = document()->cachedResourceLoader()->requestLinkPrefetch(m_url);
         if (m_cachedLinkPrefetch)
             m_cachedLinkPrefetch->addClient(this);
@@ -240,11 +256,7 @@ void HTMLLinkElement::process()
             m_cachedSheet = 0;
         }
 
-        RefPtr<Document> originalDocument = document();
-        if (!dispatchBeforeLoadEvent(m_url))
-            return;
-        // A beforeload handler might have removed us from the document or changed the document.
-        if (!inDocument() || document() != originalDocument)
+        if (!checkBeforeLoadEvent())
             return;
 
         m_loading = true;
index 298d1c9..2782e71 100644 (file)
@@ -82,6 +82,7 @@ private:
 #if ENABLE(LINK_PREFETCH)
     void onloadTimerFired(Timer<HTMLLinkElement>*);
 #endif
+    bool checkBeforeLoadEvent();
     void process();
     static void processCallback(Node*);