TestWebKitAPI doesn't successfully use the network. I wrote a little socket server.
rdar://problem/22543960
Created attachment 260428 [details] Patch
Comment on attachment 260428 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=260428&action=review > Tools/ChangeLog:3 > + Test loading from the network in TestWebKitAPI. You should discuss this with Sam, Alexey, and Brady and make sure we actually want it. But, it seems like it might (eventually) make it possible to test things that we previously couldn't. > Tools/TestWebKitAPI/Tests/WebKit2Cocoa/NetworkLoading.mm:55 > + TCPServer server("HTTP/1.1 200 OK\r\n\r\n<html><head><title>TestTitle</title></head><body>TestBody</body></html>"); Please consider factoring the 200 header into something vended by TCPServer because it looks ugly. > Tools/TestWebKitAPI/Tests/WebKit2Cocoa/NetworkLoading.mm:59 > + urlBuilder.append("http://127.0.0.1:"); I think the operators work > Tools/TestWebKitAPI/Tests/WebKit2Cocoa/NetworkLoading.mm:64 > + RetainPtr<WebView> webView = adoptNS([[WebView alloc] initWithFrame:NSMakeRect(0, 0, 120, 200) frameName:nil groupName:nil]); Can you/should you use PlatformWebView? Otherwise, do you want to be using WK2? > Tools/TestWebKitAPI/Tests/WebKit2Cocoa/NetworkLoading.mm:67 > + [[webView.get() mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithCString:urlBuilder.toString().utf8().data() encoding:NSUTF8StringEncoding]]]]; There's got to be a better way to say this. > Tools/TestWebKitAPI/Tests/WebKit2Cocoa/NetworkLoading.mm:70 > + EXPECT_STREQ([[webView.get() mainFrameTitle] UTF8String], "TestTitle"); Stop it with the .get()s > Tools/TestWebKitAPI/Tests/WebKit2Cocoa/TCPServer.cpp:100 > +void TCPServer::replyToRequest() This is more like waitForAndReplyToRequest (it does more than just reply) > Tools/TestWebKitAPI/Tests/WebKit2Cocoa/TCPServer.cpp:111 > + String request = readEntireRequest(); So, someday you'll support verifying the request, and multiple request/response pairs? > Tools/TestWebKitAPI/Tests/WebKit2Cocoa/TCPServer.cpp:114 > + extra newline
It's definitely a great idea to allow networking tests in TestWebKitAPI. However, I'm worried about adding yet another server that has to find a port for itself, to make sure that everything works in concurrent scenarios, and eventually to support https and websockets. Writing C++ code to implement trivial HTTP responses seems undesirable too. Can't we just use the same Apache setup as in layout tests? Let's discuss this before landing.
Created attachment 267020 [details] Patch
> It's definitely a great idea to allow networking tests in TestWebKitAPI. Having talked to Alex in person, I now wonder if it would be better to test such things in WebKitTestRunner, because that's where our end-to-end tests are normally run.