Changeset 203905 in webkit
- Timestamp:
- Jul 29, 2016 10:49:03 AM (8 years ago)
- Location:
- trunk/Tools
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Tools/ChangeLog
r203902 r203905 1 2016-07-29 Wenson Hsieh <wenson_hsieh@apple.com> 2 3 Add TestWebKitAPI support for interacting with media controls 4 https://bugs.webkit.org/show_bug.cgi?id=160342 5 <rdar://problem/27610246> 6 7 Reviewed by Beth Dakin. 8 9 Adds support for testing interaction with some media controls, as well as a basic test 10 verifying that media control teardown after interaction does not result in a crash. 11 12 * TestWebKitAPI/Tests/WebKit2Cocoa/VideoControlsManager.mm: 13 (-[WKWebView mouseDownAtPoint:]): 14 (-[WKWebView performAfterLoading:]): 15 (TestWebKitAPI::TEST): 16 1 17 2016-07-29 Jonathan Bedard <jbedard@apple.com> 2 18 -
trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/VideoControlsManager.mm
r203698 r203905 41 41 static bool receivedScriptMessage; 42 42 43 @interface WKWebView (UserInteraction)44 45 - (void)mouseDownAtPoint:(NSPoint)point;46 47 @end48 49 @implementation WKWebView (UserInteraction)50 51 - (void)mouseDownAtPoint:(NSPoint)point {52 [self mouseDown:[NSEvent mouseEventWithType:NSEventTypeLeftMouseDown location:NSMakePoint(point.x, point.y) modifierFlags:0 timestamp:GetCurrentEventTime() windowNumber:0 context:[NSGraphicsContext currentContext] eventNumber:0 clickCount:0 pressure:0]];53 }54 55 @end56 57 43 @interface MediaPlaybackMessageHandler : NSObject <WKScriptMessageHandler> { 58 44 RetainPtr<WKWebView> _webView; … … 128 114 @end 129 115 116 @interface WKWebView (WKWebViewAdditions) 117 118 - (void)_interactWithMediaControlsForTesting; 119 120 @end 121 122 @interface WKWebView (TestingAdditions) 123 124 - (void)mouseDownAtPoint:(NSPoint)point; 125 - (void)performAfterLoading:(dispatch_block_t)actions; 126 127 @end 128 129 @implementation WKWebView (TestingAdditions) 130 131 - (void)mouseDownAtPoint:(NSPoint)point { 132 [self mouseDown:[NSEvent mouseEventWithType:NSEventTypeLeftMouseDown location:NSMakePoint(point.x, point.y) modifierFlags:0 timestamp:GetCurrentEventTime() windowNumber:0 context:[NSGraphicsContext currentContext] eventNumber:0 clickCount:0 pressure:0]]; 133 } 134 135 - (void)performAfterLoading:(dispatch_block_t)actions { 136 OnLoadMessageHandler *handler = [[OnLoadMessageHandler alloc] initWithWKWebView:self handler:actions]; 137 NSString *onloadScript = @"window.onload = function() { window.webkit.messageHandlers.onloadHandler.postMessage('loaded'); }"; 138 WKUserScript *script = [[WKUserScript alloc] initWithSource:onloadScript injectionTime:WKUserScriptInjectionTimeAtDocumentStart forMainFrameOnly:NO]; 139 [[[self configuration] userContentController] addUserScript:script]; 140 [[[self configuration] userContentController] addScriptMessageHandler:handler name:@"onloadHandler"]; 141 } 142 143 @end 144 130 145 namespace TestWebKitAPI { 131 146 … … 351 366 } 352 367 368 TEST(VideoControlsManager, VideoControlsManagerTearsDownMediaControlsOnDealloc) 369 { 370 RetainPtr<WKWebViewConfiguration> configuration = adoptNS([[WKWebViewConfiguration alloc] init]); 371 configuration.get().mediaTypesRequiringUserActionForPlayback = WKAudiovisualMediaTypeNone; 372 RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 100, 100) configuration:configuration.get()]); 373 374 RetainPtr<NSWindow> window = adoptNS([[NSWindow alloc] initWithContentRect:[webView frame] styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:NO]); 375 [[window contentView] addSubview:webView.get()]; 376 377 NSURL *urlOfVideo = [[NSBundle mainBundle] URLForResource:@"video-with-audio" withExtension:@"mp4" subdirectory:@"TestWebKitAPI.resources"]; 378 [webView loadFileURL:urlOfVideo allowingReadAccessToURL:[urlOfVideo URLByDeletingLastPathComponent]]; 379 380 __block bool finishedTest = false; 381 [webView performAfterLoading:^() 382 { 383 // Verify that we tear down the media controls properly, such that we don't crash when the web view is released. 384 if ([webView respondsToSelector:@selector(_interactWithMediaControlsForTesting)]) 385 [webView _interactWithMediaControlsForTesting]; 386 387 [webView release]; 388 finishedTest = true; 389 }]; 390 391 TestWebKitAPI::Util::run(&finishedTest); 392 } 393 353 394 TEST(VideoControlsManager, VideoControlsManagerSmallVideoInMediaDocument) 354 395 { … … 361 402 362 403 __block bool finishedLoad = false; 363 dispatch_block_t handleFinishedLoad =^()404 [webView performAfterLoading:^() 364 405 { 365 406 finishedLoad = true; 366 }; 367 OnLoadMessageHandler *handler = [[OnLoadMessageHandler alloc] initWithWKWebView:webView.get() handler:handleFinishedLoad]; 368 369 NSString *onloadScript = @"window.onload = function() { window.webkit.messageHandlers.onloadHandler.postMessage('loaded'); }"; 370 WKUserScript *script = [[WKUserScript alloc] initWithSource:onloadScript injectionTime:WKUserScriptInjectionTimeAtDocumentStart forMainFrameOnly:NO]; 371 [[configuration userContentController] addUserScript:script]; 372 [[configuration userContentController] addScriptMessageHandler:handler name:@"onloadHandler"]; 407 }]; 373 408 374 409 NSURL *urlOfVideo = [[NSBundle mainBundle] URLForResource:@"video-with-audio" withExtension:@"mp4" subdirectory:@"TestWebKitAPI.resources"];
Note: See TracChangeset
for help on using the changeset viewer.