Need infrastructure to test Content-Disposition filename encoding support
authorap@apple.com <ap@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 19 Jan 2012 01:54:40 +0000 (01:54 +0000)
committerap@apple.com <ap@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 19 Jan 2012 01:54:40 +0000 (01:54 +0000)
        https://bugs.webkit.org/show_bug.cgi?id=76572
        <rdar://problem/6421825>

        Reviewed by Sam Weinig.

        Made policy delegate log suggested file name when resource has Content-Disposition: attachment.

        WebKitTestRunner does not have a policy delegate yet, bug 42546.

        * DumpRenderTree/mac/PolicyDelegate.mm:
        (dispositionTypeFromContentDispositionHeader):
        (-[PolicyDelegate webView:decidePolicyForMIMEType:request:frame:decisionListener:]):

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

12 files changed:
LayoutTests/ChangeLog
LayoutTests/http/tests/download/basic-ascii-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/download/basic-ascii.html [new file with mode: 0644]
LayoutTests/http/tests/download/resources/basic-ascii.php [new file with mode: 0755]
LayoutTests/platform/chromium/test_expectations.txt
LayoutTests/platform/efl/Skipped
LayoutTests/platform/gtk/Skipped
LayoutTests/platform/qt/Skipped
LayoutTests/platform/win/Skipped
LayoutTests/platform/wk2/Skipped
Tools/ChangeLog
Tools/DumpRenderTree/mac/PolicyDelegate.mm

index 851afd9..e385174 100644 (file)
@@ -1,3 +1,25 @@
+2012-01-18  Alexey Proskuryakov  <ap@apple.com>
+
+        Need infrastructure to test Content-Disposition filename encoding support
+        https://bugs.webkit.org/show_bug.cgi?id=76572
+        <rdar://problem/6421825>
+
+        Reviewed by Sam Weinig.
+
+        Added a very simple test just to check that it works.
+
+        * http/tests/download: Added.
+        * http/tests/download/basic-ascii-expected.txt: Added.
+        * http/tests/download/basic-ascii.html: Added.
+        * http/tests/download/resources: Added.
+        * http/tests/download/resources/basic-ascii.php: Added.
+        * platform/chromium/test_expectations.txt:
+        * platform/efl/Skipped:
+        * platform/gtk/Skipped:
+        * platform/qt/Skipped:
+        * platform/win/Skipped:
+        * platform/wk2/Skipped:
+
 2012-01-18  James Robinson  <jamesr@chromium.org>
 
         [chromium] Update a few chromium expectations.
diff --git a/LayoutTests/http/tests/download/basic-ascii-expected.txt b/LayoutTests/http/tests/download/basic-ascii-expected.txt
new file mode 100644 (file)
index 0000000..51e584c
--- /dev/null
@@ -0,0 +1,5 @@
+Policy delegate: attempt to load http://127.0.0.1:8000/download/resources/basic-ascii.php with navigation type 'other'
+Policy delegate: resource is an attachment, suggested file name 'test file.txt'
+Download file name should be "test file.txt".
+
+
diff --git a/LayoutTests/http/tests/download/basic-ascii.html b/LayoutTests/http/tests/download/basic-ascii.html
new file mode 100644 (file)
index 0000000..ed6bef0
--- /dev/null
@@ -0,0 +1,9 @@
+<meta charset="koi8-r">
+<script>
+if (window.layoutTestController) {
+    layoutTestController.dumpAsText();
+    layoutTestController.setCustomPolicyDelegate(true, true);
+}
+</script>
+<p>Download file name should be "test file.txt".</p>
+<iframe src="resources/basic-ascii.php"></iframe>
diff --git a/LayoutTests/http/tests/download/resources/basic-ascii.php b/LayoutTests/http/tests/download/resources/basic-ascii.php
new file mode 100755 (executable)
index 0000000..ffb1e15
--- /dev/null
@@ -0,0 +1,6 @@
+<?php
+header("Content-Disposition: attachment; filename=test file.txt");
+header("Content-Type: text/plain");
+?>
+
+Test file content.
index 461af55..45d3192 100644 (file)
@@ -3919,3 +3919,6 @@ BUGWK76446 : svg/custom/pointer-events-text.svg = TEXT
 
 // RenderSVGRoot now reports a correct size.
 BUGWK76646 : svg/foreignObject/text-tref-02-b.svg = TEXT
+
+// Need to implement file name logging.
+BUGWK76572 : http/tests/download = FAIL
index 1098448..b4b98c5 100644 (file)
@@ -442,6 +442,7 @@ fast/loader/javascript-url-hierarchical-execution.html
 fast/loader/onload-policy-ignore-for-frame.html
 fast/loader/policy-delegate-action-hit-test-zoomed.html
 fast/loader/reload-policy-delegate.html
+http/tests/download
 
 # EFL's LayoutTestController does not implement setScrollbarPolicy
 fast/overflow/scrollbar-restored-and-then-locked.html
index 0f92222..2533f2c 100644 (file)
@@ -1628,3 +1628,6 @@ fast/text/international/spaces-combined-in-vertical-text.html
 
 # https://bugs.webkit.org/show_bug.cgi?id=76048
 fast/text/font-kerning.html
+
+# Needs custom policy delegate enhancement to log downloads
+http/tests/download
index 50b5fae..323a980 100644 (file)
@@ -2591,3 +2591,6 @@ http/tests/misc/iframe-invalid-source-crash.html
 # https://bugs.webkit.org/show_bug.cgi?id=76566
 http/tests/inspector/console-resource-errors.html
 http/tests/inspector/console-cross-origin-iframe-logging.html
+
+# Needs custom policy delegate enhancement to log downloads
+http/tests/download
index 2bc1d17..9c2e26d 100644 (file)
@@ -501,6 +501,7 @@ editing/execCommand/enabling-and-selection-2.html
 
 # Needs custom policy delegate enhancement in DRT
 http/tests/navigation/post-goback-repost-policy.html
+http/tests/download
 
 # Needs scheduleAsynchronousClick method for EventSender
 fast/events/popup-blocking-click-in-iframe.html
index 50c6765..7396f3d 100644 (file)
@@ -581,6 +581,7 @@ fast/loader/reload-policy-delegate.html
 http/tests/misc/policy-delegate-called-twice.html
 http/tests/misc/redirect-to-external-url.html
 http/tests/security/feed-urls-from-remote.html
+http/tests/download
 
 # WebKitTestRunner needs layoutTestController.setDashboardCompatibilityMode
 # <https://bugs.webkit.org/show_bug.cgi?id=42547>
index e352c61..e81fdad 100644 (file)
@@ -1,3 +1,19 @@
+2012-01-18  Alexey Proskuryakov  <ap@apple.com>
+
+        Need infrastructure to test Content-Disposition filename encoding support
+        https://bugs.webkit.org/show_bug.cgi?id=76572
+        <rdar://problem/6421825>
+
+        Reviewed by Sam Weinig.
+
+        Made policy delegate log suggested file name when resource has Content-Disposition: attachment.
+
+        WebKitTestRunner does not have a policy delegate yet, bug 42546.
+
+        * DumpRenderTree/mac/PolicyDelegate.mm:
+        (dispositionTypeFromContentDispositionHeader):
+        (-[PolicyDelegate webView:decidePolicyForMIMEType:request:frame:decisionListener:]):
+
 2012-01-18  Ojan Vafai  <ojan@chromium.org>
 
         Fix tests from http://trac.webkit.org/changeset/105332.
index 6935ea7..d0cfd89 100644 (file)
@@ -32,6 +32,7 @@
 #import "DumpRenderTree.h"
 #import "LayoutTestController.h"
 #import <WebKit/DOMElement.h>
+#import <WebKit/WebFrame.h>
 #import <WebKit/WebPolicyDelegate.h>
 #import <WebKit/WebView.h>
 
     printf("%s\n", [message UTF8String]);
 }
 
+static NSString *dispositionTypeFromContentDispositionHeader(NSString *header)
+{
+    NSMutableString *result = [[[[header componentsSeparatedByString:@";"] objectAtIndex:0] mutableCopy] autorelease];
+    if (result)
+        CFStringTrimWhitespace((CFMutableStringRef)result);
+    return result;
+}
+
+- (void)webView:(WebView *)c decidePolicyForMIMEType:(NSString *)type
+                                 request:(NSURLRequest *)request
+                                   frame:(WebFrame *)frame
+                            decisionListener:(id<WebPolicyDecisionListener>)listener
+{
+    NSHTTPURLResponse *HTTPResponse = (NSHTTPURLResponse *)[[frame provisionalDataSource] response];
+    if (![HTTPResponse isKindOfClass:[NSHTTPURLResponse class]])
+        HTTPResponse = nil;
+
+    NSString *dispositionType = dispositionTypeFromContentDispositionHeader([[HTTPResponse allHeaderFields] objectForKey:@"Content-Disposition"]);
+    if (dispositionType && [dispositionType compare:@"attachment" options:NSCaseInsensitiveSearch] == NSOrderedSame) {
+        printf("Policy delegate: resource is an attachment, suggested file name '%s'\n", [[HTTPResponse suggestedFilename] UTF8String]);
+        [listener ignore];
+        return;
+    }
+
+    [listener use];
+}
+
 - (void)setPermissive:(BOOL)permissive
 {
     permissiveDelegate = permissive;