summaryrefslogtreecommitdiffstats
path: root/src/3rdparty/webkit/WebKit/qt/tests
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@nokia.com>2009-10-01 12:43:40 (GMT)
committerSimon Hausmann <simon.hausmann@nokia.com>2009-10-01 12:49:15 (GMT)
commit976adc629192d42882eeba33d5b398618d4445b1 (patch)
tree6bb705cbf1895252e0e37f131e2bf70294668385 /src/3rdparty/webkit/WebKit/qt/tests
parentd2d4fa3365beecc6fe1dca7bcffb8a9167fa991d (diff)
downloadQt-976adc629192d42882eeba33d5b398618d4445b1.zip
Qt-976adc629192d42882eeba33d5b398618d4445b1.tar.gz
Qt-976adc629192d42882eeba33d5b398618d4445b1.tar.bz2
Implementation for QWebPage::inputMethodQuery and QWebPagePrivate::inputMethodEvent
Patch by Joe Ligman <joseph.ligman@nokia.com> on 2009-10-01 Reviewed by Simon Hausmann. https://bugs.webkit.org/show_bug.cgi?id=29681 Some additional changes from axis: * Fixed surrounding text to exclude preedit string * Avoid emission of microFocusChanged during setComposition() * Api/qwebpage.cpp: (QWebPagePrivate::inputMethodEvent): (QWebPage::inputMethodQuery): * WebCoreSupport/EditorClientQt.cpp: (WebCore::EditorClientQt::respondToChangedSelection): * tests/qwebpage/tst_qwebpage.cpp: (tst_QWebPage::inputMethods): git-svn-id: http://svn.webkit.org/repository/webkit/trunk@48967 268f45cc-cd09-0410-ab3c-d52691b4dbfc Signed-off-by: Simon Hausmann <simon.hausmann@nokia.com>
Diffstat (limited to 'src/3rdparty/webkit/WebKit/qt/tests')
-rw-r--r--src/3rdparty/webkit/WebKit/qt/tests/qwebpage/tst_qwebpage.cpp90
1 files changed, 90 insertions, 0 deletions
diff --git a/src/3rdparty/webkit/WebKit/qt/tests/qwebpage/tst_qwebpage.cpp b/src/3rdparty/webkit/WebKit/qt/tests/qwebpage/tst_qwebpage.cpp
index 283950e..8f9a740 100644
--- a/src/3rdparty/webkit/WebKit/qt/tests/qwebpage/tst_qwebpage.cpp
+++ b/src/3rdparty/webkit/WebKit/qt/tests/qwebpage/tst_qwebpage.cpp
@@ -20,6 +20,7 @@
#include <QtTest/QtTest>
+#include <qwebelement.h>
#include <qwebpage.h>
#include <qwidget.h>
#include <qwebview.h>
@@ -114,6 +115,7 @@ private slots:
void testOptionalJSObjects();
void testEnablePersistentStorage();
void consoleOutput();
+ void inputMethods();
void crashTests_LazyInitializationOfMainFrame();
@@ -1203,6 +1205,94 @@ void tst_QWebPage::frameAt()
frameAtHelper(webPage, webPage->mainFrame(), webPage->mainFrame()->pos());
}
+void tst_QWebPage::inputMethods()
+{
+ m_view->page()->mainFrame()->setHtml("<html><body>" \
+ "<input type='text' id='input1' style='font-family: serif' value='' maxlength='20'/>" \
+ "</body></html>");
+ m_view->page()->mainFrame()->setFocus();
+
+ QList<QWebElement> inputs = m_view->page()->mainFrame()->documentElement().findAll("input");
+
+ QMouseEvent evpres(QEvent::MouseButtonPress, inputs.at(0).geometry().center(), Qt::LeftButton, Qt::NoButton, Qt::NoModifier);
+ m_view->page()->event(&evpres);
+ QMouseEvent evrel(QEvent::MouseButtonRelease, inputs.at(0).geometry().center(), Qt::LeftButton, Qt::NoButton, Qt::NoModifier);
+ m_view->page()->event(&evrel);
+
+ //ImMicroFocus
+ QVariant variant = m_view->page()->inputMethodQuery(Qt::ImMicroFocus);
+ QRect focusRect = variant.toRect();
+ QVERIFY(inputs.at(0).geometry().contains(variant.toRect().topLeft()));
+
+ //ImFont
+ variant = m_view->page()->inputMethodQuery(Qt::ImFont);
+ QFont font = variant.value<QFont>();
+ QCOMPARE(QString("-webkit-serif"), font.family());
+
+ QList<QInputMethodEvent::Attribute> inputAttributes;
+
+ //Insert text.
+ {
+ QInputMethodEvent eventText("QtWebKit", inputAttributes);
+ QSignalSpy signalSpy(m_view->page(), SIGNAL(microFocusChanged()));
+ m_view->page()->event(&eventText);
+ QCOMPARE(signalSpy.count(), 0);
+ }
+
+ {
+ QInputMethodEvent eventText("", inputAttributes);
+ eventText.setCommitString(QString("QtWebKit"), 0, 0);
+ m_view->page()->event(&eventText);
+ }
+
+#if QT_VERSION >= 0x040600
+ //ImMaximumTextLength
+ variant = m_view->page()->inputMethodQuery(Qt::ImMaximumTextLength);
+ QCOMPARE(20, variant.toInt());
+
+ //Set selection
+ inputAttributes << QInputMethodEvent::Attribute(QInputMethodEvent::Selection, 3, 2, QVariant());
+ QInputMethodEvent eventSelection("",inputAttributes);
+ m_view->page()->event(&eventSelection);
+
+ //ImAnchorPosition
+ variant = m_view->page()->inputMethodQuery(Qt::ImAnchorPosition);
+ int anchorPosition = variant.toInt();
+ QCOMPARE(anchorPosition, 3);
+
+ //ImCursorPosition
+ variant = m_view->page()->inputMethodQuery(Qt::ImCursorPosition);
+ int cursorPosition = variant.toInt();
+ QCOMPARE(cursorPosition, 5);
+
+ //ImCurrentSelection
+ variant = m_view->page()->inputMethodQuery(Qt::ImCurrentSelection);
+ QString selectionValue = variant.value<QString>();
+ QCOMPARE(selectionValue, QString("eb"));
+#endif
+
+ //ImSurroundingText
+ variant = m_view->page()->inputMethodQuery(Qt::ImSurroundingText);
+ QString value = variant.value<QString>();
+ QCOMPARE(value, QString("QtWebKit"));
+
+#if QT_VERSION >= 0x040600
+ {
+ 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);
+ m_view->page()->event(&event);
+ }
+
+ // A ongoing composition should not change the surrounding text before it is committed.
+ variant = m_view->page()->inputMethodQuery(Qt::ImSurroundingText);
+ value = variant.value<QString>();
+ QCOMPARE(value, QString("QtWebKit"));
+#endif
+}
+
// import a little DRT helper function to trigger the garbage collector
void QWEBKIT_EXPORT qt_drt_garbageCollector_collect();