diff options
author | Oswald Buddenhagen <oswald.buddenhagen@qt.io> | 2017-02-01 20:50:41 +0100 |
---|---|---|
committer | Oswald Buddenhagen <oswald.buddenhagen@qt.io> | 2017-02-01 20:58:12 +0100 |
commit | b5d7ec9226eee41d9c3516bf51dc48c283e8b13e (patch) | |
tree | 994d2f09fd2106efed07e007becffed6e56a584c /tests | |
parent | 3c4c080e46a8fa229d7e1fdaee82f750b3558aa0 (diff) | |
parent | 2313a580c0e3f0636a12697ba4b872bfdccbcf7f (diff) |
Merge dev into 5.9
Change-Id: Id919bfd67d9d435fd5a05a892151a12ae5bcd3c0
Diffstat (limited to 'tests')
7 files changed, 315 insertions, 205 deletions
diff --git a/tests/auto/quick/publicapi/tst_publicapi.cpp b/tests/auto/quick/publicapi/tst_publicapi.cpp index f9fd854cc..5cc0d18df 100644 --- a/tests/auto/quick/publicapi/tst_publicapi.cpp +++ b/tests/auto/quick/publicapi/tst_publicapi.cpp @@ -34,6 +34,7 @@ #include <QQmlListProperty> #include <QtTest/QtTest> #include <QtWebEngine/QQuickWebEngineProfile> +#include <QtWebEngine/QQuickWebEngineScript> #include <private/qquickwebengineview_p.h> #include <private/qquickwebenginecertificateerror_p.h> #include <private/qquickwebenginedialogrequests_p.h> @@ -42,7 +43,6 @@ #include <private/qquickwebengineloadrequest_p.h> #include <private/qquickwebenginenavigationrequest_p.h> #include <private/qquickwebenginenewviewrequest_p.h> -#include <private/qquickwebenginescript_p.h> #include <private/qquickwebenginesettings_p.h> #include <private/qquickwebenginesingleton_p.h> #include <private/qquickwebenginecontextmenurequest_p.h> diff --git a/tests/auto/quick/qmltests/data/tst_userScripts.qml b/tests/auto/quick/qmltests/data/tst_userScripts.qml index 88fa6f6e3..e9a4eba99 100644 --- a/tests/auto/quick/qmltests/data/tst_userScripts.qml +++ b/tests/auto/quick/qmltests/data/tst_userScripts.qml @@ -61,6 +61,12 @@ Item { } TestWebEngineView { + id: webEngineView2 + width: 400 + height: 300 + } + + TestWebEngineView { id: webEngineViewWithConditionalUserScripts width: 400 height: 300 @@ -82,6 +88,7 @@ Item { function init() { webEngineView.url = ""; webEngineView.userScripts = []; + webEngineView.profile.userScripts = []; } function test_oneScript() { @@ -173,5 +180,17 @@ Item { webEngineView.waitForLoadSucceeded(); tryCompare(webEngineView, "title", "Test page with huge link area"); } + + function test_profileWideScript() { + webEngineView.profile.userScripts = [ changeDocumentTitleScript ]; + + webEngineView.url = Qt.resolvedUrl("test1.html"); + webEngineView.waitForLoadSucceeded(); + compare(webEngineView.title, "New title"); + + webEngineView2.url = Qt.resolvedUrl("test1.html"); + webEngineView2.waitForLoadSucceeded(); + compare(webEngineView2.title, "New title"); + } } } diff --git a/tests/auto/quick/qquickwebengineview/tst_qquickwebengineview.cpp b/tests/auto/quick/qquickwebengineview/tst_qquickwebengineview.cpp index 2ae699310..8df84e048 100644 --- a/tests/auto/quick/qquickwebengineview/tst_qquickwebengineview.cpp +++ b/tests/auto/quick/qquickwebengineview/tst_qquickwebengineview.cpp @@ -34,6 +34,7 @@ #include <QtGui/qpa/qwindowsysteminterface.h> #include <QtQml/QQmlEngine> #include <QtTest/QtTest> +#include <QtWebEngine/QQuickWebEngineProfile> #include <private/qquickwebengineview_p.h> #include <functional> @@ -77,6 +78,7 @@ private Q_SLOTS: void inputEventForwardingDisabledWhenActiveFocusOnPressDisabled(); void changeLocale(); + void userScripts(); private: inline QQuickWebEngineView *newWebEngineView(); @@ -720,5 +722,28 @@ void tst_QQuickWebEngineView::changeLocale() delete viewEN; } +void tst_QQuickWebEngineView::userScripts() +{ + QScopedPointer<QQuickWebEngineView> webEngineView1(newWebEngineView()); + webEngineView1->setParentItem(m_window->contentItem()); + QScopedPointer<QQuickWebEngineView> webEngineView2(newWebEngineView()); + webEngineView2->setParentItem(m_window->contentItem()); + + QQmlListReference list(webEngineView1->profile(), "userScripts"); + QQuickWebEngineScript script; + script.setSourceCode("document.title = 'New title';"); + list.append(&script); + + webEngineView1->setUrl(urlFromTestPath("html/basic_page.html")); + QVERIFY(waitForLoadSucceeded(webEngineView1.data())); + QTRY_COMPARE(webEngineView1->title(), QStringLiteral("New title")); + + webEngineView2->setUrl(urlFromTestPath("html/basic_page.html")); + QVERIFY(waitForLoadSucceeded(webEngineView2.data())); + QTRY_COMPARE(webEngineView2->title(), QStringLiteral("New title")); + + list.clear(); +} + QTEST_MAIN(tst_QQuickWebEngineView) #include "tst_qquickwebengineview.moc" diff --git a/tests/auto/widgets/qwebenginepage/qwebenginepage.pro b/tests/auto/widgets/qwebenginepage/qwebenginepage.pro index fef92c311..e0765736e 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, use_pdf): DEFINES+=QWEBENGINEPAGE_PDFPRINTINGENABLED diff --git a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp index 5467ce39e..7e78e2b0e 100644 --- a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp +++ b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp @@ -32,17 +32,15 @@ #include <QOpenGLWidget> #include <QPaintEngine> #include <QPushButton> +#include <QScreen> #include <QStateMachine> -#include <QStyle> #include <QtGui/QClipboard> #include <QtTest/QtTest> #include <QTextCharFormat> #include <QWebChannel> -#include <private/qinputmethod_p.h> #include <qnetworkcookiejar.h> #include <qnetworkreply.h> #include <qnetworkrequest.h> -#include <qpa/qplatforminputcontext.h> #include <qwebenginedownloaditem.h> #include <qwebenginefullscreenrequest.h> #include <qwebenginehistory.h> @@ -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 @@ -1671,24 +1637,6 @@ void tst_QWebEnginePage::inputMethods_data() } #if defined(QWEBENGINEPAGE_INPUTMETHODQUERY) -static Qt::InputMethodHints inputMethodHints(QObject* object) -{ - if (QGraphicsObject* o = qobject_cast<QGraphicsObject*>(object)) - return o->inputMethodHints(); - if (QWidget* w = qobject_cast<QWidget*>(object)) - return w->inputMethodHints(); - return Qt::InputMethodHints(); -} - -static bool inputMethodEnabled(QObject* object) -{ - if (QGraphicsObject* o = qobject_cast<QGraphicsObject*>(object)) - return o->flags() & QGraphicsItem::ItemAcceptsInputMethod; - if (QWidget* w = qobject_cast<QWidget*>(object)) - return w->testAttribute(Qt::WA_InputMethodEnabled); - return false; -} - static void clickOnPage(QWebEnginePage* page, const QPoint& position) { QMouseEvent evpres(QEvent::MouseButtonPress, position, Qt::LeftButton, Qt::NoButton, Qt::NoModifier); @@ -1741,32 +1689,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<QWebEngineView*>(view)) - inputPanel = wv->style()->styleHint(QStyle::SH_RequestSoftwareInputPanel); - } else if (viewType == "QGraphicsWebView") { - if (QGraphicsWebView* wv = qobject_cast<QGraphicsWebView*>(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())); @@ -1960,38 +1882,6 @@ void tst_QWebEnginePage::inputMethods() //END - Tests for Selection when the Editor is not in Composition mode - //ImhHiddenText - QPoint passwordInputCenter = inputs.at(1).geometry().center(); - clickOnPage(page, passwordInputCenter); - - QVERIFY(inputMethodEnabled(view)); - QVERIFY(inputMethodHints(view) & Qt::ImhHiddenText); - - clickOnPage(page, textInputCenter); - QVERIFY(!(inputMethodHints(view) & Qt::ImhHiddenText)); - - page->setHtml("<html><body><p>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("<html><body>" \ - "<input type='text' id='input3' value='QtWebEngine2'/>" \ - "</body></html>"); - evaluateJavaScriptSync(page, "var inputEle = document.getElementById('input3'); inputEle.focus(); inputEle.select();"); - - //Send empty QInputMethodEvent - QInputMethodEvent emptyEvent; - page->event(&emptyEvent); - - QString inputValue = evaluateJavaScriptSync(page, "document.getElementById('input3').value").toString(); - QCOMPARE(inputValue, QString("QtWebEngine2")); - //END - Test for sending empty QInputMethodEvent - page->setHtml("<html><body>" \ "<input type='text' id='input4' value='QtWebEngine inputMethod'/>" \ "</body></html>"); @@ -2299,98 +2189,6 @@ void tst_QWebEnginePage::inputMethods() variant = page->inputMethodQuery(Qt::ImAnchorPosition); anchorPosition = variant.toInt(); QCOMPARE(anchorPosition, 12); - - // Check sending RequestSoftwareInputPanel event - page->setHtml("<html><body>" \ - "<input type='text' id='input5' value='QtWebEngine inputMethod'/>" \ - "<div id='btnDiv' onclick='i=document.getElementById("input5"); i.focus();'>abc</div>"\ - "</body></html>"); - QWebEngineElement inputElement = page->mainFrame()->findFirstElement("div"); - clickOnPage(page, inputElement.geometry().center()); - - QVERIFY(!testContext.isInputPanelVisible()); - - // START - Newline test for textarea - qApp->processEvents(); - page->setHtml("<html><body>" \ - "<textarea rows='5' cols='1' id='input5' value=''/>" \ - "</body></html>"); - evaluateJavaScriptSync(page, "var inputEle = document.getElementById('input5'); inputEle.focus(); inputEle.select();"); - - // Enter Key without key text - QKeyEvent keyEnter(QEvent::KeyPress, Qt::Key_Enter, Qt::NoModifier); - page->event(&keyEnter); - QList<QInputMethodEvent::Attribute> attribs; - - QInputMethodEvent eventText(QString(), attribs); - eventText.setCommitString("\n"); - page->event(&eventText); - - QInputMethodEvent eventText2(QString(), attribs); - eventText2.setCommitString("third line"); - page->event(&eventText2); - qApp->processEvents(); - - QString inputValue2 = evaluateJavaScriptSync(page, "document.getElementById('input5').value").toString(); - QCOMPARE(inputValue2, QString("\n\nthird line")); - - // Enter Key with key text '\r' - evaluateJavaScriptSync(page, "var inputEle = document.getElementById('input5'); inputEle.value = ''; inputEle.focus(); inputEle.select();"); - inputValue2 = evaluateJavaScriptSync(page, "document.getElementById('input5').value").toString(); - QCOMPARE(inputValue2, QString("")); - - QKeyEvent keyEnterWithCarriageReturn(QEvent::KeyPress, Qt::Key_Enter, Qt::NoModifier, "\r"); - page->event(&keyEnterWithCarriageReturn); - page->event(&eventText); - page->event(&eventText2); - qApp->processEvents(); - - inputValue2 = evaluateJavaScriptSync(page, "document.getElementById('input5').value").toString(); - QCOMPARE(inputValue2, QString("\n\nthird line")); - - // Enter Key with key text '\n' - page->runJavaScript("var inputEle = document.getElementById('input5'); inputEle.value = ''; inputEle.focus(); inputEle.select();"); - inputValue2 = evaluateJavaScriptSync(page, "document.getElementById('input5').value").toString(); - QCOMPARE(inputValue2, QString("")); - - QKeyEvent keyEnterWithLineFeed(QEvent::KeyPress, Qt::Key_Enter, Qt::NoModifier, "\n"); - page->event(&keyEnterWithLineFeed); - page->event(&eventText); - page->event(&eventText2); - qApp->processEvents(); - - inputValue2 = evaluateJavaScriptSync(page, "document.getElementById('input5').value").toString(); - QCOMPARE(inputValue2, QString("\n\nthird line")); - - // Enter Key with key text "\n\r" - page->runJavaScript("var inputEle = document.getElementById('input5'); inputEle.value = ''; inputEle.focus(); inputEle.select();"); - inputValue2 = evaluateJavaScriptSync(page, "document.getElementById('input5').value").toString(); - QCOMPARE(inputValue2, QString("")); - - QKeyEvent keyEnterWithLFCR(QEvent::KeyPress, Qt::Key_Enter, Qt::NoModifier, "\n\r"); - page->event(&keyEnterWithLFCR); - page->event(&eventText); - page->event(&eventText2); - qApp->processEvents(); - - inputValue2 = evaluateJavaScriptSync(page, "document.getElementById('input5').value").toString(); - QCOMPARE(inputValue2, QString("\n\nthird line")); - - // Return Key without key text - page->runJavaScript("var inputEle = document.getElementById('input5'); inputEle.value = ''; inputEle.focus(); inputEle.select();"); - inputValue2 = evaluateJavaScriptSync(page, "document.getElementById('input5').value").toString(); - QCOMPARE(inputValue2, QString("")); - - QKeyEvent keyReturn(QEvent::KeyPress, Qt::Key_Return, Qt::NoModifier); - page->event(&keyReturn); - page->event(&eventText); - page->event(&eventText2); - qApp->processEvents(); - - inputValue2 = evaluateJavaScriptSync(page, "document.getElementById('input5').value").toString(); - QCOMPARE(inputValue2, QString("\n\nthird line")); - - // END - Newline test for textarea #endif } 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 53c7650fb..b173c3474 100644 --- a/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp +++ b/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp @@ -22,8 +22,10 @@ #include <qtest.h> #include "../util.h" +#include <private/qinputmethod_p.h> #include <qpainter.h> #include <qpagelayout.h> +#include <qpa/qplatforminputcontext.h> #include <qwebengineview.h> #include <qwebenginepage.h> #include <qwebenginesettings.h> @@ -39,6 +41,7 @@ #include <QtWebEngineCore/qwebenginehttprequest.h> #include <QTcpServer> #include <QTcpSocket> +#include <QStyle> #define VERIFY_INPUTMETHOD_HINTS(actual, expect) \ QVERIFY(actual == expect); @@ -91,6 +94,11 @@ private Q_SLOTS: void keyboardEvents(); void keyboardFocusAfterPopup(); void postData(); + + void softwareInputPanel(); + void hiddenText(); + void emptyInputMethodEvent(); + void newlineInTextarea(); }; // This will be called before the first test function is executed. @@ -1216,5 +1224,264 @@ void tst_QWebEngineView::postData() server.close(); } +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("<html><body>" + " <input type='text' id='input1' value='' size='50'/>" + "</body></html>"); + 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("<html><body><p id='para'>nothing to input here</p></body></html>"); + 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("<html><body>" + " <input type='text' id='input1' value='QtWebEngine inputMethod'/>" + " <div id='btnDiv' onclick='i=document.getElementById("input1"); i.focus();'>abc</div>" + "</body></html>"); + QVERIFY(loadFinishedSpy.wait()); + + QPoint btnDivCenter = elementCenter(view.page(), "btnDiv"); + QTest::mouseClick(view.focusProxy(), Qt::LeftButton, 0, btnDivCenter); + + QVERIFY(!testContext.isInputPanelVisible()); +} + +void tst_QWebEngineView::hiddenText() +{ + QWebEngineView view; + view.show(); + + QSignalSpy loadFinishedSpy(&view, SIGNAL(loadFinished(bool))); + view.setHtml("<html><body>" + " <input type='text' id='input1' value='QtWebEngine' size='50'/><br>" + " <input type='password' id='password1'/>" + "</body></html>"); + QVERIFY(loadFinishedSpy.wait()); + + QPoint passwordInputCenter = elementCenter(view.page(), "password1"); + QTest::mouseClick(view.focusProxy(), Qt::LeftButton, 0, passwordInputCenter); + QTRY_COMPARE(evaluateJavaScriptSync(view.page(), "document.activeElement.id").toString(), QStringLiteral("password1")); + + QVERIFY(view.focusProxy()->testAttribute(Qt::WA_InputMethodEnabled)); + QVERIFY(view.focusProxy()->inputMethodHints() & Qt::ImhHiddenText); + + 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")); + QVERIFY(!(view.focusProxy()->inputMethodHints() & Qt::ImhHiddenText)); +} + +void tst_QWebEngineView::emptyInputMethodEvent() +{ + QWebEngineView view; + view.show(); + + QSignalSpy selectionChangedSpy(&view, SIGNAL(selectionChanged())); + QSignalSpy loadFinishedSpy(&view, SIGNAL(loadFinished(bool))); + view.setHtml("<html><body>" + " <input type='text' id='input1' value='QtWebEngine'/>" + "</body></html>"); + QVERIFY(loadFinishedSpy.wait()); + + evaluateJavaScriptSync(view.page(), "var inputEle = document.getElementById('input1'); inputEle.focus(); inputEle.select();"); + QTRY_VERIFY(!evaluateJavaScriptSync(view.page(), "window.getSelection().toString()").toString().isEmpty()); + + QEXPECT_FAIL("", "https://bugreports.qt.io/browse/QTBUG-53134", Continue); + QVERIFY(selectionChangedSpy.wait(100)); + QEXPECT_FAIL("", "https://bugreports.qt.io/browse/QTBUG-53134", Continue); + QCOMPARE(selectionChangedSpy.count(), 1); + + // Send empty QInputMethodEvent + QInputMethodEvent emptyEvent; + QApplication::sendEvent(view.focusProxy(), &emptyEvent); + + QString inputValue = evaluateJavaScriptSync(view.page(), "document.getElementById('input1').value").toString(); + QCOMPARE(inputValue, QString("QtWebEngine")); +} + +void tst_QWebEngineView::newlineInTextarea() +{ + QWebEngineView view; + view.show(); + + QSignalSpy loadFinishedSpy(&view, SIGNAL(loadFinished(bool))); + view.page()->setHtml("<html><body>" + " <textarea rows='5' cols='1' id='input1'></textarea>" + "</body></html>"); + QVERIFY(loadFinishedSpy.wait()); + + evaluateJavaScriptSync(view.page(), "var inputEle = document.getElementById('input1'); inputEle.focus(); inputEle.select();"); + QTRY_VERIFY(evaluateJavaScriptSync(view.page(), "document.getElementById('input1').value").toString().isEmpty()); + + // Enter Key without key text + QKeyEvent keyPressEnter(QEvent::KeyPress, Qt::Key_Enter, Qt::NoModifier); + QKeyEvent keyReleaseEnter(QEvent::KeyRelease, Qt::Key_Enter, Qt::NoModifier); + QApplication::sendEvent(view.focusProxy(), &keyPressEnter); + QApplication::sendEvent(view.focusProxy(), &keyReleaseEnter); + + QList<QInputMethodEvent::Attribute> attribs; + + QInputMethodEvent eventText(QString(), attribs); + eventText.setCommitString("\n"); + QApplication::sendEvent(view.focusProxy(), &eventText); + + QInputMethodEvent eventText2(QString(), attribs); + eventText2.setCommitString("third line"); + QApplication::sendEvent(view.focusProxy(), &eventText2); + + qApp->processEvents(); + QTRY_COMPARE(evaluateJavaScriptSync(view.page(), "document.getElementById('input1').value").toString(), QString("\n\nthird line")); + QTRY_COMPARE(view.focusProxy()->inputMethodQuery(Qt::ImSurroundingText).toString(), QString("\n\nthird line")); + + // Enter Key with key text '\r' + evaluateJavaScriptSync(view.page(), "var inputEle = document.getElementById('input1'); inputEle.value = ''; inputEle.focus(); inputEle.select();"); + QTRY_VERIFY(evaluateJavaScriptSync(view.page(), "document.getElementById('input1').value").toString().isEmpty()); + + QKeyEvent keyPressEnterWithCarriageReturn(QEvent::KeyPress, Qt::Key_Enter, Qt::NoModifier, "\r"); + QKeyEvent keyReleaseEnterWithCarriageReturn(QEvent::KeyRelease, Qt::Key_Enter, Qt::NoModifier); + QApplication::sendEvent(view.focusProxy(), &keyPressEnterWithCarriageReturn); + QApplication::sendEvent(view.focusProxy(), &keyReleaseEnterWithCarriageReturn); + + QApplication::sendEvent(view.focusProxy(), &eventText); + QApplication::sendEvent(view.focusProxy(), &eventText2); + + qApp->processEvents(); + QTRY_COMPARE(evaluateJavaScriptSync(view.page(), "document.getElementById('input1').value").toString(), QString("\n\nthird line")); + QTRY_COMPARE(view.focusProxy()->inputMethodQuery(Qt::ImSurroundingText).toString(), QString("\n\nthird line")); + + // Enter Key with key text '\n' + evaluateJavaScriptSync(view.page(), "var inputEle = document.getElementById('input1'); inputEle.value = ''; inputEle.focus(); inputEle.select();"); + QTRY_VERIFY(evaluateJavaScriptSync(view.page(), "document.getElementById('input1').value").toString().isEmpty()); + + QKeyEvent keyPressEnterWithLineFeed(QEvent::KeyPress, Qt::Key_Enter, Qt::NoModifier, "\n"); + QKeyEvent keyReleaseEnterWithLineFeed(QEvent::KeyRelease, Qt::Key_Enter, Qt::NoModifier, "\n"); + QApplication::sendEvent(view.focusProxy(), &keyPressEnterWithLineFeed); + QApplication::sendEvent(view.focusProxy(), &keyReleaseEnterWithLineFeed); + + QApplication::sendEvent(view.focusProxy(), &eventText); + QApplication::sendEvent(view.focusProxy(), &eventText2); + + qApp->processEvents(); + QTRY_COMPARE(evaluateJavaScriptSync(view.page(), "document.getElementById('input1').value").toString(), QString("\n\nthird line")); + QTRY_COMPARE(view.focusProxy()->inputMethodQuery(Qt::ImSurroundingText).toString(), QString("\n\nthird line")); + + // Enter Key with key text "\n\r" + evaluateJavaScriptSync(view.page(), "var inputEle = document.getElementById('input1'); inputEle.value = ''; inputEle.focus(); inputEle.select();"); + QTRY_VERIFY(evaluateJavaScriptSync(view.page(), "document.getElementById('input1').value").toString().isEmpty()); + + QKeyEvent keyPressEnterWithLFCR(QEvent::KeyPress, Qt::Key_Enter, Qt::NoModifier, "\n\r"); + QKeyEvent keyReleaseEnterWithLFCR(QEvent::KeyRelease, Qt::Key_Enter, Qt::NoModifier, "\n\r"); + QApplication::sendEvent(view.focusProxy(), &keyPressEnterWithLFCR); + QApplication::sendEvent(view.focusProxy(), &keyReleaseEnterWithLFCR); + + QApplication::sendEvent(view.focusProxy(), &eventText); + QApplication::sendEvent(view.focusProxy(), &eventText2); + + qApp->processEvents(); + QTRY_COMPARE(evaluateJavaScriptSync(view.page(), "document.getElementById('input1').value").toString(), QString("\n\nthird line")); + QTRY_COMPARE(view.focusProxy()->inputMethodQuery(Qt::ImSurroundingText).toString(), QString("\n\nthird line")); + + // Return Key without key text + evaluateJavaScriptSync(view.page(), "var inputEle = document.getElementById('input1'); inputEle.value = ''; inputEle.focus(); inputEle.select();"); + QTRY_VERIFY(evaluateJavaScriptSync(view.page(), "document.getElementById('input1').value").toString().isEmpty()); + + QKeyEvent keyPressReturn(QEvent::KeyPress, Qt::Key_Enter, Qt::NoModifier); + QKeyEvent keyReleaseReturn(QEvent::KeyRelease, Qt::Key_Enter, Qt::NoModifier); + QApplication::sendEvent(view.focusProxy(), &keyPressReturn); + QApplication::sendEvent(view.focusProxy(), &keyReleaseReturn); + + QApplication::sendEvent(view.focusProxy(), &eventText); + QApplication::sendEvent(view.focusProxy(), &eventText2); + + qApp->processEvents(); + QTRY_COMPARE(evaluateJavaScriptSync(view.page(), "document.getElementById('input1').value").toString(), QString("\n\nthird line")); + QTRY_COMPARE(view.focusProxy()->inputMethodQuery(Qt::ImSurroundingText).toString(), QString("\n\nthird line")); +} + QTEST_MAIN(tst_QWebEngineView) #include "tst_qwebengineview.moc" |