Changeset 229150 in webkit


Ignore:
Timestamp:
Mar 1, 2018 3:18:28 PM (6 years ago)
Author:
commit-queue@webkit.org
Message:

Add API test to validate setting of service worker and cache storage directories
https://bugs.webkit.org/show_bug.cgi?id=182543

Patch by Youenn Fablet <youenn@apple.com> on 2018-03-01
Reviewed by Chris Dumez.

Source/WebCore:

Covered by API tests.

Add getters to service worker registration directory.

  • testing/Internals.cpp:

(WebCore::Internals::serviceWorkerRegistrationDirectory):

  • testing/Internals.h:
  • testing/Internals.idl:
  • workers/service/SWClientConnection.h:
  • workers/service/server/RegistrationDatabase.h:

(WebCore::RegistrationDatabase::serviceWorkerRegistrationDirectory const):

  • workers/service/server/RegistrationStore.h:

(WebCore::RegistrationStore::serviceWorkerRegistrationDirectory const):

  • workers/service/server/SWServer.h:

(WebCore::SWServer::serviceWorkerRegistrationDirectory const):

Source/WebKit:

Add cache engine directory path to its representation dump.
This is used in API tests to check that the path is correctly set.

Add a way for to know whether a service worker was registered from a WKWebsiteDataStore.
This is used in API tests to check that the path is correctly set.

  • NetworkProcess/cache/CacheStorageEngine.cpp:

(WebKit::CacheStorage::Engine::representation):

  • UIProcess/API/Cocoa/WKWebsiteDataStore.mm:

(-[WKWebsiteDataStore _hasRegisteredServiceWorker]):

  • UIProcess/API/Cocoa/WKWebsiteDataStorePrivate.h:

Tools:

  • TestWebKitAPI/Tests/WebKitCocoa/ServiceWorkerBasic.mm:

LayoutTests:

Updated tests according new engine representation.

  • http/tests/cache-storage/cache-clearing-origin.https.html:
  • http/tests/cache-storage/cache-origins.https.html:
  • http/tests/cache-storage/cache-representation.https.html:
Location:
trunk
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r229147 r229150  
     12018-03-01  Youenn Fablet  <youenn@apple.com>
     2
     3        Add API test to validate setting of service worker and cache storage directories
     4        https://bugs.webkit.org/show_bug.cgi?id=182543
     5
     6        Reviewed by Chris Dumez.
     7
     8        Updated tests according new engine representation.
     9
     10        * http/tests/cache-storage/cache-clearing-origin.https.html:
     11        * http/tests/cache-storage/cache-origins.https.html:
     12        * http/tests/cache-storage/cache-representation.https.html:
     13
    1142018-03-01  Daniel Bates  <dabates@apple.com>
    215
  • trunk/LayoutTests/http/tests/cache-storage/cache-clearing-origin.https.html

    r226481 r229150  
    2424        var counter = 0;
    2525        window.addEventListener("message", async (event) => {
    26             var representation = JSON.parse(await internals.cacheStorageEngineRepresentation());
     26            var representation = JSON.parse(await internals.cacheStorageEngineRepresentation()).origins;
    2727            test(() => {
    2828                representation.sort(compareClientOrigins);
     
    3535            testRunner.clearDOMCache('https://localhost:8443');
    3636
    37             representation = JSON.parse(await internals.cacheStorageEngineRepresentation());
     37            representation = JSON.parse(await internals.cacheStorageEngineRepresentation()).origins;
    3838            test(() => {
    3939                representation.sort(compareClientOrigins);
  • trunk/LayoutTests/http/tests/cache-storage/cache-origins.https.html

    r226481 r229150  
    2020    async function checkCachesAfterClearingOrigins() {
    2121        testRunner.clearDOMCache('https://127.0.0.1:8443');
    22         var representation = JSON.parse(await internals.cacheStorageEngineRepresentation());
     22        var representation = JSON.parse(await internals.cacheStorageEngineRepresentation()).origins;
    2323        test(() => {
    2424            assert_equals(representation[0].origin.topOrigin, "https://127.0.0.1:8443", "top origin of cache 1");
     
    3232
    3333    async function checkCacheRepresentation() {
    34         var representation = JSON.parse(await internals.cacheStorageEngineRepresentation());
     34        var representation = JSON.parse(await internals.cacheStorageEngineRepresentation()).origins;
    3535        test(() => {
    3636            assert_equals(representation[0].origin.topOrigin, "https://127.0.0.1:8443", "top origin of cache 1");
  • trunk/LayoutTests/http/tests/cache-storage/cache-representation.https.html

    r226481 r229150  
    1515    function checkCaches(hasPersistent, hasRemoved, name, value) {
    1616        test(() => {
    17             var results = JSON.parse(value);
     17            var results = JSON.parse(value).origins;
    1818            assert_equals(results.length, 1);
    1919            var caches = results[0].caches;
  • trunk/Source/WebCore/ChangeLog

    r229149 r229150  
     12018-03-01  Youenn Fablet  <youenn@apple.com>
     2
     3        Add API test to validate setting of service worker and cache storage directories
     4        https://bugs.webkit.org/show_bug.cgi?id=182543
     5
     6        Reviewed by Chris Dumez.
     7
     8        Covered by API tests.
     9
     10        Add getters to service worker registration directory.
     11
     12        * testing/Internals.cpp:
     13        (WebCore::Internals::serviceWorkerRegistrationDirectory):
     14        * testing/Internals.h:
     15        * testing/Internals.idl:
     16        * workers/service/SWClientConnection.h:
     17        * workers/service/server/RegistrationDatabase.h:
     18        (WebCore::RegistrationDatabase::serviceWorkerRegistrationDirectory const):
     19        * workers/service/server/RegistrationStore.h:
     20        (WebCore::RegistrationStore::serviceWorkerRegistrationDirectory const):
     21        * workers/service/server/SWServer.h:
     22        (WebCore::SWServer::serviceWorkerRegistrationDirectory const):
     23
    1242018-03-01  Youenn Fablet  <youenn@apple.com>
    225
  • trunk/Source/WebKit/ChangeLog

    r229148 r229150  
     12018-03-01  Youenn Fablet  <youenn@apple.com>
     2
     3        Add API test to validate setting of service worker and cache storage directories
     4        https://bugs.webkit.org/show_bug.cgi?id=182543
     5
     6        Reviewed by Chris Dumez.
     7
     8        Add cache engine directory path to its representation dump.
     9        This is used in API tests to check that the path is correctly set.
     10
     11        Add a way for to know whether a service worker was registered from a WKWebsiteDataStore.
     12        This is used in API tests to check that the path is correctly set.
     13
     14        * NetworkProcess/cache/CacheStorageEngine.cpp:
     15        (WebKit::CacheStorage::Engine::representation):
     16        * UIProcess/API/Cocoa/WKWebsiteDataStore.mm:
     17        (-[WKWebsiteDataStore _hasRegisteredServiceWorker]):
     18        * UIProcess/API/Cocoa/WKWebsiteDataStorePrivate.h:
     19
    1202018-03-01  Wenson Hsieh  <wenson_hsieh@apple.com>
    221
  • trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngine.cpp

    r228925 r229150  
    476476    bool isFirst = true;
    477477    StringBuilder builder;
    478     builder.append("[");
     478    builder.append("{ \"path\": \"");
     479    builder.append(m_rootPath);
     480    builder.append("\", \"origins\": [");
    479481    for (auto& keyValue : m_caches) {
    480482        if (!isFirst)
     
    490492        builder.append("}");
    491493    }
    492     builder.append("\n]");
     494    builder.append("]}");
    493495    return builder.toString();
    494496}
  • trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebsiteDataStore.mm

    r228442 r229150  
    3838#import "_WKWebsiteDataStoreConfiguration.h"
    3939#import <WebCore/URL.h>
     40#import <WebKit/ServiceWorkerProcessProxy.h>
    4041#import <wtf/BlockPtr.h>
    4142
     
    342343}
    343344
     345- (bool)_hasRegisteredServiceWorker
     346{
     347    return WebKit::ServiceWorkerProcessProxy::hasRegisteredServiceWorkers(_websiteDataStore->websiteDataStore().serviceWorkerRegistrationDirectory());
     348}
     349
    344350@end
    345351
  • trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebsiteDataStorePrivate.h

    r228304 r229150  
    5858- (void)_getAllStorageAccessEntries:(void (^)(NSArray<NSString *> *domains))completionHandler WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
    5959+ (void)_allowWebsiteDataRecordsForAllOrigins WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
     60- (bool)_hasRegisteredServiceWorker WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
     61
    6062@end
    6163
  • trunk/Tools/ChangeLog

    r229143 r229150  
     12018-03-01  Youenn Fablet  <youenn@apple.com>
     2
     3        Add API test to validate setting of service worker and cache storage directories
     4        https://bugs.webkit.org/show_bug.cgi?id=182543
     5
     6        Reviewed by Chris Dumez.
     7
     8        * TestWebKitAPI/Tests/WebKitCocoa/ServiceWorkerBasic.mm:
     9
    1102018-03-01  Ross Kirsling  <ross.kirsling@sony.com>
    211
  • trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ServiceWorkerBasic.mm

    r228978 r229150  
    5555
    5656static String expectedMessage;
     57static String retrievedString;
    5758
    5859@interface SWMessageHandler : NSObject <WKScriptMessageHandler>
     
    979980    done = false;
    980981}
     982
     983static const char* regularPageGrabbingCacheStorageDirectory = R"SWRESOURCE(
     984<script>
     985async function getResult()
     986{
     987    var result = await window.internals.cacheStorageEngineRepresentation();
     988    window.webkit.messageHandlers.sw.postMessage(result);
     989}
     990getResult();
     991</script>
     992)SWRESOURCE";
     993
     994@interface DirectoryPageMessageHandler : NSObject <WKScriptMessageHandler>
     995@end
     996
     997@implementation DirectoryPageMessageHandler
     998- (void)userContentController:(WKUserContentController *)userContentController didReceiveScriptMessage:(WKScriptMessage *)message
     999{
     1000    retrievedString = [message body];
     1001    done = true;
     1002}
     1003@end
     1004
     1005TEST(ServiceWorkers, ServiceWorkerAndCacheStorageDefaultDirectories)
     1006{
     1007    ASSERT(mainBytes);
     1008    ASSERT(scriptBytes);
     1009
     1010    [WKWebsiteDataStore _allowWebsiteDataRecordsForAllOrigins];
     1011
     1012    RetainPtr<WKWebViewConfiguration> configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
     1013
     1014    configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
     1015    setConfigurationInjectedBundlePath(configuration.get());
     1016
     1017    RetainPtr<DirectoryPageMessageHandler> directoryPageMessageHandler = adoptNS([[DirectoryPageMessageHandler alloc] init]);
     1018    [[configuration userContentController] addScriptMessageHandler:directoryPageMessageHandler.get() name:@"sw"];
     1019
     1020    RetainPtr<SWSchemes> handler = adoptNS([[SWSchemes alloc] init]);
     1021    handler->resources.set("sw://host/main.html", ResourceInfo { @"text/html", mainBytes });
     1022    handler->resources.set("sw://host/regularPageGrabbingCacheStorageDirectory.html", ResourceInfo { @"text/html", regularPageGrabbingCacheStorageDirectory });
     1023    handler->resources.set("sw://host/sw.js", ResourceInfo { @"application/javascript", scriptBytes });
     1024    [configuration setURLSchemeHandler:handler.get() forURLScheme:@"SW"];
     1025
     1026    RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
     1027    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"sw://host/main.html"]];
     1028
     1029    [webView loadRequest:request];
     1030    TestWebKitAPI::Util::run(&done);
     1031    done = false;
     1032    EXPECT_TRUE([[configuration websiteDataStore] _hasRegisteredServiceWorker]);
     1033
     1034    webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
     1035    [webView.get().configuration.processPool _registerURLSchemeServiceWorkersCanHandle:@"sw"];
     1036
     1037    request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"sw://host/regularPageGrabbingCacheStorageDirectory.html"]];
     1038    [webView loadRequest:request];
     1039    TestWebKitAPI::Util::run(&done);
     1040    done = false;
     1041    EXPECT_TRUE(retrievedString.contains("/Caches/TestWebKitAPI/WebKit/CacheStorage"));
     1042
     1043    [[configuration websiteDataStore] removeDataOfTypes:[WKWebsiteDataStore allWebsiteDataTypes] modifiedSince:[NSDate distantPast] completionHandler:^() {
     1044        done = true;
     1045    }];
     1046    TestWebKitAPI::Util::run(&done);
     1047    done = false;
     1048}
     1049
     1050TEST(ServiceWorkers, ServiceWorkerAndCacheStorageSpecificDirectories)
     1051{
     1052    ASSERT(mainBytes);
     1053    ASSERT(scriptBytes);
     1054
     1055    [WKWebsiteDataStore _allowWebsiteDataRecordsForAllOrigins];
     1056
     1057    RetainPtr<WKWebViewConfiguration> configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
     1058
     1059    configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
     1060    setConfigurationInjectedBundlePath(configuration.get());
     1061    auto websiteDataStore = [configuration websiteDataStore];
     1062    [websiteDataStore _setCacheStorageDirectory:@"/var/tmp"];
     1063    [websiteDataStore _setServiceWorkerRegistrationDirectory:@"/var/tmp"];
     1064
     1065    RetainPtr<DirectoryPageMessageHandler> directoryPageMessageHandler = adoptNS([[DirectoryPageMessageHandler alloc] init]);
     1066    [[configuration userContentController] addScriptMessageHandler:directoryPageMessageHandler.get() name:@"sw"];
     1067
     1068    RetainPtr<SWSchemes> handler = adoptNS([[SWSchemes alloc] init]);
     1069    handler->resources.set("sw://host/main.html", ResourceInfo { @"text/html", mainBytes });
     1070    handler->resources.set("sw://host/regularPageGrabbingCacheStorageDirectory.html", ResourceInfo { @"text/html", regularPageGrabbingCacheStorageDirectory });
     1071    handler->resources.set("sw://host/sw.js", ResourceInfo { @"application/javascript", scriptBytes });
     1072    [configuration setURLSchemeHandler:handler.get() forURLScheme:@"SW"];
     1073
     1074    RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
     1075    [webView.get().configuration.processPool _registerURLSchemeServiceWorkersCanHandle:@"sw"];
     1076
     1077    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"sw://host/main.html"]];
     1078    [webView loadRequest:request];
     1079    TestWebKitAPI::Util::run(&done);
     1080    done = false;
     1081    EXPECT_TRUE([websiteDataStore _hasRegisteredServiceWorker]);
     1082
     1083    webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
     1084    request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"sw://host/regularPageGrabbingCacheStorageDirectory.html"]];
     1085
     1086    [webView loadRequest:request];
     1087    TestWebKitAPI::Util::run(&done);
     1088    done = false;
     1089    EXPECT_TRUE(retrievedString.contains("\"path\": \"/var/tmp\""));
     1090
     1091    [[configuration websiteDataStore] removeDataOfTypes:[WKWebsiteDataStore allWebsiteDataTypes] modifiedSince:[NSDate distantPast] completionHandler:^() {
     1092        done = true;
     1093    }];
     1094    TestWebKitAPI::Util::run(&done);
     1095    done = false;
     1096}
     1097
    9811098#endif // WK_HAVE_C_SPI
    9821099
Note: See TracChangeset for help on using the changeset viewer.