Skip to content
Permalink
Browse files
WKNavigationResponse._downloadAttribute should be nil when no downloa…
…d attribute is present

https://bugs.webkit.org/show_bug.cgi?id=196809
<rdar://49800762>

Patch by Alex Christensen <achristensen@webkit.org> on 2019-04-10
Reviewed by Brady Eidson.

Source/WebKit:

* UIProcess/API/Cocoa/WKNavigationResponse.mm:
(-[WKNavigationResponse _downloadAttribute]):

Tools:

* TestWebKitAPI/Tests/WebKitCocoa/WKNavigationResponse.mm:
(TEST):

Canonical link: https://commits.webkit.org/211095@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@244184 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
Alex Christensen authored and webkit-commit-queue committed Apr 11, 2019
1 parent 5c9fb29 commit a3cbc14074fc3d7394fd01902b593177b4ad29fd
Showing 4 changed files with 62 additions and 32 deletions.
@@ -1,3 +1,14 @@
2019-04-10 Alex Christensen <achristensen@webkit.org>

WKNavigationResponse._downloadAttribute should be nil when no download attribute is present
https://bugs.webkit.org/show_bug.cgi?id=196809
<rdar://49800762>

Reviewed by Brady Eidson.

* UIProcess/API/Cocoa/WKNavigationResponse.mm:
(-[WKNavigationResponse _downloadAttribute]):

2019-04-10 Tim Horton <timothy_horton@apple.com>

REGRESSION (r241734): ⌥⌘↑ and ⌥⌘↓ no longer navigate to previous/next Reading List article
@@ -80,7 +80,8 @@ - (NSURLRequest *)_request

- (NSString *)_downloadAttribute
{
return _navigationResponse->downloadAttribute();
const String& attribute = _navigationResponse->downloadAttribute();
return attribute.isNull() ? nil : (NSString *)attribute;
}

@end
@@ -1,3 +1,14 @@
2019-04-10 Alex Christensen <achristensen@webkit.org>

WKNavigationResponse._downloadAttribute should be nil when no download attribute is present
https://bugs.webkit.org/show_bug.cgi?id=196809
<rdar://49800762>

Reviewed by Brady Eidson.

* TestWebKitAPI/Tests/WebKitCocoa/WKNavigationResponse.mm:
(TEST):

2019-04-10 Said Abou-Hallawa <sabouhallawa@apple.com>

requestAnimationFrame should execute before the next frame
@@ -212,36 +212,43 @@ static void writeResponse(int socket, NSString *response)

TEST(WebKit, WKNavigationResponseDownloadAttribute)
{
TestWebKitAPI::TCPServer server([](int socket) {
readRequest(socket);
NSString *body = @"<a id='link' href='/fromHref.txt' download='fromDownloadAttribute.txt'>Click Me!</a>";
unsigned bodyLength = body.length;
writeResponse(socket, [NSString stringWithFormat:
@"HTTP/1.1 200 OK\r\n"
"Content-Length: %d\r\n\r\n"
"%@",
bodyLength,
body
]);
readRequest(socket);
writeResponse(socket,
@"HTTP/1.1 200 OK\r\n"
"Content-Length: 6\r\n"
"Content-Disposition: attachment; filename=fromHeader.txt;\r\n\r\n"
"Hello!"
);
});
auto delegate = adoptNS([NavigationResponseTestDelegate new]);
auto webView = adoptNS([WKWebView new]);
[webView setNavigationDelegate:delegate.get()];

[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://127.0.0.1:%d/", server.port()]]]];
[delegate waitForNavigationFinishedCallback];

[webView evaluateJavaScript:@"document.getElementById('link').click();" completionHandler:nil];
[delegate waitForNavigationResponseCallback];
auto getDownloadResponse = [] (RetainPtr<NSString> body) -> RetainPtr<WKNavigationResponse> {
TestWebKitAPI::TCPServer server([body](int socket) {
readRequest(socket);
unsigned bodyLength = [body length];
writeResponse(socket, [NSString stringWithFormat:
@"HTTP/1.1 200 OK\r\n"
"Content-Length: %d\r\n\r\n"
"%@",
bodyLength,
body.get()
]);
readRequest(socket);
writeResponse(socket,
@"HTTP/1.1 200 OK\r\n"
"Content-Length: 6\r\n"
"Content-Disposition: attachment; filename=fromHeader.txt;\r\n\r\n"
"Hello!"
);
});
auto delegate = adoptNS([NavigationResponseTestDelegate new]);
auto webView = adoptNS([WKWebView new]);
[webView setNavigationDelegate:delegate.get()];

[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://127.0.0.1:%d/", server.port()]]]];
[delegate waitForNavigationFinishedCallback];

[webView evaluateJavaScript:@"document.getElementById('link').click();" completionHandler:nil];
[delegate waitForNavigationResponseCallback];
EXPECT_STREQ([delegate navigationResponse].response.suggestedFilename.UTF8String, "fromHeader.txt");
return [delegate navigationResponse];
};
auto shouldBeFromDownloadAttribute = getDownloadResponse(@"<a id='link' href='/fromHref.txt' download='fromDownloadAttribute.txt'>Click Me!</a>");
auto shouldBeNull = getDownloadResponse(@"<a id='link' href='/fromHref.txt'>Click Me!</a>");
auto shouldBeEmpty = getDownloadResponse(@"<a id='link' href='/fromHref.txt' download=''>Click Me!</a>");

WKNavigationResponse *response = [delegate navigationResponse];
EXPECT_STREQ(response.response.suggestedFilename.UTF8String, "fromHeader.txt");
EXPECT_STREQ(response._downloadAttribute.UTF8String, "fromDownloadAttribute.txt");
EXPECT_STREQ([shouldBeFromDownloadAttribute _downloadAttribute].UTF8String, "fromDownloadAttribute.txt");
EXPECT_STREQ([shouldBeEmpty _downloadAttribute].UTF8String, "");
EXPECT_NOT_NULL([shouldBeEmpty _downloadAttribute]);
EXPECT_NULL([shouldBeNull _downloadAttribute]);
}

0 comments on commit a3cbc14

Please sign in to comment.