Changeset 283272 in webkit
- Timestamp:
- Sep 29, 2021, 4:02:43 PM (5 years ago)
- Location:
- trunk/Tools
- Files:
-
- 3 edited
-
ChangeLog (modified) (1 diff)
-
TestWebKitAPI/Tests/WebKitCocoa/Download.mm (modified) (9 diffs)
-
TestWebKitAPI/cocoa/HTTPServer.mm (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Tools/ChangeLog
r283270 r283272 1 2021-09-29 Alex Christensen <achristensen@webkit.org> 2 3 Migrate _WKDownload tests from TCPServer to HTTPServer 4 https://bugs.webkit.org/show_bug.cgi?id=230980 5 <rdar://82100878> 6 7 Reviewed by Chris Dumez. 8 9 The former is very picky when it comes to numbers of TCP connections, and causes tests to time out when 10 the number of connections changes. The latter is more forgiving and runs code on the main thread. 11 12 * TestWebKitAPI/Tests/WebKitCocoa/Download.mm: 13 (TestWebKitAPI::respondSlowly): 14 (TestWebKitAPI::downloadAtRate): 15 (TEST): 16 * TestWebKitAPI/cocoa/HTTPServer.mm: 17 (TestWebKitAPI::Connection::send const): 18 1 19 2021-09-29 Matt Lewis <jlewis3@apple.com> 2 20 -
trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/Download.mm
r278253 r283272 27 27 #import <WebKit/WKFoundation.h> 28 28 29 #if PLATFORM(MAC) || PLATFORM(IOS)30 31 29 #import "HTTPServer.h" 32 30 #import "PlatformUtilities.h" 33 #import "TCPServer.h"34 31 #import "Test.h" 35 32 #import "TestDownloadDelegate.h" … … 859 856 namespace TestWebKitAPI { 860 857 861 void respondSlowly(int socket, double kbps, bool& terminateServer) 862 { 863 EXPECT_FALSE(isMainThread()); 864 char readBuffer[1000]; 865 auto bytesRead = ::read(socket, readBuffer, sizeof(readBuffer)); 866 EXPECT_GT(bytesRead, 0); 867 EXPECT_TRUE(static_cast<size_t>(bytesRead) < sizeof(readBuffer)); 868 869 const char* responseHeader = 870 "HTTP/1.1 200 OK\r\n" 871 "Content-Disposition: attachment; filename=\"filename.dat\"\r\n" 872 "Content-Length: 100000000\r\n\r\n"; 873 auto bytesWritten = ::write(socket, responseHeader, strlen(responseHeader)); 874 EXPECT_EQ(static_cast<size_t>(bytesWritten), strlen(responseHeader)); 875 858 void respondSlowly(const Connection& connection, double kbps) 859 { 860 EXPECT_TRUE(isMainThread()); 861 876 862 const double writesPerSecond = 100; 877 Vector<char> writeBuffer(static_cast<size_t>(1024 * kbps / writesPerSecond)); 878 while (!terminateServer) { 879 auto before = MonotonicTime::now(); 880 ::write(socket, writeBuffer.data(), writeBuffer.size()); 863 Vector<uint8_t> writeBuffer(static_cast<size_t>(1024 * kbps / writesPerSecond)); 864 auto before = MonotonicTime::now(); 865 connection.send(WTFMove(writeBuffer), [=] { 881 866 double writeDuration = (MonotonicTime::now() - before).seconds(); 882 867 double desiredSleep = 1.0 / writesPerSecond; 883 868 if (writeDuration < desiredSleep) 884 869 usleep(USEC_PER_SEC * (desiredSleep - writeDuration)); 885 } 870 respondSlowly(connection, kbps); 871 }); 886 872 } 887 873 … … 911 897 void downloadAtRate(double desiredKbps, unsigned speedMultiplier, AppReturnsToForeground returnToForeground = AppReturnsToForeground::No) 912 898 { 913 bool terminateServer = false; 914 TCPServer server([&](int socket) { 915 respondSlowly(socket, desiredKbps, terminateServer); 899 HTTPServer server([=](const Connection& connection) { 900 connection.receiveHTTPRequest([=](Vector<char>&&) { 901 const char* responseHeader = 902 "HTTP/1.1 200 OK\r\n" 903 "Content-Disposition: attachment; filename=\"filename.dat\"\r\n" 904 "Content-Length: 100000000\r\n\r\n"; 905 connection.send(responseHeader, [=] { 906 respondSlowly(connection, desiredKbps); 907 }); 908 }); 916 909 }); 917 910 … … 925 918 [[webView configuration].websiteDataStore _synthesizeAppIsBackground:NO]; 926 919 [monitorDelegate() waitForDidFail]; 927 terminateServer = true;928 920 [[NSFileManager defaultManager] removeItemAtURL:[NSURL fileURLWithPath:destination.get() isDirectory:NO] error:nil]; 929 921 } … … 1127 1119 using namespace TestWebKitAPI; 1128 1120 1129 std::atomic<bool> receivedFirstConnection { false }; 1130 1131 TCPServer server([&](int socket) { 1132 if (!receivedFirstConnection.exchange(true)) { 1133 TCPServer::read(socket); 1134 1135 const char* responseHeader = 1136 "HTTP/1.1 200 OK\r\n" 1137 "ETag: test\r\n" 1138 "Content-Length: 10000\r\n\r\n"; 1139 TCPServer::write(socket, responseHeader, strlen(responseHeader)); 1140 1141 char data[5000]; 1142 memset(data, 0, 5000); 1143 TCPServer::write(socket, data, 5000); 1144 1145 // Wait for the client to cancel the download before closing the connection. 1146 Util::run(&isDone); 1147 } else { 1148 TCPServer::read(socket); 1121 HTTPServer server([receivedFirstConnection = false] (Connection connection) mutable { 1122 if (!std::exchange(receivedFirstConnection, true)) { 1123 connection.receiveHTTPRequest([=](Vector<char>&&) { 1124 const char* responseHeader = 1125 "HTTP/1.1 200 OK\r\n" 1126 "ETag: test\r\n" 1127 "Content-Length: 10000\r\n\r\n"; 1128 connection.send(responseHeader, [=] { 1129 connection.send(Vector<uint8_t>(5000, 0)); 1130 }); 1131 }); 1132 return; 1133 } 1134 connection.receiveHTTPRequest([=](Vector<char>&&) { 1149 1135 const char* challengeHeader = 1150 1136 "HTTP/1.1 401 Unauthorized\r\n" … … 1152 1138 "Content-Length: 0\r\n" 1153 1139 "WWW-Authenticate: Basic realm=\"testrealm\"\r\n\r\n"; 1154 TCPServer::write(socket, challengeHeader, strlen(challengeHeader)); 1155 1156 TCPServer::read(socket); 1157 1158 const char* responseHeader = 1159 "HTTP/1.1 206 Partial Content\r\n" 1160 "ETag: test\r\n" 1161 "Content-Range: bytes 5000-9999/10000\r\n" 1162 "Content-Length: 5000\r\n\r\n"; 1163 TCPServer::write(socket, responseHeader, strlen(responseHeader)); 1164 1165 char data[5000]; 1166 memset(data, 1, 5000); 1167 TCPServer::write(socket, data, 5000); 1168 } 1169 }, 2); 1140 connection.send(challengeHeader, [=] { 1141 connection.receiveHTTPRequest([=](Vector<char>&&) { 1142 const char* responseHeader = 1143 "HTTP/1.1 206 Partial Content\r\n" 1144 "ETag: test\r\n" 1145 "Content-Range: bytes 5000-9999/10000\r\n" 1146 "Content-Length: 5000\r\n\r\n"; 1147 connection.send(responseHeader, [=] { 1148 connection.send(Vector<uint8_t>(5000, 1)); 1149 }); 1150 }); 1151 }); 1152 }); 1153 }); 1170 1154 1171 1155 auto processPool = adoptNS([[WKProcessPool alloc] init]); 1172 auto websiteDataStore = adoptNS([WKWebsiteDataStore defaultDataStore]);1156 auto websiteDataStore = [WKWebsiteDataStore defaultDataStore]; 1173 1157 1174 1158 auto delegate1 = adoptNS([[DownloadCancelingDelegate alloc] init]); … … 1177 1161 isDone = false; 1178 1162 NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://127.0.0.1:%d/", server.port()]]]; 1179 [processPool _downloadURLRequest:request websiteDataStore:websiteDataStore .get()originatingWebView:nil];1163 [processPool _downloadURLRequest:request websiteDataStore:websiteDataStore originatingWebView:nil]; 1180 1164 1181 1165 Util::run(&isDone); … … 1184 1168 auto delegate2 = adoptNS([[AuthenticationChallengeHandlingDelegate alloc] init]); 1185 1169 [processPool _setDownloadDelegate:delegate2.get()]; 1186 [processPool _resumeDownloadFromData:[delegate1 resumeData].get() websiteDataStore:websiteDataStore .get()path:[delegate1 path].get() originatingWebView:nil];1170 [processPool _resumeDownloadFromData:[delegate1 resumeData].get() websiteDataStore:websiteDataStore path:[delegate1 path].get() originatingWebView:nil]; 1187 1171 1188 1172 Util::run(&isDone); … … 2636 2620 2637 2621 } 2638 2639 #endif // PLATFORM(MAC) || PLATFORM(IOS) -
trunk/Tools/TestWebKitAPI/cocoa/HTTPServer.mm
r282755 r283272 322 322 { 323 323 nw_connection_send(m_connection.get(), message.get(), NW_CONNECTION_DEFAULT_MESSAGE_CONTEXT, true, makeBlockPtr([completionHandler = WTFMove(completionHandler)](nw_error_t error) mutable { 324 ASSERT(!error);325 324 if (completionHandler) 326 325 completionHandler();
Note:
See TracChangeset
for help on using the changeset viewer.