Changeset 203464 in webkit


Ignore:
Timestamp:
Jul 20, 2016 12:25:16 PM (8 years ago)
Author:
Wenson Hsieh
Message:

Media controls don't appear when pausing a small autoplaying video
https://bugs.webkit.org/show_bug.cgi?id=159972
<rdar://problem/27180657>

Reviewed by Beth Dakin.

Source/WebCore:

When pausing an autoplaying video, remove behavior restrictions for the
initial user gesture and show media controls.

New WebKit API test. See VideoControlsManagerSingleSmallAutoplayingVideo.

  • html/HTMLMediaElement.cpp:

(WebCore::HTMLMediaElement::pause):

Tools:

Adds a new test that verifies media controls show up when pausing a small autoplayed video. Also adds mechanisms
for simulating basic user interaction in VideoControlsManager.

  • TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
  • TestWebKitAPI/Tests/WebKit2Cocoa/VideoControlsManager.mm:

(-[WKWebView mouseDownAtPoint:]):
(-[DidPlayMessageHandler userContentController:didReceiveScriptMessage:]):
(-[OnLoadMessageHandler initWithWKWebView:handler:]):
(-[OnLoadMessageHandler userContentController:didReceiveScriptMessage:]):
(TestWebKitAPI::TEST):

  • TestWebKitAPI/Tests/WebKit2Cocoa/autoplaying-video-with-audio.html: Added.
Location:
trunk
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r203463 r203464  
     12016-07-20  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        Media controls don't appear when pausing a small autoplaying video
     4        https://bugs.webkit.org/show_bug.cgi?id=159972
     5        <rdar://problem/27180657>
     6
     7        Reviewed by Beth Dakin.
     8
     9        When pausing an autoplaying video, remove behavior restrictions for the
     10        initial user gesture and show media controls.
     11
     12        New WebKit API test. See VideoControlsManagerSingleSmallAutoplayingVideo.
     13
     14        * html/HTMLMediaElement.cpp:
     15        (WebCore::HTMLMediaElement::pause):
     16
    1172016-07-20  Chris Dumez  <cdumez@apple.com>
    218
  • trunk/Source/WebCore/html/HTMLMediaElement.cpp

    r203388 r203464  
    31563156        return;
    31573157
     3158    if (ScriptController::processingUserGestureForMedia())
     3159        removeBehaviorsRestrictionsAfterFirstUserGesture();
     3160
    31583161    pauseInternal();
    31593162}
  • trunk/Tools/ChangeLog

    r203457 r203464  
     12016-07-20  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        Media controls don't appear when pausing a small autoplaying video
     4        https://bugs.webkit.org/show_bug.cgi?id=159972
     5        <rdar://problem/27180657>
     6
     7        Reviewed by Beth Dakin.
     8
     9        Adds a new test that verifies media controls show up when pausing a small autoplayed video. Also adds mechanisms
     10        for simulating basic user interaction in VideoControlsManager.
     11
     12        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
     13        * TestWebKitAPI/Tests/WebKit2Cocoa/VideoControlsManager.mm:
     14        (-[WKWebView mouseDownAtPoint:]):
     15        (-[DidPlayMessageHandler userContentController:didReceiveScriptMessage:]):
     16        (-[OnLoadMessageHandler initWithWKWebView:handler:]):
     17        (-[OnLoadMessageHandler userContentController:didReceiveScriptMessage:]):
     18        (TestWebKitAPI::TEST):
     19        * TestWebKitAPI/Tests/WebKit2Cocoa/autoplaying-video-with-audio.html: Added.
     20
    1212016-07-20  Per Arne Vollan  <pvollan@apple.com>
    222
  • trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj

    r203426 r203464  
    5252                2DC4CF771D2D9DD800ECCC94 /* DataDetection.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2DC4CF761D2D9DD800ECCC94 /* DataDetection.mm */; };
    5353                2DD7D3AF178227B30026E1E3 /* lots-of-text-vertical-lr.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 2DD7D3AE178227AC0026E1E3 /* lots-of-text-vertical-lr.html */; };
     54                2E14A5291D3FE96B0010F35B /* autoplaying-video-with-audio.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 2E14A5281D3FE8B80010F35B /* autoplaying-video-with-audio.html */; };
    5455                2E7765CD16C4D80A00BA2BB1 /* mainIOS.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2E7765CC16C4D80A00BA2BB1 /* mainIOS.mm */; };
    5556                2E7765CF16C4D81100BA2BB1 /* mainMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2E7765CE16C4D81100BA2BB1 /* mainMac.mm */; };
     
    495496                                5C9E59421D3EB5AC00E3C62E /* ApplicationCache.db-shm in Copy Resources */,
    496497                                5C9E59431D3EB5AC00E3C62E /* ApplicationCache.db-wal in Copy Resources */,
     498                                2E14A5291D3FE96B0010F35B /* autoplaying-video-with-audio.html in Copy Resources */,
    497499                                7CCB99231D3B4A46003922F6 /* open-multiple-external-url.html in Copy Resources */,
    498500                                932AE53D1D371047005DFFAF /* focus-inputs.html in Copy Resources */,
     
    688690                2DD7D3A9178205D00026E1E3 /* ResizeReversePaginatedWebView.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ResizeReversePaginatedWebView.cpp; sourceTree = "<group>"; };
    689691                2DD7D3AE178227AC0026E1E3 /* lots-of-text-vertical-lr.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = "lots-of-text-vertical-lr.html"; sourceTree = "<group>"; };
     692                2E14A5281D3FE8B80010F35B /* autoplaying-video-with-audio.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "autoplaying-video-with-audio.html"; sourceTree = "<group>"; };
    690693                2E7765CC16C4D80A00BA2BB1 /* mainIOS.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = mainIOS.mm; sourceTree = "<group>"; };
    691694                2E7765CE16C4D81100BA2BB1 /* mainMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = mainMac.mm; sourceTree = "<group>"; };
     
    13191322                                5C9E593F1D3EB1DE00E3C62E /* ApplicationCache.db-shm */,
    13201323                                5C9E59401D3EB1DE00E3C62E /* ApplicationCache.db-wal */,
     1324                                2E14A5281D3FE8B80010F35B /* autoplaying-video-with-audio.html */,
    13211325                                93CFA8661CEB9DE1000565A8 /* autofocused-text-input.html */,
    13221326                                A16F66B91C40EA2000BD4D24 /* ContentFiltering.html */,
  • trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/VideoControlsManager.mm

    r201165 r203464  
    2727
    2828#import "PlatformUtilities.h"
     29#import <Carbon/Carbon.h>
    2930#import <WebKit/WKWebViewConfigurationPrivate.h>
    3031#import <WebKit/WKWebViewPrivate.h>
     
    3637static bool receivedScriptMessage;
    3738
     39@interface WKWebView (UserInteraction)
     40
     41- (void)mouseDownAtPoint:(NSPoint)point;
     42
     43@end
     44
     45@implementation WKWebView (UserInteraction)
     46
     47- (void)mouseDownAtPoint:(NSPoint)point {
     48    [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]];
     49}
     50
     51@end
     52
    3853@interface DidPlayMessageHandler : NSObject <WKScriptMessageHandler> {
    3954    RetainPtr<WKWebView> _webView;
     
    6277
    6378    NSString *bodyString = (NSString *)[message body];
    64     if ([bodyString isEqualToString:@"playing"]) {
     79    if ([bodyString isEqualToString:@"playing"] || [bodyString isEqualToString:@"paused"]) {
    6580        BOOL hasControlsManager = [_webView _hasActiveVideoForControlsManager];
    6681        if (self.expectedToHaveControlsManager)
     
    7388@end
    7489
     90@interface OnLoadMessageHandler : NSObject <WKScriptMessageHandler> {
     91    RetainPtr<WKWebView> _webView;
     92}
     93
     94@property (nonatomic, strong) dispatch_block_t onloadHandler;
     95
     96- (instancetype)initWithWKWebView:(WKWebView*)webView handler:(dispatch_block_t)handler;
     97@end
     98
     99@implementation OnLoadMessageHandler
     100
     101- (instancetype)initWithWKWebView:(WKWebView*)webView handler:(dispatch_block_t)handler
     102{
     103    if (!(self = [super init]))
     104        return nil;
     105
     106    _webView = webView;
     107    _onloadHandler = handler;
     108
     109    return self;
     110}
     111
     112- (void)userContentController:(WKUserContentController *)userContentController didReceiveScriptMessage:(WKScriptMessage *)message
     113{
     114    if (![(NSString *)[message body] isEqualToString:@"loaded"])
     115        return;
     116
     117    if (_onloadHandler)
     118        _onloadHandler();
     119
     120    _onloadHandler = nil;
     121}
     122@end
     123
    75124namespace TestWebKitAPI {
    76125
     
    117166}
    118167
     168TEST(VideoControlsManager, VideoControlsManagerSingleSmallAutoplayingVideo)
     169{
     170    RetainPtr<WKWebViewConfiguration> configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
     171    configuration.get().mediaTypesRequiringUserActionForPlayback = WKAudiovisualMediaTypeNone;
     172    RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 100, 100) configuration:configuration.get()]);
     173    RetainPtr<DidPlayMessageHandler> playbackHandler = adoptNS([[DidPlayMessageHandler alloc] initWithWKWebView:webView.get()]);
     174    [[configuration userContentController] addScriptMessageHandler:playbackHandler.get() name:@"playingHandler"];
     175
     176    RetainPtr<NSWindow> window = adoptNS([[NSWindow alloc] initWithContentRect:[webView frame] styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:NO]);
     177    [[window contentView] addSubview:webView.get()];
     178
     179    RetainPtr<OnLoadMessageHandler> onloadHandler = adoptNS([[OnLoadMessageHandler alloc] initWithWKWebView:webView.get() handler:^() {
     180        [webView mouseDownAtPoint:NSMakePoint(50, 50)];
     181    }]);
     182    [[configuration userContentController] addScriptMessageHandler:onloadHandler.get() name:@"onloadHandler"];
     183
     184    // A small video should have a controls manager after the first user gesture, which includes pausing the video. The expectation is YES.
     185    [playbackHandler setExpectedToHaveControlsManager:YES];
     186    NSURLRequest *request = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"autoplaying-video-with-audio" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]];
     187    [webView loadRequest:request];
     188
     189    TestWebKitAPI::Util::run(&testedControlsManagerAfterPlaying);
     190    TestWebKitAPI::Util::run(&receivedScriptMessage);
     191}
     192
    119193TEST(VideoControlsManager, VideoControlsManagerSingleLargeVideoWithoutAudio)
    120194{
Note: See TracChangeset for help on using the changeset viewer.