Bug 148719 - Test loading from the network in TestWebKitAPI
Summary: Test loading from the network in TestWebKitAPI
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: Tools / Tests (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Alex Christensen
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-09-02 12:51 PDT by Alex Christensen
Modified: 2015-12-09 11:23 PST (History)
2 users (show)

See Also:


Attachments
Patch (15.62 KB, patch)
2015-09-02 12:56 PDT, Alex Christensen
no flags Details | Formatted Diff | Diff
Patch (16.16 KB, patch)
2015-12-09 10:28 PST, Alex Christensen
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Alex Christensen 2015-09-02 12:51:23 PDT
TestWebKitAPI doesn't successfully use the network.  I wrote a little socket server.
Comment 1 Alex Christensen 2015-09-02 12:56:03 PDT
rdar://problem/22543960
Comment 2 Alex Christensen 2015-09-02 12:56:50 PDT
Created attachment 260428 [details]
Patch
Comment 3 Tim Horton 2015-09-02 18:23:12 PDT
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
Comment 4 Alexey Proskuryakov 2015-09-04 10:25:58 PDT
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.
Comment 5 Alex Christensen 2015-12-09 10:28:09 PST
Created attachment 267020 [details]
Patch
Comment 6 Alexey Proskuryakov 2015-12-09 11:23:12 PST
> 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.