Diff
Modified: trunk/Source/WebKit/ChangeLog (258615 => 258616)
--- trunk/Source/WebKit/ChangeLog 2020-03-18 00:31:23 UTC (rev 258615)
+++ trunk/Source/WebKit/ChangeLog 2020-03-18 00:45:40 UTC (rev 258616)
@@ -1,3 +1,21 @@
+2020-03-17 Kate Cheney <[email protected]>
+
+ Expand In-App-Browser-Privacy testing
+ https://bugs.webkit.org/show_bug.cgi?id=209142
+ <rdar://problem/60496618>
+
+ Reviewed by Darin Adler.
+
+ Adds a testing API to check whether a navigation was classified as
+ app-bound.
+
+ * UIProcess/API/Cocoa/WKWebView.mm:
+ (-[WKWebView _isNavigatingToAppBoundDomain:]):
+ * UIProcess/API/Cocoa/WKWebViewPrivate.h:
+ * UIProcess/WebPageProxy.cpp:
+ (WebKit::WebPageProxy::isNavigatingToAppBoundDomainTesting):
+ * UIProcess/WebPageProxy.h:
+
2020-03-17 Alex Christensen <[email protected]>
Fix API tests after r258574
Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm (258615 => 258616)
--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm 2020-03-18 00:31:23 UTC (rev 258615)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm 2020-03-18 00:45:40 UTC (rev 258616)
@@ -2694,6 +2694,13 @@
_page->recordNavigationSnapshot(item._item);
}
+- (void)_isNavigatingToAppBoundDomain:(void(^)(BOOL))completionHandler
+{
+ _page->isNavigatingToAppBoundDomainTesting([completionHandler = makeBlockPtr(completionHandler)] (bool isAppBound) {
+ completionHandler(isAppBound);
+ });
+}
+
- (void)_setIsNavigatingToAppBoundDomain:(BOOL)isNavigatingToAppBoundDomain completionHandler:(void (^)(void))completionHandler
{
_page->setIsNavigatingToAppBoundDomainTesting(isNavigatingToAppBoundDomain, [completionHandler = makeBlockPtr(completionHandler)]() {
Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivate.h (258615 => 258616)
--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivate.h 2020-03-18 00:31:23 UTC (rev 258615)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivate.h 2020-03-18 00:45:40 UTC (rev 258616)
@@ -340,6 +340,7 @@
- (void)_getProcessDisplayNameWithCompletionHandler:(void (^)(NSString *))completionHandler WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
+- (void)_isNavigatingToAppBoundDomain:(void(^)(BOOL))completionHandler WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
- (void)_setIsNavigatingToAppBoundDomain:(BOOL)isNavigatingToAppBoundDomain completionHandler:(void (^)(void))completionHandler WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
- (void)_grantAccessToPreferenceService WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.cpp (258615 => 258616)
--- trunk/Source/WebKit/UIProcess/WebPageProxy.cpp 2020-03-18 00:31:23 UTC (rev 258615)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.cpp 2020-03-18 00:45:40 UTC (rev 258616)
@@ -3123,6 +3123,11 @@
sendWithAsyncReply(Messages::WebPage::SetIsNavigatingToAppBoundDomainTesting(isNavigatingToAppBoundDomain), WTFMove(completionHandler));
}
+void WebPageProxy::isNavigatingToAppBoundDomainTesting(CompletionHandler<void(bool)>&& completionHandler)
+{
+ completionHandler(m_isNavigatingToAppBoundDomain == NavigatingToAppBoundDomain::Yes);
+}
+
void WebPageProxy::receivedNavigationPolicyDecision(PolicyAction policyAction, API::Navigation* navigation, ProcessSwapRequestedByClient processSwapRequestedByClient, WebFrameProxy& frame, API::WebsitePolicies* policies, Ref<PolicyDecisionSender>&& sender)
{
Ref<WebsiteDataStore> websiteDataStore = m_websiteDataStore.copyRef();
Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.h (258615 => 258616)
--- trunk/Source/WebKit/UIProcess/WebPageProxy.h 2020-03-18 00:31:23 UTC (rev 258615)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.h 2020-03-18 00:45:40 UTC (rev 258616)
@@ -1713,6 +1713,7 @@
#endif
void setIsNavigatingToAppBoundDomainTesting(bool, CompletionHandler<void()>&&);
+ void isNavigatingToAppBoundDomainTesting(CompletionHandler<void(bool)>&&);
private:
WebPageProxy(PageClient&, WebProcessProxy&, Ref<API::PageConfiguration>&&);
Modified: trunk/Tools/ChangeLog (258615 => 258616)
--- trunk/Tools/ChangeLog 2020-03-18 00:31:23 UTC (rev 258615)
+++ trunk/Tools/ChangeLog 2020-03-18 00:45:40 UTC (rev 258616)
@@ -1,3 +1,42 @@
+2020-03-17 Kate Cheney <[email protected]>
+
+ Expand In-App-Browser-Privacy testing
+ https://bugs.webkit.org/show_bug.cgi?id=209142
+ <rdar://problem/60496618>
+
+ Reviewed by Darin Adler.
+
+ Expanded test coverage by adding new tests and creating a custom url
+ scheme handler to get around the fact that local file loads are
+ always classified as app-bound.
+
+ * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+ * TestWebKitAPI/Tests/WebKitCocoa/InAppBrowserPrivacy.mm:
+ (-[InAppBrowserSchemeHandler webView:startURLSchemeTask:]):
+ If the path indicates testing user scripts on load, notify the script message
+ handler that the navigation has finished. If the path indicates
+ testing user-agent scripts, set the window.wkUserScriptInjected
+ variable to true. A user agent script will attempt to read this
+ variable and should fail.
+
+ (-[InAppBrowserSchemeHandler webView:stopURLSchemeTask:]):
+ (initializeInAppBrowserPrivacyTestSettings):
+ Basic test setup. Initialize the main run loop and make sure we are
+ starting with a clean state.
+
+ (TEST):
+ Add tests for all protocols checked in shouldBeTreatedAsAppBound,
+ except for blob files which must be generated within the web content.
+
+ * TestWebKitAPI/Tests/WebKitCocoa/in-app-browser-privacy-local-file.html: Added.
+ Basic html document to test local file loads are classified as
+ app-bound.
+
+ * TestWebKitAPI/Tests/WebKitCocoa/in-app-browser-privacy-test-user-agent-script.html: Removed.
+ * TestWebKitAPI/Tests/WebKitCocoa/in-app-browser-privacy-test-user-script.html: Removed.
+ These files are no longer needed as their content is directly copied
+ into the URL scheme handler.
+
2020-03-17 Chris Dumez <[email protected]>
REGRESSION: [ macOS wk1 ] ASSERTION FAILED: _notifications.contains(notificationID) imported/w3c/web-platform-tests/notifications/constructor-basic.html is flaky crashing
Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (258615 => 258616)
--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj 2020-03-18 00:31:23 UTC (rev 258615)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj 2020-03-18 00:45:40 UTC (rev 258616)
@@ -252,9 +252,8 @@
46FA2FEE23846CA5000CCB0C /* HTTPHeaderMap.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 46FA2FED23846C9A000CCB0C /* HTTPHeaderMap.cpp */; };
46FACF7423E8842300A9EBC6 /* beforeunload-slow.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 46FACF7323E883EE00A9EBC6 /* beforeunload-slow.html */; };
4909EE3A2D09480C88982D56 /* Markable.cpp in Sources */ = {isa = PBXBuildFile; fileRef = EC79F168BE454E579E417B05 /* Markable.cpp */; };
+ 49897D6C241FE9E400ECF153 /* in-app-browser-privacy-local-file.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 49D7FBA7241FDDDA00AB67FA /* in-app-browser-privacy-local-file.html */; };
49AEEF6D2407359D00C87E4C /* InAppBrowserPrivacy.mm in Sources */ = {isa = PBXBuildFile; fileRef = 49AEEF6B2407358600C87E4C /* InAppBrowserPrivacy.mm */; };
- 49AEEF7224073FC900C87E4C /* in-app-browser-privacy-test-user-script.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 49AEEF6E24073F9300C87E4C /* in-app-browser-privacy-test-user-script.html */; };
- 49AEEF7324073FC900C87E4C /* in-app-browser-privacy-test-user-agent-script.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 49AEEF6F24073F9300C87E4C /* in-app-browser-privacy-test-user-agent-script.html */; };
4BFDFFA71314776C0061F24B /* HitTestResultNodeHandle_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4BFDFFA61314776C0061F24B /* HitTestResultNodeHandle_Bundle.cpp */; };
510477721D298DDD009747EB /* IDBDeleteRecovery.sqlite3 in Copy Resources */ = {isa = PBXBuildFile; fileRef = 5104776F1D298D85009747EB /* IDBDeleteRecovery.sqlite3 */; };
510477731D298DDD009747EB /* IDBDeleteRecovery.sqlite3-shm in Copy Resources */ = {isa = PBXBuildFile; fileRef = 510477701D298D85009747EB /* IDBDeleteRecovery.sqlite3-shm */; };
@@ -1349,8 +1348,7 @@
F45B63FB1F197F4A009D38B9 /* image-map.html in Copy Resources */,
3128A8152376413300D90D40 /* image.html in Copy Resources */,
7283A9D022FA754900B21C7D /* img-with-rotated-image.html in Copy Resources */,
- 49AEEF7324073FC900C87E4C /* in-app-browser-privacy-test-user-agent-script.html in Copy Resources */,
- 49AEEF7224073FC900C87E4C /* in-app-browser-privacy-test-user-script.html in Copy Resources */,
+ 49897D6C241FE9E400ECF153 /* in-app-browser-privacy-local-file.html in Copy Resources */,
935786CD20F6A2910000CDFC /* IndexedDB.sqlite3 in Copy Resources */,
935786CE20F6A2A10000CDFC /* IndexedDB.sqlite3-shm in Copy Resources */,
935786CC20F6A2700000CDFC /* IndexedDB.sqlite3-wal in Copy Resources */,
@@ -1860,8 +1858,7 @@
46FACF7323E883EE00A9EBC6 /* beforeunload-slow.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "beforeunload-slow.html"; sourceTree = "<group>"; };
49AEEF682407276F00C87E4C /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
49AEEF6B2407358600C87E4C /* InAppBrowserPrivacy.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = InAppBrowserPrivacy.mm; sourceTree = "<group>"; };
- 49AEEF6E24073F9300C87E4C /* in-app-browser-privacy-test-user-script.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "in-app-browser-privacy-test-user-script.html"; sourceTree = "<group>"; };
- 49AEEF6F24073F9300C87E4C /* in-app-browser-privacy-test-user-agent-script.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "in-app-browser-privacy-test-user-agent-script.html"; sourceTree = "<group>"; };
+ 49D7FBA7241FDDDA00AB67FA /* in-app-browser-privacy-local-file.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = "in-app-browser-privacy-local-file.html"; sourceTree = "<group>"; };
4A410F4B19AF7BD6002EBAB5 /* UserMedia.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = UserMedia.cpp; sourceTree = "<group>"; };
4A410F4D19AF7BEF002EBAB5 /* getUserMedia.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = getUserMedia.html; sourceTree = "<group>"; };
4A410F4D19AF7BEF002EBAB6 /* ondevicechange.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = ondevicechange.html; sourceTree = "<group>"; };
@@ -3514,8 +3511,7 @@
F45B63FA1F197F33009D38B9 /* image-map.html */,
3128A814237640FD00D90D40 /* image.html */,
7283A9CE22FA6BBE00B21C7D /* img-with-rotated-image.html */,
- 49AEEF6F24073F9300C87E4C /* in-app-browser-privacy-test-user-agent-script.html */,
- 49AEEF6E24073F9300C87E4C /* in-app-browser-privacy-test-user-script.html */,
+ 49D7FBA7241FDDDA00AB67FA /* in-app-browser-privacy-local-file.html */,
934FA5C720F69FEE0040DC1B /* IndexedDB.sqlite3 */,
934FA5C620F69FED0040DC1B /* IndexedDB.sqlite3-shm */,
934FA5C520F69FED0040DC1B /* IndexedDB.sqlite3-wal */,
Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/InAppBrowserPrivacy.mm (258615 => 258616)
--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/InAppBrowserPrivacy.mm 2020-03-18 00:31:23 UTC (rev 258615)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/InAppBrowserPrivacy.mm 2020-03-18 00:45:40 UTC (rev 258616)
@@ -34,12 +34,14 @@
#import <WebKit/WKPreferencesPrivate.h>
#import <WebKit/WKUserContentControllerPrivate.h>
#import <WebKit/WKWebsiteDataStorePrivate.h>
+#import <wtf/RunLoop.h>
#import <wtf/text/WTFString.h>
+#if USE(APPLE_INTERNAL_SDK)
+#include <WebKitAdditions/InAppBrowserPrivacyTestAdditions.h>
+
static bool isDone;
-#if USE(APPLE_INTERNAL_SDK)
-
static NSString * const userScriptSource = @"window.wkUserScriptInjected = true";
@interface TestInAppBrowserScriptMessageHandler : NSObject <WKScriptMessageHandler>
@@ -54,23 +56,123 @@
@end
-TEST(InAppBrowserPrivacy, NonAppBoundDomainFailedUserScripts)
+@interface InAppBrowserSchemeHandler : NSObject <WKURLSchemeHandler>
+@end
+
+@implementation InAppBrowserSchemeHandler
+
+- (void)webView:(WKWebView *)webView startURLSchemeTask:(id <WKURLSchemeTask>)task
{
+ NSString *response = nil;
+ if ([task.request.URL.path isEqualToString:@"/in-app-browser-privacy-test-user-script"])
+ response = @"<script>window.webkit.messageHandlers.testInAppBrowserPrivacy.postMessage(\"done\");</script>";
+ else if ([task.request.URL.path isEqualToString:@"/in-app-browser-privacy-test-user-agent-script"])
+ response = @"<script> window.wkUserScriptInjected = true; </script>";
+
+ [task didReceiveResponse:[[[NSURLResponse alloc] initWithURL:task.request.URL MIMEType:@"text/html" expectedContentLength:response.length textEncodingName:nil] autorelease]];
+ [task didReceiveData:[response dataUsingEncoding:NSUTF8StringEncoding]];
+ [task didFinish];
+}
+
+- (void)webView:(WKWebView *)webView stopURLSchemeTask:(id <WKURLSchemeTask>)task
+{
+}
+
+@end
+
+static void initializeInAppBrowserPrivacyTestSettings()
+{
+ RunLoop::initializeMainRunLoop();
+ WebCore::clearApplicationBundleIdentifierTestingOverride();
+ IN_APP_BROWSER_PRIVACY_ADDITIONS
+}
+
+TEST(InAppBrowserPrivacy, NonAppBoundDomainFailedUserScriptAtStart)
+{
auto messageHandler = adoptNS([[TestInAppBrowserScriptMessageHandler alloc] init]);
auto userScript = adoptNS([[WKUserScript alloc] initWithSource:userScriptSource injectionTime:WKUserScriptInjectionTimeAtDocumentStart forMainFrameOnly:YES]);
+ // First set up the configuration without In-App Browser Privacy settings to ensure it works as expected.
WKWebViewConfiguration *configuration = [WKWebViewConfiguration _test_configurationWithTestPlugInClassName:@"WebProcessPlugInWithInternals" configureJSCForTesting:YES];
+ [[configuration preferences] _setNeedsInAppBrowserPrivacyQuirks:YES];
+ [[configuration preferences] _setInAppBrowserPrivacyEnabled:NO];
+
+ auto schemeHandler = adoptNS([[InAppBrowserSchemeHandler alloc] init]);
+ [configuration setURLSchemeHandler:schemeHandler.get() forURLScheme:@"in-app-browser"];
+
+ [configuration.userContentController addUserScript:userScript.get()];
[configuration.userContentController addScriptMessageHandler:messageHandler.get() name:@"testInAppBrowserPrivacy"];
+
+ auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectZero configuration:configuration]);
+ NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"in-app-browser:///in-app-browser-privacy-test-user-script"]];
+ [webView loadRequest:request];
+ [webView _test_waitForDidFinishNavigation];
+ TestWebKitAPI::Util::run(&isDone);
+
+ [webView evaluateJavaScript:@"window.wkUserScriptInjected" completionHandler:^(id _Nullable result, NSError * _Nullable error) {
+ EXPECT_EQ(YES, [[webView objectByEvaluatingJavaScript:@"window.wkUserScriptInjected"] boolValue]);
+ EXPECT_FALSE(!!error);
+ isDone = true;
+ }];
+
+ isDone = false;
+ TestWebKitAPI::Util::run(&isDone);
+
+ // Now setup In-App Browser Privacy settings and expect a failed script evaluation result, and an error message.
+ isDone = false;
+ initializeInAppBrowserPrivacyTestSettings();
+ [[configuration preferences] _setNeedsInAppBrowserPrivacyQuirks:NO];
+ [[configuration preferences] _setInAppBrowserPrivacyEnabled:YES];
+
+ auto webView2 = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectZero configuration:configuration]);
+ [webView2 loadRequest:request];
+ TestWebKitAPI::Util::run(&isDone);
+
+ // Check that request to read this variable is rejected.
+ [webView2 evaluateJavaScript:@"window.wkUserScriptInjected" completionHandler:^(id _Nullable result, NSError * _Nullable error) {
+ EXPECT_FALSE(result);
+ EXPECT_TRUE(!!error);
+ isDone = true;
+ }];
+
+ isDone = false;
+ TestWebKitAPI::Util::run(&isDone);
+
+ // Turn back on In-App Browser Privacy quirks to check that original attempt to set this variable was rejected.
+ isDone = false;
+ [[[webView2 configuration] preferences] _setNeedsInAppBrowserPrivacyQuirks:YES];
+ [webView2 evaluateJavaScript:@"window.wkUserScriptInjected" completionHandler:^(id _Nullable result, NSError * _Nullable error) {
+ EXPECT_EQ(NO, [[webView2 objectByEvaluatingJavaScript:@"window.wkUserScriptInjected"] boolValue]);
+ EXPECT_FALSE(!!error);
+ isDone = true;
+ }];
+
+ isDone = false;
+ TestWebKitAPI::Util::run(&isDone);
+}
+
+TEST(InAppBrowserPrivacy, NonAppBoundDomainFailedUserScriptAtEnd)
+{
+ auto messageHandler = adoptNS([[TestInAppBrowserScriptMessageHandler alloc] init]);
+ auto userScript = adoptNS([[WKUserScript alloc] initWithSource:userScriptSource injectionTime:WKUserScriptInjectionTimeAtDocumentEnd forMainFrameOnly:YES]);
+
+ // First set up the configuration without In-App Browser Privacy settings to ensure it works as expected.
+ WKWebViewConfiguration *configuration = [WKWebViewConfiguration _test_configurationWithTestPlugInClassName:@"WebProcessPlugInWithInternals" configureJSCForTesting:YES];
+ [[configuration preferences] _setNeedsInAppBrowserPrivacyQuirks:YES];
[[configuration preferences] _setInAppBrowserPrivacyEnabled:NO];
+ auto schemeHandler = adoptNS([[InAppBrowserSchemeHandler alloc] init]);
+ [configuration setURLSchemeHandler:schemeHandler.get() forURLScheme:@"in-app-browser"];
+
+ [configuration.userContentController addUserScript:userScript.get()];
+ [configuration.userContentController addScriptMessageHandler:messageHandler.get() name:@"testInAppBrowserPrivacy"];
+
auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectZero configuration:configuration]);
-
- NSURLRequest *request = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"in-app-browser-privacy-test-user-script" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]];
+ NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"in-app-browser:///in-app-browser-privacy-test-user-script"]];
[webView loadRequest:request];
[webView _test_waitForDidFinishNavigation];
TestWebKitAPI::Util::run(&isDone);
-
- [configuration.userContentController _addUserScriptImmediately:userScript.get()];
+
[webView evaluateJavaScript:@"window.wkUserScriptInjected" completionHandler:^(id _Nullable result, NSError * _Nullable error) {
EXPECT_EQ(YES, [[webView objectByEvaluatingJavaScript:@"window.wkUserScriptInjected"] boolValue]);
EXPECT_FALSE(!!error);
@@ -80,15 +182,17 @@
isDone = false;
TestWebKitAPI::Util::run(&isDone);
+ // Now setup In-App Browser Privacy settings and expect a failed script evaluation result, and an error message.
isDone = false;
+ initializeInAppBrowserPrivacyTestSettings();
+ [[configuration preferences] _setNeedsInAppBrowserPrivacyQuirks:NO];
+ [[configuration preferences] _setInAppBrowserPrivacyEnabled:YES];
- [[configuration preferences] _setInAppBrowserPrivacyEnabled:YES];
auto webView2 = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectZero configuration:configuration]);
-
[webView2 loadRequest:request];
TestWebKitAPI::Util::run(&isDone);
- [configuration.userContentController _addUserScriptImmediately:userScript.get()];
+ // Check that request to read this variable is rejected.
[webView2 evaluateJavaScript:@"window.wkUserScriptInjected" completionHandler:^(id _Nullable result, NSError * _Nullable error) {
EXPECT_FALSE(result);
EXPECT_TRUE(!!error);
@@ -97,16 +201,31 @@
isDone = false;
TestWebKitAPI::Util::run(&isDone);
+
+ // Turn back on In-App Browser Privacy quirks to check that original attempt to set this variable was rejected.
+ isDone = false;
+ [[[webView2 configuration] preferences] _setNeedsInAppBrowserPrivacyQuirks:YES];
+ [webView2 evaluateJavaScript:@"window.wkUserScriptInjected" completionHandler:^(id _Nullable result, NSError * _Nullable error) {
+ EXPECT_EQ(NO, [[webView2 objectByEvaluatingJavaScript:@"window.wkUserScriptInjected"] boolValue]);
+ EXPECT_FALSE(!!error);
+ isDone = true;
+ }];
+
+ isDone = false;
+ TestWebKitAPI::Util::run(&isDone);
}
TEST(InAppBrowserPrivacy, NonAppBoundDomainFailedUserAgentScripts)
{
WKWebViewConfiguration *configuration = [WKWebViewConfiguration _test_configurationWithTestPlugInClassName:@"WebProcessPlugInWithInternals" configureJSCForTesting:YES];
+ [[configuration preferences] _setNeedsInAppBrowserPrivacyQuirks:YES];
[[configuration preferences] _setInAppBrowserPrivacyEnabled:NO];
+ auto schemeHandler = adoptNS([[InAppBrowserSchemeHandler alloc] init]);
+ [configuration setURLSchemeHandler:schemeHandler.get() forURLScheme:@"in-app-browser"];
+
auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectZero configuration:configuration]);
-
- NSURLRequest *request = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"in-app-browser-privacy-test-user-agent-script" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]];
+ NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"in-app-browser:///in-app-browser-privacy-test-user-agent-script"]];
[webView loadRequest:request];
[webView _test_waitForDidFinishNavigation];
@@ -118,6 +237,8 @@
isDone = false;
TestWebKitAPI::Util::run(&isDone);
+ initializeInAppBrowserPrivacyTestSettings();
+ [[configuration preferences] _setNeedsInAppBrowserPrivacyQuirks:NO];
[[configuration preferences] _setInAppBrowserPrivacyEnabled:YES];
auto webView2 = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectZero configuration:configuration]);
@@ -138,16 +259,20 @@
TEST(InAppBrowserPrivacy, SwapBackToAppBoundRejectsUserScript)
{
+ initializeInAppBrowserPrivacyTestSettings();
auto messageHandler = adoptNS([[TestInAppBrowserScriptMessageHandler alloc] init]);
auto userScript = adoptNS([[WKUserScript alloc] initWithSource:userScriptSource injectionTime:WKUserScriptInjectionTimeAtDocumentStart forMainFrameOnly:YES]);
WKWebViewConfiguration *configuration = [WKWebViewConfiguration _test_configurationWithTestPlugInClassName:@"WebProcessPlugInWithInternals" configureJSCForTesting:YES];
[configuration.userContentController addScriptMessageHandler:messageHandler.get() name:@"testInAppBrowserPrivacy"];
+ [[configuration preferences] _setNeedsInAppBrowserPrivacyQuirks:NO];
[[configuration preferences] _setInAppBrowserPrivacyEnabled:YES];
+ auto schemeHandler = adoptNS([[InAppBrowserSchemeHandler alloc] init]);
+ [configuration setURLSchemeHandler:schemeHandler.get() forURLScheme:@"in-app-browser"];
+
auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectZero configuration:configuration]);
-
- NSURLRequest *request = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"in-app-browser-privacy-test-user-script" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]];
+ NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"in-app-browser:///in-app-browser-privacy-test-user-script"]];
[webView loadRequest:request];
[webView _test_waitForDidFinishNavigation];
TestWebKitAPI::Util::run(&isDone);
@@ -179,10 +304,9 @@
TestWebKitAPI::Util::run(&isDone);
}
-#endif // USE(APPLE_INTERNAL_SDK)
-
TEST(InAppBrowserPrivacy, AppBoundDomains)
{
+ initializeInAppBrowserPrivacyTestSettings();
isDone = false;
[[WKWebsiteDataStore defaultDataStore] _appBoundDomains:^(NSArray<NSString *> *domains) {
NSArray *domainsToCompare = [NSArray arrayWithObjects:@"apple.com", @"bar.com", @"example.com", @"foo.com", @"localhost", @"webkit.org", nil];
@@ -199,3 +323,93 @@
TestWebKitAPI::Util::run(&isDone);
}
+TEST(InAppBrowserPrivacy, LocalFilesAreAppBound)
+{
+ initializeInAppBrowserPrivacyTestSettings();
+ auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+ [[configuration preferences] _setInAppBrowserPrivacyEnabled:YES];
+
+ auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectZero configuration:configuration.get()]);
+ NSURLRequest *request = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"in-app-browser-privacy-local-file" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]];
+ [webView loadRequest:request];
+ [webView _test_waitForDidFinishNavigation];
+
+ isDone = false;
+ [webView _isNavigatingToAppBoundDomain:^(BOOL isAppBound) {
+ EXPECT_TRUE(isAppBound);
+ isDone = true;
+ }];
+ TestWebKitAPI::Util::run(&isDone);
+}
+
+TEST(InAppBrowserPrivacy, DataFilesAreAppBound)
+{
+ initializeInAppBrowserPrivacyTestSettings();
+ auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+ [[configuration preferences] _setInAppBrowserPrivacyEnabled:YES];
+
+ auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectZero configuration:configuration.get()]);
+ [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"data:text/html,start"]]];
+ [webView _test_waitForDidFinishNavigation];
+
+ isDone = false;
+ [webView _isNavigatingToAppBoundDomain:^(BOOL isAppBound) {
+ EXPECT_TRUE(isAppBound);
+ isDone = true;
+ }];
+ TestWebKitAPI::Util::run(&isDone);
+}
+
+TEST(InAppBrowserPrivacy, AboutFilesAreAppBound)
+{
+ initializeInAppBrowserPrivacyTestSettings();
+ auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+ [[configuration preferences] _setInAppBrowserPrivacyEnabled:YES];
+
+ auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectZero configuration:configuration.get()]);
+ [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"about:blank"]]];
+ [webView _test_waitForDidFinishNavigation];
+
+ isDone = false;
+ [webView _isNavigatingToAppBoundDomain:^(BOOL isAppBound) {
+ EXPECT_TRUE(isAppBound);
+ isDone = true;
+ }];
+ TestWebKitAPI::Util::run(&isDone);
+}
+
+TEST(InAppBrowserPrivacy, IgnoreAppBoundDomainsAcceptsUserScripts)
+{
+ initializeInAppBrowserPrivacyTestSettings();
+ auto messageHandler = adoptNS([[TestInAppBrowserScriptMessageHandler alloc] init]);
+ auto userScript = adoptNS([[WKUserScript alloc] initWithSource:userScriptSource injectionTime:WKUserScriptInjectionTimeAtDocumentStart forMainFrameOnly:YES]);
+
+ WKWebViewConfiguration *configuration = [WKWebViewConfiguration _test_configurationWithTestPlugInClassName:@"WebProcessPlugInWithInternals" configureJSCForTesting:YES];
+ [configuration.userContentController addScriptMessageHandler:messageHandler.get() name:@"testInAppBrowserPrivacy"];
+ [[configuration preferences] _setNeedsInAppBrowserPrivacyQuirks:NO];
+ [[configuration preferences] _setInAppBrowserPrivacyEnabled:YES];
+ [configuration _setIgnoresAppBoundDomains:YES];
+
+ auto schemeHandler = adoptNS([[InAppBrowserSchemeHandler alloc] init]);
+ [configuration setURLSchemeHandler:schemeHandler.get() forURLScheme:@"in-app-browser"];
+
+ auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectZero configuration:configuration]);
+ NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"in-app-browser:///in-app-browser-privacy-test-user-script"]];
+
+ [webView loadRequest:request];
+ [webView _test_waitForDidFinishNavigation];
+ TestWebKitAPI::Util::run(&isDone);
+
+ [configuration.userContentController _addUserScriptImmediately:userScript.get()];
+ [webView evaluateJavaScript:@"window.wkUserScriptInjected" completionHandler:^(id _Nullable result, NSError * _Nullable error) {
+ EXPECT_EQ(YES, [[webView objectByEvaluatingJavaScript:@"window.wkUserScriptInjected"] boolValue]);
+ EXPECT_FALSE(!!error);
+ isDone = true;
+ }];
+
+ isDone = false;
+ TestWebKitAPI::Util::run(&isDone);
+}
+
+#endif // USE(APPLE_INTERNAL_SDK)
+
Added: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/in-app-browser-privacy-local-file.html (0 => 258616)
--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/in-app-browser-privacy-local-file.html (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/in-app-browser-privacy-local-file.html 2020-03-18 00:45:40 UTC (rev 258616)
@@ -0,0 +1,5 @@
+<!DOCTYPE html>
+<html>
+<body>
+</body>
+</html>
Deleted: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/in-app-browser-privacy-test-user-agent-script.html (258615 => 258616)
--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/in-app-browser-privacy-test-user-agent-script.html 2020-03-18 00:31:23 UTC (rev 258615)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/in-app-browser-privacy-test-user-agent-script.html 2020-03-18 00:45:40 UTC (rev 258616)
@@ -1,5 +0,0 @@
-<!DOCTYPE html>
-<body>
-<script>
- window.wkUserScriptInjected = true;
-</script>
Deleted: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/in-app-browser-privacy-test-user-script.html (258615 => 258616)
--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/in-app-browser-privacy-test-user-script.html 2020-03-18 00:31:23 UTC (rev 258615)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/in-app-browser-privacy-test-user-script.html 2020-03-18 00:45:40 UTC (rev 258616)
@@ -1,5 +0,0 @@
-<!DOCTYPE html>
-<body>
-<script>
- window.webkit.messageHandlers.testInAppBrowserPrivacy.postMessage("done");
-</script>