diff options
author | Pierre Rossi <pierre.rossi@digia.com> | 2014-03-18 15:29:22 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-04-29 16:37:52 +0200 |
commit | 6fca3ec615102f9ce2e1b3330406ef1d654d2474 (patch) | |
tree | a043ba929f034ed6587f987ceaa9cb0c98aa79fc /tests/auto | |
parent | 070846b2efff8c8f2e8bdebef259f411ddeaac1e (diff) |
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 <zeno.albisser@digia.com>
Diffstat (limited to 'tests/auto')
-rw-r--r-- | tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp | 65 |
1 files changed, 65 insertions, 0 deletions
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) |