|
26 | 26 | #include <glib/gstdio.h>
|
27 | 27 | #include <wtf/gobject/GRefPtr.h>
|
28 | 28 |
|
| 29 | +class IsPlayingAudioWebViewTest : public WebViewTest { |
| 30 | +public: |
| 31 | + MAKE_GLIB_TEST_FIXTURE(IsPlayingAudioWebViewTest); |
| 32 | + |
| 33 | + static void isPlayingAudioChanged(GObject*, GParamSpec*, IsPlayingAudioWebViewTest* test) |
| 34 | + { |
| 35 | + g_signal_handlers_disconnect_by_func(test->m_webView, reinterpret_cast<void*>(isPlayingAudioChanged), test); |
| 36 | + g_main_loop_quit(test->m_mainLoop); |
| 37 | + } |
| 38 | + |
| 39 | + void waitUntilIsPlayingAudioChanged() |
| 40 | + { |
| 41 | + g_signal_connect(m_webView, "notify::is-playing-audio", G_CALLBACK(isPlayingAudioChanged), this); |
| 42 | + g_main_loop_run(m_mainLoop); |
| 43 | + } |
| 44 | +}; |
| 45 | + |
29 | 46 | static WebKitTestServer* gServer;
|
30 | 47 |
|
31 | 48 | static void testWebViewWebContext(WebViewTest* test, gconstpointer)
|
@@ -702,6 +719,31 @@ static void testWebViewNotification(NotificationWebViewTest* test, gconstpointer
|
702 | 719 | g_assert(test->m_event == NotificationWebViewTest::Cancelled);
|
703 | 720 | }
|
704 | 721 |
|
| 722 | +static void testWebViewIsPlayingAudio(IsPlayingAudioWebViewTest* test, gconstpointer) |
| 723 | +{ |
| 724 | + // The web view must be realized for the video to start playback and |
| 725 | + // trigger changes in WebKitWebView::is-playing-audio. |
| 726 | + test->showInWindowAndWaitUntilMapped(GTK_WINDOW_TOPLEVEL); |
| 727 | + |
| 728 | + // Initially, web views should always report no audio being played. |
| 729 | + g_assert(!webkit_web_view_is_playing_audio(test->m_webView)); |
| 730 | + |
| 731 | + GUniquePtr<char> resourcePath(g_build_filename(Test::getResourcesDir(Test::WebKit2Resources).data(), "file-with-video.html", nullptr)); |
| 732 | + GUniquePtr<char> resourceURL(g_filename_to_uri(resourcePath.get(), nullptr, nullptr)); |
| 733 | + webkit_web_view_load_uri(test->m_webView, resourceURL.get()); |
| 734 | + test->waitUntilLoadFinished(); |
| 735 | + g_assert(!webkit_web_view_is_playing_audio(test->m_webView)); |
| 736 | + |
| 737 | + webkit_web_view_run_javascript(test->m_webView, "playVideo();", nullptr, nullptr, nullptr); |
| 738 | + test->waitUntilIsPlayingAudioChanged(); |
| 739 | + g_assert(webkit_web_view_is_playing_audio(test->m_webView)); |
| 740 | + |
| 741 | + // Pause the video, and check again. |
| 742 | + webkit_web_view_run_javascript(test->m_webView, "document.getElementById('test-video').pause();", nullptr, nullptr, nullptr); |
| 743 | + test->waitUntilIsPlayingAudioChanged(); |
| 744 | + g_assert(!webkit_web_view_is_playing_audio(test->m_webView)); |
| 745 | +} |
| 746 | + |
705 | 747 | static void serverCallback(SoupServer* server, SoupMessage* message, const char* path, GHashTable*, SoupClientContext*, gpointer)
|
706 | 748 | {
|
707 | 749 | if (message->method != SOUP_METHOD_GET) {
|
@@ -733,6 +775,7 @@ void beforeAll()
|
733 | 775 | SnapshotWebViewTest::add("WebKitWebView", "snapshot", testWebViewSnapshot);
|
734 | 776 | WebViewTest::add("WebKitWebView", "page-visibility", testWebViewPageVisibility);
|
735 | 777 | NotificationWebViewTest::add("WebKitWebView", "notification", testWebViewNotification);
|
| 778 | + IsPlayingAudioWebViewTest::add("WebKitWebView", "is-playing-audio", testWebViewIsPlayingAudio); |
736 | 779 | }
|
737 | 780 |
|
738 | 781 | void afterAll()
|
|
0 commit comments