summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorViktor Engelmann <viktor.engelmann@qt.io>2017-09-22 09:13:50 +0200
committerViktor Engelmann <viktor.engelmann@qt.io>2017-11-08 09:22:25 +0000
commit86207b164df8ea4251b4269b4fa688d41ce8230f (patch)
treec98cf23b4e0e37a2724fc55dba7433054d6e5911
parent64ad0e8b335509970062ba550a06018426b7c285 (diff)
Make GetUserMediaTestPage more robust
A 5 second timeout might not be enough for our underpowered CI VMs. Also, if the page isn't loaded (to slow or for other reasons), we must abort, to prevent the JavaScripts from being run on different pages (first scripts to the old page, then to the new page if it eventually finishes loading). The first JavaScript in particular is rejected on the old page, because "about:blank" doesn't have a secure origin. This could even make the test accept wrongfully if all scripts are run on the old page, because the request (which is supposed to be rejected) can be rejected for being run on the wrong page, instead of for requesting forbidden permissions. Task-number: QTBUG-63347 Change-Id: Ib63d55477d35001b174900b73dc3dd23d33c7263 Reviewed-by: Jüri Valdmann <juri.valdmann@qt.io> Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
-rw-r--r--tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp18
1 files changed, 14 insertions, 4 deletions
diff --git a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp
index b4b1abc8c..76a0bbf4d 100644
--- a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp
+++ b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp
@@ -2655,18 +2655,19 @@ Q_OBJECT
public:
GetUserMediaTestPage()
: m_gotRequest(false)
+ , m_loadSucceeded(false)
{
connect(this, &QWebEnginePage::featurePermissionRequested, this, &GetUserMediaTestPage::onFeaturePermissionRequested);
-
+ connect(this, &QWebEnginePage::loadFinished, [this](bool success){
+ m_loadSucceeded = success;
+ });
// We need to load content from a resource in order for the securityOrigin to be valid.
- QSignalSpy loadSpy(this, SIGNAL(loadFinished(bool)));
load(QUrl("qrc:///resources/content.html"));
- QTRY_COMPARE(loadSpy.count(), 1);
}
void jsGetUserMedia(const QString & constraints)
{
- runJavaScript(
+ evaluateJavaScriptSync(this,
QStringLiteral(
"var promiseFulfilled = false;"
"var promiseRejected = false;"
@@ -2707,6 +2708,11 @@ public:
return m_gotRequest;
}
+ bool loadSucceeded() const
+ {
+ return m_loadSucceeded;
+ }
+
private Q_SLOTS:
void onFeaturePermissionRequested(const QUrl &securityOrigin, QWebEnginePage::Feature feature)
{
@@ -2717,6 +2723,7 @@ private Q_SLOTS:
private:
bool m_gotRequest;
+ bool m_loadSucceeded;
QWebEnginePage::Feature m_requestedFeature;
QUrl m_requestSecurityOrigin;
@@ -2747,6 +2754,7 @@ void tst_QWebEnginePage::getUserMediaRequest()
QFETCH(QWebEnginePage::Feature, feature);
GetUserMediaTestPage page;
+ QTRY_VERIFY_WITH_TIMEOUT(page.loadSucceeded(), 20000);
page.settings()->setAttribute(QWebEngineSettings::ScreenCaptureEnabled, true);
// 1. Rejecting request on C++ side should reject promise on JS side.
@@ -2775,6 +2783,7 @@ void tst_QWebEnginePage::getUserMediaRequest()
void tst_QWebEnginePage::getUserMediaRequestDesktopAudio()
{
GetUserMediaTestPage page;
+ QTRY_VERIFY_WITH_TIMEOUT(page.loadSucceeded(), 20000);
page.settings()->setAttribute(QWebEngineSettings::ScreenCaptureEnabled, true);
// Audio-only desktop capture is not supported. JS Promise should be
@@ -2792,6 +2801,7 @@ void tst_QWebEnginePage::getUserMediaRequestDesktopAudio()
void tst_QWebEnginePage::getUserMediaRequestSettingDisabled()
{
GetUserMediaTestPage page;
+ QTRY_VERIFY_WITH_TIMEOUT(page.loadSucceeded(), 20000);
page.settings()->setAttribute(QWebEngineSettings::ScreenCaptureEnabled, false);
// With the setting disabled, the JS Promise should be rejected without