Changeset 251384 in webkit
- Timestamp:
- Oct 21, 2019, 2:28:58 PM (5 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 18 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r251379 r251384 1 2019-10-21 Alex Christensen <achristensen@webkit.org> 2 3 ServiceWorker tests should use TCPServer instead of WKURLSchemeHandler 4 https://bugs.webkit.org/show_bug.cgi?id=203141 5 6 Reviewed by Youenn Fablet. 7 8 This makes the tests more like what users will see, 9 and it allows us to not consult custom schemes when loading service workers, 10 which is preventing us from moving logic to the NetworkProcess. See bug 203055. 11 Also, I now remove test-only code that's not used anymore. 12 13 * workers/service/server/SWServer.cpp: 14 (WebCore::SWServer::SWServer): 15 (WebCore::SWServer::canHandleScheme const): 16 * workers/service/server/SWServer.h: 17 1 18 2019-10-21 Joseph Pecoraro <pecoraro@apple.com> 2 19 -
trunk/Source/WebCore/workers/service/server/SWServer.cpp
r251124 r251384 300 300 } 301 301 302 SWServer::SWServer(UniqueRef<SWOriginStore>&& originStore, HashSet<String>&& registeredSchemes,bool processTerminationDelayEnabled, String&& registrationDatabaseDirectory, PAL::SessionID sessionID, CreateContextConnectionCallback&& callback)302 SWServer::SWServer(UniqueRef<SWOriginStore>&& originStore, bool processTerminationDelayEnabled, String&& registrationDatabaseDirectory, PAL::SessionID sessionID, CreateContextConnectionCallback&& callback) 303 303 : m_originStore(WTFMove(originStore)) 304 304 , m_sessionID(sessionID) 305 305 , m_isProcessTerminationDelayEnabled(processTerminationDelayEnabled) 306 , m_registeredSchemes(WTFMove(registeredSchemes))307 306 , m_createContextConnectionCallback(WTFMove(callback)) 308 307 { … … 979 978 if (scheme.isNull()) 980 979 return false; 981 982 if (equalLettersIgnoringASCIICase(scheme.substring(0, 4), "http")) { 983 if (scheme.length() == 4) 984 return true; 985 if (scheme.length() == 5 && isASCIIAlphaCaselessEqual(scheme[4], 's')) 986 return true; 987 } 988 989 return m_registeredSchemes.contains(scheme.toStringWithoutCopying()); 980 if (!equalLettersIgnoringASCIICase(scheme.substring(0, 4), "http")) 981 return false; 982 if (scheme.length() == 5 && isASCIIAlphaCaselessEqual(scheme[4], 's')) 983 return true; 984 return scheme.length() == 4; 990 985 } 991 986 -
trunk/Source/WebCore/workers/service/server/SWServer.h
r251124 r251384 126 126 127 127 using CreateContextConnectionCallback = Function<void(const WebCore::RegistrableDomain&)>; 128 WEBCORE_EXPORT SWServer(UniqueRef<SWOriginStore>&&, HashSet<String>&& registeredSchemes,bool processTerminationDelayEnabled, String&& registrationDatabaseDirectory, PAL::SessionID, CreateContextConnectionCallback&&);128 WEBCORE_EXPORT SWServer(UniqueRef<SWOriginStore>&&, bool processTerminationDelayEnabled, String&& registrationDatabaseDirectory, PAL::SessionID, CreateContextConnectionCallback&&); 129 129 130 130 WEBCORE_EXPORT ~SWServer(); … … 257 257 bool m_importCompleted { false }; 258 258 bool m_isProcessTerminationDelayEnabled { true }; 259 HashSet<String> m_registeredSchemes;260 259 Vector<CompletionHandler<void()>> m_clearCompletionCallbacks; 261 260 Vector<Function<void(const HashSet<SecurityOriginData>&)>> m_getOriginsWithRegistrationsCallbacks; -
trunk/Source/WebKit/ChangeLog
r251382 r251384 1 2019-10-21 Alex Christensen <achristensen@webkit.org> 2 3 ServiceWorker tests should use TCPServer instead of WKURLSchemeHandler 4 https://bugs.webkit.org/show_bug.cgi?id=203141 5 6 Reviewed by Youenn Fablet. 7 8 * NetworkProcess/NetworkProcess.cpp: 9 (WebKit::NetworkProcess::initializeNetworkProcess): 10 (WebKit::NetworkProcess::addWebsiteDataStore): 11 (WebKit::NetworkProcess::swServerForSession): 12 (WebKit::NetworkProcess::addServiceWorkerSession): 13 * NetworkProcess/NetworkProcess.h: 14 * Shared/WebsiteDataStoreParameters.cpp: 15 (WebKit::WebsiteDataStoreParameters::encode const): 16 (WebKit::WebsiteDataStoreParameters::decode): 17 * Shared/WebsiteDataStoreParameters.h: 18 * UIProcess/API/Cocoa/_WKWebsiteDataStoreConfiguration.h: 19 * UIProcess/API/Cocoa/_WKWebsiteDataStoreConfiguration.mm: 20 (-[_WKWebsiteDataStoreConfiguration registerURLSchemeServiceWorkersCanHandleForTesting:]): Deleted. 21 * UIProcess/WebProcessPool.cpp: 22 (WebKit::WebProcessPool::initializeNewWebProcess): 23 * UIProcess/WebsiteData/Cocoa/WebsiteDataStoreCocoa.mm: 24 (WebKit::WebsiteDataStore::parameters): 25 * UIProcess/WebsiteData/WebsiteDataStoreConfiguration.cpp: 26 (WebKit::WebsiteDataStoreConfiguration::copy): 27 * UIProcess/WebsiteData/WebsiteDataStoreConfiguration.h: 28 (WebKit::WebsiteDataStoreConfiguration::serviceWorkerRegisteredSchemes const): Deleted. 29 (WebKit::WebsiteDataStoreConfiguration::registerServiceWorkerScheme): Deleted. 30 1 31 2019-10-21 Tim Horton <timothy_horton@apple.com> 2 32 -
trunk/Source/WebKit/NetworkProcess/NetworkProcess.cpp
r251213 r251384 324 324 if (parentProcessHasServiceWorkerEntitlement()) { 325 325 bool serviceWorkerProcessTerminationDelayEnabled = true; 326 addServiceWorkerSession(PAL::SessionID::defaultSessionID(), serviceWorkerProcessTerminationDelayEnabled, { },WTFMove(parameters.serviceWorkerRegistrationDirectory), parameters.serviceWorkerRegistrationDirectoryExtensionHandle);326 addServiceWorkerSession(PAL::SessionID::defaultSessionID(), serviceWorkerProcessTerminationDelayEnabled, WTFMove(parameters.serviceWorkerRegistrationDirectory), parameters.serviceWorkerRegistrationDirectoryExtensionHandle); 327 327 } 328 328 #endif … … 447 447 #if ENABLE(SERVICE_WORKER) 448 448 if (parentProcessHasServiceWorkerEntitlement()) 449 addServiceWorkerSession(parameters.networkSessionParameters.sessionID, parameters.serviceWorkerProcessTerminationDelayEnabled, WTFMove(parameters.serviceWorkerRegist eredSchemes), WTFMove(parameters.serviceWorkerRegistrationDirectory), parameters.serviceWorkerRegistrationDirectoryExtensionHandle);449 addServiceWorkerSession(parameters.networkSessionParameters.sessionID, parameters.serviceWorkerProcessTerminationDelayEnabled, WTFMove(parameters.serviceWorkerRegistrationDirectory), parameters.serviceWorkerRegistrationDirectoryExtensionHandle); 450 450 #endif 451 451 … … 2398 2398 auto info = m_serviceWorkerInfo.get(sessionID); 2399 2399 auto path = info.databasePath; 2400 auto registeredSchemes = info.registeredSchemes;2401 2400 // There should already be a registered path for this PAL::SessionID. 2402 2401 // If there's not, then where did this PAL::SessionID come from? 2403 2402 ASSERT(sessionID.isEphemeral() || !path.isEmpty()); 2404 2403 2405 return makeUnique<SWServer>(makeUniqueRef<WebSWOriginStore>(), WTFMove(registeredSchemes),info.processTerminationDelayEnabled, WTFMove(path), sessionID, [this, sessionID](auto& registrableDomain) {2404 return makeUnique<SWServer>(makeUniqueRef<WebSWOriginStore>(), info.processTerminationDelayEnabled, WTFMove(path), sessionID, [this, sessionID](auto& registrableDomain) { 2406 2405 ASSERT(!registrableDomain.isEmpty()); 2407 2406 parentProcessConnection()->send(Messages::NetworkProcessProxy::EstablishWorkerContextConnectionToNetworkProcess { registrableDomain, sessionID }, 0); … … 2434 2433 } 2435 2434 2436 void NetworkProcess::addServiceWorkerSession(PAL::SessionID sessionID, bool processTerminationDelayEnabled, HashSet<String>&& registeredSchemes,String&& serviceWorkerRegistrationDirectory, const SandboxExtension::Handle& handle)2435 void NetworkProcess::addServiceWorkerSession(PAL::SessionID sessionID, bool processTerminationDelayEnabled, String&& serviceWorkerRegistrationDirectory, const SandboxExtension::Handle& handle) 2437 2436 { 2438 2437 ServiceWorkerInfo info { 2439 2438 WTFMove(serviceWorkerRegistrationDirectory), 2440 processTerminationDelayEnabled, 2441 WTFMove(registeredSchemes) 2439 processTerminationDelayEnabled 2442 2440 }; 2443 2441 auto addResult = m_serviceWorkerInfo.add(sessionID, WTFMove(info)); -
trunk/Source/WebKit/NetworkProcess/NetworkProcess.h
r251213 r251384 464 464 WebSWOriginStore* existingSWOriginStoreForSession(PAL::SessionID) const; 465 465 466 void addServiceWorkerSession(PAL::SessionID, bool processTerminationDelayEnabled, HashSet<String>&& registeredSchemes,String&& serviceWorkerRegistrationDirectory, const SandboxExtension::Handle&);466 void addServiceWorkerSession(PAL::SessionID, bool processTerminationDelayEnabled, String&& serviceWorkerRegistrationDirectory, const SandboxExtension::Handle&); 467 467 #endif 468 468 … … 532 532 String databasePath; 533 533 bool processTerminationDelayEnabled { true }; 534 HashSet<String> registeredSchemes;535 534 }; 536 535 HashMap<PAL::SessionID, ServiceWorkerInfo> m_serviceWorkerInfo; -
trunk/Source/WebKit/Shared/WebsiteDataStoreParameters.cpp
r250728 r251384 52 52 #if ENABLE(SERVICE_WORKER) 53 53 encoder << serviceWorkerRegistrationDirectory << serviceWorkerRegistrationDirectoryExtensionHandle << serviceWorkerProcessTerminationDelayEnabled; 54 encoder << serviceWorkerRegisteredSchemes;55 54 #endif 56 55 … … 129 128 return WTF::nullopt; 130 129 parameters.serviceWorkerProcessTerminationDelayEnabled = WTFMove(*serviceWorkerProcessTerminationDelayEnabled); 131 132 Optional<HashSet<String>> serviceWorkerRegisteredSchemes;133 decoder >> serviceWorkerRegisteredSchemes;134 if (!serviceWorkerRegisteredSchemes)135 return WTF::nullopt;136 parameters.serviceWorkerRegisteredSchemes = WTFMove(*serviceWorkerRegisteredSchemes);137 130 #endif 138 131 -
trunk/Source/WebKit/Shared/WebsiteDataStoreParameters.h
r250728 r251384 67 67 SandboxExtension::Handle serviceWorkerRegistrationDirectoryExtensionHandle; 68 68 bool serviceWorkerProcessTerminationDelayEnabled { true }; 69 HashSet<String> serviceWorkerRegisteredSchemes;70 69 #endif 71 70 -
trunk/Source/WebKit/UIProcess/API/Cocoa/_WKWebsiteDataStoreConfiguration.h
r250728 r251384 72 72 73 73 // Testing only. 74 - (void)registerURLSchemeServiceWorkersCanHandleForTesting:(NSString *)scheme WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));75 74 @property (nonatomic) BOOL allLoadsBlockedByDeviceManagementRestrictionsForTesting WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA)); 76 75 -
trunk/Source/WebKit/UIProcess/API/Cocoa/_WKWebsiteDataStoreConfiguration.mm
r250728 r251384 401 401 } 402 402 403 - (void)registerURLSchemeServiceWorkersCanHandleForTesting:(NSString *)scheme404 {405 _configuration->registerServiceWorkerScheme(scheme);406 }407 408 403 - (API::Object&)_apiObject 409 404 { -
trunk/Source/WebKit/UIProcess/WebProcessPool.cpp
r251220 r251384 953 953 parameters.urlSchemesRegisteredAsAlwaysRevalidated = copyToVector(m_schemesToRegisterAsAlwaysRevalidated); 954 954 parameters.urlSchemesRegisteredAsCachePartitioned = copyToVector(m_schemesToRegisterAsCachePartitioned); 955 if (websiteDataStore)956 parameters.urlSchemesServiceWorkersCanHandle = copyToVector(websiteDataStore->configuration().serviceWorkerRegisteredSchemes());957 955 parameters.urlSchemesRegisteredAsCanDisplayOnlyIfCanRequest = copyToVector(m_schemesToRegisterAsCanDisplayOnlyIfCanRequest); 958 956 -
trunk/Source/WebKit/UIProcess/WebsiteData/Cocoa/WebsiteDataStoreCocoa.mm
r251213 r251384 183 183 SandboxExtension::createHandleForReadWriteDirectory(parameters.serviceWorkerRegistrationDirectory, parameters.serviceWorkerRegistrationDirectoryExtensionHandle); 184 184 parameters.serviceWorkerProcessTerminationDelayEnabled = m_configuration->serviceWorkerProcessTerminationDelayEnabled(); 185 parameters.serviceWorkerRegisteredSchemes = m_configuration->serviceWorkerRegisteredSchemes();186 185 #endif 187 186 -
trunk/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStoreConfiguration.cpp
r250728 r251384 55 55 56 56 copy->m_serviceWorkerProcessTerminationDelayEnabled = this->m_serviceWorkerProcessTerminationDelayEnabled; 57 copy->m_serviceWorkerRegisteredSchemes = this->m_serviceWorkerRegisteredSchemes;58 57 copy->m_fastServerTrustEvaluationEnabled = this->m_fastServerTrustEvaluationEnabled; 59 58 copy->m_networkCacheSpeculativeValidationEnabled = this->m_networkCacheSpeculativeValidationEnabled; -
trunk/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStoreConfiguration.h
r250728 r251384 118 118 void setServiceWorkerProcessTerminationDelayEnabled(bool enabled) { m_serviceWorkerProcessTerminationDelayEnabled = enabled; } 119 119 120 const HashSet<String> serviceWorkerRegisteredSchemes() const { return m_serviceWorkerRegisteredSchemes; }121 void registerServiceWorkerScheme(String&& scheme) { m_serviceWorkerRegisteredSchemes.add(scheme); }122 123 120 const String& sourceApplicationBundleIdentifier() const { return m_sourceApplicationBundleIdentifier; } 124 121 void setSourceApplicationBundleIdentifier(String&& identifier) { m_sourceApplicationBundleIdentifier = WTFMove(identifier); } … … 183 180 bool m_suppressesConnectionTerminationOnSystemChange { false }; 184 181 unsigned m_testSpeedMultiplier { 1 }; 185 HashSet<String> m_serviceWorkerRegisteredSchemes;186 182 #if PLATFORM(COCOA) 187 183 RetainPtr<CFDictionaryRef> m_proxyConfiguration; -
trunk/Tools/ChangeLog
r251383 r251384 1 2019-10-21 Alex Christensen <achristensen@webkit.org> 2 3 ServiceWorker tests should use TCPServer instead of WKURLSchemeHandler 4 https://bugs.webkit.org/show_bug.cgi?id=203141 5 6 Reviewed by Youenn Fablet. 7 8 * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: 9 * TestWebKitAPI/Tests/WebKitCocoa/ServiceWorkerBasic.mm: 10 (-[SWMessageHandlerForRestoreFromDiskTest userContentController:didReceiveScriptMessage:]): 11 (-[SWSchemes handledRequests]): Deleted. 12 (-[SWSchemes webView:startURLSchemeTask:]): Deleted. 13 (-[SWSchemes webView:stopURLSchemeTask:]): Deleted. 14 * TestWebKitAPI/Tests/WebKitCocoa/ServiceWorkerTCPServer.h: Added. 15 (ServiceWorkerTCPServer::ServiceWorkerTCPServer): 16 (ServiceWorkerTCPServer::request): 17 (ServiceWorkerTCPServer::requestWithLocalhost): 18 (ServiceWorkerTCPServer::requestWithFragment): 19 (ServiceWorkerTCPServer::userAgentsChecked): 20 (ServiceWorkerTCPServer::requestWithFormat): 21 * TestWebKitAPI/Tests/WebKitCocoa/StorageQuota.mm: 22 (-[StorageSchemes webView:startURLSchemeTask:]): Deleted. 23 (-[StorageSchemes webView:stopURLSchemeTask:]): Deleted. 24 1 25 2019-10-21 Jonathan Bedard <jbedard@apple.com> 2 26 -
trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
r251377 r251384 1909 1909 5C4A84941F7EEFD400ACFC54 /* Configuration.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = Configuration.mm; sourceTree = "<group>"; }; 1910 1910 5C5E633D1D0B67940085A025 /* UniqueRef.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = UniqueRef.cpp; sourceTree = "<group>"; }; 1911 5C683471235ACC7C0041E6B1 /* ServiceWorkerTCPServer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ServiceWorkerTCPServer.h; sourceTree = "<group>"; }; 1911 1912 5C69BDD41F82A7EB000F4F4B /* JavaScriptDuringNavigation.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = JavaScriptDuringNavigation.mm; sourceTree = "<group>"; }; 1912 1913 5C6E27A6224EEBEA00128736 /* URLCanonicalization.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = URLCanonicalization.mm; sourceTree = "<group>"; }; … … 2925 2926 CE0947362063223B003C9BA0 /* SchemeRegistry.mm */, 2926 2927 51EB12931FDF050500A5A1BD /* ServiceWorkerBasic.mm */, 2928 5C683471235ACC7C0041E6B1 /* ServiceWorkerTCPServer.h */, 2927 2929 5CCB10DF2134579D00AC5AF0 /* ShouldGoToBackForwardListItem.mm */, 2928 2930 37BCA61B1B596BA9002012CA /* ShouldOpenExternalURLsInNewWindowActions.mm */, -
trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ServiceWorkerBasic.mm
r251138 r251384 27 27 28 28 #import "PlatformUtilities.h" 29 #import " TCPServer.h"29 #import "ServiceWorkerTCPServer.h" 30 30 #import "Test.h" 31 31 #import "TestNavigationDelegate.h" … … 50 50 #import <wtf/text/WTFString.h> 51 51 52 struct ResourceInfo {53 RetainPtr<NSString> mimeType;54 const char* data;55 };56 57 52 static bool done; 58 53 static bool didFinishNavigation; … … 114 109 - (void)userContentController:(WKUserContentController *)userContentController didReceiveScriptMessage:(WKScriptMessage *)message 115 110 { 116 EXPECT_ TRUE([[message body] isEqualToString:_expectedMessage]);111 EXPECT_WK_STREQ(message.body, _expectedMessage); 117 112 done = true; 118 113 } 119 @end120 121 @interface SWSchemes : NSObject <WKURLSchemeHandler> {122 @public123 HashMap<String, ResourceInfo> resources;124 NSString *expectedUserAgent;125 }126 127 -(size_t)handledRequests;128 @end129 130 @implementation SWSchemes {131 size_t _handledRequests;132 }133 134 -(size_t)handledRequests135 {136 return _handledRequests;137 }138 139 - (void)webView:(WKWebView *)webView startURLSchemeTask:(id <WKURLSchemeTask>)task140 {141 if (expectedUserAgent)142 EXPECT_WK_STREQ(expectedUserAgent, [[task.request valueForHTTPHeaderField:@"User-Agent"] UTF8String]);143 144 auto entry = resources.find([task.request.URL absoluteString]);145 if (entry == resources.end()) {146 NSLog(@"Did not find resource entry for URL %@", task.request.URL);147 return;148 }149 150 ++_handledRequests;151 RetainPtr<NSURLResponse> response = adoptNS([[NSURLResponse alloc] initWithURL:task.request.URL MIMEType:entry->value.mimeType.get() expectedContentLength:1 textEncodingName:nil]);152 [task didReceiveResponse:response.get()];153 154 [task didReceiveData:[NSData dataWithBytesNoCopy:(void*)entry->value.data length:strlen(entry->value.data) freeWhenDone:NO]];155 [task didFinish];156 }157 158 - (void)webView:(WKWebView *)webView stopURLSchemeTask:(id <WKURLSchemeTask>)task159 {160 }161 162 114 @end 163 115 … … 358 310 </body> 359 311 </html> 360 )SWRESOURCE";361 362 static const char* testBytes = R"SWRESOURCE(363 <body>364 NOT intercepted by worker365 </body>366 312 )SWRESOURCE"; 367 313 … … 471 417 )SWRESOURCE"; 472 418 473 static WKWebsiteDataStore *dataStoreWithRegisteredServiceWorkerScheme(NSString *scheme)474 {475 _WKWebsiteDataStoreConfiguration *configuration = [[[_WKWebsiteDataStoreConfiguration alloc] init] autorelease];476 [configuration registerURLSchemeServiceWorkersCanHandleForTesting:scheme];477 return [[[WKWebsiteDataStore alloc] _initWithConfiguration:configuration] autorelease];478 }479 480 419 TEST(ServiceWorkers, Basic) 481 420 { 482 ASSERT(mainBytes); 483 ASSERT(scriptBytes); 484 485 [WKWebsiteDataStore _allowWebsiteDataRecordsForAllOrigins]; 486 487 auto* dataStore = dataStoreWithRegisteredServiceWorkerScheme(@"sw"); 488 489 // Start with a clean slate data store 490 [dataStore removeDataOfTypes:[WKWebsiteDataStore allWebsiteDataTypes] modifiedSince:[NSDate distantPast] completionHandler:^() { 491 done = true; 492 }]; 493 TestWebKitAPI::Util::run(&done); 494 done = false; 495 496 auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]); 497 [configuration setWebsiteDataStore:dataStore]; 498 499 RetainPtr<SWMessageHandler> messageHandler = adoptNS([[SWMessageHandler alloc] init]); 500 [[configuration userContentController] addScriptMessageHandler:messageHandler.get() name:@"sw"]; 501 502 RetainPtr<SWSchemes> handler = adoptNS([[SWSchemes alloc] init]); 503 handler->resources.set("sw://host/main.html", ResourceInfo { @"text/html", mainBytes }); 504 handler->resources.set("sw://host/sw.js", ResourceInfo { @"application/javascript", scriptBytes }); 505 [configuration setURLSchemeHandler:handler.get() forURLScheme:@"SW"]; 506 507 RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]); 508 509 NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"sw://host/main.html"]]; 510 [webView loadRequest:request]; 511 512 TestWebKitAPI::Util::run(&done); 513 done = false; 514 515 webView = nullptr; 516 517 [dataStore fetchDataRecordsOfTypes:[NSSet setWithObject:WKWebsiteDataTypeServiceWorkerRegistrations] completionHandler:^(NSArray<WKWebsiteDataRecord *> *websiteDataRecords) { 518 EXPECT_EQ(1u, [websiteDataRecords count]); 519 EXPECT_TRUE([websiteDataRecords[0].displayName isEqualToString:@"sw host"]); 520 521 done = true; 522 }]; 523 524 TestWebKitAPI::Util::run(&done); 525 done = false; 526 } 527 528 TEST(ServiceWorkers, BasicDefaultSession) 529 { 530 using namespace TestWebKitAPI; 531 TCPServer server([] (int socket) { 532 NSString *format = @"HTTP/1.1 200 OK\r\n" 533 "Content-Type: %s\r\n" 534 "Content-Length: %d\r\n\r\n" 535 "%s"; 536 NSString *firstResponse = [NSString stringWithFormat:format, "text/html", strlen(mainBytes), mainBytes]; 537 NSString *secondResponse = [NSString stringWithFormat:format, "application/javascript", strlen(scriptBytes), scriptBytes]; 538 539 TCPServer::read(socket); 540 TCPServer::write(socket, firstResponse.UTF8String, firstResponse.length); 541 TCPServer::read(socket); 542 TCPServer::write(socket, secondResponse.UTF8String, secondResponse.length); 421 ServiceWorkerTCPServer server({ 422 { "text/html", mainBytes }, 423 { "application/javascript", scriptBytes}, 543 424 }); 544 425 … … 559 440 auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]); 560 441 561 [webView loadRequest: [NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://127.0.0.1:%d/", server.port()]]]];442 [webView loadRequest:server.request()]; 562 443 563 444 TestWebKitAPI::Util::run(&done); … … 638 519 [WKWebsiteDataStore _allowWebsiteDataRecordsForAllOrigins]; 639 520 640 auto* dataStore = dataStoreWithRegisteredServiceWorkerScheme(@"sw");641 642 521 // Start with a clean slate data store 643 [ dataStoreremoveDataOfTypes:[WKWebsiteDataStore allWebsiteDataTypes] modifiedSince:[NSDate distantPast] completionHandler:^() {522 [[WKWebsiteDataStore defaultDataStore] removeDataOfTypes:[WKWebsiteDataStore allWebsiteDataTypes] modifiedSince:[NSDate distantPast] completionHandler:^() { 644 523 done = true; 645 524 }]; … … 648 527 649 528 auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]); 650 [configuration setWebsiteDataStore:dataStore];651 529 652 530 auto messageHandler = adoptNS([[SWUserAgentMessageHandler alloc] initWithExpectedMessage:@"Message from worker: Foo Custom UserAgent"]); 653 531 [[configuration userContentController] addScriptMessageHandler:messageHandler.get() name:@"sw"]; 654 532 655 auto handler = adoptNS([[SWSchemes alloc] init]); 656 handler->resources.set("sw://host/main.html", ResourceInfo { @"text/html", mainBytes }); 657 handler->resources.set("sw://host/sw.js", ResourceInfo { @"application/javascript", userAgentSWBytes }); 658 handler->expectedUserAgent = @"Foo Custom UserAgent"; 659 [configuration setURLSchemeHandler:handler.get() forURLScheme:@"SW"]; 533 ServiceWorkerTCPServer server({ 534 { "text/html", mainBytes }, 535 { "application/javascript", userAgentSWBytes }, 536 }, { 537 { "text/html", mainBytes }, 538 { "application/javascript", userAgentSWBytes }, 539 }, 2, { "Foo Custom UserAgent"_s, "Bar Custom UserAgent"_s }); 660 540 661 541 auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]); … … 664 544 [webView setNavigationDelegate:delegate.get()]; 665 545 666 NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"sw://host/main.html"]]; 667 [webView loadRequest:request]; 546 [webView loadRequest:server.request()]; 668 547 669 548 TestWebKitAPI::Util::run(&done); … … 673 552 webView = nullptr; 674 553 delegate = nullptr; 675 handler = nullptr;676 554 messageHandler = nullptr; 677 555 configuration = nullptr; 678 556 679 557 configuration = adoptNS([[WKWebViewConfiguration alloc] init]); 680 [configuration setWebsiteDataStore:dataStore];681 558 682 559 messageHandler = adoptNS([[SWUserAgentMessageHandler alloc] initWithExpectedMessage:@"Message from worker: Bar Custom UserAgent"]); 683 560 [[configuration userContentController] addScriptMessageHandler:messageHandler.get() name:@"sw"]; 684 685 handler = adoptNS([[SWSchemes alloc] init]);686 handler->resources.set("sw://host/main.html", ResourceInfo { @"text/html", mainBytes });687 handler->resources.set("sw://host/sw.js", ResourceInfo { @"application/javascript", userAgentSWBytes });688 handler->expectedUserAgent = @"Bar Custom UserAgent";689 [configuration setURLSchemeHandler:handler.get() forURLScheme:@"SW"];690 561 691 562 webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]); … … 694 565 [webView setNavigationDelegate:delegate.get()]; 695 566 696 request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"sw://host/main.html"]];697 [webView loadRequest:request]; 698 699 TestWebKitAPI::Util::run(&done);700 done = false;567 [webView loadRequest:server.request()]; 568 569 TestWebKitAPI::Util::run(&done); 570 done = false; 571 EXPECT_EQ(server.userAgentsChecked(), 3ull); 701 572 } 702 573 703 574 TEST(ServiceWorkers, RestoreFromDisk) 704 575 { 705 ASSERT(mainRegisteringWorkerBytes); 706 ASSERT(scriptBytes); 707 ASSERT(mainRegisteringAlreadyExistingWorkerBytes); 708 709 [WKWebsiteDataStore _allowWebsiteDataRecordsForAllOrigins]; 710 711 auto* dataStore = dataStoreWithRegisteredServiceWorkerScheme(@"sw"); 576 [WKWebsiteDataStore _allowWebsiteDataRecordsForAllOrigins]; 712 577 713 578 // Start with a clean slate data store 714 [ dataStoreremoveDataOfTypes:[WKWebsiteDataStore allWebsiteDataTypes] modifiedSince:[NSDate distantPast] completionHandler:^() {579 [[WKWebsiteDataStore defaultDataStore] removeDataOfTypes:[WKWebsiteDataStore allWebsiteDataTypes] modifiedSince:[NSDate distantPast] completionHandler:^() { 715 580 done = true; 716 581 }]; … … 719 584 720 585 auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]); 721 [configuration setWebsiteDataStore:dataStore];722 586 723 587 RetainPtr<SWMessageHandlerForRestoreFromDiskTest> messageHandler = adoptNS([[SWMessageHandlerForRestoreFromDiskTest alloc] initWithExpectedMessage:@"PASS: Registration was successful and service worker was activated"]); 724 588 [[configuration userContentController] addScriptMessageHandler:messageHandler.get() name:@"sw"]; 725 589 726 RetainPtr<SWSchemes> handler = adoptNS([[SWSchemes alloc] init]); 727 handler->resources.set("sw://host/main.html", ResourceInfo { @"text/html", mainRegisteringWorkerBytes }); 728 handler->resources.set("sw://host/sw.js", ResourceInfo { @"application/javascript", scriptBytes }); 729 [configuration setURLSchemeHandler:handler.get() forURLScheme:@"SW"]; 590 ServiceWorkerTCPServer server({ 591 { "text/html", mainRegisteringWorkerBytes }, 592 { "application/javascript", scriptBytes }, 593 }, { 594 { "text/html", mainRegisteringAlreadyExistingWorkerBytes }, 595 { "application/javascript", scriptBytes }, 596 }); 730 597 731 598 RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]); 732 599 733 NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"sw://host/main.html"]]; 734 [webView loadRequest:request]; 600 [webView loadRequest:server.request()]; 735 601 736 602 TestWebKitAPI::Util::run(&done); … … 739 605 configuration = nullptr; 740 606 messageHandler = nullptr; 741 handler = nullptr;742 607 743 608 done = false; 744 609 745 610 configuration = adoptNS([[WKWebViewConfiguration alloc] init]); 746 [configuration setWebsiteDataStore:dataStore];747 611 messageHandler = adoptNS([[SWMessageHandlerForRestoreFromDiskTest alloc] initWithExpectedMessage:@"PASS: Registration already has an active worker"]); 748 612 [[configuration userContentController] addScriptMessageHandler:messageHandler.get() name:@"sw"]; 749 613 750 handler = adoptNS([[SWSchemes alloc] init]);751 handler->resources.set("sw://host/main.html", ResourceInfo { @"text/html", mainRegisteringAlreadyExistingWorkerBytes });752 handler->resources.set("sw://host/sw.js", ResourceInfo { @"application/javascript", scriptBytes });753 [configuration setURLSchemeHandler:handler.get() forURLScheme:@"SW"];754 755 614 webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]); 756 615 757 request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"sw://host/main.html"]]; 758 [webView loadRequest:request]; 616 [webView loadRequest:server.request()]; 759 617 760 618 TestWebKitAPI::Util::run(&done); … … 764 622 TEST(ServiceWorkers, CacheStorageRestoreFromDisk) 765 623 { 766 ASSERT(mainCacheStorageBytes); 767 [WKWebsiteDataStore _allowWebsiteDataRecordsForAllOrigins]; 768 769 auto* dataStore = dataStoreWithRegisteredServiceWorkerScheme(@"sw"); 770 624 [WKWebsiteDataStore _allowWebsiteDataRecordsForAllOrigins]; 625 771 626 // Start with a clean slate data store 772 [ dataStoreremoveDataOfTypes:[WKWebsiteDataStore allWebsiteDataTypes] modifiedSince:[NSDate distantPast] completionHandler:^() {627 [[WKWebsiteDataStore defaultDataStore] removeDataOfTypes:[WKWebsiteDataStore allWebsiteDataTypes] modifiedSince:[NSDate distantPast] completionHandler:^() { 773 628 done = true; 774 629 }]; … … 779 634 [WKWebsiteDataStore _deleteDefaultDataStoreForTesting]; 780 635 781 auto handler = adoptNS([[SWSchemes alloc] init]); 782 handler->resources.set("sw://host/main.html", ResourceInfo { @"text/html", mainCacheStorageBytes }); 636 ServiceWorkerTCPServer server({ 637 { "text/html", mainCacheStorageBytes } 638 }, { 639 { "text/html", mainCacheStorageBytes } 640 }); 783 641 784 642 auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]); 785 [configuration setWebsiteDataStore:dataStore];786 643 auto messageHandler = adoptNS([[SWMessageHandlerForRestoreFromDiskTest alloc] initWithExpectedMessage:@"No cache storage data"]); 787 644 788 645 [[configuration userContentController] addScriptMessageHandler:messageHandler.get() name:@"sw"]; 789 [configuration setURLSchemeHandler:handler.get() forURLScheme:@"SW"];790 646 791 647 auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]); 792 648 793 // Trigger creation of network process. 794 [webView.get().configuration.processPool _syncNetworkProcessCookies]; 795 796 auto *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"sw://host/main.html"]]; 797 [webView loadRequest:request]; 649 [webView loadRequest:server.request()]; 798 650 799 651 TestWebKitAPI::Util::run(&done); … … 805 657 806 658 configuration = adoptNS([[WKWebViewConfiguration alloc] init]); 807 [configuration setWebsiteDataStore:dataStore];808 659 messageHandler = adoptNS([[SWMessageHandlerForRestoreFromDiskTest alloc] initWithExpectedMessage:@"Some cache storage data: my cache"]); 809 660 810 661 [[configuration userContentController] addScriptMessageHandler:messageHandler.get() name:@"sw"]; 811 [configuration setURLSchemeHandler:handler.get() forURLScheme:@"SW"];812 662 813 663 webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]); 814 664 815 request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"sw://host/main.html"]]; 816 [webView loadRequest:request]; 817 818 TestWebKitAPI::Util::run(&done); 819 done = false; 820 } 821 665 [webView loadRequest:server.request()]; 666 667 TestWebKitAPI::Util::run(&done); 668 done = false; 669 } 822 670 823 671 TEST(ServiceWorkers, FetchAfterRestoreFromDisk) 824 672 { 825 ASSERT(mainForFetchTestBytes); 826 ASSERT(scriptHandlingFetchBytes); 827 828 [WKWebsiteDataStore _allowWebsiteDataRecordsForAllOrigins]; 829 830 auto* dataStore = dataStoreWithRegisteredServiceWorkerScheme(@"sw"); 831 673 [WKWebsiteDataStore _allowWebsiteDataRecordsForAllOrigins]; 674 832 675 // Start with a clean slate data store 833 [ dataStoreremoveDataOfTypes:[WKWebsiteDataStore allWebsiteDataTypes] modifiedSince:[NSDate distantPast] completionHandler:^() {676 [[WKWebsiteDataStore defaultDataStore] removeDataOfTypes:[WKWebsiteDataStore allWebsiteDataTypes] modifiedSince:[NSDate distantPast] completionHandler:^() { 834 677 done = true; 835 678 }]; … … 838 681 839 682 RetainPtr<WKWebViewConfiguration> configuration = adoptNS([[WKWebViewConfiguration alloc] init]); 840 [configuration setWebsiteDataStore:dataStore];841 683 842 684 RetainPtr<SWMessageHandlerForFetchTest> messageHandler = adoptNS([[SWMessageHandlerForFetchTest alloc] init]); 843 685 [[configuration userContentController] addScriptMessageHandler:messageHandler.get() name:@"sw"]; 844 686 845 RetainPtr<SWSchemes> handler = adoptNS([[SWSchemes alloc] init]); 846 handler->resources.set("sw://host/main.html", ResourceInfo { @"text/html", mainForFetchTestBytes }); 847 handler->resources.set("sw://host/test.html", ResourceInfo { @"text/html", testBytes }); 848 handler->resources.set("sw://host/sw.js", ResourceInfo { @"application/javascript", scriptHandlingFetchBytes }); 849 [configuration setURLSchemeHandler:handler.get() forURLScheme:@"SW"]; 687 ServiceWorkerTCPServer server({ 688 { "text/html", mainForFetchTestBytes }, 689 { "application/javascript", scriptHandlingFetchBytes }, 690 }, { 691 { "text/html", mainForFetchTestBytes }, 692 { "application/javascript", scriptHandlingFetchBytes }, 693 }); 850 694 851 695 RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]); 852 696 853 NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"sw://host/main.html"]]; 854 [webView loadRequest:request]; 697 [webView loadRequest:server.request()]; 855 698 856 699 TestWebKitAPI::Util::run(&done); … … 859 702 configuration = nullptr; 860 703 messageHandler = nullptr; 861 handler = nullptr;862 704 863 705 done = false; 864 706 865 707 configuration = adoptNS([[WKWebViewConfiguration alloc] init]); 866 [configuration setWebsiteDataStore:dataStore];867 708 messageHandler = adoptNS([[SWMessageHandlerForFetchTest alloc] init]); 868 709 [[configuration userContentController] addScriptMessageHandler:messageHandler.get() name:@"sw"]; 869 710 870 handler = adoptNS([[SWSchemes alloc] init]);871 handler->resources.set("sw://host/main.html", ResourceInfo { @"text/html", mainForFetchTestBytes });872 handler->resources.set("sw://host/test.html", ResourceInfo { @"text/html", testBytes });873 handler->resources.set("sw://host/sw.js", ResourceInfo { @"application/javascript", scriptHandlingFetchBytes });874 [configuration setURLSchemeHandler:handler.get() forURLScheme:@"SW"];875 876 711 webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]); 877 712 878 request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"sw://host/main.html"]]; 879 [webView loadRequest:request]; 713 [webView loadRequest:server.request()]; 880 714 881 715 TestWebKitAPI::Util::run(&done); … … 885 719 TEST(ServiceWorkers, InterceptFirstLoadAfterRestoreFromDisk) 886 720 { 887 ASSERT(mainForFirstLoadInterceptTestBytes); 888 ASSERT(scriptHandlingFetchBytes); 889 890 [WKWebsiteDataStore _allowWebsiteDataRecordsForAllOrigins]; 891 892 auto* dataStore = dataStoreWithRegisteredServiceWorkerScheme(@"sw"); 721 [WKWebsiteDataStore _allowWebsiteDataRecordsForAllOrigins]; 893 722 894 723 // Start with a clean slate data store 895 [ dataStoreremoveDataOfTypes:[WKWebsiteDataStore allWebsiteDataTypes] modifiedSince:[NSDate distantPast] completionHandler:^() {724 [[WKWebsiteDataStore defaultDataStore] removeDataOfTypes:[WKWebsiteDataStore allWebsiteDataTypes] modifiedSince:[NSDate distantPast] completionHandler:^() { 896 725 done = true; 897 726 }]; … … 900 729 901 730 RetainPtr<WKWebViewConfiguration> configuration = adoptNS([[WKWebViewConfiguration alloc] init]); 902 [configuration setWebsiteDataStore:dataStore];903 731 904 732 RetainPtr<SWMessageHandlerWithExpectedMessage> messageHandler = adoptNS([[SWMessageHandlerWithExpectedMessage alloc] init]); 905 733 [[configuration userContentController] addScriptMessageHandler:messageHandler.get() name:@"sw"]; 906 734 907 RetainPtr<SWSchemes> handler = adoptNS([[SWSchemes alloc] init]); 908 handler->resources.set("sw://host/main.html", ResourceInfo { @"text/html", mainForFirstLoadInterceptTestBytes }); 909 handler->resources.set("sw://host/sw.js", ResourceInfo { @"application/javascript", scriptInterceptingFirstLoadBytes }); 910 [configuration setURLSchemeHandler:handler.get() forURLScheme:@"SW"]; 735 ServiceWorkerTCPServer server({ 736 { "text/html", mainForFirstLoadInterceptTestBytes }, 737 { "application/javascript", scriptInterceptingFirstLoadBytes }, 738 }, { 739 { "application/javascript", scriptInterceptingFirstLoadBytes }, 740 }); 911 741 912 742 RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]); 913 743 914 744 expectedMessage = "Service Worker activated"; 915 NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"sw://host/main.html"]]; 916 [webView loadRequest:request]; 745 [webView loadRequest:server.request()]; 917 746 918 747 TestWebKitAPI::Util::run(&done); … … 921 750 configuration = nullptr; 922 751 messageHandler = nullptr; 923 handler = nullptr;924 752 925 753 done = false; 926 754 927 755 configuration = adoptNS([[WKWebViewConfiguration alloc] init]); 928 [configuration setWebsiteDataStore:dataStore];929 756 messageHandler = adoptNS([[SWMessageHandlerWithExpectedMessage alloc] init]); 930 757 [[configuration userContentController] addScriptMessageHandler:messageHandler.get() name:@"sw"]; 931 758 932 handler = adoptNS([[SWSchemes alloc] init]);933 handler->resources.set("sw://host/main.html", ResourceInfo { @"text/html", mainForFirstLoadInterceptTestBytes });934 handler->resources.set("sw://host/sw.js", ResourceInfo { @"application/javascript", scriptInterceptingFirstLoadBytes });935 [configuration setURLSchemeHandler:handler.get() forURLScheme:@"SW"];936 937 759 webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]); 938 760 939 761 expectedMessage = "Intercepted by worker"; 940 request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"sw://host/main.html"]]; 941 [webView loadRequest:request]; 762 [webView loadRequest:server.request()]; 942 763 943 764 TestWebKitAPI::Util::run(&done); … … 949 770 [WKWebsiteDataStore _allowWebsiteDataRecordsForAllOrigins]; 950 771 951 auto* dataStore = dataStoreWithRegisteredServiceWorkerScheme(@"sw");952 953 772 // Start with a clean slate data store 954 [ dataStoreremoveDataOfTypes:[WKWebsiteDataStore allWebsiteDataTypes] modifiedSince:[NSDate distantPast] completionHandler:^() {773 [[WKWebsiteDataStore defaultDataStore] removeDataOfTypes:[WKWebsiteDataStore allWebsiteDataTypes] modifiedSince:[NSDate distantPast] completionHandler:^() { 955 774 done = true; 956 775 }]; … … 959 778 960 779 RetainPtr<WKWebViewConfiguration> configuration = adoptNS([[WKWebViewConfiguration alloc] init]); 961 [configuration setWebsiteDataStore:dataStore];962 780 963 781 RetainPtr<SWMessageHandlerWithExpectedMessage> messageHandler = adoptNS([[SWMessageHandlerWithExpectedMessage alloc] init]); 964 782 [[configuration userContentController] addScriptMessageHandler:messageHandler.get() name:@"sw"]; 965 783 966 RetainPtr<SWSchemes> handler = adoptNS([[SWSchemes alloc] init]); 967 handler->resources.set("sw://host/main.html", ResourceInfo { @"text/html", mainForFirstLoadInterceptTestBytes }); 968 handler->resources.set("sw://host/sw.js", ResourceInfo { @"application/javascript", scriptInterceptingFirstLoadBytes }); 969 [configuration setURLSchemeHandler:handler.get() forURLScheme:@"SW"]; 784 ServiceWorkerTCPServer server({ 785 { "text/html", mainForFirstLoadInterceptTestBytes }, 786 { "application/javascript", scriptInterceptingFirstLoadBytes }, 787 }, { 788 { "application/javascript", scriptInterceptingFirstLoadBytes }, 789 }); 970 790 971 791 RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]); … … 973 793 // Register a service worker and activate it. 974 794 expectedMessage = "Service Worker activated"; 975 NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"sw://host/main.html"]]; 976 [webView loadRequest:request]; 795 [webView loadRequest:server.request()]; 977 796 978 797 TestWebKitAPI::Util::run(&done); … … 981 800 configuration = nullptr; 982 801 messageHandler = nullptr; 983 handler = nullptr;984 802 985 803 done = false; 986 804 987 805 configuration = adoptNS([[WKWebViewConfiguration alloc] init]); 988 [configuration setWebsiteDataStore:dataStore];989 806 messageHandler = adoptNS([[SWMessageHandlerWithExpectedMessage alloc] init]); 990 807 [[configuration userContentController] addScriptMessageHandler:messageHandler.get() name:@"sw"]; 991 992 handler = adoptNS([[SWSchemes alloc] init]);993 handler->resources.set("sw://host/main.html", ResourceInfo { @"text/html", mainForFirstLoadInterceptTestBytes });994 handler->resources.set("sw://host/sw.js", ResourceInfo { @"application/javascript", scriptInterceptingFirstLoadBytes });995 [configuration setURLSchemeHandler:handler.get() forURLScheme:@"SW"];996 808 997 809 webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]); … … 999 811 // Verify service worker is intercepting load. 1000 812 expectedMessage = "Intercepted by worker"; 1001 request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"sw://host/main.html"]]; 1002 [webView loadRequest:request]; 813 [webView loadRequest:server.request()]; 1003 814 1004 815 TestWebKitAPI::Util::run(&done); … … 1015 826 1016 827 // Verify service worker load goes well when policy delegate is ok. 1017 request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"sw://host/main.html"]]; 1018 [webView loadRequest:request]; 828 [webView loadRequest:server.request()]; 1019 829 TestWebKitAPI::Util::run(&navigationComplete); 1020 830 … … 1030 840 1031 841 // Verify service worker load fails well when policy delegate is not ok. 1032 request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"sw://host/main.html"]]; 1033 [webView loadRequest:request]; 842 [webView loadRequest:server.request()]; 1034 843 TestWebKitAPI::Util::run(&navigationComplete); 1035 844 1036 845 EXPECT_TRUE(navigationFailed); 1037 846 } 847 1038 848 #if WK_HAVE_C_SPI 1039 849 … … 1042 852 WKRetainPtr<WKContextRef> context = adoptWK(TestWebKitAPI::Util::createContextForInjectedBundleTest("InternalsInjectedBundleTest")); 1043 853 configuration.processPool = (WKProcessPool *)context.get(); 1044 configuration.websiteDataStore = dataStoreWithRegisteredServiceWorkerScheme(@"sw");1045 854 } 1046 855 … … 1072 881 TEST(ServiceWorkers, SWProcessConnectionCreation) 1073 882 { 1074 ASSERT(mainBytes);1075 ASSERT(scriptBytes);1076 1077 883 [WKWebsiteDataStore _allowWebsiteDataRecordsForAllOrigins]; 1078 884 … … 1101 907 [[configuration userContentController] addScriptMessageHandler:regularPageMessageHandler.get() name:@"regularPage"]; 1102 908 1103 RetainPtr<SWSchemes> handler = adoptNS([[SWSchemes alloc] init]); 1104 handler->resources.set("sw://host/regularPageWithoutConnection.html", ResourceInfo { @"text/html", regularPageWithoutConnectionBytes }); 1105 handler->resources.set("sw://host/regularPageWithConnection.html", ResourceInfo { @"text/html", regularPageWithConnectionBytes }); 1106 handler->resources.set("sw://host/main.html", ResourceInfo { @"text/html", mainBytes }); 1107 handler->resources.set("sw://host/sw.js", ResourceInfo { @"application/javascript", scriptBytes }); 1108 [configuration setURLSchemeHandler:handler.get() forURLScheme:@"SW"]; 909 ServiceWorkerTCPServer server({ 910 { "text/html", regularPageWithoutConnectionBytes }, 911 { "text/html", mainBytes }, 912 { "application/javascript", scriptBytes }, 913 { "text/html", regularPageWithConnectionBytes }, 914 { "text/html", regularPageWithConnectionBytes }, 915 }); 1109 916 1110 917 RetainPtr<WKWebView> regularPageWebView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]); … … 1113 920 1114 921 // Test that a regular page does not trigger a service worker connection to network process if there is no registered service worker. 1115 NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"sw://host/regularPageWithoutConnection.html"]]; 1116 1117 [regularPageWebView loadRequest:request]; 922 [regularPageWebView loadRequest:server.request()]; 1118 923 TestWebKitAPI::Util::run(&done); 1119 924 done = false; 1120 925 1121 926 // Test that a sw scheme page can register a service worker. 1122 request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"sw://host/main.html"]]; 1123 1124 [webView loadRequest:request]; 927 [webView loadRequest:server.request()]; 1125 928 TestWebKitAPI::Util::run(&done); 1126 929 done = false; … … 1128 931 1129 932 // Now that a service worker is registered, the regular page should have a service worker connection. 1130 request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"sw://host/regularPageWithConnection.html"]]; 1131 1132 [regularPageWebView loadRequest:request]; 933 [regularPageWebView loadRequest:server.request()]; 1133 934 TestWebKitAPI::Util::run(&done); 1134 935 done = false; 1135 936 regularPageWebView = nullptr; 1136 937 1137 [newRegularPageWebView loadRequest: request];938 [newRegularPageWebView loadRequest:server.request()]; 1138 939 TestWebKitAPI::Util::run(&done); 1139 940 done = false; … … 1142 943 [[configuration websiteDataStore] fetchDataRecordsOfTypes:[NSSet setWithObject:WKWebsiteDataTypeServiceWorkerRegistrations] completionHandler:^(NSArray<WKWebsiteDataRecord *> *websiteDataRecords) { 1143 944 EXPECT_EQ(1u, [websiteDataRecords count]); 1144 EXPECT_ TRUE([websiteDataRecords[0].displayName isEqualToString:@"sw host"]);945 EXPECT_WK_STREQ(websiteDataRecords[0].displayName, "127.0.0.1"); 1145 946 1146 947 done = true; … … 1209 1010 [[configuration userContentController] addScriptMessageHandler:regularPageMessageHandler.get() name:@"regularPage"]; 1210 1011 1211 RetainPtr<SWSchemes> handler = adoptNS([[SWSchemes alloc] init]); 1212 handler->resources.set("sw://host/regularPageWithoutConnection.html", ResourceInfo { @"text/html", regularPageWithoutConnectionBytes }); 1213 handler->resources.set("sw://host/regularPageWithConnection.html", ResourceInfo { @"text/html", regularPageWithConnectionBytes }); 1214 handler->resources.set("sw://host/mainWithScope.html", ResourceInfo { @"text/html", mainBytesWithScope }); 1215 handler->resources.set("sw://host/main.html", ResourceInfo { @"text/html", mainBytes }); 1216 handler->resources.set("sw://host/sw.js", ResourceInfo { @"application/javascript", scriptBytes }); 1217 [configuration setURLSchemeHandler:handler.get() forURLScheme:@"SW"]; 1012 ServiceWorkerTCPServer server({ 1013 { "text/html", mainBytesWithScope }, 1014 { "application/javascript", scriptBytes }, 1015 }, { 1016 { "text/html", regularPageWithConnectionBytes }, 1017 { "text/html", mainBytes }, 1018 { "application/javascript", scriptBytes }, 1019 }); 1218 1020 1219 1021 RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]); 1220 1022 1221 1023 // Load a page that registers a service worker. 1222 NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"sw://host/mainWithScope.html"]]; 1223 1224 [webView loadRequest:request]; 1024 [webView loadRequest:server.request()]; 1225 1025 TestWebKitAPI::Util::run(&done); 1226 1026 done = false; … … 1234 1034 [[newConfiguration userContentController] addScriptMessageHandler:messageHandler.get() name:@"sw"]; 1235 1035 [[newConfiguration userContentController] addScriptMessageHandler:regularPageMessageHandler.get() name:@"regularPage"]; 1236 [newConfiguration setURLSchemeHandler:handler.get() forURLScheme:@"SW"];1237 1036 1238 1037 webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:newConfiguration.get()]); 1239 1038 EXPECT_EQ(1u, webView.get().configuration.processPool._webProcessCountIgnoringPrewarmed); 1240 request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"sw://host/regularPageWithConnection.html"]]; 1241 [webView loadRequest:request]; 1039 [webView loadRequest:server.request()]; 1242 1040 TestWebKitAPI::Util::run(&done); 1243 1041 done = false; … … 1248 1046 webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:newConfiguration.get()]); 1249 1047 EXPECT_EQ(2u, webView.get().configuration.processPool._webProcessCountIgnoringPrewarmed); 1250 request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"sw://host/main.html"]]; 1251 [webView loadRequest:request]; 1048 [webView loadRequest:server.request()]; 1252 1049 TestWebKitAPI::Util::run(&done); 1253 1050 done = false; … … 1290 1087 [[configuration userContentController] addScriptMessageHandler:regularPageMessageHandler.get() name:@"regularPage"]; 1291 1088 1292 RetainPtr<SWSchemes> handler = adoptNS([[SWSchemes alloc] init]); 1293 handler->resources.set("sw://host/regularPageWithoutConnection.html", ResourceInfo { @"text/html", regularPageWithoutConnectionBytes }); 1294 handler->resources.set("sw://host/regularPageWithConnection.html", ResourceInfo { @"text/html", regularPageWithConnectionBytes }); 1295 handler->resources.set("sw://host/mainWithScope.html", ResourceInfo { @"text/html", mainBytesWithScope }); 1296 handler->resources.set("sw://host/main.html", ResourceInfo { @"text/html", mainBytes }); 1297 handler->resources.set("sw://host/sw.js", ResourceInfo { @"application/javascript", scriptBytes }); 1298 [configuration setURLSchemeHandler:handler.get() forURLScheme:@"SW"]; 1089 ServiceWorkerTCPServer server({ 1090 { "text/html", mainBytesWithScope }, 1091 { "application/javascript", scriptBytes }, 1092 }, { 1093 { "text/html", regularPageWithoutConnectionBytes }, 1094 }, { 1095 { "text/html", regularPageWithConnectionBytes } 1096 }); 1299 1097 1300 1098 RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]); 1301 1099 1302 1100 // Load a page that registers a service worker. 1303 NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"sw://host/mainWithScope.html"]]; 1304 1305 [webView loadRequest:request]; 1101 [webView loadRequest:server.request()]; 1306 1102 TestWebKitAPI::Util::run(&done); 1307 1103 done = false; … … 1314 1110 [[newConfiguration userContentController] addScriptMessageHandler:messageHandler.get() name:@"sw"]; 1315 1111 [[newConfiguration userContentController] addScriptMessageHandler:regularPageMessageHandler.get() name:@"regularPage"]; 1316 [newConfiguration setURLSchemeHandler:handler.get() forURLScheme:@"SW"];1317 1112 1318 1113 newConfiguration.get().websiteDataStore = [WKWebsiteDataStore nonPersistentDataStore]; … … 1320 1115 1321 1116 webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:newConfiguration.get()]); 1322 request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"sw://host/regularPageWithoutConnection.html"]]; 1323 [webView loadRequest:request]; 1117 [webView loadRequest:server.request()]; 1324 1118 TestWebKitAPI::Util::run(&done); 1325 1119 done = false; … … 1330 1124 webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:newConfiguration.get()]); 1331 1125 EXPECT_EQ(2u, webView.get().configuration.processPool._webProcessCountIgnoringPrewarmed); 1332 request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"sw://host/regularPageWithConnection.html"]]; 1333 [webView loadRequest:request]; 1126 [webView loadRequest:server.request()]; 1334 1127 TestWebKitAPI::Util::run(&done); 1335 1128 done = false; … … 1399 1192 [[configuration userContentController] addScriptMessageHandler:messageHandler.get() name:@"sw"]; 1400 1193 1401 auto handler = adoptNS([[SWSchemes alloc] init]); 1402 handler->resources.set("sw://host/readCache.html", ResourceInfo { @"text/html", readCacheBytes }); 1403 handler->resources.set("sw://host/writeCache.html", ResourceInfo { @"text/html", writeCacheBytes }); 1404 [configuration setURLSchemeHandler:handler.get() forURLScheme:@"SW"]; 1405 1406 _WKWebsiteDataStoreConfiguration *dataStoreConfiguration = [[[_WKWebsiteDataStoreConfiguration alloc] initNonPersistentConfiguration] autorelease]; 1407 [dataStoreConfiguration registerURLSchemeServiceWorkersCanHandleForTesting:@"sw"]; 1408 configuration.get().websiteDataStore = [[[WKWebsiteDataStore alloc] _initWithConfiguration:dataStoreConfiguration] autorelease]; 1194 ServiceWorkerTCPServer server({ 1195 { "text/html", writeCacheBytes }, 1196 { "text/html", readCacheBytes }, 1197 }); 1198 1199 configuration.get().websiteDataStore = [WKWebsiteDataStore nonPersistentDataStore]; 1409 1200 1410 1201 auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]); 1411 auto *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"sw://host/writeCache.html"]]; 1412 [webView loadRequest:request]; 1202 [webView loadRequest:server.request()]; 1413 1203 TestWebKitAPI::Util::run(&done); 1414 1204 done = false; 1415 1205 1416 1206 webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]); 1417 request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"sw://host/readCache.html"]]; 1418 [webView loadRequest:request]; 1207 [webView loadRequest:server.request()]; 1419 1208 TestWebKitAPI::Util::run(&done); 1420 1209 done = false; … … 1460 1249 [WKWebsiteDataStore _allowWebsiteDataRecordsForAllOrigins]; 1461 1250 1462 auto* dataStore = dataStoreWithRegisteredServiceWorkerScheme(@"sw");1463 1464 1251 // Start with a clean slate data store 1465 [ dataStoreremoveDataOfTypes:[WKWebsiteDataStore allWebsiteDataTypes] modifiedSince:[NSDate distantPast] completionHandler:^() {1252 [[WKWebsiteDataStore defaultDataStore] removeDataOfTypes:[WKWebsiteDataStore allWebsiteDataTypes] modifiedSince:[NSDate distantPast] completionHandler:^() { 1466 1253 done = true; 1467 1254 }]; … … 1473 1260 auto context = adoptWK(TestWebKitAPI::Util::createContextForInjectedBundleTest("InternalsInjectedBundleTest")); 1474 1261 [configuration setProcessPool:(WKProcessPool *)context.get()]; 1475 [configuration setWebsiteDataStore:dataStore];1476 1262 1477 1263 auto defaultPreferences = [configuration preferences]; 1478 1264 [defaultPreferences _setSecureContextChecksEnabled:NO]; 1479 1265 1480 auto handler = adoptNS([[SWSchemes alloc] init]); 1481 handler->resources.set("sw://host/openCache.html", ResourceInfo { @"text/html", "foo" }); 1482 handler->resources.set("sw://host/main.html", ResourceInfo { @"text/html", serviceWorkerCacheAccessEphemeralSessionMainBytes }); 1483 handler->resources.set("sw://host/serviceworker-private-browsing-worker.js", ResourceInfo { @"application/javascript", serviceWorkerCacheAccessEphemeralSessionSWBytes }); 1484 [configuration setURLSchemeHandler:handler.get() forURLScheme:@"SW"]; 1266 ServiceWorkerTCPServer server({ 1267 { "text/html", serviceWorkerCacheAccessEphemeralSessionMainBytes }, 1268 { "application/javascript", serviceWorkerCacheAccessEphemeralSessionSWBytes }, 1269 }); 1485 1270 1486 1271 auto defaultWebView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]); 1487 NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"sw://host/openCache.html"]]; 1488 [defaultWebView synchronouslyLoadRequest:request]; 1489 1272 [defaultWebView synchronouslyLoadHTMLString:@"foo" baseURL:server.request().URL]; 1273 1490 1274 bool openedCache = false; 1491 1275 [defaultWebView evaluateJavaScript:@"self.caches.open('test');" completionHandler: [&] (id innerText, NSError *error) { … … 1494 1278 TestWebKitAPI::Util::run(&openedCache); 1495 1279 1496 _WKWebsiteDataStoreConfiguration *nonPersistentConfiguration = [[[_WKWebsiteDataStoreConfiguration alloc] initNonPersistentConfiguration] autorelease]; 1497 [nonPersistentConfiguration registerURLSchemeServiceWorkersCanHandleForTesting:@"sw"]; 1498 configuration.get().websiteDataStore = [[[WKWebsiteDataStore alloc] _initWithConfiguration:nonPersistentConfiguration] autorelease]; 1280 configuration.get().websiteDataStore = [WKWebsiteDataStore nonPersistentDataStore]; 1499 1281 1500 1282 auto messageHandler = adoptNS([[SWMessageHandlerForCacheStorage alloc] init]); … … 1502 1284 1503 1285 auto ephemeralWebView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]); 1504 request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"sw://host/main.html"]]; 1505 1506 [ephemeralWebView loadRequest:request]; 1286 1287 [ephemeralWebView loadRequest:server.request()]; 1507 1288 TestWebKitAPI::Util::run(&done); 1508 1289 done = false; … … 1564 1345 [[configuration userContentController] addScriptMessageHandler:messageHandler.get() name:@"sw"]; 1565 1346 1566 auto handler = adoptNS([[SWSchemes alloc] init]); 1567 handler->resources.set("sw://host/main.html", ResourceInfo { @"text/html", differentSessionsUseDifferentRegistrationsMainBytes }); 1568 handler->resources.set("sw://host/main2.html", ResourceInfo { @"text/html", defaultPageMainBytes }); 1569 handler->resources.set("sw://host/empty-worker.js", ResourceInfo { @"application/javascript", "" }); 1570 handler->resources.set("sw://host/private.html", ResourceInfo { @"text/html", privatePageMainBytes }); 1571 [configuration setURLSchemeHandler:handler.get() forURLScheme:@"SW"]; 1347 ServiceWorkerTCPServer server({ 1348 { "text/html", differentSessionsUseDifferentRegistrationsMainBytes }, 1349 { "application/javascript", "" }, 1350 { "text/html", defaultPageMainBytes } 1351 }, { 1352 { "text/html", privatePageMainBytes } 1353 }); 1572 1354 1573 1355 auto defaultWebView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]); 1574 NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"sw://host/main.html"]]; 1575 [defaultWebView synchronouslyLoadRequest:request]; 1576 1577 TestWebKitAPI::Util::run(&done); 1578 done = false; 1579 1580 request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"sw://host/main2.html"]]; 1581 [defaultWebView synchronouslyLoadRequest:request]; 1582 1583 TestWebKitAPI::Util::run(&done); 1584 done = false; 1585 1356 [defaultWebView synchronouslyLoadRequest:server.request()]; 1357 1358 TestWebKitAPI::Util::run(&done); 1359 done = false; 1360 1361 [defaultWebView synchronouslyLoadRequest:server.request()]; 1362 1363 TestWebKitAPI::Util::run(&done); 1364 done = false; 1365 1586 1366 configuration.get().websiteDataStore = [WKWebsiteDataStore nonPersistentDataStore]; 1587 1367 auto ephemeralWebView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]); 1588 request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"sw://host/private.html"]]; 1589 [ephemeralWebView synchronouslyLoadRequest:request]; 1368 [ephemeralWebView synchronouslyLoadRequest:server.request()]; 1590 1369 1591 1370 TestWebKitAPI::Util::run(&done); … … 1617 1396 TEST(ServiceWorkers, ServiceWorkerAndCacheStorageDefaultDirectories) 1618 1397 { 1619 ASSERT(mainBytes); 1620 ASSERT(scriptBytes); 1621 1622 [WKWebsiteDataStore _allowWebsiteDataRecordsForAllOrigins]; 1623 1624 auto* dataStore = dataStoreWithRegisteredServiceWorkerScheme(@"sw"); 1398 [WKWebsiteDataStore _allowWebsiteDataRecordsForAllOrigins]; 1625 1399 1626 1400 auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]); 1627 [configuration setWebsiteDataStore:dataStore];1628 1401 setConfigurationInjectedBundlePath(configuration.get()); 1629 1402 … … 1631 1404 [[configuration userContentController] addScriptMessageHandler:directoryPageMessageHandler.get() name:@"sw"]; 1632 1405 1633 RetainPtr<SWSchemes> handler = adoptNS([[SWSchemes alloc] init]);1634 handler->resources.set("sw://host/main.html", ResourceInfo { @"text/html", mainBytes });1635 handler->resources.set("sw://host/regularPageGrabbingCacheStorageDirectory.html", ResourceInfo { @"text/html", regularPageGrabbingCacheStorageDirectory });1636 handler->resources.set("sw://host/sw.js", ResourceInfo { @"application/javascript", scriptBytes });1637 [configuration setURLSchemeHandler:handler.get() forURLScheme:@"SW"];1406 ServiceWorkerTCPServer server({ 1407 { "text/html", mainBytes }, 1408 { "application/javascript", scriptBytes }, 1409 { "text/html", regularPageGrabbingCacheStorageDirectory }, 1410 }); 1638 1411 1639 1412 RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]); 1640 NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"sw://host/main.html"]]; 1641 1642 [webView loadRequest:request]; 1413 1414 [webView loadRequest:server.request()]; 1643 1415 TestWebKitAPI::Util::run(&done); 1644 1416 done = false; … … 1648 1420 webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]); 1649 1421 1650 request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"sw://host/regularPageGrabbingCacheStorageDirectory.html"]]; 1651 [webView loadRequest:request]; 1422 [webView loadRequest:server.request()]; 1652 1423 TestWebKitAPI::Util::run(&done); 1653 1424 done = false; … … 1663 1434 TEST(ServiceWorkers, ServiceWorkerAndCacheStorageSpecificDirectories) 1664 1435 { 1665 ASSERT(mainBytes);1666 ASSERT(scriptBytes);1667 1668 1436 [WKWebsiteDataStore defaultDataStore]; 1669 1437 [WKWebsiteDataStore _allowWebsiteDataRecordsForAllOrigins]; 1670 1438 1671 auto* dataStore = dataStoreWithRegisteredServiceWorkerScheme(@"sw");1672 1673 1439 RetainPtr<WKWebViewConfiguration> configuration = adoptNS([[WKWebViewConfiguration alloc] init]); 1674 [configuration setWebsiteDataStore:dataStore];1675 1440 1676 1441 configuration = adoptNS([[WKWebViewConfiguration alloc] init]); … … 1683 1448 [[configuration userContentController] addScriptMessageHandler:directoryPageMessageHandler.get() name:@"sw"]; 1684 1449 1685 RetainPtr<SWSchemes> handler = adoptNS([[SWSchemes alloc] init]);1686 handler->resources.set("sw://host/main.html", ResourceInfo { @"text/html", mainBytes });1687 handler->resources.set("sw://host/regularPageGrabbingCacheStorageDirectory.html", ResourceInfo { @"text/html", regularPageGrabbingCacheStorageDirectory });1688 handler->resources.set("sw://host/sw.js", ResourceInfo { @"application/javascript", scriptBytes });1689 [configuration setURLSchemeHandler:handler.get() forURLScheme:@"SW"];1450 ServiceWorkerTCPServer server({ 1451 { "text/html", mainBytes }, 1452 { "application/javascript", scriptBytes }, 1453 { "text/html", regularPageGrabbingCacheStorageDirectory }, 1454 }); 1690 1455 1691 1456 RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]); 1692 1457 1693 NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"sw://host/main.html"]]; 1694 [webView loadRequest:request]; 1458 [webView loadRequest:server.request()]; 1695 1459 TestWebKitAPI::Util::run(&done); 1696 1460 done = false; 1697 1461 while (![websiteDataStore _hasRegisteredServiceWorker]) 1698 TestWebKitAPI::Util::spinRunLoop( 0.1);1462 TestWebKitAPI::Util::spinRunLoop(); 1699 1463 1700 1464 webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]); 1701 request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"sw://host/regularPageGrabbingCacheStorageDirectory.html"]]; 1702 1703 [webView loadRequest:request]; 1465 1466 [webView loadRequest:server.request()]; 1704 1467 TestWebKitAPI::Util::run(&done); 1705 1468 done = false; … … 1730 1493 websiteDataStoreConfiguration.get()._serviceWorkerRegistrationDirectory = serviceWorkersPath; 1731 1494 websiteDataStoreConfiguration.get()._indexedDBDatabaseDirectory = idbPath; 1732 [websiteDataStoreConfiguration registerURLSchemeServiceWorkersCanHandleForTesting:@"sw"];1733 1495 1734 1496 configuration.get().websiteDataStore = [[[WKWebsiteDataStore alloc] _initWithConfiguration:websiteDataStoreConfiguration.get()] autorelease]; … … 1737 1499 [[configuration userContentController] addScriptMessageHandler:messageHandler.get() name:@"sw"]; 1738 1500 1739 RetainPtr<SWSchemes> handler = adoptNS([[SWSchemes alloc] init]);1740 handler->resources.set("sw://host/main.html", ResourceInfo { @"text/html", mainBytesForSessionIDTest });1741 handler->resources.set("sw://host/sw.js", ResourceInfo { @"application/javascript", scriptBytesForSessionIDTest });1742 [configuration setURLSchemeHandler:handler.get() forURLScheme:@"SW"];1501 ServiceWorkerTCPServer server({ 1502 { "text/html", mainBytesForSessionIDTest }, 1503 { "application/javascript", scriptBytesForSessionIDTest }, 1504 }); 1743 1505 1744 1506 expectedMessage = "PASS: activation successful"; 1745 1507 RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]); 1746 1508 1747 NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"sw://host/main.html"]]; 1748 [webView loadRequest:request]; 1509 [webView loadRequest:server.request()]; 1749 1510 1750 1511 TestWebKitAPI::Util::run(&done); … … 1758 1519 [configuration.get().websiteDataStore fetchDataRecordsOfTypes:[NSSet setWithObject:WKWebsiteDataTypeServiceWorkerRegistrations] completionHandler:^(NSArray<WKWebsiteDataRecord *> *websiteDataRecords) { 1759 1520 EXPECT_EQ(1u, [websiteDataRecords count]); 1760 EXPECT_ TRUE([websiteDataRecords[0].displayName isEqualToString:@"sw host"]);1521 EXPECT_WK_STREQ(websiteDataRecords[0].displayName, "127.0.0.1"); 1761 1522 1762 1523 done = true; … … 1778 1539 TEST(ServiceWorkers, ProcessPerSite) 1779 1540 { 1780 ASSERT(mainBytes);1781 ASSERT(scriptBytes);1782 1783 1541 [WKWebsiteDataStore _allowWebsiteDataRecordsForAllOrigins]; 1784 1542 … … 1787 1545 _WKWebsiteDataStoreConfiguration *dataStoreConfiguration = [[[_WKWebsiteDataStoreConfiguration alloc] init] autorelease]; 1788 1546 dataStoreConfiguration.serviceWorkerProcessTerminationDelayEnabled = NO; 1789 [dataStoreConfiguration registerURLSchemeServiceWorkersCanHandleForTesting:@"sw1"];1790 [dataStoreConfiguration registerURLSchemeServiceWorkersCanHandleForTesting:@"sw2"];1791 1547 1792 1548 auto dataStore = adoptNS([[WKWebsiteDataStore alloc] _initWithConfiguration:dataStoreConfiguration]); … … 1805 1561 [[configuration userContentController] addScriptMessageHandler:messageHandler.get() name:@"sw"]; 1806 1562 1807 RetainPtr<SWSchemes> handler1 = adoptNS([[SWSchemes alloc] init]); 1808 handler1->resources.set("sw1://host/main.html", ResourceInfo { @"text/html", mainBytes }); 1809 handler1->resources.set("sw1://host/sw.js", ResourceInfo { @"application/javascript", scriptBytes }); 1810 handler1->resources.set("sw1://host2/main.html", ResourceInfo { @"text/html", mainBytes }); 1811 handler1->resources.set("sw1://host2/sw.js", ResourceInfo { @"application/javascript", scriptBytes }); 1812 [configuration setURLSchemeHandler:handler1.get() forURLScheme:@"sw1"]; 1813 1814 RetainPtr<SWSchemes> handler2 = adoptNS([[SWSchemes alloc] init]); 1815 handler2->resources.set("sw2://host/main.html", ResourceInfo { @"text/html", mainBytes }); 1816 handler2->resources.set("sw2://host/sw.js", ResourceInfo { @"application/javascript", scriptBytes }); 1817 [configuration setURLSchemeHandler:handler2.get() forURLScheme:@"sw2"]; 1563 ServiceWorkerTCPServer server1({ 1564 { "text/html", mainBytes }, 1565 { "application/javascript", scriptBytes }, 1566 { "text/html", mainBytes }, 1567 { "text/html", mainBytes }, 1568 }); 1569 ServiceWorkerTCPServer server2({ 1570 { "text/html", mainBytes }, 1571 { "application/javascript", scriptBytes }, 1572 }); 1818 1573 1819 1574 WKProcessPool *processPool = configuration.get().processPool; … … 1821 1576 RetainPtr<WKWebView> webView1 = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]); 1822 1577 1823 NSURLRequest *request1 = [NSURLRequest requestWithURL:[NSURL URLWithString:@"sw1://host/main.html"]]; 1824 [webView1 loadRequest:request1]; 1578 [webView1 loadRequest:server1.request()]; 1825 1579 1826 1580 TestWebKitAPI::Util::run(&done); … … 1830 1584 1831 1585 RetainPtr<WKWebView> webView2 = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]); 1832 [webView2 loadRequest: request1];1586 [webView2 loadRequest:server1.request()]; 1833 1587 1834 1588 TestWebKitAPI::Util::run(&done); … … 1838 1592 1839 1593 RetainPtr<WKWebView> webView3 = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]); 1840 NSURLRequest *request2 = [NSURLRequest requestWithURL:[NSURL URLWithString:@"sw2://host/main.html"]]; 1841 [webView3 loadRequest:request2]; 1594 [webView3 loadRequest:server1.request()]; 1842 1595 1843 1596 TestWebKitAPI::Util::run(&done); … … 1847 1600 1848 1601 RetainPtr<WKWebView> webView4 = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]); 1849 NSURLRequest *request3 = [NSURLRequest requestWithURL:[NSURL URLWithString:@"sw1://host2/main.html"]]; 1850 [webView4 loadRequest:request3]; 1602 [webView4 loadRequest:server2.requestWithLocalhost()]; 1851 1603 1852 1604 TestWebKitAPI::Util::run(&done); … … 1875 1627 [WKWebsiteDataStore _allowWebsiteDataRecordsForAllOrigins]; 1876 1628 1877 auto* dataStore = dataStoreWithRegisteredServiceWorkerScheme(@"sw1");1878 1879 1629 // Start with a clean slate data store 1880 [ dataStoreremoveDataOfTypes:[WKWebsiteDataStore allWebsiteDataTypes] modifiedSince:[NSDate distantPast] completionHandler:^() {1630 [[WKWebsiteDataStore defaultDataStore] removeDataOfTypes:[WKWebsiteDataStore allWebsiteDataTypes] modifiedSince:[NSDate distantPast] completionHandler:^() { 1881 1631 done = true; 1882 1632 }]; … … 1885 1635 1886 1636 auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]); 1887 [configuration setWebsiteDataStore:dataStore];1888 1637 1889 1638 auto messageHandler = adoptNS([[SWMessageHandler alloc] init]); 1890 1639 [[configuration userContentController] addScriptMessageHandler:messageHandler.get() name:@"sw"]; 1891 1640 1892 auto handler1 = adoptNS([[SWSchemes alloc] init]); 1893 handler1->resources.set("sw1://host/main.html", ResourceInfo { @"text/html", mainBytes }); 1894 handler1->resources.set("sw1://host/sw.js", ResourceInfo { @"application/javascript", scriptBytes }); 1895 handler1->resources.set("sw1://host2/main.html", ResourceInfo { @"text/html", mainBytes }); 1896 handler1->resources.set("sw1://host2/sw.js", ResourceInfo { @"application/javascript", scriptBytes }); 1897 [configuration setURLSchemeHandler:handler1.get() forURLScheme:@"sw1"]; 1641 ServiceWorkerTCPServer server1({ 1642 { "text/html", mainBytes }, 1643 { "application/javascript", scriptBytes }, 1644 }); 1645 ServiceWorkerTCPServer server2({ 1646 { "text/html", mainBytes }, 1647 { "application/javascript", scriptBytes }, 1648 }); 1898 1649 1899 1650 auto *processPool = configuration.get().processPool; 1900 1651 1901 1652 auto webView1 = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]); 1902 NSURLRequest *request1 = [NSURLRequest requestWithURL:[NSURL URLWithString:@"sw1://host/main.html"]];1903 1653 1904 1654 auto webView2 = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]); 1905 NSURLRequest *request2 = [NSURLRequest requestWithURL:[NSURL URLWithString:@"sw1://host2/main.html"]]; 1906 1907 [webView1 loadRequest:request1]; 1908 [webView2 loadRequest:request2]; 1655 1656 [webView1 loadRequest:server1.request()]; 1657 [webView2 loadRequest:server2.requestWithLocalhost()]; 1909 1658 1910 1659 waitUntilServiceWorkerProcessCount(processPool, 2); … … 1915 1664 [WKWebsiteDataStore _allowWebsiteDataRecordsForAllOrigins]; 1916 1665 1917 auto* dataStore = dataStoreWithRegisteredServiceWorkerScheme(@"sw");1918 1919 1666 // Start with a clean slate data store 1920 [ dataStoreremoveDataOfTypes:[WKWebsiteDataStore allWebsiteDataTypes] modifiedSince:[NSDate distantPast] completionHandler:^() {1667 [[WKWebsiteDataStore defaultDataStore] removeDataOfTypes:[WKWebsiteDataStore allWebsiteDataTypes] modifiedSince:[NSDate distantPast] completionHandler:^() { 1921 1668 done = true; 1922 1669 }]; … … 1925 1672 1926 1673 auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]); 1927 [configuration setWebsiteDataStore:dataStore];1928 1674 1929 1675 auto messageHandler = adoptNS([[SWMessageHandler alloc] init]); 1930 1676 [[configuration userContentController] addScriptMessageHandler:messageHandler.get() name:@"sw"]; 1931 1677 1932 auto handler1 = adoptNS([[SWSchemes alloc] init]); 1933 handler1->resources.set("sw://host/main.html", ResourceInfo { @"text/html", mainBytes }); 1934 handler1->resources.set("sw://host/sw.js", ResourceInfo { @"application/javascript", scriptBytes }); 1935 handler1->resources.set("sw://host2/main.html", ResourceInfo { @"text/html", mainBytes }); 1936 handler1->resources.set("sw://host2/sw.js", ResourceInfo { @"application/javascript", scriptBytes }); 1937 [configuration setURLSchemeHandler:handler1.get() forURLScheme:@"sw"]; 1678 ServiceWorkerTCPServer server({ 1679 { "text/html", mainBytes }, 1680 { "application/javascript", scriptBytes }, 1681 }); 1938 1682 1939 1683 auto *processPool = configuration.get().processPool; … … 1941 1685 1942 1686 auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]); 1943 NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"sw://host/main.html"]]; 1944 1945 [webView loadRequest:request]; 1687 1688 [webView loadRequest:server.request()]; 1946 1689 1947 1690 waitUntilServiceWorkerProcessCount(processPool, 1); … … 1960 1703 TEST(ServiceWorkers, ThrottleCrash) 1961 1704 { 1962 ASSERT(mainBytes); 1963 ASSERT(scriptBytes); 1964 1965 [WKWebsiteDataStore _allowWebsiteDataRecordsForAllOrigins]; 1966 1967 auto* dataStore = dataStoreWithRegisteredServiceWorkerScheme(@"sw1"); 1705 [WKWebsiteDataStore _allowWebsiteDataRecordsForAllOrigins]; 1968 1706 1969 1707 // Start with a clean slate data store 1970 [ dataStoreremoveDataOfTypes:[WKWebsiteDataStore allWebsiteDataTypes] modifiedSince:[NSDate distantPast] completionHandler:^() {1708 [[WKWebsiteDataStore defaultDataStore] removeDataOfTypes:[WKWebsiteDataStore allWebsiteDataTypes] modifiedSince:[NSDate distantPast] completionHandler:^() { 1971 1709 done = true; 1972 1710 }]; … … 1976 1714 auto messageHandler = adoptNS([[SWMessageHandler alloc] init]); 1977 1715 1978 auto handler = adoptNS([[SWSchemes alloc] init]); 1979 handler->resources.set("sw1://host/main.html", ResourceInfo { @"text/html", mainBytes }); 1980 handler->resources.set("sw1://host/sw.js", ResourceInfo { @"application/javascript", scriptBytes }); 1716 ServiceWorkerTCPServer server({ 1717 { "text/html", mainBytes }, 1718 { "application/javascript", scriptBytes }, 1719 { "text/html", mainBytes }, 1720 }); 1981 1721 1982 1722 auto navigationDelegate = adoptNS([[TestNavigationDelegate alloc] init]); … … 1986 1726 1987 1727 auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]); 1988 [configuration setWebsiteDataStore:dataStore];1989 1728 #if PLATFORM(MAC) 1990 1729 [[configuration preferences] _setAppNapEnabled:YES]; 1991 1730 #endif 1992 1731 [[configuration userContentController] addScriptMessageHandler:messageHandler.get() name:@"sw"]; 1993 [configuration setURLSchemeHandler:handler.get() forURLScheme:@"sw1"];1994 1732 1995 1733 auto *processPool = configuration.get().processPool; … … 2004 1742 #endif 2005 1743 2006 auto *request1 = [NSURLRequest requestWithURL:[NSURL URLWithString:@"sw1://host/main.html"]]; 2007 [webView1 loadRequest:request1]; 1744 [webView1 loadRequest:server.request()]; 2008 1745 2009 1746 didFinishNavigation = false; 2010 1747 TestWebKitAPI::Util::run(&didFinishNavigation); 1748 TestWebKitAPI::Util::run(&done); 1749 done = false; 2011 1750 2012 1751 auto webView2Configuration = adoptNS([[WKWebViewConfiguration alloc] init]); … … 2015 1754 #endif 2016 1755 [webView2Configuration setProcessPool:processPool]; 2017 [webView2Configuration setWebsiteDataStore:dataStore];2018 1756 [[webView2Configuration userContentController] addScriptMessageHandler:messageHandler.get() name:@"sw"]; 2019 [webView2Configuration setURLSchemeHandler:handler.get() forURLScheme:@"sw1"];2020 1757 webView2Configuration.get()._relatedWebView = webView1.get(); 2021 1758 … … 2023 1760 [webView2 setNavigationDelegate:navigationDelegate.get()]; 2024 1761 2025 [webView2 loadRequest: request1];1762 [webView2 loadRequest:server.request()]; 2026 1763 2027 1764 didFinishNavigation = false; … … 2031 1768 TEST(ServiceWorkers, LoadData) 2032 1769 { 2033 ASSERT(mainBytes); 2034 ASSERT(scriptBytes); 2035 2036 [WKWebsiteDataStore _allowWebsiteDataRecordsForAllOrigins]; 2037 2038 auto* dataStore = dataStoreWithRegisteredServiceWorkerScheme(@"sw"); 1770 [WKWebsiteDataStore _allowWebsiteDataRecordsForAllOrigins]; 2039 1771 2040 1772 // Start with a clean slate data store 2041 [ dataStoreremoveDataOfTypes:[WKWebsiteDataStore allWebsiteDataTypes] modifiedSince:[NSDate distantPast] completionHandler:^() {1773 [[WKWebsiteDataStore defaultDataStore] removeDataOfTypes:[WKWebsiteDataStore allWebsiteDataTypes] modifiedSince:[NSDate distantPast] completionHandler:^() { 2042 1774 done = true; 2043 1775 }]; … … 2046 1778 2047 1779 RetainPtr<WKWebViewConfiguration> configuration = adoptNS([[WKWebViewConfiguration alloc] init]); 2048 [configuration setWebsiteDataStore:dataStore];2049 1780 2050 1781 RetainPtr<SWMessageHandler> messageHandler = adoptNS([[SWMessageHandler alloc] init]); 2051 1782 [[configuration userContentController] addScriptMessageHandler:messageHandler.get() name:@"sw"]; 2052 1783 2053 RetainPtr<SWSchemes> handler = adoptNS([[SWSchemes alloc] init]);2054 handler->resources.set("sw://host/main.html", ResourceInfo { @"text/html", mainBytes });2055 handler->resources.set("sw://host/sw.js", ResourceInfo { @"application/javascript", scriptBytes });2056 [configuration setURLSchemeHandler:handler.get() forURLScheme:@"SW"];1784 ServiceWorkerTCPServer server({ 1785 { "text/html", mainBytes }, 1786 { "application/javascript", scriptBytes }, 1787 }); 2057 1788 2058 1789 RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]); … … 2065 1796 2066 1797 // Normal load to get SW registered. 2067 NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"sw://host/main.html"]]; 2068 [webView loadRequest:request]; 1798 [webView loadRequest:server.request()]; 2069 1799 2070 1800 TestWebKitAPI::Util::run(&done); … … 2073 1803 // Now try a data load. 2074 1804 NSData *data = [NSData dataWithBytes:mainBytes length:strlen(mainBytes)]; 2075 [webView loadData:data MIMEType:@"text/html" characterEncodingName:@"UTF-8" baseURL: [NSURL URLWithString:@"sw://host/main.html"]];1805 [webView loadData:data MIMEType:@"text/html" characterEncodingName:@"UTF-8" baseURL:server.request().URL]; 2076 1806 2077 1807 TestWebKitAPI::Util::run(&done); … … 2081 1811 TEST(ServiceWorkers, RestoreFromDiskNonDefaultStore) 2082 1812 { 2083 ASSERT(mainRegisteringWorkerBytes);2084 ASSERT(scriptBytes);2085 ASSERT(mainRegisteringAlreadyExistingWorkerBytes);2086 2087 1813 [WKWebsiteDataStore _allowWebsiteDataRecordsForAllOrigins]; 2088 1814 … … 2096 1822 RetainPtr<WKProcessPool> protectedProcessPool; 2097 1823 1824 ServiceWorkerTCPServer server({ 1825 { "text/html", mainRegisteringWorkerBytes }, 1826 { "application/javascript", scriptBytes }, 1827 }, { 1828 { "text/html", mainRegisteringAlreadyExistingWorkerBytes }, 1829 { "application/javascript", scriptBytes }, 1830 }); 1831 2098 1832 @autoreleasepool { 2099 1833 auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]); … … 2101 1835 auto websiteDataStoreConfiguration = adoptNS([[_WKWebsiteDataStoreConfiguration alloc] init]); 2102 1836 websiteDataStoreConfiguration.get()._serviceWorkerRegistrationDirectory = swDBPath; 2103 [websiteDataStoreConfiguration registerURLSchemeServiceWorkersCanHandleForTesting:@"sw"];2104 1837 auto nonDefaultDataStore = adoptNS([[WKWebsiteDataStore alloc] _initWithConfiguration:websiteDataStoreConfiguration.get()]); 2105 1838 configuration.get().websiteDataStore = nonDefaultDataStore.get(); … … 2108 1841 [[configuration userContentController] addScriptMessageHandler:messageHandler.get() name:@"sw"]; 2109 1842 2110 auto handler = adoptNS([[SWSchemes alloc] init]);2111 handler->resources.set("sw://host/main.html", ResourceInfo { @"text/html", mainRegisteringWorkerBytes });2112 handler->resources.set("sw://host/sw.js", ResourceInfo { @"application/javascript", scriptBytes });2113 [configuration setURLSchemeHandler:handler.get() forURLScheme:@"SW"];2114 2115 1843 auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]); 2116 1844 protectedProcessPool = webView.get().configuration.processPool; 2117 1845 2118 [webView loadRequest: [NSURLRequest requestWithURL:[NSURL URLWithString:@"sw://host/main.html"]]];1846 [webView loadRequest:server.request()]; 2119 1847 2120 1848 TestWebKitAPI::Util::run(&done); … … 2129 1857 auto websiteDataStoreConfiguration = adoptNS([[_WKWebsiteDataStoreConfiguration alloc] init]); 2130 1858 websiteDataStoreConfiguration.get()._serviceWorkerRegistrationDirectory = swDBPath; 2131 [websiteDataStoreConfiguration registerURLSchemeServiceWorkersCanHandleForTesting:@"sw"];2132 1859 auto nonDefaultDataStore = adoptNS([[WKWebsiteDataStore alloc] _initWithConfiguration:websiteDataStoreConfiguration.get()]); 2133 1860 configuration.get().websiteDataStore = nonDefaultDataStore.get(); … … 2136 1863 [[configuration userContentController] addScriptMessageHandler:messageHandler.get() name:@"sw"]; 2137 1864 2138 auto handler = adoptNS([[SWSchemes alloc] init]);2139 handler->resources.set("sw://host/main.html", ResourceInfo { @"text/html", mainRegisteringAlreadyExistingWorkerBytes });2140 handler->resources.set("sw://host/sw.js", ResourceInfo { @"application/javascript", scriptBytes });2141 [configuration setURLSchemeHandler:handler.get() forURLScheme:@"SW"];2142 2143 1865 auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]); 2144 1866 2145 [webView loadRequest: [NSURLRequest requestWithURL:[NSURL URLWithString:@"sw://host/main.html"]]];1867 [webView loadRequest:server.request()]; 2146 1868 2147 1869 TestWebKitAPI::Util::run(&done); … … 2154 1876 [WKWebsiteDataStore _allowWebsiteDataRecordsForAllOrigins]; 2155 1877 2156 auto* dataStore = dataStoreWithRegisteredServiceWorkerScheme(@"sw");2157 2158 1878 // Start with a clean slate data store 2159 [ dataStoreremoveDataOfTypes:[WKWebsiteDataStore allWebsiteDataTypes] modifiedSince:[NSDate distantPast] completionHandler:^() {1879 [[WKWebsiteDataStore defaultDataStore] removeDataOfTypes:[WKWebsiteDataStore allWebsiteDataTypes] modifiedSince:[NSDate distantPast] completionHandler:^() { 2160 1880 done = true; 2161 1881 }]; … … 2164 1884 2165 1885 RetainPtr<WKWebViewConfiguration> configuration = adoptNS([[WKWebViewConfiguration alloc] init]); 2166 [configuration setWebsiteDataStore:dataStore];2167 1886 2168 1887 RetainPtr<SWMessageHandler> messageHandler = adoptNS([[SWMessageHandler alloc] init]); 2169 1888 [[configuration userContentController] addScriptMessageHandler:messageHandler.get() name:@"sw"]; 2170 1889 2171 RetainPtr<SWSchemes> handler = adoptNS([[SWSchemes alloc] init]); 2172 handler->resources.set("sw://host/main.html", ResourceInfo { @"text/html", mainBytes }); 2173 handler->resources.set("sw://host/sw.js", ResourceInfo { @"application/javascript", scriptBytes }); 2174 [configuration setURLSchemeHandler:handler.get() forURLScheme:@"SW"]; 1890 ServiceWorkerTCPServer server({ 1891 { "text/html", mainBytes }, 1892 { "application/javascript", scriptBytes }, 1893 { "text/html", mainBytes }, 1894 }); 2175 1895 2176 1896 RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]); … … 2183 1903 2184 1904 // Normal load to get SW registered. 2185 NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"sw://host/main.html"]]; 2186 [webView loadRequest:request]; 1905 [webView loadRequest:server.request()]; 2187 1906 2188 1907 TestWebKitAPI::Util::run(&done); … … 2203 1922 [ webView.get().configuration.processPool _sendNetworkProcessDidResume]; 2204 1923 2205 [webView loadRequest: request];1924 [webView loadRequest:server.request()]; 2206 1925 TestWebKitAPI::Util::run(&done); 2207 1926 done = false; … … 2241 1960 [WKWebsiteDataStore _allowWebsiteDataRecordsForAllOrigins]; 2242 1961 2243 auto* dataStore = dataStoreWithRegisteredServiceWorkerScheme(@"sw1");2244 2245 1962 // Start with a clean slate data store 2246 [ dataStoreremoveDataOfTypes:[WKWebsiteDataStore allWebsiteDataTypes] modifiedSince:[NSDate distantPast] completionHandler:^() {1963 [[WKWebsiteDataStore defaultDataStore] removeDataOfTypes:[WKWebsiteDataStore allWebsiteDataTypes] modifiedSince:[NSDate distantPast] completionHandler:^() { 2247 1964 done = true; 2248 1965 }]; … … 2251 1968 2252 1969 auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]); 2253 [configuration setWebsiteDataStore:dataStore];2254 1970 2255 1971 auto messageHandler = adoptNS([[SWMessageHandler alloc] init]); 2256 1972 [[configuration userContentController] addScriptMessageHandler:messageHandler.get() name:@"sw"]; 2257 1973 2258 auto handler1 = adoptNS([[SWSchemes alloc] init]); 2259 handler1->resources.set("sw1://host/main.html", ResourceInfo { @"text/html", mainBytes }); 2260 handler1->resources.set("sw1://host/sw.js", ResourceInfo { @"application/javascript", scriptBytes }); 2261 handler1->resources.set("sw1://host2/main.html", ResourceInfo { @"text/html", mainBytes }); 2262 handler1->resources.set("sw1://host2/sw.js", ResourceInfo { @"application/javascript", scriptBytes }); 2263 [configuration setURLSchemeHandler:handler1.get() forURLScheme:@"sw1"]; 1974 ServiceWorkerTCPServer server1({ 1975 { "text/html", mainBytes }, 1976 { "application/javascript", scriptBytes }, 1977 }); 2264 1978 2265 1979 WKProcessPool *processPool = configuration.get().processPool; 2266 1980 2267 NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"sw1://host/main.html"]];2268 2269 configuration.get().websiteDataStore = dataStore;2270 2271 1981 auto webView1 = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]); 2272 [webView1 loadRequest: request];1982 [webView1 loadRequest:server1.request()]; 2273 1983 TestWebKitAPI::Util::run(&done); 2274 1984 done = false; … … 2276 1986 EXPECT_EQ(1U, processPool._serviceWorkerProcessCount); 2277 1987 2278 _WKWebsiteDataStoreConfiguration *nonPersistentConfiguration = [[[_WKWebsiteDataStoreConfiguration alloc] initNonPersistentConfiguration] autorelease]; 2279 [nonPersistentConfiguration registerURLSchemeServiceWorkersCanHandleForTesting:@"sw1"]; 2280 configuration.get().websiteDataStore = [[[WKWebsiteDataStore alloc] _initWithConfiguration:nonPersistentConfiguration] autorelease]; 1988 configuration.get().websiteDataStore = [WKWebsiteDataStore nonPersistentDataStore]; 1989 1990 ServiceWorkerTCPServer server2({ 1991 { "text/html", mainBytes }, 1992 { "application/javascript", scriptBytes }, 1993 }); 2281 1994 2282 1995 auto webView2 = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]); 2283 [webView2 loadRequest: request];1996 [webView2 loadRequest:server2.requestWithLocalhost()]; 2284 1997 TestWebKitAPI::Util::run(&done); 2285 1998 done = false; -
trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/StorageQuota.mm
r250728 r251384 28 28 29 29 #import "PlatformUtilities.h" 30 #import "ServiceWorkerTCPServer.h" 30 31 #import "Test.h" 31 32 #import "TestNavigationDelegate.h" … … 110 111 }; 111 112 112 @interface StorageSchemes : NSObject <WKURLSchemeHandler> {113 @public114 HashMap<String, ResourceInfo> resources;115 }116 @end117 118 @implementation StorageSchemes {119 }120 121 - (void)webView:(WKWebView *)webView startURLSchemeTask:(id <WKURLSchemeTask>)task122 {123 auto entry = resources.find([task.request.URL absoluteString]);124 if (entry == resources.end()) {125 NSLog(@"Did not find resource entry for URL %@", task.request.URL);126 return;127 }128 129 RetainPtr<NSURLResponse> response = adoptNS([[NSURLResponse alloc] initWithURL:task.request.URL MIMEType:entry->value.mimeType.get() expectedContentLength:1 textEncodingName:nil]);130 [task didReceiveResponse:response.get()];131 132 [task didReceiveData:[NSData dataWithBytesNoCopy:(void*)entry->value.data length:strlen(entry->value.data) freeWhenDone:NO]];133 [task didFinish];134 }135 136 - (void)webView:(WKWebView *)webView stopURLSchemeTask:(id <WKURLSchemeTask>)task137 {138 }139 140 @end141 142 113 static bool receivedMessage; 143 114 … … 228 199 _WKWebsiteDataStoreConfiguration *storeConfiguration = [[[_WKWebsiteDataStoreConfiguration alloc] init] autorelease]; 229 200 storeConfiguration.perOriginStorageQuota = 1024 * 400; 230 [storeConfiguration registerURLSchemeServiceWorkersCanHandleForTesting:@"qt1"];231 [storeConfiguration registerURLSchemeServiceWorkersCanHandleForTesting:@"qt2"];232 201 WKWebsiteDataStore *dataStore = [[[WKWebsiteDataStore alloc] _initWithConfiguration:storeConfiguration] autorelease]; 233 202 [dataStore removeDataOfTypes:[WKWebsiteDataStore allWebsiteDataTypes] modifiedSince:[NSDate distantPast] completionHandler:^() { … … 242 211 [[configuration userContentController] addScriptMessageHandler:messageHandler.get() name:@"qt"]; 243 212 244 auto handler1 = adoptNS([[StorageSchemes alloc] init]); 245 handler1->resources.set("qt1://test1.html", ResourceInfo { @"text/html", TestBytes }); 246 [configuration setURLSchemeHandler:handler1.get() forURLScheme:@"QT1"]; 247 248 auto handler2 = adoptNS([[StorageSchemes alloc] init]); 249 handler2->resources.set("qt2://test2.html", ResourceInfo { @"text/html", TestBytes }); 250 [configuration setURLSchemeHandler:handler2.get() forURLScheme:@"QT2"]; 213 ServiceWorkerTCPServer server({ 214 { "text/html", TestBytes } 215 }, { 216 { "text/html", TestBytes } 217 }); 251 218 252 219 auto webView1 = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get() addToWindow:YES]); … … 256 223 257 224 receivedQuotaDelegateCalled = false; 258 [webView1 loadRequest: [NSURLRequest requestWithURL:[NSURL URLWithString:@"qt1://test1.html"]]];225 [webView1 loadRequest:server.request()]; 259 226 Util::run(&receivedQuotaDelegateCalled); 260 227 … … 265 232 266 233 receivedMessage = false; 267 [webView2 loadRequest: [NSURLRequest requestWithURL:[NSURL URLWithString:@"qt2://test2.html"]]];234 [webView2 loadRequest:server.requestWithLocalhost()]; 268 235 [messageHandler setExpectedMessage: @"start"]; 269 236 Util::run(&receivedMessage); … … 290 257 done = false; 291 258 _WKWebsiteDataStoreConfiguration *storeConfiguration = [[[_WKWebsiteDataStoreConfiguration alloc] init] autorelease]; 292 storeConfiguration.perOriginStorageQuota = 1024 * 400;293 [storeConfiguration registerURLSchemeServiceWorkersCanHandleForTesting:@"qt"];294 WKWebsiteDataStore *dataStore = [[[WKWebsiteDataStore alloc] _initWithConfiguration:storeConfiguration] autorelease];295 [dataStore removeDataOfTypes:[WKWebsiteDataStore allWebsiteDataTypes] modifiedSince:[NSDate distantPast] completionHandler:^() {296 done = true;297 }];298 TestWebKitAPI::Util::run(&done);299 300 auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);301 [configuration setWebsiteDataStore:dataStore];302 303 auto messageHandler = adoptNS([[QuotaMessageHandler alloc] init]);304 [[configuration userContentController] addScriptMessageHandler:messageHandler.get() name:@"qt"];305 306 auto handler = adoptNS([[StorageSchemes alloc] init]);307 handler->resources.set("qt://test1.html", ResourceInfo { @"text/html", TestBytes });308 [configuration setURLSchemeHandler:handler.get() forURLScheme:@"QT"];309 310 auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get() addToWindow:YES]);311 auto delegate = adoptNS([[QuotaDelegate alloc] init]);312 [webView setUIDelegate:delegate.get()];313 setVisible(webView.get());314 315 receivedQuotaDelegateCalled = false;316 [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"qt://test1.html"]]];317 Util::run(&receivedQuotaDelegateCalled);318 319 [delegate denyQuota];320 321 [messageHandler setExpectedMessage: @"fail"];322 receivedMessage = false;323 Util::run(&receivedMessage);324 325 receivedQuotaDelegateCalled = false;326 [webView reload];327 Util::run(&receivedQuotaDelegateCalled);328 329 [delegate grantQuota];330 331 [messageHandler setExpectedMessage: @"pass"];332 receivedMessage = false;333 Util::run(&receivedMessage);334 }335 336 TEST(WebKit, QuotaDelegateNavigateFragment)337 {338 done = false;339 _WKWebsiteDataStoreConfiguration *storeConfiguration = [[[_WKWebsiteDataStoreConfiguration alloc] init] autorelease];340 [storeConfiguration registerURLSchemeServiceWorkersCanHandleForTesting:@"qt"];341 259 storeConfiguration.perOriginStorageQuota = 1024 * 400; 342 260 WKWebsiteDataStore *dataStore = [[[WKWebsiteDataStore alloc] _initWithConfiguration:storeConfiguration] autorelease]; … … 345 263 }]; 346 264 TestWebKitAPI::Util::run(&done); 347 265 348 266 auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]); 349 267 [configuration setWebsiteDataStore:dataStore]; 350 268 351 269 auto messageHandler = adoptNS([[QuotaMessageHandler alloc] init]); 352 270 [[configuration userContentController] addScriptMessageHandler:messageHandler.get() name:@"qt"]; 353 354 auto handler = adoptNS([[StorageSchemes alloc] init]); 355 handler->resources.set("qt://test1.html", ResourceInfo { @"text/html", TestBytes }); 356 [configuration setURLSchemeHandler:handler.get() forURLScheme:@"QT"]; 357 271 272 ServiceWorkerTCPServer server({ 273 { "text/html", TestBytes }, 274 { "text/html", TestBytes } 275 }); 276 358 277 auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get() addToWindow:YES]); 359 278 auto delegate = adoptNS([[QuotaDelegate alloc] init]); … … 362 281 363 282 receivedQuotaDelegateCalled = false; 364 [webView loadRequest: [NSURLRequest requestWithURL:[NSURL URLWithString:@"qt://test1.html"]]];283 [webView loadRequest:server.request()]; 365 284 Util::run(&receivedQuotaDelegateCalled); 366 285 … … 372 291 373 292 receivedQuotaDelegateCalled = false; 374 [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"qt://test1.html#fragment"]]]; 375 [webView stringByEvaluatingJavaScript:@"doTestAgain()"]; 376 377 [messageHandler setExpectedMessage: @"start"]; 378 receivedMessage = false; 379 Util::run(&receivedMessage); 380 381 [messageHandler setExpectedMessage: @"fail"]; 382 receivedMessage = false; 383 Util::run(&receivedMessage); 384 385 EXPECT_FALSE(receivedQuotaDelegateCalled); 386 } 387 388 TEST(WebKit, DefaultQuota) 293 [webView reload]; 294 Util::run(&receivedQuotaDelegateCalled); 295 296 [delegate grantQuota]; 297 298 [messageHandler setExpectedMessage: @"pass"]; 299 receivedMessage = false; 300 Util::run(&receivedMessage); 301 } 302 303 TEST(WebKit, QuotaDelegateNavigateFragment) 389 304 { 390 305 done = false; 391 306 _WKWebsiteDataStoreConfiguration *storeConfiguration = [[[_WKWebsiteDataStoreConfiguration alloc] init] autorelease]; 392 [storeConfiguration registerURLSchemeServiceWorkersCanHandleForTesting:@"qt"];307 storeConfiguration.perOriginStorageQuota = 1024 * 400; 393 308 WKWebsiteDataStore *dataStore = [[[WKWebsiteDataStore alloc] _initWithConfiguration:storeConfiguration] autorelease]; 394 395 309 [dataStore removeDataOfTypes:[WKWebsiteDataStore allWebsiteDataTypes] modifiedSince:[NSDate distantPast] completionHandler:^() { 396 310 done = true; … … 404 318 [[configuration userContentController] addScriptMessageHandler:messageHandler.get() name:@"qt"]; 405 319 406 auto handler = adoptNS([[StorageSchemes alloc] init]); 407 handler->resources.set("qt://test1.html", ResourceInfo { @"text/html", TestUrlBytes }); 408 [configuration setURLSchemeHandler:handler.get() forURLScheme:@"QT"]; 320 ServiceWorkerTCPServer server({ 321 { "text/html", TestBytes } 322 }); 323 324 auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get() addToWindow:YES]); 325 auto delegate = adoptNS([[QuotaDelegate alloc] init]); 326 [webView setUIDelegate:delegate.get()]; 327 setVisible(webView.get()); 328 329 receivedQuotaDelegateCalled = false; 330 [webView loadRequest:server.request()]; 331 Util::run(&receivedQuotaDelegateCalled); 332 333 [delegate denyQuota]; 334 335 [messageHandler setExpectedMessage: @"fail"]; 336 receivedMessage = false; 337 Util::run(&receivedMessage); 338 339 receivedQuotaDelegateCalled = false; 340 [webView loadRequest:server.requestWithFragment()]; 341 [webView stringByEvaluatingJavaScript:@"doTestAgain()"]; 342 343 [messageHandler setExpectedMessage: @"start"]; 344 receivedMessage = false; 345 Util::run(&receivedMessage); 346 347 [messageHandler setExpectedMessage: @"fail"]; 348 receivedMessage = false; 349 Util::run(&receivedMessage); 350 351 EXPECT_FALSE(receivedQuotaDelegateCalled); 352 } 353 354 TEST(WebKit, DefaultQuota) 355 { 356 done = false; 357 _WKWebsiteDataStoreConfiguration *storeConfiguration = [[[_WKWebsiteDataStoreConfiguration alloc] init] autorelease]; 358 WKWebsiteDataStore *dataStore = [[[WKWebsiteDataStore alloc] _initWithConfiguration:storeConfiguration] autorelease]; 359 360 [dataStore removeDataOfTypes:[WKWebsiteDataStore allWebsiteDataTypes] modifiedSince:[NSDate distantPast] completionHandler:^() { 361 done = true; 362 }]; 363 TestWebKitAPI::Util::run(&done); 364 365 auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]); 366 [configuration setWebsiteDataStore:dataStore]; 367 368 auto messageHandler = adoptNS([[QuotaMessageHandler alloc] init]); 369 [[configuration userContentController] addScriptMessageHandler:messageHandler.get() name:@"qt"]; 370 371 ServiceWorkerTCPServer server({ 372 { "text/html", TestUrlBytes } 373 }); 409 374 410 375 auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get() addToWindow:YES]); … … 420 385 421 386 didFinishNavigation = false; 422 [webView loadRequest: [NSURLRequest requestWithURL:[NSURL URLWithString:@"qt://test1.html"]]];387 [webView loadRequest:server.request()]; 423 388 Util::run(&didFinishNavigation); 424 389
Note:
See TracChangeset
for help on using the changeset viewer.