Refactor DataInteractionTests.UnresponsivePageDoesNotHangUI to not check against...
authorwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 10 Apr 2017 22:22:39 +0000 (22:22 +0000)
committerwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 10 Apr 2017 22:22:39 +0000 (22:22 +0000)
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:]):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@215207 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Tools/ChangeLog
Tools/TestWebKitAPI/Tests/ios/DataInteractionTests.mm
Tools/TestWebKitAPI/cocoa/TestWKWebView.h
Tools/TestWebKitAPI/cocoa/TestWKWebView.mm

index 699d8d1..6751c2b 100644 (file)
@@ -1,3 +1,21 @@
+2017-04-10  Wenson Hsieh  <wenson_hsieh@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  <bfulgham@apple.com>
 
         [WK2][macOS] Block access to Apple Events before launch.
index 1deec3a..ffc5ad5 100644 (file)
@@ -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, CustomActionSheetPopover)
 
 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
index 45da659..0c3a31e 100644 (file)
 
 #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;
index 1ec6497..9505b25 100644 (file)
@@ -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 @@ NSEventMask __simulated_forceClickAssociatedEventsMask(id self, SEL _cmd)
 @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 @@ NSEventMask __simulated_forceClickAssociatedEventsMask(id self, SEL _cmd)
     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 @@ NSEventMask __simulated_forceClickAssociatedEventsMask(id self, SEL _cmd)
     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