diff options
author | Peter Varga <pvarga@inf.u-szeged.hu> | 2016-08-23 13:32:55 +0200 |
---|---|---|
committer | Peter Varga <pvarga@inf.u-szeged.hu> | 2016-09-23 05:34:16 +0000 |
commit | dd7917e0203a9144719214c5a5d36fcd7a0b6f93 (patch) | |
tree | 1ab6c2d6d4ef0d43e663e30bc59cc3b538456030 /tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp | |
parent | a4dcc5b4894aac423f65fcf9a13394078ee72257 (diff) |
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 <allan.jensen@qt.io>
Diffstat (limited to 'tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp')
-rw-r--r-- | tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp | 65 |
1 files changed, 65 insertions, 0 deletions
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<QString>("string"); + QTest::addColumn<int>("start"); + QTest::addColumn<int>("length"); + QTest::addColumn<int>("underlineStyle"); + QTest::addColumn<QColor>("underlineColor"); + QTest::addColumn<QColor>("backgroundColor"); + + QTest::newRow("") << QString("") << 0 << 0 << static_cast<int>(QTextCharFormat::SingleUnderline) << QColor("red") << QColor(); + QTest::newRow("Q") << QString("Q") << 0 << 1 << static_cast<int>(QTextCharFormat::SingleUnderline) << QColor("red") << QColor(); + QTest::newRow("Qt") << QString("Qt") << 0 << 1 << static_cast<int>(QTextCharFormat::SingleUnderline) << QColor("red") << QColor(); + QTest::newRow("Qt") << QString("Qt") << 0 << 2 << static_cast<int>(QTextCharFormat::SingleUnderline) << QColor("red") << QColor(); + QTest::newRow("Qt") << QString("Qt") << 1 << 1 << static_cast<int>(QTextCharFormat::SingleUnderline) << QColor("red") << QColor(); + QTest::newRow("Qt ") << QString("Qt ") << 0 << 1 << static_cast<int>(QTextCharFormat::SingleUnderline) << QColor("red") << QColor(); + QTest::newRow("Qt ") << QString("Qt ") << 1 << 1 << static_cast<int>(QTextCharFormat::SingleUnderline) << QColor("red") << QColor(); + QTest::newRow("Qt ") << QString("Qt ") << 2 << 1 << static_cast<int>(QTextCharFormat::SingleUnderline) << QColor("red") << QColor(); + QTest::newRow("Qt ") << QString("Qt ") << 2 << -1 << static_cast<int>(QTextCharFormat::SingleUnderline) << QColor("red") << QColor(); + QTest::newRow("Qt ") << QString("Qt ") << -2 << 3 << static_cast<int>(QTextCharFormat::SingleUnderline) << QColor("red") << QColor(); + QTest::newRow("Qt ") << QString("Qt ") << -1 << -1 << static_cast<int>(QTextCharFormat::SingleUnderline) << QColor("red") << QColor(); + QTest::newRow("Qt ") << QString("Qt ") << 0 << 3 << static_cast<int>(QTextCharFormat::SingleUnderline) << QColor("red") << QColor(); + QTest::newRow("The Qt") << QString("The Qt") << 0 << 1 << static_cast<int>(QTextCharFormat::SingleUnderline) << QColor("red") << QColor(); + QTest::newRow("The Qt Company") << QString("The Qt Company") << 0 << 1 << static_cast<int>(QTextCharFormat::SingleUnderline) << QColor("red") << QColor(); + QTest::newRow("The Qt Company") << QString("The Qt Company") << 0 << 3 << static_cast<int>(QTextCharFormat::SingleUnderline) << QColor("green") << QColor(); + QTest::newRow("The Qt Company") << QString("The Qt Company") << 4 << 2 << static_cast<int>(QTextCharFormat::SingleUnderline) << QColor("green") << QColor("red"); + QTest::newRow("The Qt Company") << QString("The Qt Company") << 7 << 7 << static_cast<int>(QTextCharFormat::NoUnderline) << QColor("green") << QColor("red"); + QTest::newRow("The Qt Company") << QString("The Qt Company") << 7 << 7 << static_cast<int>(QTextCharFormat::NoUnderline) << QColor() << QColor("red"); +} + + +void tst_QWebEngineView::inputMethodsTextFormat() +{ + QWebEngineView view; + QSignalSpy loadFinishedSpy(&view, SIGNAL(loadFinished(bool))); + + view.setHtml("<html><body>" + " <input type='text' id='input1' style='font-family: serif' value='' maxlength='20'/>" + "</body></html>"); + 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<QInputMethodEvent::Attribute> attrs; + QTextCharFormat format; + format.setUnderlineStyle(static_cast<QTextCharFormat::UnderlineStyle>(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" |