Source/WebKit2:
authoradachan@apple.com <adachan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 8 Oct 2014 18:20:12 +0000 (18:20 +0000)
committeradachan@apple.com <adachan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 8 Oct 2014 18:20:12 +0000 (18:20 +0000)
Implement WKPageIsPlayingAudio().
https://bugs.webkit.org/show_bug.cgi?id=137048

Reviewed by Darin Adler.

* UIProcess/API/C/WKPage.cpp:
(WKPageIsPlayingAudio):

Tools:
Add a test for WKPageIsPlayingAudio().
https://bugs.webkit.org/show_bug.cgi?id=137048

Reviewed by Darin Adler.

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
Add file-with-video.html, test.mp4, and WKPageIsPlayingAudio.cpp to the project.
* TestWebKitAPI/Tests/WebKit2/WKPageIsPlayingAudio.cpp: Added.
(TestWebKitAPI::nullJavaScriptCallback):
(TestWebKitAPI::didFinishLoadForFrame):
(TestWebKitAPI::isPlayingAudioDidChangeCallback):
(TestWebKitAPI::setUpClients):
(TestWebKitAPI::TEST):
This test loads a page with a video in it. When the page is loaded, we first check that
WKPageIsPlayingAudio() returns false for the page. Then we call a method to start the video.
When the WKPageUIClient::isPlayingAudioDidChange callback gets called, check that WKPageIsPlayingAudio()
now returns true for the page.
* TestWebKitAPI/Tests/WebKit2/file-with-video.html: Added.
* TestWebKitAPI/Tests/WebKit2/test.mp4: Added.
This is a video copied from LayoutTests/media/content.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@174463 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/API/C/WKPage.cpp
Tools/ChangeLog
Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
Tools/TestWebKitAPI/Tests/WebKit2/WKPageIsPlayingAudio.cpp [new file with mode: 0644]
Tools/TestWebKitAPI/Tests/WebKit2/file-with-video.html [new file with mode: 0644]
Tools/TestWebKitAPI/Tests/WebKit2/test.mp4 [new file with mode: 0644]

index 816474e..f7ebe53 100644 (file)
@@ -1,3 +1,13 @@
+2014-10-08  Ada Chan  <adachan@apple.com>
+
+        Implement WKPageIsPlayingAudio().
+        https://bugs.webkit.org/show_bug.cgi?id=137048
+
+        Reviewed by Darin Adler.
+
+        * UIProcess/API/C/WKPage.cpp:
+        (WKPageIsPlayingAudio):
+
 2014-10-08  Gyuyoung Kim  <gyuyoung.kim@samsung.com>
 
         [EFL][CoordinatedGraphics] All EFL layout tests are broken since r174231
index cf38939..adcbdc0 100644 (file)
@@ -1887,10 +1887,9 @@ void WKPageSetAddsVisitedLinks(WKPageRef page, bool addsVisitedLinks)
     toImpl(page)->setAddsVisitedLinks(addsVisitedLinks);
 }
 
-bool WKPageIsPlayingAudio(WKPageRef)
+bool WKPageIsPlayingAudio(WKPageRef page)
 {
-    // FIXME: To be implemented (https://bugs.webkit.org/show_bug.cgi?id=137048).
-    return false;
+    return toImpl(page)->isPlayingAudio();
 }
 
 #if ENABLE(NETSCAPE_PLUGIN_API)
index 4cd3d9d..c2ea7b1 100644 (file)
@@ -1,3 +1,26 @@
+2014-10-08  Ada Chan  <adachan@apple.com>
+
+        Add a test for WKPageIsPlayingAudio().
+        https://bugs.webkit.org/show_bug.cgi?id=137048
+
+        Reviewed by Darin Adler.
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        Add file-with-video.html, test.mp4, and WKPageIsPlayingAudio.cpp to the project.
+        * TestWebKitAPI/Tests/WebKit2/WKPageIsPlayingAudio.cpp: Added.
+        (TestWebKitAPI::nullJavaScriptCallback):
+        (TestWebKitAPI::didFinishLoadForFrame):
+        (TestWebKitAPI::isPlayingAudioDidChangeCallback):
+        (TestWebKitAPI::setUpClients):
+        (TestWebKitAPI::TEST):
+        This test loads a page with a video in it. When the page is loaded, we first check that
+        WKPageIsPlayingAudio() returns false for the page. Then we call a method to start the video.
+        When the WKPageUIClient::isPlayingAudioDidChange callback gets called, check that WKPageIsPlayingAudio()
+        now returns true for the page.
+        * TestWebKitAPI/Tests/WebKit2/file-with-video.html: Added.
+        * TestWebKitAPI/Tests/WebKit2/test.mp4: Added.
+        This is a video copied from LayoutTests/media/content.
+
 2014-10-08  Csaba Osztrogon√°c  <ossy@webkit.org>
 
         [webkitpy] Use python-irclib-0.4.8.tar.gz instead of zip in AutoInstaller
index 75980c8..6eea998 100644 (file)
                51FCF7A11534B2A000104491 /* ShouldGoToBackForwardListItem_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 51FCF7971534AC6D00104491 /* ShouldGoToBackForwardListItem_Bundle.cpp */; };
                520BCF4C141EB09E00937EA8 /* WebArchive_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 520BCF4A141EB09E00937EA8 /* WebArchive_Bundle.cpp */; };
                520BCF4D141EB09E00937EA8 /* WebArchive.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 520BCF4B141EB09E00937EA8 /* WebArchive.cpp */; };
+               524BBC9D19DF377A002F1AF1 /* WKPageIsPlayingAudio.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 524BBC9C19DF377A002F1AF1 /* WKPageIsPlayingAudio.cpp */; };
+               524BBC9E19DF72C0002F1AF1 /* file-with-video.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 524BBC9B19DF3714002F1AF1 /* file-with-video.html */; };
+               524BBCA119E30C77002F1AF1 /* test.mp4 in Copy Resources */ = {isa = PBXBuildFile; fileRef = 524BBCA019E30C63002F1AF1 /* test.mp4 */; };
                52B8CF9615868CF000281053 /* SetDocumentURI.mm in Sources */ = {isa = PBXBuildFile; fileRef = 52B8CF9515868CF000281053 /* SetDocumentURI.mm */; };
                52B8CF9815868D9100281053 /* SetDocumentURI.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 52B8CF9415868CF000281053 /* SetDocumentURI.html */; };
                52CB47411448FB9300873995 /* LoadAlternateHTMLStringWithNonDirectoryURL.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 52CB47401448FB9300873995 /* LoadAlternateHTMLStringWithNonDirectoryURL.cpp */; };
                                C5E1AFFE16B221F1006CC1F2 /* execCopy.html in Copy Resources */,
                                1A7E8B3618120B2F00AEB74A /* FragmentNavigation.html in Copy Resources */,
                                BC2D006412AA04CE00E732A3 /* file-with-anchor.html in Copy Resources */,
+                               524BBC9E19DF72C0002F1AF1 /* file-with-video.html in Copy Resources */,
                                C5101C4F176B8D9200EE9B15 /* findRanges.html in Copy Resources */,
                                1A02C870125D4CFD00E3F4BD /* find.html in Copy Resources */,
                                26F52EB218288F240023D412 /* geolocationWatchPosition.html in Copy Resources */,
                                BC909784125571CF00083756 /* simple.html in Copy Resources */,
                                C01A23F21266156700C9ED55 /* spacebar-scrolling.html in Copy Resources */,
                                E194E1BD177E53C7009C4D4E /* StopLoadingFromDidReceiveResponse.html in Copy Resources */,
+                               524BBCA119E30C77002F1AF1 /* test.mp4 in Copy Resources */,
                                C540F784152E5A9A00A40C8C /* verboseMarkup.html in Copy Resources */,
                                A5E2027515B21F6E00C13E14 /* WindowlessWebViewWithMedia.html in Copy Resources */,
                        );
                51FCF7981534AC6D00104491 /* ShouldGoToBackForwardListItem.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ShouldGoToBackForwardListItem.cpp; sourceTree = "<group>"; };
                520BCF4A141EB09E00937EA8 /* WebArchive_Bundle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebArchive_Bundle.cpp; sourceTree = "<group>"; };
                520BCF4B141EB09E00937EA8 /* WebArchive.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebArchive.cpp; sourceTree = "<group>"; };
+               524BBC9B19DF3714002F1AF1 /* file-with-video.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "file-with-video.html"; sourceTree = "<group>"; };
+               524BBC9C19DF377A002F1AF1 /* WKPageIsPlayingAudio.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WKPageIsPlayingAudio.cpp; sourceTree = "<group>"; };
+               524BBCA019E30C63002F1AF1 /* test.mp4 */ = {isa = PBXFileReference; lastKnownFileType = file; path = test.mp4; sourceTree = "<group>"; };
                52B8CF9415868CF000281053 /* SetDocumentURI.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = SetDocumentURI.html; sourceTree = "<group>"; };
                52B8CF9515868CF000281053 /* SetDocumentURI.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = SetDocumentURI.mm; sourceTree = "<group>"; };
                52CB47401448FB9300873995 /* LoadAlternateHTMLStringWithNonDirectoryURL.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = LoadAlternateHTMLStringWithNonDirectoryURL.cpp; sourceTree = "<group>"; };
                                A1FDFD2E19C288BB005148A4 /* WKImageCreateCGImageCrash.cpp */,
                                BC9099931256ACF100083756 /* WKStringJSString.cpp */,
                                51E93016156B13E1004C99DF /* WKPageGetScaleFactorNotZero.cpp */,
+                               524BBC9C19DF377A002F1AF1 /* WKPageIsPlayingAudio.cpp */,
                                BC7B619A1299FE9E00D174A4 /* WKPreferences.cpp */,
                                BC90995D12567BC100083756 /* WKString.cpp */,
                        );
                                290F4274172A1FDE00939FF0 /* custom-protocol-sync-xhr.html */,
                                C5E1AFFD16B22179006CC1F2 /* execCopy.html */,
                                BC2D004A12A9FEB300E732A3 /* file-with-anchor.html */,
+                               524BBC9B19DF3714002F1AF1 /* file-with-video.html */,
                                1A02C84B125D4A5E00E3F4BD /* find.html */,
                                C5101C4E176B8BB900EE9B15 /* findRanges.html */,
                                26F52EAC1828820E0023D412 /* geolocationGetCurrentPosition.html */,
                                51E780361919AFF8001829A2 /* simple2.html */,
                                51E780371919AFF8001829A2 /* simple3.html */,
                                C02B7882126615410026BF0F /* spacebar-scrolling.html */,
+                               524BBCA019E30C63002F1AF1 /* test.mp4 */,
                        );
                        name = Resources;
                        sourceTree = "<group>";
                                BCBD3710125AA2EB00D2C29F /* FrameMIMETypeHTML.cpp in Sources */,
                                BCBD3761125ABCFE00D2C29F /* FrameMIMETypePNG.cpp in Sources */,
                                CE32C7C818184C4900CD8C28 /* WillPerformClientRedirectToURLCrash.mm in Sources */,
+                               524BBC9D19DF377A002F1AF1 /* WKPageIsPlayingAudio.cpp in Sources */,
                                290F427B172A23A500939FF0 /* TestProtocol.mm in Sources */,
                                1AA9E55914980A9900001A8A /* Functional.cpp in Sources */,
                                C0C5D3BE14598B6F00A802A6 /* GetBackingScaleFactor.mm in Sources */,
diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/WKPageIsPlayingAudio.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/WKPageIsPlayingAudio.cpp
new file mode 100644 (file)
index 0000000..ec933af
--- /dev/null
@@ -0,0 +1,94 @@
+/*
+ * Copyright (C) 2014 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"
+#include "PlatformUtilities.h"
+#include "PlatformWebView.h"
+#include "Test.h"
+#include <WebKit/WKPagePrivate.h>
+
+// This test loads file-with-video.html. It first checks to make sure WKPageIsPlayingAudio() returns
+// false for the page. Then it calls a JavaScript method to play the video, waits for
+// WKPageUIClient::isPlayingAudioDidChange() to get called, and checks that WKPageIsPlayingAudio() now
+// returns true for the page.
+
+namespace TestWebKitAPI {
+
+static bool didFinishLoad;
+static bool isPlayingAudioChanged;
+
+static void nullJavaScriptCallback(WKSerializedScriptValueRef, WKErrorRef error, void*)
+{
+}
+
+static void didFinishLoadForFrame(WKPageRef page, WKFrameRef, WKTypeRef, const void*)
+{
+    didFinishLoad = true;
+}
+
+static void isPlayingAudioDidChangeCallback(WKPageRef page, const void*)
+{
+    isPlayingAudioChanged = true;
+}
+
+static void setUpClients(WKPageRef page)
+{
+    WKPageLoaderClientV0 loaderClient;
+    memset(&loaderClient, 0, sizeof(loaderClient));
+
+    loaderClient.base.version = 0;
+    loaderClient.didFinishLoadForFrame = didFinishLoadForFrame;
+
+    WKPageSetPageLoaderClient(page, &loaderClient.base);
+
+    WKPageUIClientV4 uiClient;
+    memset(&uiClient, 0, sizeof(uiClient));
+
+    uiClient.base.version = 4;
+    uiClient.isPlayingAudioDidChange = isPlayingAudioDidChangeCallback;
+
+    WKPageSetPageUIClient(page, &uiClient.base);
+}
+
+TEST(WebKit2, WKPageIsPlayingAudio)
+{
+    WKRetainPtr<WKContextRef> context = adoptWK(WKContextCreate());
+
+    PlatformWebView webView(context.get());
+    setUpClients(webView.page());
+
+    WKRetainPtr<WKURLRef> url = adoptWK(Util::createURLForResource("file-with-video", "html"));
+    WKPageLoadURL(webView.page(), url.get());
+
+    Util::run(&didFinishLoad);
+
+    EXPECT_FALSE(WKPageIsPlayingAudio(webView.page()));
+    WKPageRunJavaScriptInMainFrame(webView.page(), Util::toWK("playVideo()").get(), 0, nullJavaScriptCallback);
+
+    Util::run(&isPlayingAudioChanged);
+    EXPECT_TRUE(WKPageIsPlayingAudio(webView.page()));
+}
+
+} // namespace TestWebKitAPI
diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/file-with-video.html b/Tools/TestWebKitAPI/Tests/WebKit2/file-with-video.html
new file mode 100644 (file)
index 0000000..aa2259a
--- /dev/null
@@ -0,0 +1,18 @@
+<html>
+<head>
+  <script>
+    function playVideo()
+    {
+        document.getElementById("test-video").play();
+    }
+  </script>
+</head>
+<body>
+    <p>
+    <video id="test-video" src="test.mp4" controls></video>
+    </p>
+    <p>
+    <button onclick="playVideo()">Play Video</button>
+    </p>
+</body>
+</html>
diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/test.mp4 b/Tools/TestWebKitAPI/Tests/WebKit2/test.mp4
new file mode 100644 (file)
index 0000000..d278c8a
Binary files /dev/null and b/Tools/TestWebKitAPI/Tests/WebKit2/test.mp4 differ