From 6fca3ec615102f9ce2e1b3330406ef1d654d2474 Mon Sep 17 00:00:00 2001 From: Pierre Rossi Date: Tue, 18 Mar 2014 15:29:22 +0100 Subject: WebRTC Widgets API Simply reuse the existing feature request approach that was used for geolocation and notifications in QtWebKit. Change-Id: I8fec4f4e9e81b491163912fadb4ce17d343864dd Reviewed-by: Zeno Albisser --- .../widgets/qwebenginepage/tst_qwebenginepage.cpp | 65 ++++++++++++++++++++++ 1 file changed, 65 insertions(+) (limited to 'tests') diff --git a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp index c22ea0051..75f8bf5fb 100644 --- a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp +++ b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp @@ -153,6 +153,7 @@ private Q_SLOTS: void userAgentNewlineStripping(); void undoActionHaveCustomText(); void renderWidgetHostViewNotShowTopLevel(); + void getUserMediaRequest(); void viewModes(); @@ -3589,6 +3590,70 @@ void tst_QWebEnginePage::renderWidgetHostViewNotShowTopLevel() QCOMPARE(widget->isVisible(), false); } +class GetUserMediaTestPage : public QWebEnginePage { +Q_OBJECT + +public: + GetUserMediaTestPage() + : m_gotRequest(false) + { + connect(this, &QWebEnginePage::featurePermissionRequested, this, &GetUserMediaTestPage::onFeaturePermissionRequested); + } + + void rejectPendingRequest() + { + setFeaturePermission(m_requestSecurityOrigin, m_requestedFeature, QWebEnginePage::PermissionDeniedByUser); + m_gotRequest = false; + } + void acceptPendingRequest() + { + setFeaturePermission(m_requestSecurityOrigin, m_requestedFeature, QWebEnginePage::PermissionGrantedByUser); + m_gotRequest = false; + } + + bool gotFeatureRequest(QWebEnginePage::Feature feature) + { + return m_gotRequest && m_requestedFeature == feature; + } + +private Q_SLOTS: + void onFeaturePermissionRequested(const QUrl &securityOrigin, QWebEnginePage::Feature feature) + { + m_requestedFeature = feature; + m_requestSecurityOrigin = securityOrigin; + m_gotRequest = true; + } + +private: + bool m_gotRequest; + QWebEnginePage::Feature m_requestedFeature; + QUrl m_requestSecurityOrigin; + +}; + + +void tst_QWebEnginePage::getUserMediaRequest() +{ + GetUserMediaTestPage *page = new GetUserMediaTestPage(); + + // We need to load content from a resource in order for the securityOrigin to be valid. + page->load(QUrl("qrc:///resources/content.html")); + + QVERIFY(evaluateJavaScriptSync(page, QStringLiteral("!!navigator.webkitGetUserMedia")).toBool()); + evaluateJavaScriptSync(page, QStringLiteral("navigator.webkitGetUserMedia({audio: true}, function() {}, function(){})")); + QTRY_VERIFY_WITH_TIMEOUT(page->gotFeatureRequest(QWebEnginePage::MediaAudioDevices), 100); + // Might end up failing due to the lack of physical media devices deeper in the content layer, so the JS callback is not guaranteed to be called, + // but at least we go through that code path, potentially uncovering failing assertions. + page->acceptPendingRequest(); + + page->runJavaScript(QStringLiteral("errorCallbackCalled = false;")); + evaluateJavaScriptSync(page, QStringLiteral("navigator.webkitGetUserMedia({audio: true, video: true}, function() {}, function(){errorCallbackCalled = true;})")); + QTRY_VERIFY_WITH_TIMEOUT(page->gotFeatureRequest(QWebEnginePage::MediaAudioVideoDevices), 100); + page->rejectPendingRequest(); // Should always end up calling the error callback in JS. + QTRY_VERIFY_WITH_TIMEOUT(evaluateJavaScriptSync(page, QStringLiteral("errorCallbackCalled;")).toBool(), 100); + delete page; +} + void tst_QWebEnginePage::openWindowDefaultSize() { #if !defined(QWEBENGINEPAGE_SETTINGS) -- cgit v1.2.3