Remove support for load/error on link=prefetch
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 3 Sep 2019 11:48:11 +0000 (11:48 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 3 Sep 2019 11:48:11 +0000 (11:48 +0000)
https://bugs.webkit.org/show_bug.cgi?id=201348

Patch by Rob Buis <rbuis@igalia.com> on 2019-09-03
Reviewed by Youenn Fablet.

Source/WebCore:

Remove support for firing load/error on link=prefetch
to address tracking concerns.

Tests: http/wpt/prefetch/load-events-dynamic.html
       http/wpt/prefetch/load-events.html

* html/HTMLLinkElement.cpp:
(WebCore::HTMLLinkElement::linkLoaded):
(WebCore::HTMLLinkElement::linkLoadingErrored):
* html/HTMLLinkElement.h:
* testing/Internals.cpp:
(WebCore::Internals::addPrefetchLoadEventListener):

LayoutTests:

Adjust beforeload tests to also test load/error events.

* http/tests/cache/link-prefetch-main-resource-iframe.html:
* http/tests/cache/link-prefetch-main-resource.html:
* http/wpt/prefetch/beforeload-dynamic-expected.txt: Removed.
* http/wpt/prefetch/beforeload-expected.txt: Removed.
* http/wpt/prefetch/load-events-dynamic-expected.txt: Added.
* http/wpt/prefetch/load-events-dynamic.html: Renamed from LayoutTests/http/wpt/prefetch/beforeload-dynamic.html.
* http/wpt/prefetch/load-events-expected.txt: Added.
* http/wpt/prefetch/load-events.html: Renamed from LayoutTests/http/wpt/prefetch/beforeload.html.
* http/wpt/prefetch/resources/navigate-skip-disk-cache.html:
* http/wpt/prefetch/resources/navigate.html:
* platform/mac-wk1/TestExpectations:
* platform/win/TestExpectations:

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

18 files changed:
LayoutTests/ChangeLog
LayoutTests/http/tests/cache/link-prefetch-main-resource-iframe.html
LayoutTests/http/tests/cache/link-prefetch-main-resource.html
LayoutTests/http/wpt/prefetch/beforeload-dynamic-expected.txt [deleted file]
LayoutTests/http/wpt/prefetch/beforeload-dynamic.html [deleted file]
LayoutTests/http/wpt/prefetch/beforeload-expected.txt [deleted file]
LayoutTests/http/wpt/prefetch/load-events-dynamic-expected.txt [new file with mode: 0644]
LayoutTests/http/wpt/prefetch/load-events-dynamic.html [new file with mode: 0644]
LayoutTests/http/wpt/prefetch/load-events-expected.txt [new file with mode: 0644]
LayoutTests/http/wpt/prefetch/load-events.html [moved from LayoutTests/http/wpt/prefetch/beforeload.html with 51% similarity]
LayoutTests/http/wpt/prefetch/resources/navigate-skip-disk-cache.html
LayoutTests/http/wpt/prefetch/resources/navigate.html
LayoutTests/platform/mac-wk1/TestExpectations
LayoutTests/platform/win/TestExpectations
Source/WebCore/ChangeLog
Source/WebCore/html/HTMLLinkElement.cpp
Source/WebCore/html/HTMLLinkElement.h
Source/WebCore/testing/Internals.cpp

index dd4226b..48a4555 100644 (file)
@@ -1,3 +1,25 @@
+2019-09-03  Rob Buis  <rbuis@igalia.com>
+
+        Remove support for load/error on link=prefetch
+        https://bugs.webkit.org/show_bug.cgi?id=201348
+
+        Reviewed by Youenn Fablet.
+
+        Adjust beforeload tests to also test load/error events.
+
+        * http/tests/cache/link-prefetch-main-resource-iframe.html:
+        * http/tests/cache/link-prefetch-main-resource.html:
+        * http/wpt/prefetch/beforeload-dynamic-expected.txt: Removed.
+        * http/wpt/prefetch/beforeload-expected.txt: Removed.
+        * http/wpt/prefetch/load-events-dynamic-expected.txt: Added.
+        * http/wpt/prefetch/load-events-dynamic.html: Renamed from LayoutTests/http/wpt/prefetch/beforeload-dynamic.html.
+        * http/wpt/prefetch/load-events-expected.txt: Added.
+        * http/wpt/prefetch/load-events.html: Renamed from LayoutTests/http/wpt/prefetch/beforeload.html.
+        * http/wpt/prefetch/resources/navigate-skip-disk-cache.html:
+        * http/wpt/prefetch/resources/navigate.html:
+        * platform/mac-wk1/TestExpectations:
+        * platform/win/TestExpectations:
+
 2019-09-02  Fujii Hironori  <Hironori.Fujii@sony.com>
 
         [SVG] fragment-only url 'url(#fragment)' should be resolved against the current document with regardless to HTML <base> element
index 44366f5..14a1f1b 100644 (file)
@@ -1,5 +1,5 @@
 <html>
-<body>
+<body onload="runTest()">
 <div id="result"></div>
 <script>
 
@@ -32,7 +32,14 @@ window.onmessage = function(message)
     document.getElementById('result').textContent = message.data;
 }
 
+function runTest() {
+    var link = document.createElement("link");
+    link.rel = "prefetch";
+    link.href = "http://localhost:8000/cache/resources/prefetched-main-resource-iframe.php";
+    if (internals)
+        internals.addPrefetchLoadEventListener(link, () => { loadAfterPrefetch(); });
+    document.body.appendChild(link);
+}
 </script>
-<link rel="prefetch" href="http://localhost:8000/cache/resources/prefetched-main-resource-iframe.php" onload="setTimeout(loadAfterPrefetch, 0);">
 </body>
 </html>
index 7420df5..db3a8bd 100644 (file)
@@ -9,8 +9,16 @@ function loadAfterPrefetch()
 {
      window.location.assign('http://localhost:8000/cache/resources/prefetched-main-resource.php');
 }
+
+function runTest() {
+    var link = document.createElement("link");
+    link.rel = "prefetch";
+    link.href = "http://localhost:8000/cache/resources/prefetched-main-resource.php";
+    if (internals)
+        internals.addPrefetchLoadEventListener(link, () => { loadAfterPrefetch(); });
+    document.body.appendChild(link);
+}
 </script>
-<body>
-<link rel="prefetch" href="http://localhost:8000/cache/resources/prefetched-main-resource.php" onload="loadAfterPrefetch();">
+<body onload="runTest()">
 </body>
 </html>
diff --git a/LayoutTests/http/wpt/prefetch/beforeload-dynamic-expected.txt b/LayoutTests/http/wpt/prefetch/beforeload-dynamic-expected.txt
deleted file mode 100644 (file)
index 9529be0..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-
-PASS Makes sure that dynamically added prefetch does not call beforeload. 
-
diff --git a/LayoutTests/http/wpt/prefetch/beforeload-dynamic.html b/LayoutTests/http/wpt/prefetch/beforeload-dynamic.html
deleted file mode 100644 (file)
index 07d2c1a..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-<!DOCTYPE html>
-<script src="/resources/testharness.js"></script>
-<script src="/resources/testharnessreport.js"></script>
-<body>
-<script>
-var t = async_test('Makes sure that dynamically added prefetch does not call beforeload.');
-t.step(function() {
-    onload = t.step_func(function() { setTimeout(t.done(), 100); });
-    var link = document.createElement("link");
-    link.rel = "prefetch";
-    link.onbeforeload = t.step_func(function() {
-        assert_unreached("Beforeload should not be called.")
-    })
-    document.body.appendChild(link);
-});
-</script>
-</body>
diff --git a/LayoutTests/http/wpt/prefetch/beforeload-expected.txt b/LayoutTests/http/wpt/prefetch/beforeload-expected.txt
deleted file mode 100644 (file)
index d93d929..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-
-PASS Makes sure that prefetch does not call beforeload. 
-
diff --git a/LayoutTests/http/wpt/prefetch/load-events-dynamic-expected.txt b/LayoutTests/http/wpt/prefetch/load-events-dynamic-expected.txt
new file mode 100644 (file)
index 0000000..713681b
--- /dev/null
@@ -0,0 +1,3 @@
+
+PASS Makes sure that dynamically added prefetch does not fire beforeload, error or load events. 
+
diff --git a/LayoutTests/http/wpt/prefetch/load-events-dynamic.html b/LayoutTests/http/wpt/prefetch/load-events-dynamic.html
new file mode 100644 (file)
index 0000000..4bd0b77
--- /dev/null
@@ -0,0 +1,32 @@
+<!DOCTYPE html>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<body>
+<script>
+var t = async_test('Makes sure that dynamically added prefetch does not fire beforeload, error or load events.');
+t.step(function() {
+    onload = t.step_func(function() { setTimeout(t.done(), 100); });
+    var link = document.createElement("link");
+    link.rel = "prefetch";
+    link.onbeforeload = t.step_func(function() {
+        assert_unreached("Beforeload should not be fired.")
+    })
+    link.onload = t.step_func(function() {
+        assert_unreached("Load should not be fired.")
+    })
+    link.onerror = t.step_func(function() {
+        assert_unreached("Error should not be fired.")
+    })
+    link.addEventListener("beforeload", function() {
+        assert_unreached("Beforeload should not be fired.")
+    });
+    link.addEventListener("load", function() {
+        assert_unreached("Load should not be fired.")
+    });
+    link.addEventListener("error", function() {
+        assert_unreached("Error should not be fired.")
+    });
+    document.body.appendChild(link);
+});
+</script>
+</body>
diff --git a/LayoutTests/http/wpt/prefetch/load-events-expected.txt b/LayoutTests/http/wpt/prefetch/load-events-expected.txt
new file mode 100644 (file)
index 0000000..bb0f3c7
--- /dev/null
@@ -0,0 +1,3 @@
+
+PASS Makes sure that prefetch does not fire beforeload, error or load events. 
+
@@ -3,7 +3,7 @@
 <script src="/resources/testharnessreport.js"></script>
 <body onload="setTimeout(t.done(), 100);">
 <script>
-    var t = async_test('Makes sure that prefetch does not call beforeload.');
+    var t = async_test('Makes sure that prefetch does not fire beforeload, error or load events.');
 </script>
-<link rel="prefetch" onbeforeload="assert_unreached('Beforeload should not be called.')">
+<link rel="prefetch" onbeforeload="assert_unreached('Beforeload should not be fired.')" onload="assert_unreached('Load should not be fired.')" onerror="assert_unreached('Error should not be fired.')">
 </body>
index e607630..46d36fa 100644 (file)
@@ -6,7 +6,7 @@
   var link = document.createElement("link");
   link.rel = "prefetch";
   link.href = get_host_info().HTTP_REMOTE_ORIGIN + "/WebKit/prefetch/resources/main-resource-skip-disk-cache.py";
-  document.body.appendChild(link);
   internals.addPrefetchLoadEventListener(link, () => { window.location = get_host_info().HTTP_REMOTE_ORIGIN + "/WebKit/prefetch/resources/main-resource-skip-disk-cache.py" });
+  document.body.appendChild(link);
 </script>
 </body>
index 44d8bd1..1cbbf3c 100644 (file)
@@ -6,9 +6,7 @@
   var link = document.createElement("link");
   link.rel = "prefetch";
   link.href = get_host_info().HTTP_REMOTE_ORIGIN + "/WebKit/prefetch/resources/prefetched-main-resource-redirect.py";
-  link.onload = function() {
-    window.location = get_host_info().HTTP_REMOTE_ORIGIN + "/WebKit/prefetch/resources/prefetched-main-resource-redirect.py";
-  };
+  internals.addPrefetchLoadEventListener(link, () => { window.location = get_host_info().HTTP_REMOTE_ORIGIN + "/WebKit/prefetch/resources/prefetched-main-resource-redirect.py" });
   document.body.appendChild(link);
 </script>
 </body>
index 18d068a..1c9fa94 100644 (file)
@@ -739,8 +739,8 @@ webkit.org/b/195623 http/tests/cache/link-prefetch-main-resource-iframe.html [ S
 webkit.org/b/197371 http/wpt/prefetch/link-prefetch-main-resource-redirect.html [ Skip ]
 webkit.org/b/199499 http/wpt/prefetch/link-prefetch-skip-disk-cache.html [ Skip ]
 
-webkit.org/b/199632 http/wpt/prefetch/beforeload.html [ Skip ]
-webkit.org/b/199632 http/wpt/prefetch/beforeload-dynamic.html [ Skip ]
+webkit.org/b/199632 http/wpt/prefetch/load-events.html [ Skip ]
+webkit.org/b/199632 http/wpt/prefetch/load-events-dynamic.html [ Skip ]
 
 webkit.org/b/198177 pointerevents/mouse/compatibility-mouse-events-prevention-mouse-pressed.html [ Skip ]
 
index d35047a..4e02fe0 100644 (file)
@@ -4423,8 +4423,8 @@ webkit.org/b/195623 http/tests/cache/link-prefetch-main-resource-iframe.html [ S
 webkit.org/b/197371 http/wpt/prefetch/link-prefetch-main-resource-redirect.html [ Skip ]
 webkit.org/b/199499 http/wpt/prefetch/link-prefetch-skip-disk-cache.html [ Skip ]
 
-webkit.org/b/199632 http/wpt/prefetch/beforeload.html [ Skip ]
-webkit.org/b/199632 http/wpt/prefetch/beforeload-dynamic.html [ Skip ]
+webkit.org/b/199632 http/wpt/prefetch/load-events.html [ Skip ]
+webkit.org/b/199632 http/wpt/prefetch/load-events-dynamic.html [ Skip ]
 
 webkit.org/b/198112 http/tests/security/showModalDialog-sync-cross-origin-page-load2.html [ Skip ]
 
index 0df7203..7b164a4 100644 (file)
@@ -1,3 +1,23 @@
+2019-09-03  Rob Buis  <rbuis@igalia.com>
+
+        Remove support for load/error on link=prefetch
+        https://bugs.webkit.org/show_bug.cgi?id=201348
+
+        Reviewed by Youenn Fablet.
+
+        Remove support for firing load/error on link=prefetch
+        to address tracking concerns.
+
+        Tests: http/wpt/prefetch/load-events-dynamic.html
+               http/wpt/prefetch/load-events.html
+
+        * html/HTMLLinkElement.cpp:
+        (WebCore::HTMLLinkElement::linkLoaded):
+        (WebCore::HTMLLinkElement::linkLoadingErrored):
+        * html/HTMLLinkElement.h:
+        * testing/Internals.cpp:
+        (WebCore::Internals::addPrefetchLoadEventListener):
+
 2019-09-02  Yusuke Suzuki  <ysuzuki@apple.com>
 
         [WebCore] Resource usage accounting should accept non KERN_SUCCESS
index f6a7bc8..6ffb6d6 100644 (file)
@@ -488,12 +488,14 @@ DOMTokenList& HTMLLinkElement::sizes()
 void HTMLLinkElement::linkLoaded()
 {
     m_loadedResource = true;
-    linkLoadEventSender().dispatchEventSoon(*this);
+    if (!m_relAttribute.isLinkPrefetch || m_allowPrefetchLoadAndErrorForTesting)
+        linkLoadEventSender().dispatchEventSoon(*this);
 }
 
 void HTMLLinkElement::linkLoadingErrored()
 {
-    linkErrorEventSender().dispatchEventSoon(*this);
+    if (!m_relAttribute.isLinkPrefetch || m_allowPrefetchLoadAndErrorForTesting)
+        linkErrorEventSender().dispatchEventSoon(*this);
 }
 
 bool HTMLLinkElement::sheetLoaded()
index f4bc72b..07352a3 100644 (file)
@@ -78,6 +78,8 @@ public:
     bool isApplicationManifest() const { return m_relAttribute.isApplicationManifest; }
 #endif
 
+    void allowPrefetchLoadAndErrorForTesting() { m_allowPrefetchLoadAndErrorForTesting = true; }
+
 private:
     void parseAttribute(const QualifiedName&, const AtomString&) final;
 
@@ -141,6 +143,7 @@ private:
     bool m_firedLoad;
     bool m_loadedResource;
     bool m_isHandlingBeforeLoad { false };
+    bool m_allowPrefetchLoadAndErrorForTesting { false };
 
     PendingSheetType m_pendingSheetType;
     String m_integrityMetadataForPendingSheetRequest;
index 02e07aa..b471de5 100644 (file)
@@ -5160,8 +5160,10 @@ Internals::TextIndicatorInfo Internals::textIndicatorForRange(const Range& range
 
 void Internals::addPrefetchLoadEventListener(HTMLLinkElement& link, RefPtr<EventListener>&& listener)
 {
-    if (RuntimeEnabledFeatures::sharedFeatures().linkPrefetchEnabled() && equalLettersIgnoringASCIICase(link.rel(), "prefetch"))
+    if (RuntimeEnabledFeatures::sharedFeatures().linkPrefetchEnabled() && equalLettersIgnoringASCIICase(link.rel(), "prefetch")) {
+        link.allowPrefetchLoadAndErrorForTesting();
         link.addEventListener(eventNames().loadEvent, listener.releaseNonNull(), false);
+    }
 }
 
 } // namespace WebCore