Changeset 149194 in webkit
- Timestamp:
- Apr 26, 2013 9:55:12 AM (11 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 11 edited
- 3 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit2/ChangeLog
r149192 r149194 1 2013-04-25 Andy Estes <aestes@apple.com> 2 3 [WebKit2] Loading a resource from a custom protocol in a synchronous XHR times out 4 https://bugs.webkit.org/show_bug.cgi?id=115223 5 6 Reviewed by Darin Adler. 7 8 When WebKit performs a synchronous load on the Mac, it spins a nested 9 run loop in a mode that only accepts input from the NSURLConnection 10 performing the load. When the load is for a custom protocol in WebKit2, 11 we proxy it to the UI process via CoreIPC messages, but the response 12 messages from the UI process are never processed as long as the run 13 loop is in a non-common mode (and we wouldn't want to process messages 14 that could re-enter WebCore in the middle of loading, anyway). Since 15 these messages never make it back to the NSURLConnection handling the 16 request, the connection eventually times out. 17 18 Fix this by using a work queue to handle custom protocol messages in 19 the networking process. The work queue can process incoming custom 20 protocol messages while the main thread is blocked. 21 22 * NetworkProcess/NetworkProcess.cpp: 23 (WebKit::NetworkProcess::initializeConnection): Called 24 initializeConnection() on all the NetworkProcess's supplements. 25 * Shared/ChildProcessSupplement.h: Added a base class for 26 NetworkProcessSupplement and WebProcessSupplement which defines 27 initializeConnection and provides an empty default implementation. 28 (WebKit::ChildProcessSupplement::~ChildProcessSupplement): 29 (WebKit::ChildProcessSupplement::initializeConnection): 30 * Shared/Network/CustomProtocols/CustomProtocolManager.h: 31 * Shared/Network/CustomProtocols/mac/CustomProtocolManagerMac.mm: 32 (WebKit::CustomProtocolManager::CustomProtocolManager): Instantiated a 33 work queue for message processing. 34 (WebKit::CustomProtocolManager::initializeConnection): Added the work 35 queue as a message receiver on the CoreIPC connection. 36 (WebKit::CustomProtocolManager::initialize): If we're in the web 37 process and the network process is being used, unregister and destroy 38 the work queue we previously created. It'd be better to not create it 39 in the first place, but we have to register our work queue with the 40 CoreIPC connection before it is established, which is before the UI 41 process has told us whether the network process is in use. 42 * Shared/Network/NetworkProcessSupplement.h: Inherited from 43 ChildProcessSupplement. 44 * WebKit2.xcodeproj/project.pbxproj: Added ChildProcessSupplement.h. 45 * WebProcess/WebProcess.cpp: 46 (WebKit::WebProcess::initializeConnection): Called 47 initializeConnection() on all the WebProcess's supplements. 48 * WebProcess/WebProcessSupplement.h: Inherited from 49 ChildProcessSupplement. 50 1 51 2013-04-26 Eduardo Lima Mitev <elima@igalia.com> 2 52 -
trunk/Source/WebKit2/NetworkProcess/NetworkProcess.cpp
r147251 r149194 175 175 SecItemShim::shared().initializeConnection(connection); 176 176 #endif 177 178 NetworkProcessSupplementMap::const_iterator it = m_supplements.begin(); 179 NetworkProcessSupplementMap::const_iterator end = m_supplements.end(); 180 for (; it != end; ++it) 181 it->value->initializeConnection(connection); 177 182 } 178 183 -
trunk/Source/WebKit2/Shared/ChildProcessSupplement.h
r149193 r149194 1 1 /* 2 * Copyright (C) 201 2Apple Inc. All rights reserved.2 * Copyright (C) 2013 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 24 24 */ 25 25 26 #ifndef WebProcessSupplement_h 27 #define WebProcessSupplement_h 26 #ifndef ChildProcessSupplement_h 27 #define ChildProcessSupplement_h 28 29 namespace CoreIPC { 30 class Connection; 31 } // namespace CoreIPC 28 32 29 33 namespace WebKit { 30 34 31 struct WebProcessCreationParameters; 32 33 class WebProcessSupplement { 35 class ChildProcessSupplement { 34 36 public: 35 virtual ~ WebProcessSupplement()37 virtual ~ChildProcessSupplement() 36 38 { 37 39 } 38 40 39 virtual void initialize (const WebProcessCreationParameters&)41 virtual void initializeConnection(CoreIPC::Connection*) 40 42 { 41 43 } … … 44 46 } // namespace WebKit 45 47 46 #endif // WebProcessSupplement_h48 #endif // ChildProcessSupplement_h -
trunk/Source/WebKit2/Shared/Network/CustomProtocols/CustomProtocolManager.h
r149121 r149194 29 29 #if ENABLE(CUSTOM_PROTOCOLS) 30 30 31 #include " MessageReceiver.h"31 #include "Connection.h" 32 32 #include "NetworkProcessSupplement.h" 33 33 #include "WebProcessSupplement.h" 34 #include "WorkQueue.h" 34 35 #include <wtf/HashSet.h> 35 36 #include <wtf/Threading.h> … … 57 58 struct NetworkProcessCreationParameters; 58 59 59 class CustomProtocolManager : public WebProcessSupplement, public NetworkProcessSupplement, public CoreIPC:: MessageReceiver {60 class CustomProtocolManager : public WebProcessSupplement, public NetworkProcessSupplement, public CoreIPC::Connection::WorkQueueMessageReceiver { 60 61 WTF_MAKE_NONCOPYABLE(CustomProtocolManager); 61 62 public: … … 76 77 77 78 private: 79 // ChildProcessSupplement 80 void initializeConnection(CoreIPC::Connection*) OVERRIDE; 81 78 82 // WebProcessSupplement 79 83 void initialize(const WebProcessCreationParameters&) OVERRIDE; … … 94 98 HashSet<String> m_registeredSchemes; 95 99 ChildProcess* m_childProcess; 100 RefPtr<WorkQueue> m_messageQueue; 96 101 97 102 #if PLATFORM(MAC) -
trunk/Source/WebKit2/Shared/Network/CustomProtocols/mac/CustomProtocolManagerMac.mm
r149121 r149194 117 117 CustomProtocolManager::CustomProtocolManager(ChildProcess* childProcess) 118 118 : m_childProcess(childProcess) 119 { 120 m_childProcess->addMessageReceiver(Messages::CustomProtocolManager::messageReceiverName(), this); 121 119 , m_messageQueue(WorkQueue::create("com.apple.WebKit.CustomProtocolManager")) 120 { 122 121 ASSERT(!sharedCustomProtocolManager); 123 122 sharedCustomProtocolManager = this; 124 123 } 125 124 125 void CustomProtocolManager::initializeConnection(CoreIPC::Connection* connection) 126 { 127 connection->addWorkQueueMessageReceiver(Messages::CustomProtocolManager::messageReceiverName(), m_messageQueue.get(), this); 128 } 129 126 130 void CustomProtocolManager::initialize(const WebProcessCreationParameters& parameters) 127 131 { 128 132 #if ENABLE(NETWORK_PROCESS) 129 133 ASSERT(parameters.urlSchemesRegisteredForCustomProtocols.isEmpty() || !parameters.usesNetworkProcess); 130 if (parameters.usesNetworkProcess) 131 return; 134 if (parameters.usesNetworkProcess) { 135 m_childProcess->connection()->removeWorkQueueMessageReceiver(Messages::CustomProtocolManager::messageReceiverName()); 136 m_messageQueue = nullptr; 137 return; 138 } 132 139 #endif 133 140 -
trunk/Source/WebKit2/Shared/Network/NetworkProcessSupplement.h
r138569 r149194 27 27 #define NetworkProcessSupplement_h 28 28 29 #include "ChildProcessSupplement.h" 30 29 31 namespace WebKit { 30 32 31 33 struct NetworkProcessCreationParameters; 32 34 33 class NetworkProcessSupplement {35 class NetworkProcessSupplement : public ChildProcessSupplement { 34 36 #if ENABLE(NETWORK_PROCESS) 35 37 public: 36 virtual ~NetworkProcessSupplement()37 {38 }39 40 38 virtual void initialize(const NetworkProcessCreationParameters&) 41 39 { -
trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj
r149107 r149194 296 296 1QQ417CB12C00CCA002BE67B /* TextCheckerCompletion.h in Headers */ = {isa = PBXBuildFile; fileRef = 1CC417C912C00CCA002BE67B /* TextCheckerCompletion.h */; }; 297 297 1ZZ417EF12C00D87002BE67B /* TextCheckerCompletion.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1BB417C912C00CCA002BE67B /* TextCheckerCompletion.cpp */; }; 298 290F4272172A0C7400939FF0 /* ChildProcessSupplement.h in Headers */ = {isa = PBXBuildFile; fileRef = 290F4271172A0C7400939FF0 /* ChildProcessSupplement.h */; }; 298 299 293EBEAB1627D9C9005F89F1 /* WKDOMText.h in Headers */ = {isa = PBXBuildFile; fileRef = 293EBEA91627D9C9005F89F1 /* WKDOMText.h */; settings = {ATTRIBUTES = (Public, ); }; }; 299 300 293EBEAC1627D9C9005F89F1 /* WKDOMText.mm in Sources */ = {isa = PBXBuildFile; fileRef = 293EBEAA1627D9C9005F89F1 /* WKDOMText.mm */; }; … … 1720 1721 1CBC945D16515ED200D68AAE /* DockBottom.pdf */ = {isa = PBXFileReference; lastKnownFileType = image.pdf; name = DockBottom.pdf; path = Resources/DockBottom.pdf; sourceTree = "<group>"; }; 1721 1722 1CC417C912C00CCA002BE67B /* TextCheckerCompletion.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TextCheckerCompletion.h; sourceTree = "<group>"; }; 1723 290F4271172A0C7400939FF0 /* ChildProcessSupplement.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ChildProcessSupplement.h; sourceTree = "<group>"; }; 1722 1724 293EBEA91627D9C9005F89F1 /* WKDOMText.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKDOMText.h; sourceTree = "<group>"; }; 1723 1725 293EBEAA1627D9C9005F89F1 /* WKDOMText.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKDOMText.mm; sourceTree = "<group>"; }; … … 3205 3207 E1513C64166EABB200149FCB /* ChildProcessProxy.cpp */, 3206 3208 E1513C65166EABB200149FCB /* ChildProcessProxy.h */, 3209 290F4271172A0C7400939FF0 /* ChildProcessSupplement.h */, 3207 3210 1A6F9F8E11E13EFC00DB1371 /* CommandLine.h */, 3208 3211 5136183B163126DA00A99DDE /* ConnectionStack.cpp */, … … 5618 5621 BC646C1D11DD399F006455B0 /* WKBackForwardListItem.h in Headers */, 5619 5622 BCDDB317124EBD130048D13C /* WKBase.h in Headers */, 5623 290F4272172A0C7400939FF0 /* ChildProcessSupplement.h in Headers */, 5620 5624 BCBAAC73144E619E0053F82F /* WKBrowsingContextController.h in Headers */, 5621 5625 BCBAAC74144E61A50053F82F /* WKBrowsingContextControllerInternal.h in Headers */, -
trunk/Source/WebKit2/WebProcess/WebProcess.cpp
r149074 r149194 230 230 SecItemShim::shared().initializeConnection(connection); 231 231 #endif 232 233 WebProcessSupplementMap::const_iterator it = m_supplements.begin(); 234 WebProcessSupplementMap::const_iterator end = m_supplements.end(); 235 for (; it != end; ++it) 236 it->value->initializeConnection(connection); 232 237 233 238 m_webConnection = WebConnectionToUIProcess::create(this); -
trunk/Source/WebKit2/WebProcess/WebProcessSupplement.h
r138569 r149194 27 27 #define WebProcessSupplement_h 28 28 29 #include "ChildProcessSupplement.h" 30 29 31 namespace WebKit { 30 32 31 33 struct WebProcessCreationParameters; 32 34 33 class WebProcessSupplement {35 class WebProcessSupplement : public ChildProcessSupplement { 34 36 public: 35 virtual ~WebProcessSupplement()36 {37 }38 39 37 virtual void initialize(const WebProcessCreationParameters&) 40 38 { -
trunk/Tools/ChangeLog
r149193 r149194 1 2013-04-25 Andy Estes <aestes@apple.com> 2 3 [WebKit2] Loading a resource from a custom protocol in a synchronous XHR times out 4 https://bugs.webkit.org/show_bug.cgi?id=115223 5 6 Reviewed by Darin Adler. 7 8 Added an API test. 9 10 * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: Added new files. 11 * TestWebKitAPI/Tests/CustomProtocolsSyncXHRTest.mm: Added. 12 (TestWebKitAPI::TEST): Tested that a synchronous XHR does not time out 13 when it loads a request with a custom protocol. 14 * TestWebKitAPI/Tests/WebKit2/custom-protocol-sync-xhr.html: Added. 15 * TestWebKitAPI/Tests/WebKit2ObjC/CustomProtocolsTest.mm: Moved the 16 NSURLProtocol subclass to TestProtocol.{h, mm} and did some 17 miscellaneous cleanup. 18 * TestWebKitAPI/mac/TestProtocol.h: Copied from Source/WebKit2/WebProcess/WebProcessSupplement.h. 19 * TestWebKitAPI/mac/TestProtocol.mm: Copied from Tools/TestWebKitAPI/Tests/WebKit2ObjC/CustomProtocolsTest.mm. 20 (+[TestProtocol canInitWithRequest:]): 21 (+[TestProtocol canonicalRequestForRequest:]): 22 (+[TestProtocol requestIsCacheEquivalent:toRequest:]): 23 (+[TestProtocol scheme]): 24 (-[TestProtocol startLoading]): 25 (-[TestProtocol stopLoading]): 26 1 27 2013-04-26 Martin Robinson <mrobinson@igalia.com> 2 28 -
trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
r148921 r149194 36 36 26F1B44415CA434F00D1E4BF /* AtomicString.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 26F1B44215CA434F00D1E4BF /* AtomicString.cpp */; }; 37 37 26F1B44515CA434F00D1E4BF /* StringImpl.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 26F1B44315CA434F00D1E4BF /* StringImpl.cpp */; }; 38 290F4275172A221C00939FF0 /* custom-protocol-sync-xhr.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 290F4274172A1FDE00939FF0 /* custom-protocol-sync-xhr.html */; }; 39 290F4278172A232C00939FF0 /* CustomProtocolsSyncXHRTest.mm in Sources */ = {isa = PBXBuildFile; fileRef = 290F4276172A232C00939FF0 /* CustomProtocolsSyncXHRTest.mm */; }; 40 290F427B172A23A500939FF0 /* TestProtocol.mm in Sources */ = {isa = PBXBuildFile; fileRef = 290F4279172A23A500939FF0 /* TestProtocol.mm */; }; 38 41 2943BE86161DFEB800999E3D /* UserContentTest.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2943BE84161DFEB800999E3D /* UserContentTest.mm */; }; 39 42 29AB8AA1164C735800D49BEC /* CustomProtocolsTest.mm in Sources */ = {isa = PBXBuildFile; fileRef = 29AB8A9F164C735800D49BEC /* CustomProtocolsTest.mm */; }; … … 233 236 dstSubfolderSpec = 7; 234 237 files = ( 238 290F4275172A221C00939FF0 /* custom-protocol-sync-xhr.html in Copy Resources */, 235 239 C2CF975B16CEC71B0054E99D /* JSContextBackForwardCache1.html in Copy Resources */, 236 240 C2CF975A16CEC7140054E99D /* JSContextBackForwardCache2.html in Copy Resources */, … … 303 307 26F1B44215CA434F00D1E4BF /* AtomicString.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = AtomicString.cpp; path = WTF/AtomicString.cpp; sourceTree = "<group>"; }; 304 308 26F1B44315CA434F00D1E4BF /* StringImpl.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = StringImpl.cpp; path = WTF/StringImpl.cpp; sourceTree = "<group>"; }; 309 290F4274172A1FDE00939FF0 /* custom-protocol-sync-xhr.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "custom-protocol-sync-xhr.html"; sourceTree = "<group>"; }; 310 290F4276172A232C00939FF0 /* CustomProtocolsSyncXHRTest.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = CustomProtocolsSyncXHRTest.mm; sourceTree = "<group>"; }; 311 290F4279172A23A500939FF0 /* TestProtocol.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = TestProtocol.mm; sourceTree = "<group>"; }; 312 290F427A172A23A500939FF0 /* TestProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TestProtocol.h; sourceTree = "<group>"; }; 305 313 2943BE84161DFEB800999E3D /* UserContentTest.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = UserContentTest.mm; path = WebKit2ObjC/UserContentTest.mm; sourceTree = "<group>"; }; 306 314 29AB8A9F164C735800D49BEC /* CustomProtocolsTest.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = CustomProtocolsTest.mm; path = WebKit2ObjC/CustomProtocolsTest.mm; sourceTree = "<group>"; }; … … 599 607 children = ( 600 608 29AB8A9F164C735800D49BEC /* CustomProtocolsTest.mm */, 609 290F4276172A232C00939FF0 /* CustomProtocolsSyncXHRTest.mm */, 601 610 2943BE84161DFEB800999E3D /* UserContentTest.mm */, 602 611 BC3C4C7D14587AA60025FB62 /* WKBrowsingContextGroupTest.mm */, … … 746 755 C045F9461385C2F800C0F3CD /* 18-characters.html */, 747 756 76E182DE15475A8300F1FADD /* auto-submitting-form.html */, 757 290F4274172A1FDE00939FF0 /* custom-protocol-sync-xhr.html */, 748 758 C5E1AFFD16B22179006CC1F2 /* execCopy.html */, 749 759 BC2D004A12A9FEB300E732A3 /* file-with-anchor.html */, … … 780 790 29AB8AA3164C7A9300D49BEC /* TestBrowsingContextLoadDelegate.h */, 781 791 29AB8AA2164C7A9300D49BEC /* TestBrowsingContextLoadDelegate.mm */, 792 290F427A172A23A500939FF0 /* TestProtocol.h */, 793 290F4279172A23A500939FF0 /* TestProtocol.mm */, 782 794 C08587BE13FE956C001EF4E5 /* WebKitAgnosticTest.h */, 783 795 C08587BD13FE956C001EF4E5 /* WebKitAgnosticTest.mm */, … … 1023 1035 BCBD3710125AA2EB00D2C29F /* FrameMIMETypeHTML.cpp in Sources */, 1024 1036 BCBD3761125ABCFE00D2C29F /* FrameMIMETypePNG.cpp in Sources */, 1037 290F427B172A23A500939FF0 /* TestProtocol.mm in Sources */, 1025 1038 1AA9E55914980A9900001A8A /* Functional.cpp in Sources */, 1026 1039 C0C5D3BE14598B6F00A802A6 /* GetBackingScaleFactor.mm in Sources */, … … 1105 1118 520BCF4D141EB09E00937EA8 /* WebArchive.cpp in Sources */, 1106 1119 0F17BBD615AF6C4D007AB753 /* WebCoreStatisticsWithNoWebProcess.cpp in Sources */, 1120 290F4278172A232C00939FF0 /* CustomProtocolsSyncXHRTest.mm in Sources */, 1107 1121 C08587BF13FE956C001EF4E5 /* WebKitAgnosticTest.mm in Sources */, 1108 1122 51FBBB4D1513D4E900822738 /* WebViewCanPasteURL.mm in Sources */, -
trunk/Tools/TestWebKitAPI/Tests/WebKit2ObjC/CustomProtocolsTest.mm
r134681 r149194 29 29 #import "PlatformUtilities.h" 30 30 #import "TestBrowsingContextLoadDelegate.h" 31 #import <Foundation/Foundation.h>31 #import "TestProtocol.h" 32 32 #import <WebKit2/WebKit2.h> 33 33 34 static NSString *testScheme = @"test";35 static NSString *testHost = @"test";36 34 static bool testFinished = false; 37 35 38 @interface TestProtocol : NSURLProtocol { 39 } 40 @end 36 namespace TestWebKitAPI { 41 37 42 @implementation TestProtocol 43 44 + (BOOL)canInitWithRequest:(NSURLRequest *)request 45 { 46 return [[[request URL] scheme] caseInsensitiveCompare:testScheme] == NSOrderedSame; 47 } 48 49 + (NSURLRequest *)canonicalRequestForRequest:(NSURLRequest *)request 50 { 51 return request; 52 } 53 54 + (BOOL)requestIsCacheEquivalent:(NSURLRequest *)a toRequest:(NSURLRequest *)b 55 { 56 return NO; 57 } 58 59 - (void)startLoading 60 { 61 EXPECT_TRUE([[[[self request] URL] scheme] isEqualToString:testScheme]); 62 EXPECT_TRUE([[[[self request] URL] host] isEqualToString:testHost]); 63 64 NSData *data = [@"<body>PASS</body>" dataUsingEncoding:NSASCIIStringEncoding]; 65 NSURLResponse *response = [[NSURLResponse alloc] initWithURL:[[self request] URL] MIMEType:@"text/html" expectedContentLength:[data length] textEncodingName:nil]; 66 [[self client] URLProtocol:self didReceiveResponse:response cacheStoragePolicy:NSURLCacheStorageNotAllowed]; 67 [[self client] URLProtocol:self didLoadData:data]; 68 [[self client] URLProtocolDidFinishLoading:self]; 69 [response release]; 70 } 71 72 - (void)stopLoading 73 { 74 } 75 76 @end 77 78 TEST(WebKit2CustomProtocolsTest, CustomProtocolUsed) 38 TEST(WebKit2CustomProtocolsTest, MainResource) 79 39 { 80 40 [NSURLProtocol registerClass:[TestProtocol class]]; 81 [WKBrowsingContextController registerSchemeForCustomProtocol: testScheme];41 [WKBrowsingContextController registerSchemeForCustomProtocol:[TestProtocol scheme]]; 82 42 83 43 WKProcessGroup *processGroup = [[WKProcessGroup alloc] init]; … … 87 47 testFinished = true; 88 48 }]; 89 [wkView.browsingContextController loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@:// %@", testScheme, testHost]]]];49 [wkView.browsingContextController loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@://test", [TestProtocol scheme]]]]]; 90 50 91 TestWebKitAPI::Util::run(&testFinished);51 Util::run(&testFinished); 92 52 } 53 54 } // namespace TestWebKitAPI -
trunk/Tools/TestWebKitAPI/mac/TestProtocol.h
r149193 r149194 1 1 /* 2 * Copyright (C) 201 2Apple Inc. All rights reserved.2 * Copyright (C) 2013 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 24 24 */ 25 25 26 #ifndef WebProcessSupplement_h27 #define WebProcessSupplement_h26 #ifndef TestProtocol_h 27 #define TestProtocol_h 28 28 29 namespace WebKit { 29 @interface TestProtocol : NSURLProtocol { 30 } 31 + (NSString *)scheme; 32 @end 30 33 31 struct WebProcessCreationParameters; 32 33 class WebProcessSupplement { 34 public: 35 virtual ~WebProcessSupplement() 36 { 37 } 38 39 virtual void initialize(const WebProcessCreationParameters&) 40 { 41 } 42 }; 43 44 } // namespace WebKit 45 46 #endif // WebProcessSupplement_h 34 #endif // TestProtocol_h -
trunk/Tools/TestWebKitAPI/mac/TestProtocol.mm
r149193 r149194 1 1 /* 2 * Copyright (C) 201 2Apple Inc. All rights reserved.2 * Copyright (C) 2013 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 25 25 26 26 #import "config.h" 27 #import "Test.h" 28 29 #import "PlatformUtilities.h" 30 #import "TestBrowsingContextLoadDelegate.h" 31 #import <Foundation/Foundation.h> 32 #import <WebKit2/WebKit2.h> 27 #import "TestProtocol.h" 33 28 34 29 static NSString *testScheme = @"test"; 35 static NSString *testHost = @"test";36 static bool testFinished = false;37 38 @interface TestProtocol : NSURLProtocol {39 }40 @end41 30 42 31 @implementation TestProtocol … … 57 46 } 58 47 48 + (NSString *)scheme 49 { 50 return testScheme; 51 } 52 59 53 - (void)startLoading 60 54 { 61 55 EXPECT_TRUE([[[[self request] URL] scheme] isEqualToString:testScheme]); 62 EXPECT_TRUE([[[[self request] URL] host] isEqualToString:testHost]);63 56 64 NSData *data = [@" <body>PASS</body>" dataUsingEncoding:NSASCIIStringEncoding];57 NSData *data = [@"PASS" dataUsingEncoding:NSASCIIStringEncoding]; 65 58 NSURLResponse *response = [[NSURLResponse alloc] initWithURL:[[self request] URL] MIMEType:@"text/html" expectedContentLength:[data length] textEncodingName:nil]; 66 59 [[self client] URLProtocol:self didReceiveResponse:response cacheStoragePolicy:NSURLCacheStorageNotAllowed]; … … 75 68 76 69 @end 77 78 TEST(WebKit2CustomProtocolsTest, CustomProtocolUsed)79 {80 [NSURLProtocol registerClass:[TestProtocol class]];81 [WKBrowsingContextController registerSchemeForCustomProtocol:testScheme];82 83 WKProcessGroup *processGroup = [[WKProcessGroup alloc] init];84 WKBrowsingContextGroup *browsingContextGroup = [[WKBrowsingContextGroup alloc] initWithIdentifier:@"TestIdentifier"];85 WKView *wkView = [[WKView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) processGroup:processGroup browsingContextGroup:browsingContextGroup];86 wkView.browsingContextController.loadDelegate = [[TestBrowsingContextLoadDelegate alloc] initWithBlockToRunOnLoad:^(WKBrowsingContextController *sender) {87 testFinished = true;88 }];89 [wkView.browsingContextController loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@://%@", testScheme, testHost]]]];90 91 TestWebKitAPI::Util::run(&testFinished);92 }
Note: See TracChangeset
for help on using the changeset viewer.