Title: [215207] trunk/Tools
Revision
215207
Author
wenson_hs...@apple.com
Date
2017-04-10 15:22:39 -0700 (Mon, 10 Apr 2017)

Log Message

Refactor DataInteractionTests.UnresponsivePageDoesNotHangUI to not check against a fixed time interval
https://bugs.webkit.org/show_bug.cgi?id=170658

Reviewed by Tim Horton.

Uses ignoreSynchronousMessagingTimeoutsForTesting to ensure that this test times out if data interaction
preparation is synchronous, or passes if it is asynchronous.

* TestWebKitAPI/Tests/ios/DataInteractionTests.mm:
(TestWebKitAPI::TEST):
* TestWebKitAPI/cocoa/TestWKWebView.h:
* TestWebKitAPI/cocoa/TestWKWebView.mm:
(-[TestWKWebView initWithFrame:]):
(-[TestWKWebView initWithFrame:configuration:processPoolConfiguration:]):
(-[TestWKWebView _setUpTestWindow:]):

Modified Paths

Diff

Modified: trunk/Tools/ChangeLog (215206 => 215207)


--- trunk/Tools/ChangeLog	2017-04-10 21:46:04 UTC (rev 215206)
+++ trunk/Tools/ChangeLog	2017-04-10 22:22:39 UTC (rev 215207)
@@ -1,3 +1,21 @@
+2017-04-10  Wenson Hsieh  <wenson_hs...@apple.com>
+
+        Refactor DataInteractionTests.UnresponsivePageDoesNotHangUI to not check against a fixed time interval
+        https://bugs.webkit.org/show_bug.cgi?id=170658
+
+        Reviewed by Tim Horton.
+
+        Uses ignoreSynchronousMessagingTimeoutsForTesting to ensure that this test times out if data interaction
+        preparation is synchronous, or passes if it is asynchronous.
+
+        * TestWebKitAPI/Tests/ios/DataInteractionTests.mm:
+        (TestWebKitAPI::TEST):
+        * TestWebKitAPI/cocoa/TestWKWebView.h:
+        * TestWebKitAPI/cocoa/TestWKWebView.mm:
+        (-[TestWKWebView initWithFrame:]):
+        (-[TestWKWebView initWithFrame:configuration:processPoolConfiguration:]):
+        (-[TestWKWebView _setUpTestWindow:]):
+
 2017-04-10  Brent Fulgham  <bfulg...@apple.com>
 
         [WK2][macOS] Block access to Apple Events before launch.

Modified: trunk/Tools/TestWebKitAPI/Tests/ios/DataInteractionTests.mm (215206 => 215207)


--- trunk/Tools/TestWebKitAPI/Tests/ios/DataInteractionTests.mm	2017-04-10 21:46:04 UTC (rev 215206)
+++ trunk/Tools/TestWebKitAPI/Tests/ios/DataInteractionTests.mm	2017-04-10 22:22:39 UTC (rev 215207)
@@ -35,6 +35,7 @@
 #import <UIKit/UIItemProvider_Private.h>
 #import <WebKit/WKPreferencesPrivate.h>
 #import <WebKit/WKWebViewConfigurationPrivate.h>
+#import <WebKit/_WKProcessPoolConfiguration.h>
 
 @implementation TestWKWebView (DataInteractionTests)
 
@@ -387,14 +388,15 @@
 
 TEST(DataInteractionTests, UnresponsivePageDoesNotHangUI)
 {
-    RetainPtr<TestWKWebView> webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]);
+    _WKProcessPoolConfiguration *processPoolConfiguration = [[[_WKProcessPoolConfiguration alloc] init] autorelease];
+    processPoolConfiguration.ignoreSynchronousMessagingTimeoutsForTesting = YES;
+
+    RetainPtr<TestWKWebView> webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500) configuration:[[[WKWebViewConfiguration alloc] init] autorelease] processPoolConfiguration:processPoolConfiguration]);
     [webView synchronouslyLoadTestPageNamed:@"simple"];
     [webView evaluateJavaScript:@"while(1);" completionHandler:nil];
 
-    NSTimeInterval startTime = [NSDate timeIntervalSinceReferenceDate];
+    // The test passes if we can prepare for data interaction without timing out.
     [webView _simulatePrepareForDataInteractionSession:nil completion:^() { }];
-
-    EXPECT_LT([NSDate timeIntervalSinceReferenceDate] - startTime, 1);
 }
 
 } // namespace TestWebKitAPI

Modified: trunk/Tools/TestWebKitAPI/cocoa/TestWKWebView.h (215206 => 215207)


--- trunk/Tools/TestWebKitAPI/cocoa/TestWKWebView.h	2017-04-10 21:46:04 UTC (rev 215206)
+++ trunk/Tools/TestWebKitAPI/cocoa/TestWKWebView.h	2017-04-10 22:22:39 UTC (rev 215207)
@@ -28,11 +28,14 @@
 
 #if WK_API_ENABLED
 
+@class _WKProcessPoolConfiguration;
+
 @interface TestMessageHandler : NSObject <WKScriptMessageHandler>
 - (void)addMessage:(NSString *)message withHandler:(dispatch_block_t)handler;
 @end
 
 @interface TestWKWebView : WKWebView
+- (instancetype)initWithFrame:(CGRect)frame configuration:(WKWebViewConfiguration *)configuration processPoolConfiguration:(_WKProcessPoolConfiguration *)processPoolConfiguration;
 - (void)clearMessageHandlers:(NSArray *)messageNames;
 - (void)performAfterReceivingMessage:(NSString *)message action:(dispatch_block_t)action;
 - (void)loadTestPageNamed:(NSString *)pageName;

Modified: trunk/Tools/TestWebKitAPI/cocoa/TestWKWebView.mm (215206 => 215207)


--- trunk/Tools/TestWebKitAPI/cocoa/TestWKWebView.mm	2017-04-10 21:46:04 UTC (rev 215206)
+++ trunk/Tools/TestWebKitAPI/cocoa/TestWKWebView.mm	2017-04-10 22:22:39 UTC (rev 215207)
@@ -31,7 +31,9 @@
 #import "TestNavigationDelegate.h"
 #import "Utilities.h"
 
+#import <WebKit/WKWebViewConfigurationPrivate.h>
 #import <WebKit/WebKitPrivate.h>
+#import <WebKit/_WKProcessPoolConfiguration.h>
 #import <objc/runtime.h>
 #import <wtf/RetainPtr.h>
 
@@ -159,13 +161,13 @@
 @end
 
 @implementation TestWKWebView {
-    TestWKWebViewHostWindow *_hostWindow;
+    RetainPtr<TestWKWebViewHostWindow> _hostWindow;
     RetainPtr<TestMessageHandler> _testHandler;
 }
 
 - (instancetype)initWithFrame:(CGRect)frame
 {
-    WKWebViewConfiguration *defaultConfiguration = [[WKWebViewConfiguration alloc] init];
+    WKWebViewConfiguration *defaultConfiguration = [[[WKWebViewConfiguration alloc] init] autorelease];
     return [self initWithFrame:frame configuration:defaultConfiguration];
 }
 
@@ -177,17 +179,23 @@
     return self;
 }
 
+- (instancetype)initWithFrame:(CGRect)frame configuration:(WKWebViewConfiguration *)configuration processPoolConfiguration:(_WKProcessPoolConfiguration *)processPoolConfiguration
+{
+    [configuration setProcessPool:[[[WKProcessPool alloc] _initWithConfiguration:processPoolConfiguration] autorelease]];
+    return [self initWithFrame:frame configuration:configuration];
+}
+
 - (void)_setUpTestWindow:(NSRect)frame
 {
 #if PLATFORM(MAC)
-    _hostWindow = [[TestWKWebViewHostWindow alloc] initWithContentRect:frame styleMask:NSWindowStyleMaskBorderless backing:NSBackingStoreBuffered defer:NO];
+    _hostWindow = adoptNS([[TestWKWebViewHostWindow alloc] initWithContentRect:frame styleMask:NSWindowStyleMaskBorderless backing:NSBackingStoreBuffered defer:NO]);
     [_hostWindow setFrameOrigin:NSMakePoint(0, 0)];
     [_hostWindow setIsVisible:YES];
     [[_hostWindow contentView] addSubview:self];
     [_hostWindow makeKeyAndOrderFront:self];
 #else
-    _hostWindow = [[TestWKWebViewHostWindow alloc] initWithFrame:frame];
-    _hostWindow.hidden = NO;
+    _hostWindow = adoptNS([[TestWKWebViewHostWindow alloc] initWithFrame:frame]);
+    [_hostWindow setHidden:NO];
     [_hostWindow addSubview:self];
 #endif
 }
@@ -306,8 +314,8 @@
     NSString *characterAsString = [NSString stringWithFormat:@"%c" , character];
     NSEventType keyDownEventType = NSEventTypeKeyDown;
     NSEventType keyUpEventType = NSEventTypeKeyUp;
-    [self keyDown:[NSEvent keyEventWithType:keyDownEventType location:NSZeroPoint modifierFlags:0 timestamp:GetCurrentEventTime() windowNumber:_hostWindow.windowNumber context:nil characters:characterAsString charactersIgnoringModifiers:characterAsString isARepeat:NO keyCode:character]];
-    [self keyUp:[NSEvent keyEventWithType:keyUpEventType location:NSZeroPoint modifierFlags:0 timestamp:GetCurrentEventTime() windowNumber:_hostWindow.windowNumber context:nil characters:characterAsString charactersIgnoringModifiers:characterAsString isARepeat:NO keyCode:character]];
+    [self keyDown:[NSEvent keyEventWithType:keyDownEventType location:NSZeroPoint modifierFlags:0 timestamp:GetCurrentEventTime() windowNumber:[_hostWindow windowNumber] context:nil characters:characterAsString charactersIgnoringModifiers:characterAsString isARepeat:NO keyCode:character]];
+    [self keyUp:[NSEvent keyEventWithType:keyUpEventType location:NSZeroPoint modifierFlags:0 timestamp:GetCurrentEventTime() windowNumber:[_hostWindow windowNumber] context:nil characters:characterAsString charactersIgnoringModifiers:characterAsString isARepeat:NO keyCode:character]];
 }
 @end
 #endif
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to