WKNavigationResponse._downloadAttribute should be nil when no download attribute...
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 11 Apr 2019 06:16:01 +0000 (06:16 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 11 Apr 2019 06:16:01 +0000 (06:16 +0000)
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):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@244184 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebKit/ChangeLog
Source/WebKit/UIProcess/API/Cocoa/WKNavigationResponse.mm
Tools/ChangeLog
Tools/TestWebKitAPI/Tests/WebKitCocoa/WKNavigationResponse.mm

index 33749b2..ba05193 100644 (file)
@@ -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
index 728c40e..6c37063 100644 (file)
@@ -80,7 +80,8 @@
 
 - (NSString *)_downloadAttribute
 {
-    return _navigationResponse->downloadAttribute();
+    const String& attribute = _navigationResponse->downloadAttribute();
+    return attribute.isNull() ? nil : (NSString *)attribute;
 }
 
 @end
index f4881bc..8ecfe11 100644 (file)
@@ -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
index 78bf4e7..fb2f1ac 100644 (file)
@@ -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]);
 }