Diff
Modified: trunk/Source/WebCore/ChangeLog (205416 => 205417)
--- trunk/Source/WebCore/ChangeLog 2016-09-04 05:09:28 UTC (rev 205416)
+++ trunk/Source/WebCore/ChangeLog 2016-09-04 05:45:10 UTC (rev 205417)
@@ -1,3 +1,26 @@
+2016-09-03 Wenson Hsieh <[email protected]>
+
+ 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.
+
+ 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):
+
2016-09-03 Ryosuke Niwa <[email protected]>
Update the semantics of defined-ness of custom elements per spec changes
Modified: trunk/Source/WebCore/html/HTMLMediaElement.cpp (205416 => 205417)
--- trunk/Source/WebCore/html/HTMLMediaElement.cpp 2016-09-04 05:09:28 UTC (rev 205416)
+++ trunk/Source/WebCore/html/HTMLMediaElement.cpp 2016-09-04 05:45:10 UTC (rev 205417)
@@ -481,6 +481,7 @@
, m_elementIsHidden(document.hidden())
, m_creatingControls(false)
, m_receivedLayoutSizeChanged(false)
+ , m_hasEverNotifiedAboutPlaying(false)
#if ENABLE(MEDIA_CONTROLS_SCRIPT)
, m_mediaControlsDependOnPageScaleFactor(false)
, m_haveSetUpCaptionContainer(false)
@@ -1014,8 +1015,16 @@
{
dispatchEvent(Event::create(eventNames().playingEvent, false, true));
resolvePendingPlayPromises();
+
+ m_hasEverNotifiedAboutPlaying = true;
+ scheduleUpdatePlaybackControlsManager();
}
+bool HTMLMediaElement::hasEverNotifiedAboutPlaying() const
+{
+ return m_hasEverNotifiedAboutPlaying;
+}
+
void HTMLMediaElement::pendingActionTimerFired()
{
Ref<HTMLMediaElement> protectedThis(*this); // loadNextSourceChild may fire 'beforeload', which can make arbitrary DOM mutations.
Modified: trunk/Source/WebCore/html/HTMLMediaElement.h (205416 => 205417)
--- trunk/Source/WebCore/html/HTMLMediaElement.h 2016-09-04 05:09:28 UTC (rev 205416)
+++ trunk/Source/WebCore/html/HTMLMediaElement.h 2016-09-04 05:45:10 UTC (rev 205417)
@@ -470,6 +470,7 @@
void resetPlaybackSessionState();
bool isVisibleInViewport() const;
+ bool hasEverNotifiedAboutPlaying() const;
protected:
HTMLMediaElement(const QualifiedName&, Document&, bool createdByParser);
@@ -943,6 +944,7 @@
bool m_elementIsHidden : 1;
bool m_creatingControls : 1;
bool m_receivedLayoutSizeChanged : 1;
+ bool m_hasEverNotifiedAboutPlaying : 1;
#if ENABLE(MEDIA_CONTROLS_SCRIPT)
bool m_mediaControlsDependOnPageScaleFactor : 1;
Modified: trunk/Source/WebCore/html/MediaElementSession.cpp (205416 => 205417)
--- trunk/Source/WebCore/html/MediaElementSession.cpp 2016-09-04 05:09:28 UTC (rev 205416)
+++ trunk/Source/WebCore/html/MediaElementSession.cpp 2016-09-04 05:45:10 UTC (rev 205417)
@@ -228,6 +228,11 @@
return false;
}
+ if (m_element.document().isMediaDocument()) {
+ LOG(Media, "MediaElementSession::canShowControlsManager - returning TRUE: Is media document");
+ return true;
+ }
+
if (m_element.document().activeDOMObjectsAreSuspended()) {
LOG(Media, "MediaElementSession::canShowControlsManager - returning FALSE: activeDOMObjectsAreSuspended()");
return false;
@@ -253,6 +258,11 @@
return false;
}
+ if (!m_element.hasEverNotifiedAboutPlaying()) {
+ LOG(Media, "MediaElementSession::canShowControlsManager - returning FALSE: Hasn't fired playing notification");
+ return false;
+ }
+
if (m_element.isVideo()) {
if (!m_element.renderer()) {
LOG(Media, "MediaElementSession::canShowControlsManager - returning FALSE: No renderer");
@@ -259,11 +269,6 @@
return false;
}
- if (m_element.document().isMediaDocument()) {
- LOG(Media, "MediaElementSession::canShowControlsManager - returning TRUE: Is media document");
- return true;
- }
-
if (!m_element.hasVideo()) {
LOG(Media, "MediaElementSession::canShowControlsManager - returning FALSE: No video");
return false;
Modified: trunk/Tools/ChangeLog (205416 => 205417)
--- trunk/Tools/ChangeLog 2016-09-04 05:09:28 UTC (rev 205416)
+++ trunk/Tools/ChangeLog 2016-09-04 05:45:10 UTC (rev 205417)
@@ -1,5 +1,35 @@
2016-09-03 Wenson Hsieh <[email protected]>
+ 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.
+
+ 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:
+
+2016-09-03 Wenson Hsieh <[email protected]>
+
Refactor the heuristic for showing media controls to take all media sessions into account
https://bugs.webkit.org/show_bug.cgi?id=161503
<rdar://problem/28033783>
Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (205416 => 205417)
--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj 2016-09-04 05:09:28 UTC (rev 205416)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj 2016-09-04 05:45:10 UTC (rev 205417)
@@ -64,6 +64,7 @@
2E1DFDED1D42A51100714A00 /* large-videos-with-audio.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 2E1DFDEC1D42A41C00714A00 /* large-videos-with-audio.html */; };
2E1DFDEF1D42A6F200714A00 /* large-videos-with-audio-autoplay.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 2E1DFDEE1D42A6EB00714A00 /* large-videos-with-audio-autoplay.html */; };
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 */; };
+ 2E54F40D1D7BC84200921ADF /* large-video-mutes-onplaying.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 2E54F40C1D7BC83900921ADF /* large-video-mutes-onplaying.html */; };
2E691AEA1D78B53600129407 /* large-videos-paused-video-hides-controls.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 2E691AE81D78B52B00129407 /* large-videos-paused-video-hides-controls.html */; };
2E691AEB1D78B53600129407 /* large-videos-playing-video-keeps-controls.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 2E691AE91D78B52B00129407 /* large-videos-playing-video-keeps-controls.html */; };
2E691AED1D78B91000129407 /* large-videos-playing-muted-video-hides-controls.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 2E691AEC1D78B90200129407 /* large-videos-playing-muted-video-hides-controls.html */; };
@@ -526,6 +527,7 @@
dstPath = TestWebKitAPI.resources;
dstSubfolderSpec = 7;
files = (
+ 2E54F40D1D7BC84200921ADF /* large-video-mutes-onplaying.html in Copy Resources */,
2E691AF31D79E75E00129407 /* large-video-playing-scroll-away.html in Copy Resources */,
2E691AF11D79E51A00129407 /* large-videos-autoplaying-scroll-to-video.html in Copy Resources */,
2E691AEF1D79DE8400129407 /* large-videos-autoplaying-click-to-pause.html in Copy Resources */,
@@ -755,6 +757,7 @@
2E1DFDEC1D42A41C00714A00 /* large-videos-with-audio.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "large-videos-with-audio.html"; sourceTree = "<group>"; };
2E1DFDEE1D42A6EB00714A00 /* large-videos-with-audio-autoplay.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "large-videos-with-audio-autoplay.html"; sourceTree = "<group>"; };
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>"; };
+ 2E54F40C1D7BC83900921ADF /* large-video-mutes-onplaying.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "large-video-mutes-onplaying.html"; sourceTree = "<group>"; };
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>"; };
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>"; };
2E691AEC1D78B90200129407 /* large-videos-playing-muted-video-hides-controls.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "large-videos-playing-muted-video-hides-controls.html"; sourceTree = "<group>"; };
@@ -1418,6 +1421,7 @@
A16F66B81C40E9E100BD4D24 /* Resources */ = {
isa = PBXGroup;
children = (
+ 2E54F40C1D7BC83900921ADF /* large-video-mutes-onplaying.html */,
2E691AF21D79E75400129407 /* large-video-playing-scroll-away.html */,
2E691AF01D79E51400129407 /* large-videos-autoplaying-scroll-to-video.html */,
2E691AEE1D79DE6F00129407 /* large-videos-autoplaying-click-to-pause.html */,
Modified: trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/VideoControlsManager.mm (205416 => 205417)
--- trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/VideoControlsManager.mm 2016-09-04 05:09:28 UTC (rev 205416)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/VideoControlsManager.mm 2016-09-04 05:45:10 UTC (rev 205417)
@@ -43,17 +43,14 @@
@end
-@interface MessageHandler : NSObject <WKScriptMessageHandler> {
+@interface MessageHandler : NSObject <WKScriptMessageHandler>
+@end
+
+@implementation MessageHandler {
dispatch_block_t _handler;
NSString *_message;
}
-- (instancetype)initWithMessage:(NSString *)message handler:(dispatch_block_t)handler;
-
-@end
-
-@implementation MessageHandler
-
- (instancetype)initWithMessage:(NSString *)message handler:(dispatch_block_t)handler
{
if (!(self = [super init]))
@@ -74,15 +71,6 @@
@end
@interface VideoControlsManagerTestWebView : WKWebView
-
-- (void)mouseDownAtPoint:(NSPoint)point;
-- (void)performAfterLoading:(dispatch_block_t)actions;
-- (void)loadTestPageNamed:(NSString *)pageName;
-- (void)loadTestPageNamed:(NSString *)pageName andExpectControlsManager:(BOOL)expectControlsManager afterReceivingMessage:(NSString *)message;
-- (void)performAfterReceivingMessage:(NSString *)message action:(dispatch_block_t)action;
-
-@property (nonatomic, readonly) NSString *controlledElementID;
-
@end
@implementation VideoControlsManagerTestWebView {
@@ -104,6 +92,12 @@
[contentController addScriptMessageHandler:handler name:@"onloadHandler"];
}
+- (void)callJavascriptFunction:(NSString *)functionName
+{
+ NSString *command = [NSString stringWithFormat:@"%@()", functionName];
+ [self evaluateJavaScript:command completionHandler:nil];
+}
+
- (void)loadTestPageNamed:(NSString *)pageName
{
NSURLRequest *request = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:pageName withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]];
@@ -110,7 +104,7 @@
[self loadRequest:request];
}
-- (void)loadTestPageNamed:(NSString *)pageName andExpectControlsManager:(BOOL)expectControlsManager afterReceivingMessage:(NSString *)message
+- (void)expectControlsManager:(BOOL)expectControlsManager afterReceivingMessage:(NSString *)message
{
__block bool doneWaiting = false;
[self performAfterReceivingMessage:message action:^ {
@@ -122,7 +116,6 @@
doneWaiting = true;
}];
- [self loadTestPageNamed:pageName];
TestWebKitAPI::Util::run(&doneWaiting);
}
@@ -129,9 +122,35 @@
- (void)performAfterReceivingMessage:(NSString *)message action:(dispatch_block_t)action
{
RetainPtr<MessageHandler> handler = adoptNS([[MessageHandler alloc] initWithMessage:message handler:action]);
- [[[self configuration] userContentController] addScriptMessageHandler:handler.get() name:@"playingHandler"];
+ WKUserContentController* contentController = [[self configuration] userContentController];
+ [contentController removeScriptMessageHandlerForName:@"playingHandler"];
+ [contentController addScriptMessageHandler:handler.get() name:@"playingHandler"];
}
+- (void)waitForPageToLoadWithAutoplayingVideos:(int)numberOfAutoplayingVideos
+{
+ __block int remainingAutoplayedCount = numberOfAutoplayingVideos;
+ __block bool autoplayingIsFinished = !numberOfAutoplayingVideos;
+ __block bool pageHasLoaded = false;
+
+ [self performAfterLoading:^()
+ {
+ pageHasLoaded = true;
+ }];
+
+ if (numberOfAutoplayingVideos) {
+ [self performAfterReceivingMessage:@"autoplayed" action:^()
+ {
+ remainingAutoplayedCount--;
+ if (remainingAutoplayedCount <= 0)
+ autoplayingIsFinished = true;
+ }];
+ }
+
+ TestWebKitAPI::Util::run(&pageHasLoaded);
+ TestWebKitAPI::Util::run(&autoplayingIsFinished);
+}
+
- (NSString *)controlledElementID
{
_isDoneQueryingControlledElementID = false;
@@ -167,7 +186,8 @@
// A large video with audio should have a controls manager even if it is played via script like this video.
// So the expectation is YES.
- [webView loadTestPageNamed:@"large-video-with-audio" andExpectControlsManager:YES afterReceivingMessage:@"playing"];
+ [webView loadTestPageNamed:@"large-video-with-audio"];
+ [webView expectControlsManager:YES afterReceivingMessage:@"playing"];
}
TEST(VideoControlsManager, VideoControlsManagerSingleSmallVideo)
@@ -176,7 +196,8 @@
// A small video will not have a controls manager unless it started playing because of a user gesture. Since this
// video is started with a script, the expectation is NO.
- [webView loadTestPageNamed:@"video-with-audio" andExpectControlsManager:NO afterReceivingMessage:@"playing"];
+ [webView loadTestPageNamed:@"video-with-audio"];
+ [webView expectControlsManager:NO afterReceivingMessage:@"playing"];
}
TEST(VideoControlsManager, VideoControlsManagerMultipleVideosWithAudio)
@@ -183,18 +204,10 @@
{
RetainPtr<VideoControlsManagerTestWebView*> webView = setUpWebViewForTestingVideoControlsManager(NSMakeRect(0, 0, 100, 100));
- __block BOOL didShowMediaControls;
- __block bool isDoneLoading = false;
-
- [webView performAfterLoading:^ {
- didShowMediaControls = [webView _hasActiveVideoForControlsManager];
- isDoneLoading = true;
- }];
-
[webView loadTestPageNamed:@"large-videos-with-audio"];
+ [webView waitForPageToLoadWithAutoplayingVideos:0];
- TestWebKitAPI::Util::run(&isDoneLoading);
- EXPECT_FALSE(didShowMediaControls);
+ EXPECT_FALSE([webView _hasActiveVideoForControlsManager]);
}
TEST(VideoControlsManager, VideoControlsManagerMultipleVideosWithAudioAndAutoplay)
@@ -201,18 +214,11 @@
{
RetainPtr<VideoControlsManagerTestWebView*> webView = setUpWebViewForTestingVideoControlsManager(NSMakeRect(0, 0, 100, 100));
- __block BOOL didShowMediaControls;
- __block bool isDoneLoading = false;
-
- [webView performAfterLoading:^ {
- didShowMediaControls = [webView _hasActiveVideoForControlsManager];
- isDoneLoading = true;
- }];
-
[webView loadTestPageNamed:@"large-videos-with-audio-autoplay"];
+ [webView waitForPageToLoadWithAutoplayingVideos:1];
- TestWebKitAPI::Util::run(&isDoneLoading);
- EXPECT_TRUE(didShowMediaControls);
+ EXPECT_TRUE([webView _hasActiveVideoForControlsManager]);
+ EXPECT_TRUE([[webView controlledElementID] isEqualToString:@"bar"]);
}
TEST(VideoControlsManager, VideoControlsManagerMultipleVideosScrollPausedVideoOutOfView)
@@ -219,7 +225,11 @@
{
RetainPtr<VideoControlsManagerTestWebView*> webView = setUpWebViewForTestingVideoControlsManager(NSMakeRect(0, 0, 500, 500));
- [webView loadTestPageNamed:@"large-videos-paused-video-hides-controls" andExpectControlsManager:NO afterReceivingMessage:@"paused"];
+ [webView loadTestPageNamed:@"large-videos-paused-video-hides-controls"];
+ [webView waitForPageToLoadWithAutoplayingVideos:1];
+
+ [webView callJavascriptFunction:@"pauseFirstVideoAndScrollToSecondVideo"];
+ [webView expectControlsManager:NO afterReceivingMessage:@"paused"];
}
TEST(VideoControlsManager, VideoControlsManagerMultipleVideosScrollPlayingVideoWithSoundOutOfView)
@@ -226,7 +236,11 @@
{
RetainPtr<VideoControlsManagerTestWebView*> webView = setUpWebViewForTestingVideoControlsManager(NSMakeRect(0, 0, 500, 500));
- [webView loadTestPageNamed:@"large-videos-playing-video-keeps-controls" andExpectControlsManager:YES afterReceivingMessage:@"playing"];
+ [webView loadTestPageNamed:@"large-videos-playing-video-keeps-controls"];
+ [webView waitForPageToLoadWithAutoplayingVideos:1];
+
+ [webView callJavascriptFunction:@"scrollToSecondVideo"];
+ [webView expectControlsManager:YES afterReceivingMessage:@"scrolled"];
}
TEST(VideoControlsManager, VideoControlsManagerMultipleVideosScrollPlayingMutedVideoOutOfView)
@@ -233,7 +247,11 @@
{
RetainPtr<VideoControlsManagerTestWebView*> webView = setUpWebViewForTestingVideoControlsManager(NSMakeRect(0, 0, 500, 500));
- [webView loadTestPageNamed:@"large-videos-playing-muted-video-hides-controls" andExpectControlsManager:NO afterReceivingMessage:@"playing"];
+ [webView loadTestPageNamed:@"large-videos-playing-muted-video-hides-controls"];
+ [webView waitForPageToLoadWithAutoplayingVideos:1];
+
+ [webView callJavascriptFunction:@"muteFirstVideoAndScrollToSecondVideo"];
+ [webView expectControlsManager:NO afterReceivingMessage:@"playing"];
}
TEST(VideoControlsManager, VideoControlsManagerMultipleVideosShowControlsForLastInteractedVideo)
@@ -241,25 +259,25 @@
RetainPtr<VideoControlsManagerTestWebView*> webView = setUpWebViewForTestingVideoControlsManager(NSMakeRect(0, 0, 800, 600));
NSPoint clickPoint = NSMakePoint(400, 300);
- [webView performAfterLoading:^ {
- [webView mouseDownAtPoint:clickPoint];
- }];
+ [webView loadTestPageNamed:@"large-videos-autoplaying-click-to-pause"];
+ [webView waitForPageToLoadWithAutoplayingVideos:2];
+ [webView mouseDownAtPoint:clickPoint];
+
__block bool firstVideoPaused = false;
__block bool secondVideoPaused = false;
[webView performAfterReceivingMessage:@"paused" action:^ {
NSString *controlledElementID = [webView controlledElementID];
if (firstVideoPaused) {
+ EXPECT_TRUE([controlledElementID isEqualToString:@"second"]);
secondVideoPaused = true;
- EXPECT_TRUE([controlledElementID isEqualToString:@"second"]);
} else {
+ EXPECT_TRUE([controlledElementID isEqualToString:@"first"]);
[webView mouseDownAtPoint:clickPoint];
- EXPECT_TRUE([controlledElementID isEqualToString:@"first"]);
}
firstVideoPaused = true;
}];
- [webView loadTestPageNamed:@"large-videos-autoplaying-click-to-pause"];
TestWebKitAPI::Util::run(&secondVideoPaused);
}
@@ -267,13 +285,12 @@
{
RetainPtr<VideoControlsManagerTestWebView*> webView = setUpWebViewForTestingVideoControlsManager(NSMakeRect(0, 0, 800, 600));
- __block bool scrolledSecondVideoIntoView = false;
[webView loadTestPageNamed:@"large-videos-autoplaying-scroll-to-video"];
- [webView performAfterReceivingMessage:@"scrolled" action:^ {
- scrolledSecondVideoIntoView = true;
- }];
+ [webView waitForPageToLoadWithAutoplayingVideos:2];
- TestWebKitAPI::Util::run(&scrolledSecondVideoIntoView);
+ [webView callJavascriptFunction:@"scrollToSecondView"];
+ [webView expectControlsManager:YES afterReceivingMessage:@"scrolled"];
+
EXPECT_TRUE([[webView controlledElementID] isEqualToString:@"second"]);
}
@@ -281,7 +298,10 @@
{
RetainPtr<VideoControlsManagerTestWebView*> webView = setUpWebViewForTestingVideoControlsManager(NSMakeRect(0, 0, 500, 500));
- [webView loadTestPageNamed:@"large-video-playing-scroll-away" andExpectControlsManager:YES afterReceivingMessage:@"scrolled"];
+ [webView loadTestPageNamed:@"large-video-playing-scroll-away"];
+ [webView waitForPageToLoadWithAutoplayingVideos:1];
+ [webView callJavascriptFunction:@"scrollVideoOutOfView"];
+ [webView expectControlsManager:YES afterReceivingMessage:@"scrolled"];
}
TEST(VideoControlsManager, VideoControlsManagerSingleSmallAutoplayingVideo)
@@ -288,11 +308,11 @@
{
RetainPtr<VideoControlsManagerTestWebView*> webView = setUpWebViewForTestingVideoControlsManager(NSMakeRect(0, 0, 100, 100));
- [webView performAfterLoading:^ {
- [webView mouseDownAtPoint:NSMakePoint(50, 50)];
- }];
+ [webView loadTestPageNamed:@"autoplaying-video-with-audio"];
+ [webView waitForPageToLoadWithAutoplayingVideos:1];
- [webView loadTestPageNamed:@"autoplaying-video-with-audio" andExpectControlsManager:YES afterReceivingMessage:@"paused"];
+ [webView mouseDownAtPoint:NSMakePoint(50, 50)];
+ [webView expectControlsManager:YES afterReceivingMessage:@"paused"];
}
TEST(VideoControlsManager, VideoControlsManagerLargeAutoplayingVideoSeeksAfterEnding)
@@ -300,7 +320,8 @@
RetainPtr<VideoControlsManagerTestWebView*> webView = setUpWebViewForTestingVideoControlsManager(NSMakeRect(0, 0, 100, 100));
// Since the video has ended, the expectation is NO even if the page programmatically seeks to the beginning.
- [webView loadTestPageNamed:@"large-video-seek-after-ending" andExpectControlsManager:NO afterReceivingMessage:@"ended"];
+ [webView loadTestPageNamed:@"large-video-seek-after-ending"];
+ [webView expectControlsManager:NO afterReceivingMessage:@"ended"];
}
TEST(VideoControlsManager, VideoControlsManagerLargeAutoplayingVideoSeeksAndPlaysAfterEnding)
@@ -308,7 +329,8 @@
RetainPtr<VideoControlsManagerTestWebView*> webView = setUpWebViewForTestingVideoControlsManager(NSMakeRect(0, 0, 100, 100));
// Since the video is still playing, the expectation is YES even if the video has ended once.
- [webView loadTestPageNamed:@"large-video-seek-to-beginning-and-play-after-ending" andExpectControlsManager:YES afterReceivingMessage:@"replaying"];
+ [webView loadTestPageNamed:@"large-video-seek-to-beginning-and-play-after-ending"];
+ [webView expectControlsManager:YES afterReceivingMessage:@"replaying"];
}
TEST(VideoControlsManager, VideoControlsManagerLargeAutoplayingVideoAfterSeekingToEnd)
@@ -315,13 +337,13 @@
{
RetainPtr<VideoControlsManagerTestWebView*> webView = setUpWebViewForTestingVideoControlsManager(NSMakeRect(0, 0, 100, 100));
- [webView performAfterLoading:^ {
- [webView mouseDownAtPoint:NSMakePoint(50, 50)];
- }];
+ [webView loadTestPageNamed:@"large-video-hides-controls-after-seek-to-end"];
+ [webView waitForPageToLoadWithAutoplayingVideos:1];
+ [webView mouseDownAtPoint:NSMakePoint(50, 50)];
// We expect there to be media controls, since this is a user gestured seek to the end.
// This is akin to seeking to the end by scrubbing in the controls.
- [webView loadTestPageNamed:@"large-video-hides-controls-after-seek-to-end" andExpectControlsManager:YES afterReceivingMessage:@"ended"];
+ [webView expectControlsManager:YES afterReceivingMessage:@"ended"];
}
TEST(VideoControlsManager, VideoControlsManagerSingleLargeVideoWithoutAudio)
@@ -330,7 +352,8 @@
// A large video with no audio will not have a controls manager unless it started playing because of a user gesture. Since this
// video is started with a script, the expectation is NO.
- [webView loadTestPageNamed:@"large-video-without-audio" andExpectControlsManager:NO afterReceivingMessage:@"playing"];
+ [webView loadTestPageNamed:@"large-video-without-audio"];
+ [webView expectControlsManager:NO afterReceivingMessage:@"playing"];
}
TEST(VideoControlsManager, VideoControlsManagerAudioElementStartedWithScript)
@@ -338,7 +361,8 @@
RetainPtr<VideoControlsManagerTestWebView*> webView = setUpWebViewForTestingVideoControlsManager(NSMakeRect(0, 0, 100, 100));
// An audio element MUST be started with a user gesture in order to have a controls manager, so the expectation is NO.
- [webView loadTestPageNamed:@"audio-only" andExpectControlsManager:NO afterReceivingMessage:@"playing"];
+ [webView loadTestPageNamed:@"audio-only"];
+ [webView expectControlsManager:NO afterReceivingMessage:@"playing"];
}
TEST(VideoControlsManager, VideoControlsManagerTearsDownMediaControlsOnDealloc)
@@ -383,7 +407,8 @@
{
RetainPtr<VideoControlsManagerTestWebView*> webView = setUpWebViewForTestingVideoControlsManager(NSMakeRect(0, 0, 1600, 800));
- [webView loadTestPageNamed:@"skinny-autoplaying-video-with-audio" andExpectControlsManager:NO afterReceivingMessage:@"playing"];
+ [webView loadTestPageNamed:@"skinny-autoplaying-video-with-audio"];
+ [webView expectControlsManager:NO afterReceivingMessage:@"playing"];
}
TEST(VideoControlsManager, VideoControlsManagerFullSizeVideoInWideMainFrame)
@@ -390,9 +415,18 @@
{
RetainPtr<VideoControlsManagerTestWebView*> webView = setUpWebViewForTestingVideoControlsManager(NSMakeRect(0, 0, 1600, 800));
- [webView loadTestPageNamed:@"full-size-autoplaying-video-with-audio" andExpectControlsManager:YES afterReceivingMessage:@"playing"];
+ [webView loadTestPageNamed:@"full-size-autoplaying-video-with-audio"];
+ [webView expectControlsManager:YES afterReceivingMessage:@"playing"];
}
+TEST(VideoControlsManager, VideoControlsManagerVideoMutesOnPlaying)
+{
+ RetainPtr<VideoControlsManagerTestWebView*> webView = setUpWebViewForTestingVideoControlsManager(NSMakeRect(0, 0, 500, 500));
+
+ [webView loadTestPageNamed:@"large-video-mutes-onplaying"];
+ [webView expectControlsManager:NO afterReceivingMessage:@"playing"];
+}
+
} // namespace TestWebKitAPI
#endif // WK_API_ENABLED && PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101200
Modified: trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/autoplaying-video-with-audio.html (205416 => 205417)
--- trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/autoplaying-video-with-audio.html 2016-09-04 05:09:28 UTC (rev 205416)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/autoplaying-video-with-audio.html 2016-09-04 05:45:10 UTC (rev 205417)
@@ -4,17 +4,8 @@
<script>
var timeout;
- function beginTest() {
- timeout = window.setTimeout(stillPlaying, 5000);
- window.addEventListener("mousedown", pauseVideo);
- try {
- window.webkit.messageHandlers.onloadHandler.postMessage('loaded');
- } catch(e) { }
- }
-
function pauseVideo() {
- document.getElementsByTagName('video')[0].pause();
- window.clearTimeout(timeout);
+ document.getElementsByTagName("video")[0].pause();
}
function handlePaused() {
@@ -21,20 +12,23 @@
// Wait until the next runloop to allow media controls to update.
setTimeout(function() {
try {
- window.webkit.messageHandlers.playingHandler.postMessage('paused');
+ window.webkit.messageHandlers.playingHandler.postMessage("paused");
} catch(e) { }
}, 0);
}
- function stillPlaying() {
- try {
- window.webkit.messageHandlers.playingHandler.postMessage('playing');
- } catch(e) { }
+ function beganAutoplaying() {
+ setTimeout(function() {
+ try {
+ window.webkit.messageHandlers.playingHandler.postMessage("autoplayed");
+ } catch(e) {
+ }
+ }, 0)
}
</script>
</head>
-<body _onload_="beginTest()">
- <video controls autoplay src="" webkit-playsinline _onpause_="handlePaused()"></video>
+<body _onmousedown_=pauseVideo()>
+ <video autoplay controls _onplaying_=beganAutoplaying() src="" webkit-playsinline _onpause_=handlePaused()></video>
</body>
</html>
Modified: trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/large-video-hides-controls-after-seek-to-end.html (205416 => 205417)
--- trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/large-video-hides-controls-after-seek-to-end.html 2016-09-04 05:09:28 UTC (rev 205416)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/large-video-hides-controls-after-seek-to-end.html 2016-09-04 05:45:10 UTC (rev 205417)
@@ -23,9 +23,18 @@
} catch(e) { }
}
+ function beganAutoplaying() {
+ setTimeout(function() {
+ try {
+ window.webkit.messageHandlers.playingHandler.postMessage("autoplayed");
+ } catch(e) {
+ }
+ }, 0)
+ }
+
</script>
</head>
<body _onmousedown_=seekToEnd() _onload_=beginTest()>
- <video autoplay _onended_=handleEnded() src="" webkit-playsinline style="width: 800px; height: 600px;"></video>
+ <video autoplay _onplaying_=beganAutoplaying() _onended_=handleEnded() src="" webkit-playsinline style="width: 800px; height: 600px;"></video>
</body>
</html>
Added: trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/large-video-mutes-onplaying.html (0 => 205417)
--- trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/large-video-mutes-onplaying.html (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/large-video-mutes-onplaying.html 2016-09-04 05:45:10 UTC (rev 205417)
@@ -0,0 +1,16 @@
+<html>
+<head>
+<script>
+ function handlePlaying() {
+ try {
+ window.webkit.messageHandlers.playingHandler.postMessage("playing");
+ } catch(e) {
+ }
+ document.querySelector("video").muted = true;
+ }
+</script>
+</head>
+<body>
+ <video autoplay src="" width=640 height=480 _onplaying_=handlePlaying()></video>
+</body>
+</html>
Modified: trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/large-video-playing-scroll-away.html (205416 => 205417)
--- trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/large-video-playing-scroll-away.html 2016-09-04 05:09:28 UTC (rev 205416)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/large-video-playing-scroll-away.html 2016-09-04 05:45:10 UTC (rev 205417)
@@ -11,16 +11,25 @@
}
</style>
<script>
- function handleLoaded() {
+ function scrollVideoOutOfView() {
document.querySelector("div").scrollIntoView();
setTimeout(function() {
window.webkit.messageHandlers.playingHandler.postMessage("scrolled");
}, 0);
}
+
+ function beganAutoplaying() {
+ setTimeout(function() {
+ try {
+ window.webkit.messageHandlers.playingHandler.postMessage("autoplayed");
+ } catch(e) {
+ }
+ }, 0)
+ }
</script>
</head>
- <body _onload_=handleLoaded()>
- <video autoplay loop id="first" src=""
+ <body>
+ <video autoplay _onplaying_=beganAutoplaying() loop id="first" src=""
<br>
<div>hello world!</div>
</body>
Modified: trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/large-videos-autoplaying-click-to-pause.html (205416 => 205417)
--- trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/large-videos-autoplaying-click-to-pause.html 2016-09-04 05:09:28 UTC (rev 205416)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/large-videos-autoplaying-click-to-pause.html 2016-09-04 05:45:10 UTC (rev 205417)
@@ -29,10 +29,19 @@
} catch(e) { }
}, 0);
}
+
+ function beganAutoplaying() {
+ setTimeout(function() {
+ try {
+ window.webkit.messageHandlers.playingHandler.postMessage("autoplayed");
+ } catch(e) {
+ }
+ }, 0)
+ }
</script>
</head>
<body _onmousedown_=handleMouseDown()>
- <video autoplay loop id="first" src="" _onpause_=handleFirstPause()></video>
- <video autoplay loop id="second" src="" _onpause_=handleSecondPause()></video>
+ <video autoplay _onplaying_=beganAutoplaying() loop id="first" src="" _onpause_=handleFirstPause()></video>
+ <video autoplay _onplaying_=beganAutoplaying() loop id="second" src="" _onpause_=handleSecondPause()></video>
</body>
<html>
Modified: trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/large-videos-autoplaying-scroll-to-video.html (205416 => 205417)
--- trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/large-videos-autoplaying-scroll-to-video.html 2016-09-04 05:09:28 UTC (rev 205416)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/large-videos-autoplaying-scroll-to-video.html 2016-09-04 05:45:10 UTC (rev 205417)
@@ -11,17 +11,25 @@
}
</style>
<script>
- function handleLoaded() {
+ function scrollToSecondView() {
document.querySelector("#second").scrollIntoView();
setTimeout(function() {
window.webkit.messageHandlers.playingHandler.postMessage("scrolled");
}, 0);
}
+ function beganAutoplaying() {
+ setTimeout(function() {
+ try {
+ window.webkit.messageHandlers.playingHandler.postMessage("autoplayed");
+ } catch(e) {
+ }
+ }, 0)
+ }
</script>
</head>
- <body _onload_=handleLoaded()>
- <video autoplay loop id="first" src=""
+ <body>
+ <video autoplay _onplaying_=beganAutoplaying() loop id="first" src=""
<br>
- <video autoplay loop id="second" src=""
+ <video autoplay _onplaying_=beganAutoplaying() loop id="second" src=""
</body>
<html>
Modified: trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/large-videos-paused-video-hides-controls.html (205416 => 205417)
--- trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/large-videos-paused-video-hides-controls.html 2016-09-04 05:09:28 UTC (rev 205416)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/large-videos-paused-video-hides-controls.html 2016-09-04 05:45:10 UTC (rev 205417)
@@ -10,7 +10,7 @@
}
</style>
<script>
- function handleLoaded() {
+ function pauseFirstVideoAndScrollToSecondVideo() {
document.querySelector("#bar").scrollIntoView();
document.querySelector("#foo").pause();
}
@@ -21,9 +21,17 @@
} catch(e) { }
}, 0);
}
+ function beganAutoplaying() {
+ setTimeout(function() {
+ try {
+ window.webkit.messageHandlers.playingHandler.postMessage("autoplayed");
+ } catch(e) {
+ }
+ }, 0)
+ }
</script>
-<body _onload_=handleLoaded()>
- <video autoplay loop id="foo" _onpause_=handlePaused()><source src=""
+<body>
+ <video autoplay _onplaying_=beganAutoplaying() loop id="foo" _onpause_=handlePaused()><source src=""
<br>
<video id="bar"><source src=""
</body>
Modified: trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/large-videos-playing-muted-video-hides-controls.html (205416 => 205417)
--- trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/large-videos-playing-muted-video-hides-controls.html 2016-09-04 05:09:28 UTC (rev 205416)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/large-videos-playing-muted-video-hides-controls.html 2016-09-04 05:45:10 UTC (rev 205417)
@@ -10,7 +10,7 @@
}
</style>
<script>
- function handleLoaded() {
+ function muteFirstVideoAndScrollToSecondVideo() {
document.querySelector("#foo").muted = true;
document.querySelector("#bar").scrollIntoView();
setTimeout(function() {
@@ -19,9 +19,17 @@
} catch(e) { }
}, 0);
}
+ function beganAutoplaying() {
+ setTimeout(function() {
+ try {
+ window.webkit.messageHandlers.playingHandler.postMessage("autoplayed");
+ } catch(e) {
+ }
+ }, 0)
+ }
</script>
-<body _onload_=handleLoaded()>
- <video autoplay loop id="foo"><source src=""
+<body>
+ <video autoplay _onplaying_=beganAutoplaying() loop id="foo"><source src=""
<br>
<video id="bar"><source src=""
</body>
Modified: trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/large-videos-playing-video-keeps-controls.html (205416 => 205417)
--- trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/large-videos-playing-video-keeps-controls.html 2016-09-04 05:09:28 UTC (rev 205416)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/large-videos-playing-video-keeps-controls.html 2016-09-04 05:45:10 UTC (rev 205417)
@@ -10,17 +10,25 @@
}
</style>
<script>
- function handleLoaded() {
+ function scrollToSecondVideo() {
document.querySelector("#bar").scrollIntoView();
setTimeout(function() {
try {
- window.webkit.messageHandlers.playingHandler.postMessage("playing");
+ window.webkit.messageHandlers.playingHandler.postMessage("scrolled");
} catch(e) { }
}, 0);
}
+ function beganAutoplaying() {
+ setTimeout(function() {
+ try {
+ window.webkit.messageHandlers.playingHandler.postMessage("autoplayed");
+ } catch(e) {
+ }
+ }, 0)
+ }
</script>
-<body _onload_=handleLoaded()>
- <video autoplay loop id="foo"><source src=""
+<body>
+ <video autoplay _onplaying_=beganAutoplaying() loop id="foo"><source src=""
<br>
<video id="bar"><source src=""
</body>
Modified: trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/large-videos-with-audio-autoplay.html (205416 => 205417)
--- trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/large-videos-with-audio-autoplay.html 2016-09-04 05:09:28 UTC (rev 205416)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/large-videos-with-audio-autoplay.html 2016-09-04 05:45:10 UTC (rev 205417)
@@ -1,18 +1,18 @@
<!DOCTYPE html>
<html>
<script>
- function handleLoaded() {
- // The media controls should be updated on the next runloop.
+ function beganAutoplaying() {
setTimeout(function() {
try {
- window.webkit.messageHandlers.onloadHandler.postMessage("loaded");
- } catch(e) { }
- }, 0);
+ window.webkit.messageHandlers.playingHandler.postMessage("autoplayed");
+ } catch(e) {
+ }
+ }, 0)
}
</script>
-<body _onload_=handleLoaded()>
+<body>
<video id="foo" style="width: 480px; height: 320px;"><source src=""
- <video autoplay id="bar" style="width: 480px; height: 320px;"><source src=""
+ <video autoplay _onplaying_=beganAutoplaying() id="bar" style="width: 480px; height: 320px;"><source src=""
<video id="baz" style="width: 480px; height: 320px;"><source src=""
</body>
<html>