Title: [216291] trunk
Revision
216291
Author
[email protected]
Date
2017-05-05 16:39:19 -0700 (Fri, 05 May 2017)

Log 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.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (216290 => 216291)


--- trunk/LayoutTests/ChangeLog	2017-05-05 23:33:04 UTC (rev 216290)
+++ trunk/LayoutTests/ChangeLog	2017-05-05 23:39:19 UTC (rev 216291)
@@ -1,3 +1,19 @@
+2017-05-05  Simon Fraser  <[email protected]>
+
+        Make it possible to test rotation in iOS WebKitTestRunner
+        https://bugs.webkit.org/show_bug.cgi?id=171755
+
+        Reviewed by Tim Horton.
+
+        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.
+
 2017-05-05  Ryan Haddad  <[email protected]>
 
         Mark http/tests/loading/resourceLoadStatistics/prevalent-resource-without-user-interaction.html as flaky.

Added: trunk/LayoutTests/fast/events/ios/rotation/basic-rotation-expected.txt (0 => 216291)


--- trunk/LayoutTests/fast/events/ios/rotation/basic-rotation-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/events/ios/rotation/basic-rotation-expected.txt	2017-05-05 23:39:19 UTC (rev 216291)
@@ -0,0 +1,15 @@
+Before rotation
+PASS window.innerWidth is 320
+PASS window.innerHeight is 548
+In orientationchange event handler:
+FAIL window.innerWidth should be 568. Was 320.
+FAIL window.innerHeight should be 320. Was 548.
+
+In resize event handler:
+FAIL window.innerWidth should be 568. Was 320.
+PASS window.innerHeight is 320
+
+After rotation
+PASS window.innerWidth is 568
+PASS window.innerHeight is 320
+Rotation test.

Added: trunk/LayoutTests/fast/events/ios/rotation/basic-rotation.html (0 => 216291)


--- trunk/LayoutTests/fast/events/ios/rotation/basic-rotation.html	                        (rev 0)
+++ trunk/LayoutTests/fast/events/ios/rotation/basic-rotation.html	2017-05-05 23:39:19 UTC (rev 216291)
@@ -0,0 +1,58 @@
+<!DOCTYPE html> <!-- webkit-test-runner [ useFlexibleViewport=true ] -->
+
+<html>
+<head>
+    <meta name="viewport" content="initial-scale=1.0">
+    <script src=""
+    <script>
+        jsTestIsAsync = true;
+        function getRotationUIScript()
+        {
+            return `
+            (function() {
+                uiController.simulateRotation('landscape-right', function() {
+                    uiController.doAfterVisibleContentRectUpdate(function () {
+                        uiController.uiScriptComplete();
+                    })
+                });
+            })();`
+        }
+
+        function doTest()
+        {
+            debug('Before rotation');
+            shouldBe("window.innerWidth", "320");
+            shouldBe("window.innerHeight", "548");
+            if (!window.testRunner)
+                return;
+
+            testRunner.runUIScript(getRotationUIScript(), function(result) {
+                debug('After rotation');
+                shouldBe("window.innerWidth", "568");
+                shouldBe("window.innerHeight", "320");
+
+                if (window.testRunner)
+                    testRunner.notifyDone();
+            });
+        }
+        window.addEventListener('resize', function() {
+            debug('In resize event handler:');
+            shouldBe("window.innerWidth", "568");
+            shouldBe("window.innerHeight", "320");
+            debug('');
+        }, false);
+        window.addEventListener('orientationchange', function() {
+            debug('In orientationchange event handler:');
+            shouldBe("window.innerWidth", "568");
+            shouldBe("window.innerHeight", "320");
+            debug('');
+        }, false);
+
+        window.addEventListener('load', doTest, false);
+    </script>
+</head>
+<body>
+    Rotation test.
+<script src=""
+</body>
+</html>

Added: trunk/LayoutTests/fast/events/ios/rotation/safari-like-rotation-expected.txt (0 => 216291)


--- trunk/LayoutTests/fast/events/ios/rotation/safari-like-rotation-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/events/ios/rotation/safari-like-rotation-expected.txt	2017-05-05 23:39:19 UTC (rev 216291)
@@ -0,0 +1,15 @@
+Before rotation
+PASS window.innerWidth is 320
+PASS window.innerHeight is 548
+In resize event handler:
+PASS window.innerWidth is 568
+PASS window.innerHeight is 320
+
+In orientationchange event handler:
+PASS window.innerWidth is 568
+PASS window.innerHeight is 320
+
+After rotation
+PASS window.innerWidth is 568
+PASS window.innerHeight is 320
+Rotation test.

Added: trunk/LayoutTests/fast/events/ios/rotation/safari-like-rotation.html (0 => 216291)


--- trunk/LayoutTests/fast/events/ios/rotation/safari-like-rotation.html	                        (rev 0)
+++ trunk/LayoutTests/fast/events/ios/rotation/safari-like-rotation.html	2017-05-05 23:39:19 UTC (rev 216291)
@@ -0,0 +1,58 @@
+<!DOCTYPE html> <!-- webkit-test-runner [ useFlexibleViewport=true ] -->
+
+<html>
+<head>
+    <meta name="viewport" content="initial-scale=1.0">
+    <script src=""
+    <script>
+        jsTestIsAsync = true;
+        function getRotationUIScript()
+        {
+            return `
+            (function() {
+                uiController.simulateRotationLikeSafari('landscape-right', function() {
+                    uiController.doAfterVisibleContentRectUpdate(function () {
+                        uiController.uiScriptComplete();
+                    })
+                });
+            })();`
+        }
+
+        function doTest()
+        {
+            debug('Before rotation');
+            shouldBe("window.innerWidth", "320");
+            shouldBe("window.innerHeight", "548");
+            if (!window.testRunner)
+                return;
+
+            testRunner.runUIScript(getRotationUIScript(), function(result) {
+                debug('After rotation');
+                shouldBe("window.innerWidth", "568");
+                shouldBe("window.innerHeight", "320");
+
+                if (window.testRunner)
+                    testRunner.notifyDone();
+            });
+        }
+        window.addEventListener('resize', function() {
+            debug('In resize event handler:');
+            shouldBe("window.innerWidth", "568");
+            shouldBe("window.innerHeight", "320");
+            debug('');
+        }, false);
+        window.addEventListener('orientationchange', function() {
+            debug('In orientationchange event handler:');
+            shouldBe("window.innerWidth", "568");
+            shouldBe("window.innerHeight", "320");
+            debug('');
+        }, false);
+
+        window.addEventListener('load', doTest, false);
+    </script>
+</head>
+<body>
+    Rotation test.
+<script src=""
+</body>
+</html>

Added: trunk/LayoutTests/fast/events/ios/rotation/zz-no-rotation-expected.txt (0 => 216291)


--- trunk/LayoutTests/fast/events/ios/rotation/zz-no-rotation-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/events/ios/rotation/zz-no-rotation-expected.txt	2017-05-05 23:39:19 UTC (rev 216291)
@@ -0,0 +1,6 @@
+PASS successfullyParsed is true
+
+TEST COMPLETE
+PASS window.innerWidth is 320
+PASS window.innerHeight is 568
+This test checks that the view is not left in a rotated state after the previous tests.

Added: trunk/LayoutTests/fast/events/ios/rotation/zz-no-rotation.html (0 => 216291)


--- trunk/LayoutTests/fast/events/ios/rotation/zz-no-rotation.html	                        (rev 0)
+++ trunk/LayoutTests/fast/events/ios/rotation/zz-no-rotation.html	2017-05-05 23:39:19 UTC (rev 216291)
@@ -0,0 +1,20 @@
+<!DOCTYPE html> <!-- webkit-test-runner [ useFlexibleViewport=true ] -->
+
+<html>
+<head>
+    <meta name="viewport" content="initial-scale=1.0">
+    <script src=""
+    <script>
+        function doTest()
+        {
+            shouldBe("window.innerWidth", "320");
+            shouldBe("window.innerHeight", "568");
+        }
+        window.addEventListener('load', doTest, false);
+    </script>
+</head>
+<body>
+    This test checks that the view is not left in a rotated state after the previous tests.
+    <script src=""
+</body>
+</html>

Modified: trunk/Tools/ChangeLog (216290 => 216291)


--- trunk/Tools/ChangeLog	2017-05-05 23:33:04 UTC (rev 216290)
+++ trunk/Tools/ChangeLog	2017-05-05 23:39:19 UTC (rev 216291)
@@ -1,3 +1,52 @@
+2017-05-05  Simon Fraser  <[email protected]>
+
+        Make it possible to test rotation in iOS WebKitTestRunner
+        https://bugs.webkit.org/show_bug.cgi?id=171755
+
+        Reviewed by Tim Horton.
+
+        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):
+
 2017-05-05  Jonathan Bedard  <[email protected]>
 
         Use ImageDiff built by host SDK and remove ImageDiff from DumpRenderTree

Modified: trunk/Tools/DumpRenderTree/ios/UIScriptControllerIOS.mm (216290 => 216291)


--- trunk/Tools/DumpRenderTree/ios/UIScriptControllerIOS.mm	2017-05-05 23:33:04 UTC (rev 216290)
+++ trunk/Tools/DumpRenderTree/ios/UIScriptControllerIOS.mm	2017-05-05 23:39:19 UTC (rev 216291)
@@ -222,7 +222,6 @@
 {
 }
 
-
 JSObjectRef UIScriptController::contentVisibleRect() const
 {
     CGRect contentVisibleRect = [gWebBrowserView documentVisibleRect];
@@ -308,6 +307,14 @@
     return nullptr;
 }
 
+void UIScriptController::simulateRotation(DeviceOrientation*, JSValueRef)
+{
+}
+
+void UIScriptController::simulateRotationLikeSafari(DeviceOrientation*, JSValueRef)
+{
+}
+
 void UIScriptController::removeViewFromWindow(JSValueRef)
 {
 }

Modified: trunk/Tools/DumpRenderTree/mac/UIScriptControllerMac.mm (216290 => 216291)


--- trunk/Tools/DumpRenderTree/mac/UIScriptControllerMac.mm	2017-05-05 23:33:04 UTC (rev 216290)
+++ trunk/Tools/DumpRenderTree/mac/UIScriptControllerMac.mm	2017-05-05 23:39:19 UTC (rev 216291)
@@ -108,6 +108,14 @@
         preferences.minimumFontSize = [(NSString *)value.get() doubleValue];
 }
 
+void UIScriptController::simulateRotation(DeviceOrientation*, JSValueRef)
+{
+}
+
+void UIScriptController::simulateRotationLikeSafari(DeviceOrientation*, JSValueRef)
+{
+}
+
 void UIScriptController::removeViewFromWindow(JSValueRef callback)
 {
     unsigned callbackID = m_context->prepareForAsyncTask(callback, CallbackTypeNonPersistent);

Modified: trunk/Tools/TestRunnerShared/UIScriptContext/Bindings/UIScriptController.idl (216290 => 216291)


--- trunk/Tools/TestRunnerShared/UIScriptContext/Bindings/UIScriptController.idl	2017-05-05 23:33:04 UTC (rev 216290)
+++ trunk/Tools/TestRunnerShared/UIScriptContext/Bindings/UIScriptController.idl	2017-05-05 23:39:19 UTC (rev 216291)
@@ -22,6 +22,13 @@
  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  * THE POSSIBILITY OF SUCH DAMAGE.
  */
+ 
+enum DeviceOrientation {
+    "portrait",
+    "portrait-upsidedown",
+    "landscape-left",
+    "landscape-right"
+};
 
 interface UIScriptController {
 
@@ -226,6 +233,9 @@
 
     void retrieveSpeakSelectionContent(object callback);
     readonly attribute DOMString accessibilitySpeakSelectionContent;
+    
+    void simulateRotation(DeviceOrientation orientation, object callback);
+    void simulateRotationLikeSafari(DeviceOrientation orientation, object callback);
 
     // Unparent and parent the web view, simulating, for example, tab switching.
     void removeViewFromWindow(object callback);

Modified: trunk/Tools/TestRunnerShared/UIScriptContext/UIScriptController.cpp (216290 => 216291)


--- trunk/Tools/TestRunnerShared/UIScriptContext/UIScriptController.cpp	2017-05-05 23:33:04 UTC (rev 216290)
+++ trunk/Tools/TestRunnerShared/UIScriptContext/UIScriptController.cpp	2017-05-05 23:39:19 UTC (rev 216291)
@@ -29,9 +29,35 @@
 #include "JSUIScriptController.h"
 #include "UIScriptContext.h"
 #include <_javascript_Core/JSValueRef.h>
+#include <_javascript_Core/OpaqueJSString.h>
 
 namespace WTR {
 
+DeviceOrientation* toDeviceOrientation(JSContextRef context, JSValueRef value)
+{
+    static DeviceOrientation values[] = {
+        DeviceOrientation::Portrait,
+        DeviceOrientation::PortraitUpsideDown,
+        DeviceOrientation::LandscapeLeft,
+        DeviceOrientation::LandscapeRight
+    };
+
+    JSRetainPtr<JSStringRef> option(Adopt, JSValueToStringCopy(context, value, nullptr));
+    if (option.get()->string() == "portrait")
+        return &values[0];
+        
+    if (option.get()->string() == "portrait-upsidedown")
+        return &values[1];
+        
+    if (option.get()->string() == "landscape-left")
+        return &values[2];
+        
+    if (option.get()->string() == "landscape-right")
+        return &values[3];
+        
+    return nullptr;
+}
+
 UIScriptController::UIScriptController(UIScriptContext& context)
     : m_context(&context)
 {
@@ -407,6 +433,14 @@
 
 #if !PLATFORM(COCOA)
 
+void UIScriptController::simulateRotation(DeviceOrientation*, JSValueRef callback)
+{
+}
+
+void UIScriptController::simulateRotationLikeSafari(DeviceOrientation*, JSValueRef callback)
+{
+}
+
 void UIScriptController::removeViewFromWindow(JSValueRef)
 {
 }

Modified: trunk/Tools/TestRunnerShared/UIScriptContext/UIScriptController.h (216290 => 216291)


--- trunk/Tools/TestRunnerShared/UIScriptContext/UIScriptController.h	2017-05-05 23:33:04 UTC (rev 216290)
+++ trunk/Tools/TestRunnerShared/UIScriptContext/UIScriptController.h	2017-05-05 23:39:19 UTC (rev 216291)
@@ -39,6 +39,15 @@
 
 class UIScriptContext;
 
+enum class DeviceOrientation {
+    Portrait,
+    PortraitUpsideDown,
+    LandscapeLeft,
+    LandscapeRight
+};
+
+DeviceOrientation* toDeviceOrientation(JSContextRef, JSValueRef);
+
 class UIScriptController : public JSWrappable {
 public:
     static Ref<UIScriptController> create(UIScriptContext& context)
@@ -151,6 +160,9 @@
     
     void retrieveSpeakSelectionContent(JSValueRef);
     JSRetainPtr<JSStringRef> accessibilitySpeakSelectionContent() const;
+    
+    void simulateRotation(DeviceOrientation*, JSValueRef);
+    void simulateRotationLikeSafari(DeviceOrientation*, JSValueRef);
 
     // These use a callback to allow the client to know when view visibility state updates get to the web process.
     void removeViewFromWindow(JSValueRef);

Modified: trunk/Tools/WebKitTestRunner/cocoa/TestRunnerWKWebView.h (216290 => 216291)


--- trunk/Tools/WebKitTestRunner/cocoa/TestRunnerWKWebView.h	2017-05-05 23:33:04 UTC (rev 216290)
+++ trunk/Tools/WebKitTestRunner/cocoa/TestRunnerWKWebView.h	2017-05-05 23:39:19 UTC (rev 216291)
@@ -40,13 +40,17 @@
 @property (nonatomic, copy) void (^didShowKeyboardCallback)(void);
 @property (nonatomic, copy) void (^didHideKeyboardCallback)(void);
 @property (nonatomic, copy) void (^didEndScrollingCallback)(void);
+@property (nonatomic, copy) void (^rotationDidEndCallback)(void);
 @property (nonatomic, copy) NSString *accessibilitySpeakSelectionContent;
 
 - (void)zoomToScale:(double)scale animated:(BOOL)animated completionHandler:(void (^)(void))completionHandler;
 - (void)accessibilityRetrieveSpeakSelectionContentWithCompletionHandler:(void (^)(void))completionHandler;
+- (void)_didEndRotation;
 
 @property (nonatomic, assign) UIEdgeInsets overrideSafeAreaInsets;
 
+@property (nonatomic, assign) BOOL usesSafariLikeRotation;
+
 #endif
 
 @property (nonatomic, retain, setter=_setStableStateOverride:) NSNumber *_stableStateOverride;

Modified: trunk/Tools/WebKitTestRunner/cocoa/TestRunnerWKWebView.mm (216290 => 216291)


--- trunk/Tools/WebKitTestRunner/cocoa/TestRunnerWKWebView.mm	2017-05-05 23:33:04 UTC (rev 216290)
+++ trunk/Tools/WebKitTestRunner/cocoa/TestRunnerWKWebView.mm	2017-05-05 23:39:19 UTC (rev 216291)
@@ -91,6 +91,7 @@
     self.didShowKeyboardCallback = nil;
     self.didHideKeyboardCallback = nil;
     self.didEndScrollingCallback = nil;
+    self.rotationDidEndCallback = nil;
 
     self.zoomToScaleCompletionHandler = nil;
     self.showKeyboardCompletionHandler = nil;
@@ -191,6 +192,12 @@
     [self _scheduleVisibleContentRectUpdate];
 }
 
+- (void)_didEndRotation
+{
+    if (self.rotationDidEndCallback)
+        self.rotationDidEndCallback();
+}
+
 - (void)_accessibilityDidGetSpeakSelectionContent:(NSString *)content
 {
     self.accessibilitySpeakSelectionContent = content;

Modified: trunk/Tools/WebKitTestRunner/ios/PlatformWebViewIOS.mm (216290 => 216291)


--- trunk/Tools/WebKitTestRunner/ios/PlatformWebViewIOS.mm	2017-05-05 23:33:04 UTC (rev 216290)
+++ trunk/Tools/WebKitTestRunner/ios/PlatformWebViewIOS.mm	2017-05-05 23:39:19 UTC (rev 216291)
@@ -28,6 +28,7 @@
 
 #import "TestController.h"
 #import "TestRunnerWKWebView.h"
+#import "UIKitSPI.h"
 #import <WebCore/QuartzCoreSPI.h>
 #import <WebKit/WKImageCG.h>
 #import <WebKit/WKPreferencesPrivate.h>
@@ -107,6 +108,41 @@
 
 @end
 
+@interface PlatformWebViewController : UIViewController
+@end
+
+@implementation PlatformWebViewController
+
+- (void)viewWillTransitionToSize:(CGSize)toSize withTransitionCoordinator:(id <UIViewControllerTransitionCoordinator>)coordinator
+{
+    [super viewWillTransitionToSize:toSize withTransitionCoordinator:coordinator];
+    
+    TestRunnerWKWebView *webView = WTR::TestController::singleton().mainWebView()->platformView();
+    
+    if (webView.usesSafariLikeRotation)
+        [webView _setInterfaceOrientationOverride:[[UIApplication sharedApplication] statusBarOrientation]];
+        
+    [coordinator animateAlongsideTransition: ^(id<UIViewControllerTransitionCoordinatorContext> context) {
+        if (webView.usesSafariLikeRotation) {
+            [webView _beginAnimatedResizeWithUpdates:^{
+                auto size = self.view.bounds.size;
+                webView.frame = self.view.bounds;
+                [webView _overrideLayoutParametersWithMinimumLayoutSize:size maximumUnobscuredSizeOverride:size];
+                [webView _setInterfaceOrientationOverride:[[UIApplication sharedApplication] statusBarOrientation]];
+            }];
+        } else
+            webView.frame = self.view.bounds;
+    } completion:^(id<UIViewControllerTransitionCoordinatorContext> context) {
+        webView.frame = self.view.bounds;
+        if (webView.usesSafariLikeRotation)
+            [webView _endAnimatedResize];
+            
+        [webView _didEndRotation];
+    }];
+}
+
+@end
+
 namespace WTR {
 
 enum class WebViewSizingMode {
@@ -130,7 +166,7 @@
     m_window.backgroundColor = [UIColor lightGrayColor];
     m_window.platformWebView = this;
 
-    UIViewController *viewController = [[UIViewController alloc] init];
+    UIViewController *viewController = [[PlatformWebViewController alloc] init];
     [m_window setRootViewController:viewController];
     [viewController release];
 

Modified: trunk/Tools/WebKitTestRunner/ios/TestControllerIOS.mm (216290 => 216291)


--- trunk/Tools/WebKitTestRunner/ios/TestControllerIOS.mm	2017-05-05 23:33:04 UTC (rev 216290)
+++ trunk/Tools/WebKitTestRunner/ios/TestControllerIOS.mm	2017-05-05 23:39:19 UTC (rev 216291)
@@ -80,8 +80,11 @@
 {
     cocoaResetStateToConsistentValues();
 
+    [[UIDevice currentDevice] setOrientation:UIDeviceOrientationPortrait animated:NO];
+    
     if (PlatformWebView* webView = mainWebView()) {
         webView->platformView()._stableStateOverride = nil;
+        webView->platformView().usesSafariLikeRotation = NO;
         UIScrollView *scrollView = webView->platformView().scrollView;
         [scrollView _removeAllAnimations:YES];
         [scrollView setZoomScale:1 animated:NO];

Modified: trunk/Tools/WebKitTestRunner/ios/UIKitSPI.h (216290 => 216291)


--- trunk/Tools/WebKitTestRunner/ios/UIKitSPI.h	2017-05-05 23:33:04 UTC (rev 216290)
+++ trunk/Tools/WebKitTestRunner/ios/UIKitSPI.h	2017-05-05 23:39:19 UTC (rev 216291)
@@ -23,8 +23,7 @@
  * THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#ifndef UIKitSPI_h
-#define UIKitSPI_h
+#pragma once
 
 #import <wtf/Platform.h>
 
@@ -38,6 +37,7 @@
 #import <UIKit/UIKeyboard.h>
 #import <UIKit/UIView_Private.h>
 #import <UIKit/UIWindow_Private.h>
+#import <UIKit/UIDevice_Private.h>
 
 @interface UIKeyboardPredictionView : UIView
 + (UIKeyboardPredictionView *)activeInstance;
@@ -65,6 +65,10 @@
 - (void)_removeAllAnimations:(BOOL)includeSubviews;
 @end
 
+@interface UIDevice ()
+- (void)setOrientation:(UIDeviceOrientation)orientation animated:(BOOL)animated;
+ @end
+ 
 #endif // USE(APPLE_INTERNAL_SDK)
 
 #if __IPHONE_OS_VERSION_MIN_REQUIRED >= 110000
@@ -75,4 +79,3 @@
 
 #endif // PLATFORM(IOS)
 
-#endif // UIKitSPI_h

Modified: trunk/Tools/WebKitTestRunner/ios/UIScriptControllerIOS.mm (216290 => 216291)


--- trunk/Tools/WebKitTestRunner/ios/UIScriptControllerIOS.mm	2017-05-05 23:33:04 UTC (rev 216290)
+++ trunk/Tools/WebKitTestRunner/ios/UIScriptControllerIOS.mm	2017-05-05 23:39:19 UTC (rev 216291)
@@ -553,6 +553,57 @@
     return JSValueToObject(m_context->jsContext(), [JSValue valueWithObject:[TestController::singleton().mainWebView()->platformView() _propertiesOfLayerWithID:layerID] inContext:[JSContext contextWithJSGlobalContextRef:m_context->jsContext()]].JSValueRef, nullptr);
 }
 
+static UIDeviceOrientation toUIDeviceOrientation(DeviceOrientation* orientation)
+{
+    if (!orientation)
+        return UIDeviceOrientationPortrait;
+        
+    switch (*orientation) {
+    case DeviceOrientation::Portrait:
+        return UIDeviceOrientationPortrait;
+    case DeviceOrientation::PortraitUpsideDown:
+        return UIDeviceOrientationPortraitUpsideDown;
+    case DeviceOrientation::LandscapeLeft:
+        return UIDeviceOrientationLandscapeLeft;
+    case DeviceOrientation::LandscapeRight:
+        return UIDeviceOrientationLandscapeRight;
+    }
+    
+    return UIDeviceOrientationPortrait;
+}
+
+void UIScriptController::simulateRotation(DeviceOrientation* orientation, JSValueRef callback)
+{
+    TestRunnerWKWebView *webView = TestController::singleton().mainWebView()->platformView();
+    webView.usesSafariLikeRotation = NO;
+    
+    unsigned callbackID = m_context->prepareForAsyncTask(callback, CallbackTypeNonPersistent);
+    
+    webView.rotationDidEndCallback = ^{
+        if (!m_context)
+            return;
+        m_context->asyncTaskComplete(callbackID);
+    };
+    
+    [[UIDevice currentDevice] setOrientation:toUIDeviceOrientation(orientation) animated:YES];
+}
+
+void UIScriptController::simulateRotationLikeSafari(DeviceOrientation* orientation, JSValueRef callback)
+{
+    TestRunnerWKWebView *webView = TestController::singleton().mainWebView()->platformView();
+    webView.usesSafariLikeRotation = YES;
+    
+    unsigned callbackID = m_context->prepareForAsyncTask(callback, CallbackTypeNonPersistent);
+    
+    webView.rotationDidEndCallback = ^{
+        if (!m_context)
+            return;
+        m_context->asyncTaskComplete(callbackID);
+    };
+    
+    [[UIDevice currentDevice] setOrientation:toUIDeviceOrientation(orientation) animated:YES];
+}
+
 void UIScriptController::removeViewFromWindow(JSValueRef callback)
 {
     TestController::singleton().mainWebView()->removeFromWindow();
@@ -666,6 +717,7 @@
     webView.didHideKeyboardCallback = nil;
     webView.didShowKeyboardCallback = nil;
     webView.didEndScrollingCallback = nil;
+    webView.rotationDidEndCallback = nil;
 }
 
 void UIScriptController::setSafeAreaInsets(double top, double right, double bottom, double left)

Modified: trunk/Tools/WebKitTestRunner/mac/UIScriptControllerMac.mm (216290 => 216291)


--- trunk/Tools/WebKitTestRunner/mac/UIScriptControllerMac.mm	2017-05-05 23:33:04 UTC (rev 216290)
+++ trunk/Tools/WebKitTestRunner/mac/UIScriptControllerMac.mm	2017-05-05 23:39:19 UTC (rev 216291)
@@ -156,6 +156,14 @@
 #endif
 }
 
+void UIScriptController::simulateRotation(DeviceOrientation*, JSValueRef)
+{
+}
+
+void UIScriptController::simulateRotationLikeSafari(DeviceOrientation*, JSValueRef)
+{
+}
+
 void UIScriptController::removeViewFromWindow(JSValueRef callback)
 {
 #if WK_API_ENABLED
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to