Skip to content

Commit d0f3276

Browse files
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:]): git-svn-id: http://svn.webkit.org/repository/webkit/trunk@215207 268f45cc-cd09-0410-ab3c-d52691b4dbfc
1 parent f7256e6 commit d0f3276

File tree

4 files changed

+42
-11
lines changed

4 files changed

+42
-11
lines changed

Tools/ChangeLog

+18
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1+
2017-04-10 Wenson Hsieh <[email protected]>
2+
3+
Refactor DataInteractionTests.UnresponsivePageDoesNotHangUI to not check against a fixed time interval
4+
https://bugs.webkit.org/show_bug.cgi?id=170658
5+
6+
Reviewed by Tim Horton.
7+
8+
Uses ignoreSynchronousMessagingTimeoutsForTesting to ensure that this test times out if data interaction
9+
preparation is synchronous, or passes if it is asynchronous.
10+
11+
* TestWebKitAPI/Tests/ios/DataInteractionTests.mm:
12+
(TestWebKitAPI::TEST):
13+
* TestWebKitAPI/cocoa/TestWKWebView.h:
14+
* TestWebKitAPI/cocoa/TestWKWebView.mm:
15+
(-[TestWKWebView initWithFrame:]):
16+
(-[TestWKWebView initWithFrame:configuration:processPoolConfiguration:]):
17+
(-[TestWKWebView _setUpTestWindow:]):
18+
119
2017-04-10 Brent Fulgham <[email protected]>
220

321
[WK2][macOS] Block access to Apple Events before launch.

Tools/TestWebKitAPI/Tests/ios/DataInteractionTests.mm

+6-4
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#import <UIKit/UIItemProvider_Private.h>
3636
#import <WebKit/WKPreferencesPrivate.h>
3737
#import <WebKit/WKWebViewConfigurationPrivate.h>
38+
#import <WebKit/_WKProcessPoolConfiguration.h>
3839

3940
@implementation TestWKWebView (DataInteractionTests)
4041

@@ -387,14 +388,15 @@ static void checkTypeIdentifierPrecedesOtherTypeIdentifier(DataInteractionSimula
387388

388389
TEST(DataInteractionTests, UnresponsivePageDoesNotHangUI)
389390
{
390-
RetainPtr<TestWKWebView> webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]);
391+
_WKProcessPoolConfiguration *processPoolConfiguration = [[[_WKProcessPoolConfiguration alloc] init] autorelease];
392+
processPoolConfiguration.ignoreSynchronousMessagingTimeoutsForTesting = YES;
393+
394+
RetainPtr<TestWKWebView> webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500) configuration:[[[WKWebViewConfiguration alloc] init] autorelease] processPoolConfiguration:processPoolConfiguration]);
391395
[webView synchronouslyLoadTestPageNamed:@"simple"];
392396
[webView evaluateJavaScript:@"while(1);" completionHandler:nil];
393397

394-
NSTimeInterval startTime = [NSDate timeIntervalSinceReferenceDate];
398+
// The test passes if we can prepare for data interaction without timing out.
395399
[webView _simulatePrepareForDataInteractionSession:nil completion:^() { }];
396-
397-
EXPECT_LT([NSDate timeIntervalSinceReferenceDate] - startTime, 1);
398400
}
399401

400402
} // namespace TestWebKitAPI

Tools/TestWebKitAPI/cocoa/TestWKWebView.h

+3
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,14 @@
2828

2929
#if WK_API_ENABLED
3030

31+
@class _WKProcessPoolConfiguration;
32+
3133
@interface TestMessageHandler : NSObject <WKScriptMessageHandler>
3234
- (void)addMessage:(NSString *)message withHandler:(dispatch_block_t)handler;
3335
@end
3436

3537
@interface TestWKWebView : WKWebView
38+
- (instancetype)initWithFrame:(CGRect)frame configuration:(WKWebViewConfiguration *)configuration processPoolConfiguration:(_WKProcessPoolConfiguration *)processPoolConfiguration;
3639
- (void)clearMessageHandlers:(NSArray *)messageNames;
3740
- (void)performAfterReceivingMessage:(NSString *)message action:(dispatch_block_t)action;
3841
- (void)loadTestPageNamed:(NSString *)pageName;

Tools/TestWebKitAPI/cocoa/TestWKWebView.mm

+15-7
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@
3131
#import "TestNavigationDelegate.h"
3232
#import "Utilities.h"
3333

34+
#import <WebKit/WKWebViewConfigurationPrivate.h>
3435
#import <WebKit/WebKitPrivate.h>
36+
#import <WebKit/_WKProcessPoolConfiguration.h>
3537
#import <objc/runtime.h>
3638
#import <wtf/RetainPtr.h>
3739

@@ -159,13 +161,13 @@ - (void)resignKeyWindow
159161
@end
160162

161163
@implementation TestWKWebView {
162-
TestWKWebViewHostWindow *_hostWindow;
164+
RetainPtr<TestWKWebViewHostWindow> _hostWindow;
163165
RetainPtr<TestMessageHandler> _testHandler;
164166
}
165167

166168
- (instancetype)initWithFrame:(CGRect)frame
167169
{
168-
WKWebViewConfiguration *defaultConfiguration = [[WKWebViewConfiguration alloc] init];
170+
WKWebViewConfiguration *defaultConfiguration = [[[WKWebViewConfiguration alloc] init] autorelease];
169171
return [self initWithFrame:frame configuration:defaultConfiguration];
170172
}
171173

@@ -177,17 +179,23 @@ - (instancetype)initWithFrame:(CGRect)frame configuration:(WKWebViewConfiguratio
177179
return self;
178180
}
179181

182+
- (instancetype)initWithFrame:(CGRect)frame configuration:(WKWebViewConfiguration *)configuration processPoolConfiguration:(_WKProcessPoolConfiguration *)processPoolConfiguration
183+
{
184+
[configuration setProcessPool:[[[WKProcessPool alloc] _initWithConfiguration:processPoolConfiguration] autorelease]];
185+
return [self initWithFrame:frame configuration:configuration];
186+
}
187+
180188
- (void)_setUpTestWindow:(NSRect)frame
181189
{
182190
#if PLATFORM(MAC)
183-
_hostWindow = [[TestWKWebViewHostWindow alloc] initWithContentRect:frame styleMask:NSWindowStyleMaskBorderless backing:NSBackingStoreBuffered defer:NO];
191+
_hostWindow = adoptNS([[TestWKWebViewHostWindow alloc] initWithContentRect:frame styleMask:NSWindowStyleMaskBorderless backing:NSBackingStoreBuffered defer:NO]);
184192
[_hostWindow setFrameOrigin:NSMakePoint(0, 0)];
185193
[_hostWindow setIsVisible:YES];
186194
[[_hostWindow contentView] addSubview:self];
187195
[_hostWindow makeKeyAndOrderFront:self];
188196
#else
189-
_hostWindow = [[TestWKWebViewHostWindow alloc] initWithFrame:frame];
190-
_hostWindow.hidden = NO;
197+
_hostWindow = adoptNS([[TestWKWebViewHostWindow alloc] initWithFrame:frame]);
198+
[_hostWindow setHidden:NO];
191199
[_hostWindow addSubview:self];
192200
#endif
193201
}
@@ -306,8 +314,8 @@ - (void)typeCharacter:(char)character {
306314
NSString *characterAsString = [NSString stringWithFormat:@"%c" , character];
307315
NSEventType keyDownEventType = NSEventTypeKeyDown;
308316
NSEventType keyUpEventType = NSEventTypeKeyUp;
309-
[self keyDown:[NSEvent keyEventWithType:keyDownEventType location:NSZeroPoint modifierFlags:0 timestamp:GetCurrentEventTime() windowNumber:_hostWindow.windowNumber context:nil characters:characterAsString charactersIgnoringModifiers:characterAsString isARepeat:NO keyCode:character]];
310-
[self keyUp:[NSEvent keyEventWithType:keyUpEventType location:NSZeroPoint modifierFlags:0 timestamp:GetCurrentEventTime() windowNumber:_hostWindow.windowNumber context:nil characters:characterAsString charactersIgnoringModifiers:characterAsString isARepeat:NO keyCode:character]];
317+
[self keyDown:[NSEvent keyEventWithType:keyDownEventType location:NSZeroPoint modifierFlags:0 timestamp:GetCurrentEventTime() windowNumber:[_hostWindow windowNumber] context:nil characters:characterAsString charactersIgnoringModifiers:characterAsString isARepeat:NO keyCode:character]];
318+
[self keyUp:[NSEvent keyEventWithType:keyUpEventType location:NSZeroPoint modifierFlags:0 timestamp:GetCurrentEventTime() windowNumber:[_hostWindow windowNumber] context:nil characters:characterAsString charactersIgnoringModifiers:characterAsString isARepeat:NO keyCode:character]];
311319
}
312320
@end
313321
#endif

0 commit comments

Comments
 (0)