⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 280980 in webkit


Ignore:
Timestamp:
Aug 12, 2021, 1:16:51 PM (5 years ago)
Author:
weinig@apple.com
Message:

Allow testing of the final UIView tree on iOS platforms
https://bugs.webkit.org/show_bug.cgi?id=229016

Reviewed by Tim Horton.

Source/WebKit:

Test: remote-layer-tree/ios/uiview-tree-basic.html

  • UIProcess/API/ios/WKWebViewPrivateForTestingIOS.h:
  • UIProcess/API/ios/WKWebViewTestingIOS.mm:

(allowListedClassToString):
(dumpUIView):
(-[WKWebView _uiViewTreeAsText]):
Add partner SPI called _uiViewTreeAsText that dumps the WKWebView's
UIView tree as constructed via remote layer creation. It currently
dumps some basic properties of each view and uses an allow list of
class names so changes to implementation details in frameworks below
us, like UIKit, don't cause tests to fail.

Tools:

  • TestRunnerShared/UIScriptContext/Bindings/UIScriptController.idl:
  • TestRunnerShared/UIScriptContext/UIScriptController.h:

(WTR::UIScriptController::uiViewTreeAsText const):

  • WebKitTestRunner/ios/UIScriptControllerIOS.h:
  • WebKitTestRunner/ios/UIScriptControllerIOS.mm:

(WTR::UIScriptControllerIOS::uiViewTreeAsText const):
Pipe new _uiViewTreeAsText SPI through to UIScriptController, matching the pattern
established by scrollingTreeAsText.

LayoutTests:

  • remote-layer-tree: Added.
  • remote-layer-tree/ios: Added.
  • remote-layer-tree/ios/uiview-tree-basic-expected.txt: Added.
  • remote-layer-tree/ios/uiview-tree-basic.html: Added.

Add basic test case excercising UIView tree dumping to ensure
it is working properly.

  • resources/ui-helper.js:

(window.UIHelper.getUIViewTree):
Add helper to use get the UIView tree as text.

Ensure these tests are only run on iOS.

Location:
trunk
Files:
4 added
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r280960 r280980  
     12021-08-12  Sam Weinig  <weinig@apple.com>
     2
     3        Allow testing of the final UIView tree on iOS platforms
     4        https://bugs.webkit.org/show_bug.cgi?id=229016
     5
     6        Reviewed by Tim Horton.
     7
     8        * remote-layer-tree: Added.
     9        * remote-layer-tree/ios: Added.
     10        * remote-layer-tree/ios/uiview-tree-basic-expected.txt: Added.
     11        * remote-layer-tree/ios/uiview-tree-basic.html: Added.
     12        Add basic test case excercising UIView tree dumping to ensure
     13        it is working properly.
     14
     15        * resources/ui-helper.js:
     16        (window.UIHelper.getUIViewTree):
     17        Add helper to use get the UIView tree as text.
     18
     19        * TestExpectations:
     20        * platform/ios/TestExpectations:
     21        Ensure these tests are only run on iOS.
     22
    1232021-08-12  Martin Robinson  <mrobinson@webkit.org>
    224
  • trunk/LayoutTests/TestExpectations

    r280963 r280980  
    8383fast/media/ios [ Skip ]
    8484fast/dom/Range/mac [ Skip ]
     85remote-layer-tree/ios [ Skip ]
    8586inspector/page/setScreenSizeOverride.html [ Skip ]
    8687
  • trunk/LayoutTests/platform/ios/TestExpectations

    r280794 r280980  
    1919quicklook [ Pass ]
    2020system-preview [ Pass ]
     21remote-layer-tree/ios [ Pass ]
    2122swipe [ Pass ]
    2223http/tests/swipe [ Pass ]
  • trunk/LayoutTests/resources/ui-helper.js

    r280767 r280980  
    14061406            testRunner.runUIScript(`(() => {
    14071407                return uiController.scrollingTreeAsText;
     1408            })()`, resolve);
     1409        });
     1410    }
     1411
     1412    static getUIViewTree()
     1413    {
     1414        if (!this.isWebKit2() || !this.isIOSFamily())
     1415            return Promise.resolve();
     1416
     1417        return new Promise(resolve => {
     1418            testRunner.runUIScript(`(() => {
     1419                return uiController.uiViewTreeAsText;
    14081420            })()`, resolve);
    14091421        });
  • trunk/Source/WebKit/ChangeLog

    r280976 r280980  
     12021-08-12  Sam Weinig  <weinig@apple.com>
     2
     3        Allow testing of the final UIView tree on iOS platforms
     4        https://bugs.webkit.org/show_bug.cgi?id=229016
     5
     6        Reviewed by Tim Horton.
     7
     8        Test: remote-layer-tree/ios/uiview-tree-basic.html
     9
     10        * UIProcess/API/ios/WKWebViewPrivateForTestingIOS.h:
     11        * UIProcess/API/ios/WKWebViewTestingIOS.mm:
     12        (allowListedClassToString):
     13        (dumpUIView):
     14        (-[WKWebView _uiViewTreeAsText]):
     15        Add partner SPI called _uiViewTreeAsText that dumps the WKWebView's
     16        UIView tree as constructed via remote layer creation. It currently
     17        dumps some basic properties of each view and uses an allow list of
     18        class names so changes to implementation details in frameworks below
     19        us, like UIKit, don't cause tests to fail.
     20
    1212021-08-12  Jer Noble  <jer.noble@apple.com>
    222
  • trunk/Source/WebKit/UIProcess/API/ios/WKWebViewPrivateForTestingIOS.h

    r280767 r280980  
    4444@property (nonatomic, readonly) CGRect _inputViewBoundsInWindow;
    4545@property (nonatomic, readonly) NSString *_scrollingTreeAsText;
     46@property (nonatomic, readonly) NSString *_uiViewTreeAsText;
    4647@property (nonatomic, readonly) NSNumber *_stableStateOverride;
    4748@property (nonatomic, readonly) CGRect _dragCaretRect;
  • trunk/Source/WebKit/UIProcess/API/ios/WKWebViewTestingIOS.mm

    r280767 r280980  
    4242#import <WebCore/ColorSerialization.h>
    4343#import <WebCore/ElementContext.h>
     44#import <wtf/SortedArrayMap.h>
     45#import <wtf/text/TextStream.h>
    4446
    4547@implementation WKWebView (WKTestingIOS)
     
    228230}
    229231
     232static String allowListedClassToString(UIView *view)
     233{
     234    static constexpr ComparableASCIILiteral allowedClassesArray[] = {
     235        "UIView",
     236        "WKBackdropView",
     237        "WKCompositingView",
     238        "WKContentView",
     239        "WKModelView",
     240        "WKRemoteView",
     241        "WKScrollView",
     242        "WKSeparatedModelView"
     243        "WKShapeView",
     244        "WKSimpleBackdropView",
     245        "WKTransformView",
     246        "WKUIRemoteView",
     247        "WKWebView",
     248        "_UILayerHostView",
     249    };
     250    static constexpr SortedArraySet allowedClasses { allowedClassesArray };
     251
     252    String classString { NSStringFromClass(view.class) };
     253    if (allowedClasses.contains(classString))
     254        return classString;
     255   
     256    ASSERT(classString != "WKCompositingView");
     257    return makeString("<class not in allowed list of classes>");
     258}
     259
     260static void dumpUIView(TextStream& ts, UIView *view)
     261{
     262    auto rectToString = [] (auto rect) {
     263        return makeString("[x: ", rect.origin.x, " y: ", rect.origin.x, " width: ", rect.size.width, " height: ", rect.size.height, "]");
     264    };
     265
     266    auto pointToString = [] (auto point) {
     267        return makeString("[x: ", point.x, " y: ", point.x, "]");
     268    };
     269
     270
     271    ts << "view [class: " << allowListedClassToString(view) << "]";
     272
     273    ts.dumpProperty("layer bounds", rectToString(view.layer.bounds));
     274   
     275    if (view.layer.position.x != 0 || view.layer.position.y != 0)
     276        ts.dumpProperty("layer position", pointToString(view.layer.position));
     277   
     278    if (view.layer.zPosition != 0)
     279        ts.dumpProperty("layer zPosition", makeString(view.layer.zPosition));
     280   
     281    if (view.layer.anchorPoint.x != 0.5 || view.layer.anchorPoint.y != 0.5)
     282        ts.dumpProperty("layer anchorPoint", pointToString(view.layer.anchorPoint));
     283   
     284    if (view.layer.anchorPointZ != 0)
     285        ts.dumpProperty("layer anchorPointZ", makeString(view.layer.anchorPointZ));
     286
     287    if (view.subviews.count > 0) {
     288        TextStream::GroupScope scope(ts);
     289        ts << "subviews";
     290        for (UIView *subview in view.subviews) {
     291            TextStream::GroupScope scope(ts);
     292            dumpUIView(ts, subview);
     293        }
     294    }
     295}
     296
     297- (NSString *)_uiViewTreeAsText
     298{
     299    TextStream ts(TextStream::LineMode::MultipleLine);
     300
     301    {
     302        TextStream::GroupScope scope(ts);
     303        ts << "UIView tree root ";
     304        dumpUIView(ts, self);
     305    }
     306
     307    return ts.release();
     308}
     309
    230310- (NSNumber *)_stableStateOverride
    231311{
  • trunk/Tools/ChangeLog

    r280973 r280980  
     12021-08-12  Sam Weinig  <weinig@apple.com>
     2
     3        Allow testing of the final UIView tree on iOS platforms
     4        https://bugs.webkit.org/show_bug.cgi?id=229016
     5
     6        Reviewed by Tim Horton.
     7
     8        * TestRunnerShared/UIScriptContext/Bindings/UIScriptController.idl:
     9        * TestRunnerShared/UIScriptContext/UIScriptController.h:
     10        (WTR::UIScriptController::uiViewTreeAsText const):
     11        * WebKitTestRunner/ios/UIScriptControllerIOS.h:
     12        * WebKitTestRunner/ios/UIScriptControllerIOS.mm:
     13        (WTR::UIScriptControllerIOS::uiViewTreeAsText const):
     14        Pipe new _uiViewTreeAsText SPI through to UIScriptController, matching the pattern
     15        established by scrollingTreeAsText.
     16
    1172021-08-12  Devin Rousso  <drousso@apple.com>
    218
  • trunk/Tools/TestRunnerShared/UIScriptContext/Bindings/UIScriptController.idl

    r280767 r280980  
    333333
    334334    readonly attribute DOMString scrollingTreeAsText;
     335    readonly attribute DOMString uiViewTreeAsText;
    335336
    336337    boolean mayContainEditableElementsInRect(unsigned long x, unsigned long y, unsigned long width, unsigned long height);
  • trunk/Tools/TestRunnerShared/UIScriptContext/UIScriptController.h

    r280767 r280980  
    147147
    148148    virtual JSRetainPtr<JSStringRef> scrollingTreeAsText() const { notImplemented(); return nullptr; }
     149    virtual JSRetainPtr<JSStringRef> uiViewTreeAsText() const { notImplemented(); return nullptr; }
    149150
    150151    // Touches
  • trunk/Tools/WebKitTestRunner/ios/UIScriptControllerIOS.h

    r280767 r280980  
    118118    JSObjectRef inputViewBounds() const override;
    119119    JSRetainPtr<JSStringRef> scrollingTreeAsText() const override;
     120    JSRetainPtr<JSStringRef> uiViewTreeAsText() const override;
    120121    JSObjectRef propertiesOfLayerWithID(uint64_t layerID) const override;
    121122    void simulateRotation(DeviceOrientation*, JSValueRef) override;
  • trunk/Tools/WebKitTestRunner/ios/UIScriptControllerIOS.mm

    r280767 r280980  
    858858}
    859859
     860JSRetainPtr<JSStringRef> UIScriptControllerIOS::uiViewTreeAsText() const
     861{
     862    return adopt(JSStringCreateWithCFString((CFStringRef)[webView() _uiViewTreeAsText]));
     863}
     864
    860865JSObjectRef UIScriptControllerIOS::propertiesOfLayerWithID(uint64_t layerID) const
    861866{
Note: See TracChangeset for help on using the changeset viewer.