Changeset 205417 in webkit


Ignore:
Timestamp:
Sep 3, 2016 10:45:10 PM (8 years ago)
Author:
Wenson Hsieh
Message:

Media controls behave strangely when videos mute from within a playing handler
https://bugs.webkit.org/show_bug.cgi?id=161559
<rdar://problem/28018438>

Reviewed by Darin Adler.

Source/WebCore:

Defer showing media controls until after the media element has fired its onplaying handler. This handles cases
where videos that autoplay may initially meet the criteria for main content, but once the video begins to play,
the page may change the media in some way (e.g. muting) that makes the video no longer main content. This causes
media controls to flicker in and out.

These changes are covered by existing unit tests, which have been refactored to check media controller state
after all autoplaying videos have begun playing. Also adds an additional unit test.

  • html/HTMLMediaElement.cpp:

(WebCore::HTMLMediaElement::notifyAboutPlaying):
(WebCore::HTMLMediaElement::hasEverNotifiedAboutPlaying):

  • html/HTMLMediaElement.h:
  • html/MediaElementSession.cpp:

(WebCore::MediaElementSession::canShowControlsManager):

Tools:

Accounts for changes when determining whether or not to show media controls for autoplaying videos that have not
begun playing yet. Rather than check for a controlled media element upon page load, we force tests to wait until
all autoplaying videos have actually begun playing. This extends to tests that involve interaction, such as
clicking or scrolling.

  • TestWebKitAPI/Tests/WebKit2Cocoa/VideoControlsManager.mm:

(-[VideoControlsManagerTestWebView callJavascriptFunction:]):
(-[VideoControlsManagerTestWebView expectControlsManager:afterReceivingMessage:]):
(-[VideoControlsManagerTestWebView performAfterReceivingMessage:action:]):
(-[VideoControlsManagerTestWebView waitForPageToLoadWithAutoplayingVideos:]):
(TestWebKitAPI::TEST):
(-[VideoControlsManagerTestWebView loadTestPageNamed:andExpectControlsManager:afterReceivingMessage:]): Deleted.

  • TestWebKitAPI/Tests/WebKit2Cocoa/autoplaying-video-with-audio.html:
  • TestWebKitAPI/Tests/WebKit2Cocoa/large-video-hides-controls-after-seek-to-end.html:
  • TestWebKitAPI/Tests/WebKit2Cocoa/large-video-playing-scroll-away.html:
  • TestWebKitAPI/Tests/WebKit2Cocoa/large-videos-autoplaying-click-to-pause.html:
  • TestWebKitAPI/Tests/WebKit2Cocoa/large-videos-autoplaying-scroll-to-video.html:
  • TestWebKitAPI/Tests/WebKit2Cocoa/large-videos-paused-video-hides-controls.html:
  • TestWebKitAPI/Tests/WebKit2Cocoa/large-videos-playing-muted-video-hides-controls.html:
  • TestWebKitAPI/Tests/WebKit2Cocoa/large-videos-playing-video-keeps-controls.html:
  • TestWebKitAPI/Tests/WebKit2Cocoa/large-videos-with-audio-autoplay.html:
Location:
trunk
Files:
1 added
16 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r205416 r205417  
     12016-09-03  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        Media controls behave strangely when videos mute from within a playing handler
     4        https://bugs.webkit.org/show_bug.cgi?id=161559
     5        <rdar://problem/28018438>
     6
     7        Reviewed by Darin Adler.
     8
     9        Defer showing media controls until after the media element has fired its onplaying handler. This handles cases
     10        where videos that autoplay may initially meet the criteria for main content, but once the video begins to play,
     11        the page may change the media in some way (e.g. muting) that makes the video no longer main content. This causes
     12        media controls to flicker in and out.
     13
     14        These changes are covered by existing unit tests, which have been refactored to check media controller state
     15        after all autoplaying videos have begun playing. Also adds an additional unit test.
     16
     17        * html/HTMLMediaElement.cpp:
     18        (WebCore::HTMLMediaElement::notifyAboutPlaying):
     19        (WebCore::HTMLMediaElement::hasEverNotifiedAboutPlaying):
     20        * html/HTMLMediaElement.h:
     21        * html/MediaElementSession.cpp:
     22        (WebCore::MediaElementSession::canShowControlsManager):
     23
    1242016-09-03  Ryosuke Niwa  <rniwa@webkit.org>
    225
  • trunk/Source/WebCore/html/HTMLMediaElement.cpp

    r205412 r205417  
    482482    , m_creatingControls(false)
    483483    , m_receivedLayoutSizeChanged(false)
     484    , m_hasEverNotifiedAboutPlaying(false)
    484485#if ENABLE(MEDIA_CONTROLS_SCRIPT)
    485486    , m_mediaControlsDependOnPageScaleFactor(false)
     
    10151016    dispatchEvent(Event::create(eventNames().playingEvent, false, true));
    10161017    resolvePendingPlayPromises();
     1018
     1019    m_hasEverNotifiedAboutPlaying = true;
     1020    scheduleUpdatePlaybackControlsManager();
     1021}
     1022
     1023bool HTMLMediaElement::hasEverNotifiedAboutPlaying() const
     1024{
     1025    return m_hasEverNotifiedAboutPlaying;
    10171026}
    10181027
  • trunk/Source/WebCore/html/HTMLMediaElement.h

    r205412 r205417  
    471471    void resetPlaybackSessionState();
    472472    bool isVisibleInViewport() const;
     473    bool hasEverNotifiedAboutPlaying() const;
    473474
    474475protected:
     
    944945    bool m_creatingControls : 1;
    945946    bool m_receivedLayoutSizeChanged : 1;
     947    bool m_hasEverNotifiedAboutPlaying : 1;
    946948
    947949#if ENABLE(MEDIA_CONTROLS_SCRIPT)
  • trunk/Source/WebCore/html/MediaElementSession.cpp

    r205412 r205417  
    229229    }
    230230
     231    if (m_element.document().isMediaDocument()) {
     232        LOG(Media, "MediaElementSession::canShowControlsManager - returning TRUE: Is media document");
     233        return true;
     234    }
     235
    231236    if (m_element.document().activeDOMObjectsAreSuspended()) {
    232237        LOG(Media, "MediaElementSession::canShowControlsManager - returning FALSE: activeDOMObjectsAreSuspended()");
     
    251256    if (m_element.muted()) {
    252257        LOG(Media, "MediaElementSession::canShowControlsManager - returning FALSE: Muted");
     258        return false;
     259    }
     260
     261    if (!m_element.hasEverNotifiedAboutPlaying()) {
     262        LOG(Media, "MediaElementSession::canShowControlsManager - returning FALSE: Hasn't fired playing notification");
    253263        return false;
    254264    }
     
    258268            LOG(Media, "MediaElementSession::canShowControlsManager - returning FALSE: No renderer");
    259269            return false;
    260         }
    261 
    262         if (m_element.document().isMediaDocument()) {
    263             LOG(Media, "MediaElementSession::canShowControlsManager - returning TRUE: Is media document");
    264             return true;
    265270        }
    266271
  • trunk/Tools/ChangeLog

    r205412 r205417  
     12016-09-03  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        Media controls behave strangely when videos mute from within a playing handler
     4        https://bugs.webkit.org/show_bug.cgi?id=161559
     5        <rdar://problem/28018438>
     6
     7        Reviewed by Darin Adler.
     8
     9        Accounts for changes when determining whether or not to show media controls for autoplaying videos that have not
     10        begun playing yet. Rather than check for a controlled media element upon page load, we force tests to wait until
     11        all autoplaying videos have actually begun playing. This extends to tests that involve interaction, such as
     12        clicking or scrolling.
     13
     14        * TestWebKitAPI/Tests/WebKit2Cocoa/VideoControlsManager.mm:
     15        (-[VideoControlsManagerTestWebView callJavascriptFunction:]):
     16        (-[VideoControlsManagerTestWebView expectControlsManager:afterReceivingMessage:]):
     17        (-[VideoControlsManagerTestWebView performAfterReceivingMessage:action:]):
     18        (-[VideoControlsManagerTestWebView waitForPageToLoadWithAutoplayingVideos:]):
     19        (TestWebKitAPI::TEST):
     20        (-[VideoControlsManagerTestWebView loadTestPageNamed:andExpectControlsManager:afterReceivingMessage:]): Deleted.
     21        * TestWebKitAPI/Tests/WebKit2Cocoa/autoplaying-video-with-audio.html:
     22        * TestWebKitAPI/Tests/WebKit2Cocoa/large-video-hides-controls-after-seek-to-end.html:
     23        * TestWebKitAPI/Tests/WebKit2Cocoa/large-video-playing-scroll-away.html:
     24        * TestWebKitAPI/Tests/WebKit2Cocoa/large-videos-autoplaying-click-to-pause.html:
     25        * TestWebKitAPI/Tests/WebKit2Cocoa/large-videos-autoplaying-scroll-to-video.html:
     26        * TestWebKitAPI/Tests/WebKit2Cocoa/large-videos-paused-video-hides-controls.html:
     27        * TestWebKitAPI/Tests/WebKit2Cocoa/large-videos-playing-muted-video-hides-controls.html:
     28        * TestWebKitAPI/Tests/WebKit2Cocoa/large-videos-playing-video-keeps-controls.html:
     29        * TestWebKitAPI/Tests/WebKit2Cocoa/large-videos-with-audio-autoplay.html:
     30
    1312016-09-03  Wenson Hsieh  <wenson_hsieh@apple.com>
    232
  • trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj

    r205412 r205417  
    6565                2E1DFDEF1D42A6F200714A00 /* large-videos-with-audio-autoplay.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 2E1DFDEE1D42A6EB00714A00 /* large-videos-with-audio-autoplay.html */; };
    6666                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 */; };
     67                2E54F40D1D7BC84200921ADF /* large-video-mutes-onplaying.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 2E54F40C1D7BC83900921ADF /* large-video-mutes-onplaying.html */; };
    6768                2E691AEA1D78B53600129407 /* large-videos-paused-video-hides-controls.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 2E691AE81D78B52B00129407 /* large-videos-paused-video-hides-controls.html */; };
    6869                2E691AEB1D78B53600129407 /* large-videos-playing-video-keeps-controls.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 2E691AE91D78B52B00129407 /* large-videos-playing-video-keeps-controls.html */; };
     
    527528                        dstSubfolderSpec = 7;
    528529                        files = (
     530                                2E54F40D1D7BC84200921ADF /* large-video-mutes-onplaying.html in Copy Resources */,
    529531                                2E691AF31D79E75E00129407 /* large-video-playing-scroll-away.html in Copy Resources */,
    530532                                2E691AF11D79E51A00129407 /* large-videos-autoplaying-scroll-to-video.html in Copy Resources */,
     
    756758                2E1DFDEE1D42A6EB00714A00 /* large-videos-with-audio-autoplay.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "large-videos-with-audio-autoplay.html"; sourceTree = "<group>"; };
    757759                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>"; };
     760                2E54F40C1D7BC83900921ADF /* large-video-mutes-onplaying.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "large-video-mutes-onplaying.html"; sourceTree = "<group>"; };
    758761                2E691AE81D78B52B00129407 /* large-videos-paused-video-hides-controls.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "large-videos-paused-video-hides-controls.html"; sourceTree = "<group>"; };
    759762                2E691AE91D78B52B00129407 /* large-videos-playing-video-keeps-controls.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "large-videos-playing-video-keeps-controls.html"; sourceTree = "<group>"; };
     
    14191422                        isa = PBXGroup;
    14201423                        children = (
     1424                                2E54F40C1D7BC83900921ADF /* large-video-mutes-onplaying.html */,
    14211425                                2E691AF21D79E75400129407 /* large-video-playing-scroll-away.html */,
    14221426                                2E691AF01D79E51400129407 /* large-videos-autoplaying-scroll-to-video.html */,
  • trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/VideoControlsManager.mm

    r205412 r205417  
    4444@end
    4545
    46 @interface MessageHandler : NSObject <WKScriptMessageHandler> {
     46@interface MessageHandler : NSObject <WKScriptMessageHandler>
     47@end
     48
     49@implementation MessageHandler {
    4750    dispatch_block_t _handler;
    4851    NSString *_message;
    4952}
    5053
    51 - (instancetype)initWithMessage:(NSString *)message handler:(dispatch_block_t)handler;
    52 
    53 @end
    54 
    55 @implementation MessageHandler
    56 
    5754- (instancetype)initWithMessage:(NSString *)message handler:(dispatch_block_t)handler
    5855{
     
    7572
    7673@interface VideoControlsManagerTestWebView : WKWebView
    77 
    78 - (void)mouseDownAtPoint:(NSPoint)point;
    79 - (void)performAfterLoading:(dispatch_block_t)actions;
    80 - (void)loadTestPageNamed:(NSString *)pageName;
    81 - (void)loadTestPageNamed:(NSString *)pageName andExpectControlsManager:(BOOL)expectControlsManager afterReceivingMessage:(NSString *)message;
    82 - (void)performAfterReceivingMessage:(NSString *)message action:(dispatch_block_t)action;
    83 
    84 @property (nonatomic, readonly) NSString *controlledElementID;
    85 
    8674@end
    8775
     
    10593}
    10694
     95- (void)callJavascriptFunction:(NSString *)functionName
     96{
     97    NSString *command = [NSString stringWithFormat:@"%@()", functionName];
     98    [self evaluateJavaScript:command completionHandler:nil];
     99}
     100
    107101- (void)loadTestPageNamed:(NSString *)pageName
    108102{
     
    111105}
    112106
    113 - (void)loadTestPageNamed:(NSString *)pageName andExpectControlsManager:(BOOL)expectControlsManager afterReceivingMessage:(NSString *)message
     107- (void)expectControlsManager:(BOOL)expectControlsManager afterReceivingMessage:(NSString *)message
    114108{
    115109    __block bool doneWaiting = false;
     
    123117    }];
    124118
    125     [self loadTestPageNamed:pageName];
    126119    TestWebKitAPI::Util::run(&doneWaiting);
    127120}
     
    130123{
    131124    RetainPtr<MessageHandler> handler = adoptNS([[MessageHandler alloc] initWithMessage:message handler:action]);
    132     [[[self configuration] userContentController] addScriptMessageHandler:handler.get() name:@"playingHandler"];
     125    WKUserContentController* contentController = [[self configuration] userContentController];
     126    [contentController removeScriptMessageHandlerForName:@"playingHandler"];
     127    [contentController addScriptMessageHandler:handler.get() name:@"playingHandler"];
     128}
     129
     130- (void)waitForPageToLoadWithAutoplayingVideos:(int)numberOfAutoplayingVideos
     131{
     132    __block int remainingAutoplayedCount = numberOfAutoplayingVideos;
     133    __block bool autoplayingIsFinished = !numberOfAutoplayingVideos;
     134    __block bool pageHasLoaded = false;
     135
     136    [self performAfterLoading:^()
     137    {
     138        pageHasLoaded = true;
     139    }];
     140
     141    if (numberOfAutoplayingVideos) {
     142        [self performAfterReceivingMessage:@"autoplayed" action:^()
     143        {
     144            remainingAutoplayedCount--;
     145            if (remainingAutoplayedCount <= 0)
     146                autoplayingIsFinished = true;
     147        }];
     148    }
     149
     150    TestWebKitAPI::Util::run(&pageHasLoaded);
     151    TestWebKitAPI::Util::run(&autoplayingIsFinished);
    133152}
    134153
     
    168187    // A large video with audio should have a controls manager even if it is played via script like this video.
    169188    // So the expectation is YES.
    170     [webView loadTestPageNamed:@"large-video-with-audio" andExpectControlsManager:YES afterReceivingMessage:@"playing"];
     189    [webView loadTestPageNamed:@"large-video-with-audio"];
     190    [webView expectControlsManager:YES afterReceivingMessage:@"playing"];
    171191}
    172192
     
    177197    // A small video will not have a controls manager unless it started playing because of a user gesture. Since this
    178198    // video is started with a script, the expectation is NO.
    179     [webView loadTestPageNamed:@"video-with-audio" andExpectControlsManager:NO afterReceivingMessage:@"playing"];
     199    [webView loadTestPageNamed:@"video-with-audio"];
     200    [webView expectControlsManager:NO afterReceivingMessage:@"playing"];
    180201}
    181202
     
    184205    RetainPtr<VideoControlsManagerTestWebView*> webView = setUpWebViewForTestingVideoControlsManager(NSMakeRect(0, 0, 100, 100));
    185206
    186     __block BOOL didShowMediaControls;
    187     __block bool isDoneLoading = false;
    188 
    189     [webView performAfterLoading:^ {
    190         didShowMediaControls = [webView _hasActiveVideoForControlsManager];
    191         isDoneLoading = true;
    192     }];
    193 
    194207    [webView loadTestPageNamed:@"large-videos-with-audio"];
    195 
    196     TestWebKitAPI::Util::run(&isDoneLoading);
    197     EXPECT_FALSE(didShowMediaControls);
     208    [webView waitForPageToLoadWithAutoplayingVideos:0];
     209
     210    EXPECT_FALSE([webView _hasActiveVideoForControlsManager]);
    198211}
    199212
     
    202215    RetainPtr<VideoControlsManagerTestWebView*> webView = setUpWebViewForTestingVideoControlsManager(NSMakeRect(0, 0, 100, 100));
    203216
    204     __block BOOL didShowMediaControls;
    205     __block bool isDoneLoading = false;
    206 
    207     [webView performAfterLoading:^ {
    208         didShowMediaControls = [webView _hasActiveVideoForControlsManager];
    209         isDoneLoading = true;
    210     }];
    211 
    212217    [webView loadTestPageNamed:@"large-videos-with-audio-autoplay"];
    213 
    214     TestWebKitAPI::Util::run(&isDoneLoading);
    215     EXPECT_TRUE(didShowMediaControls);
     218    [webView waitForPageToLoadWithAutoplayingVideos:1];
     219
     220    EXPECT_TRUE([webView _hasActiveVideoForControlsManager]);
     221    EXPECT_TRUE([[webView controlledElementID] isEqualToString:@"bar"]);
    216222}
    217223
     
    220226    RetainPtr<VideoControlsManagerTestWebView*> webView = setUpWebViewForTestingVideoControlsManager(NSMakeRect(0, 0, 500, 500));
    221227
    222     [webView loadTestPageNamed:@"large-videos-paused-video-hides-controls" andExpectControlsManager:NO afterReceivingMessage:@"paused"];
     228    [webView loadTestPageNamed:@"large-videos-paused-video-hides-controls"];
     229    [webView waitForPageToLoadWithAutoplayingVideos:1];
     230
     231    [webView callJavascriptFunction:@"pauseFirstVideoAndScrollToSecondVideo"];
     232    [webView expectControlsManager:NO afterReceivingMessage:@"paused"];
    223233}
    224234
     
    227237    RetainPtr<VideoControlsManagerTestWebView*> webView = setUpWebViewForTestingVideoControlsManager(NSMakeRect(0, 0, 500, 500));
    228238
    229     [webView loadTestPageNamed:@"large-videos-playing-video-keeps-controls" andExpectControlsManager:YES afterReceivingMessage:@"playing"];
     239    [webView loadTestPageNamed:@"large-videos-playing-video-keeps-controls"];
     240    [webView waitForPageToLoadWithAutoplayingVideos:1];
     241
     242    [webView callJavascriptFunction:@"scrollToSecondVideo"];
     243    [webView expectControlsManager:YES afterReceivingMessage:@"scrolled"];
    230244}
    231245
     
    234248    RetainPtr<VideoControlsManagerTestWebView*> webView = setUpWebViewForTestingVideoControlsManager(NSMakeRect(0, 0, 500, 500));
    235249
    236     [webView loadTestPageNamed:@"large-videos-playing-muted-video-hides-controls" andExpectControlsManager:NO afterReceivingMessage:@"playing"];
     250    [webView loadTestPageNamed:@"large-videos-playing-muted-video-hides-controls"];
     251    [webView waitForPageToLoadWithAutoplayingVideos:1];
     252
     253    [webView callJavascriptFunction:@"muteFirstVideoAndScrollToSecondVideo"];
     254    [webView expectControlsManager:NO afterReceivingMessage:@"playing"];
    237255}
    238256
     
    242260    NSPoint clickPoint = NSMakePoint(400, 300);
    243261
    244     [webView performAfterLoading:^ {
    245         [webView mouseDownAtPoint:clickPoint];
    246     }];
     262    [webView loadTestPageNamed:@"large-videos-autoplaying-click-to-pause"];
     263    [webView waitForPageToLoadWithAutoplayingVideos:2];
     264
     265    [webView mouseDownAtPoint:clickPoint];
    247266
    248267    __block bool firstVideoPaused = false;
     
    251270        NSString *controlledElementID = [webView controlledElementID];
    252271        if (firstVideoPaused) {
     272            EXPECT_TRUE([controlledElementID isEqualToString:@"second"]);
    253273            secondVideoPaused = true;
    254             EXPECT_TRUE([controlledElementID isEqualToString:@"second"]);
    255274        } else {
     275            EXPECT_TRUE([controlledElementID isEqualToString:@"first"]);
    256276            [webView mouseDownAtPoint:clickPoint];
    257             EXPECT_TRUE([controlledElementID isEqualToString:@"first"]);
    258277        }
    259278        firstVideoPaused = true;
    260279    }];
    261280
    262     [webView loadTestPageNamed:@"large-videos-autoplaying-click-to-pause"];
    263281    TestWebKitAPI::Util::run(&secondVideoPaused);
    264282}
     
    268286    RetainPtr<VideoControlsManagerTestWebView*> webView = setUpWebViewForTestingVideoControlsManager(NSMakeRect(0, 0, 800, 600));
    269287
    270     __block bool scrolledSecondVideoIntoView = false;
    271288    [webView loadTestPageNamed:@"large-videos-autoplaying-scroll-to-video"];
    272     [webView performAfterReceivingMessage:@"scrolled" action:^ {
    273         scrolledSecondVideoIntoView = true;
    274     }];
    275 
    276     TestWebKitAPI::Util::run(&scrolledSecondVideoIntoView);
     289    [webView waitForPageToLoadWithAutoplayingVideos:2];
     290
     291    [webView callJavascriptFunction:@"scrollToSecondView"];
     292    [webView expectControlsManager:YES afterReceivingMessage:@"scrolled"];
     293
    277294    EXPECT_TRUE([[webView controlledElementID] isEqualToString:@"second"]);
    278295}
     
    282299    RetainPtr<VideoControlsManagerTestWebView*> webView = setUpWebViewForTestingVideoControlsManager(NSMakeRect(0, 0, 500, 500));
    283300
    284     [webView loadTestPageNamed:@"large-video-playing-scroll-away" andExpectControlsManager:YES afterReceivingMessage:@"scrolled"];
     301    [webView loadTestPageNamed:@"large-video-playing-scroll-away"];
     302    [webView waitForPageToLoadWithAutoplayingVideos:1];
     303    [webView callJavascriptFunction:@"scrollVideoOutOfView"];
     304    [webView expectControlsManager:YES afterReceivingMessage:@"scrolled"];
    285305}
    286306
     
    289309    RetainPtr<VideoControlsManagerTestWebView*> webView = setUpWebViewForTestingVideoControlsManager(NSMakeRect(0, 0, 100, 100));
    290310
    291     [webView performAfterLoading:^ {
    292         [webView mouseDownAtPoint:NSMakePoint(50, 50)];
    293     }];
    294 
    295     [webView loadTestPageNamed:@"autoplaying-video-with-audio" andExpectControlsManager:YES afterReceivingMessage:@"paused"];
     311    [webView loadTestPageNamed:@"autoplaying-video-with-audio"];
     312    [webView waitForPageToLoadWithAutoplayingVideos:1];
     313
     314    [webView mouseDownAtPoint:NSMakePoint(50, 50)];
     315    [webView expectControlsManager:YES afterReceivingMessage:@"paused"];
    296316}
    297317
     
    301321
    302322    // Since the video has ended, the expectation is NO even if the page programmatically seeks to the beginning.
    303     [webView loadTestPageNamed:@"large-video-seek-after-ending" andExpectControlsManager:NO afterReceivingMessage:@"ended"];
     323    [webView loadTestPageNamed:@"large-video-seek-after-ending"];
     324    [webView expectControlsManager:NO afterReceivingMessage:@"ended"];
    304325}
    305326
     
    309330
    310331    // Since the video is still playing, the expectation is YES even if the video has ended once.
    311     [webView loadTestPageNamed:@"large-video-seek-to-beginning-and-play-after-ending" andExpectControlsManager:YES afterReceivingMessage:@"replaying"];
     332    [webView loadTestPageNamed:@"large-video-seek-to-beginning-and-play-after-ending"];
     333    [webView expectControlsManager:YES afterReceivingMessage:@"replaying"];
    312334}
    313335
     
    316338    RetainPtr<VideoControlsManagerTestWebView*> webView = setUpWebViewForTestingVideoControlsManager(NSMakeRect(0, 0, 100, 100));
    317339
    318     [webView performAfterLoading:^ {
    319         [webView mouseDownAtPoint:NSMakePoint(50, 50)];
    320     }];
     340    [webView loadTestPageNamed:@"large-video-hides-controls-after-seek-to-end"];
     341    [webView waitForPageToLoadWithAutoplayingVideos:1];
     342    [webView mouseDownAtPoint:NSMakePoint(50, 50)];
    321343
    322344    // We expect there to be media controls, since this is a user gestured seek to the end.
    323345    // This is akin to seeking to the end by scrubbing in the controls.
    324     [webView loadTestPageNamed:@"large-video-hides-controls-after-seek-to-end" andExpectControlsManager:YES afterReceivingMessage:@"ended"];
     346    [webView expectControlsManager:YES afterReceivingMessage:@"ended"];
    325347}
    326348
     
    331353    // A large video with no audio will not have a controls manager unless it started playing because of a user gesture. Since this
    332354    // video is started with a script, the expectation is NO.
    333     [webView loadTestPageNamed:@"large-video-without-audio" andExpectControlsManager:NO afterReceivingMessage:@"playing"];
     355    [webView loadTestPageNamed:@"large-video-without-audio"];
     356    [webView expectControlsManager:NO afterReceivingMessage:@"playing"];
    334357}
    335358
     
    339362
    340363    // An audio element MUST be started with a user gesture in order to have a controls manager, so the expectation is NO.
    341     [webView loadTestPageNamed:@"audio-only" andExpectControlsManager:NO afterReceivingMessage:@"playing"];
     364    [webView loadTestPageNamed:@"audio-only"];
     365    [webView expectControlsManager:NO afterReceivingMessage:@"playing"];
    342366}
    343367
     
    384408    RetainPtr<VideoControlsManagerTestWebView*> webView = setUpWebViewForTestingVideoControlsManager(NSMakeRect(0, 0, 1600, 800));
    385409
    386     [webView loadTestPageNamed:@"skinny-autoplaying-video-with-audio" andExpectControlsManager:NO afterReceivingMessage:@"playing"];
     410    [webView loadTestPageNamed:@"skinny-autoplaying-video-with-audio"];
     411    [webView expectControlsManager:NO afterReceivingMessage:@"playing"];
    387412}
    388413
     
    391416    RetainPtr<VideoControlsManagerTestWebView*> webView = setUpWebViewForTestingVideoControlsManager(NSMakeRect(0, 0, 1600, 800));
    392417
    393     [webView loadTestPageNamed:@"full-size-autoplaying-video-with-audio" andExpectControlsManager:YES afterReceivingMessage:@"playing"];
     418    [webView loadTestPageNamed:@"full-size-autoplaying-video-with-audio"];
     419    [webView expectControlsManager:YES afterReceivingMessage:@"playing"];
     420}
     421
     422TEST(VideoControlsManager, VideoControlsManagerVideoMutesOnPlaying)
     423{
     424    RetainPtr<VideoControlsManagerTestWebView*> webView = setUpWebViewForTestingVideoControlsManager(NSMakeRect(0, 0, 500, 500));
     425
     426    [webView loadTestPageNamed:@"large-video-mutes-onplaying"];
     427    [webView expectControlsManager:NO afterReceivingMessage:@"playing"];
    394428}
    395429
  • trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/autoplaying-video-with-audio.html

    r203464 r205417  
    55    var timeout;
    66
    7     function beginTest() {
    8         timeout = window.setTimeout(stillPlaying, 5000);
    9         window.addEventListener("mousedown", pauseVideo);
    10         try {
    11             window.webkit.messageHandlers.onloadHandler.postMessage('loaded');
    12         } catch(e) { }
    13     }
    14 
    157    function pauseVideo() {
    16         document.getElementsByTagName('video')[0].pause();
    17         window.clearTimeout(timeout);
     8        document.getElementsByTagName("video")[0].pause();
    189    }
    1910
     
    2213        setTimeout(function() {
    2314            try {
    24                 window.webkit.messageHandlers.playingHandler.postMessage('paused');
     15                window.webkit.messageHandlers.playingHandler.postMessage("paused");
    2516            } catch(e) { }
    2617        }, 0);
    2718    }
    2819
    29     function stillPlaying() {
    30         try {
    31             window.webkit.messageHandlers.playingHandler.postMessage('playing');
    32         } catch(e) { }
     20    function beganAutoplaying() {
     21        setTimeout(function() {
     22            try {
     23                window.webkit.messageHandlers.playingHandler.postMessage("autoplayed");
     24            } catch(e) {
     25            }
     26        }, 0)
    3327    }
    3428
    3529   </script>
    3630</head>
    37 <body onload="beginTest()">
    38     <video controls autoplay src="video-with-audio.mp4" webkit-playsinline onpause="handlePaused()"></video>
     31<body onmousedown=pauseVideo()>
     32    <video autoplay controls onplaying=beganAutoplaying() src="video-with-audio.mp4" webkit-playsinline onpause=handlePaused()></video>
    3933</body>
    4034</html>
  • trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/large-video-hides-controls-after-seek-to-end.html

    r203690 r205417  
    2424    }
    2525
     26    function beganAutoplaying() {
     27        setTimeout(function() {
     28            try {
     29                window.webkit.messageHandlers.playingHandler.postMessage("autoplayed");
     30            } catch(e) {
     31            }
     32        }, 0)
     33    }
     34
    2635   </script>
    2736</head>
    2837<body onmousedown=seekToEnd() onload=beginTest()>
    29     <video autoplay onended=handleEnded() src="large-video-with-audio.mp4" webkit-playsinline style="width: 800px; height: 600px;"></video>
     38    <video autoplay onplaying=beganAutoplaying() onended=handleEnded() src="large-video-with-audio.mp4" webkit-playsinline style="width: 800px; height: 600px;"></video>
    3039</body>
    3140</html>
  • trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/large-video-playing-scroll-away.html

    r205412 r205417  
    1212        </style>
    1313        <script>
    14             function handleLoaded() {
     14            function scrollVideoOutOfView() {
    1515                document.querySelector("div").scrollIntoView();
    1616                setTimeout(function() {
     
    1818                }, 0);
    1919            }
     20
     21            function beganAutoplaying() {
     22                setTimeout(function() {
     23                    try {
     24                        window.webkit.messageHandlers.playingHandler.postMessage("autoplayed");
     25                    } catch(e) {
     26                    }
     27                }, 0)
     28            }
    2029        </script>
    2130    </head>
    22     <body onload=handleLoaded()>
    23         <video autoplay loop id="first" src="large-video-with-audio.mp4"></video>
     31    <body>
     32        <video autoplay onplaying=beganAutoplaying() loop id="first" src="large-video-with-audio.mp4"></video>
    2433        <br>
    2534        <div>hello world!</div>
  • trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/large-videos-autoplaying-click-to-pause.html

    r205412 r205417  
    3030                }, 0);
    3131            }
     32
     33            function beganAutoplaying() {
     34                setTimeout(function() {
     35                    try {
     36                        window.webkit.messageHandlers.playingHandler.postMessage("autoplayed");
     37                    } catch(e) {
     38                    }
     39                }, 0)
     40            }
    3241        </script>
    3342    </head>
    3443    <body onmousedown=handleMouseDown()>
    35         <video autoplay loop id="first" src="large-video-with-audio.mp4" onpause=handleFirstPause()></video>
    36         <video autoplay loop id="second" src="large-video-with-audio.mp4" onpause=handleSecondPause()></video>
     44        <video autoplay onplaying=beganAutoplaying() loop id="first" src="large-video-with-audio.mp4" onpause=handleFirstPause()></video>
     45        <video autoplay onplaying=beganAutoplaying() loop id="second" src="large-video-with-audio.mp4" onpause=handleSecondPause()></video>
    3746    </body>
    3847<html>
  • trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/large-videos-autoplaying-scroll-to-video.html

    r205412 r205417  
    1212        </style>
    1313        <script>
    14             function handleLoaded() {
     14            function scrollToSecondView() {
    1515                document.querySelector("#second").scrollIntoView();
    1616                setTimeout(function() {
     
    1818                }, 0);
    1919            }
     20            function beganAutoplaying() {
     21                setTimeout(function() {
     22                    try {
     23                        window.webkit.messageHandlers.playingHandler.postMessage("autoplayed");
     24                    } catch(e) {
     25                    }
     26                }, 0)
     27            }
    2028        </script>
    2129    </head>
    22     <body onload=handleLoaded()>
    23         <video autoplay loop id="first" src="large-video-with-audio.mp4"></video>
     30    <body>
     31        <video autoplay onplaying=beganAutoplaying() loop id="first" src="large-video-with-audio.mp4"></video>
    2432        <br>
    25         <video autoplay loop id="second" src="large-video-with-audio.mp4"></video>
     33        <video autoplay onplaying=beganAutoplaying() loop id="second" src="large-video-with-audio.mp4"></video>
    2634    </body>
    2735<html>
  • trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/large-videos-paused-video-hides-controls.html

    r205412 r205417  
    1111</style>
    1212<script>
    13     function handleLoaded() {
     13    function pauseFirstVideoAndScrollToSecondVideo() {
    1414        document.querySelector("#bar").scrollIntoView();
    1515        document.querySelector("#foo").pause();
     
    2222        }, 0);
    2323    }
     24    function beganAutoplaying() {
     25        setTimeout(function() {
     26            try {
     27                window.webkit.messageHandlers.playingHandler.postMessage("autoplayed");
     28            } catch(e) {
     29            }
     30        }, 0)
     31    }
    2432</script>
    25 <body onload=handleLoaded()>
    26     <video autoplay loop id="foo" onpause=handlePaused()><source src="large-video-with-audio.mp4"></video>
     33<body>
     34    <video autoplay onplaying=beganAutoplaying() loop id="foo" onpause=handlePaused()><source src="large-video-with-audio.mp4"></video>
    2735    <br>
    2836    <video id="bar"><source src="large-video-with-audio.mp4"></video>
  • trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/large-videos-playing-muted-video-hides-controls.html

    r205412 r205417  
    1111</style>
    1212<script>
    13     function handleLoaded() {
     13    function muteFirstVideoAndScrollToSecondVideo() {
    1414        document.querySelector("#foo").muted = true;
    1515        document.querySelector("#bar").scrollIntoView();
     
    2020        }, 0);
    2121    }
     22    function beganAutoplaying() {
     23        setTimeout(function() {
     24            try {
     25                window.webkit.messageHandlers.playingHandler.postMessage("autoplayed");
     26            } catch(e) {
     27            }
     28        }, 0)
     29    }
    2230</script>
    23 <body onload=handleLoaded()>
    24     <video autoplay loop id="foo"><source src="large-video-with-audio.mp4"></video>
     31<body>
     32    <video autoplay onplaying=beganAutoplaying() loop id="foo"><source src="large-video-with-audio.mp4"></video>
    2533    <br>
    2634    <video id="bar"><source src="large-video-with-audio.mp4"></video>
  • trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/large-videos-playing-video-keeps-controls.html

    r205412 r205417  
    1111</style>
    1212<script>
    13     function handleLoaded() {
     13    function scrollToSecondVideo() {
    1414        document.querySelector("#bar").scrollIntoView();
    1515        setTimeout(function() {
    1616            try {
    17                 window.webkit.messageHandlers.playingHandler.postMessage("playing");
     17                window.webkit.messageHandlers.playingHandler.postMessage("scrolled");
    1818            } catch(e) { }
    1919        }, 0);
    2020    }
     21    function beganAutoplaying() {
     22        setTimeout(function() {
     23            try {
     24                window.webkit.messageHandlers.playingHandler.postMessage("autoplayed");
     25            } catch(e) {
     26            }
     27        }, 0)
     28    }
    2129</script>
    22 <body onload=handleLoaded()>
    23     <video autoplay loop id="foo"><source src="large-video-with-audio.mp4"></video>
     30<body>
     31    <video autoplay onplaying=beganAutoplaying() loop id="foo"><source src="large-video-with-audio.mp4"></video>
    2432    <br>
    2533    <video id="bar"><source src="large-video-with-audio.mp4"></video>
  • trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/large-videos-with-audio-autoplay.html

    r203698 r205417  
    22<html>
    33<script>
    4     function handleLoaded() {
    5         // The media controls should be updated on the next runloop.
     4    function beganAutoplaying() {
    65        setTimeout(function() {
    76            try {
    8                 window.webkit.messageHandlers.onloadHandler.postMessage("loaded");
    9             } catch(e) { }
    10         }, 0);
     7                window.webkit.messageHandlers.playingHandler.postMessage("autoplayed");
     8            } catch(e) {
     9            }
     10        }, 0)
    1111    }
    1212</script>
    13 <body onload=handleLoaded()>
     13<body>
    1414    <video id="foo" style="width: 480px; height: 320px;"><source src="large-video-with-audio.mp4"></video>
    15     <video autoplay id="bar" style="width: 480px; height: 320px;"><source src="large-video-with-audio.mp4"></video>
     15    <video autoplay onplaying=beganAutoplaying() id="bar" style="width: 480px; height: 320px;"><source src="large-video-with-audio.mp4"></video>
    1616    <video id="baz" style="width: 480px; height: 320px;"><source src="large-video-with-audio.mp4"></video>
    1717</body>
Note: See TracChangeset for help on using the changeset viewer.