Title: [200403] trunk
Revision
200403
Author
[email protected]
Date
2016-05-03 18:46:30 -0700 (Tue, 03 May 2016)

Log Message

Add VideoControlsManager tests
https://bugs.webkit.org/show_bug.cgi?id=157332
-and corresponding-
rdar://problem/24358431

Reviewed by Sam Weinig.

Source/WebKit2:

Expose _hasActiveVideoForControlsManager on WKWebViewPrivate for the sake of 
testing. 
* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView _hasActiveVideoForControlsManager]):
(-[WKWebView _doAfterNextPresentationUpdate:]):
* UIProcess/API/Cocoa/WKWebViewPrivate.h:

Tools:

This patch adds three VideoControlsManager tests.

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WebKit/ios/video-with-audio.html:
* TestWebKitAPI/Tests/WebKit2Cocoa/VideoControlsManager.mm: Added.
(-[DidPlayMessageHandler initWithWKWebView:]):
(-[DidPlayMessageHandler userContentController:didReceiveScriptMessage:]):
(TestWebKitAPI::TEST):
* TestWebKitAPI/Tests/WebKit2Cocoa/large-video-with-audio.html: Added.
* TestWebKitAPI/Tests/WebKit2Cocoa/large-video-with-audio.mp4: Added.
* TestWebKitAPI/Tests/WebKit2Cocoa/large-video-without-audio.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (200402 => 200403)


--- trunk/Source/WebKit2/ChangeLog	2016-05-04 01:21:38 UTC (rev 200402)
+++ trunk/Source/WebKit2/ChangeLog	2016-05-04 01:46:30 UTC (rev 200403)
@@ -1,3 +1,19 @@
+2016-05-03  Beth Dakin  <[email protected]>
+
+        Add VideoControlsManager tests
+        https://bugs.webkit.org/show_bug.cgi?id=157332
+        -and corresponding-
+        rdar://problem/24358431
+
+        Reviewed by Sam Weinig.
+
+        Expose _hasActiveVideoForControlsManager on WKWebViewPrivate for the sake of 
+        testing. 
+        * UIProcess/API/Cocoa/WKWebView.mm:
+        (-[WKWebView _hasActiveVideoForControlsManager]):
+        (-[WKWebView _doAfterNextPresentationUpdate:]):
+        * UIProcess/API/Cocoa/WKWebViewPrivate.h:
+
 2016-05-03  Jer Noble  <[email protected]>
 
         [iOS][WK2] Allow WKWebView to play local filesystem media when created with -loadFileURL:allowingReadAccessToURL:

Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm (200402 => 200403)


--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm	2016-05-04 01:21:38 UTC (rev 200402)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm	2016-05-04 01:46:30 UTC (rev 200403)
@@ -4348,6 +4348,13 @@
 
 #endif // PLATFORM(IOS)
 
+#if PLATFORM(MAC)
+- (BOOL)_hasActiveVideoForControlsManager
+{
+    return _page && _page->hasActiveVideoForControlsManager();
+}
+#endif // PLATFORM(MAC)
+
 // Execute the supplied block after the next transaction from the WebProcess.
 - (void)_doAfterNextPresentationUpdate:(void (^)(void))updateBlock
 {

Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewPrivate.h (200402 => 200403)


--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewPrivate.h	2016-05-04 01:21:38 UTC (rev 200402)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewPrivate.h	2016-05-04 01:46:30 UTC (rev 200403)
@@ -252,6 +252,10 @@
 - (CGPoint)_convertPointFromViewToContents:(CGPoint)point WK_AVAILABLE(WK_MAC_TBA, WK_IOS_TBA);
 #endif
 
+#if !TARGET_OS_IPHONE
+@property (nonatomic, readonly) BOOL _hasActiveVideoForControlsManager WK_AVAILABLE(WK_MAC_TBA, NA);
+#endif
+
 - (void)_doAfterNextPresentationUpdate:(void (^)(void))updateBlock WK_AVAILABLE(WK_MAC_TBA, WK_IOS_TBA);
 
 @end

Modified: trunk/Tools/ChangeLog (200402 => 200403)


--- trunk/Tools/ChangeLog	2016-05-04 01:21:38 UTC (rev 200402)
+++ trunk/Tools/ChangeLog	2016-05-04 01:46:30 UTC (rev 200403)
@@ -1,3 +1,24 @@
+2016-05-03  Beth Dakin  <[email protected]>
+
+        Add VideoControlsManager tests
+        https://bugs.webkit.org/show_bug.cgi?id=157332
+        -and corresponding-
+        rdar://problem/24358431
+
+        Reviewed by Sam Weinig.
+
+        This patch adds three VideoControlsManager tests.
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        * TestWebKitAPI/Tests/WebKit/ios/video-with-audio.html:
+        * TestWebKitAPI/Tests/WebKit2Cocoa/VideoControlsManager.mm: Added.
+        (-[DidPlayMessageHandler initWithWKWebView:]):
+        (-[DidPlayMessageHandler userContentController:didReceiveScriptMessage:]):
+        (TestWebKitAPI::TEST):
+        * TestWebKitAPI/Tests/WebKit2Cocoa/large-video-with-audio.html: Added.
+        * TestWebKitAPI/Tests/WebKit2Cocoa/large-video-with-audio.mp4: Added.
+        * TestWebKitAPI/Tests/WebKit2Cocoa/large-video-without-audio.html: Added.
+
 2016-05-03  Joanmarie Diggs  <[email protected]>
 
         [ATK] accessibility/document-attributes.html is failing

Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (200402 => 200403)


--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2016-05-04 01:21:38 UTC (rev 200402)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2016-05-04 01:46:30 UTC (rev 200403)
@@ -293,8 +293,12 @@
 		83CF1C301C4F1B8B00688447 /* StringUtilities.mm in Sources */ = {isa = PBXBuildFile; fileRef = 83CF1C2C1C4F19AE00688447 /* StringUtilities.mm */; };
 		930AD402150698D00067970F /* lots-of-text.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 930AD401150698B30067970F /* lots-of-text.html */; };
 		9361002914DC95A70061379D /* lots-of-iframes.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 9361002814DC957B0061379D /* lots-of-iframes.html */; };
+		93625D271CD9741C006DC1F1 /* large-video-without-audio.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 93625D261CD973AF006DC1F1 /* large-video-without-audio.html */; };
+		936F72801CD7D9EC0068A0FB /* large-video-with-audio.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 936F727E1CD7D9D00068A0FB /* large-video-with-audio.html */; };
+		936F72811CD7D9EC0068A0FB /* large-video-with-audio.mp4 in Copy Resources */ = {isa = PBXBuildFile; fileRef = 936F727F1CD7D9D00068A0FB /* large-video-with-audio.mp4 */; };
 		93AF4ECE1506F064007FD57E /* NewFirstVisuallyNonEmptyLayoutForImages_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 93AF4ECD1506F064007FD57E /* NewFirstVisuallyNonEmptyLayoutForImages_Bundle.cpp */; };
 		93AF4ED11506F130007FD57E /* lots-of-images.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 93AF4ECF1506F123007FD57E /* lots-of-images.html */; };
+		93E943F21CD3E87E00AC08C2 /* VideoControlsManager.mm in Sources */ = {isa = PBXBuildFile; fileRef = 93E943F11CD3E87E00AC08C2 /* VideoControlsManager.mm */; };
 		93F1DB3414DA20870024C362 /* NewFirstVisuallyNonEmptyLayout_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 93F1DB3314DA20870024C362 /* NewFirstVisuallyNonEmptyLayout_Bundle.cpp */; };
 		93F1DB5714DB1B840024C362 /* NewFirstVisuallyNonEmptyLayoutFails_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 93F1DB5614DB1B840024C362 /* NewFirstVisuallyNonEmptyLayoutFails_Bundle.cpp */; };
 		93F7E86F14DC8E5C00C84A99 /* NewFirstVisuallyNonEmptyLayoutFrames_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 93F7E86E14DC8E5B00C84A99 /* NewFirstVisuallyNonEmptyLayoutFrames_Bundle.cpp */; };
@@ -417,6 +421,9 @@
 			dstPath = TestWebKitAPI.resources;
 			dstSubfolderSpec = 7;
 			files = (
+				93625D271CD9741C006DC1F1 /* large-video-without-audio.html in Copy Resources */,
+				936F72801CD7D9EC0068A0FB /* large-video-with-audio.html in Copy Resources */,
+				936F72811CD7D9EC0068A0FB /* large-video-with-audio.mp4 in Copy Resources */,
 				536770361CC81B6100D425B1 /* WebScriptObjectDescription.html in Copy Resources */,
 				57901FB11CAF142D00ED64F9 /* LoadInvalidURLRequest.html in Copy Resources */,
 				5714ECBD1CA8C22A00051AC8 /* DownloadRequestOriginalURL2.html in Copy Resources */,
@@ -719,6 +726,9 @@
 		930AD401150698B30067970F /* lots-of-text.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "lots-of-text.html"; sourceTree = "<group>"; };
 		9331407B17B4419000F083B1 /* DidNotHandleKeyDown.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DidNotHandleKeyDown.cpp; sourceTree = "<group>"; };
 		9361002814DC957B0061379D /* lots-of-iframes.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "lots-of-iframes.html"; sourceTree = "<group>"; };
+		93625D261CD973AF006DC1F1 /* large-video-without-audio.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "large-video-without-audio.html"; sourceTree = "<group>"; };
+		936F727E1CD7D9D00068A0FB /* large-video-with-audio.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "large-video-with-audio.html"; sourceTree = "<group>"; };
+		936F727F1CD7D9D00068A0FB /* large-video-with-audio.mp4 */ = {isa = PBXFileReference; lastKnownFileType = file; path = "large-video-with-audio.mp4"; sourceTree = "<group>"; };
 		939BA91614103412001A01BD /* DeviceScaleFactorOnBack.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DeviceScaleFactorOnBack.mm; sourceTree = "<group>"; };
 		939BFE3918E5548900883275 /* StringTruncator.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = StringTruncator.mm; sourceTree = "<group>"; };
 		93A427A8180D9B0700CD24D7 /* RefPtr.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RefPtr.cpp; sourceTree = "<group>"; };
@@ -733,6 +743,7 @@
 		93AF4ECF1506F123007FD57E /* lots-of-images.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "lots-of-images.html"; sourceTree = "<group>"; };
 		93D3D19B17B1A7B000C7C415 /* all-content-in-one-iframe.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "all-content-in-one-iframe.html"; sourceTree = "<group>"; };
 		93D3D19D17B1A84200C7C415 /* LayoutMilestonesWithAllContentInFrame.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = LayoutMilestonesWithAllContentInFrame.cpp; sourceTree = "<group>"; };
+		93E943F11CD3E87E00AC08C2 /* VideoControlsManager.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = VideoControlsManager.mm; sourceTree = "<group>"; };
 		93F1DB3014DA20760024C362 /* NewFirstVisuallyNonEmptyLayout.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = NewFirstVisuallyNonEmptyLayout.cpp; sourceTree = "<group>"; };
 		93F1DB3314DA20870024C362 /* NewFirstVisuallyNonEmptyLayout_Bundle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = NewFirstVisuallyNonEmptyLayout_Bundle.cpp; sourceTree = "<group>"; };
 		93F1DB5414DB1B730024C362 /* NewFirstVisuallyNonEmptyLayoutFails.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = NewFirstVisuallyNonEmptyLayoutFails.cpp; sourceTree = "<group>"; };
@@ -1052,6 +1063,7 @@
 				CD9E292B1C90A71F000BB800 /* RequiresUserActionForPlayback.mm */,
 				37BCA61B1B596BA9002012CA /* ShouldOpenExternalURLsInNewWindowActions.mm */,
 				2D9A53AE1B31FA8D0074D5AA /* ShrinkToFit.mm */,
+				93E943F11CD3E87E00AC08C2 /* VideoControlsManager.mm */,
 				7CC3E1FA197E234100BE6252 /* UserContentController.mm */,
 				7C882E031C80C624006BF731 /* UserContentWorld.mm */,
 				7C882E041C80C624006BF731 /* UserContentWorldPlugIn.mm */,
@@ -1141,6 +1153,9 @@
 				51BCEE4D1C84F52C0042C82E /* IndexedDBMultiProcess-2.html */,
 				51B1EE941C80FADD0064FB98 /* IndexedDBPersistence-1.html */,
 				51B1EE951C80FADD0064FB98 /* IndexedDBPersistence-2.html */,
+				936F727E1CD7D9D00068A0FB /* large-video-with-audio.html */,
+				936F727F1CD7D9D00068A0FB /* large-video-with-audio.mp4 */,
+				93625D261CD973AF006DC1F1 /* large-video-without-audio.html */,
 			);
 			name = Resources;
 			sourceTree = "<group>";
@@ -1973,6 +1988,7 @@
 				1CB9BC381A67482300FE5678 /* WeakPtr.cpp in Sources */,
 				2E7765CD16C4D80A00BA2BB1 /* mainIOS.mm in Sources */,
 				2D8104CC1BEC13E70020DA46 /* FindInPage.mm in Sources */,
+				93E943F21CD3E87E00AC08C2 /* VideoControlsManager.mm in Sources */,
 				5798E2B01CAF5C2800C5CBA0 /* ProvisionalURLNotChange.mm in Sources */,
 				CD225C081C45A69200140761 /* ParsedContentRange.cpp in Sources */,
 				41973B5D1AF22875006C7B36 /* SharedBuffer.cpp in Sources */,

Added: trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/VideoControlsManager.mm (0 => 200403)


--- trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/VideoControlsManager.mm	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/VideoControlsManager.mm	2016-05-04 01:46:30 UTC (rev 200403)
@@ -0,0 +1,158 @@
+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+
+#import "PlatformUtilities.h"
+#import <WebKit/WKWebViewConfigurationPrivate.h>
+#import <WebKit/WKWebViewPrivate.h>
+#import <wtf/RetainPtr.h>
+
+#if WK_API_ENABLED && PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101200
+
+static bool testedControlsManagerAfterPlaying;
+static bool receivedScriptMessage;
+
+@interface DidPlayMessageHandler : NSObject <WKScriptMessageHandler> {
+    RetainPtr<WKWebView> _webView;
+}
+
+@property (nonatomic) BOOL expectedToHaveControlsManager;
+
+- (instancetype)initWithWKWebView:(WKWebView*)webView;
+@end
+
+@implementation DidPlayMessageHandler
+
+- (instancetype)initWithWKWebView:(WKWebView*)webView
+{
+    if (!(self = [super init]))
+        return nil;
+
+    _webView = webView;
+
+    return self;
+}
+
+- (void)userContentController:(WKUserContentController *)userContentController didReceiveScriptMessage:(WKScriptMessage *)message
+{
+    receivedScriptMessage = true;
+
+    NSString *bodyString = (NSString *)[message body];
+    if ([bodyString isEqualToString:@"playing"]) {
+        BOOL hasControlsManager = [_webView _hasActiveVideoForControlsManager];
+        if (self.expectedToHaveControlsManager)
+            EXPECT_TRUE(hasControlsManager);
+        else
+            EXPECT_FALSE(hasControlsManager);
+        testedControlsManagerAfterPlaying = true;
+    }
+}
+@end
+
+namespace TestWebKitAPI {
+
+TEST(VideoControlsManager, VideoControlsManagerSingleLargeVideo)
+{
+    RetainPtr<WKWebViewConfiguration> configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+    RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 100, 100) configuration:configuration.get()]);
+    RetainPtr<DidPlayMessageHandler> handler = adoptNS([[DidPlayMessageHandler alloc] initWithWKWebView:webView.get()]);
+    [[configuration userContentController] addScriptMessageHandler:handler.get() name:@"playingHandler"];
+
+    RetainPtr<NSWindow> window = adoptNS([[NSWindow alloc] initWithContentRect:[webView frame] styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:NO]);
+    [[window contentView] addSubview:webView.get()];
+
+    // 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.
+    [handler setExpectedToHaveControlsManager:YES];
+    NSURLRequest *request = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"large-video-with-audio" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]];
+    [webView loadRequest:request];
+
+    TestWebKitAPI::Util::run(&testedControlsManagerAfterPlaying);
+    TestWebKitAPI::Util::run(&receivedScriptMessage);
+}
+
+TEST(VideoControlsManager, VideoControlsManagerSingleSmallVideo)
+{
+    RetainPtr<WKWebViewConfiguration> configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+    RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 100, 100) configuration:configuration.get()]);
+    RetainPtr<DidPlayMessageHandler> handler = adoptNS([[DidPlayMessageHandler alloc] initWithWKWebView:webView.get()]);
+    [[configuration userContentController] addScriptMessageHandler:handler.get() name:@"playingHandler"];
+
+    RetainPtr<NSWindow> window = adoptNS([[NSWindow alloc] initWithContentRect:[webView frame] styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:NO]);
+    [[window contentView] addSubview:webView.get()];
+
+    // 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.
+    [handler setExpectedToHaveControlsManager:NO];
+    NSURLRequest *request = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"video-with-audio" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]];
+    [webView loadRequest:request];
+
+    TestWebKitAPI::Util::run(&testedControlsManagerAfterPlaying);
+    TestWebKitAPI::Util::run(&receivedScriptMessage);
+}
+
+TEST(VideoControlsManager, VideoControlsManagerSingleLargeVideoWithoutAudio)
+{
+    RetainPtr<WKWebViewConfiguration> configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+    RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 100, 100) configuration:configuration.get()]);
+    RetainPtr<DidPlayMessageHandler> handler = adoptNS([[DidPlayMessageHandler alloc] initWithWKWebView:webView.get()]);
+    [[configuration userContentController] addScriptMessageHandler:handler.get() name:@"playingHandler"];
+
+    RetainPtr<NSWindow> window = adoptNS([[NSWindow alloc] initWithContentRect:[webView frame] styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:NO]);
+    [[window contentView] addSubview:webView.get()];
+
+    // 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.
+    [handler setExpectedToHaveControlsManager:NO];
+    NSURLRequest *request = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"large-video-without-audio" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]];
+    [webView loadRequest:request];
+
+    TestWebKitAPI::Util::run(&testedControlsManagerAfterPlaying);
+    TestWebKitAPI::Util::run(&receivedScriptMessage);
+}
+
+TEST(VideoControlsManager, VideoControlsManagerAudioElementStartedWithScript)
+{
+    RetainPtr<WKWebViewConfiguration> configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+    RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 100, 100) configuration:configuration.get()]);
+    RetainPtr<DidPlayMessageHandler> handler = adoptNS([[DidPlayMessageHandler alloc] initWithWKWebView:webView.get()]);
+    [[configuration userContentController] addScriptMessageHandler:handler.get() name:@"playingHandler"];
+
+    RetainPtr<NSWindow> window = adoptNS([[NSWindow alloc] initWithContentRect:[webView frame] styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:NO]);
+    [[window contentView] addSubview:webView.get()];
+
+    // An audio element MUST be started with a user gesture in order to have a controls manager, so the expectation is NO.
+    [handler setExpectedToHaveControlsManager:NO];
+    NSURLRequest *request = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"audio-only" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]];
+    [webView loadRequest:request];
+
+    TestWebKitAPI::Util::run(&testedControlsManagerAfterPlaying);
+    TestWebKitAPI::Util::run(&receivedScriptMessage);
+}
+
+} // namespace TestWebKitAPI
+
+#endif // WK_API_ENABLED && PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101200

Added: trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/large-video-with-audio.html (0 => 200403)


--- trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/large-video-with-audio.html	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/large-video-with-audio.html	2016-05-04 01:46:30 UTC (rev 200403)
@@ -0,0 +1,32 @@
+<html>
+<head>
+<script>
+    var timeout;
+
+    function go() {
+        var video = document.getElementsByTagName('video')[0];
+        timeout = window.setTimeout(notPlaying, 250);
+        video.addEventListener('playing', playing);
+        video.play();
+    }
+
+    function playing() {
+        window.clearTimeout(timeout);
+        try {
+            window.webkit.messageHandlers.playingHandler.postMessage('playing');
+        } catch(e) {
+            window.location = 'callback:playing';
+        }
+    }
+
+    function notPlaying() {
+        try {
+            window.webkit.messageHandlers.playingHandler.postMessage('not playing');
+        } catch(e) { }
+    }
+</script>
+</head>
+<body _onload_="go()">
+    <video id="test-video" src="" controls width=640 height=480></video>
+</body>
+</html>

Added: trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/large-video-with-audio.mp4


(Binary files differ)
Property changes on: trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/large-video-with-audio.mp4 ___________________________________________________________________

Added: svn:mime-type

Added: trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/large-video-without-audio.html (0 => 200403)


--- trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/large-video-without-audio.html	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/large-video-without-audio.html	2016-05-04 01:46:30 UTC (rev 200403)
@@ -0,0 +1,32 @@
+<html>
+<head>
+<script>
+    var timeout;
+
+    function go() {
+        var video = document.getElementsByTagName('video')[0];
+        timeout = window.setTimeout(notPlaying, 250);
+        video.addEventListener('playing', playing);
+        video.play();
+    }
+
+    function playing() {
+        window.clearTimeout(timeout);
+        try {
+            window.webkit.messageHandlers.playingHandler.postMessage('playing');
+        } catch(e) {
+            window.location = 'callback:playing';
+        }
+    }
+
+    function notPlaying() {
+        try {
+            window.webkit.messageHandlers.playingHandler.postMessage('not playing');
+        } catch(e) { }
+    }
+</script>
+</head>
+<body _onload_="go()">
+    <video id="test-video" src="" controls width=640 height=480></video>
+</body>
+</html>
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to