diff options
author | Joerg Bornemann <joerg.bornemann@qt.io> | 2017-05-29 13:19:03 +0200 |
---|---|---|
committer | Joerg Bornemann <joerg.bornemann@qt.io> | 2017-06-08 11:12:36 +0000 |
commit | 532cc891fdad5e329bb31724f527bfba1e2e8a44 (patch) | |
tree | 35c62428a36f2fb67bb5ee731a40c671cb03c0cf /tests/auto | |
parent | 9da1f08d224bc94f81ae72c4353bf234af6f8592 (diff) |
Override shortcuts only when an HTML input field has focus
Otherwise an application shortcut like Shift+Delete would no longer
work when webengine has focus (e.g. "delete mail" in KMail)
This removes unconditional calls to editorActionForKeyEvent for
ShortcutOverride event handling. We can remove those, because the key
sequences that are checked by editorActionForKeyEvent are a subset of
the key sequences checked by isCommonTextEditShortcut.
This amends commit 3902b27e.
Change-Id: I12a98368381edef36f11457c8b864d843efb871a
Reviewed-by: David Faure <david.faure@kdab.com>
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Diffstat (limited to 'tests/auto')
-rw-r--r-- | tests/auto/widgets/qwebengineview/BLACKLIST | 3 | ||||
-rw-r--r-- | tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp | 21 |
2 files changed, 15 insertions, 9 deletions
diff --git a/tests/auto/widgets/qwebengineview/BLACKLIST b/tests/auto/widgets/qwebengineview/BLACKLIST index 7121f7561..b3f393af4 100644 --- a/tests/auto/widgets/qwebengineview/BLACKLIST +++ b/tests/auto/widgets/qwebengineview/BLACKLIST @@ -3,3 +3,6 @@ windows [imeComposition] osx + +[inputFieldOverridesShortcuts] +osx diff --git a/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp b/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp index c35617b3d..ad03839d6 100644 --- a/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp +++ b/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp @@ -1344,7 +1344,6 @@ void tst_QWebEngineView::inputFieldOverridesShortcuts() { bool actionTriggered = false; QAction *action = new QAction; - action->setShortcut(Qt::Key_X); connect(action, &QAction::triggered, [&actionTriggered] () { actionTriggered = true; }); QWebEngineView view; @@ -1352,7 +1351,7 @@ void tst_QWebEngineView::inputFieldOverridesShortcuts() QSignalSpy loadFinishedSpy(&view, SIGNAL(loadFinished(bool))); view.setHtml(QString("<html><body onload=\"input1=document.getElementById('input1')\">" - "<input id=\"dummy\" type=\"text\">" + "<button id=\"btn1\" type=\"button\">push it real good</button>" "<input id=\"input1\" type=\"text\" value=\"x\">" "</body></html>")); QVERIFY(loadFinishedSpy.wait()); @@ -1365,7 +1364,15 @@ void tst_QWebEngineView::inputFieldOverridesShortcuts() "input1.value").toString(); }; + // The input form is not focused. The action is triggered on pressing Shift+Delete. + action->setShortcut(Qt::SHIFT + Qt::Key_Delete); + QTest::keyClick(view.windowHandle(), Qt::Key_Delete, Qt::ShiftModifier); + QTRY_VERIFY(actionTriggered); + QCOMPARE(inputFieldValue(), QString("x")); + // The input form is not focused. The action is triggered on pressing X. + action->setShortcut(Qt::Key_X); + actionTriggered = false; QTest::keyClick(view.windowHandle(), Qt::Key_X); QTRY_VERIFY(actionTriggered); QCOMPARE(inputFieldValue(), QString("x")); @@ -1384,16 +1391,12 @@ void tst_QWebEngineView::inputFieldOverridesShortcuts() QTRY_VERIFY(actionTriggered); QCOMPARE(inputFieldValue(), QString("yx")); - // Remove focus from the input field. A QKeySequence::Copy action still must not be triggered. - evaluateJavaScriptSync(view.page(), "input1.blur();"); + // Remove focus from the input field. A QKeySequence::Copy action must be triggerable. + evaluateJavaScriptSync(view.page(), "document.getElementById('btn1').focus();"); action->setShortcut(QKeySequence::Copy); actionTriggered = false; QTest::keyClick(view.windowHandle(), Qt::Key_C, Qt::ControlModifier); - // Add some text in the input field to ensure that the key event went through. - evaluateJavaScriptSync(view.page(), "input1.focus();"); - QTest::keyClick(view.windowHandle(), Qt::Key_U); - QTRY_COMPARE(inputFieldValue(), QString("yux")); - QVERIFY(!actionTriggered); + QTRY_VERIFY(actionTriggered); } class TestInputContext : public QPlatformInputContext |