Title: [221778] trunk
Revision
221778
Author
[email protected]
Date
2017-09-07 23:21:29 -0700 (Thu, 07 Sep 2017)

Log Message

WebKit should claim that it can show responses for a broader range of JSON MIMETypes
https://bugs.webkit.org/show_bug.cgi?id=176252
<rdar://problem/34212885>

Patch by Joseph Pecoraro <[email protected]> on 2017-09-07
Reviewed by Ryosuke Niwa.

Source/WebCore:

* platform/MIMETypeRegistry.h:
* platform/MIMETypeRegistry.cpp:
(WebCore::MIMETypeRegistry::canShowMIMEType):
Extend this to support _javascript_ and JSON MIMETypes that WebKit
knows how to treat as text.

Tools:

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WebKitCocoa/WKNavigationResponse.mm: Added.
(-[WKNavigationResponseTestNavigationDelegate webView:decidePolicyForNavigationResponse:decisionHandler:]):
(-[WKNavigationResponseTestNavigationDelegate webView:didCommitNavigation:]):
(-[WKNavigationResponseTestSchemeHandler webView:startURLSchemeTask:]):
(-[WKNavigationResponseTestSchemeHandler webView:stopURLSchemeTask:]):
(TEST):
Test for canShowMIMEType with multiple JSON mime types and a garbage mime type.
Previously canShowMIMEType would have been YES for "application/json" but
NO for "application/vnd.api+json". Now it shows YES for both.

* TestWebKitAPI/PlatformGTK.cmake:
* TestWebKitAPI/PlatformWPE.cmake:
* TestWebKitAPI/PlatformWin.cmake:
* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WebCore/MIMETypeRegistry.cpp: Added.
(TestWebKitAPI::TEST):
Tests for MIMETypeRegistry's dynamic JSON mime type detection.

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (221777 => 221778)


--- trunk/Source/WebCore/ChangeLog	2017-09-08 02:58:08 UTC (rev 221777)
+++ trunk/Source/WebCore/ChangeLog	2017-09-08 06:21:29 UTC (rev 221778)
@@ -1,3 +1,17 @@
+2017-09-07  Joseph Pecoraro  <[email protected]>
+
+        WebKit should claim that it can show responses for a broader range of JSON MIMETypes
+        https://bugs.webkit.org/show_bug.cgi?id=176252
+        <rdar://problem/34212885>
+
+        Reviewed by Ryosuke Niwa.
+
+        * platform/MIMETypeRegistry.h:
+        * platform/MIMETypeRegistry.cpp:
+        (WebCore::MIMETypeRegistry::canShowMIMEType):
+        Extend this to support _javascript_ and JSON MIMETypes that WebKit
+        knows how to treat as text.
+
 2017-09-07  Andy Estes  <[email protected]>
 
         [Mac] Upstream QTKit-related WebKitSystemInterface functions

Modified: trunk/Source/WebCore/platform/MIMETypeRegistry.cpp (221777 => 221778)


--- trunk/Source/WebCore/platform/MIMETypeRegistry.cpp	2017-09-08 02:58:08 UTC (rev 221777)
+++ trunk/Source/WebCore/platform/MIMETypeRegistry.cpp	2017-09-08 06:21:29 UTC (rev 221778)
@@ -102,7 +102,7 @@
     // These were removed for <rdar://problem/6564538> Re-enable UTI code in WebCore now that MobileCoreServices exists
     // But Mail relies on at least image/tif reported as being supported (should be image/tiff).
     // This can be removed when Mail addresses:
-    // <rdar://problem/7879510> Mail should use standard image mimetypes 
+    // <rdar://problem/7879510> Mail should use standard image mimetypes
     // and we fix sniffing so that it corrects items such as image/jpg -> image/jpeg.
     static const char* const malformedMIMETypes[] = {
         // JPEG (image/jpeg)
@@ -639,6 +639,9 @@
     if (isSupportedImageMIMEType(mimeType) || isSupportedNonImageMIMEType(mimeType) || isSupportedMediaMIMEType(mimeType))
         return true;
 
+    if (isSupportedJavaScriptMIMEType(mimeType) || isSupportedJSONMIMEType(mimeType))
+        return true;
+
     if (mimeType.startsWith("text/", false))
         return !isUnsupportedTextMIMEType(mimeType);
 

Modified: trunk/Source/WebCore/platform/MIMETypeRegistry.h (221777 => 221778)


--- trunk/Source/WebCore/platform/MIMETypeRegistry.h	2017-09-08 02:58:08 UTC (rev 221777)
+++ trunk/Source/WebCore/platform/MIMETypeRegistry.h	2017-09-08 06:21:29 UTC (rev 221778)
@@ -58,8 +58,8 @@
     static bool isSupportedImageMIMETypeForEncoding(const String& mimeType);
 
     // Check to see if a MIME type is suitable for being loaded as a _javascript_ or JSON resource.
-    static bool isSupportedJavaScriptMIMEType(const String& mimeType);
-    static bool isSupportedJSONMIMEType(const String& mimeType);
+    WEBCORE_EXPORT static bool isSupportedJavaScriptMIMEType(const String& mimeType);
+    WEBCORE_EXPORT static bool isSupportedJSONMIMEType(const String& mimeType);
 
     // Check to see if a MIME type is suitable for being loaded as a style sheet.
     static bool isSupportedStyleSheetMIMEType(const String& mimeType);
@@ -68,7 +68,7 @@
     static bool isSupportedFontMIMEType(const String& mimeType);
 
     // Check to see if a non-image MIME type is suitable for being loaded as a
-    // document in a frame. Includes supported _javascript_ MIME types.
+    // document in a frame. Does not include supported _javascript_ and JSON MIME types.
     WEBCORE_EXPORT static bool isSupportedNonImageMIMEType(const String& mimeType);
 
     // Check to see if a MIME type is suitable for being loaded using <video> and <audio>.
@@ -88,9 +88,10 @@
     static bool isPDFMIMEType(const String& mimeType);
 
     // Check to see if a MIME type is suitable for being shown inside a page.
-    // Returns true if any of isSupportedImageMIMEType(), isSupportedNonImageMIMEType(), or
-    // isSupportedMediaMIMEType() returns true or if the given MIME type begins with
-    // "text/" and isUnsupportedTextMIMEType() returns false.
+    // Returns true if any of isSupportedImageMIMEType(), isSupportedNonImageMIMEType(),
+    // isSupportedMediaMIMEType(), isSupportedJavaScriptMIMEType(), isSupportedJSONMIMEType(),
+    // returns true or if the given MIME type begins with "text/" and
+    // isUnsupportedTextMIMEType() returns false.
     WEBCORE_EXPORT static bool canShowMIMEType(const String& mimeType);
 
     // Check to see if a MIME type is one where an XML document should be created

Modified: trunk/Tools/ChangeLog (221777 => 221778)


--- trunk/Tools/ChangeLog	2017-09-08 02:58:08 UTC (rev 221777)
+++ trunk/Tools/ChangeLog	2017-09-08 06:21:29 UTC (rev 221778)
@@ -1,3 +1,30 @@
+2017-09-07  Joseph Pecoraro  <[email protected]>
+
+        WebKit should claim that it can show responses for a broader range of JSON MIMETypes
+        https://bugs.webkit.org/show_bug.cgi?id=176252
+        <rdar://problem/34212885>
+
+        Reviewed by Ryosuke Niwa.
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        * TestWebKitAPI/Tests/WebKitCocoa/WKNavigationResponse.mm: Added.
+        (-[WKNavigationResponseTestNavigationDelegate webView:decidePolicyForNavigationResponse:decisionHandler:]):
+        (-[WKNavigationResponseTestNavigationDelegate webView:didCommitNavigation:]):
+        (-[WKNavigationResponseTestSchemeHandler webView:startURLSchemeTask:]):
+        (-[WKNavigationResponseTestSchemeHandler webView:stopURLSchemeTask:]):
+        (TEST):
+        Test for canShowMIMEType with multiple JSON mime types and a garbage mime type.
+        Previously canShowMIMEType would have been YES for "application/json" but
+        NO for "application/vnd.api+json". Now it shows YES for both.
+
+        * TestWebKitAPI/PlatformGTK.cmake:
+        * TestWebKitAPI/PlatformWPE.cmake:
+        * TestWebKitAPI/PlatformWin.cmake:
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        * TestWebKitAPI/Tests/WebCore/MIMETypeRegistry.cpp: Added.
+        (TestWebKitAPI::TEST):
+        Tests for MIMETypeRegistry's dynamic JSON mime type detection.
+
 2017-09-07  Matthew Stewart  <[email protected]>
 
         Add Live PLT implemented with WebDriver

Modified: trunk/Tools/TestWebKitAPI/PlatformGTK.cmake (221777 => 221778)


--- trunk/Tools/TestWebKitAPI/PlatformGTK.cmake	2017-09-08 02:58:08 UTC (rev 221777)
+++ trunk/Tools/TestWebKitAPI/PlatformGTK.cmake	2017-09-08 06:21:29 UTC (rev 221778)
@@ -136,6 +136,7 @@
     ${TESTWEBKITAPI_DIR}/Tests/WebCore/GridPosition.cpp
     ${TESTWEBKITAPI_DIR}/Tests/WebCore/HTMLParserIdioms.cpp
     ${TESTWEBKITAPI_DIR}/Tests/WebCore/LayoutUnit.cpp
+    ${TESTWEBKITAPI_DIR}/Tests/WebCore/MIMETypeRegistry.cpp
     ${TESTWEBKITAPI_DIR}/Tests/WebCore/PublicSuffix.cpp
     ${TESTWEBKITAPI_DIR}/Tests/WebCore/SecurityOrigin.cpp
     ${TESTWEBKITAPI_DIR}/Tests/WebCore/SharedBuffer.cpp

Modified: trunk/Tools/TestWebKitAPI/PlatformWPE.cmake (221777 => 221778)


--- trunk/Tools/TestWebKitAPI/PlatformWPE.cmake	2017-09-08 02:58:08 UTC (rev 221777)
+++ trunk/Tools/TestWebKitAPI/PlatformWPE.cmake	2017-09-08 06:21:29 UTC (rev 221778)
@@ -45,6 +45,7 @@
     ${TESTWEBKITAPI_DIR}/TestsController.cpp
     ${TESTWEBKITAPI_DIR}/Tests/WebCore/HTMLParserIdioms.cpp
     ${TESTWEBKITAPI_DIR}/Tests/WebCore/LayoutUnit.cpp
+    ${TESTWEBKITAPI_DIR}/Tests/WebCore/MIMETypeRegistry.cpp
     ${TESTWEBKITAPI_DIR}/Tests/WebCore/URL.cpp
     ${TESTWEBKITAPI_DIR}/Tests/WebCore/SharedBuffer.cpp
     ${TESTWEBKITAPI_DIR}/Tests/WebCore/SharedBufferTest.cpp

Modified: trunk/Tools/TestWebKitAPI/PlatformWin.cmake (221777 => 221778)


--- trunk/Tools/TestWebKitAPI/PlatformWin.cmake	2017-09-08 02:58:08 UTC (rev 221777)
+++ trunk/Tools/TestWebKitAPI/PlatformWin.cmake	2017-09-08 06:21:29 UTC (rev 221778)
@@ -57,6 +57,7 @@
     ${TESTWEBKITAPI_DIR}/Tests/WebCore/IntPoint.cpp
     ${TESTWEBKITAPI_DIR}/Tests/WebCore/IntSize.cpp
     ${TESTWEBKITAPI_DIR}/Tests/WebCore/LayoutUnit.cpp
+    ${TESTWEBKITAPI_DIR}/Tests/WebCore/MIMETypeRegistry.cpp
     ${TESTWEBKITAPI_DIR}/Tests/WebCore/ParsedContentRange.cpp
     ${TESTWEBKITAPI_DIR}/Tests/WebCore/SecurityOrigin.cpp
     ${TESTWEBKITAPI_DIR}/Tests/WebCore/SharedBuffer.cpp

Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (221777 => 221778)


--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2017-09-08 02:58:08 UTC (rev 221777)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2017-09-08 06:21:29 UTC (rev 221778)
@@ -569,6 +569,8 @@
 		A57D54F31F338C3600A97AA7 /* NeverDestroyed.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A57D54F21F338C3600A97AA7 /* NeverDestroyed.cpp */; };
 		A57D54F61F3395D000A97AA7 /* Logger.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A57D54F41F3395D000A97AA7 /* Logger.cpp */; };
 		A57D54F91F3397B400A97AA7 /* LifecycleLogger.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A57D54F71F3397B400A97AA7 /* LifecycleLogger.cpp */; };
+		A5A729F11F622AA700DE5A28 /* WKNavigationResponse.mm in Sources */ = {isa = PBXBuildFile; fileRef = A5A729F01F622A9A00DE5A28 /* WKNavigationResponse.mm */; };
+		A5B149DE1F5A19EA00C6DAFF /* MIMETypeRegistry.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A5B149DD1F5A19DC00C6DAFF /* MIMETypeRegistry.cpp */; };
 		A5E2027515B21F6E00C13E14 /* WindowlessWebViewWithMedia.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = A5E2027015B2180600C13E14 /* WindowlessWebViewWithMedia.html */; };
 		AD57AC201DA7465000FF1BDE /* DidRemoveFrameFromHiearchyInPageCache_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = AD57AC1E1DA7464D00FF1BDE /* DidRemoveFrameFromHiearchyInPageCache_Bundle.cpp */; };
 		AD57AC211DA7465B00FF1BDE /* DidRemoveFrameFromHiearchyInPageCache.cpp in Sources */ = {isa = PBXBuildFile; fileRef = AD57AC1F1DA7464D00FF1BDE /* DidRemoveFrameFromHiearchyInPageCache.cpp */; };
@@ -1512,6 +1514,8 @@
 		A57D54F51F3395D000A97AA7 /* Logger.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Logger.h; sourceTree = "<group>"; };
 		A57D54F71F3397B400A97AA7 /* LifecycleLogger.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = LifecycleLogger.cpp; sourceTree = "<group>"; };
 		A57D54F81F3397B400A97AA7 /* LifecycleLogger.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = LifecycleLogger.h; sourceTree = "<group>"; };
+		A5A729F01F622A9A00DE5A28 /* WKNavigationResponse.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKNavigationResponse.mm; sourceTree = "<group>"; };
+		A5B149DD1F5A19DC00C6DAFF /* MIMETypeRegistry.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MIMETypeRegistry.cpp; sourceTree = "<group>"; };
 		A5E2027015B2180600C13E14 /* WindowlessWebViewWithMedia.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = WindowlessWebViewWithMedia.html; sourceTree = "<group>"; };
 		A5E2027215B2181900C13E14 /* WindowlessWebViewWithMedia.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WindowlessWebViewWithMedia.mm; sourceTree = "<group>"; };
 		A7A966DA140ECCC8005EF9B4 /* CheckedArithmeticOperations.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CheckedArithmeticOperations.cpp; sourceTree = "<group>"; };
@@ -1990,6 +1994,7 @@
 				2D838B1E1EEF3A5B009B980E /* WKContentViewEditingActions.mm */,
 				370CE2291F57343400E7410B /* WKContentViewTargetForAction.mm */,
 				51D124971E763AF8002B2820 /* WKHTTPCookieStore.mm */,
+				A5A729F01F622A9A00DE5A28 /* WKNavigationResponse.mm */,
 				375E0E151D66674400EFEC2C /* WKNSNumber.mm */,
 				37B47E2E1D64E7CA005F4EFF /* WKObject.mm */,
 				A14AAB611E78D7DE00C1ADC2 /* WKPDFView.mm */,
@@ -2067,6 +2072,7 @@
 				7A909A751D877475007E10F8 /* IntSize.cpp */,
 				14464012167A8305000BD218 /* LayoutUnit.cpp */,
 				076E507E1F45031E006E9F5A /* Logging.cpp */,
+				A5B149DD1F5A19DC00C6DAFF /* MIMETypeRegistry.cpp */,
 				CD225C071C45A69200140761 /* ParsedContentRange.cpp */,
 				CDCFA7A91E45122F00C2433D /* SampleMap.cpp */,
 				CE06DF9A1E1851F200E570C9 /* SecurityOrigin.cpp */,
@@ -3264,6 +3270,7 @@
 				5C0BF88D1DD5964D00B00328 /* MemoryPressureHandler.mm in Sources */,
 				7C83E0B71D0A64B800FEBCF3 /* MenuTypesForMouseEvents.cpp in Sources */,
 				5C0BF8941DD599C900B00328 /* MenuTypesForMouseEvents.mm in Sources */,
+				A5B149DE1F5A19EA00C6DAFF /* MIMETypeRegistry.cpp in Sources */,
 				51CD1C6C1B38CE4300142CA5 /* ModalAlerts.mm in Sources */,
 				7C83E0B61D0A64B300FEBCF3 /* ModalAlertsSPI.cpp in Sources */,
 				7CCE7F011A411AE600447C4C /* MouseMoveAfterCrash.cpp in Sources */,
@@ -3400,6 +3407,7 @@
 				370CE22A1F57343400E7410B /* WKContentViewTargetForAction.mm in Sources */,
 				51D124981E763B02002B2820 /* WKHTTPCookieStore.mm in Sources */,
 				7CCE7F1D1A411AE600447C4C /* WKImageCreateCGImageCrash.cpp in Sources */,
+				A5A729F11F622AA700DE5A28 /* WKNavigationResponse.mm in Sources */,
 				375E0E171D66674400EFEC2C /* WKNSNumber.mm in Sources */,
 				37B47E301D64E7CA005F4EFF /* WKObject.mm in Sources */,
 				7C89D2AC1A69B80D003A5FDE /* WKPageConfiguration.cpp in Sources */,

Added: trunk/Tools/TestWebKitAPI/Tests/WebCore/MIMETypeRegistry.cpp (0 => 221778)


--- trunk/Tools/TestWebKitAPI/Tests/WebCore/MIMETypeRegistry.cpp	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebCore/MIMETypeRegistry.cpp	2017-09-08 06:21:29 UTC (rev 221778)
@@ -0,0 +1,83 @@
+/*
+ * Copyright (C) 2017 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+
+#include <WebCore/MIMETypeRegistry.h>
+
+using namespace WebCore;
+
+namespace TestWebKitAPI {
+
+TEST(MIMETypeRegistry, JSONMIMETypes)
+{
+    ASSERT_TRUE(MIMETypeRegistry::isSupportedJSONMIMEType("application/json"));
+    ASSERT_TRUE(MIMETypeRegistry::isSupportedJSONMIMEType("APPLICATION/JSON"));
+    ASSERT_TRUE(MIMETypeRegistry::isSupportedJSONMIMEType("application/vnd.api+json"));
+    ASSERT_TRUE(MIMETypeRegistry::isSupportedJSONMIMEType("anything/something+json"));
+
+    ASSERT_FALSE(MIMETypeRegistry::isSupportedJSONMIMEType("text/plain"));
+    ASSERT_FALSE(MIMETypeRegistry::isSupportedJSONMIMEType("text/json"));
+    ASSERT_FALSE(MIMETypeRegistry::isSupportedJSONMIMEType("text/_javascript_"));
+}
+
+TEST(MIMETypeRegistry, _javascript_MIMETypes)
+{
+    ASSERT_TRUE(MIMETypeRegistry::isSupportedJavaScriptMIMEType("text/_javascript_"));
+    ASSERT_TRUE(MIMETypeRegistry::isSupportedJavaScriptMIMEType("TEXT/_javascript_"));
+    ASSERT_TRUE(MIMETypeRegistry::isSupportedJavaScriptMIMEType("application/_javascript_"));
+    ASSERT_TRUE(MIMETypeRegistry::isSupportedJavaScriptMIMEType("application/ecmascript"));
+    ASSERT_TRUE(MIMETypeRegistry::isSupportedJavaScriptMIMEType("application/x-_javascript_"));
+    ASSERT_TRUE(MIMETypeRegistry::isSupportedJavaScriptMIMEType("application/x-ecmascript"));
+
+    ASSERT_FALSE(MIMETypeRegistry::isSupportedJavaScriptMIMEType("text/plain"));
+    ASSERT_FALSE(MIMETypeRegistry::isSupportedJavaScriptMIMEType("application/json"));
+    ASSERT_FALSE(MIMETypeRegistry::isSupportedJavaScriptMIMEType("foo/_javascript_"));
+}
+
+TEST(MIMETypeRegistry, CanShowMIMEType)
+{
+    ASSERT_TRUE(MIMETypeRegistry::canShowMIMEType("text/plain"));
+    ASSERT_TRUE(MIMETypeRegistry::canShowMIMEType("text/html"));
+    ASSERT_TRUE(MIMETypeRegistry::canShowMIMEType("text/xml"));
+    ASSERT_TRUE(MIMETypeRegistry::canShowMIMEType("text/foo"));
+
+    ASSERT_TRUE(MIMETypeRegistry::canShowMIMEType("application/json"));
+    ASSERT_TRUE(MIMETypeRegistry::canShowMIMEType("APPLICATION/JSON"));
+    ASSERT_TRUE(MIMETypeRegistry::canShowMIMEType("application/vnd.api+json"));
+    ASSERT_TRUE(MIMETypeRegistry::canShowMIMEType("anything/something+json"));
+
+    ASSERT_TRUE(MIMETypeRegistry::canShowMIMEType("text/_javascript_"));
+    ASSERT_TRUE(MIMETypeRegistry::canShowMIMEType("TEXT/_javascript_"));
+    ASSERT_TRUE(MIMETypeRegistry::canShowMIMEType("application/_javascript_"));
+    ASSERT_TRUE(MIMETypeRegistry::canShowMIMEType("application/ecmascript"));
+    ASSERT_TRUE(MIMETypeRegistry::canShowMIMEType("application/x-_javascript_"));
+    ASSERT_TRUE(MIMETypeRegistry::canShowMIMEType("application/x-ecmascript"));
+
+    ASSERT_FALSE(MIMETypeRegistry::canShowMIMEType("foo/bar"));
+    ASSERT_FALSE(MIMETypeRegistry::canShowMIMEType("text/vcard"));
+}
+
+} // namespace TestWebKitAPI

Added: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKNavigationResponse.mm (0 => 221778)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKNavigationResponse.mm	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKNavigationResponse.mm	2017-09-08 06:21:29 UTC (rev 221778)
@@ -0,0 +1,127 @@
+/*
+ * Copyright (C) 2017 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "config.h"
+
+#if WK_API_ENABLED
+
+#import "Utilities.h"
+#import <WebKit/WebKit.h>
+#import <wtf/RetainPtr.h>
+
+static bool isDone;
+
+@interface WKNavigationResponseTestNavigationDelegate : NSObject <WKNavigationDelegate>
+@property (nonatomic) BOOL expectation;
+@end
+
+@implementation WKNavigationResponseTestNavigationDelegate
+
+- (void)webView:(WKWebView *)webView decidePolicyForNavigationResponse:(WKNavigationResponse *)navigationResponse decisionHandler:(void (^)(WKNavigationResponsePolicy))decisionHandler
+{
+    EXPECT_EQ(navigationResponse.canShowMIMEType, self.expectation);
+    decisionHandler(WKNavigationResponsePolicyAllow);
+}
+
+- (void)webView:(WKWebView *)webView didCommitNavigation:(WKNavigation *)navigation
+{
+    isDone = true;
+}
+
+@end
+
+@interface WKNavigationResponseTestSchemeHandler : NSObject <WKURLSchemeHandler>
+@property (nonatomic, copy) NSString *mimeType;
+@end
+
+@implementation WKNavigationResponseTestSchemeHandler
+
+- (void)webView:(WKWebView *)webView startURLSchemeTask:(id <WKURLSchemeTask>)task
+{
+    RetainPtr<NSURLResponse> response = adoptNS([[NSURLResponse alloc] initWithURL:[NSURL URLWithString:@"test:///json-response"] MIMEType:self.mimeType expectedContentLength:1 textEncodingName:nil]);
+    [task didReceiveResponse:response.get()];
+    [task didReceiveData:[@"{\"data\":1234}" dataUsingEncoding:NSUTF8StringEncoding]];
+    [task didFinish];
+}
+
+- (void)webView:(WKWebView *)webView stopURLSchemeTask:(id <WKURLSchemeTask>)urlSchemeTask { }
+
+@end
+
+TEST(WebKit, WKNavigationResponseJSONMIMEType)
+{
+    isDone = false;
+    auto schemeHandler = adoptNS([[WKNavigationResponseTestSchemeHandler alloc] init]);
+    auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+    [configuration setURLSchemeHandler:schemeHandler.get() forURLScheme:@"test"];
+    auto webView = adoptNS([[WKWebView alloc] initWithFrame:CGRectMake(0, 0, 800, 600) configuration:configuration.get()]);
+    auto navigationDelegate = adoptNS([[WKNavigationResponseTestNavigationDelegate alloc] init]);
+    webView.get().navigationDelegate = navigationDelegate.get();
+
+    schemeHandler.get().mimeType = @"application/json";
+    navigationDelegate.get().expectation = YES;
+
+    NSURL *testURL = [NSURL URLWithString:@"test:///json-response"];
+    [webView loadRequest:[NSURLRequest requestWithURL:testURL]];
+    TestWebKitAPI::Util::run(&isDone);
+}
+
+TEST(WebKit, WKNavigationResponseJSONMIMEType2)
+{
+    isDone = false;
+    auto schemeHandler = adoptNS([[WKNavigationResponseTestSchemeHandler alloc] init]);
+    auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+    [configuration setURLSchemeHandler:schemeHandler.get() forURLScheme:@"test"];
+    auto webView = adoptNS([[WKWebView alloc] initWithFrame:CGRectMake(0, 0, 800, 600) configuration:configuration.get()]);
+    auto navigationDelegate = adoptNS([[WKNavigationResponseTestNavigationDelegate alloc] init]);
+    webView.get().navigationDelegate = navigationDelegate.get();
+
+    schemeHandler.get().mimeType = @"application/vnd.api+json";
+    navigationDelegate.get().expectation = YES;
+
+    NSURL *testURL = [NSURL URLWithString:@"test:///json-response"];
+    [webView loadRequest:[NSURLRequest requestWithURL:testURL]];
+    TestWebKitAPI::Util::run(&isDone);
+}
+
+TEST(WebKit, WKNavigationResponseUnknownMIMEType)
+{
+    isDone = false;
+    auto schemeHandler = adoptNS([[WKNavigationResponseTestSchemeHandler alloc] init]);
+    auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+    [configuration setURLSchemeHandler:schemeHandler.get() forURLScheme:@"test"];
+    auto webView = adoptNS([[WKWebView alloc] initWithFrame:CGRectMake(0, 0, 800, 600) configuration:configuration.get()]);
+    auto navigationDelegate = adoptNS([[WKNavigationResponseTestNavigationDelegate alloc] init]);
+    webView.get().navigationDelegate = navigationDelegate.get();
+
+    schemeHandler.get().mimeType = @"garbage/json";
+    navigationDelegate.get().expectation = NO;
+
+    NSURL *testURL = [NSURL URLWithString:@"test:///json-response"];
+    [webView loadRequest:[NSURLRequest requestWithURL:testURL]];
+    TestWebKitAPI::Util::run(&isDone);
+}
+
+#endif // WK_API_ENABLED
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to