Diff
Modified: trunk/Tools/ChangeLog (283461 => 283462)
--- trunk/Tools/ChangeLog 2021-10-03 04:04:30 UTC (rev 283461)
+++ trunk/Tools/ChangeLog 2021-10-03 04:41:47 UTC (rev 283462)
@@ -1,3 +1,31 @@
+2021-10-02 Alex Christensen <[email protected]>
+
+ Migrate some tests from TCPServer to HTTPServer
+ https://bugs.webkit.org/show_bug.cgi?id=231130
+
+ Reviewed by Chris Dumez.
+
+ The former runs logic on a non-main thread and has a destructor that waits for all threads to join,
+ which often causes timeouts in tests. This is progress towards removing TCPServer, which has been
+ replaced by HTTPServer.
+
+ * TestWebKitAPI/Tests/WebKitCocoa/DisplayName.mm:
+ * TestWebKitAPI/Tests/WebKitCocoa/PDFLinkReferrer.mm:
+ (TEST):
+ * TestWebKitAPI/Tests/WebKitCocoa/ResourceLoadDelegate.mm:
+ * TestWebKitAPI/Tests/WebKitCocoa/ServiceWorkerBasic.mm:
+ * TestWebKitAPI/Tests/WebKitCocoa/UploadDirectory.mm:
+ (TEST):
+ * TestWebKitAPI/Tests/WebKitCocoa/WKNavigationResponse.mm:
+ (TEST):
+ * TestWebKitAPI/Tests/WebKitCocoa/WKWebViewEvaluateJavaScript.mm:
+ (TEST):
+ * TestWebKitAPI/Tests/WebKitCocoa/WKWebsiteDatastore.mm:
+ (TestWebKitAPI::TEST):
+ * TestWebKitAPI/Tests/WebKitCocoa/WebsiteDataStoreCustomPaths.mm:
+ (TEST):
+ (respondToRangeRequests):
+
2021-10-01 Chris Dumez <[email protected]>
Drop support for macOS < 10.15
Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/DisplayName.mm (283461 => 283462)
--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/DisplayName.mm 2021-10-03 04:04:30 UTC (rev 283461)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/DisplayName.mm 2021-10-03 04:41:47 UTC (rev 283462)
@@ -26,7 +26,6 @@
#import "config.h"
#import "PlatformUtilities.h"
-#import "TCPServer.h"
#import "Test.h"
#import "TestWKWebView.h"
#import <WebKit/_WKWebsiteDataStoreConfiguration.h>
Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/PDFLinkReferrer.mm (283461 => 283462)
--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/PDFLinkReferrer.mm 2021-10-03 04:04:30 UTC (rev 283461)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/PDFLinkReferrer.mm 2021-10-03 04:41:47 UTC (rev 283462)
@@ -27,7 +27,7 @@
#if PLATFORM(MAC)
-#import "TCPServer.h"
+#import "HTTPServer.h"
#import "Test.h"
#import "TestNavigationDelegate.h"
#import "TestWKWebView.h"
@@ -34,8 +34,6 @@
#import "Utilities.h"
#import <WebKit/WKFoundation.h>
-// FIXME: Re-enable this test once rdar://68639688 is resolved.
-#if __MAC_OS_X_VERSION_MIN_REQUIRED < 110000
static size_t putPDFBytesCallback(void* info, void* buffer, size_t count)
{
[(NSMutableData *)info appendBytes:buffer length:count];
@@ -75,23 +73,20 @@
TEST(WebKit, PDFLinkReferrer)
{
using namespace TestWebKitAPI;
- TCPServer server([] (int socket) {
- // This assumes all the data from the HTTP request is available to be read at once,
- // which is probably an okay assumption.
- auto requestBytes = TCPServer::read(socket);
-
- // Look for a referer header.
- const auto* currentLine = reinterpret_cast<const char*>(requestBytes.data());
- while (currentLine) {
- EXPECT_NE(strncasecmp(currentLine, "referer:", 8), 0);
- const char* nextLine = strchr(currentLine, '\n');
- currentLine = nextLine ? nextLine + 1 : 0;
- }
-
- const char* responseHeader =
- "HTTP/1.1 200 OK\r\n"
- "Content-Length: 0\r\n\r\n";
- TCPServer::write(socket, responseHeader, strlen(responseHeader));
+ HTTPServer server([] (Connection connection) {
+ connection.receiveHTTPRequest([=](Vector<char>&& requestBytes) {
+ // Look for a referer header.
+ const auto* currentLine = reinterpret_cast<const char*>(requestBytes.data());
+ while (currentLine) {
+ EXPECT_NE(strncasecmp(currentLine, "referer:", 8), 0);
+ const char* nextLine = strchr(currentLine, '\n');
+ currentLine = nextLine ? nextLine + 1 : 0;
+ }
+ const char* responseHeader =
+ "HTTP/1.1 200 OK\r\n"
+ "Content-Length: 0\r\n\r\n";
+ connection.send(responseHeader);
+ });
});
RetainPtr<TestWKWebView> webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]);
@@ -114,6 +109,5 @@
[navigationDelegate waitForDidFinishNavigation];
}
-#endif //__MAC_OS_X_VERSION_MIN_REQUIRED < 110000
#endif // PLATFORM(MAC)
Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ResourceLoadDelegate.mm (283461 => 283462)
--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ResourceLoadDelegate.mm 2021-10-03 04:04:30 UTC (rev 283461)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ResourceLoadDelegate.mm 2021-10-03 04:41:47 UTC (rev 283462)
@@ -27,7 +27,6 @@
#import "HTTPServer.h"
#import "PlatformUtilities.h"
-#import "TCPServer.h"
#import "TestNavigationDelegate.h"
#import "TestUIDelegate.h"
#import "TestWKWebView.h"
Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ServiceWorkerBasic.mm (283461 => 283462)
--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ServiceWorkerBasic.mm 2021-10-03 04:04:30 UTC (rev 283461)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ServiceWorkerBasic.mm 2021-10-03 04:41:47 UTC (rev 283462)
@@ -2150,22 +2150,19 @@
[[configuration userContentController] addContentRuleList:contentRuleList.get()];
using namespace TestWebKitAPI;
- TCPServer server([] (int socket) {
- auto respond = [socket] (const char* body, const char* mimeType) {
- NSString *format = @"HTTP/1.1 200 OK\r\n"
- "Content-Type: %s\r\n"
- "Content-Length: %d\r\n\r\n"
- "%s";
- NSString *response = [NSString stringWithFormat:format, mimeType, strlen(body), body];
- TCPServer::write(socket, response.UTF8String, response.length);
- };
- TCPServer::read(socket);
- respond(mainBytes, "text/html");
- TCPServer::read(socket);
- respond(contentRuleListWorkerScript, "application/_javascript_");
- auto lastRequest = TCPServer::read(socket);
- EXPECT_TRUE(strnstr((const char*)lastRequest.data(), "allowedsubresource", lastRequest.size()));
- respond("successful fetch", "application/octet-stream");
+ HTTPServer server([] (Connection connection) {
+ connection.receiveHTTPRequest([=](Vector<char>&&) {
+ connection.send(HTTPResponse({{ "Content-Type", "text/html" }}, mainBytes).serialize(), [=] {
+ connection.receiveHTTPRequest([=](Vector<char>&&) {
+ connection.send(HTTPResponse({{ "Content-Type", "application/_javascript_" }}, contentRuleListWorkerScript).serialize(), [=] {
+ connection.receiveHTTPRequest([=](Vector<char>&& lastRequest) {
+ EXPECT_TRUE(strnstr((const char*)lastRequest.data(), "allowedsubresource", lastRequest.size()));
+ connection.send(HTTPResponse("successful fetch").serialize());
+ });
+ });
+ });
+ });
+ });
});
expectedMessage = @"Message from worker: PASS - blocked first request, allowed second";
Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/UploadDirectory.mm (283461 => 283462)
--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/UploadDirectory.mm 2021-10-03 04:04:30 UTC (rev 283461)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/UploadDirectory.mm 2021-10-03 04:41:47 UTC (rev 283462)
@@ -28,7 +28,7 @@
#if PLATFORM(MAC)
#import "DragAndDropSimulator.h"
-#import "TCPServer.h"
+#import "HTTPServer.h"
#import "TestNavigationDelegate.h"
#import "TestWKWebView.h"
#import "Utilities.h"
@@ -80,25 +80,26 @@
{
using namespace TestWebKitAPI;
- TCPServer server([] (int socket) {
- TCPServer::read(socket);
- const char* response =
- "HTTP/1.1 200 OK\r\n"
- "Content-Type: text/html\r\n"
- "Content-Length: 123\r\n\r\n"
- "<form id='form' action='' method='post' enctype='multipart/form-data'><input type='file' name='testname'></form>";
- TCPServer::write(socket, response, strlen(response));
-
- auto header = TCPServer::read(socket);
- EXPECT_TRUE(String(header.data(), header.size()).contains("Content-Length: 543"));
- size_t bodyBytesRead = 0;
- while (bodyBytesRead < 543)
- bodyBytesRead += TCPServer::read(socket).size();
- EXPECT_EQ(bodyBytesRead, 543ull);
- const char* secondResponse =
- "HTTP/1.1 200 OK\r\n"
- "Content-Length: 0\r\n\r\n";
- TCPServer::write(socket, secondResponse, strlen(secondResponse));
+ HTTPServer server([] (Connection connection) {
+ connection.receiveHTTPRequest([=](Vector<char>&&) {
+ const char* response =
+ "HTTP/1.1 200 OK\r\n"
+ "Content-Type: text/html\r\n"
+ "Content-Length: 123\r\n\r\n"
+ "<form id='form' action='' method='post' enctype='multipart/form-data'><input type='file' name='testname'></form>";
+ connection.send(response, [=] {
+ connection.receiveHTTPRequest([=](Vector<char>&& request) {
+ EXPECT_TRUE(strnstr(request.data(), "Content-Length: 543\r\n", request.size()));
+ auto* headerEnd = strnstr(request.data(), "\r\n\r\n", request.size());
+ EXPECT_TRUE(headerEnd);
+ EXPECT_EQ(request.end() - (headerEnd + + strlen("\r\n\r\n")), 543);
+ const char* secondResponse =
+ "HTTP/1.1 200 OK\r\n"
+ "Content-Length: 0\r\n\r\n";
+ connection.send(secondResponse);
+ });
+ });
+ });
});
auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 800, 600)]);
Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKNavigationResponse.mm (283461 => 283462)
--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKNavigationResponse.mm 2021-10-03 04:04:30 UTC (rev 283461)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKNavigationResponse.mm 2021-10-03 04:41:47 UTC (rev 283462)
@@ -25,7 +25,7 @@
#import "config.h"
-#import "TCPServer.h"
+#import "HTTPServer.h"
#import "Test.h"
#import "Utilities.h"
#import <WebKit/WKNavigationResponsePrivate.h>
@@ -199,24 +199,26 @@
{
auto getDownloadResponse = [] (RetainPtr<NSString> body) -> RetainPtr<WKNavigationResponse> {
using namespace TestWebKitAPI;
- TCPServer server([body](int socket) {
- unsigned bodyLength = [body length];
- NSString *firstResponse = [NSString stringWithFormat:
- @"HTTP/1.1 200 OK\r\n"
- "Content-Length: %d\r\n\r\n"
- "%@",
- bodyLength,
- body.get()
- ];
- NSString *secondResponse = @"HTTP/1.1 200 OK\r\n"
- "Content-Length: 6\r\n"
- "Content-Disposition: attachment; filename=fromHeader.txt;\r\n\r\n"
- "Hello!";
-
- TCPServer::read(socket);
- TCPServer::write(socket, firstResponse.UTF8String, firstResponse.length);
- TCPServer::read(socket);
- TCPServer::write(socket, secondResponse.UTF8String, secondResponse.length);
+ HTTPServer server([body](Connection connection) {
+ connection.receiveHTTPRequest([=](Vector<char>&&) {
+ unsigned bodyLength = [body length];
+ NSString *firstResponse = [NSString stringWithFormat:
+ @"HTTP/1.1 200 OK\r\n"
+ "Content-Length: %d\r\n\r\n"
+ "%@",
+ bodyLength,
+ body.get()
+ ];
+ connection.send(firstResponse, [=] {
+ connection.receiveHTTPRequest([=](Vector<char>&&) {
+ NSString *secondResponse = @"HTTP/1.1 200 OK\r\n"
+ "Content-Length: 6\r\n"
+ "Content-Disposition: attachment; filename=fromHeader.txt;\r\n\r\n"
+ "Hello!";
+ connection.send(secondResponse);
+ });
+ });
+ });
});
auto delegate = adoptNS([NavigationResponseTestDelegate new]);
auto webView = adoptNS([WKWebView new]);
Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKWebViewEvaluateJavaScript.mm (283461 => 283462)
--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKWebViewEvaluateJavaScript.mm 2021-10-03 04:04:30 UTC (rev 283461)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKWebViewEvaluateJavaScript.mm 2021-10-03 04:41:47 UTC (rev 283462)
@@ -28,7 +28,6 @@
#import "HTTPServer.h"
#import "PlatformUtilities.h"
-#import "TCPServer.h"
#import "Test.h"
#import "TestNavigationDelegate.h"
#import "TestURLSchemeHandler.h"
@@ -338,14 +337,14 @@
// Evaluating _javascript_ in such a document should fail and result in an error.
using namespace TestWebKitAPI;
- TCPServer server([](int socket) {
- NSString *response = @"HTTP/1.1 200 OK\r\n"
- "Content-Length: 12\r\n"
- "Content-Disposition: attachment; filename=fromHeader.txt;\r\n\r\n"
- "Hello world!";
-
- TCPServer::read(socket);
- TCPServer::write(socket, response.UTF8String, response.length);
+ HTTPServer server([](Connection connection) {
+ connection.receiveHTTPRequest([=](Vector<char>&&) {
+ constexpr auto response = "HTTP/1.1 200 OK\r\n"
+ "Content-Length: 12\r\n"
+ "Content-Disposition: attachment; filename=fromHeader.txt;\r\n\r\n"
+ "Hello world!";
+ connection.send(response);
+ });
});
auto webView = adoptNS([TestWKWebView new]);
[webView synchronouslyLoadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://127.0.0.1:%d/", server.port()]]]];
Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKWebsiteDatastore.mm (283461 => 283462)
--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKWebsiteDatastore.mm 2021-10-03 04:04:30 UTC (rev 283461)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKWebsiteDatastore.mm 2021-10-03 04:41:47 UTC (rev 283462)
@@ -27,7 +27,6 @@
#import "HTTPServer.h"
#import "PlatformUtilities.h"
-#import "TCPServer.h"
#import "Test.h"
#import "TestWKWebView.h"
#import <WebKit/WKProcessPoolPrivate.h>
@@ -120,7 +119,7 @@
TEST(WKWebsiteDataStore, FetchNonPersistentCredentials)
{
- TCPServer server(TCPServer::respondWithChallengeThenOK);
+ HTTPServer server(HTTPServer::respondWithChallengeThenOK);
usePersistentCredentialStorage = false;
auto configuration = adoptNS([WKWebViewConfiguration new]);
@@ -145,7 +144,7 @@
TEST(WKWebsiteDataStore, FetchPersistentCredentials)
{
- TCPServer server(TCPServer::respondWithChallengeThenOK);
+ HTTPServer server(HTTPServer::respondWithChallengeThenOK);
usePersistentCredentialStorage = true;
auto websiteDataStore = [WKWebsiteDataStore defaultDataStore];
@@ -174,7 +173,7 @@
TEST(WKWebsiteDataStore, RemoveNonPersistentCredentials)
{
- TCPServer server(TCPServer::respondWithChallengeThenOK);
+ HTTPServer server(HTTPServer::respondWithChallengeThenOK);
usePersistentCredentialStorage = false;
auto configuration = adoptNS([WKWebViewConfiguration new]);
Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WebsiteDataStoreCustomPaths.mm (283461 => 283462)
--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WebsiteDataStoreCustomPaths.mm 2021-10-03 04:04:30 UTC (rev 283461)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WebsiteDataStoreCustomPaths.mm 2021-10-03 04:41:47 UTC (rev 283462)
@@ -27,7 +27,6 @@
#import "HTTPServer.h"
#import "PlatformUtilities.h"
-#import "TCPServer.h"
#import "Test.h"
#import "TestNavigationDelegate.h"
#import "TestWKWebView.h"
@@ -609,14 +608,15 @@
TEST(WebKit, NetworkCacheDirectory)
{
using namespace TestWebKitAPI;
- TCPServer server([] (int socket) {
- TCPServer::read(socket);
- const char* response =
- "HTTP/1.1 200 OK\r\n"
- "Cache-Control: max-age=1000000\r\n"
- "Content-Length: 6\r\n\r\n"
- "Hello!";
- TCPServer::write(socket, response, strlen(response));
+ HTTPServer server([] (Connection connection) {
+ connection.receiveHTTPRequest([=] (Vector<char>&&) {
+ const char* response =
+ "HTTP/1.1 200 OK\r\n"
+ "Cache-Control: max-age=1000000\r\n"
+ "Content-Length: 6\r\n\r\n"
+ "Hello!";
+ connection.send(response);
+ });
});
NSURL *tempDir = [NSURL fileURLWithPath:[NSTemporaryDirectory() stringByAppendingPathComponent:@"CustomPathsTest"] isDirectory:YES];
@@ -740,52 +740,54 @@
#endif // HAVE(CFNETWORK_ALTERNATIVE_SERVICE)
+static void respondToRangeRequests(const TestWebKitAPI::Connection& connection, const RetainPtr<NSData>& data)
+{
+ connection.receiveHTTPRequest([=] (Vector<char>&& bytes) {
+ StringView request(reinterpret_cast<const LChar*>(bytes.data()), bytes.size());
+ auto rangeBytes = "Range: bytes="_s;
+ auto begin = request.find(StringView(rangeBytes), 0);
+ ASSERT(begin != notFound);
+ auto dash = request.find('-', begin);
+ ASSERT(dash != notFound);
+ auto end = request.find('\r', dash);
+ ASSERT(end != notFound);
+
+ auto rangeBegin = parseInteger<uint64_t>(request.substring(begin + rangeBytes.length(), dash - begin - rangeBytes.length())).value();
+ auto rangeEnd = parseInteger<uint64_t>(request.substring(dash + 1, end - dash - 1)).value();
+
+ NSString *responseHeaderString = [NSString stringWithFormat:
+ @"HTTP/1.1 206 Partial Content\r\n"
+ "Content-Range: bytes %llu-%llu/%llu\r\n"
+ "Content-Length: %llu\r\n\r\n",
+ rangeBegin, rangeEnd, static_cast<uint64_t>(data.get().length), rangeEnd - rangeBegin];
+ NSData *responseHeader = [responseHeaderString dataUsingEncoding:NSUTF8StringEncoding];
+ NSData *responseBody = [data subdataWithRange:NSMakeRange(rangeBegin, rangeEnd - rangeBegin)];
+ Vector<uint8_t> response { static_cast<const uint8_t*>(responseHeader.bytes), responseHeader.length };
+ response.append(static_cast<const uint8_t*>(responseBody.bytes), responseBody.length);
+ connection.send(WTFMove(response), [=] {
+ respondToRangeRequests(connection, data);
+ });
+ });
+}
+
TEST(WebKit, MediaCache)
{
JSC::Config::configureForTesting();
- std::atomic<bool> done = false;
using namespace TestWebKitAPI;
RetainPtr<NSData> data = "" dataWithContentsOfURL:[[NSBundle mainBundle] URLForResource:@"test" withExtension:@"mp4" subdirectory:@"TestWebKitAPI.resources"]];
- uint64_t dataLength = [data length];
- TCPServer server([&] (int socket) {
- TCPServer::read(socket);
- const char* firstResponse =
- "HTTP/1.1 200 OK\r\n"
- "Content-Type: text/html\r\n"
- "Content-Length: 55\r\n\r\n"
- "<video><source src='' type='video/mp4'></video>";
- TCPServer::write(socket, firstResponse, strlen(firstResponse));
-
- while (!done) {
- auto bytes = TCPServer::read(socket);
- if (done || bytes.isEmpty())
- break;
- StringView request(static_cast<const LChar*>(bytes.data()), bytes.size());
- String rangeBytes = "Range: bytes="_s;
- auto begin = request.find(StringView(rangeBytes), 0);
- ASSERT(begin != notFound);
- auto dash = request.find('-', begin);
- ASSERT(dash != notFound);
- auto end = request.find('\r', dash);
- ASSERT(end != notFound);
-
- auto rangeBegin = parseInteger<uint64_t>(request.substring(begin + rangeBytes.length(), dash - begin - rangeBytes.length())).value();
- auto rangeEnd = parseInteger<uint64_t>(request.substring(dash + 1, end - dash - 1)).value();
-
- NSString *responseHeaderString = [NSString stringWithFormat:
- @"HTTP/1.1 206 Partial Content\r\n"
- "Content-Range: bytes %llu-%llu/%llu\r\n"
- "Content-Length: %llu\r\n\r\n",
- rangeBegin, rangeEnd, dataLength, rangeEnd - rangeBegin];
- NSData *responseHeader = [responseHeaderString dataUsingEncoding:NSUTF8StringEncoding];
- NSData *responseBody = [data subdataWithRange:NSMakeRange(rangeBegin, rangeEnd - rangeBegin)];
- NSMutableData *response = [NSMutableData dataWithCapacity:responseHeader.length + responseBody.length];
- [response appendData:responseHeader];
- [response appendData:responseBody];
- TCPServer::write(socket, response.bytes, response.length);
- }
+ HTTPServer server([&] (Connection connection) {
+ connection.receiveHTTPRequest([=] (Vector<char>&&) {
+ const char* firstResponse =
+ "HTTP/1.1 200 OK\r\n"
+ "Content-Type: text/html\r\n"
+ "Content-Length: 55\r\n\r\n"
+ "<video><source src='' type='video/mp4'></video>";
+ connection.send(firstResponse, [=] {
+ respondToRangeRequests(connection, data);
+ });
+ });
});
NSURL *tempDir = [NSURL fileURLWithPath:[NSTemporaryDirectory() stringByAppendingPathComponent:@"CustomPathsTest"] isDirectory:YES];
@@ -807,7 +809,6 @@
Util::spinRunLoop();
EXPECT_FALSE(error);
- done = true;
[[webView configuration].websiteDataStore _terminateNetworkProcess];
[fileManager removeItemAtPath:path error:&error];