mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2024-12-29 02:52:19 +01:00
ceftests: Fix MediaAccessTest.Desktop failures
Fixes InvalidStateError: Failed to execute 'getDisplayMedia' on 'MediaDevices': getDisplayMedia() requires transient activation (user gesture).
This commit is contained in:
parent
dc2231cdfb
commit
baf98ee6e9
@ -9,6 +9,7 @@
|
|||||||
#include "include/cef_parser.h"
|
#include "include/cef_parser.h"
|
||||||
#include "include/cef_permission_handler.h"
|
#include "include/cef_permission_handler.h"
|
||||||
#include "include/cef_request_context_handler.h"
|
#include "include/cef_request_context_handler.h"
|
||||||
|
#include "include/test/cef_test_helpers.h"
|
||||||
#include "include/wrapper/cef_closure_task.h"
|
#include "include/wrapper/cef_closure_task.h"
|
||||||
#include "include/wrapper/cef_stream_resource_handler.h"
|
#include "include/wrapper/cef_stream_resource_handler.h"
|
||||||
#include "tests/ceftests/test_handler.h"
|
#include "tests/ceftests/test_handler.h"
|
||||||
@ -49,6 +50,9 @@ class TestSetup {
|
|||||||
|
|
||||||
// CONFIGURATION
|
// CONFIGURATION
|
||||||
|
|
||||||
|
// True if a user gesture is required for the getDisplayMedia call.
|
||||||
|
bool needs_user_gesture = false;
|
||||||
|
|
||||||
// Deny the prompt by returning false in OnRequestMediaAccessPermission.
|
// Deny the prompt by returning false in OnRequestMediaAccessPermission.
|
||||||
bool deny_implicitly = false;
|
bool deny_implicitly = false;
|
||||||
|
|
||||||
@ -129,7 +133,8 @@ class MediaAccessTestHandler : public TestHandler, public CefPermissionHandler {
|
|||||||
" document.location = "
|
" document.location = "
|
||||||
"`http://tests/"
|
"`http://tests/"
|
||||||
"exit?result=${val}&data=${encodeURIComponent(JSON.stringify(data))}`;"
|
"exit?result=${val}&data=${encodeURIComponent(JSON.stringify(data))}`;"
|
||||||
"}";
|
"}"
|
||||||
|
"function runTest() {";
|
||||||
|
|
||||||
if (want_audio_device() || want_video_device()) {
|
if (want_audio_device() || want_video_device()) {
|
||||||
page += std::string("navigator.mediaDevices.getUserMedia({audio: ") +
|
page += std::string("navigator.mediaDevices.getUserMedia({audio: ") +
|
||||||
@ -150,7 +155,8 @@ class MediaAccessTestHandler : public TestHandler, public CefPermissionHandler {
|
|||||||
".catch(function(err) {"
|
".catch(function(err) {"
|
||||||
" console.log(err.toString());"
|
" console.log(err.toString());"
|
||||||
" onResult(`ERROR`, {error_str: err.toString()});"
|
" onResult(`ERROR`, {error_str: err.toString()});"
|
||||||
"});";
|
"});"
|
||||||
|
"}";
|
||||||
|
|
||||||
if (test_setup_->deny_implicitly && IsChromeRuntimeEnabled()) {
|
if (test_setup_->deny_implicitly && IsChromeRuntimeEnabled()) {
|
||||||
// Default behavior with the Chrome runtime is to show a UI prompt, so add
|
// Default behavior with the Chrome runtime is to show a UI prompt, so add
|
||||||
@ -164,7 +170,13 @@ class MediaAccessTestHandler : public TestHandler, public CefPermissionHandler {
|
|||||||
|
|
||||||
page +=
|
page +=
|
||||||
"</script>"
|
"</script>"
|
||||||
"</head><body>MEDIA ACCESS TEST</body></html>";
|
"</head><body>";
|
||||||
|
|
||||||
|
if (!test_setup_->needs_user_gesture) {
|
||||||
|
page += "<script>runTest();</script>";
|
||||||
|
}
|
||||||
|
|
||||||
|
page += "MEDIA ACCESS TEST</body></html>";
|
||||||
|
|
||||||
// Create the request context that will use an in-memory cache.
|
// Create the request context that will use an in-memory cache.
|
||||||
CefRequestContextSettings settings;
|
CefRequestContextSettings settings;
|
||||||
@ -196,6 +208,8 @@ class MediaAccessTestHandler : public TestHandler, public CefPermissionHandler {
|
|||||||
if (frame->GetURL().ToString() == kMediaNavUrl) {
|
if (frame->GetURL().ToString() == kMediaNavUrl) {
|
||||||
DestroyTest();
|
DestroyTest();
|
||||||
}
|
}
|
||||||
|
} else if (test_setup_->needs_user_gesture) {
|
||||||
|
CefExecuteJavaScriptWithUserGestureForTests(frame, "runTest()");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -631,6 +645,7 @@ TEST(MediaAccessTest, DeviceSuccessAudioVideoAsync) {
|
|||||||
// Screen capture tests
|
// Screen capture tests
|
||||||
TEST(MediaAccessTest, DesktopFailureWhenReturningNoPermission) {
|
TEST(MediaAccessTest, DesktopFailureWhenReturningNoPermission) {
|
||||||
TestSetup test_setup;
|
TestSetup test_setup;
|
||||||
|
test_setup.needs_user_gesture = true;
|
||||||
|
|
||||||
CefRefPtr<MediaAccessTestHandler> handler =
|
CefRefPtr<MediaAccessTestHandler> handler =
|
||||||
new MediaAccessTestHandler(&test_setup,
|
new MediaAccessTestHandler(&test_setup,
|
||||||
@ -649,6 +664,7 @@ TEST(MediaAccessTest, DesktopFailureWhenReturningNoPermission) {
|
|||||||
|
|
||||||
TEST(MediaAccessTest, DesktopFailureWhenRequestingVideoButReturningAudio) {
|
TEST(MediaAccessTest, DesktopFailureWhenRequestingVideoButReturningAudio) {
|
||||||
TestSetup test_setup;
|
TestSetup test_setup;
|
||||||
|
test_setup.needs_user_gesture = true;
|
||||||
|
|
||||||
CefRefPtr<MediaAccessTestHandler> handler = new MediaAccessTestHandler(
|
CefRefPtr<MediaAccessTestHandler> handler = new MediaAccessTestHandler(
|
||||||
&test_setup, CEF_MEDIA_PERMISSION_DESKTOP_VIDEO_CAPTURE,
|
&test_setup, CEF_MEDIA_PERMISSION_DESKTOP_VIDEO_CAPTURE,
|
||||||
@ -665,6 +681,7 @@ TEST(MediaAccessTest, DesktopFailureWhenRequestingVideoButReturningAudio) {
|
|||||||
|
|
||||||
TEST(MediaAccessTest, DesktopPartialSuccessReturningVideo) {
|
TEST(MediaAccessTest, DesktopPartialSuccessReturningVideo) {
|
||||||
TestSetup test_setup;
|
TestSetup test_setup;
|
||||||
|
test_setup.needs_user_gesture = true;
|
||||||
|
|
||||||
CefRefPtr<MediaAccessTestHandler> handler =
|
CefRefPtr<MediaAccessTestHandler> handler =
|
||||||
new MediaAccessTestHandler(&test_setup,
|
new MediaAccessTestHandler(&test_setup,
|
||||||
@ -683,6 +700,8 @@ TEST(MediaAccessTest, DesktopPartialSuccessReturningVideo) {
|
|||||||
|
|
||||||
TEST(MediaAccessTest, DesktopPartialFailureReturningAudio) {
|
TEST(MediaAccessTest, DesktopPartialFailureReturningAudio) {
|
||||||
TestSetup test_setup;
|
TestSetup test_setup;
|
||||||
|
test_setup.needs_user_gesture = true;
|
||||||
|
|
||||||
CefRefPtr<MediaAccessTestHandler> handler =
|
CefRefPtr<MediaAccessTestHandler> handler =
|
||||||
new MediaAccessTestHandler(&test_setup,
|
new MediaAccessTestHandler(&test_setup,
|
||||||
CEF_MEDIA_PERMISSION_DESKTOP_AUDIO_CAPTURE |
|
CEF_MEDIA_PERMISSION_DESKTOP_AUDIO_CAPTURE |
|
||||||
|
Loading…
Reference in New Issue
Block a user