From dd7917e0203a9144719214c5a5d36fcd7a0b6f93 Mon Sep 17 00:00:00 2001 From: Peter Varga Date: Tue, 23 Aug 2016 13:32:55 +0200 Subject: Add support of colored underline and background to InputMethodEvent Moreover, unskip and update inputMethodsTextFormat widget auto test and move it to the tst_QWebEngineView tests. New manual test has been also added for testing input methods format. Task-number: QTBUG-55766 Change-Id: I4c71e15cb426925f76c770266a3c20f1cc12b687 Reviewed-by: Allan Sandfeld Jensen --- .../widgets/qwebenginepage/tst_qwebenginepage.cpp | 57 ------------------- .../widgets/qwebengineview/tst_qwebengineview.cpp | 65 ++++++++++++++++++++++ 2 files changed, 65 insertions(+), 57 deletions(-) (limited to 'tests/auto/widgets') diff --git a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp index 88b7596d9..2d56d3521 100644 --- a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp +++ b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp @@ -155,8 +155,6 @@ private Q_SLOTS: void consoleOutput(); void inputMethods_data(); void inputMethods(); - void inputMethodsTextFormat_data(); - void inputMethodsTextFormat(); void errorPageExtension(); void errorPageExtensionLoadFinished(); void userAgentNewlineStripping(); @@ -2405,61 +2403,6 @@ void tst_QWebEnginePage::inputMethods() #endif } -void tst_QWebEnginePage::inputMethodsTextFormat_data() -{ - QTest::addColumn("string"); - QTest::addColumn("start"); - QTest::addColumn("length"); - - QTest::newRow("") << QString("") << 0 << 0; - QTest::newRow("Q") << QString("Q") << 0 << 1; - QTest::newRow("Qt") << QString("Qt") << 0 << 1; - QTest::newRow("Qt") << QString("Qt") << 0 << 2; - QTest::newRow("Qt") << QString("Qt") << 1 << 1; - QTest::newRow("Qt ") << QString("Qt ") << 0 << 1; - QTest::newRow("Qt ") << QString("Qt ") << 1 << 1; - QTest::newRow("Qt ") << QString("Qt ") << 2 << 1; - QTest::newRow("Qt ") << QString("Qt ") << 2 << -1; - QTest::newRow("Qt ") << QString("Qt ") << -2 << 3; - QTest::newRow("Qt ") << QString("Qt ") << 0 << 3; - QTest::newRow("Qt by") << QString("Qt by") << 0 << 1; - QTest::newRow("Qt by Nokia") << QString("Qt by Nokia") << 0 << 1; -} - - -void tst_QWebEnginePage::inputMethodsTextFormat() -{ -#if !defined(QINPUTMETHODEVENT_TEXTFORMAT) - QSKIP("QINPUTMETHODEVENT_TEXTFORMAT"); -#else - QWebEnginePage* page = new QWebEnginePage; - QWebEngineView* view = new QWebEngineView; - view->setPage(page); - page->settings()->setFontFamily(QWebEngineSettings::SerifFont, "FooSerifFont"); - page->setHtml("" \ - ""); - evaluateJavaScriptSync(page, "document.getElementById('input1').focus()"); - page->mainFrame()->setFocus(); - view->show(); - - QFETCH(QString, string); - QFETCH(int, start); - QFETCH(int, length); - - QList attrs; - QTextCharFormat format; - format.setUnderlineStyle(QTextCharFormat::SingleUnderline); - format.setUnderlineColor(Qt::red); - attrs.append(QInputMethodEvent::Attribute(QInputMethodEvent::TextFormat, start, length, format)); - QInputMethodEvent im(string, attrs); - page->event(&im); - - QTest::qWait(1000); - - delete view; -#endif -} - void tst_QWebEnginePage::protectBindingsRuntimeObjectsFromCollector() { #if !defined(QWEBENGINEPAGE_CREATEPLUGIN) diff --git a/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp b/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp index ac142bb38..156c56933 100644 --- a/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp +++ b/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp @@ -80,6 +80,8 @@ private Q_SLOTS: void focusOnNavigation(); void changeLocale(); + void inputMethodsTextFormat_data(); + void inputMethodsTextFormat(); }; // This will be called before the first test function is executed. @@ -859,5 +861,68 @@ void tst_QWebEngineView::changeLocale() QCOMPARE(viewDE.title(), QStringLiteral("Nicht verf\u00FCgbar: %1").arg(url.toString())); } +void tst_QWebEngineView::inputMethodsTextFormat_data() +{ + QTest::addColumn("string"); + QTest::addColumn("start"); + QTest::addColumn("length"); + QTest::addColumn("underlineStyle"); + QTest::addColumn("underlineColor"); + QTest::addColumn("backgroundColor"); + + QTest::newRow("") << QString("") << 0 << 0 << static_cast(QTextCharFormat::SingleUnderline) << QColor("red") << QColor(); + QTest::newRow("Q") << QString("Q") << 0 << 1 << static_cast(QTextCharFormat::SingleUnderline) << QColor("red") << QColor(); + QTest::newRow("Qt") << QString("Qt") << 0 << 1 << static_cast(QTextCharFormat::SingleUnderline) << QColor("red") << QColor(); + QTest::newRow("Qt") << QString("Qt") << 0 << 2 << static_cast(QTextCharFormat::SingleUnderline) << QColor("red") << QColor(); + QTest::newRow("Qt") << QString("Qt") << 1 << 1 << static_cast(QTextCharFormat::SingleUnderline) << QColor("red") << QColor(); + QTest::newRow("Qt ") << QString("Qt ") << 0 << 1 << static_cast(QTextCharFormat::SingleUnderline) << QColor("red") << QColor(); + QTest::newRow("Qt ") << QString("Qt ") << 1 << 1 << static_cast(QTextCharFormat::SingleUnderline) << QColor("red") << QColor(); + QTest::newRow("Qt ") << QString("Qt ") << 2 << 1 << static_cast(QTextCharFormat::SingleUnderline) << QColor("red") << QColor(); + QTest::newRow("Qt ") << QString("Qt ") << 2 << -1 << static_cast(QTextCharFormat::SingleUnderline) << QColor("red") << QColor(); + QTest::newRow("Qt ") << QString("Qt ") << -2 << 3 << static_cast(QTextCharFormat::SingleUnderline) << QColor("red") << QColor(); + QTest::newRow("Qt ") << QString("Qt ") << -1 << -1 << static_cast(QTextCharFormat::SingleUnderline) << QColor("red") << QColor(); + QTest::newRow("Qt ") << QString("Qt ") << 0 << 3 << static_cast(QTextCharFormat::SingleUnderline) << QColor("red") << QColor(); + QTest::newRow("The Qt") << QString("The Qt") << 0 << 1 << static_cast(QTextCharFormat::SingleUnderline) << QColor("red") << QColor(); + QTest::newRow("The Qt Company") << QString("The Qt Company") << 0 << 1 << static_cast(QTextCharFormat::SingleUnderline) << QColor("red") << QColor(); + QTest::newRow("The Qt Company") << QString("The Qt Company") << 0 << 3 << static_cast(QTextCharFormat::SingleUnderline) << QColor("green") << QColor(); + QTest::newRow("The Qt Company") << QString("The Qt Company") << 4 << 2 << static_cast(QTextCharFormat::SingleUnderline) << QColor("green") << QColor("red"); + QTest::newRow("The Qt Company") << QString("The Qt Company") << 7 << 7 << static_cast(QTextCharFormat::NoUnderline) << QColor("green") << QColor("red"); + QTest::newRow("The Qt Company") << QString("The Qt Company") << 7 << 7 << static_cast(QTextCharFormat::NoUnderline) << QColor() << QColor("red"); +} + + +void tst_QWebEngineView::inputMethodsTextFormat() +{ + QWebEngineView view; + QSignalSpy loadFinishedSpy(&view, SIGNAL(loadFinished(bool))); + + view.setHtml("" + " " + ""); + QTRY_COMPARE(loadFinishedSpy.count(), 1); + + evaluateJavaScriptSync(view.page(), "document.getElementById('input1').focus()"); + view.show(); + + QFETCH(QString, string); + QFETCH(int, start); + QFETCH(int, length); + QFETCH(int, underlineStyle); + QFETCH(QColor, underlineColor); + QFETCH(QColor, backgroundColor); + + QList attrs; + QTextCharFormat format; + format.setUnderlineStyle(static_cast(underlineStyle)); + format.setUnderlineColor(underlineColor); + if (backgroundColor.isValid()) + format.setBackground(QBrush(backgroundColor)); + attrs.append(QInputMethodEvent::Attribute(QInputMethodEvent::TextFormat, start, length, format)); + + QInputMethodEvent im(string, attrs); + QVERIFY(QApplication::sendEvent(view.focusProxy(), &im)); + QTRY_COMPARE(evaluateJavaScriptSync(view.page(), "document.getElementById('input1').value").toString(), string); +} + QTEST_MAIN(tst_QWebEngineView) #include "tst_qwebengineview.moc" -- cgit v1.2.3