Changeset 216291 in webkit


Ignore:
Timestamp:
May 5, 2017 4:39:19 PM (7 years ago)
Author:
Simon Fraser
Message:

Make it possible to test rotation in iOS WebKitTestRunner
https://bugs.webkit.org/show_bug.cgi?id=171755

Reviewed by Tim Horton.

Tools:

Add to UIScriptController:

void simulateRotation(DeviceOrientation orientation, object callback);
void simulateRotationLikeSafari(DeviceOrientation orientation, object callback);

The former just does a view resize, as a simple WKWebView app would do. The second does
animation more like MobileSafari, using _begin/_endAnimatedResize. and associated override
layout size and interface orientation. The two behaviors produce different resize and
orientationchange events and sizes, and both need to be tested.

Rotation is initiated by a call on UIDevice, and responded to by the root view controller,
which is now a custom subclass (PlatformWebViewController).

  • DumpRenderTree/ios/UIScriptControllerIOS.mm:

(WTR::UIScriptController::simulateRotation):
(WTR::UIScriptController::simulateRotationLikeSafari):

  • DumpRenderTree/mac/UIScriptControllerMac.mm:

(WTR::UIScriptController::simulateRotation):
(WTR::UIScriptController::simulateRotationLikeSafari):

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

(WTR::toDeviceOrientation):
(WTR::UIScriptController::simulateRotation):
(WTR::UIScriptController::simulateRotationLikeSafari):

  • TestRunnerShared/UIScriptContext/UIScriptController.h:
  • WebKitTestRunner/cocoa/TestRunnerWKWebView.h:
  • WebKitTestRunner/cocoa/TestRunnerWKWebView.mm:

(-[TestRunnerWKWebView dealloc]):
(-[TestRunnerWKWebView _didEndRotation]):

  • WebKitTestRunner/ios/PlatformWebViewIOS.mm:

(-[PlatformWebViewController viewWillTransitionToSize:withTransitionCoordinator:]):
(WTR::PlatformWebView::PlatformWebView):

  • WebKitTestRunner/ios/TestControllerIOS.mm:

(WTR::TestController::platformResetStateToConsistentValues):

  • WebKitTestRunner/ios/UIScriptControllerIOS.mm:

(WTR::toUIDeviceOrientation):
(WTR::UIScriptController::simulateRotation):
(WTR::UIScriptController::simulateRotationLikeSafari):
(WTR::UIScriptController::platformClearAllCallbacks):

  • WebKitTestRunner/mac/UIScriptControllerMac.mm:

(WTR::UIScriptController::simulateRotation):
(WTR::UIScriptController::simulateRotationLikeSafari):

LayoutTests:

Two rotation tests and one that comes last to ensure that the device was not left in a rotated state.

  • fast/events/ios/rotation/basic-rotation-expected.txt: Added.
  • fast/events/ios/rotation/basic-rotation.html: Added.
  • fast/events/ios/rotation/safari-like-rotation-expected.txt: Added.
  • fast/events/ios/rotation/safari-like-rotation.html: Added.
  • fast/events/ios/rotation/zz-no-rotation-expected.txt: Added.
  • fast/events/ios/rotation/zz-no-rotation.html: Added.
Location:
trunk
Files:
7 added
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r216289 r216291  
     12017-05-05  Simon Fraser  <simon.fraser@apple.com>
     2
     3        Make it possible to test rotation in iOS WebKitTestRunner
     4        https://bugs.webkit.org/show_bug.cgi?id=171755
     5
     6        Reviewed by Tim Horton.
     7
     8        Two rotation tests and one that comes last to ensure that the device was not left in a rotated state.
     9
     10        * fast/events/ios/rotation/basic-rotation-expected.txt: Added.
     11        * fast/events/ios/rotation/basic-rotation.html: Added.
     12        * fast/events/ios/rotation/safari-like-rotation-expected.txt: Added.
     13        * fast/events/ios/rotation/safari-like-rotation.html: Added.
     14        * fast/events/ios/rotation/zz-no-rotation-expected.txt: Added.
     15        * fast/events/ios/rotation/zz-no-rotation.html: Added.
     16
    1172017-05-05  Ryan Haddad  <ryanhaddad@apple.com>
    218
  • trunk/Tools/ChangeLog

    r216288 r216291  
     12017-05-05  Simon Fraser  <simon.fraser@apple.com>
     2
     3        Make it possible to test rotation in iOS WebKitTestRunner
     4        https://bugs.webkit.org/show_bug.cgi?id=171755
     5
     6        Reviewed by Tim Horton.
     7
     8        Add to UIScriptController:
     9            void simulateRotation(DeviceOrientation orientation, object callback);
     10            void simulateRotationLikeSafari(DeviceOrientation orientation, object callback);
     11
     12        The former just does a view resize, as a simple WKWebView app would do. The second does
     13        animation more like MobileSafari, using _begin/_endAnimatedResize. and associated override
     14        layout size and interface orientation. The two behaviors produce different resize and
     15        orientationchange events and sizes, and both need to be tested.
     16
     17        Rotation is initiated by a call on UIDevice, and responded to by the root view controller,
     18        which is now a custom subclass (PlatformWebViewController).
     19
     20        * DumpRenderTree/ios/UIScriptControllerIOS.mm:
     21        (WTR::UIScriptController::simulateRotation):
     22        (WTR::UIScriptController::simulateRotationLikeSafari):
     23        * DumpRenderTree/mac/UIScriptControllerMac.mm:
     24        (WTR::UIScriptController::simulateRotation):
     25        (WTR::UIScriptController::simulateRotationLikeSafari):
     26        * TestRunnerShared/UIScriptContext/Bindings/UIScriptController.idl:
     27        * TestRunnerShared/UIScriptContext/UIScriptController.cpp:
     28        (WTR::toDeviceOrientation):
     29        (WTR::UIScriptController::simulateRotation):
     30        (WTR::UIScriptController::simulateRotationLikeSafari):
     31        * TestRunnerShared/UIScriptContext/UIScriptController.h:
     32        * WebKitTestRunner/cocoa/TestRunnerWKWebView.h:
     33        * WebKitTestRunner/cocoa/TestRunnerWKWebView.mm:
     34        (-[TestRunnerWKWebView dealloc]):
     35        (-[TestRunnerWKWebView _didEndRotation]):
     36        * WebKitTestRunner/ios/PlatformWebViewIOS.mm:
     37        (-[PlatformWebViewController viewWillTransitionToSize:withTransitionCoordinator:]):
     38        (WTR::PlatformWebView::PlatformWebView):
     39        * WebKitTestRunner/ios/TestControllerIOS.mm:
     40        (WTR::TestController::platformResetStateToConsistentValues):
     41        * WebKitTestRunner/ios/UIScriptControllerIOS.mm:
     42        (WTR::toUIDeviceOrientation):
     43        (WTR::UIScriptController::simulateRotation):
     44        (WTR::UIScriptController::simulateRotationLikeSafari):
     45        (WTR::UIScriptController::platformClearAllCallbacks):
     46        * WebKitTestRunner/mac/UIScriptControllerMac.mm:
     47        (WTR::UIScriptController::simulateRotation):
     48        (WTR::UIScriptController::simulateRotationLikeSafari):
     49
    1502017-05-05  Jonathan Bedard  <jbedard@apple.com>
    251
  • trunk/Tools/DumpRenderTree/ios/UIScriptControllerIOS.mm

    r216047 r216291  
    223223}
    224224
    225 
    226225JSObjectRef UIScriptController::contentVisibleRect() const
    227226{
     
    309308}
    310309
     310void UIScriptController::simulateRotation(DeviceOrientation*, JSValueRef)
     311{
     312}
     313
     314void UIScriptController::simulateRotationLikeSafari(DeviceOrientation*, JSValueRef)
     315{
     316}
     317
    311318void UIScriptController::removeViewFromWindow(JSValueRef)
    312319{
  • trunk/Tools/DumpRenderTree/mac/UIScriptControllerMac.mm

    r214586 r216291  
    109109}
    110110
     111void UIScriptController::simulateRotation(DeviceOrientation*, JSValueRef)
     112{
     113}
     114
     115void UIScriptController::simulateRotationLikeSafari(DeviceOrientation*, JSValueRef)
     116{
     117}
     118
    111119void UIScriptController::removeViewFromWindow(JSValueRef callback)
    112120{
  • trunk/Tools/TestRunnerShared/UIScriptContext/Bindings/UIScriptController.idl

    r216047 r216291  
    2323 * THE POSSIBILITY OF SUCH DAMAGE.
    2424 */
     25 
     26enum DeviceOrientation {
     27    "portrait",
     28    "portrait-upsidedown",
     29    "landscape-left",
     30    "landscape-right"
     31};
    2532
    2633interface UIScriptController {
     
    227234    void retrieveSpeakSelectionContent(object callback);
    228235    readonly attribute DOMString accessibilitySpeakSelectionContent;
     236   
     237    void simulateRotation(DeviceOrientation orientation, object callback);
     238    void simulateRotationLikeSafari(DeviceOrientation orientation, object callback);
    229239
    230240    // Unparent and parent the web view, simulating, for example, tab switching.
  • trunk/Tools/TestRunnerShared/UIScriptContext/UIScriptController.cpp

    r216047 r216291  
    3030#include "UIScriptContext.h"
    3131#include <JavaScriptCore/JSValueRef.h>
     32#include <JavaScriptCore/OpaqueJSString.h>
    3233
    3334namespace WTR {
     35
     36DeviceOrientation* toDeviceOrientation(JSContextRef context, JSValueRef value)
     37{
     38    static DeviceOrientation values[] = {
     39        DeviceOrientation::Portrait,
     40        DeviceOrientation::PortraitUpsideDown,
     41        DeviceOrientation::LandscapeLeft,
     42        DeviceOrientation::LandscapeRight
     43    };
     44
     45    JSRetainPtr<JSStringRef> option(Adopt, JSValueToStringCopy(context, value, nullptr));
     46    if (option.get()->string() == "portrait")
     47        return &values[0];
     48       
     49    if (option.get()->string() == "portrait-upsidedown")
     50        return &values[1];
     51       
     52    if (option.get()->string() == "landscape-left")
     53        return &values[2];
     54       
     55    if (option.get()->string() == "landscape-right")
     56        return &values[3];
     57       
     58    return nullptr;
     59}
    3460
    3561UIScriptController::UIScriptController(UIScriptContext& context)
     
    408434#if !PLATFORM(COCOA)
    409435
     436void UIScriptController::simulateRotation(DeviceOrientation*, JSValueRef callback)
     437{
     438}
     439
     440void UIScriptController::simulateRotationLikeSafari(DeviceOrientation*, JSValueRef callback)
     441{
     442}
     443
    410444void UIScriptController::removeViewFromWindow(JSValueRef)
    411445{
  • trunk/Tools/TestRunnerShared/UIScriptContext/UIScriptController.h

    r216047 r216291  
    4040class UIScriptContext;
    4141
     42enum class DeviceOrientation {
     43    Portrait,
     44    PortraitUpsideDown,
     45    LandscapeLeft,
     46    LandscapeRight
     47};
     48
     49DeviceOrientation* toDeviceOrientation(JSContextRef, JSValueRef);
     50
    4251class UIScriptController : public JSWrappable {
    4352public:
     
    152161    void retrieveSpeakSelectionContent(JSValueRef);
    153162    JSRetainPtr<JSStringRef> accessibilitySpeakSelectionContent() const;
     163   
     164    void simulateRotation(DeviceOrientation*, JSValueRef);
     165    void simulateRotationLikeSafari(DeviceOrientation*, JSValueRef);
    154166
    155167    // These use a callback to allow the client to know when view visibility state updates get to the web process.
  • trunk/Tools/WebKitTestRunner/cocoa/TestRunnerWKWebView.h

    r216047 r216291  
    4141@property (nonatomic, copy) void (^didHideKeyboardCallback)(void);
    4242@property (nonatomic, copy) void (^didEndScrollingCallback)(void);
     43@property (nonatomic, copy) void (^rotationDidEndCallback)(void);
    4344@property (nonatomic, copy) NSString *accessibilitySpeakSelectionContent;
    4445
    4546- (void)zoomToScale:(double)scale animated:(BOOL)animated completionHandler:(void (^)(void))completionHandler;
    4647- (void)accessibilityRetrieveSpeakSelectionContentWithCompletionHandler:(void (^)(void))completionHandler;
     48- (void)_didEndRotation;
    4749
    4850@property (nonatomic, assign) UIEdgeInsets overrideSafeAreaInsets;
     51
     52@property (nonatomic, assign) BOOL usesSafariLikeRotation;
    4953
    5054#endif
  • trunk/Tools/WebKitTestRunner/cocoa/TestRunnerWKWebView.mm

    r216047 r216291  
    9292    self.didHideKeyboardCallback = nil;
    9393    self.didEndScrollingCallback = nil;
     94    self.rotationDidEndCallback = nil;
    9495
    9596    self.zoomToScaleCompletionHandler = nil;
     
    192193}
    193194
     195- (void)_didEndRotation
     196{
     197    if (self.rotationDidEndCallback)
     198        self.rotationDidEndCallback();
     199}
     200
    194201- (void)_accessibilityDidGetSpeakSelectionContent:(NSString *)content
    195202{
  • trunk/Tools/WebKitTestRunner/ios/PlatformWebViewIOS.mm

    r215176 r216291  
    2929#import "TestController.h"
    3030#import "TestRunnerWKWebView.h"
     31#import "UIKitSPI.h"
    3132#import <WebCore/QuartzCoreSPI.h>
    3233#import <WebKit/WKImageCG.h>
     
    108109@end
    109110
     111@interface PlatformWebViewController : UIViewController
     112@end
     113
     114@implementation PlatformWebViewController
     115
     116- (void)viewWillTransitionToSize:(CGSize)toSize withTransitionCoordinator:(id <UIViewControllerTransitionCoordinator>)coordinator
     117{
     118    [super viewWillTransitionToSize:toSize withTransitionCoordinator:coordinator];
     119   
     120    TestRunnerWKWebView *webView = WTR::TestController::singleton().mainWebView()->platformView();
     121   
     122    if (webView.usesSafariLikeRotation)
     123        [webView _setInterfaceOrientationOverride:[[UIApplication sharedApplication] statusBarOrientation]];
     124       
     125    [coordinator animateAlongsideTransition: ^(id<UIViewControllerTransitionCoordinatorContext> context) {
     126        if (webView.usesSafariLikeRotation) {
     127            [webView _beginAnimatedResizeWithUpdates:^{
     128                auto size = self.view.bounds.size;
     129                webView.frame = self.view.bounds;
     130                [webView _overrideLayoutParametersWithMinimumLayoutSize:size maximumUnobscuredSizeOverride:size];
     131                [webView _setInterfaceOrientationOverride:[[UIApplication sharedApplication] statusBarOrientation]];
     132            }];
     133        } else
     134            webView.frame = self.view.bounds;
     135    } completion:^(id<UIViewControllerTransitionCoordinatorContext> context) {
     136        webView.frame = self.view.bounds;
     137        if (webView.usesSafariLikeRotation)
     138            [webView _endAnimatedResize];
     139           
     140        [webView _didEndRotation];
     141    }];
     142}
     143
     144@end
     145
    110146namespace WTR {
    111147
     
    131167    m_window.platformWebView = this;
    132168
    133     UIViewController *viewController = [[UIViewController alloc] init];
     169    UIViewController *viewController = [[PlatformWebViewController alloc] init];
    134170    [m_window setRootViewController:viewController];
    135171    [viewController release];
  • trunk/Tools/WebKitTestRunner/ios/TestControllerIOS.mm

    r216047 r216291  
    8181    cocoaResetStateToConsistentValues();
    8282
     83    [[UIDevice currentDevice] setOrientation:UIDeviceOrientationPortrait animated:NO];
     84   
    8385    if (PlatformWebView* webView = mainWebView()) {
    8486        webView->platformView()._stableStateOverride = nil;
     87        webView->platformView().usesSafariLikeRotation = NO;
    8588        UIScrollView *scrollView = webView->platformView().scrollView;
    8689        [scrollView _removeAllAnimations:YES];
  • trunk/Tools/WebKitTestRunner/ios/UIKitSPI.h

    r216047 r216291  
    2424 */
    2525
    26 #ifndef UIKitSPI_h
    27 #define UIKitSPI_h
     26#pragma once
    2827
    2928#import <wtf/Platform.h>
     
    3938#import <UIKit/UIView_Private.h>
    4039#import <UIKit/UIWindow_Private.h>
     40#import <UIKit/UIDevice_Private.h>
    4141
    4242@interface UIKeyboardPredictionView : UIView
     
    6666@end
    6767
     68@interface UIDevice ()
     69- (void)setOrientation:(UIDeviceOrientation)orientation animated:(BOOL)animated;
     70 @end
     71 
    6872#endif // USE(APPLE_INTERNAL_SDK)
    6973
     
    7680#endif // PLATFORM(IOS)
    7781
    78 #endif // UIKitSPI_h
  • trunk/Tools/WebKitTestRunner/ios/UIScriptControllerIOS.mm

    r216047 r216291  
    554554}
    555555
     556static UIDeviceOrientation toUIDeviceOrientation(DeviceOrientation* orientation)
     557{
     558    if (!orientation)
     559        return UIDeviceOrientationPortrait;
     560       
     561    switch (*orientation) {
     562    case DeviceOrientation::Portrait:
     563        return UIDeviceOrientationPortrait;
     564    case DeviceOrientation::PortraitUpsideDown:
     565        return UIDeviceOrientationPortraitUpsideDown;
     566    case DeviceOrientation::LandscapeLeft:
     567        return UIDeviceOrientationLandscapeLeft;
     568    case DeviceOrientation::LandscapeRight:
     569        return UIDeviceOrientationLandscapeRight;
     570    }
     571   
     572    return UIDeviceOrientationPortrait;
     573}
     574
     575void UIScriptController::simulateRotation(DeviceOrientation* orientation, JSValueRef callback)
     576{
     577    TestRunnerWKWebView *webView = TestController::singleton().mainWebView()->platformView();
     578    webView.usesSafariLikeRotation = NO;
     579   
     580    unsigned callbackID = m_context->prepareForAsyncTask(callback, CallbackTypeNonPersistent);
     581   
     582    webView.rotationDidEndCallback = ^{
     583        if (!m_context)
     584            return;
     585        m_context->asyncTaskComplete(callbackID);
     586    };
     587   
     588    [[UIDevice currentDevice] setOrientation:toUIDeviceOrientation(orientation) animated:YES];
     589}
     590
     591void UIScriptController::simulateRotationLikeSafari(DeviceOrientation* orientation, JSValueRef callback)
     592{
     593    TestRunnerWKWebView *webView = TestController::singleton().mainWebView()->platformView();
     594    webView.usesSafariLikeRotation = YES;
     595   
     596    unsigned callbackID = m_context->prepareForAsyncTask(callback, CallbackTypeNonPersistent);
     597   
     598    webView.rotationDidEndCallback = ^{
     599        if (!m_context)
     600            return;
     601        m_context->asyncTaskComplete(callbackID);
     602    };
     603   
     604    [[UIDevice currentDevice] setOrientation:toUIDeviceOrientation(orientation) animated:YES];
     605}
     606
    556607void UIScriptController::removeViewFromWindow(JSValueRef callback)
    557608{
     
    667718    webView.didShowKeyboardCallback = nil;
    668719    webView.didEndScrollingCallback = nil;
     720    webView.rotationDidEndCallback = nil;
    669721}
    670722
  • trunk/Tools/WebKitTestRunner/mac/UIScriptControllerMac.mm

    r214586 r216291  
    157157}
    158158
     159void UIScriptController::simulateRotation(DeviceOrientation*, JSValueRef)
     160{
     161}
     162
     163void UIScriptController::simulateRotationLikeSafari(DeviceOrientation*, JSValueRef)
     164{
     165}
     166
    159167void UIScriptController::removeViewFromWindow(JSValueRef callback)
    160168{
Note: See TracChangeset for help on using the changeset viewer.