Title: [276476] trunk
Revision
276476
Author
[email protected]
Date
2021-04-22 17:09:05 -0700 (Thu, 22 Apr 2021)

Log Message

[Cocoa] re-enable test case WKInspectorDelegate.InspectorConfiguration
https://bugs.webkit.org/show_bug.cgi?id=224577
<rdar://70505272>

Reviewed by Devin Rousso.

Source/WebInspectorUI:

Adjust the CSP directive list in the <meta> tag to allow for customization
by WebKit ports.

* UserInterface/Main.html:
- Remove `default-src 'self'` so as not to block custom scheme loads.
- Remove `connect-src * ws:` so as not to block custom scheme loads.
- Add `object-src 'none'` as we have no reason to allow <object>, <embed>, or <applet>.

Source/WebKit:

For the purposes of testing, we want to be able to issue a fetch() that will
hit a custom URL scheme handler registered with _WKInspectorConfiguration.
This is not allowed by the existing <meta> tag CSP directive list because 'connect-src *'
does not allow connecting to arbitrary schemes, just arbitrary domains.

To fix this, relax the 'connect-src' directive in Main.html and apply
a dynamically-computed CSP directive using the 'Content-Security-Policy' HTTP
response header. This is only sent for main resources (Main.html and Test.html)
using the newly added inspector-resource: URL scheme handler.

The dynamically computed directive explicitly allows 'self' and any other registered
custom URL scheme handlers. WebKit ports which have not migrated away from file:///
will only apply the weaker 'connect-src' directive from the <meta> tag after this change.

Progresses an existing API test: WKInspectorDelegate.InspectorConfiguration.

* UIProcess/API/Cocoa/_WKInspectorDelegate.h:
* UIProcess/API/APIInspectorClient.h:
(API::InspectorClient::frontendLoaded):
* UIProcess/API/Cocoa/_WKInspectorPrivateForTesting.h:
* UIProcess/API/Cocoa/_WKInspector.mm:
* UIProcess/API/Cocoa/_WKInspectorTesting.mm:
(_javascript_SnippetToFetchURL):
(-[_WKInspector _fetchURLForTesting:]):

* UIProcess/Inspector/WebInspectorUIProxy.cpp:
(WebKit::WebInspectorUIProxy::frontendLoaded): Notify the _WKInspectorDelegate
adapter that the frontend has finished loading.

* UIProcess/Inspector/mac/WKInspectorResourceURLSchemeHandler.h:
* UIProcess/Inspector/mac/WKInspectorResourceURLSchemeHandler.mm:
(-[WKInspectorResourceURLSchemeHandler allowedURLSchemesForCSP]):
(-[WKInspectorResourceURLSchemeHandler setAllowedURLSchemesForCSP:]):
(-[WKInspectorResourceURLSchemeHandler webView:startURLSchemeTask:]):
Added. Keep track of allowed custom schemes and allowed main resources.
Apply the CSP directive for main resource requests only.

* UIProcess/Inspector/mac/WKInspectorViewController.mm:
(-[WKInspectorViewController webViewConfiguration]):
Set the allowed URL schemes property so the URL scheme handler can include
the schemes in the dynamically computed 'connect-src' directive.

Tools:

Trigger a fetch of a resource that uses a custom URL scheme handler in
order to test that custom scheme handlers registered in an _WKInspectorConfiguration
are getting used as expected.

Add an -inspectorFrontendLoaded: delegate method to -WKInspectorDelegate.
This is mainly used to prevent tests from progressing with a half-loaded inspector.

To make it possible to do this fetch(), there are some CSP related changes
that were made for Main.html so that fetching from a registered custom scheme is allowed.

Drive-by, per post-commit comments, add a better fix for the memory leak reported in
https://bugs.webkit.org/show_bug.cgi?id=223899. Thanks Joe!

* TestWebKitAPI/Tests/WebKitCocoa/WKInspectorDelegate.mm:
(resetGlobalState):
(-[InspectorDelegate inspectorFrontendLoaded:]):
(TEST):
(-[UIDelegate _webView:didAttachLocalInspector:]):
(-[UIDelegate _webView:willCloseLocalInspector:]):
(-[UIDelegate _webViewDidEnableInspectorBrowserDomain:]):
(-[UIDelegate _webViewDidDisableInspectorBrowserDomain:]):

Modified Paths

Diff

Modified: trunk/Source/WebInspectorUI/ChangeLog (276475 => 276476)


--- trunk/Source/WebInspectorUI/ChangeLog	2021-04-22 23:04:43 UTC (rev 276475)
+++ trunk/Source/WebInspectorUI/ChangeLog	2021-04-23 00:09:05 UTC (rev 276476)
@@ -1,3 +1,19 @@
+2021-04-22  BJ Burg  <[email protected]>
+
+        [Cocoa] re-enable test case WKInspectorDelegate.InspectorConfiguration
+        https://bugs.webkit.org/show_bug.cgi?id=224577
+        <rdar://70505272>
+
+        Reviewed by Devin Rousso.
+
+        Adjust the CSP directive list in the <meta> tag to allow for customization
+        by WebKit ports. 
+
+        * UserInterface/Main.html:
+        - Remove `default-src 'self'` so as not to block custom scheme loads.
+        - Remove `connect-src * ws:` so as not to block custom scheme loads.
+        - Add `object-src 'none'` as we have no reason to allow <object>, <embed>, or <applet>.
+
 2021-04-20  Razvan Caliman  <[email protected]>
 
         Web Inspector: Tree Outlines: `ondetach` can be called without `onattach` ever being called

Modified: trunk/Source/WebInspectorUI/UserInterface/Main.html (276475 => 276476)


--- trunk/Source/WebInspectorUI/UserInterface/Main.html	2021-04-22 23:04:43 UTC (rev 276475)
+++ trunk/Source/WebInspectorUI/UserInterface/Main.html	2021-04-23 00:09:05 UTC (rev 276476)
@@ -1,5 +1,5 @@
 <!--
- * Copyright (C) 2013, 2014 Apple Inc. All rights reserved.
+ * Copyright (C) 2013-2021 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -26,7 +26,11 @@
 <html>
 <head>
     <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
-    <meta http-equiv="Content-Security-Policy" content="default-src 'self'; img-src * file: blob: resource:; connect-src * ws:; media-src * blob:; font-src * blob:; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' data:">
+    <!--
+        Note that some WebKit ports may set custom 'frame-src' and 'connect-src' directives via HTTP response header.
+        The combined CSP policy requires a request to be allowed by both directive lists, so 'default-src' is omitted.
+    -->
+    <meta http-equiv="Content-Security-Policy" content="img-src * file: blob: resource:; media-src * blob:; font-src * blob:; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' data:; object-src 'none'">
 
     <link rel="stylesheet" href=""
 

Modified: trunk/Source/WebKit/ChangeLog (276475 => 276476)


--- trunk/Source/WebKit/ChangeLog	2021-04-22 23:04:43 UTC (rev 276475)
+++ trunk/Source/WebKit/ChangeLog	2021-04-23 00:09:05 UTC (rev 276476)
@@ -1,3 +1,53 @@
+2021-04-22  BJ Burg  <[email protected]>
+
+        [Cocoa] re-enable test case WKInspectorDelegate.InspectorConfiguration
+        https://bugs.webkit.org/show_bug.cgi?id=224577
+        <rdar://70505272>
+
+        Reviewed by Devin Rousso.
+
+        For the purposes of testing, we want to be able to issue a fetch() that will
+        hit a custom URL scheme handler registered with _WKInspectorConfiguration.
+        This is not allowed by the existing <meta> tag CSP directive list because 'connect-src *'
+        does not allow connecting to arbitrary schemes, just arbitrary domains.
+
+        To fix this, relax the 'connect-src' directive in Main.html and apply
+        a dynamically-computed CSP directive using the 'Content-Security-Policy' HTTP
+        response header. This is only sent for main resources (Main.html and Test.html)
+        using the newly added inspector-resource: URL scheme handler.
+
+        The dynamically computed directive explicitly allows 'self' and any other registered
+        custom URL scheme handlers. WebKit ports which have not migrated away from file:///
+        will only apply the weaker 'connect-src' directive from the <meta> tag after this change.
+
+        Progresses an existing API test: WKInspectorDelegate.InspectorConfiguration.
+
+        * UIProcess/API/Cocoa/_WKInspectorDelegate.h:
+        * UIProcess/API/APIInspectorClient.h:
+        (API::InspectorClient::frontendLoaded):
+        * UIProcess/API/Cocoa/_WKInspectorPrivateForTesting.h:
+        * UIProcess/API/Cocoa/_WKInspector.mm:
+        * UIProcess/API/Cocoa/_WKInspectorTesting.mm:
+        (_javascript_SnippetToFetchURL):
+        (-[_WKInspector _fetchURLForTesting:]):
+
+        * UIProcess/Inspector/WebInspectorUIProxy.cpp:
+        (WebKit::WebInspectorUIProxy::frontendLoaded): Notify the _WKInspectorDelegate
+        adapter that the frontend has finished loading.
+
+        * UIProcess/Inspector/mac/WKInspectorResourceURLSchemeHandler.h:
+        * UIProcess/Inspector/mac/WKInspectorResourceURLSchemeHandler.mm:
+        (-[WKInspectorResourceURLSchemeHandler allowedURLSchemesForCSP]):
+        (-[WKInspectorResourceURLSchemeHandler setAllowedURLSchemesForCSP:]):
+        (-[WKInspectorResourceURLSchemeHandler webView:startURLSchemeTask:]):
+        Added. Keep track of allowed custom schemes and allowed main resources.
+        Apply the CSP directive for main resource requests only.
+
+        * UIProcess/Inspector/mac/WKInspectorViewController.mm:
+        (-[WKInspectorViewController webViewConfiguration]):
+        Set the allowed URL schemes property so the URL scheme handler can include
+        the schemes in the dynamically computed 'connect-src' directive.
+
 2021-04-22  Simon Fraser  <[email protected]>
 
         Add trace points for WKWebView snapshotting

Modified: trunk/Source/WebKit/UIProcess/API/APIInspectorClient.h (276475 => 276476)


--- trunk/Source/WebKit/UIProcess/API/APIInspectorClient.h	2021-04-22 23:04:43 UTC (rev 276475)
+++ trunk/Source/WebKit/UIProcess/API/APIInspectorClient.h	2021-04-23 00:09:05 UTC (rev 276476)
@@ -39,6 +39,7 @@
     virtual ~InspectorClient() = default;
 
     virtual void openURLExternally(WebKit::WebInspectorUIProxy&, const WTF::String& url) { }
+    virtual void frontendLoaded(WebKit::WebInspectorUIProxy&) { }
 };
 
 } // namespace API

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/_WKInspector.mm (276475 => 276476)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/_WKInspector.mm	2021-04-22 23:04:43 UTC (rev 276475)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/_WKInspector.mm	2021-04-23 00:09:05 UTC (rev 276476)
@@ -54,6 +54,7 @@
     explicit InspectorClient(id <_WKInspectorDelegate> delegate)
         : m_delegate(delegate)
         , m_respondsToInspectorOpenURLExternally([delegate respondsToSelector:@selector(inspector:openURLExternally:)])
+        , m_respondsToInspectorFrontendLoaded([delegate respondsToSelector:@selector(inspectorFrontendLoaded:)])
     {
     }
 
@@ -69,9 +70,18 @@
         [m_delegate inspector:wrapper(inspector) openURLExternally:[NSURL URLWithString:url]];
     }
 
+    void frontendLoaded(WebKit::WebInspectorUIProxy& inspector) final
+    {
+        if (!m_delegate || !m_respondsToInspectorFrontendLoaded)
+            return;
+
+        [m_delegate inspectorFrontendLoaded:wrapper(inspector)];
+    }
+
     WeakObjCPtr<id <_WKInspectorDelegate> > m_delegate;
 
     bool m_respondsToInspectorOpenURLExternally : 1;
+    bool m_respondsToInspectorFrontendLoaded : 1;
 };
 
 @implementation _WKInspector

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/_WKInspectorDelegate.h (276475 => 276476)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/_WKInspectorDelegate.h	2021-04-22 23:04:43 UTC (rev 276475)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/_WKInspectorDelegate.h	2021-04-23 00:09:05 UTC (rev 276476)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2020 Apple Inc. All rights reserved.
+ * Copyright (C) 2020-2021 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -38,4 +38,9 @@
  */
 - (void)inspector:(_WKInspector *)inspector openURLExternally:(NSURL *)url;
 
+/*! @abstract Called when the _WKInspector user interface has been fully loaded.
+    @param inspector the associated inspector that has finished loading.
+*/
+- (void)inspectorFrontendLoaded:(_WKInspector *)inspector;
+
 @end

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/_WKInspectorPrivateForTesting.h (276475 => 276476)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/_WKInspectorPrivateForTesting.h	2021-04-22 23:04:43 UTC (rev 276475)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/_WKInspectorPrivateForTesting.h	2021-04-23 00:09:05 UTC (rev 276476)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2020 Apple Inc. All rights reserved.
+ * Copyright (C) 2020-2021 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -26,6 +26,7 @@
 #import "_WKInspector.h"
 
 @interface _WKInspector (WKTesting)
+- (void)_fetchURLForTesting:(NSURL *)url;
 - (void)_openURLExternallyForTesting:(NSURL *)url useFrontendAPI:(BOOL)useFrontendAPI;
 - (WKWebView *)inspectorWebView;
 @end

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/_WKInspectorTesting.mm (276475 => 276476)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/_WKInspectorTesting.mm	2021-04-22 23:04:43 UTC (rev 276475)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/_WKInspectorTesting.mm	2021-04-23 00:09:05 UTC (rev 276476)
@@ -38,6 +38,11 @@
     return [NSString stringWithFormat:@"InspectorFrontendHost.openURLExternally(\"%@\")", url.absoluteString];
 }
 
+static NSString *_javascript_SnippetToFetchURL(NSURL *url)
+{
+    return [NSString stringWithFormat:@"fetch(\"%@\")", url.absoluteString];
+}
+
 @implementation _WKInspector (WKTesting)
 
 - (WKWebView *)inspectorWebView
@@ -46,6 +51,11 @@
     return page ? page->cocoaView().autorelease() : nil;
 }
 
+- (void)_fetchURLForTesting:(NSURL *)url
+{
+    _inspector->evaluateInFrontendForTesting(_javascript_SnippetToFetchURL(url));
+}
+
 - (void)_openURLExternallyForTesting:(NSURL *)url useFrontendAPI:(BOOL)useFrontendAPI
 {
     if (useFrontendAPI)

Modified: trunk/Source/WebKit/UIProcess/Inspector/WebInspectorUIProxy.cpp (276475 => 276476)


--- trunk/Source/WebKit/UIProcess/Inspector/WebInspectorUIProxy.cpp	2021-04-22 23:04:43 UTC (rev 276475)
+++ trunk/Source/WebKit/UIProcess/Inspector/WebInspectorUIProxy.cpp	2021-04-23 00:09:05 UTC (rev 276476)
@@ -589,6 +589,9 @@
     if (m_extensionController)
         m_extensionController->inspectorFrontendLoaded();
 #endif
+
+    if (m_inspectorClient)
+        m_inspectorClient->frontendLoaded(*this);
 }
 
 void WebInspectorUIProxy::bringToFront()

Modified: trunk/Source/WebKit/UIProcess/Inspector/mac/WKInspectorResourceURLSchemeHandler.h (276475 => 276476)


--- trunk/Source/WebKit/UIProcess/Inspector/mac/WKInspectorResourceURLSchemeHandler.h	2021-04-22 23:04:43 UTC (rev 276475)
+++ trunk/Source/WebKit/UIProcess/Inspector/mac/WKInspectorResourceURLSchemeHandler.h	2021-04-23 00:09:05 UTC (rev 276476)
@@ -33,6 +33,7 @@
 NS_ASSUME_NONNULL_BEGIN
 
 @interface WKInspectorResourceURLSchemeHandler : NSObject <WKURLSchemeHandler>
+@property (nonatomic, copy, nullable) NSSet<NSString *> *allowedURLSchemesForCSP;
 @end
 
 NS_ASSUME_NONNULL_END

Modified: trunk/Source/WebKit/UIProcess/Inspector/mac/WKInspectorResourceURLSchemeHandler.mm (276475 => 276476)


--- trunk/Source/WebKit/UIProcess/Inspector/mac/WKInspectorResourceURLSchemeHandler.mm	2021-04-22 23:04:43 UTC (rev 276475)
+++ trunk/Source/WebKit/UIProcess/Inspector/mac/WKInspectorResourceURLSchemeHandler.mm	2021-04-23 00:09:05 UTC (rev 276476)
@@ -30,6 +30,8 @@
 
 #import "Logging.h"
 #import "WKURLSchemeTask.h"
+#import "WebInspectorUIProxy.h"
+#import "WebURLSchemeHandlerCocoa.h"
 #import <WebCore/MIMETypeRegistry.h>
 #import <wtf/Assertions.h>
 
@@ -37,8 +39,29 @@
     RetainPtr<NSMapTable<id <WKURLSchemeTask>, NSOperation *>> _fileLoadOperations;
     RetainPtr<NSBundle> _cachedBundle;
     RetainPtr<NSOperationQueue> _operationQueue;
+    
+    RetainPtr<NSSet<NSString *>> _allowedURLSchemesForCSP;
+    RetainPtr<NSSet<NSURL *>> _mainResourceURLsForCSP;
 }
 
+- (NSSet<NSString *> *)allowedURLSchemesForCSP
+{
+    return _allowedURLSchemesForCSP.get();
+}
+
+- (void)setAllowedURLSchemesForCSP:(NSSet<NSString *> *)allowedURLSchemes
+{
+    _allowedURLSchemesForCSP = adoptNS([allowedURLSchemes copy]);
+}
+
+- (NSSet<NSURL *> *)mainResourceURLsForCSP
+{
+    if (!_mainResourceURLsForCSP)
+        _mainResourceURLsForCSP = adoptNS([[NSSet alloc] initWithObjects:[NSURL URLWithString:WebKit::WebInspectorUIProxy::inspectorPageURL()], [NSURL URLWithString:WebKit::WebInspectorUIProxy::inspectorTestPageURL()], nil]);
+
+    return _mainResourceURLsForCSP.get();
+}
+
 // MARK - WKURLSchemeHandler Protocol
 
 - (void)webView:(WKWebView *)webView startURLSchemeTask:(id <WKURLSchemeTask>)urlSchemeTask
@@ -89,12 +112,19 @@
         if (!mimeType)
             mimeType = @"application/octet-stream";
 
-        RetainPtr<NSHTTPURLResponse> urlResponse = adoptNS([[NSHTTPURLResponse alloc] initWithURL:urlSchemeTask.request.URL statusCode:200 HTTPVersion:nil headerFields:@{
+        RetainPtr<NSMutableDictionary> headerFields = adoptNS(@{
             @"Access-Control-Allow-Origin": @"*",
             @"Content-Length": [NSString stringWithFormat:@"%zu", (size_t)fileData.length],
             @"Content-Type": mimeType,
-        }]);
+        }.mutableCopy);
 
+        // Allow fetches for resources that use a registered custom URL scheme.
+        if (_allowedURLSchemesForCSP && [self.mainResourceURLsForCSP containsObject:requestURL]) {
+            NSString *stringForCSPPolicy = [NSString stringWithFormat:@"connect-src * %@:", [_allowedURLSchemesForCSP.get().allObjects componentsJoinedByString:@": "]];
+            [headerFields setObject:stringForCSPPolicy forKey:@"Content-Security-Policy"];
+        }
+
+        RetainPtr<NSHTTPURLResponse> urlResponse = adoptNS([[NSHTTPURLResponse alloc] initWithURL:urlSchemeTask.request.URL statusCode:200 HTTPVersion:nil headerFields:headerFields.get()]);
         [urlSchemeTask didReceiveResponse:urlResponse.get()];
         [urlSchemeTask didReceiveData:fileData];
         [urlSchemeTask didFinish];

Modified: trunk/Source/WebKit/UIProcess/Inspector/mac/WKInspectorViewController.mm (276475 => 276476)


--- trunk/Source/WebKit/UIProcess/Inspector/mac/WKInspectorViewController.mm	2021-04-22 23:04:43 UTC (rev 276475)
+++ trunk/Source/WebKit/UIProcess/Inspector/mac/WKInspectorViewController.mm	2021-04-23 00:09:05 UTC (rev 276476)
@@ -114,9 +114,14 @@
 - (WKWebViewConfiguration *)webViewConfiguration
 {
     RetainPtr<WKWebViewConfiguration> configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
-    RetainPtr<WKInspectorResourceURLSchemeHandler> inspectorSchemeHandler = adoptNS([[WKInspectorResourceURLSchemeHandler alloc] init]);
-    [configuration setURLSchemeHandler:inspectorSchemeHandler.autorelease() forURLScheme:WKInspectorResourceScheme];
+    RetainPtr<WKInspectorResourceURLSchemeHandler> inspectorSchemeHandler = adoptNS([WKInspectorResourceURLSchemeHandler new]);
+    RetainPtr<NSMutableSet<NSString *>> allowedURLSchemes = adoptNS([[NSMutableSet alloc] initWithObjects:WKInspectorResourceScheme, nil]);
+    for (auto& pair : _configuration->_configuration->urlSchemeHandlers())
+        [allowedURLSchemes addObject:pair.second];
 
+    [inspectorSchemeHandler setAllowedURLSchemesForCSP:allowedURLSchemes.get()];
+    [configuration setURLSchemeHandler:inspectorSchemeHandler.get() forURLScheme:WKInspectorResourceScheme];
+
     WKPreferences *preferences = configuration.get().preferences;
     preferences._allowFileAccessFromFileURLs = YES;
     [configuration _setAllowUniversalAccessFromFileURLs:YES];

Modified: trunk/Tools/ChangeLog (276475 => 276476)


--- trunk/Tools/ChangeLog	2021-04-22 23:04:43 UTC (rev 276475)
+++ trunk/Tools/ChangeLog	2021-04-23 00:09:05 UTC (rev 276476)
@@ -1,3 +1,33 @@
+2021-04-22  BJ Burg  <[email protected]>
+
+        [Cocoa] re-enable test case WKInspectorDelegate.InspectorConfiguration
+        https://bugs.webkit.org/show_bug.cgi?id=224577
+        <rdar://70505272>
+
+        Reviewed by Devin Rousso.
+
+        Trigger a fetch of a resource that uses a custom URL scheme handler in
+        order to test that custom scheme handlers registered in an _WKInspectorConfiguration
+        are getting used as expected.
+
+        Add an -inspectorFrontendLoaded: delegate method to -WKInspectorDelegate.
+        This is mainly used to prevent tests from progressing with a half-loaded inspector.
+
+        To make it possible to do this fetch(), there are some CSP related changes
+        that were made for Main.html so that fetching from a registered custom scheme is allowed.
+
+        Drive-by, per post-commit comments, add a better fix for the memory leak reported in
+        https://bugs.webkit.org/show_bug.cgi?id=223899. Thanks Joe!
+
+        * TestWebKitAPI/Tests/WebKitCocoa/WKInspectorDelegate.mm:
+        (resetGlobalState):
+        (-[InspectorDelegate inspectorFrontendLoaded:]):
+        (TEST):
+        (-[UIDelegate _webView:didAttachLocalInspector:]):
+        (-[UIDelegate _webView:willCloseLocalInspector:]):
+        (-[UIDelegate _webViewDidEnableInspectorBrowserDomain:]):
+        (-[UIDelegate _webViewDidDisableInspectorBrowserDomain:]):
+
 2021-04-22  Lauro Moura  <[email protected]>
 
         Unreviewed. Gardening TestSSL flakiness

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKInspectorDelegate.mm (276475 => 276476)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKInspectorDelegate.mm	2021-04-22 23:04:43 UTC (rev 276475)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKInspectorDelegate.mm	2021-04-23 00:09:05 UTC (rev 276476)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2017-2020 Apple Inc. All rights reserved.
+ * Copyright (C) 2017-2021 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -46,6 +46,7 @@
 @class SimpleURLSchemeHandler;
 
 static bool didAttachLocalInspectorCalled = false;
+static bool inspectorFrontendLoadedCalled = false;
 static bool willCloseLocalInspectorCalled = false;
 static bool browserDomainEnabledForInspectorCalled = false;
 static bool browserDomainDisabledForInspectorCalled = false;
@@ -61,6 +62,7 @@
 static void resetGlobalState()
 {
     didAttachLocalInspectorCalled = false;
+    inspectorFrontendLoadedCalled = false;
     willCloseLocalInspectorCalled = false;
     browserDomainEnabledForInspectorCalled = false;
     browserDomainDisabledForInspectorCalled = false;
@@ -110,12 +112,17 @@
     openURLExternallyCalled = true;
 }
 
+- (void)inspectorFrontendLoaded:(_WKInspector *)inspector
+{
+    inspectorFrontendLoadedCalled = true;
+}
+
 @end
 
-@interface UIDelegate : NSObject <WKUIDelegate>
+@interface UIDelegateForTesting : NSObject <WKUIDelegate>
 @end
 
-@implementation UIDelegate
+@implementation UIDelegateForTesting
 
 - (_WKInspectorConfiguration *)_webView:(WKWebView *)webView configurationForLocalInspector:(_WKInspector *)inspector
 {
@@ -165,7 +172,7 @@
     auto webViewConfiguration = adoptNS([WKWebViewConfiguration new]);
     webViewConfiguration.get().preferences._developerExtrasEnabled = YES;
     auto webView = adoptNS([[WKWebView alloc] initWithFrame:CGRectMake(0, 0, 800, 600) configuration:webViewConfiguration.get()]);
-    auto uiDelegate = adoptNS([UIDelegate new]);
+    auto uiDelegate = adoptNS([UIDelegateForTesting new]);
 
     [webView setUIDelegate:uiDelegate.get()];
     [webView loadHTMLString:@"<head><title>Test page to be inspected</title></head><body><p>Filler content</p></body>" baseURL:[NSURL URLWithString:@"http://example.com/"]];
@@ -189,7 +196,7 @@
     auto webViewConfiguration = adoptNS([WKWebViewConfiguration new]);
     webViewConfiguration.get().preferences._developerExtrasEnabled = YES;
     auto webView = adoptNS([[WKWebView alloc] initWithFrame:CGRectMake(0, 0, 800, 600) configuration:webViewConfiguration.get()]);
-    auto uiDelegate = adoptNS([UIDelegate new]);
+    auto uiDelegate = adoptNS([UIDelegateForTesting new]);
 
     [webView setUIDelegate:uiDelegate.get()];
     [webView loadHTMLString:@"<head><title>Test page to be inspected</title></head><body><p>Filler content</p></body>" baseURL:[NSURL URLWithString:@"http://example.com/"]];
@@ -213,7 +220,7 @@
     auto webViewConfiguration = adoptNS([WKWebViewConfiguration new]);
     webViewConfiguration.get().preferences._developerExtrasEnabled = YES;
     auto webView = adoptNS([[WKWebView alloc] initWithFrame:CGRectMake(0, 0, 800, 600) configuration:webViewConfiguration.get()]);
-    auto uiDelegate = adoptNS([UIDelegate new]);
+    auto uiDelegate = adoptNS([UIDelegateForTesting new]);
 
     [webView setUIDelegate:uiDelegate.get()];
     [webView loadHTMLString:@"<head><title>Test page to be inspected</title></head><body><p>Filler content</p></body>" baseURL:[NSURL URLWithString:@"http://example.com/"]];
@@ -220,6 +227,7 @@
 
     [[webView _inspector] show];
     TestWebKitAPI::Util::run(&didAttachLocalInspectorCalled);
+    TestWebKitAPI::Util::run(&inspectorFrontendLoadedCalled);
 
     urlToOpen = [NSURL URLWithString:@"https://www.webkit.org/"];
 
@@ -232,8 +240,7 @@
     TestWebKitAPI::Util::run(&openURLExternallyCalled);
 }
 
-// FIXME: re-enabling this test case is blocked, tracking this task in <rdar://problem/70505272>.
-TEST(WKInspectorDelegate, DISABLED_InspectorConfiguration)
+TEST(WKInspectorDelegate, InspectorConfiguration)
 {
     resetGlobalState();
 
@@ -240,7 +247,7 @@
     auto webViewConfiguration = adoptNS([WKWebViewConfiguration new]);
     webViewConfiguration.get().preferences._developerExtrasEnabled = YES;
     auto webView = adoptNS([[WKWebView alloc] initWithFrame:CGRectMake(0, 0, 800, 600) configuration:webViewConfiguration.get()]);
-    auto uiDelegate = adoptNS([UIDelegate new]);
+    auto uiDelegate = adoptNS([UIDelegateForTesting new]);
 
     [webView setUIDelegate:uiDelegate.get()];
     [webView loadHTMLString:@"<head><title>Test page to be inspected</title></head><body><p>Filler content</p></body>" baseURL:[NSURL URLWithString:@"http://example.com/"]];
@@ -250,13 +257,11 @@
     [[webView _inspector] show];
     TestWebKitAPI::Util::run(&configurationForLocalInspectorCalled);
     TestWebKitAPI::Util::run(&didAttachLocalInspectorCalled);
+    TestWebKitAPI::Util::run(&inspectorFrontendLoadedCalled);
 
-    // FIXME: WKInspectorViewController's navigation delegate cancels all main frame
-    // loads that are not the Web Inspector page. So, this cannot be fully tested until
-    // we can used the createTab API to load the custom URL scheme resource in an iframe.
     urlToOpen = [NSURL URLWithString:@"testing:main1"];
     sharedURLSchemeHandler.get().expectedURL = urlToOpen.get();
-    [[webView _inspector] _openURLExternallyForTesting:urlToOpen.get() useFrontendAPI:NO];
+    [[webView _inspector] _fetchURLForTesting:urlToOpen.get()];
     TestWebKitAPI::Util::run(&startURLSchemeTaskCalled);
 
     [[webView _inspector] close];
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to