Unreviewed, rolling out r245418.
[WebKit-https.git] / Tools / TestWebKitAPI / Tests / WebKitCocoa / WKWebsiteDatastore.mm
index 31d1b55..3f953a7 100644 (file)
@@ -110,9 +110,36 @@ TEST(WKWebsiteDataStore, RemoveEphemeralData)
     TestWebKitAPI::Util::run(&done);
 }
 
+static void respondWithChallengeThenOK(int socket)
+{
+    char readBuffer[1000];
+    auto bytesRead = ::read(socket, readBuffer, sizeof(readBuffer));
+    EXPECT_GT(bytesRead, 0);
+    EXPECT_TRUE(static_cast<size_t>(bytesRead) < sizeof(readBuffer));
+    
+    const char* challengeHeader =
+    "HTTP/1.1 401 Unauthorized\r\n"
+    "Date: Sat, 23 Mar 2019 06:29:01 GMT\r\n"
+    "Content-Length: 0\r\n"
+    "WWW-Authenticate: Basic realm=\"testrealm\"\r\n\r\n";
+    auto bytesWritten = ::write(socket, challengeHeader, strlen(challengeHeader));
+    EXPECT_EQ(static_cast<size_t>(bytesWritten), strlen(challengeHeader));
+    
+    bytesRead = ::read(socket, readBuffer, sizeof(readBuffer));
+    EXPECT_GT(bytesRead, 0);
+    EXPECT_TRUE(static_cast<size_t>(bytesRead) < sizeof(readBuffer));
+    
+    const char* responseHeader =
+    "HTTP/1.1 200 OK\r\n"
+    "Content-Length: 13\r\n\r\n"
+    "Hello, World!";
+    bytesWritten = ::write(socket, responseHeader, strlen(responseHeader));
+    EXPECT_EQ(static_cast<size_t>(bytesWritten), strlen(responseHeader));
+}
+    
 TEST(WKWebsiteDataStore, FetchNonPersistentCredentials)
 {
-    TCPServer server(TCPServer::respondWithChallengeThenOK);
+    TCPServer server(respondWithChallengeThenOK);
     
     usePersistentCredentialStorage = false;
     auto configuration = adoptNS([WKWebViewConfiguration new]);
@@ -137,7 +164,7 @@ TEST(WKWebsiteDataStore, FetchNonPersistentCredentials)
 
 TEST(WKWebsiteDataStore, FetchPersistentCredentials)
 {
-    TCPServer server(TCPServer::respondWithChallengeThenOK);
+    TCPServer server(respondWithChallengeThenOK);
     
     usePersistentCredentialStorage = true;
     auto websiteDataStore = [WKWebsiteDataStore defaultDataStore];
@@ -175,7 +202,7 @@ TEST(WKWebsiteDataStore, FetchPersistentCredentials)
 
 TEST(WKWebsiteDataStore, RemovePersistentCredentials)
 {
-    TCPServer server(TCPServer::respondWithChallengeThenOK);
+    TCPServer server(respondWithChallengeThenOK);
 
     usePersistentCredentialStorage = true;
     auto websiteDataStore = [WKWebsiteDataStore defaultDataStore];
@@ -226,7 +253,7 @@ TEST(WKWebsiteDataStore, RemovePersistentCredentials)
 
 TEST(WKWebsiteDataStore, RemoveNonPersistentCredentials)
 {
-    TCPServer server(TCPServer::respondWithChallengeThenOK);
+    TCPServer server(respondWithChallengeThenOK);
 
     usePersistentCredentialStorage = false;
     auto configuration = adoptNS([WKWebViewConfiguration new]);