Changeset 232891 in webkit


Ignore:
Timestamp:
Jun 15, 2018 1:11:41 PM (6 years ago)
Author:
Chris Dumez
Message:

Add API test coverage for SW RegistrationDatabase destruction and fix issues found by the test
https://bugs.webkit.org/show_bug.cgi?id=186681

Reviewed by Brady Eidson.

Source/WebCore:

  • workers/service/server/RegistrationDatabase.cpp:

(WebCore::RegistrationDatabase::RegistrationDatabase):
(WebCore::RegistrationDatabase::importRecords):

  • workers/service/server/RegistrationDatabase.h:

Rename m_session to m_sessionID for clarity.

  • workers/service/server/RegistrationStore.cpp:

(WebCore::RegistrationStore::~RegistrationStore):
Drop bad assertion now that the RegistrationDatabase is refcounted
and can outlive the RegistrationStore. The RegistrationDatabase will
take care of closing / destroying the SQLiteDatabase on the background
thread when destroyed.

Source/WebKit:

Make sure StorageProcess::unregisterSWServerConnection() does not unnecessarily
create a SWServer. Otherwise, we were in quick session destroying the SWServer
and then re-constructing it for the same sessionID, merely to try ot unregister
a SWServerConnection.

  • StorageProcess/StorageProcess.cpp:

(WebKit::StorageProcess::existingSWOriginStoreForSession const):
(WebKit::StorageProcess::unregisterSWServerConnection):

  • StorageProcess/StorageProcess.h:

Tools:

Add API test coverage.

  • TestWebKitAPI/Tests/WebKitCocoa/ServiceWorkerBasic.mm:
Location:
trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r232880 r232891  
     12018-06-15  Chris Dumez  <cdumez@apple.com>
     2
     3        Add API test coverage for SW RegistrationDatabase destruction and fix issues found by the test
     4        https://bugs.webkit.org/show_bug.cgi?id=186681
     5
     6        Reviewed by Brady Eidson.
     7
     8        * workers/service/server/RegistrationDatabase.cpp:
     9        (WebCore::RegistrationDatabase::RegistrationDatabase):
     10        (WebCore::RegistrationDatabase::importRecords):
     11        * workers/service/server/RegistrationDatabase.h:
     12        Rename m_session to m_sessionID for clarity.
     13
     14        * workers/service/server/RegistrationStore.cpp:
     15        (WebCore::RegistrationStore::~RegistrationStore):
     16        Drop bad assertion now that the RegistrationDatabase is refcounted
     17        and can outlive the RegistrationStore. The RegistrationDatabase will
     18        take care of closing / destroying the SQLiteDatabase on the background
     19        thread when destroyed.
     20
    1212018-06-15  Timothy Hatcher  <timothy@apple.com>
    222
  • trunk/Source/WebCore/workers/service/server/RegistrationDatabase.cpp

    r232874 r232891  
    9696    : m_workQueue(WorkQueue::create("ServiceWorker I/O Thread", WorkQueue::Type::Serial))
    9797    , m_store(makeWeakPtr(store))
    98     , m_session(m_store->server().sessionID())
     98    , m_sessionID(m_store->server().sessionID())
    9999    , m_databaseDirectory(WTFMove(databaseDirectory))
    100100    , m_databaseFilePath(FileSystem::pathByAppendingComponent(m_databaseDirectory, databaseFilename()))
     
    405405        auto serviceWorkerData = ServiceWorkerData { workerIdentifier, scriptURL, ServiceWorkerState::Activated, *workerType, registrationIdentifier };
    406406        auto registration = ServiceWorkerRegistrationData { WTFMove(*key), registrationIdentifier, URL(originURL, scopePath), *updateViaCache, lastUpdateCheckTime, std::nullopt, std::nullopt, WTFMove(serviceWorkerData) };
    407         auto contextData = ServiceWorkerContextData { std::nullopt, WTFMove(registration), workerIdentifier, WTFMove(script), WTFMove(contentSecurityPolicy), WTFMove(scriptURL), *workerType, m_session, true, WTFMove(scriptResourceMap) };
     407        auto contextData = ServiceWorkerContextData { std::nullopt, WTFMove(registration), workerIdentifier, WTFMove(script), WTFMove(contentSecurityPolicy), WTFMove(scriptURL), *workerType, m_sessionID, true, WTFMove(scriptResourceMap) };
    408408
    409409        callOnMainThread([protectedThis = makeRef(*this), contextData = contextData.isolatedCopy()]() mutable {
  • trunk/Source/WebCore/workers/service/server/RegistrationDatabase.h

    r232874 r232891  
    7878    Ref<WorkQueue> m_workQueue;
    7979    WeakPtr<RegistrationStore> m_store;
    80     PAL::SessionID m_session;
     80    PAL::SessionID m_sessionID;
    8181    String m_databaseDirectory;
    8282    String m_databaseFilePath;
  • trunk/Source/WebCore/workers/service/server/RegistrationStore.cpp

    r232874 r232891  
    4242RegistrationStore::~RegistrationStore()
    4343{
    44     ASSERT(m_database->isClosed());
    4544}
    4645
  • trunk/Source/WebKit/ChangeLog

    r232888 r232891  
     12018-06-15  Chris Dumez  <cdumez@apple.com>
     2
     3        Add API test coverage for SW RegistrationDatabase destruction and fix issues found by the test
     4        https://bugs.webkit.org/show_bug.cgi?id=186681
     5
     6        Reviewed by Brady Eidson.
     7
     8        Make sure StorageProcess::unregisterSWServerConnection() does not unnecessarily
     9        create a SWServer. Otherwise, we were in quick session destroying the SWServer
     10        and then re-constructing it for the same sessionID, merely to try ot unregister
     11        a SWServerConnection.
     12
     13        * StorageProcess/StorageProcess.cpp:
     14        (WebKit::StorageProcess::existingSWOriginStoreForSession const):
     15        (WebKit::StorageProcess::unregisterSWServerConnection):
     16        * StorageProcess/StorageProcess.h:
     17
    1182018-06-15  Basuke Suzuki  <Basuke.Suzuki@sony.com>
    219
  • trunk/Source/WebKit/StorageProcess/StorageProcess.cpp

    r232484 r232891  
    457457}
    458458
     459WebSWOriginStore* StorageProcess::existingSWOriginStoreForSession(PAL::SessionID sessionID) const
     460{
     461    auto* swServer = m_swServers.get(sessionID);
     462    if (!swServer)
     463        return nullptr;
     464    return &static_cast<WebSWOriginStore&>(swServer->originStore());
     465}
     466
    459467WebSWServerToContextConnection* StorageProcess::serverToContextConnectionForOrigin(const SecurityOriginData& securityOrigin)
    460468{
     
    534542    ASSERT(m_swServerConnections.get(connection.identifier()) == &connection);
    535543    m_swServerConnections.remove(connection.identifier());
    536     swOriginStoreForSession(connection.sessionID()).unregisterSWServerConnection(connection);
     544    if (auto* store = existingSWOriginStoreForSession(connection.sessionID()))
     545        store->unregisterSWServerConnection(connection);
    537546}
    538547
  • trunk/Source/WebKit/StorageProcess/StorageProcess.h

    r232484 r232891  
    152152
    153153    WebSWOriginStore& swOriginStoreForSession(PAL::SessionID);
     154    WebSWOriginStore* existingSWOriginStoreForSession(PAL::SessionID) const;
    154155    bool needsServerToContextConnectionForOrigin(const WebCore::SecurityOriginData&) const;
    155156#endif
  • trunk/Tools/ChangeLog

    r232886 r232891  
     12018-06-15  Chris Dumez  <cdumez@apple.com>
     2
     3        Add API test coverage for SW RegistrationDatabase destruction and fix issues found by the test
     4        https://bugs.webkit.org/show_bug.cgi?id=186681
     5
     6        Reviewed by Brady Eidson.
     7
     8       Add API test coverage.
     9
     10        * TestWebKitAPI/Tests/WebKitCocoa/ServiceWorkerBasic.mm:
     11
    1122018-06-15  Brady Eidson  <beidson@apple.com>
    213
  • trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ServiceWorkerBasic.mm

    r232580 r232891  
    14191419}
    14201420
     1421TEST(ServiceWorkers, RestoreFromDiskNonDefaultStore)
     1422{
     1423    ASSERT(mainRegisteringWorkerBytes);
     1424    ASSERT(scriptBytes);
     1425    ASSERT(mainRegisteringAlreadyExistingWorkerBytes);
     1426
     1427    [WKWebsiteDataStore _allowWebsiteDataRecordsForAllOrigins];
     1428
     1429    NSURL *swDBPath = [NSURL fileURLWithPath:[@"~/Library/WebKit/TestWebKitAPI/CustomWebsiteData/ServiceWorkers/" stringByExpandingTildeInPath]];
     1430    [[NSFileManager defaultManager] removeItemAtURL:swDBPath error:nil];
     1431    EXPECT_FALSE([[NSFileManager defaultManager] fileExistsAtPath:swDBPath.path]);
     1432    [[NSFileManager defaultManager] createDirectoryAtURL:swDBPath withIntermediateDirectories:YES attributes:nil error:nil];
     1433    EXPECT_TRUE([[NSFileManager defaultManager] fileExistsAtPath:swDBPath.path]);
     1434
     1435    // We protect the process pool so that it outlives the WebsiteDataStore.
     1436    RetainPtr<WKProcessPool> protectedProcessPool;
     1437
     1438    @autoreleasepool {
     1439        auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
     1440
     1441        auto websiteDataStoreConfiguration = adoptNS([[_WKWebsiteDataStoreConfiguration alloc] init]);
     1442        websiteDataStoreConfiguration.get()._serviceWorkerRegistrationDirectory = swDBPath;
     1443        auto nonDefaultDataStore = adoptNS([[WKWebsiteDataStore alloc] _initWithConfiguration:websiteDataStoreConfiguration.get()]);
     1444        configuration.get().websiteDataStore = nonDefaultDataStore.get();
     1445
     1446        auto messageHandler = adoptNS([[SWMessageHandlerForRestoreFromDiskTest alloc] initWithExpectedMessage:@"PASS: Registration was successful and service worker was activated"]);
     1447        [[configuration userContentController] addScriptMessageHandler:messageHandler.get() name:@"sw"];
     1448
     1449        auto handler = adoptNS([[SWSchemes alloc] init]);
     1450        handler->resources.set("sw://host/main.html", ResourceInfo { @"text/html", mainRegisteringWorkerBytes });
     1451        handler->resources.set("sw://host/sw.js", ResourceInfo { @"application/javascript", scriptBytes });
     1452        [configuration setURLSchemeHandler:handler.get() forURLScheme:@"SW"];
     1453
     1454        auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
     1455        [webView.get().configuration.processPool _registerURLSchemeServiceWorkersCanHandle:@"sw"];
     1456        protectedProcessPool = webView.get().configuration.processPool;
     1457
     1458        [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"sw://host/main.html"]]];
     1459
     1460        TestWebKitAPI::Util::run(&done);
     1461        done = false;
     1462
     1463        [webView.get().configuration.processPool _terminateServiceWorkerProcesses];
     1464    }
     1465
     1466    @autoreleasepool {
     1467        auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
     1468
     1469        auto websiteDataStoreConfiguration = adoptNS([[_WKWebsiteDataStoreConfiguration alloc] init]);
     1470        websiteDataStoreConfiguration.get()._serviceWorkerRegistrationDirectory = swDBPath;
     1471        auto nonDefaultDataStore = adoptNS([[WKWebsiteDataStore alloc] _initWithConfiguration:websiteDataStoreConfiguration.get()]);
     1472        configuration.get().websiteDataStore = nonDefaultDataStore.get();
     1473
     1474        auto messageHandler = adoptNS([[SWMessageHandlerForRestoreFromDiskTest alloc] initWithExpectedMessage:@"PASS: Registration already has an active worker"]);
     1475        [[configuration userContentController] addScriptMessageHandler:messageHandler.get() name:@"sw"];
     1476
     1477        auto handler = adoptNS([[SWSchemes alloc] init]);
     1478        handler->resources.set("sw://host/main.html", ResourceInfo { @"text/html", mainRegisteringAlreadyExistingWorkerBytes });
     1479        handler->resources.set("sw://host/sw.js", ResourceInfo { @"application/javascript", scriptBytes });
     1480        [configuration setURLSchemeHandler:handler.get() forURLScheme:@"SW"];
     1481
     1482        auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
     1483        [webView.get().configuration.processPool _registerURLSchemeServiceWorkersCanHandle:@"sw"];
     1484
     1485        [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"sw://host/main.html"]]];
     1486
     1487        TestWebKitAPI::Util::run(&done);
     1488        done = false;
     1489    }
     1490}
     1491
    14211492#endif // WK_API_ENABLED
Note: See TracChangeset for help on using the changeset viewer.