diff options
author | Peter Varga <pvarga@inf.u-szeged.hu> | 2016-11-29 13:10:21 +0100 |
---|---|---|
committer | Peter Varga <pvarga@inf.u-szeged.hu> | 2017-04-12 15:02:36 +0000 |
commit | 78417958b7172ec4968088fc3a908a219ed848f6 (patch) | |
tree | 33ddd78db29b945fe7673c12b2757ac0bcc59d13 /tests/auto/widgets/qwebenginepage | |
parent | ab82c1d1adcc79e56d8287ea322ab039dedd8b32 (diff) |
Fix text selection and input method query
Instruct the render process to change the text selection if it was
requested via an input method event. Raise the selectionChanged() signal
when all the corresponding input method properties are set.
Moreover, add back the remaining input method widget auto tests. The
updated tests are moved to the QWebEngineView tests since the
corresponding APIs (inputMethodQuery() and input event handling) are now
available via the QWebEngineView's focus proxy (aka RWHV).
Task-number: QTBUG-55766
Change-Id: Ia0022d5f38b31dd59b084ff42e4abc2780ae90ec
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'tests/auto/widgets/qwebenginepage')
-rw-r--r-- | tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp | 565 |
1 files changed, 0 insertions, 565 deletions
diff --git a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp index 4d073e94c..b03418aea 100644 --- a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp +++ b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp @@ -120,8 +120,6 @@ private Q_SLOTS: void testLocalStorageVisibility(); void testEnablePersistentStorage(); void consoleOutput(); - void inputMethods_data(); - void inputMethods(); void errorPageExtension(); void errorPageExtensionLoadFinished(); void userAgentNewlineStripping(); @@ -1631,569 +1629,6 @@ void tst_QWebEnginePage::backActionUpdate() QVERIFY(action->isEnabled()); } -void tst_QWebEnginePage::inputMethods_data() -{ - QTest::addColumn<QString>("viewType"); - QTest::newRow("QWebEngineView") << "QWebEngineView"; - QTest::newRow("QGraphicsWebView") << "QGraphicsWebView"; -} - -#if defined(QWEBENGINEPAGE_INPUTMETHODQUERY) -static void clickOnPage(QWebEnginePage* page, const QPoint& position) -{ - QMouseEvent evpres(QEvent::MouseButtonPress, position, Qt::LeftButton, Qt::NoButton, Qt::NoModifier); - page->event(&evpres); - QMouseEvent evrel(QEvent::MouseButtonRelease, position, Qt::LeftButton, Qt::NoButton, Qt::NoModifier); - page->event(&evrel); -} -#endif - -void tst_QWebEnginePage::inputMethods() -{ -#if !defined(QWEBENGINEPAGE_INPUTMETHODQUERY) - QSKIP("QWEBENGINEPAGE_INPUTMETHODQUERY"); -#else - QFETCH(QString, viewType); - QWebEnginePage* page = new QWebEnginePage; - QObject* view = 0; - QScopedPointer<QObject> container(0); - if (viewType == "QWebEngineView") { - QWebEngineView* wv = new QWebEngineView; - wv->setPage(page); - view = wv; - container.reset(view); - } else if (viewType == "QGraphicsWebView") { - QGraphicsWebView* wv = new QGraphicsWebView; - wv->setPage(page); - view = wv; - - QGraphicsView* gv = new QGraphicsView; - QGraphicsScene* scene = new QGraphicsScene(gv); - gv->setScene(scene); - scene->addItem(wv); - wv->setGeometry(QRect(0, 0, 500, 500)); - - container.reset(gv); - } else - QVERIFY2(false, "Unknown view type"); - - page->settings()->setFontFamily(QWebEngineSettings::SerifFont, page->settings()->fontFamily(QWebEngineSettings::FixedFont)); - page->setHtml("<html><body>" \ - "<input type='text' id='input1' style='font-family: serif' value='' maxlength='20'/><br>" \ - "<input type='password'/>" \ - "</body></html>"); - page->mainFrame()->setFocus(); - - TestInputContext testContext; - - QWebEngineElementCollection inputs = page->mainFrame()->documentElement().findAll("input"); - QPoint textInputCenter = inputs.at(0).geometry().center(); - - clickOnPage(page, textInputCenter); - - //ImMicroFocus - QVariant variant = page->inputMethodQuery(Qt::ImMicroFocus); - QVERIFY(inputs.at(0).geometry().contains(variant.toRect().topLeft())); - - // We assigned the serif font famility to be the same as the fixef font family. - // Then test ImFont on a serif styled element, we should get our fixef font family. - variant = page->inputMethodQuery(Qt::ImFont); - QFont font = variant.value<QFont>(); - QCOMPARE(page->settings()->fontFamily(QWebEngineSettings::FixedFont), font.family()); - - QList<QInputMethodEvent::Attribute> inputAttributes; - - //Insert text. - { - QInputMethodEvent eventText("QtWebEngine", inputAttributes); - QSignalSpy signalSpy(page, SIGNAL(microFocusChanged())); - page->event(&eventText); - QCOMPARE(signalSpy.count(), 0); - } - - { - QInputMethodEvent eventText("", inputAttributes); - eventText.setCommitString(QString("QtWebEngine"), 0, 0); - page->event(&eventText); - } - - //ImMaximumTextLength - variant = page->inputMethodQuery(Qt::ImMaximumTextLength); - QCOMPARE(20, variant.toInt()); - - //Set selection - inputAttributes << QInputMethodEvent::Attribute(QInputMethodEvent::Selection, 3, 2, QVariant()); - QInputMethodEvent eventSelection("",inputAttributes); - page->event(&eventSelection); - - //ImAnchorPosition - variant = page->inputMethodQuery(Qt::ImAnchorPosition); - int anchorPosition = variant.toInt(); - QCOMPARE(anchorPosition, 3); - - //ImCursorPosition - variant = page->inputMethodQuery(Qt::ImCursorPosition); - int cursorPosition = variant.toInt(); - QCOMPARE(cursorPosition, 5); - - //ImCurrentSelection - variant = page->inputMethodQuery(Qt::ImCurrentSelection); - QString selectionValue = variant.value<QString>(); - QCOMPARE(selectionValue, QString("eb")); - - //Set selection with negative length - inputAttributes << QInputMethodEvent::Attribute(QInputMethodEvent::Selection, 6, -5, QVariant()); - QInputMethodEvent eventSelection3("",inputAttributes); - page->event(&eventSelection3); - - //ImAnchorPosition - variant = page->inputMethodQuery(Qt::ImAnchorPosition); - anchorPosition = variant.toInt(); - QCOMPARE(anchorPosition, 1); - - //ImCursorPosition - variant = page->inputMethodQuery(Qt::ImCursorPosition); - cursorPosition = variant.toInt(); - QCOMPARE(cursorPosition, 6); - - //ImCurrentSelection - variant = page->inputMethodQuery(Qt::ImCurrentSelection); - selectionValue = variant.value<QString>(); - QCOMPARE(selectionValue, QString("tWebK")); - - //ImSurroundingText - variant = page->inputMethodQuery(Qt::ImSurroundingText); - QString value = variant.value<QString>(); - QCOMPARE(value, QString("QtWebEngine")); - - { - QList<QInputMethodEvent::Attribute> attributes; - // Clear the selection, so the next test does not clear any contents. - QInputMethodEvent::Attribute newSelection(QInputMethodEvent::Selection, 0, 0, QVariant()); - attributes.append(newSelection); - QInputMethodEvent event("composition", attributes); - page->event(&event); - } - - // A ongoing composition should not change the surrounding text before it is committed. - variant = page->inputMethodQuery(Qt::ImSurroundingText); - value = variant.value<QString>(); - QCOMPARE(value, QString("QtWebEngine")); - - // Cancel current composition first - inputAttributes << QInputMethodEvent::Attribute(QInputMethodEvent::Selection, 0, 0, QVariant()); - QInputMethodEvent eventSelection4("", inputAttributes); - page->event(&eventSelection4); - - // START - Tests for Selection when the Editor is NOT in Composition mode - - // LEFT to RIGHT selection - // Deselect the selection by sending MouseButtonPress events - // This moves the current cursor to the end of the text - clickOnPage(page, textInputCenter); - - { - QList<QInputMethodEvent::Attribute> attributes; - QInputMethodEvent event(QString(), attributes); - event.setCommitString("XXX", 0, 0); - page->event(&event); - event.setCommitString(QString(), -2, 2); // Erase two characters. - page->event(&event); - event.setCommitString(QString(), -1, 1); // Erase one character. - page->event(&event); - variant = page->inputMethodQuery(Qt::ImSurroundingText); - value = variant.value<QString>(); - QCOMPARE(value, QString("QtWebEngine")); - } - - //Move to the start of the line - page->triggerAction(QWebEnginePage::MoveToStartOfLine); - - QKeyEvent keyRightEventPress(QEvent::KeyPress, Qt::Key_Right, Qt::NoModifier); - QKeyEvent keyRightEventRelease(QEvent::KeyRelease, Qt::Key_Right, Qt::NoModifier); - - //Move 2 characters RIGHT - for (int j = 0; j < 2; ++j) { - page->event(&keyRightEventPress); - page->event(&keyRightEventRelease); - } - - //Select to the end of the line - page->triggerAction(QWebEnginePage::SelectEndOfLine); - - //ImAnchorPosition QtWebEngine - variant = page->inputMethodQuery(Qt::ImAnchorPosition); - anchorPosition = variant.toInt(); - QCOMPARE(anchorPosition, 2); - - //ImCursorPosition - variant = page->inputMethodQuery(Qt::ImCursorPosition); - cursorPosition = variant.toInt(); - QCOMPARE(cursorPosition, 8); - - //ImCurrentSelection - variant = page->inputMethodQuery(Qt::ImCurrentSelection); - selectionValue = variant.value<QString>(); - QCOMPARE(selectionValue, QString("WebKit")); - - //RIGHT to LEFT selection - //Deselect the selection (this moves the current cursor to the end of the text) - clickOnPage(page, textInputCenter); - - //ImAnchorPosition - variant = page->inputMethodQuery(Qt::ImAnchorPosition); - anchorPosition = variant.toInt(); - QCOMPARE(anchorPosition, 8); - - //ImCursorPosition - variant = page->inputMethodQuery(Qt::ImCursorPosition); - cursorPosition = variant.toInt(); - QCOMPARE(cursorPosition, 8); - - //ImCurrentSelection - variant = page->inputMethodQuery(Qt::ImCurrentSelection); - selectionValue = variant.value<QString>(); - QCOMPARE(selectionValue, QString("")); - - QKeyEvent keyLeftEventPress(QEvent::KeyPress, Qt::Key_Left, Qt::NoModifier); - QKeyEvent keyLeftEventRelease(QEvent::KeyRelease, Qt::Key_Left, Qt::NoModifier); - - //Move 2 characters LEFT - for (int i = 0; i < 2; ++i) { - page->event(&keyLeftEventPress); - page->event(&keyLeftEventRelease); - } - - //Select to the start of the line - page->triggerAction(QWebEnginePage::SelectStartOfLine); - - //ImAnchorPosition - variant = page->inputMethodQuery(Qt::ImAnchorPosition); - anchorPosition = variant.toInt(); - QCOMPARE(anchorPosition, 6); - - //ImCursorPosition - variant = page->inputMethodQuery(Qt::ImCursorPosition); - cursorPosition = variant.toInt(); - QCOMPARE(cursorPosition, 0); - - //ImCurrentSelection - variant = page->inputMethodQuery(Qt::ImCurrentSelection); - selectionValue = variant.value<QString>(); - QCOMPARE(selectionValue, QString("QtWebK")); - - //END - Tests for Selection when the Editor is not in Composition mode - - page->setHtml("<html><body>" \ - "<input type='text' id='input4' value='QtWebEngine inputMethod'/>" \ - "</body></html>"); - evaluateJavaScriptSync(page, "var inputEle = document.getElementById('input4'); inputEle.focus(); inputEle.select();"); - - // Clear the selection, also cancel the ongoing composition if there is one. - { - QList<QInputMethodEvent::Attribute> attributes; - QInputMethodEvent::Attribute newSelection(QInputMethodEvent::Selection, 0, 0, QVariant()); - attributes.append(newSelection); - QInputMethodEvent event("", attributes); - page->event(&event); - } - - // ImCurrentSelection - variant = page->inputMethodQuery(Qt::ImCurrentSelection); - selectionValue = variant.value<QString>(); - QCOMPARE(selectionValue, QString("")); - - variant = page->inputMethodQuery(Qt::ImSurroundingText); - QString surroundingValue = variant.value<QString>(); - QCOMPARE(surroundingValue, QString("QtWebEngine inputMethod")); - - // ImAnchorPosition - variant = page->inputMethodQuery(Qt::ImAnchorPosition); - anchorPosition = variant.toInt(); - QCOMPARE(anchorPosition, 0); - - // ImCursorPosition - variant = page->inputMethodQuery(Qt::ImCursorPosition); - cursorPosition = variant.toInt(); - QCOMPARE(cursorPosition, 0); - - // 1. Insert a character to the beginning of the line. - // Send temporary text, which makes the editor has composition 'm'. - { - QList<QInputMethodEvent::Attribute> attributes; - QInputMethodEvent event("m", attributes); - page->event(&event); - } - - // ImCurrentSelection - variant = page->inputMethodQuery(Qt::ImCurrentSelection); - selectionValue = variant.value<QString>(); - QCOMPARE(selectionValue, QString("")); - - // ImSurroundingText - variant = page->inputMethodQuery(Qt::ImSurroundingText); - surroundingValue = variant.value<QString>(); - QCOMPARE(surroundingValue, QString("QtWebEngine inputMethod")); - - // ImCursorPosition - variant = page->inputMethodQuery(Qt::ImCursorPosition); - cursorPosition = variant.toInt(); - QCOMPARE(cursorPosition, 0); - - // ImAnchorPosition - variant = page->inputMethodQuery(Qt::ImAnchorPosition); - anchorPosition = variant.toInt(); - QCOMPARE(anchorPosition, 0); - - // Send temporary text, which makes the editor has composition 'n'. - { - QList<QInputMethodEvent::Attribute> attributes; - QInputMethodEvent event("n", attributes); - page->event(&event); - } - - // ImCurrentSelection - variant = page->inputMethodQuery(Qt::ImCurrentSelection); - selectionValue = variant.value<QString>(); - QCOMPARE(selectionValue, QString("")); - - // ImSurroundingText - variant = page->inputMethodQuery(Qt::ImSurroundingText); - surroundingValue = variant.value<QString>(); - QCOMPARE(surroundingValue, QString("QtWebEngine inputMethod")); - - // ImCursorPosition - variant = page->inputMethodQuery(Qt::ImCursorPosition); - cursorPosition = variant.toInt(); - QCOMPARE(cursorPosition, 0); - - // ImAnchorPosition - variant = page->inputMethodQuery(Qt::ImAnchorPosition); - anchorPosition = variant.toInt(); - QCOMPARE(anchorPosition, 0); - - // Send commit text, which makes the editor conforms composition. - { - QList<QInputMethodEvent::Attribute> attributes; - QInputMethodEvent event("", attributes); - event.setCommitString("o"); - page->event(&event); - } - - // ImCurrentSelection - variant = page->inputMethodQuery(Qt::ImCurrentSelection); - selectionValue = variant.value<QString>(); - QCOMPARE(selectionValue, QString("")); - - // ImSurroundingText - variant = page->inputMethodQuery(Qt::ImSurroundingText); - surroundingValue = variant.value<QString>(); - QCOMPARE(surroundingValue, QString("oQtWebEngine inputMethod")); - - // ImCursorPosition - variant = page->inputMethodQuery(Qt::ImCursorPosition); - cursorPosition = variant.toInt(); - QCOMPARE(cursorPosition, 1); - - // ImAnchorPosition - variant = page->inputMethodQuery(Qt::ImAnchorPosition); - anchorPosition = variant.toInt(); - QCOMPARE(anchorPosition, 1); - - // 2. insert a character to the middle of the line. - // Send temporary text, which makes the editor has composition 'd'. - { - QList<QInputMethodEvent::Attribute> attributes; - QInputMethodEvent event("d", attributes); - page->event(&event); - } - - // ImCurrentSelection - variant = page->inputMethodQuery(Qt::ImCurrentSelection); - selectionValue = variant.value<QString>(); - QCOMPARE(selectionValue, QString("")); - - // ImSurroundingText - variant = page->inputMethodQuery(Qt::ImSurroundingText); - surroundingValue = variant.value<QString>(); - QCOMPARE(surroundingValue, QString("oQtWebEngine inputMethod")); - - // ImCursorPosition - variant = page->inputMethodQuery(Qt::ImCursorPosition); - cursorPosition = variant.toInt(); - QCOMPARE(cursorPosition, 1); - - // ImAnchorPosition - variant = page->inputMethodQuery(Qt::ImAnchorPosition); - anchorPosition = variant.toInt(); - QCOMPARE(anchorPosition, 1); - - // Send commit text, which makes the editor conforms composition. - { - QList<QInputMethodEvent::Attribute> attributes; - QInputMethodEvent event("", attributes); - event.setCommitString("e"); - page->event(&event); - } - - // ImCurrentSelection - variant = page->inputMethodQuery(Qt::ImCurrentSelection); - selectionValue = variant.value<QString>(); - QCOMPARE(selectionValue, QString("")); - - // ImSurroundingText - variant = page->inputMethodQuery(Qt::ImSurroundingText); - surroundingValue = variant.value<QString>(); - QCOMPARE(surroundingValue, QString("oeQtWebEngine inputMethod")); - - // ImCursorPosition - variant = page->inputMethodQuery(Qt::ImCursorPosition); - cursorPosition = variant.toInt(); - QCOMPARE(cursorPosition, 2); - - // ImAnchorPosition - variant = page->inputMethodQuery(Qt::ImAnchorPosition); - anchorPosition = variant.toInt(); - QCOMPARE(anchorPosition, 2); - - // 3. Insert a character to the end of the line. - page->triggerAction(QWebEnginePage::MoveToEndOfLine); - - // Send temporary text, which makes the editor has composition 't'. - { - QList<QInputMethodEvent::Attribute> attributes; - QInputMethodEvent event("t", attributes); - page->event(&event); - } - - // ImCurrentSelection - variant = page->inputMethodQuery(Qt::ImCurrentSelection); - selectionValue = variant.value<QString>(); - QCOMPARE(selectionValue, QString("")); - - // ImSurroundingText - variant = page->inputMethodQuery(Qt::ImSurroundingText); - surroundingValue = variant.value<QString>(); - QCOMPARE(surroundingValue, QString("oeQtWebEngine inputMethod")); - - // ImCursorPosition - variant = page->inputMethodQuery(Qt::ImCursorPosition); - cursorPosition = variant.toInt(); - QCOMPARE(cursorPosition, 22); - - // ImAnchorPosition - variant = page->inputMethodQuery(Qt::ImAnchorPosition); - anchorPosition = variant.toInt(); - QCOMPARE(anchorPosition, 22); - - // Send commit text, which makes the editor conforms composition. - { - QList<QInputMethodEvent::Attribute> attributes; - QInputMethodEvent event("", attributes); - event.setCommitString("t"); - page->event(&event); - } - - // ImCurrentSelection - variant = page->inputMethodQuery(Qt::ImCurrentSelection); - selectionValue = variant.value<QString>(); - QCOMPARE(selectionValue, QString("")); - - // ImSurroundingText - variant = page->inputMethodQuery(Qt::ImSurroundingText); - surroundingValue = variant.value<QString>(); - QCOMPARE(surroundingValue, QString("oeQtWebEngine inputMethodt")); - - // ImCursorPosition - variant = page->inputMethodQuery(Qt::ImCursorPosition); - cursorPosition = variant.toInt(); - QCOMPARE(cursorPosition, 23); - - // ImAnchorPosition - variant = page->inputMethodQuery(Qt::ImAnchorPosition); - anchorPosition = variant.toInt(); - QCOMPARE(anchorPosition, 23); - - // 4. Replace the selection. - page->triggerAction(QWebEnginePage::SelectPreviousWord); - - // ImCurrentSelection - variant = page->inputMethodQuery(Qt::ImCurrentSelection); - selectionValue = variant.value<QString>(); - QCOMPARE(selectionValue, QString("inputMethodt")); - - // ImSurroundingText - variant = page->inputMethodQuery(Qt::ImSurroundingText); - surroundingValue = variant.value<QString>(); - QCOMPARE(surroundingValue, QString("oeQtWebEngine inputMethodt")); - - // ImCursorPosition - variant = page->inputMethodQuery(Qt::ImCursorPosition); - cursorPosition = variant.toInt(); - QCOMPARE(cursorPosition, 11); - - // ImAnchorPosition - variant = page->inputMethodQuery(Qt::ImAnchorPosition); - anchorPosition = variant.toInt(); - QCOMPARE(anchorPosition, 23); - - // Send temporary text, which makes the editor has composition 'w'. - { - QList<QInputMethodEvent::Attribute> attributes; - QInputMethodEvent event("w", attributes); - page->event(&event); - } - - // ImCurrentSelection - variant = page->inputMethodQuery(Qt::ImCurrentSelection); - selectionValue = variant.value<QString>(); - QCOMPARE(selectionValue, QString("")); - - // ImSurroundingText - variant = page->inputMethodQuery(Qt::ImSurroundingText); - surroundingValue = variant.value<QString>(); - QCOMPARE(surroundingValue, QString("oeQtWebEngine ")); - - // ImCursorPosition - variant = page->inputMethodQuery(Qt::ImCursorPosition); - cursorPosition = variant.toInt(); - QCOMPARE(cursorPosition, 11); - - // ImAnchorPosition - variant = page->inputMethodQuery(Qt::ImAnchorPosition); - anchorPosition = variant.toInt(); - QCOMPARE(anchorPosition, 11); - - // Send commit text, which makes the editor conforms composition. - { - QList<QInputMethodEvent::Attribute> attributes; - QInputMethodEvent event("", attributes); - event.setCommitString("2"); - page->event(&event); - } - - // ImCurrentSelection - variant = page->inputMethodQuery(Qt::ImCurrentSelection); - selectionValue = variant.value<QString>(); - QCOMPARE(selectionValue, QString("")); - - // ImSurroundingText - variant = page->inputMethodQuery(Qt::ImSurroundingText); - surroundingValue = variant.value<QString>(); - QCOMPARE(surroundingValue, QString("oeQtWebEngine 2")); - - // ImCursorPosition - variant = page->inputMethodQuery(Qt::ImCursorPosition); - cursorPosition = variant.toInt(); - QCOMPARE(cursorPosition, 12); - - // ImAnchorPosition - variant = page->inputMethodQuery(Qt::ImAnchorPosition); - anchorPosition = variant.toInt(); - QCOMPARE(anchorPosition, 12); -#endif -} - void tst_QWebEnginePage::protectBindingsRuntimeObjectsFromCollector() { #if !defined(QWEBENGINEPAGE_CREATEPLUGIN) |