Changeset 203698 in webkit


Ignore:
Timestamp:
Jul 25, 2016 1:51:43 PM (8 years ago)
Author:
Wenson Hsieh
Message:

Media controls should not be displayed for a video until it starts playing
https://bugs.webkit.org/show_bug.cgi?id=160092
<rdar://problem/26986673>

Reviewed by Beth Dakin.

Source/WebCore:

For videos that have never played back yet, we should not show media controls. To ensure this
behavior, we ensure that the playback behavior restriction is set upon creating the media
element. This restriction is then removed when the media element begins to play.

Added two new WebKit API tests.

  • html/HTMLMediaElement.cpp:

(WebCore::HTMLMediaElement::HTMLMediaElement):

Tools:

Verify that multiple videos do or don't show the media controller depending on whether videos
are playing. Also tweaks an existing API test (VideoControlsManagerSingleLargeVideo) that was
passing because we were always showing media controls for large videos with audio, even if they
had not played back yet. This change ensures that large videos with audio show media controls
only after they begin to play back, and not by virtue of being large enough for main content.

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

(TestWebKitAPI::TEST):

  • TestWebKitAPI/Tests/WebKit2Cocoa/large-video-with-audio.html:
  • TestWebKitAPI/Tests/WebKit2Cocoa/large-videos-with-audio-autoplay.html: Added.
  • TestWebKitAPI/Tests/WebKit2Cocoa/large-videos-with-audio.html: Added.
Location:
trunk
Files:
2 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r203696 r203698  
     12016-07-25  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        Media controls should not be displayed for a video until it starts playing
     4        https://bugs.webkit.org/show_bug.cgi?id=160092
     5        <rdar://problem/26986673>
     6
     7        Reviewed by Beth Dakin.
     8
     9        For videos that have never played back yet, we should not show media controls. To ensure this
     10        behavior, we ensure that the playback behavior restriction is set upon creating the media
     11        element. This restriction is then removed when the media element begins to play.
     12
     13        Added two new WebKit API tests.
     14
     15        * html/HTMLMediaElement.cpp:
     16        (WebCore::HTMLMediaElement::HTMLMediaElement):
     17
    1182016-07-25  Jiewen Tan  <jiewen_tan@apple.com>
    219
  • trunk/Source/WebCore/html/HTMLMediaElement.cpp

    r203690 r203698  
    444444#endif
    445445    m_mediaSession->addBehaviorRestriction(MediaElementSession::RequireUserGestureToControlControlsManager);
     446    m_mediaSession->addBehaviorRestriction(MediaElementSession::RequirePlaybackToControlControlsManager);
    446447
    447448    Settings* settings = document.settings();
  • trunk/Tools/ChangeLog

    r203690 r203698  
     12016-07-25  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        Media controls should not be displayed for a video until it starts playing
     4        https://bugs.webkit.org/show_bug.cgi?id=160092
     5        <rdar://problem/26986673>
     6
     7        Reviewed by Beth Dakin.
     8
     9        Verify that multiple videos do or don't show the media controller depending on whether videos
     10        are playing. Also tweaks an existing API test (VideoControlsManagerSingleLargeVideo) that was
     11        passing because we were always showing media controls for large videos with audio, even if they
     12        had not played back yet. This change ensures that large videos with audio show media controls
     13        only after they begin to play back, and not by virtue of being large enough for main content.
     14
     15        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
     16        * TestWebKitAPI/Tests/WebKit2Cocoa/VideoControlsManager.mm:
     17        (TestWebKitAPI::TEST):
     18        * TestWebKitAPI/Tests/WebKit2Cocoa/large-video-with-audio.html:
     19        * TestWebKitAPI/Tests/WebKit2Cocoa/large-videos-with-audio-autoplay.html: Added.
     20        * TestWebKitAPI/Tests/WebKit2Cocoa/large-videos-with-audio.html: Added.
     21
    1222016-07-25  Wenson Hsieh  <wenson_hsieh@apple.com>
    223
  • trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj

    r203690 r203698  
    5757                2E1B7B021D41B1B9007558B4 /* large-video-hides-controls-after-seek-to-end.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 2E1B7B011D41B1B3007558B4 /* large-video-hides-controls-after-seek-to-end.html */; };
    5858                2E1DFDF11D42E1E400714A00 /* large-video-seek-to-beginning-and-play-after-ending.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 2E1DFDF01D42E14400714A00 /* large-video-seek-to-beginning-and-play-after-ending.html */; };
     59                2E1DFDED1D42A51100714A00 /* large-videos-with-audio.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 2E1DFDEC1D42A41C00714A00 /* large-videos-with-audio.html */; };
     60                2E1DFDEF1D42A6F200714A00 /* large-videos-with-audio-autoplay.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 2E1DFDEE1D42A6EB00714A00 /* large-videos-with-audio-autoplay.html */; };
    5961                2E7765CD16C4D80A00BA2BB1 /* mainIOS.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2E7765CC16C4D80A00BA2BB1 /* mainIOS.mm */; };
    6062                2E7765CF16C4D81100BA2BB1 /* mainMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2E7765CE16C4D81100BA2BB1 /* mainMac.mm */; };
     
    505507                                2E1B7B021D41B1B9007558B4 /* large-video-hides-controls-after-seek-to-end.html in Copy Resources */,
    506508                                2E1B7B001D41ABA7007558B4 /* large-video-seek-after-ending.html in Copy Resources */,
     509                                2E1DFDEF1D42A6F200714A00 /* large-videos-with-audio-autoplay.html in Copy Resources */,
     510                                2E1DFDED1D42A51100714A00 /* large-videos-with-audio.html in Copy Resources */,
    507511                                5C9E59411D3EB5AC00E3C62E /* ApplicationCache.db in Copy Resources */,
    508512                                5C9E59421D3EB5AC00E3C62E /* ApplicationCache.db-shm in Copy Resources */,
     
    708712                2E1B7B011D41B1B3007558B4 /* large-video-hides-controls-after-seek-to-end.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "large-video-hides-controls-after-seek-to-end.html"; sourceTree = "<group>"; };
    709713                2E1DFDF01D42E14400714A00 /* large-video-seek-to-beginning-and-play-after-ending.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "large-video-seek-to-beginning-and-play-after-ending.html"; sourceTree = "<group>"; };
     714                2E1DFDEC1D42A41C00714A00 /* large-videos-with-audio.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "large-videos-with-audio.html"; sourceTree = "<group>"; };
     715                2E1DFDEE1D42A6EB00714A00 /* large-videos-with-audio-autoplay.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "large-videos-with-audio-autoplay.html"; sourceTree = "<group>"; };
    710716                2E7765CC16C4D80A00BA2BB1 /* mainIOS.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = mainIOS.mm; sourceTree = "<group>"; };
    711717                2E7765CE16C4D81100BA2BB1 /* mainMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = mainMac.mm; sourceTree = "<group>"; };
     
    13471353                                2E1DFDF01D42E14400714A00 /* large-video-seek-to-beginning-and-play-after-ending.html */,
    13481354                                2E1B7B011D41B1B3007558B4 /* large-video-hides-controls-after-seek-to-end.html */,
     1355                                2E1DFDEE1D42A6EB00714A00 /* large-videos-with-audio-autoplay.html */,
    13491356                                5C9E593E1D3EB1DE00E3C62E /* ApplicationCache.db */,
    13501357                                5C9E593F1D3EB1DE00E3C62E /* ApplicationCache.db-shm */,
     
    13821389                                51714EB31CF8C761004723C4 /* WebProcessKillIDBCleanup-2.html */,
    13831390                                2E1B7AFF1D41A95F007558B4 /* large-video-seek-after-ending.html */,
     1391                                2E1DFDEC1D42A41C00714A00 /* large-videos-with-audio.html */,
    13841392                        );
    13851393                        name = Resources;
  • trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/VideoControlsManager.mm

    r203690 r203698  
    172172}
    173173
     174TEST(VideoControlsManager, VideoControlsManagerMultipleVideosWithAudio)
     175{
     176    RetainPtr<WKWebViewConfiguration> configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
     177    configuration.get().mediaTypesRequiringUserActionForPlayback = WKAudiovisualMediaTypeNone;
     178    RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 100, 100) configuration:configuration.get()]);
     179
     180    __block BOOL didShowMediaControls;
     181    __block bool isDoneLoading = false;
     182
     183    RetainPtr<NSWindow> window = adoptNS([[NSWindow alloc] initWithContentRect:[webView frame] styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:NO]);
     184    [[window contentView] addSubview:webView.get()];
     185    RetainPtr<OnLoadMessageHandler> onloadHandler = adoptNS([[OnLoadMessageHandler alloc] initWithWKWebView:webView.get() handler:^() {
     186        didShowMediaControls = [webView _hasActiveVideoForControlsManager];
     187        isDoneLoading = true;
     188    }]);
     189    [[configuration userContentController] addScriptMessageHandler:onloadHandler.get() name:@"onloadHandler"];
     190
     191    NSURLRequest *request = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"large-videos-with-audio" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]];
     192    [webView loadRequest:request];
     193
     194    TestWebKitAPI::Util::run(&isDoneLoading);
     195    EXPECT_FALSE(didShowMediaControls);
     196}
     197
     198TEST(VideoControlsManager, VideoControlsManagerMultipleVideosWithAudioAndAutoplay)
     199{
     200    RetainPtr<WKWebViewConfiguration> configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
     201    configuration.get().mediaTypesRequiringUserActionForPlayback = WKAudiovisualMediaTypeNone;
     202    RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 100, 100) configuration:configuration.get()]);
     203
     204    __block BOOL didShowMediaControls;
     205    __block bool isDoneLoading = false;
     206
     207    RetainPtr<NSWindow> window = adoptNS([[NSWindow alloc] initWithContentRect:[webView frame] styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:NO]);
     208    [[window contentView] addSubview:webView.get()];
     209    RetainPtr<OnLoadMessageHandler> onloadHandler = adoptNS([[OnLoadMessageHandler alloc] initWithWKWebView:webView.get() handler:^() {
     210        didShowMediaControls = [webView _hasActiveVideoForControlsManager];
     211        isDoneLoading = true;
     212    }]);
     213    [[configuration userContentController] addScriptMessageHandler:onloadHandler.get() name:@"onloadHandler"];
     214
     215    NSURLRequest *request = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"large-videos-with-audio-autoplay" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]];
     216    [webView loadRequest:request];
     217
     218    TestWebKitAPI::Util::run(&isDoneLoading);
     219    EXPECT_TRUE(didShowMediaControls);
     220}
     221
    174222TEST(VideoControlsManager, VideoControlsManagerSingleSmallAutoplayingVideo)
    175223{
  • trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/large-video-with-audio.html

    r200403 r203698  
    1313    function playing() {
    1414        window.clearTimeout(timeout);
    15         try {
    16             window.webkit.messageHandlers.playingHandler.postMessage('playing');
    17         } catch(e) {
    18             window.location = 'callback:playing';
    19         }
     15        setTimeout(function() {
     16            try {
     17                window.webkit.messageHandlers.playingHandler.postMessage('playing');
     18            } catch(e) {
     19                window.location = 'callback:playing';
     20            }
     21        }, 0);
    2022    }
    2123
Note: See TracChangeset for help on using the changeset viewer.