Changeset 244594 in webkit


Ignore:
Timestamp:
Apr 24, 2019 10:14:47 AM (5 years ago)
Author:
achristensen@apple.com
Message:

Add unit test for r239322
https://bugs.webkit.org/show_bug.cgi?id=197236

Reviewed by Chris Dumez.

I initially developed this as a unit test for rdar://problem/48797895 but it seems that isn't quite ready.
May as well add the test infrastructure which was needed before and will be needed in the future.

  • TestWebKitAPI/TCPServer.cpp:

(TestWebKitAPI::TCPServer::TCPServer):

  • TestWebKitAPI/TCPServer.h:
  • TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
  • TestWebKitAPI/Tests/WebKitCocoa/Challenge.mm:

(TestWebKitAPI::TEST):

  • TestWebKitAPI/Tests/WebKitCocoa/Download.mm:

(TestWebKitAPI::downloadAtRate):

  • TestWebKitAPI/Tests/WebKitCocoa/PDFLinkReferrer.mm:

(TEST):

  • TestWebKitAPI/Tests/WebKitCocoa/Proxy.mm: Added.

(-[ProxyDelegate webView:runJavaScriptAlertPanelWithMessage:initiatedByFrame:completionHandler:]):
(-[ProxyDelegate webView:didReceiveAuthenticationChallenge:completionHandler:]):
(TestWebKitAPI::TEST):

  • TestWebKitAPI/Tests/WebKitCocoa/WKNavigationResponse.mm:

(TEST):

Location:
trunk/Tools
Files:
1 added
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Tools/ChangeLog

    r244590 r244594  
     12019-04-24  Alex Christensen  <achristensen@webkit.org>
     2
     3        Add unit test for r239322
     4        https://bugs.webkit.org/show_bug.cgi?id=197236
     5
     6        Reviewed by Chris Dumez.
     7
     8        I initially developed this as a unit test for rdar://problem/48797895 but it seems that isn't quite ready.
     9        May as well add the test infrastructure which was needed before and will be needed in the future.
     10
     11        * TestWebKitAPI/TCPServer.cpp:
     12        (TestWebKitAPI::TCPServer::TCPServer):
     13        * TestWebKitAPI/TCPServer.h:
     14        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
     15        * TestWebKitAPI/Tests/WebKitCocoa/Challenge.mm:
     16        (TestWebKitAPI::TEST):
     17        * TestWebKitAPI/Tests/WebKitCocoa/Download.mm:
     18        (TestWebKitAPI::downloadAtRate):
     19        * TestWebKitAPI/Tests/WebKitCocoa/PDFLinkReferrer.mm:
     20        (TEST):
     21        * TestWebKitAPI/Tests/WebKitCocoa/Proxy.mm: Added.
     22        (-[ProxyDelegate webView:runJavaScriptAlertPanelWithMessage:initiatedByFrame:completionHandler:]):
     23        (-[ProxyDelegate webView:didReceiveAuthenticationChallenge:completionHandler:]):
     24        (TestWebKitAPI::TEST):
     25        * TestWebKitAPI/Tests/WebKitCocoa/WKNavigationResponse.mm:
     26        (TEST):
     27
    1282019-04-24  Chris Dumez  <cdumez@apple.com>
    229
  • trunk/Tools/TestWebKitAPI/TCPServer.cpp

    r244568 r244594  
    100100}
    101101
    102 TCPServer::TCPServer(Function<void(SSL*)>&& secureConnectionHandler)
    103     : m_connectionHandler([secureConnectionHandler = WTFMove(secureConnectionHandler)] (Socket socket) {
    104 
     102TCPServer::TCPServer(Protocol protocol, Function<void(SSL*)>&& secureConnectionHandler)
     103{
     104    auto startSecureConnection = [secureConnectionHandler = WTFMove(secureConnectionHandler)] (Socket socket) {
    105105        SSL_library_init();
    106106
     
    161161       
    162162        secureConnectionHandler(ssl.get());
    163     })
    164 {
     163    };
     164
     165    switch (protocol) {
     166    case Protocol::HTTPS:
     167        m_connectionHandler = WTFMove(startSecureConnection);
     168        break;
     169    case Protocol::HTTPSProxy:
     170        m_connectionHandler = [startSecureConnection = WTFMove(startSecureConnection)] (Socket socket) {
     171            char readBuffer[1000];
     172            auto bytesRead = ::read(socket, readBuffer, sizeof(readBuffer));
     173            EXPECT_GT(bytesRead, 0);
     174            EXPECT_TRUE(static_cast<size_t>(bytesRead) < sizeof(readBuffer));
     175           
     176            const char* responseHeader = ""
     177            "HTTP/1.1 200 Connection Established\r\n"
     178            "Connection: close\r\n\r\n";
     179            auto bytesWritten = ::write(socket, responseHeader, strlen(responseHeader));
     180            EXPECT_EQ(static_cast<size_t>(bytesWritten), strlen(responseHeader));
     181            startSecureConnection(socket);
     182        };
     183        break;
     184    }
    165185    listenForConnections(1);
    166186}
  • trunk/Tools/TestWebKitAPI/TCPServer.h

    r244568 r244594  
    4444    static constexpr Port InvalidPort = 0;
    4545   
    46     TCPServer(Function<void(Socket)>&&, size_t connections);
    47     TCPServer(Function<void(SSL*)>&&);
     46    TCPServer(Function<void(Socket)>&&, size_t connections = 1);
     47    enum class Protocol : bool {
     48        HTTPS, HTTPSProxy
     49    };
     50    TCPServer(Protocol, Function<void(SSL*)>&&);
    4851    ~TCPServer();
    4952   
  • trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj

    r244568 r244594  
    348348                5CF540E92257E67C00E6BC0E /* DownloadThread.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5CF540E82257E64B00E6BC0E /* DownloadThread.mm */; };
    349349                5CFACF63226F73C60056C7D0 /* libboringssl.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 5CFACF62226F73C60056C7D0 /* libboringssl.a */; };
     350                5CFACF65226FD2DC0056C7D0 /* Proxy.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5CFACF64226FD1FB0056C7D0 /* Proxy.mm */; };
    350351                5E4B1D2E1D404C6100053621 /* WKScrollViewDelegate.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5E4B1D2C1D404C6100053621 /* WKScrollViewDelegate.mm */; };
    351352                631EFFF61E7B5E8D00D2EBB8 /* Geolocation.mm in Sources */ = {isa = PBXBuildFile; fileRef = 631EFFF51E7B5E8D00D2EBB8 /* Geolocation.mm */; };
     
    17651766                5CF540E82257E64B00E6BC0E /* DownloadThread.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DownloadThread.mm; sourceTree = "<group>"; };
    17661767                5CFACF62226F73C60056C7D0 /* libboringssl.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; path = libboringssl.a; sourceTree = BUILT_PRODUCTS_DIR; };
     1768                5CFACF64226FD1FB0056C7D0 /* Proxy.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = Proxy.mm; sourceTree = "<group>"; };
    17671769                5E4B1D2C1D404C6100053621 /* WKScrollViewDelegate.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = WKScrollViewDelegate.mm; path = ../ios/WKScrollViewDelegate.mm; sourceTree = "<group>"; };
    17681770                631EFFF51E7B5E8D00D2EBB8 /* Geolocation.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = Geolocation.mm; sourceTree = "<group>"; };
     
    26462648                                518C1152205B04F9001FF4AE /* ProcessSwapOnNavigation.mm */,
    26472649                                5798E2AF1CAF5C2800C5CBA0 /* ProvisionalURLNotChange.mm */,
     2650                                5CFACF64226FD1FB0056C7D0 /* Proxy.mm */,
    26482651                                A1C4FB6C1BACCE50003742D0 /* QuickLook.mm */,
    26492652                                1A4F81D01BDFFDCF004E672E /* RemoteObjectRegistry.h */,
     
    42914294                                518C1153205B0504001FF4AE /* ProcessSwapOnNavigation.mm in Sources */,
    42924295                                7C83E0C11D0A652F00FEBCF3 /* ProvisionalURLNotChange.mm in Sources */,
     4296                                5CFACF65226FD2DC0056C7D0 /* Proxy.mm in Sources */,
    42934297                                041A1E34216FFDBC00789E0A /* PublicSuffix.cpp in Sources */,
    42944298                                7C83E0C21D0A653500FEBCF3 /* QuickLook.mm in Sources */,
  • trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/Challenge.mm

    r244568 r244594  
    239239TEST(Challenge, SecIdentity)
    240240{
    241     TCPServer server(respondWithChallengeThenOK, 1);
     241    TCPServer server(respondWithChallengeThenOK);
    242242
    243243    auto webView = adoptNS([WKWebView new]);
     
    402402TEST(WebKit, ServerTrust)
    403403{
    404     TCPServer server([] (SSL* ssl) {
     404    TCPServer server(TCPServer::Protocol::HTTPS, [] (SSL* ssl) {
    405405        char requestBuffer[1000];
    406406        auto readResult = SSL_read(ssl, requestBuffer, sizeof(requestBuffer));
  • trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/Download.mm

    r244568 r244594  
    864864    TCPServer server([&](int socket) {
    865865        respondSlowly(socket, desiredKbps, terminateServer);
    866     }, 1);
     866    });
    867867   
    868868    auto webView = webViewWithDownloadMonitorSpeedMultiplier(speedMultiplier);
  • trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/PDFLinkReferrer.mm

    r244568 r244594  
    9393        "Content-Length: 0\r\n\r\n";
    9494        ::write(socket, responseHeader, strlen(responseHeader));
    95     }, 1);
     95    });
    9696
    9797    RetainPtr<TestWKWebView> webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]);
  • trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKNavigationResponse.mm

    r244568 r244594  
    231231                "Hello!"
    232232            );
    233         }, 1);
     233        });
    234234        auto delegate = adoptNS([NavigationResponseTestDelegate new]);
    235235        auto webView = adoptNS([WKWebView new]);
Note: See TracChangeset for help on using the changeset viewer.