Changeset 190260 in webkit


Ignore:
Timestamp:
Sep 25, 2015 5:17:27 PM (9 years ago)
Author:
Simon Fraser
Message:

[iOS WK2] Add viewport tests and fix runUIScript() timing issues
https://bugs.webkit.org/show_bug.cgi?id=149577

Reviewed by Tim Horton.

Source/WebKit2:

When calling testRunner.runUIScript() from a page load event, the script could run
in the UI process before the current remote layer tree transaction had been handled
there. This meant that runUIScript() could query state which was about to change.

Fix by delaying the execution of the UI script until a layer tree transaction has
been handled by the UI process, leveraging the existing DrawingAreaProxy::dispatchAfterEnsuringDrawing().

This is done using a new C SPI function WKPageCallAfterNextPresentationUpdate(),
which is mirrored in the Obj-C SPI as -_doAfterNextPresentationUpdate:.

Move WKWebView SPI which is testing-related into a WKTesting category. It is expected
that this will grow significantly.

  • UIProcess/API/C/WKPage.cpp:

(WKPageCallAfterNextPresentationUpdate):

  • UIProcess/API/C/WKPagePrivate.h:
  • UIProcess/API/Cocoa/WKWebView.mm:
  • UIProcess/API/Cocoa/WKWebViewPrivate.h:
  • UIProcess/WebPageProxy.cpp:

(WebKit::WebPageProxy::callAfterNextPresentationUpdate):

  • UIProcess/WebPageProxy.h:
  • UIProcess/mac/TiledCoreAnimationDrawingAreaProxy.h:
  • UIProcess/mac/TiledCoreAnimationDrawingAreaProxy.mm:

(WebKit::TiledCoreAnimationDrawingAreaProxy::dispatchAfterEnsuringDrawing):

Tools:

When calling testRunner.runUIScript() from a page load event, the script could run
in the UI process before the current remote layer tree transaction had been handled
there. This meant that runUIScript() could query state which was about to change.

Fix by delaying the execution of the UI script until a layer tree transaction has
been handled by the UI process, leveraging the existing DrawingAreaProxy::dispatchAfterEnsuringDrawing().

  • WebKitTestRunner/TestInvocation.cpp:

(WTR::TestInvocation::didReceiveMessageFromInjectedBundle):
(WTR::TestInvocation::runUISideScriptAfterUpdateCallback):

  • WebKitTestRunner/TestInvocation.h:

LayoutTests:

New viewport tests which read the scale etc. in the UI process.

(getUIScript):
(tableFromJSON):
(getViewport):
(runTest):

  • fast/viewport/ios/width-is-device-width-expected.txt: Added.
  • fast/viewport/ios/width-is-device-width-overflowing-body-overflow-hidden-tall-expected.txt: Added.
  • fast/viewport/ios/width-is-device-width-overflowing-body-overflow-hidden-tall.html: Added.
  • fast/viewport/ios/width-is-device-width-overflowing-body-overflow-hidden.html: Added.
  • fast/viewport/ios/width-is-device-width-overflowing-expected.txt: Added.
  • fast/viewport/ios/width-is-device-width-overflowing-no-shrink-to-fit-expected.txt: Added.
  • fast/viewport/ios/width-is-device-width-overflowing-no-shrink-to-fit.html: Added.
  • fast/viewport/ios/width-is-device-width-overflowing.html: Added.
  • fast/viewport/ios/width-is-device-width.html: Added.
  • platform/ios-simulator-wk2/TestExpectations:
Location:
trunk
Files:
12 added
15 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r190256 r190260  
     12015-09-25  Simon Fraser  <simon.fraser@apple.com>
     2
     3        [iOS WK2] Add viewport tests and fix runUIScript() timing issues
     4        https://bugs.webkit.org/show_bug.cgi?id=149577
     5
     6        Reviewed by Tim Horton.
     7       
     8        New viewport tests which read the scale etc. in the UI process.
     9
     10        * TestExpectations:
     11        * fast/viewport/ios/resources/viewport-test-utils.js: Added.
     12        (getUIScript):
     13        (tableFromJSON):
     14        (getViewport):
     15        (runTest):
     16        * fast/viewport/ios/width-is-device-width-expected.txt: Added.
     17        * fast/viewport/ios/width-is-device-width-overflowing-body-overflow-hidden-tall-expected.txt: Added.
     18        * fast/viewport/ios/width-is-device-width-overflowing-body-overflow-hidden-tall.html: Added.
     19        * fast/viewport/ios/width-is-device-width-overflowing-body-overflow-hidden.html: Added.
     20        * fast/viewport/ios/width-is-device-width-overflowing-expected.txt: Added.
     21        * fast/viewport/ios/width-is-device-width-overflowing-no-shrink-to-fit-expected.txt: Added.
     22        * fast/viewport/ios/width-is-device-width-overflowing-no-shrink-to-fit.html: Added.
     23        * fast/viewport/ios/width-is-device-width-overflowing.html: Added.
     24        * fast/viewport/ios/width-is-device-width.html: Added.
     25        * platform/ios-simulator-wk2/TestExpectations:
     26
    1272015-09-25  Antti Koivisto  <antti@apple.com>
    228
  • trunk/LayoutTests/TestExpectations

    r190150 r190260  
    1616swipe [ Skip ]
    1717fast/zooming/ios [ Skip ]
     18fast/viewport/ios [ Skip ]
    1819
    1920fast/forms/attributed-strings.html [ Skip ]
  • trunk/LayoutTests/platform/ios-simulator-wk2/TestExpectations

    r190100 r190260  
    1010fast/harness/concurrent-ui-side-scripts.html [ Pass ]
    1111fast/zooming/ios [ Pass ]
     12fast/viewport/ios [ Pass ]
    1213
    1314#//////////////////////////////////////////////////////////////////////////////////////////
  • trunk/Source/WebKit2/ChangeLog

    r190257 r190260  
     12015-09-25  Simon Fraser  <simon.fraser@apple.com>
     2
     3        [iOS WK2] Add viewport tests and fix runUIScript() timing issues
     4        https://bugs.webkit.org/show_bug.cgi?id=149577
     5
     6        Reviewed by Tim Horton.
     7       
     8        When calling testRunner.runUIScript() from a page load event, the script could run
     9        in the UI process before the current remote layer tree transaction had been handled
     10        there. This meant that runUIScript() could query state which was about to change.
     11       
     12        Fix by delaying the execution of the UI script until a layer tree transaction has
     13        been handled by the UI process, leveraging the existing DrawingAreaProxy::dispatchAfterEnsuringDrawing().
     14       
     15        This is done using a new C SPI function WKPageCallAfterNextPresentationUpdate(),
     16        which is mirrored in the Obj-C SPI as -_doAfterNextPresentationUpdate:.
     17       
     18        Move WKWebView SPI which is testing-related into a WKTesting category. It is expected
     19        that this will grow significantly.
     20
     21        * UIProcess/API/C/WKPage.cpp:
     22        (WKPageCallAfterNextPresentationUpdate):
     23        * UIProcess/API/C/WKPagePrivate.h:
     24        * UIProcess/API/Cocoa/WKWebView.mm:
     25        * UIProcess/API/Cocoa/WKWebViewPrivate.h:
     26        * UIProcess/WebPageProxy.cpp:
     27        (WebKit::WebPageProxy::callAfterNextPresentationUpdate):
     28        * UIProcess/WebPageProxy.h:
     29        * UIProcess/mac/TiledCoreAnimationDrawingAreaProxy.h:
     30        * UIProcess/mac/TiledCoreAnimationDrawingAreaProxy.mm:
     31        (WebKit::TiledCoreAnimationDrawingAreaProxy::dispatchAfterEnsuringDrawing):
     32
    1332015-09-25  Alexey Proskuryakov  <ap@apple.com>
    234
  • trunk/Source/WebKit2/UIProcess/API/C/WKPage.cpp

    r190064 r190260  
    24702470}
    24712471
     2472void WKPageCallAfterNextPresentationUpdate(WKPageRef pageRef, void* context, WKPagePostPresentationUpdateFunction callback)
     2473{
     2474    toImpl(pageRef)->callAfterNextPresentationUpdate([context, callback](WebKit::CallbackBase::Error error) {
     2475        callback(error != WebKit::CallbackBase::Error::None ? toAPI(API::Error::create().ptr()) : 0, context);
     2476    });
     2477}
    24722478
    24732479#if ENABLE(NETSCAPE_PLUGIN_API)
  • trunk/Source/WebKit2/UIProcess/API/C/WKPagePrivate.h

    r188793 r190260  
    122122WK_EXPORT void WKPageLoadURLWithShouldOpenExternalURLsPolicy(WKPageRef page, WKURLRef url, bool shouldOpenExternalURLs);
    123123
     124typedef void (*WKPagePostPresentationUpdateFunction)(WKErrorRef, void*);
     125WK_EXPORT void WKPageCallAfterNextPresentationUpdate(WKPageRef page, void* context, WKPagePostPresentationUpdateFunction function);
     126
    124127#ifdef __cplusplus
    125128}
  • trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm

    r190065 r190260  
    30213021}
    30223022
    3023 - (CGRect)_contentVisibleRect
    3024 {
    3025     return [self convertRect:[self bounds] toView:self._currentContentView];
    3026 }
    3027 
    3028 - (CGPoint)_convertPointFromContentsToView:(CGPoint)point
    3029 {
    3030     return [self convertPoint:point fromView:self._currentContentView];
    3031 }
    3032 
    3033 - (CGPoint)_convertPointFromViewToContents:(CGPoint)point
    3034 {
    3035     return [self convertPoint:point toView:self._currentContentView];
    3036 }
    3037 
    30383023- (_WKWebViewPrintFormatter *)_webViewPrintFormatter
    30393024{
     
    31083093}
    31093094
    3110 #endif
     3095#endif // __MAC_OS_X_VERSION_MIN_REQUIRED >= 101000
    31113096
    31123097#endif
     
    31143099@end
    31153100
    3116 #if !TARGET_OS_IPHONE
     3101
     3102@implementation WKWebView (WKTesting)
     3103
     3104#if PLATFORM(IOS)
     3105
     3106- (CGRect)_contentVisibleRect
     3107{
     3108    return [self convertRect:[self bounds] toView:self._currentContentView];
     3109}
     3110
     3111- (CGPoint)_convertPointFromContentsToView:(CGPoint)point
     3112{
     3113    return [self convertPoint:point fromView:self._currentContentView];
     3114}
     3115
     3116- (CGPoint)_convertPointFromViewToContents:(CGPoint)point
     3117{
     3118    return [self convertPoint:point toView:self._currentContentView];
     3119}
     3120
     3121#endif // PLATFORM(IOS)
     3122
     3123// Execute the supplied block after the next transaction from the WebProcess.
     3124- (void)_doAfterNextPresentationUpdate:(void (^)(void))updateBlock
     3125{
     3126    typeof(updateBlock) updateBlockCopy = nil;
     3127    if (updateBlock)
     3128        updateBlockCopy = Block_copy(updateBlock);
     3129
     3130    _page->callAfterNextPresentationUpdate([updateBlockCopy](WebKit::CallbackBase::Error error) {
     3131        updateBlockCopy();
     3132        Block_release(updateBlockCopy);
     3133    });
     3134}
     3135
     3136@end
     3137
     3138
     3139#if PLATFORM(MAC)
    31173140
    31183141@implementation WKWebView (WKIBActions)
     
    31683191@end
    31693192
    3170 #endif
     3193#endif // PLATFORM(MAC)
    31713194
    31723195#if PLATFORM(IOS)
  • trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewPrivate.h

    r190065 r190260  
    126126@property (nonatomic, readonly) CGFloat _viewportMetaTagWidth;
    127127
    128 @property (nonatomic, readonly) CGRect _contentVisibleRect;
    129 
    130128@property (nonatomic, readonly) _WKWebViewPrintFormatter *_webViewPrintFormatter;
    131 
    132 - (CGPoint)_convertPointFromContentsToView:(CGPoint)point;
    133 - (CGPoint)_convertPointFromViewToContents:(CGPoint)point;
    134129
    135130- (void)_beginInteractiveObscuredInsetsChange;
     
    218213@end
    219214
    220 #endif
     215
     216@interface WKWebView (WKTesting)
     217
     218#if TARGET_OS_IPHONE
     219@property (nonatomic, readonly) CGRect _contentVisibleRect WK_AVAILABLE(WK_MAC_TBA, WK_IOS_TBA);
     220- (CGPoint)_convertPointFromContentsToView:(CGPoint)point WK_AVAILABLE(WK_MAC_TBA, WK_IOS_TBA);
     221- (CGPoint)_convertPointFromViewToContents:(CGPoint)point WK_AVAILABLE(WK_MAC_TBA, WK_IOS_TBA);
     222#endif
     223
     224- (void)_doAfterNextPresentationUpdate:(void (^)(void))updateBlock WK_AVAILABLE(WK_MAC_TBA, WK_IOS_TBA);
     225
     226@end
     227
     228
     229#endif
  • trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp

    r190064 r190260  
    60856085}
    60866086
     6087void WebPageProxy::callAfterNextPresentationUpdate(std::function<void (CallbackBase::Error)> callback)
     6088{
     6089    m_drawingArea->dispatchAfterEnsuringDrawing(callback);
     6090}
     6091
    60876092void WebPageProxy::setShouldScaleViewToFitDocument(bool shouldScaleViewToFitDocument)
    60886093{
  • trunk/Source/WebKit2/UIProcess/WebPageProxy.h

    r190064 r190260  
    10581058    void didLayoutForCustomContentProvider();
    10591059
     1060    // For testing
    10601061    void clearWheelEventTestTrigger();
     1062    void callAfterNextPresentationUpdate(std::function<void (CallbackBase::Error)>);
    10611063
    10621064    void didLayout(uint32_t layoutMilestones);
  • trunk/Source/WebKit2/UIProcess/mac/TiledCoreAnimationDrawingAreaProxy.h

    r186662 r190260  
    5454
    5555    virtual void waitForDidUpdateViewState() override;
     56    virtual void dispatchAfterEnsuringDrawing(std::function<void (CallbackBase::Error)>) override;
    5657
    5758    virtual void willSendUpdateGeometry() override;
  • trunk/Source/WebKit2/UIProcess/mac/TiledCoreAnimationDrawingAreaProxy.mm

    r186693 r190260  
    207207}
    208208
     209void TiledCoreAnimationDrawingAreaProxy::dispatchAfterEnsuringDrawing(std::function<void (CallbackBase::Error)> callback)
     210{
     211    // This callback is primarily used for testing in RemoteLayerTreeDrawingArea. We could in theory wait for a CA commit here.
     212    dispatch_async(dispatch_get_main_queue(), ^{
     213        callback(CallbackBase::Error::None);
     214    });
     215}
     216
    209217} // namespace WebKit
    210218
  • trunk/Tools/ChangeLog

    r190257 r190260  
     12015-09-25  Simon Fraser  <simon.fraser@apple.com>
     2
     3        [iOS WK2] Add viewport tests and fix runUIScript() timing issues
     4        https://bugs.webkit.org/show_bug.cgi?id=149577
     5
     6        Reviewed by Tim Horton.
     7       
     8        When calling testRunner.runUIScript() from a page load event, the script could run
     9        in the UI process before the current remote layer tree transaction had been handled
     10        there. This meant that runUIScript() could query state which was about to change.
     11       
     12        Fix by delaying the execution of the UI script until a layer tree transaction has
     13        been handled by the UI process, leveraging the existing DrawingAreaProxy::dispatchAfterEnsuringDrawing().
     14
     15        * WebKitTestRunner/TestInvocation.cpp:
     16        (WTR::TestInvocation::didReceiveMessageFromInjectedBundle):
     17        (WTR::TestInvocation::runUISideScriptAfterUpdateCallback):
     18        * WebKitTestRunner/TestInvocation.h:
     19
    1202015-09-25  Alexey Proskuryakov  <ap@apple.com>
    221
  • trunk/Tools/WebKitTestRunner/TestInvocation.cpp

    r190065 r190260  
    669669        WKRetainPtr<WKStringRef> callbackIDKey(AdoptWK, WKStringCreateWithUTF8CString("CallbackID"));
    670670
    671         unsigned callbackID = (unsigned)WKUInt64GetValue(static_cast<WKUInt64Ref>(WKDictionaryGetItemForKey(messageBodyDictionary, callbackIDKey.get())));
    672         WKStringRef scriptString = static_cast<WKStringRef>(WKDictionaryGetItemForKey(messageBodyDictionary, scriptKey.get()));
    673 
    674         runUISideScript(scriptString, callbackID);
     671        UIScriptInvocationData* invocationData = new UIScriptInvocationData();
     672        invocationData->testInvocation = this;
     673        invocationData->callbackID = (unsigned)WKUInt64GetValue(static_cast<WKUInt64Ref>(WKDictionaryGetItemForKey(messageBodyDictionary, callbackIDKey.get())));
     674        invocationData->scriptString = static_cast<WKStringRef>(WKDictionaryGetItemForKey(messageBodyDictionary, scriptKey.get()));
     675        WKPageCallAfterNextPresentationUpdate(TestController::singleton().mainWebView()->page(), invocationData, runUISideScriptAfterUpdateCallback);
    675676        return;
    676677    }
     
    721722}
    722723
     724void TestInvocation::runUISideScriptAfterUpdateCallback(WKErrorRef, void* context)
     725{
     726    UIScriptInvocationData* data = static_cast<UIScriptInvocationData*>(context);
     727    data->testInvocation->runUISideScript(data->scriptString.get(), data->callbackID);
     728    delete data;
     729}
     730
    723731void TestInvocation::runUISideScript(WKStringRef script, unsigned scriptCallbackID)
    724732{
  • trunk/Tools/WebKitTestRunner/TestInvocation.h

    r190065 r190260  
    7575
    7676    static void forceRepaintDoneCallback(WKErrorRef, void* context);
     77   
     78    struct UIScriptInvocationData {
     79        unsigned callbackID;
     80        WebKit::WKRetainPtr<WKStringRef> scriptString;
     81        TestInvocation* testInvocation;
     82    };
     83    static void runUISideScriptAfterUpdateCallback(WKErrorRef, void* context);
    7784
    7885    bool shouldLogFrameLoadDelegates() const;
Note: See TracChangeset for help on using the changeset viewer.