Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add missing service worker content filter check
https://bugs.webkit.org/show_bug.cgi?id=255418
rdar://107453214

Reviewed by Brent Fulgham.

This patch was authored by Ben Nham and Per Arne Vollan.

Add missing service worker content filter check after finished adding data. This fixes an issue where
service workers are incorrectly blocked.

* LayoutTests/TestExpectations:
* LayoutTests/http/wpt/service-workers/basic-fetch-with-contentfilter-allow-after-adding-data-expected.txt: Added.
* LayoutTests/http/wpt/service-workers/basic-fetch-with-contentfilter-allow-after-adding-data.html: Added.
* LayoutTests/http/wpt/service-workers/basic-fetch-with-contentfilter.js:
(doTest):
* LayoutTests/platform/ios/TestExpectations:
* LayoutTests/platform/mac/TestExpectations:
* Source/WebKit/NetworkProcess/NetworkResourceLoader.cpp:
(WebKit::NetworkResourceLoader::serviceWorkerDidFinish):

Canonical link: https://commits.webkit.org/262972@main
  • Loading branch information
pvollan committed Apr 14, 2023
1 parent 4c8ed9e commit 09061ad
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 1 deletion.
1 change: 1 addition & 0 deletions LayoutTests/TestExpectations
Expand Up @@ -1010,6 +1010,7 @@ webkit.org/b/217617 imported/w3c/web-platform-tests/service-workers/service-work
# This test adds a lot of iframes and is slow to run.
fast/dom/connected-subframe-counter-overflow.html [ Slow ]

http/wpt/service-workers/basic-fetch-with-contentfilter-allow-after-adding-data.html [ Skip ]
http/wpt/service-workers/basic-fetch-with-contentfilter.https.html [ Skip ]

# Reenable it when having a custom gc exposed in service workers.
Expand Down
@@ -0,0 +1,5 @@


PASS Setup worker
PASS Fetch with content filter

@@ -0,0 +1,41 @@
<html>
<head>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/service-workers/service-worker/resources/test-helpers.sub.js"></script>
</head>
<body>
<script>
var scope = "resources";
var activeWorker;

if (window.internals) {
var settings = window.internals.mockContentFilterSettings;
settings.enabled = true;
settings.decisionPoint = "afterFinishedAddingData";
settings.decision = "allow";
settings.blockedString = "<!DOCTYPE html><body>PASS";
}

promise_test(async (test) => {
var registration = await navigator.serviceWorker.register("basic-fetch-with-contentfilter.js", { scope : scope });
activeWorker = registration.active;
if (activeWorker)
return;
activeWorker = registration.installing;
return new Promise(resolve => {
activeWorker.addEventListener('statechange', () => {
if (activeWorker.state === "activated")
resolve();
});
});
}, "Setup worker");

promise_test(async (test) => {
const iframe = await with_iframe(scope);

assert_equals(iframe.contentWindow.document.body.innerHTML, "Test");
}, "Fetch with content filter");
</script>
</body>
</html>
@@ -1,6 +1,6 @@
function doTest(event)
{
event.respondWith(new Response('Test', { status: 200, statusText: "Hello from service worker", headers: [["Hello", "World"]] }));
event.respondWith(new Response('<html><body>Test</body></html>', { status: 200, statusText: "Hello from service worker", headers: [["Content-Type", "text/html; charset=utf-8"]] }));
}

self.addEventListener("fetch", doTest);
1 change: 1 addition & 0 deletions LayoutTests/platform/ios/TestExpectations
Expand Up @@ -4372,6 +4372,7 @@ webkit.org/b/251875 fast/dynamic/create-renderer-for-whitespace-only-text.html [

webkit.org/b/252504 http/tests/site-isolation [ Skip ]

http/wpt/service-workers/basic-fetch-with-contentfilter-allow-after-adding-data.html [ Pass ]
http/wpt/service-workers/basic-fetch-with-contentfilter.https.html [ Pass ]

http/tests/misc/heic-accept-header.html [ Pass ]
Expand Down
1 change: 1 addition & 0 deletions LayoutTests/platform/mac/TestExpectations
Expand Up @@ -2748,6 +2748,7 @@ webkit.org/b/251099 [ Ventura+ ] fast/images/avif-image-document.html [ Pass Cra
# AVIF overlay images are only supported on macOS and iOS post Ventura.
[ Ventura+ ] fast/images/image-overlay-mutiple-frames.html [ Pass ImageOnlyFailure ]

http/wpt/service-workers/basic-fetch-with-contentfilter-allow-after-adding-data.html [ Pass ]
http/wpt/service-workers/basic-fetch-with-contentfilter.https.html [ Pass ]

http/tests/misc/heic-accept-header.html [ Pass ]
Expand Down
1 change: 1 addition & 0 deletions Source/WebKit/NetworkProcess/NetworkResourceLoader.cpp
Expand Up @@ -2023,6 +2023,7 @@ void NetworkResourceLoader::serviceWorkerDidFinish()
{
if (!m_contentFilter)
return;
m_contentFilter->continueAfterNotifyFinished(m_parameters.request.url());
m_contentFilter->stopFilteringMainResource();
}

Expand Down

0 comments on commit 09061ad

Please sign in to comment.