Changeset 283462 in webkit
- Timestamp:
- Oct 2, 2021, 9:41:47 PM (5 years ago)
- Location:
- trunk/Tools
- Files:
-
- 10 edited
-
ChangeLog (modified) (1 diff)
-
TestWebKitAPI/Tests/WebKitCocoa/DisplayName.mm (modified) (1 diff)
-
TestWebKitAPI/Tests/WebKitCocoa/PDFLinkReferrer.mm (modified) (4 diffs)
-
TestWebKitAPI/Tests/WebKitCocoa/ResourceLoadDelegate.mm (modified) (1 diff)
-
TestWebKitAPI/Tests/WebKitCocoa/ServiceWorkerBasic.mm (modified) (1 diff)
-
TestWebKitAPI/Tests/WebKitCocoa/UploadDirectory.mm (modified) (2 diffs)
-
TestWebKitAPI/Tests/WebKitCocoa/WKNavigationResponse.mm (modified) (2 diffs)
-
TestWebKitAPI/Tests/WebKitCocoa/WKWebViewEvaluateJavaScript.mm (modified) (2 diffs)
-
TestWebKitAPI/Tests/WebKitCocoa/WKWebsiteDatastore.mm (modified) (4 diffs)
-
TestWebKitAPI/Tests/WebKitCocoa/WebsiteDataStoreCustomPaths.mm (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Tools/ChangeLog
r283431 r283462 1 2021-10-02 Alex Christensen <achristensen@webkit.org> 2 3 Migrate some tests from TCPServer to HTTPServer 4 https://bugs.webkit.org/show_bug.cgi?id=231130 5 6 Reviewed by Chris Dumez. 7 8 The former runs logic on a non-main thread and has a destructor that waits for all threads to join, 9 which often causes timeouts in tests. This is progress towards removing TCPServer, which has been 10 replaced by HTTPServer. 11 12 * TestWebKitAPI/Tests/WebKitCocoa/DisplayName.mm: 13 * TestWebKitAPI/Tests/WebKitCocoa/PDFLinkReferrer.mm: 14 (TEST): 15 * TestWebKitAPI/Tests/WebKitCocoa/ResourceLoadDelegate.mm: 16 * TestWebKitAPI/Tests/WebKitCocoa/ServiceWorkerBasic.mm: 17 * TestWebKitAPI/Tests/WebKitCocoa/UploadDirectory.mm: 18 (TEST): 19 * TestWebKitAPI/Tests/WebKitCocoa/WKNavigationResponse.mm: 20 (TEST): 21 * TestWebKitAPI/Tests/WebKitCocoa/WKWebViewEvaluateJavaScript.mm: 22 (TEST): 23 * TestWebKitAPI/Tests/WebKitCocoa/WKWebsiteDatastore.mm: 24 (TestWebKitAPI::TEST): 25 * TestWebKitAPI/Tests/WebKitCocoa/WebsiteDataStoreCustomPaths.mm: 26 (TEST): 27 (respondToRangeRequests): 28 1 29 2021-10-01 Chris Dumez <cdumez@apple.com> 2 30 -
trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/DisplayName.mm
r273062 r283462 27 27 28 28 #import "PlatformUtilities.h" 29 #import "TCPServer.h"30 29 #import "Test.h" 31 30 #import "TestWKWebView.h" -
trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/PDFLinkReferrer.mm
r270510 r283462 28 28 #if PLATFORM(MAC) 29 29 30 #import " TCPServer.h"30 #import "HTTPServer.h" 31 31 #import "Test.h" 32 32 #import "TestNavigationDelegate.h" … … 35 35 #import <WebKit/WKFoundation.h> 36 36 37 // FIXME: Re-enable this test once rdar://68639688 is resolved.38 #if __MAC_OS_X_VERSION_MIN_REQUIRED < 11000039 37 static size_t putPDFBytesCallback(void* info, void* buffer, size_t count) 40 38 { … … 76 74 { 77 75 using namespace TestWebKitAPI; 78 TCPServer server([] (int socket) { 79 // This assumes all the data from the HTTP request is available to be read at once, 80 // which is probably an okay assumption. 81 auto requestBytes = TCPServer::read(socket); 82 83 // Look for a referer header. 84 const auto* currentLine = reinterpret_cast<const char*>(requestBytes.data()); 85 while (currentLine) { 86 EXPECT_NE(strncasecmp(currentLine, "referer:", 8), 0); 87 const char* nextLine = strchr(currentLine, '\n'); 88 currentLine = nextLine ? nextLine + 1 : 0; 89 } 90 91 const char* responseHeader = 92 "HTTP/1.1 200 OK\r\n" 93 "Content-Length: 0\r\n\r\n"; 94 TCPServer::write(socket, responseHeader, strlen(responseHeader)); 76 HTTPServer server([] (Connection connection) { 77 connection.receiveHTTPRequest([=](Vector<char>&& requestBytes) { 78 // Look for a referer header. 79 const auto* currentLine = reinterpret_cast<const char*>(requestBytes.data()); 80 while (currentLine) { 81 EXPECT_NE(strncasecmp(currentLine, "referer:", 8), 0); 82 const char* nextLine = strchr(currentLine, '\n'); 83 currentLine = nextLine ? nextLine + 1 : 0; 84 } 85 const char* responseHeader = 86 "HTTP/1.1 200 OK\r\n" 87 "Content-Length: 0\r\n\r\n"; 88 connection.send(responseHeader); 89 }); 95 90 }); 96 91 … … 115 110 116 111 } 117 #endif //__MAC_OS_X_VERSION_MIN_REQUIRED < 110000118 112 119 113 #endif // PLATFORM(MAC) -
trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ResourceLoadDelegate.mm
r273062 r283462 28 28 #import "HTTPServer.h" 29 29 #import "PlatformUtilities.h" 30 #import "TCPServer.h"31 30 #import "TestNavigationDelegate.h" 32 31 #import "TestUIDelegate.h" -
trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ServiceWorkerBasic.mm
r283431 r283462 2151 2151 2152 2152 using namespace TestWebKitAPI; 2153 TCPServer server([] (int socket) { 2154 auto respond = [socket] (const char* body, const char* mimeType) { 2155 NSString *format = @"HTTP/1.1 200 OK\r\n" 2156 "Content-Type: %s\r\n" 2157 "Content-Length: %d\r\n\r\n" 2158 "%s"; 2159 NSString *response = [NSString stringWithFormat:format, mimeType, strlen(body), body]; 2160 TCPServer::write(socket, response.UTF8String, response.length); 2161 }; 2162 TCPServer::read(socket); 2163 respond(mainBytes, "text/html"); 2164 TCPServer::read(socket); 2165 respond(contentRuleListWorkerScript, "application/javascript"); 2166 auto lastRequest = TCPServer::read(socket); 2167 EXPECT_TRUE(strnstr((const char*)lastRequest.data(), "allowedsubresource", lastRequest.size())); 2168 respond("successful fetch", "application/octet-stream"); 2153 HTTPServer server([] (Connection connection) { 2154 connection.receiveHTTPRequest([=](Vector<char>&&) { 2155 connection.send(HTTPResponse({{ "Content-Type", "text/html" }}, mainBytes).serialize(), [=] { 2156 connection.receiveHTTPRequest([=](Vector<char>&&) { 2157 connection.send(HTTPResponse({{ "Content-Type", "application/javascript" }}, contentRuleListWorkerScript).serialize(), [=] { 2158 connection.receiveHTTPRequest([=](Vector<char>&& lastRequest) { 2159 EXPECT_TRUE(strnstr((const char*)lastRequest.data(), "allowedsubresource", lastRequest.size())); 2160 connection.send(HTTPResponse("successful fetch").serialize()); 2161 }); 2162 }); 2163 }); 2164 }); 2165 }); 2169 2166 }); 2170 2167 -
trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/UploadDirectory.mm
r251996 r283462 29 29 30 30 #import "DragAndDropSimulator.h" 31 #import " TCPServer.h"31 #import "HTTPServer.h" 32 32 #import "TestNavigationDelegate.h" 33 33 #import "TestWKWebView.h" … … 81 81 { 82 82 using namespace TestWebKitAPI; 83 TCPServer server([] (int socket) { 84 TCPServer::read(socket); 85 const char* response = 86 "HTTP/1.1 200 OK\r\n" 87 "Content-Type: text/html\r\n" 88 "Content-Length: 123\r\n\r\n" 89 "<form id='form' action='/upload.php' method='post' enctype='multipart/form-data'><input type='file' name='testname'></form>"; 90 TCPServer::write(socket, response, strlen(response)); 91 92 auto header = TCPServer::read(socket); 93 EXPECT_TRUE(String(header.data(), header.size()).contains("Content-Length: 543")); 94 size_t bodyBytesRead = 0; 95 while (bodyBytesRead < 543) 96 bodyBytesRead += TCPServer::read(socket).size(); 97 EXPECT_EQ(bodyBytesRead, 543ull); 98 const char* secondResponse = 99 "HTTP/1.1 200 OK\r\n" 100 "Content-Length: 0\r\n\r\n"; 101 TCPServer::write(socket, secondResponse, strlen(secondResponse)); 83 HTTPServer server([] (Connection connection) { 84 connection.receiveHTTPRequest([=](Vector<char>&&) { 85 const char* response = 86 "HTTP/1.1 200 OK\r\n" 87 "Content-Type: text/html\r\n" 88 "Content-Length: 123\r\n\r\n" 89 "<form id='form' action='/upload.php' method='post' enctype='multipart/form-data'><input type='file' name='testname'></form>"; 90 connection.send(response, [=] { 91 connection.receiveHTTPRequest([=](Vector<char>&& request) { 92 EXPECT_TRUE(strnstr(request.data(), "Content-Length: 543\r\n", request.size())); 93 auto* headerEnd = strnstr(request.data(), "\r\n\r\n", request.size()); 94 EXPECT_TRUE(headerEnd); 95 EXPECT_EQ(request.end() - (headerEnd + + strlen("\r\n\r\n")), 543); 96 const char* secondResponse = 97 "HTTP/1.1 200 OK\r\n" 98 "Content-Length: 0\r\n\r\n"; 99 connection.send(secondResponse); 100 }); 101 }); 102 }); 102 103 }); 103 104 -
trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKNavigationResponse.mm
r246605 r283462 26 26 #import "config.h" 27 27 28 #import " TCPServer.h"28 #import "HTTPServer.h" 29 29 #import "Test.h" 30 30 #import "Utilities.h" … … 200 200 auto getDownloadResponse = [] (RetainPtr<NSString> body) -> RetainPtr<WKNavigationResponse> { 201 201 using namespace TestWebKitAPI; 202 TCPServer server([body](int socket) { 203 unsigned bodyLength = [body length]; 204 NSString *firstResponse = [NSString stringWithFormat: 205 @"HTTP/1.1 200 OK\r\n" 206 "Content-Length: %d\r\n\r\n" 207 "%@", 208 bodyLength, 209 body.get() 210 ]; 211 NSString *secondResponse = @"HTTP/1.1 200 OK\r\n" 212 "Content-Length: 6\r\n" 213 "Content-Disposition: attachment; filename=fromHeader.txt;\r\n\r\n" 214 "Hello!"; 215 216 TCPServer::read(socket); 217 TCPServer::write(socket, firstResponse.UTF8String, firstResponse.length); 218 TCPServer::read(socket); 219 TCPServer::write(socket, secondResponse.UTF8String, secondResponse.length); 202 HTTPServer server([body](Connection connection) { 203 connection.receiveHTTPRequest([=](Vector<char>&&) { 204 unsigned bodyLength = [body length]; 205 NSString *firstResponse = [NSString stringWithFormat: 206 @"HTTP/1.1 200 OK\r\n" 207 "Content-Length: %d\r\n\r\n" 208 "%@", 209 bodyLength, 210 body.get() 211 ]; 212 connection.send(firstResponse, [=] { 213 connection.receiveHTTPRequest([=](Vector<char>&&) { 214 NSString *secondResponse = @"HTTP/1.1 200 OK\r\n" 215 "Content-Length: 6\r\n" 216 "Content-Disposition: attachment; filename=fromHeader.txt;\r\n\r\n" 217 "Hello!"; 218 connection.send(secondResponse); 219 }); 220 }); 221 }); 220 222 }); 221 223 auto delegate = adoptNS([NavigationResponseTestDelegate new]); -
trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKWebViewEvaluateJavaScript.mm
r279079 r283462 29 29 #import "HTTPServer.h" 30 30 #import "PlatformUtilities.h" 31 #import "TCPServer.h"32 31 #import "Test.h" 33 32 #import "TestNavigationDelegate.h" … … 339 338 340 339 using namespace TestWebKitAPI; 341 TCPServer server([](int socket) {342 NSString *response = @"HTTP/1.1 200 OK\r\n"343 "Content-Length: 12\r\n"344 "Content-Disposition: attachment; filename=fromHeader.txt;\r\n\r\n"345 "Hello world!";346 347 TCPServer::read(socket);348 TCPServer::write(socket, response.UTF8String, response.length);340 HTTPServer server([](Connection connection) { 341 connection.receiveHTTPRequest([=](Vector<char>&&) { 342 constexpr auto response = "HTTP/1.1 200 OK\r\n" 343 "Content-Length: 12\r\n" 344 "Content-Disposition: attachment; filename=fromHeader.txt;\r\n\r\n" 345 "Hello world!"; 346 connection.send(response); 347 }); 349 348 }); 350 349 auto webView = adoptNS([TestWKWebView new]); -
trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKWebsiteDatastore.mm
r279074 r283462 28 28 #import "HTTPServer.h" 29 29 #import "PlatformUtilities.h" 30 #import "TCPServer.h"31 30 #import "Test.h" 32 31 #import "TestWKWebView.h" … … 121 120 TEST(WKWebsiteDataStore, FetchNonPersistentCredentials) 122 121 { 123 TCPServer server(TCPServer::respondWithChallengeThenOK);122 HTTPServer server(HTTPServer::respondWithChallengeThenOK); 124 123 125 124 usePersistentCredentialStorage = false; … … 146 145 TEST(WKWebsiteDataStore, FetchPersistentCredentials) 147 146 { 148 TCPServer server(TCPServer::respondWithChallengeThenOK);147 HTTPServer server(HTTPServer::respondWithChallengeThenOK); 149 148 150 149 usePersistentCredentialStorage = true; … … 175 174 TEST(WKWebsiteDataStore, RemoveNonPersistentCredentials) 176 175 { 177 TCPServer server(TCPServer::respondWithChallengeThenOK);176 HTTPServer server(HTTPServer::respondWithChallengeThenOK); 178 177 179 178 usePersistentCredentialStorage = false; -
trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WebsiteDataStoreCustomPaths.mm
r277564 r283462 28 28 #import "HTTPServer.h" 29 29 #import "PlatformUtilities.h" 30 #import "TCPServer.h"31 30 #import "Test.h" 32 31 #import "TestNavigationDelegate.h" … … 610 609 { 611 610 using namespace TestWebKitAPI; 612 TCPServer server([] (int socket) { 613 TCPServer::read(socket); 614 const char* response = 615 "HTTP/1.1 200 OK\r\n" 616 "Cache-Control: max-age=1000000\r\n" 617 "Content-Length: 6\r\n\r\n" 618 "Hello!"; 619 TCPServer::write(socket, response, strlen(response)); 611 HTTPServer server([] (Connection connection) { 612 connection.receiveHTTPRequest([=] (Vector<char>&&) { 613 const char* response = 614 "HTTP/1.1 200 OK\r\n" 615 "Cache-Control: max-age=1000000\r\n" 616 "Content-Length: 6\r\n\r\n" 617 "Hello!"; 618 connection.send(response); 619 }); 620 620 }); 621 621 … … 741 741 #endif // HAVE(CFNETWORK_ALTERNATIVE_SERVICE) 742 742 743 static void respondToRangeRequests(const TestWebKitAPI::Connection& connection, const RetainPtr<NSData>& data) 744 { 745 connection.receiveHTTPRequest([=] (Vector<char>&& bytes) { 746 StringView request(reinterpret_cast<const LChar*>(bytes.data()), bytes.size()); 747 auto rangeBytes = "Range: bytes="_s; 748 auto begin = request.find(StringView(rangeBytes), 0); 749 ASSERT(begin != notFound); 750 auto dash = request.find('-', begin); 751 ASSERT(dash != notFound); 752 auto end = request.find('\r', dash); 753 ASSERT(end != notFound); 754 755 auto rangeBegin = parseInteger<uint64_t>(request.substring(begin + rangeBytes.length(), dash - begin - rangeBytes.length())).value(); 756 auto rangeEnd = parseInteger<uint64_t>(request.substring(dash + 1, end - dash - 1)).value(); 757 758 NSString *responseHeaderString = [NSString stringWithFormat: 759 @"HTTP/1.1 206 Partial Content\r\n" 760 "Content-Range: bytes %llu-%llu/%llu\r\n" 761 "Content-Length: %llu\r\n\r\n", 762 rangeBegin, rangeEnd, static_cast<uint64_t>(data.get().length), rangeEnd - rangeBegin]; 763 NSData *responseHeader = [responseHeaderString dataUsingEncoding:NSUTF8StringEncoding]; 764 NSData *responseBody = [data subdataWithRange:NSMakeRange(rangeBegin, rangeEnd - rangeBegin)]; 765 Vector<uint8_t> response { static_cast<const uint8_t*>(responseHeader.bytes), responseHeader.length }; 766 response.append(static_cast<const uint8_t*>(responseBody.bytes), responseBody.length); 767 connection.send(WTFMove(response), [=] { 768 respondToRangeRequests(connection, data); 769 }); 770 }); 771 } 772 743 773 TEST(WebKit, MediaCache) 744 774 { 745 775 JSC::Config::configureForTesting(); 746 776 747 std::atomic<bool> done = false;748 777 using namespace TestWebKitAPI; 749 778 RetainPtr<NSData> data = [NSData dataWithContentsOfURL:[[NSBundle mainBundle] URLForResource:@"test" withExtension:@"mp4" subdirectory:@"TestWebKitAPI.resources"]]; 750 uint64_t dataLength = [data length]; 751 752 TCPServer server([&] (int socket) { 753 TCPServer::read(socket); 754 const char* firstResponse = 755 "HTTP/1.1 200 OK\r\n" 756 "Content-Type: text/html\r\n" 757 "Content-Length: 55\r\n\r\n" 758 "<video><source src='test.mp4' type='video/mp4'></video>"; 759 TCPServer::write(socket, firstResponse, strlen(firstResponse)); 760 761 while (!done) { 762 auto bytes = TCPServer::read(socket); 763 if (done || bytes.isEmpty()) 764 break; 765 StringView request(static_cast<const LChar*>(bytes.data()), bytes.size()); 766 String rangeBytes = "Range: bytes="_s; 767 auto begin = request.find(StringView(rangeBytes), 0); 768 ASSERT(begin != notFound); 769 auto dash = request.find('-', begin); 770 ASSERT(dash != notFound); 771 auto end = request.find('\r', dash); 772 ASSERT(end != notFound); 773 774 auto rangeBegin = parseInteger<uint64_t>(request.substring(begin + rangeBytes.length(), dash - begin - rangeBytes.length())).value(); 775 auto rangeEnd = parseInteger<uint64_t>(request.substring(dash + 1, end - dash - 1)).value(); 776 777 NSString *responseHeaderString = [NSString stringWithFormat: 778 @"HTTP/1.1 206 Partial Content\r\n" 779 "Content-Range: bytes %llu-%llu/%llu\r\n" 780 "Content-Length: %llu\r\n\r\n", 781 rangeBegin, rangeEnd, dataLength, rangeEnd - rangeBegin]; 782 NSData *responseHeader = [responseHeaderString dataUsingEncoding:NSUTF8StringEncoding]; 783 NSData *responseBody = [data subdataWithRange:NSMakeRange(rangeBegin, rangeEnd - rangeBegin)]; 784 NSMutableData *response = [NSMutableData dataWithCapacity:responseHeader.length + responseBody.length]; 785 [response appendData:responseHeader]; 786 [response appendData:responseBody]; 787 TCPServer::write(socket, response.bytes, response.length); 788 } 779 780 HTTPServer server([&] (Connection connection) { 781 connection.receiveHTTPRequest([=] (Vector<char>&&) { 782 const char* firstResponse = 783 "HTTP/1.1 200 OK\r\n" 784 "Content-Type: text/html\r\n" 785 "Content-Length: 55\r\n\r\n" 786 "<video><source src='test.mp4' type='video/mp4'></video>"; 787 connection.send(firstResponse, [=] { 788 respondToRangeRequests(connection, data); 789 }); 790 }); 789 791 }); 790 792 … … 808 810 EXPECT_FALSE(error); 809 811 810 done = true;811 812 [[webView configuration].websiteDataStore _terminateNetworkProcess]; 812 813
Note:
See TracChangeset
for help on using the changeset viewer.