Title: [203963] branches/safari-602-branch/Tools
Revision
203963
Author
bshaf...@apple.com
Date
2016-07-31 23:51:18 -0700 (Sun, 31 Jul 2016)

Log Message

Merge r203905. rdar://problem/27610246

Modified Paths

Diff

Modified: branches/safari-602-branch/Tools/ChangeLog (203962 => 203963)


--- branches/safari-602-branch/Tools/ChangeLog	2016-08-01 06:51:14 UTC (rev 203962)
+++ branches/safari-602-branch/Tools/ChangeLog	2016-08-01 06:51:18 UTC (rev 203963)
@@ -1,3 +1,23 @@
+2016-07-31  Babak Shafiei  <bshaf...@apple.com>
+
+        Merge r203905. rdar://problem/27610246
+
+    2016-07-29  Wenson Hsieh  <wenson_hs...@apple.com>
+
+            Add TestWebKitAPI support for interacting with media controls
+            https://bugs.webkit.org/show_bug.cgi?id=160342
+            <rdar://problem/27610246>
+
+            Reviewed by Beth Dakin.
+
+            Adds support for testing interaction with some media controls, as well as a basic test
+            verifying that media control teardown after interaction does not result in a crash.
+
+            * TestWebKitAPI/Tests/WebKit2Cocoa/VideoControlsManager.mm:
+            (-[WKWebView mouseDownAtPoint:]):
+            (-[WKWebView performAfterLoading:]):
+            (TestWebKitAPI::TEST):
+
 2016-07-28  Babak Shafiei  <bshaf...@apple.com>
 
         Merge r203755. rdar://problem/23325160

Modified: branches/safari-602-branch/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/VideoControlsManager.mm (203962 => 203963)


--- branches/safari-602-branch/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/VideoControlsManager.mm	2016-08-01 06:51:14 UTC (rev 203962)
+++ branches/safari-602-branch/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/VideoControlsManager.mm	2016-08-01 06:51:18 UTC (rev 203963)
@@ -40,20 +40,6 @@
 static bool testedControlsManagerAfterPlaying;
 static bool receivedScriptMessage;
 
-@interface WKWebView (UserInteraction)
-
-- (void)mouseDownAtPoint:(NSPoint)point;
-
-@end
-
-@implementation WKWebView (UserInteraction)
-
-- (void)mouseDownAtPoint:(NSPoint)point {
-    [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]];
-}
-
-@end
-
 @interface MediaPlaybackMessageHandler : NSObject <WKScriptMessageHandler> {
     RetainPtr<WKWebView> _webView;
 }
@@ -127,6 +113,35 @@
 }
 @end
 
+@interface WKWebView (WKWebViewAdditions)
+
+- (void)_interactWithMediaControlsForTesting;
+
+@end
+
+@interface WKWebView (TestingAdditions)
+
+- (void)mouseDownAtPoint:(NSPoint)point;
+- (void)performAfterLoading:(dispatch_block_t)actions;
+
+@end
+
+@implementation WKWebView (TestingAdditions)
+
+- (void)mouseDownAtPoint:(NSPoint)point {
+    [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]];
+}
+
+- (void)performAfterLoading:(dispatch_block_t)actions {
+    OnLoadMessageHandler *handler = [[OnLoadMessageHandler alloc] initWithWKWebView:self handler:actions];
+    NSString *_onloadScript_ = @"window._onload_ = function() { window.webkit.messageHandlers.onloadHandler.postMessage('loaded'); }";
+    WKUserScript *script = [[WKUserScript alloc] initWithSource:onloadScript injectionTime:WKUserScriptInjectionTimeAtDocumentStart forMainFrameOnly:NO];
+    [[[self configuration] userContentController] addUserScript:script];
+    [[[self configuration] userContentController] addScriptMessageHandler:handler name:@"onloadHandler"];
+}
+
+@end
+
 namespace TestWebKitAPI {
 
 TEST(VideoControlsManager, VideoControlsManagerSingleLargeVideo)
@@ -350,6 +365,32 @@
     TestWebKitAPI::Util::run(&receivedScriptMessage);
 }
 
+TEST(VideoControlsManager, VideoControlsManagerTearsDownMediaControlsOnDealloc)
+{
+    RetainPtr<WKWebViewConfiguration> configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+    configuration.get().mediaTypesRequiringUserActionForPlayback = WKAudiovisualMediaTypeNone;
+    RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 100, 100) configuration:configuration.get()]);
+
+    RetainPtr<NSWindow> window = adoptNS([[NSWindow alloc] initWithContentRect:[webView frame] styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:NO]);
+    [[window contentView] addSubview:webView.get()];
+
+    NSURL *urlOfVideo = [[NSBundle mainBundle] URLForResource:@"video-with-audio" withExtension:@"mp4" subdirectory:@"TestWebKitAPI.resources"];
+    [webView loadFileURL:urlOfVideo allowingReadAccessToURL:[urlOfVideo URLByDeletingLastPathComponent]];
+
+    __block bool finishedTest = false;
+    [webView performAfterLoading:^()
+    {
+        // Verify that we tear down the media controls properly, such that we don't crash when the web view is released.
+        if ([webView respondsToSelector:@selector(_interactWithMediaControlsForTesting)])
+            [webView _interactWithMediaControlsForTesting];
+
+        [webView release];
+        finishedTest = true;
+    }];
+
+    TestWebKitAPI::Util::run(&finishedTest);
+}
+
 TEST(VideoControlsManager, VideoControlsManagerSmallVideoInMediaDocument)
 {
     RetainPtr<WKWebViewConfiguration> configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
@@ -360,17 +401,11 @@
     [[window contentView] addSubview:webView.get()];
     
     __block bool finishedLoad = false;
-    dispatch_block_t handleFinishedLoad = ^()
+    [webView performAfterLoading:^()
     {
         finishedLoad = true;
-    };
-    OnLoadMessageHandler *handler = [[OnLoadMessageHandler alloc] initWithWKWebView:webView.get() handler:handleFinishedLoad];
+    }];
     
-    NSString *_onloadScript_ = @"window._onload_ = function() { window.webkit.messageHandlers.onloadHandler.postMessage('loaded'); }";
-    WKUserScript *script = [[WKUserScript alloc] initWithSource:onloadScript injectionTime:WKUserScriptInjectionTimeAtDocumentStart forMainFrameOnly:NO];
-    [[configuration userContentController] addUserScript:script];
-    [[configuration userContentController] addScriptMessageHandler:handler name:@"onloadHandler"];
-    
     NSURL *urlOfVideo = [[NSBundle mainBundle] URLForResource:@"video-with-audio" withExtension:@"mp4" subdirectory:@"TestWebKitAPI.resources"];
     [webView loadFileURL:urlOfVideo allowingReadAccessToURL:[urlOfVideo URLByDeletingLastPathComponent]];
     
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to