Changeset 249626 in webkit


Ignore:
Timestamp:
Sep 7, 2019 10:26:51 PM (5 years ago)
Author:
Chris Dumez
Message:

Rewrite http/tests/workers/service/serviceworker-private-browsing.https.html as an API test
https://bugs.webkit.org/show_bug.cgi?id=201574

Reviewed by Alex Christensen.

Source/WebKit:

Update Service Workers so that they obey the "secureContextChecksEnabled" preference.
This was needed to allow my service worker to access self.caches in my API test.

  • WebProcess/Storage/WebSWContextManagerConnection.cpp:

(WebKit::WebSWContextManagerConnection::updatePreferencesStore):

Tools:

Rewrite http/tests/workers/service/serviceworker-private-browsing.https.html as an API test so that
we truly test private browsing. testRunner.setPrivateBrowsingEnabled_DEPRECATED() is a hack which
does not work well for WK2.

  • TestWebKitAPI/Tests/WebKitCocoa/ServiceWorkerBasic.mm:

LayoutTests:

Drop legacy test which was replaced by an API test.

  • http/tests/workers/service/serviceworker-private-browsing-worker.js: Removed.
  • http/tests/workers/service/serviceworker-private-browsing.https-expected.txt: Removed.
  • http/tests/workers/service/serviceworker-private-browsing.https.html: Removed.
Location:
trunk
Files:
3 deleted
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r249625 r249626  
     12019-09-07  Chris Dumez  <cdumez@apple.com>
     2
     3        Rewrite http/tests/workers/service/serviceworker-private-browsing.https.html as an API test
     4        https://bugs.webkit.org/show_bug.cgi?id=201574
     5
     6        Reviewed by Alex Christensen.
     7
     8        Drop legacy test which was replaced by an API test.
     9
     10        * http/tests/workers/service/serviceworker-private-browsing-worker.js: Removed.
     11        * http/tests/workers/service/serviceworker-private-browsing.https-expected.txt: Removed.
     12        * http/tests/workers/service/serviceworker-private-browsing.https.html: Removed.
     13
    1142019-09-07  Chris Dumez  <cdumez@apple.com>
    215
  • trunk/LayoutTests/platform/gtk/TestExpectations

    r249416 r249626  
    10451045webkit.org/b/175419 http/tests/workers/service/controller-change.html [ Skip ]
    10461046webkit.org/b/175419 http/tests/workers/service/no-page-cache-when-controlled.html [ Skip ]
    1047 webkit.org/b/175419 http/tests/workers/service/serviceworker-private-browsing.https.html [ Skip ]
    10481047webkit.org/b/175419 http/wpt/service-workers/persistent-importScripts.html [ Failure ]
    10491048webkit.org/b/175419 imported/w3c/web-platform-tests/service-workers/service-worker/activation.https.html [ Skip ]
  • trunk/Source/WebKit/ChangeLog

    r249624 r249626  
     12019-09-07  Chris Dumez  <cdumez@apple.com>
     2
     3        Rewrite http/tests/workers/service/serviceworker-private-browsing.https.html as an API test
     4        https://bugs.webkit.org/show_bug.cgi?id=201574
     5
     6        Reviewed by Alex Christensen.
     7
     8        Update Service Workers so that they obey the "secureContextChecksEnabled" preference.
     9        This was needed to allow my service worker to access self.caches in my API test.
     10
     11        * WebProcess/Storage/WebSWContextManagerConnection.cpp:
     12        (WebKit::WebSWContextManagerConnection::updatePreferencesStore):
     13
    1142019-09-07  Tim Horton  <timothy_horton@apple.com>
    215
  • trunk/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.cpp

    r249501 r249626  
    114114    RuntimeEnabledFeatures::sharedFeatures().setServerTimingEnabled(store.getBoolValueForKey(WebPreferencesKey::serverTimingEnabledKey()));
    115115    RuntimeEnabledFeatures::sharedFeatures().setIsSecureContextAttributeEnabled(store.getBoolValueForKey(WebPreferencesKey::isSecureContextAttributeEnabledKey()));
     116    RuntimeEnabledFeatures::sharedFeatures().setSecureContextChecksEnabled(store.getBoolValueForKey(WebPreferencesKey::secureContextChecksEnabledKey()));
    116117
    117118    m_storageBlockingPolicy = static_cast<SecurityOrigin::StorageBlockingPolicy>(store.getUInt32ValueForKey(WebPreferencesKey::storageBlockingPolicyKey()));
  • trunk/Tools/ChangeLog

    r249625 r249626  
     12019-09-07  Chris Dumez  <cdumez@apple.com>
     2
     3        Rewrite http/tests/workers/service/serviceworker-private-browsing.https.html as an API test
     4        https://bugs.webkit.org/show_bug.cgi?id=201574
     5
     6        Reviewed by Alex Christensen.
     7
     8        Rewrite http/tests/workers/service/serviceworker-private-browsing.https.html as an API test so that
     9        we truly test private browsing. testRunner.setPrivateBrowsingEnabled_DEPRECATED() is a hack which
     10        does not work well for WK2.
     11
     12        * TestWebKitAPI/Tests/WebKitCocoa/ServiceWorkerBasic.mm:
     13
    1142019-09-07  Chris Dumez  <cdumez@apple.com>
    215
  • trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ServiceWorkerBasic.mm

    r249622 r249626  
    13501350}
    13511351
     1352static const char* serviceWorkerCacheAccessEphemeralSessionMainBytes = R"SWRESOURCE(
     1353<script>
     1354try {
     1355    navigator.serviceWorker.addEventListener("message", (event) => {
     1356        webkit.messageHandlers.sw.postMessage(event.data);
     1357    });
     1358
     1359    navigator.serviceWorker.register("serviceworker-private-browsing-worker.js", { scope : "my private backyard" }).then((registration) => {
     1360        activeWorker = registration.installing;
     1361        activeWorker.addEventListener('statechange', () => {
     1362            if (activeWorker.state === "activated") {
     1363                activeWorker.postMessage("TESTCACHE");
     1364            }
     1365        });
     1366    });
     1367} catch (e) {
     1368    webkit.messageHandlers.sw.postMessage("" + e);
     1369}
     1370</script>
     1371)SWRESOURCE";
     1372
     1373static const char* serviceWorkerCacheAccessEphemeralSessionSWBytes = R"SWRESOURCE(
     1374self.addEventListener("message", (event) => {
     1375    try {
     1376        self.caches.keys().then((keys) => {
     1377            event.source.postMessage(keys.length === 0 ? "PASS" : "FAIL: caches is not empty, got: " + JSON.stringify(keys));
     1378        });
     1379    } catch (e) {
     1380         event.source.postMessage("" + e);
     1381    }
     1382});
     1383)SWRESOURCE";
     1384
     1385// Opens a cache in the default session and checks that an ephemeral service worker
     1386// does not have access to it.
     1387TEST(ServiceWorkers, ServiceWorkerCacheAccessEphemeralSession)
     1388{
     1389    [WKWebsiteDataStore _allowWebsiteDataRecordsForAllOrigins];
     1390
     1391    // Start with a clean slate data store
     1392    [[WKWebsiteDataStore defaultDataStore] removeDataOfTypes:[WKWebsiteDataStore allWebsiteDataTypes] modifiedSince:[NSDate distantPast] completionHandler:^() {
     1393        done = true;
     1394    }];
     1395    TestWebKitAPI::Util::run(&done);
     1396    done = false;
     1397   
     1398    auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
     1399    setConfigurationInjectedBundlePath(configuration.get());
     1400   
     1401    auto defaultPreferences = [configuration preferences];
     1402    [defaultPreferences _setSecureContextChecksEnabled:NO];
     1403   
     1404    auto handler = adoptNS([[SWSchemes alloc] init]);
     1405    handler->resources.set("sw://host/openCache.html", ResourceInfo { @"text/html", "foo" });
     1406    handler->resources.set("sw://host/main.html", ResourceInfo { @"text/html", serviceWorkerCacheAccessEphemeralSessionMainBytes });
     1407    handler->resources.set("sw://host/serviceworker-private-browsing-worker.js", ResourceInfo { @"application/javascript", serviceWorkerCacheAccessEphemeralSessionSWBytes });
     1408    [configuration setURLSchemeHandler:handler.get() forURLScheme:@"SW"];
     1409
     1410    auto defaultWebView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
     1411    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"sw://host/openCache.html"]];
     1412    [defaultWebView synchronouslyLoadRequest:request];
     1413   
     1414    bool openedCache = false;
     1415    [defaultWebView evaluateJavaScript:@"self.caches.open('test');" completionHandler: [&] (id innerText, NSError *error) {
     1416        openedCache = true;
     1417    }];
     1418    TestWebKitAPI::Util::run(&openedCache);
     1419
     1420    configuration.get().websiteDataStore = [WKWebsiteDataStore nonPersistentDataStore];
     1421
     1422    auto messageHandler = adoptNS([[SWMessageHandlerForCacheStorage alloc] init]);
     1423    [[configuration userContentController] addScriptMessageHandler:messageHandler.get() name:@"sw"];
     1424
     1425    auto ephemeralWebView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
     1426    request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"sw://host/main.html"]];
     1427
     1428    [ephemeralWebView loadRequest:request];
     1429    TestWebKitAPI::Util::run(&done);
     1430    done = false;
     1431}
     1432
    13521433static const char* regularPageGrabbingCacheStorageDirectory = R"SWRESOURCE(
    13531434<script>
     
    13791460    [WKWebsiteDataStore _allowWebsiteDataRecordsForAllOrigins];
    13801461
    1381     RetainPtr<WKWebViewConfiguration> configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
    1382 
    1383     configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
     1462    auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
    13841463    setConfigurationInjectedBundlePath(configuration.get());
    13851464
Note: See TracChangeset for help on using the changeset viewer.