WebKit Bugzilla
Attachment 346739 Details for
Bug 188290
: Add a test for using SafeBrowsing
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch
bug-188290-20180807154318.patch (text/plain), 10.10 KB, created by
Alex Christensen
on 2018-08-07 15:43:19 PDT
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
Alex Christensen
Created:
2018-08-07 15:43:19 PDT
Size:
10.10 KB
patch
obsolete
>Index: Tools/ChangeLog >=================================================================== >--- Tools/ChangeLog (revision 234655) >+++ Tools/ChangeLog (working copy) >@@ -1,3 +1,18 @@ >+2018-08-07 Alex Christensen <achristensen@webkit.org> >+ >+ Add a test for using SafeBrowsing >+ https://bugs.webkit.org/show_bug.cgi?id=188290 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ Swizzle out SSBLookupContext to write tests for how WebKit responds when it responds in different ways. >+ We don't do anything with its results in WebKit yet, but when we do I'll add the expected behavior to this test. >+ >+ * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: >+ * TestWebKitAPI/Tests/WebKitCocoa/SafeBrowsing.mm: Added. >+ (-[SafeBrowsingDelegate webView:didFinishNavigation:]): >+ (TestWebKitAPI::TEST): >+ > 2018-08-07 Don Olmstead <don.olmstead@sony.com> > > [MiniBrowser][Win] Allow selection of recent user agents >Index: Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj >=================================================================== >--- Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (revision 234655) >+++ Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (working copy) >@@ -283,6 +283,7 @@ > 5C9E59431D3EB5AC00E3C62E /* ApplicationCache.db-wal in Copy Resources */ = {isa = PBXBuildFile; fileRef = 5C9E59401D3EB1DE00E3C62E /* ApplicationCache.db-wal */; }; > 5CA1DEC81F71F70100E71BD3 /* HTTPHeaderField.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5CA1DEC71F71F40700E71BD3 /* HTTPHeaderField.cpp */; }; > 5CA1DED91F74A91A00E71BD3 /* ContentRuleListNotification.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5CA1DED81F74A87100E71BD3 /* ContentRuleListNotification.mm */; }; >+ 5CA985532113CF780057EB6B /* SafeBrowsing.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5CA985512113CB8C0057EB6B /* SafeBrowsing.mm */; }; > 5CAE463820193B6A0051610F /* NetworkProcessCrashNonPersistentDataStore.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5CAE4637201937CD0051610F /* NetworkProcessCrashNonPersistentDataStore.mm */; }; > 5CB18BA81F5645E300EE23C4 /* ClickAutoFillButton.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5CB18BA71F5645B200EE23C4 /* ClickAutoFillButton.mm */; }; > 5CB3CE391FA1697F00C3A2D6 /* WKWebViewConfiguration.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5CB3CE381FA1691700C3A2D6 /* WKWebViewConfiguration.mm */; }; >@@ -1553,6 +1554,7 @@ > 5C9E59401D3EB1DE00E3C62E /* ApplicationCache.db-wal */ = {isa = PBXFileReference; lastKnownFileType = file; path = "ApplicationCache.db-wal"; sourceTree = "<group>"; }; > 5CA1DEC71F71F40700E71BD3 /* HTTPHeaderField.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = HTTPHeaderField.cpp; sourceTree = "<group>"; }; > 5CA1DED81F74A87100E71BD3 /* ContentRuleListNotification.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ContentRuleListNotification.mm; sourceTree = "<group>"; }; >+ 5CA985512113CB8C0057EB6B /* SafeBrowsing.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = SafeBrowsing.mm; sourceTree = "<group>"; }; > 5CAE4637201937CD0051610F /* NetworkProcessCrashNonPersistentDataStore.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = NetworkProcessCrashNonPersistentDataStore.mm; sourceTree = "<group>"; }; > 5CB18BA71F5645B200EE23C4 /* ClickAutoFillButton.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ClickAutoFillButton.mm; sourceTree = "<group>"; }; > 5CB3CE381FA1691700C3A2D6 /* WKWebViewConfiguration.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKWebViewConfiguration.mm; sourceTree = "<group>"; }; >@@ -2346,6 +2348,7 @@ > 51C8E1A41F26AC5400BF731B /* ResourceLoadStatistics.mm */, > A180C0F91EE67DF000468F47 /* RunOpenPanel.mm */, > F4D2986D20FEE7370092D636 /* RunScriptAfterDocumentLoad.mm */, >+ 5CA985512113CB8C0057EB6B /* SafeBrowsing.mm */, > CE0947362063223B003C9BA0 /* SchemeRegistry.mm */, > 51EB12931FDF050500A5A1BD /* ServiceWorkerBasic.mm */, > 41882F0221010A70002FF288 /* SetMaximumPrewarmedProcessCount.mm */, >@@ -3874,6 +3877,7 @@ > F418BE151F71B7DC001970E6 /* RoundedRectTests.cpp in Sources */, > A180C0FA1EE67DF000468F47 /* RunOpenPanel.mm in Sources */, > F4D2986E20FEE7370092D636 /* RunScriptAfterDocumentLoad.mm in Sources */, >+ 5CA985532113CF780057EB6B /* SafeBrowsing.mm in Sources */, > CDCFA7AA1E45183200C2433D /* SampleMap.cpp in Sources */, > CE0947372063223B003C9BA0 /* SchemeRegistry.mm in Sources */, > 7CCE7F121A411AE600447C4C /* ScrollPinningBehaviors.cpp in Sources */, >Index: Tools/TestWebKitAPI/Tests/WebKitCocoa/SafeBrowsing.mm >=================================================================== >--- Tools/TestWebKitAPI/Tests/WebKitCocoa/SafeBrowsing.mm (nonexistent) >+++ Tools/TestWebKitAPI/Tests/WebKitCocoa/SafeBrowsing.mm (working copy) >@@ -0,0 +1,167 @@ >+/* >+ * Copyright (C) 2018 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 ((PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101300) || (PLATFORM(IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 110000)) && !defined(__i386__) && !PLATFORM(IOSMAC) >+ >+#import "ClassMethodSwizzler.h" >+#import "PlatformUtilities.h" >+#import <WebKit/WKNavigationDelegate.h> >+#import <WebKit/WKWebViewPrivate.h> >+#import <wtf/NeverDestroyed.h> >+#import <wtf/RetainPtr.h> >+ >+static bool done; >+ >+@interface SafeBrowsingNavigationDelegate : NSObject <WKNavigationDelegate> >+@end >+ >+@implementation SafeBrowsingNavigationDelegate >+ >+- (void)webView:(WKWebView *)webView didFinishNavigation:(null_unspecified WKNavigation *)navigation >+{ >+ done = true; >+} >+ >+@end >+ >+@interface TestServiceLookupResult : NSObject { >+ RetainPtr<NSString> _provider; >+ BOOL _isPhishing; >+ BOOL _isMalware; >+ BOOL _isUnwantedSoftware; >+ BOOL _isKnownToBeUnsafe; >+} >+@end >+ >+@implementation TestServiceLookupResult >+ >++ (instancetype)resultWithProvider:(RetainPtr<NSString>&&)provider phishing:(BOOL)phishing malware:(BOOL)malware unwantedSoftware:(BOOL)unwantedSoftware knownToBeUnsafe:(BOOL)knownToBeUnsafe >+{ >+ TestServiceLookupResult *result = [[TestServiceLookupResult alloc] init]; >+ if (!result) >+ return nil; >+ >+ result->_provider = WTFMove(provider); >+ result->_isPhishing = phishing; >+ result->_isMalware = malware; >+ result->_isUnwantedSoftware = unwantedSoftware; >+ result->_isKnownToBeUnsafe = knownToBeUnsafe; >+ >+ return [result autorelease]; >+} >+ >+- (NSString *)provider >+{ >+ return _provider.get(); >+} >+ >+- (BOOL)isPhishing >+{ >+ return _isPhishing; >+} >+ >+- (BOOL)isMalware >+{ >+ return _isMalware; >+} >+ >+- (BOOL)isUnwantedSoftware >+{ >+ return _isUnwantedSoftware; >+} >+ >+- (BOOL)isKnownToBeUnsafe >+{ >+ return _isKnownToBeUnsafe; >+} >+ >+@end >+ >+@interface TestLookupResult : NSObject { >+ RetainPtr<NSArray> _results; >+} >+@end >+ >+@implementation TestLookupResult >+ >++ (instancetype)resultWithResults:(RetainPtr<NSArray<TestServiceLookupResult *>>&&)results >+{ >+ TestLookupResult *result = [[TestLookupResult alloc] init]; >+ if (!result) >+ return nil; >+ >+ result->_results = WTFMove(results); >+ >+ return [result autorelease]; >+} >+ >+- (NSArray<TestServiceLookupResult *> *)serviceLookupResults >+{ >+ return _results.get(); >+} >+ >+@end >+ >+@interface TestLookupContext : NSObject >+@end >+ >+@implementation TestLookupContext >+ >++ (TestLookupContext *)sharedLookupContext >+{ >+ static NeverDestroyed<RetainPtr<TestLookupContext>> context; >+ if (!context.get()) >+ context.get() = adoptNS([[TestLookupContext alloc] init]); >+ return context.get().get(); >+} >+ >+- (void)lookUpURL:(NSURL *)URL completionHandler:(void (^)(TestLookupResult *, NSError *))completionHandler >+{ >+ completionHandler([TestLookupResult resultWithResults:@[[TestServiceLookupResult resultWithProvider:@"TestProvider" phishing:YES malware:NO unwantedSoftware:NO knownToBeUnsafe:NO]]], nil); >+} >+ >+@end >+ >+namespace TestWebKitAPI { >+ >+TEST(WebKit, SafeBrowsing) >+{ >+ ClassMethodSwizzler swizzler(objc_getClass("SSBLookupContext"), @selector(sharedLookupContext), [TestLookupContext methodForSelector:@selector(sharedLookupContext)]); >+ >+ auto navigationDelegate = adoptNS([[SafeBrowsingNavigationDelegate alloc] init]); >+ auto webView = adoptNS([[WKWebView alloc] init]); >+ [webView setNavigationDelegate:navigationDelegate.get()]; >+ [webView loadRequest:[NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"simple" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]]]; >+ >+ // FIXME: Check that the loading happens as expected once we do something with safe browsing results. >+ >+ TestWebKitAPI::Util::run(&done); >+} >+ >+} // namespace TestWebKitAPI >+ >+#endif // WK_API_ENABLED
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Flags:
cdumez
:
review+
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 188290
:
346437
|
346476
|
346501
|
346506
| 346739