summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2020-01-23 11:01:28 +0100
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2020-01-23 11:01:28 +0100
commit96ec21dc0b6560cb2b86b744393b69b655af655b (patch)
treee3d03ceb9c021c6e0d67aacc50691eb60ca932e3 /tests
parentc67337856dbaf66df813a176379a9f0a6fda2470 (diff)
parentd7d40469b5bfad2cc1693ef663864d2b15d59687 (diff)
Merge branch '5.14' into 5.15
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/widgets/accessibility/tst_accessibility.cpp2
-rw-r--r--tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp93
-rw-r--r--tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp18
3 files changed, 85 insertions, 28 deletions
diff --git a/tests/auto/widgets/accessibility/tst_accessibility.cpp b/tests/auto/widgets/accessibility/tst_accessibility.cpp
index d69a4c0a7..b5def4cd7 100644
--- a/tests/auto/widgets/accessibility/tst_accessibility.cpp
+++ b/tests/auto/widgets/accessibility/tst_accessibility.cpp
@@ -365,7 +365,7 @@ void tst_Accessibility::roles_data()
//QTest::newRow("AX_ROLE_TABLE_HEADER_CONTAINER"); // No mapping to ARIA role
QTest::newRow("AX_ROLE_TAB") << QString("<div role='tab'>a</div>") << true << QAccessible::PageTab;
QTest::newRow("AX_ROLE_TAB_LIST") << QString("<div role='tablist'>a</div>") << true << QAccessible::PageTabList;
- QTest::newRow("AX_ROLE_TAB_PANEL") << QString("<div role='tab'>a</div>") << true << QAccessible::PageTab;
+ QTest::newRow("AX_ROLE_TAB_PANEL") << QString("<div role='tabpanel'>a</div>") << true << QAccessible::Pane;
QTest::newRow("AX_ROLE_TERM") << QString("<div role='term'>a</div>") << true << QAccessible::StaticText;
QTest::newRow("AX_ROLE_TEXT_FIELD") << QString("<input type='text'></input>") << false << QAccessible::EditableText;
QTest::newRow("AX_ROLE_TIME") << QString("<time>a</time>") << false << QAccessible::Clock;
diff --git a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp
index 3819080e2..f411f0872 100644
--- a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp
+++ b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp
@@ -229,6 +229,9 @@ private Q_SLOTS:
private:
static QPoint elementCenter(QWebEnginePage *page, const QString &id);
+ static bool isFalseJavaScriptResult(QWebEnginePage *page, const QString &javaScript);
+ static bool isTrueJavaScriptResult(QWebEnginePage *page, const QString &javaScript);
+ static bool isEmptyListJavaScriptResult(QWebEnginePage *page, const QString &javaScript);
QWebEngineView* m_view;
QWebEnginePage* m_page;
@@ -755,19 +758,38 @@ void tst_QWebEnginePage::textSelection()
void tst_QWebEnginePage::backActionUpdate()
{
QWebEngineView view;
+ view.resize(640, 480);
+ view.show();
+
QWebEnginePage *page = view.page();
+ QSignalSpy loadSpy(page, &QWebEnginePage::loadFinished);
QAction *action = page->action(QWebEnginePage::Back);
QVERIFY(!action->isEnabled());
- QSignalSpy loadSpy(page, SIGNAL(loadFinished(bool)));
- QUrl url = QUrl("qrc:///resources/framedindex.html");
- page->load(url);
+
+ page->load(QUrl("qrc:///resources/framedindex.html"));
QTRY_COMPARE_WITH_TIMEOUT(loadSpy.count(), 1, 20000);
QVERIFY(!action->isEnabled());
- QTest::mouseClick(&view, Qt::LeftButton, {}, QPoint(10, 10));
- QEXPECT_FAIL("", "Behavior change: Load signals are emitted only for the main frame in QtWebEngine.", Continue);
- QTRY_COMPARE_WITH_TIMEOUT(loadSpy.count(), 2, 100);
- QEXPECT_FAIL("", "FIXME: Mouse events aren't passed from the QWebEngineView down to the RWHVQtDelegateWidget", Continue);
+ auto firstAnchorCenterInFrame = [](QWebEnginePage *page, const QString &frameName) {
+ QVariantList rectList = evaluateJavaScriptSync(page,
+ "(function(){"
+ "var frame = document.getElementsByName('" + frameName + "')[0];"
+ "var anchor = frame.contentDocument.getElementsByTagName('a')[0];"
+ "var rect = anchor.getBoundingClientRect();"
+ "return [(rect.left + rect.right) / 2, (rect.top + rect.bottom) / 2];"
+ "})()").toList();
+
+ if (rectList.count() != 2) {
+ qWarning("firstAnchorCenterInFrame failed.");
+ return QPoint();
+ }
+
+ return QPoint(rectList.at(0).toInt(), rectList.at(1).toInt());
+ };
+
+ QVERIFY(evaluateJavaScriptSync(page, "document.getElementsByName('frame_b')[0].contentDocument == undefined").toBool());
+ QTest::mouseClick(view.focusProxy(), Qt::LeftButton, 0, firstAnchorCenterInFrame(page, "frame_c"));
+ QTRY_VERIFY(evaluateJavaScriptSync(page, "document.getElementsByName('frame_b')[0].contentDocument != undefined").toBool());
QVERIFY(action->isEnabled());
}
@@ -1682,34 +1704,51 @@ void tst_QWebEnginePage::openWindowDefaultSize()
QCOMPARE(requestedGeometry.height(), 100);
}
+bool tst_QWebEnginePage::isFalseJavaScriptResult(QWebEnginePage *page, const QString &javaScript)
+{
+ QVariant result = evaluateJavaScriptSync(page, javaScript);
+ return !result.isNull() && result.isValid() && result == QVariant(false);
+}
+
+bool tst_QWebEnginePage::isTrueJavaScriptResult(QWebEnginePage *page, const QString &javaScript)
+{
+ QVariant result = evaluateJavaScriptSync(page, javaScript);
+ return !result.isNull() && result.isValid() && result == QVariant(true);
+}
+
+bool tst_QWebEnginePage::isEmptyListJavaScriptResult(QWebEnginePage *page, const QString &javaScript)
+{
+ QVariant result = evaluateJavaScriptSync(page, javaScript);
+ return !result.isNull() && result.isValid() && result == QList<QVariant>();
+}
+
void tst_QWebEnginePage::runJavaScript()
{
TestPage page;
QVariant result;
- QVariantList list;
QVariantMap map;
- QTRY_VERIFY(!evaluateJavaScriptSync(&page, "false").toBool());
- QTRY_COMPARE(evaluateJavaScriptSync(&page, "2").toInt(), 2);
- QTRY_COMPARE(evaluateJavaScriptSync(&page, "2.5").toDouble(), 2.5);
- QTRY_COMPARE(evaluateJavaScriptSync(&page, "\"Test\"").toString(), "Test");
- QTRY_COMPARE(evaluateJavaScriptSync(&page, "[]").toList(), list);
+ QVERIFY(isFalseJavaScriptResult(&page, "false"));
+ QCOMPARE(evaluateJavaScriptSync(&page, "2").toInt(), 2);
+ QCOMPARE(evaluateJavaScriptSync(&page, "2.5").toDouble(), 2.5);
+ QCOMPARE(evaluateJavaScriptSync(&page, "\"Test\"").toString(), "Test");
+ QVERIFY(isEmptyListJavaScriptResult(&page, "[]"));
map.insert(QStringLiteral("test"), QVariant(2));
- QTRY_COMPARE(evaluateJavaScriptSync(&page, "var el = {\"test\": 2}; el").toMap(), map);
+ QCOMPARE(evaluateJavaScriptSync(&page, "var el = {\"test\": 2}; el").toMap(), map);
- QTRY_VERIFY(evaluateJavaScriptSync(&page, "null").isNull());
+ QVERIFY(evaluateJavaScriptSync(&page, "null").isNull());
result = evaluateJavaScriptSync(&page, "undefined");
- QTRY_VERIFY(result.isNull() && !result.isValid());
+ QVERIFY(result.isNull() && !result.isValid());
- QTRY_COMPARE(evaluateJavaScriptSync(&page, "new Date(42000)").toDate(), QVariant(42.0).toDate());
- QTRY_COMPARE(evaluateJavaScriptSync(&page, "new ArrayBuffer(8)").toByteArray(), QByteArray(8, 0));
+ QCOMPARE(evaluateJavaScriptSync(&page, "new Date(42000)").toDate(), QVariant(42.0).toDate());
+ QCOMPARE(evaluateJavaScriptSync(&page, "new ArrayBuffer(8)").toByteArray(), QByteArray(8, 0));
result = evaluateJavaScriptSync(&page, "(function(){})");
- QTRY_VERIFY(result.isNull() && !result.isValid());
+ QVERIFY(result.isNull() && !result.isValid());
- QTRY_COMPARE(evaluateJavaScriptSync(&page, "new Promise(function(){})"), QVariant(QVariantMap{}));
+ QCOMPARE(evaluateJavaScriptSync(&page, "new Promise(function(){})"), QVariant(QVariantMap{}));
}
void tst_QWebEnginePage::runJavaScriptDisabled()
@@ -1762,8 +1801,8 @@ void tst_QWebEnginePage::fullScreenRequested()
page->load(QUrl("qrc:///resources/fullscreen.html"));
QTRY_COMPARE(loadSpy.count(), 1);
- QTRY_VERIFY(evaluateJavaScriptSync(page, "document.webkitFullscreenEnabled").toBool());
- QTRY_VERIFY(!evaluateJavaScriptSync(page, "document.webkitIsFullScreen").toBool());
+ QTRY_VERIFY(isTrueJavaScriptResult(page, "document.webkitFullscreenEnabled"));
+ QVERIFY(isFalseJavaScriptResult(page, "document.webkitIsFullScreen"));
// FullscreenRequest must be a user gesture
bool acceptRequest = true;
@@ -1773,15 +1812,15 @@ void tst_QWebEnginePage::fullScreenRequested()
});
QTest::keyPress(view.focusProxy(), Qt::Key_Space);
- QTRY_VERIFY(evaluateJavaScriptSync(page, "document.webkitIsFullScreen").toBool());
- QVariant result = evaluateJavaScriptSync(page, "document.webkitExitFullscreen()");
- QTRY_VERIFY(result.isNull() && !result.isValid());
+ QTRY_VERIFY(isTrueJavaScriptResult(page, "document.webkitIsFullScreen"));
+ page->runJavaScript("document.webkitExitFullscreen()");
+ QTRY_VERIFY(isFalseJavaScriptResult(page, "document.webkitIsFullScreen"));
acceptRequest = false;
- QTRY_VERIFY(evaluateJavaScriptSync(page, "document.webkitFullscreenEnabled").toBool());
+ QVERIFY(isTrueJavaScriptResult(page, "document.webkitFullscreenEnabled"));
QTest::keyPress(view.focusProxy(), Qt::Key_Space);
- QTRY_VERIFY(!evaluateJavaScriptSync(page, "document.webkitIsFullScreen").toBool());
+ QTRY_VERIFY(isFalseJavaScriptResult(page, "document.webkitIsFullScreen"));
}
void tst_QWebEnginePage::quotaRequested()
diff --git a/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp b/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp
index bd3317e37..9c9a32917 100644
--- a/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp
+++ b/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp
@@ -1829,6 +1829,7 @@ void tst_QWebEngineView::inputFieldOverridesShortcuts()
view.setHtml(QString("<html><body>"
"<button id=\"btn1\" type=\"button\">push it real good</button>"
"<input id=\"input1\" type=\"text\" value=\"x\">"
+ "<input id=\"pass1\" type=\"password\" value=\"x\">"
"</body></html>"));
QVERIFY(loadFinishedSpy.wait());
@@ -1840,6 +1841,11 @@ void tst_QWebEngineView::inputFieldOverridesShortcuts()
"document.getElementById('input1').value").toString();
};
+ auto passwordFieldValue = [&view] () -> QString {
+ return evaluateJavaScriptSync(view.page(),
+ "document.getElementById('pass1').value").toString();
+ };
+
// The input form is not focused. The action is triggered on pressing Shift+Delete.
action->setShortcut(Qt::SHIFT + Qt::Key_Delete);
QTest::keyClick(view.windowHandle(), Qt::Key_Delete, Qt::ShiftModifier);
@@ -1863,8 +1869,20 @@ void tst_QWebEngineView::inputFieldOverridesShortcuts()
QTRY_COMPARE(inputFieldValue(), QString("yxx"));
QVERIFY(!actionTriggered);
+ // The password input form is focused. The action is not triggered, and the form's text changed.
+ evaluateJavaScriptSync(view.page(), "document.getElementById('pass1').focus();");
+ QTRY_COMPARE(evaluateJavaScriptSync(view.page(), "document.activeElement.id").toString(), QStringLiteral("pass1"));
+ actionTriggered = false;
+ QTest::keyClick(view.windowHandle(), Qt::Key_Y);
+ QTRY_COMPARE(passwordFieldValue(), QString("yx"));
+ QTest::keyClick(view.windowHandle(), Qt::Key_X);
+ QTRY_COMPARE(passwordFieldValue(), QString("yxx"));
+ QVERIFY(!actionTriggered);
+
// The input form is focused. Make sure we don't override all short cuts.
// A Ctrl-1 action is no default Qt key binding and should be triggerable.
+ evaluateJavaScriptSync(view.page(), "document.getElementById('input1').focus();");
+ QTRY_COMPARE(evaluateJavaScriptSync(view.page(), "document.activeElement.id").toString(), QStringLiteral("input1"));
action->setShortcut(Qt::CTRL + Qt::Key_1);
QTest::keyClick(view.windowHandle(), Qt::Key_1, Qt::ControlModifier);
QTRY_VERIFY(actionTriggered);