From 4634c2467875e44a5cae5bc1ce015ca7a8115682 Mon Sep 17 00:00:00 2001 From: Peter Varga Date: Mon, 19 Dec 2016 16:16:53 +0100 Subject: Add back SIP (Software Input Panel) widget test Moreover, update the Chromium SHA1 for enabling virtual keyboard support for macOS. Task-number: QTBUG-55766 Change-Id: Ic50ae79ab13a62a4b9289afedce2d6647e266f86 Reviewed-by: Allan Sandfeld Jensen --- .../auto/widgets/qwebenginepage/qwebenginepage.pro | 2 +- .../widgets/qwebenginepage/tst_qwebenginepage.cpp | 79 +-------------- .../auto/widgets/qwebengineview/qwebengineview.pro | 1 + .../widgets/qwebengineview/tst_qwebengineview.cpp | 112 +++++++++++++++++++++ 4 files changed, 115 insertions(+), 79 deletions(-) (limited to 'tests/auto/widgets') diff --git a/tests/auto/widgets/qwebenginepage/qwebenginepage.pro b/tests/auto/widgets/qwebenginepage/qwebenginepage.pro index df733c473..6446cdd7a 100644 --- a/tests/auto/widgets/qwebenginepage/qwebenginepage.pro +++ b/tests/auto/widgets/qwebenginepage/qwebenginepage.pro @@ -1,4 +1,4 @@ include(../tests.pri) -QT *= core-private gui-private +QT *= core-private contains(WEBENGINE_CONFIG, enable_pdf): DEFINES+=QWEBENGINEPAGE_PDFPRINTINGENABLED diff --git a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp index 821ab4757..059b20d4c 100644 --- a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp +++ b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp @@ -32,17 +32,15 @@ #include #include #include +#include #include -#include #include #include #include #include -#include #include #include #include -#include #include #include #include @@ -66,38 +64,6 @@ static void removeRecursive(const QString& dirname) QDir().rmdir(dirname); } -class TestInputContext : public QPlatformInputContext -{ -public: - TestInputContext() - : m_visible(false) - { - QInputMethodPrivate* inputMethodPrivate = QInputMethodPrivate::get(qApp->inputMethod()); - inputMethodPrivate->testContext = this; - } - - ~TestInputContext() - { - QInputMethodPrivate* inputMethodPrivate = QInputMethodPrivate::get(qApp->inputMethod()); - inputMethodPrivate->testContext = 0; - } - - virtual void showInputPanel() - { - m_visible = true; - } - virtual void hideInputPanel() - { - m_visible = false; - } - virtual bool isInputPanelVisible() const - { - return m_visible; - } - - bool m_visible; -}; - class tst_QWebEnginePage : public QObject { Q_OBJECT @@ -1741,32 +1707,6 @@ void tst_QWebEnginePage::inputMethods() clickOnPage(page, textInputCenter); - // This part of the test checks if the SIP (Software Input Panel) is triggered, - // which normally happens on mobile platforms, when a user input form receives - // a mouse click. - int inputPanel = 0; - if (viewType == "QWebEngineView") { - if (QWebEngineView* wv = qobject_cast(view)) - inputPanel = wv->style()->styleHint(QStyle::SH_RequestSoftwareInputPanel); - } else if (viewType == "QGraphicsWebView") { - if (QGraphicsWebView* wv = qobject_cast(view)) - inputPanel = wv->style()->styleHint(QStyle::SH_RequestSoftwareInputPanel); - } - - // For non-mobile platforms RequestSoftwareInputPanel event is not called - // because there is no SIP (Software Input Panel) triggered. In the case of a - // mobile platform, an input panel, e.g. virtual keyboard, is usually invoked - // and the RequestSoftwareInputPanel event is called. For these two situations - // this part of the test can verified as the checks below. - if (inputPanel) - QVERIFY(testContext.isInputPanelVisible()); - else - QVERIFY(!testContext.isInputPanelVisible()); - testContext.hideInputPanel(); - - clickOnPage(page, textInputCenter); - QVERIFY(testContext.isInputPanelVisible()); - //ImMicroFocus QVariant variant = page->inputMethodQuery(Qt::ImMicroFocus); QVERIFY(inputs.at(0).geometry().contains(variant.toRect().topLeft())); @@ -1970,14 +1910,6 @@ void tst_QWebEnginePage::inputMethods() clickOnPage(page, textInputCenter); QVERIFY(!(inputMethodHints(view) & Qt::ImhHiddenText)); - page->setHtml("

nothing to input here"); - testContext.hideInputPanel(); - - QWebEngineElement para = page->mainFrame()->findFirstElement("p"); - clickOnPage(page, para.geometry().center()); - - QVERIFY(!testContext.isInputPanelVisible()); - //START - Test for sending empty QInputMethodEvent page->setHtml("" \ "" \ @@ -2300,15 +2232,6 @@ void tst_QWebEnginePage::inputMethods() anchorPosition = variant.toInt(); QCOMPARE(anchorPosition, 12); - // Check sending RequestSoftwareInputPanel event - page->setHtml("" \ - "" \ - "

abc
"\ - ""); - QWebEngineElement inputElement = page->mainFrame()->findFirstElement("div"); - clickOnPage(page, inputElement.geometry().center()); - - QVERIFY(!testContext.isInputPanelVisible()); // START - Newline test for textarea qApp->processEvents(); diff --git a/tests/auto/widgets/qwebengineview/qwebengineview.pro b/tests/auto/widgets/qwebengineview/qwebengineview.pro index e99c7f493..d91c0074b 100644 --- a/tests/auto/widgets/qwebengineview/qwebengineview.pro +++ b/tests/auto/widgets/qwebengineview/qwebengineview.pro @@ -1 +1,2 @@ include(../tests.pri) +QT *= gui-private diff --git a/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp b/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp index 2baadd869..2acf2f939 100644 --- a/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp +++ b/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp @@ -22,8 +22,10 @@ #include #include "../util.h" +#include #include #include +#include #include #include #include @@ -36,6 +38,7 @@ #include #include #include +#include #define VERIFY_INPUTMETHOD_HINTS(actual, expect) \ QVERIFY(actual == expect); @@ -87,6 +90,8 @@ private Q_SLOTS: void inputMethodsTextFormat(); void keyboardEvents(); void keyboardFocusAfterPopup(); + + void softwareInputPanel(); }; // This will be called before the first test function is executed. @@ -1081,5 +1086,112 @@ void tst_QWebEngineView::keyboardFocusAfterPopup() QTRY_COMPARE(evaluateJavaScriptSync(webView->page(), "document.getElementById('input1').value").toString(), QStringLiteral("x")); } +class TestInputContext : public QPlatformInputContext +{ +public: + TestInputContext() + : m_visible(false) + { + QInputMethodPrivate* inputMethodPrivate = QInputMethodPrivate::get(qApp->inputMethod()); + inputMethodPrivate->testContext = this; + } + + ~TestInputContext() + { + QInputMethodPrivate* inputMethodPrivate = QInputMethodPrivate::get(qApp->inputMethod()); + inputMethodPrivate->testContext = 0; + } + + virtual void showInputPanel() + { + m_visible = true; + } + virtual void hideInputPanel() + { + m_visible = false; + } + virtual bool isInputPanelVisible() const + { + return m_visible; + } + + bool m_visible; +}; + +static QPoint elementCenter(QWebEnginePage *page, const QString &id) +{ + const QString jsCode( + "(function(){" + " var elem = document.getElementById('" + id + "');" + " var rect = elem.getBoundingClientRect();" + " return [(rect.left + rect.right) / 2, (rect.top + rect.bottom) / 2];" + "})()"); + QVariantList rectList = evaluateJavaScriptSync(page, jsCode).toList(); + + if (rectList.count() != 2) { + qWarning("elementCenter failed."); + return QPoint(); + } + + return QPoint(rectList.at(0).toInt(), rectList.at(1).toInt()); +} + +void tst_QWebEngineView::softwareInputPanel() +{ + TestInputContext testContext; + QWebEngineView view; + view.show(); + + QSignalSpy loadFinishedSpy(&view, SIGNAL(loadFinished(bool))); + view.setHtml("" + " " + ""); + QVERIFY(loadFinishedSpy.wait()); + + QPoint textInputCenter = elementCenter(view.page(), "input1"); + QTest::mouseClick(view.focusProxy(), Qt::LeftButton, 0, textInputCenter); + QTRY_COMPARE(evaluateJavaScriptSync(view.page(), "document.activeElement.id").toString(), QStringLiteral("input1")); + + // This part of the test checks if the SIP (Software Input Panel) is triggered, + // which normally happens on mobile platforms, when a user input form receives + // a mouse click. + int inputPanel = view.style()->styleHint(QStyle::SH_RequestSoftwareInputPanel); + + // For non-mobile platforms RequestSoftwareInputPanel event is not called + // because there is no SIP (Software Input Panel) triggered. In the case of a + // mobile platform, an input panel, e.g. virtual keyboard, is usually invoked + // and the RequestSoftwareInputPanel event is called. For these two situations + // this part of the test can verified as the checks below. + if (inputPanel) + QTRY_VERIFY(testContext.isInputPanelVisible()); + else + QTRY_VERIFY(!testContext.isInputPanelVisible()); + testContext.hideInputPanel(); + + QTest::mouseClick(view.focusProxy(), Qt::LeftButton, 0, textInputCenter); + QTRY_VERIFY(testContext.isInputPanelVisible()); + + view.setHtml("

nothing to input here

"); + QVERIFY(loadFinishedSpy.wait()); + testContext.hideInputPanel(); + + QPoint paraCenter = elementCenter(view.page(), "para"); + QTest::mouseClick(view.focusProxy(), Qt::LeftButton, 0, paraCenter); + + QVERIFY(!testContext.isInputPanelVisible()); + + // Check sending RequestSoftwareInputPanel event + view.page()->setHtml("" + " " + "
abc
" + ""); + QVERIFY(loadFinishedSpy.wait()); + + QPoint btnDivCenter = elementCenter(view.page(), "btnDiv"); + QTest::mouseClick(view.focusProxy(), Qt::LeftButton, 0, btnDivCenter); + + QVERIFY(!testContext.isInputPanelVisible()); +} + QTEST_MAIN(tst_QWebEngineView) #include "tst_qwebengineview.moc" -- cgit v1.2.3