Skip to content

Commit 41ef9a4

Browse files
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. git-svn-id: http://svn.webkit.org/repository/webkit/trunk@216291 268f45cc-cd09-0410-ab3c-d52691b4dbfc
1 parent 1fc3d6c commit 41ef9a4

20 files changed

+426
-5
lines changed

LayoutTests/ChangeLog

+16
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
2017-05-05 Simon Fraser <[email protected]>
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+
117
2017-05-05 Ryan Haddad <[email protected]>
218

319
Mark http/tests/loading/resourceLoadStatistics/prevalent-resource-without-user-interaction.html as flaky.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
Before rotation
2+
PASS window.innerWidth is 320
3+
PASS window.innerHeight is 548
4+
In orientationchange event handler:
5+
FAIL window.innerWidth should be 568. Was 320.
6+
FAIL window.innerHeight should be 320. Was 548.
7+
8+
In resize event handler:
9+
FAIL window.innerWidth should be 568. Was 320.
10+
PASS window.innerHeight is 320
11+
12+
After rotation
13+
PASS window.innerWidth is 568
14+
PASS window.innerHeight is 320
15+
Rotation test.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<!DOCTYPE html> <!-- webkit-test-runner [ useFlexibleViewport=true ] -->
2+
3+
<html>
4+
<head>
5+
<meta name="viewport" content="initial-scale=1.0">
6+
<script src="../../../../resources/js-test-pre.js"></script>
7+
<script>
8+
jsTestIsAsync = true;
9+
function getRotationUIScript()
10+
{
11+
return `
12+
(function() {
13+
uiController.simulateRotation('landscape-right', function() {
14+
uiController.doAfterVisibleContentRectUpdate(function () {
15+
uiController.uiScriptComplete();
16+
})
17+
});
18+
})();`
19+
}
20+
21+
function doTest()
22+
{
23+
debug('Before rotation');
24+
shouldBe("window.innerWidth", "320");
25+
shouldBe("window.innerHeight", "548");
26+
if (!window.testRunner)
27+
return;
28+
29+
testRunner.runUIScript(getRotationUIScript(), function(result) {
30+
debug('After rotation');
31+
shouldBe("window.innerWidth", "568");
32+
shouldBe("window.innerHeight", "320");
33+
34+
if (window.testRunner)
35+
testRunner.notifyDone();
36+
});
37+
}
38+
window.addEventListener('resize', function() {
39+
debug('In resize event handler:');
40+
shouldBe("window.innerWidth", "568");
41+
shouldBe("window.innerHeight", "320");
42+
debug('');
43+
}, false);
44+
window.addEventListener('orientationchange', function() {
45+
debug('In orientationchange event handler:');
46+
shouldBe("window.innerWidth", "568");
47+
shouldBe("window.innerHeight", "320");
48+
debug('');
49+
}, false);
50+
51+
window.addEventListener('load', doTest, false);
52+
</script>
53+
</head>
54+
<body>
55+
Rotation test.
56+
<script src="../../../../resources/js-test-post.js"></script>
57+
</body>
58+
</html>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
Before rotation
2+
PASS window.innerWidth is 320
3+
PASS window.innerHeight is 548
4+
In resize event handler:
5+
PASS window.innerWidth is 568
6+
PASS window.innerHeight is 320
7+
8+
In orientationchange event handler:
9+
PASS window.innerWidth is 568
10+
PASS window.innerHeight is 320
11+
12+
After rotation
13+
PASS window.innerWidth is 568
14+
PASS window.innerHeight is 320
15+
Rotation test.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<!DOCTYPE html> <!-- webkit-test-runner [ useFlexibleViewport=true ] -->
2+
3+
<html>
4+
<head>
5+
<meta name="viewport" content="initial-scale=1.0">
6+
<script src="../../../../resources/js-test-pre.js"></script>
7+
<script>
8+
jsTestIsAsync = true;
9+
function getRotationUIScript()
10+
{
11+
return `
12+
(function() {
13+
uiController.simulateRotationLikeSafari('landscape-right', function() {
14+
uiController.doAfterVisibleContentRectUpdate(function () {
15+
uiController.uiScriptComplete();
16+
})
17+
});
18+
})();`
19+
}
20+
21+
function doTest()
22+
{
23+
debug('Before rotation');
24+
shouldBe("window.innerWidth", "320");
25+
shouldBe("window.innerHeight", "548");
26+
if (!window.testRunner)
27+
return;
28+
29+
testRunner.runUIScript(getRotationUIScript(), function(result) {
30+
debug('After rotation');
31+
shouldBe("window.innerWidth", "568");
32+
shouldBe("window.innerHeight", "320");
33+
34+
if (window.testRunner)
35+
testRunner.notifyDone();
36+
});
37+
}
38+
window.addEventListener('resize', function() {
39+
debug('In resize event handler:');
40+
shouldBe("window.innerWidth", "568");
41+
shouldBe("window.innerHeight", "320");
42+
debug('');
43+
}, false);
44+
window.addEventListener('orientationchange', function() {
45+
debug('In orientationchange event handler:');
46+
shouldBe("window.innerWidth", "568");
47+
shouldBe("window.innerHeight", "320");
48+
debug('');
49+
}, false);
50+
51+
window.addEventListener('load', doTest, false);
52+
</script>
53+
</head>
54+
<body>
55+
Rotation test.
56+
<script src="../../../../resources/js-test-post.js"></script>
57+
</body>
58+
</html>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
PASS successfullyParsed is true
2+
3+
TEST COMPLETE
4+
PASS window.innerWidth is 320
5+
PASS window.innerHeight is 568
6+
This test checks that the view is not left in a rotated state after the previous tests.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<!DOCTYPE html> <!-- webkit-test-runner [ useFlexibleViewport=true ] -->
2+
3+
<html>
4+
<head>
5+
<meta name="viewport" content="initial-scale=1.0">
6+
<script src="../../../../resources/js-test-pre.js"></script>
7+
<script>
8+
function doTest()
9+
{
10+
shouldBe("window.innerWidth", "320");
11+
shouldBe("window.innerHeight", "568");
12+
}
13+
window.addEventListener('load', doTest, false);
14+
</script>
15+
</head>
16+
<body>
17+
This test checks that the view is not left in a rotated state after the previous tests.
18+
<script src="../../../../resources/js-test-post.js"></script>
19+
</body>
20+
</html>

Tools/ChangeLog

+49
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,52 @@
1+
2017-05-05 Simon Fraser <[email protected]>
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+
150
2017-05-05 Jonathan Bedard <[email protected]>
251

352
Use ImageDiff built by host SDK and remove ImageDiff from DumpRenderTree

Tools/DumpRenderTree/ios/UIScriptControllerIOS.mm

+8-1
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,6 @@ static CGPoint contentOffsetBoundedInValidRange(UIScrollView *scrollView, CGPoin
222222
{
223223
}
224224

225-
226225
JSObjectRef UIScriptController::contentVisibleRect() const
227226
{
228227
CGRect contentVisibleRect = [gWebBrowserView documentVisibleRect];
@@ -308,6 +307,14 @@ static CGPoint contentOffsetBoundedInValidRange(UIScrollView *scrollView, CGPoin
308307
return nullptr;
309308
}
310309

310+
void UIScriptController::simulateRotation(DeviceOrientation*, JSValueRef)
311+
{
312+
}
313+
314+
void UIScriptController::simulateRotationLikeSafari(DeviceOrientation*, JSValueRef)
315+
{
316+
}
317+
311318
void UIScriptController::removeViewFromWindow(JSValueRef)
312319
{
313320
}

Tools/DumpRenderTree/mac/UIScriptControllerMac.mm

+8
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,14 @@
108108
preferences.minimumFontSize = [(NSString *)value.get() doubleValue];
109109
}
110110

111+
void UIScriptController::simulateRotation(DeviceOrientation*, JSValueRef)
112+
{
113+
}
114+
115+
void UIScriptController::simulateRotationLikeSafari(DeviceOrientation*, JSValueRef)
116+
{
117+
}
118+
111119
void UIScriptController::removeViewFromWindow(JSValueRef callback)
112120
{
113121
unsigned callbackID = m_context->prepareForAsyncTask(callback, CallbackTypeNonPersistent);

Tools/TestRunnerShared/UIScriptContext/Bindings/UIScriptController.idl

+10
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@
2222
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
2323
* THE POSSIBILITY OF SUCH DAMAGE.
2424
*/
25+
26+
enum DeviceOrientation {
27+
"portrait",
28+
"portrait-upsidedown",
29+
"landscape-left",
30+
"landscape-right"
31+
};
2532

2633
interface UIScriptController {
2734

@@ -226,6 +233,9 @@ interface UIScriptController {
226233

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.
231241
void removeViewFromWindow(object callback);

Tools/TestRunnerShared/UIScriptContext/UIScriptController.cpp

+34
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,35 @@
2929
#include "JSUIScriptController.h"
3030
#include "UIScriptContext.h"
3131
#include <JavaScriptCore/JSValueRef.h>
32+
#include <JavaScriptCore/OpaqueJSString.h>
3233

3334
namespace WTR {
3435

36+
DeviceOrientation* 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+
}
60+
3561
UIScriptController::UIScriptController(UIScriptContext& context)
3662
: m_context(&context)
3763
{
@@ -407,6 +433,14 @@ void UIScriptController::setSafeAreaInsets(double top, double right, double bott
407433

408434
#if !PLATFORM(COCOA)
409435

436+
void UIScriptController::simulateRotation(DeviceOrientation*, JSValueRef callback)
437+
{
438+
}
439+
440+
void UIScriptController::simulateRotationLikeSafari(DeviceOrientation*, JSValueRef callback)
441+
{
442+
}
443+
410444
void UIScriptController::removeViewFromWindow(JSValueRef)
411445
{
412446
}

Tools/TestRunnerShared/UIScriptContext/UIScriptController.h

+12
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,15 @@ namespace WTR {
3939

4040
class UIScriptContext;
4141

42+
enum class DeviceOrientation {
43+
Portrait,
44+
PortraitUpsideDown,
45+
LandscapeLeft,
46+
LandscapeRight
47+
};
48+
49+
DeviceOrientation* toDeviceOrientation(JSContextRef, JSValueRef);
50+
4251
class UIScriptController : public JSWrappable {
4352
public:
4453
static Ref<UIScriptController> create(UIScriptContext& context)
@@ -151,6 +160,9 @@ class UIScriptController : public JSWrappable {
151160

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.
156168
void removeViewFromWindow(JSValueRef);

0 commit comments

Comments
 (0)