summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/quick/qmltests/data/keyboardModifierMapping.html36
-rw-r--r--tests/auto/quick/qmltests/data/tst_keyboardModifierMapping.qml119
-rw-r--r--tests/auto/quick/qmltests/qmltests.pro6
3 files changed, 160 insertions, 1 deletions
diff --git a/tests/auto/quick/qmltests/data/keyboardModifierMapping.html b/tests/auto/quick/qmltests/data/keyboardModifierMapping.html
new file mode 100644
index 000000000..b6d291207
--- /dev/null
+++ b/tests/auto/quick/qmltests/data/keyboardModifierMapping.html
@@ -0,0 +1,36 @@
+<html>
+<body>
+<kbd>Alt</kbd> is <span id="alt_state">no</span><br>
+<kbd>Ctrl</kbd> is <span id="ctrl_state">no</span><br>
+<kbd>Meta</kbd> is <span id="meta_state">no</span><br>
+last keycode: <span id="last_keycode">none</span><br>
+
+<script>
+
+document.body.onkeydown = function(e) {
+ if (e.altKey)
+ alt_state.textContent = 'pressed'
+ if (e.ctrlKey)
+ ctrl_state.textContent = 'pressed'
+ if (e.metaKey)
+ meta_state.textContent = 'pressed'
+ last_keycode.textContent = e.keyCode
+};
+document.body.onkeyup = function(e) {
+ if (e.altKey)
+ alt_state.textContent = 'released'
+ if (e.ctrlKey)
+ ctrl_state.textContent = 'released'
+ if (e.metaKey)
+ meta_state.textContent = 'released'
+ last_keycode.textContent = e.keyCode
+};
+
+function getPressedModifiers() {
+ return "alt:" + alt_state.textContent + " ctrl:" + ctrl_state.textContent + " meta:" + meta_state.textContent
+}
+
+</script>
+</body>
+</html>
+
diff --git a/tests/auto/quick/qmltests/data/tst_keyboardModifierMapping.qml b/tests/auto/quick/qmltests/data/tst_keyboardModifierMapping.qml
new file mode 100644
index 000000000..ddf025281
--- /dev/null
+++ b/tests/auto/quick/qmltests/data/tst_keyboardModifierMapping.qml
@@ -0,0 +1,119 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt Quick Controls module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQuick 2.0
+import QtTest 1.0
+import QtWebEngine 1.0
+
+TestWebEngineView {
+ id: webEngineView
+ width: 400
+ height: 300
+
+ SignalSpy {
+ id: spy
+ target: webEngineView
+ signalName: "titleChanged"
+ }
+
+ TestCase {
+ name: "WebEngineViewKeyboardModifierMapping"
+
+ when: false
+ Timer {
+ running: parent.windowShown
+ repeat: false
+ interval: 1
+ onTriggered: parent.when = true
+ }
+
+ function test_keyboardModifierMapping() {
+ webEngineView.url = Qt.resolvedUrl("keyboardModifierMapping.html")
+ waitForLoadSucceeded();
+ var callbackCalled = false;
+
+ // Alt
+ keyPress(Qt.Key_Alt);
+ runJavaScript("getPressedModifiers()", function(result) {
+ compare(result, "alt:pressed ctrl:no meta:no");
+ callbackCalled = true;
+ });
+ wait(100);
+ verify(callbackCalled);
+ keyRelease(Qt.Key_Alt)
+ callbackCalled = false;
+
+ // Ctrl
+ // On mac Qt automatically translates Meta to Ctrl and vice versa.
+ // However, if sending the events manually no mapping is being done,
+ // so we have to do this here manually.
+ // For testing we assume that the flag Qt::AA_MacDontSwapCtrlAndMeta is NOT set.
+ keyPress(Qt.platform.os == "osx" ? Qt.Key_Meta : Qt.Key_Control);
+ runJavaScript("getPressedModifiers()", function(result) {
+ compare(result, "alt:released ctrl:pressed meta:no");
+ callbackCalled = true;
+ });
+ wait(100);
+ verify(callbackCalled);
+ keyRelease(Qt.platform.os == "osx" ? Qt.Key_Meta : Qt.Key_Control);
+ callbackCalled = false;
+
+ // Meta (Command on Mac)
+ keyPress(Qt.platform.os == "osx" ? Qt.Key_Control : Qt.Key_Meta);
+ runJavaScript("getPressedModifiers()", function(result) {
+ compare(result, "alt:released ctrl:released meta:pressed");
+ callbackCalled = true;
+ });
+ wait(100);
+ verify(callbackCalled);
+ keyRelease(Qt.platform.os == "osx" ? Qt.Key_Control : Qt.Key_Meta);
+ callbackCalled = false;
+
+ runJavaScript("getPressedModifiers()", function(result) {
+ compare(result, "alt:released ctrl:released meta:released");
+ callbackCalled = true;
+ });
+ wait(100);
+ verify(callbackCalled);
+ callbackCalled = false;
+ }
+ }
+}
diff --git a/tests/auto/quick/qmltests/qmltests.pro b/tests/auto/quick/qmltests/qmltests.pro
index 33a864cf1..6789b714b 100644
--- a/tests/auto/quick/qmltests/qmltests.pro
+++ b/tests/auto/quick/qmltests/qmltests.pro
@@ -16,6 +16,8 @@ OTHER_FILES += \
$$PWD/data/test1.html \
$$PWD/data/test2.html \
$$PWD/data/test3.html \
+ $$PWD/data/test4.html \
+ $$PWD/data/keyboardModifierMapping.html \
$$PWD/data/tst_desktopBehaviorLoadHtml.qml \
$$PWD/data/tst_favIconLoad.qml \
$$PWD/data/tst_linkHovered.qml \
@@ -29,7 +31,9 @@ OTHER_FILES += \
$$PWD/data/tst_navigationRequested.qml \
$$PWD/data/tst_properties.qml \
$$PWD/data/tst_runJavaScript.qml \
- $$PWD/data/tst_titleChanged.qml
+ $$PWD/data/tst_titleChanged.qml \
+ $$PWD/data/tst_keyboardModifierMapping.qml \
+
load(qt_build_paths)
DEFINES += QUICK_TEST_SOURCE_DIR=\"\\\"$$PWD$${QMAKE_DIR_SEP}data\\\"\"