@@ -18,12 +18,19 @@ import QtQuick 2.4
18import QtTest 1.0
18import QtTest 1.0
19import "../../../qml/Components"
19import "../../../qml/Components"
20import Powerd 0.1
20import Powerd 0.1
23− name: "PhysicalKeysMapper"
24+ width: 100
25 property var physicalKeysMapper: loader.item
27 property var physicalKeysMapper: loader.item
30+ Keys.onPressed: physicalKeysMapper.onKeyPressed(event, currentEventTimestamp);
31+ Keys.onReleased: physicalKeysMapper.onKeyReleased(event, currentEventTimestamp);
28 // Using a Loader here to make sure mapper state is coherent
35 // Using a Loader here to make sure mapper state is coherent
29 // regardless of unmatched KeyPress and KeyRelease events
36 // regardless of unmatched KeyPress and KeyRelease events
@@ -32,6 +39,21 @@ TestCase {
32 sourceComponent: PhysicalKeysMapper { }
39 sourceComponent: PhysicalKeysMapper { }
46+ property var pressedKeys: []
47+ property var releasedKeys: []
50+ inputCatcher.pressedKeys.push(event.key);
53+ inputCatcher.releasedKeys.push(event.key);
35 SignalSpy {
57 SignalSpy {
36 id: powerSpy
58 id: powerSpy
37 target: physicalKeysMapper
59 target: physicalKeysMapper
@@ -44,65 +66,117 @@ TestCase {
44 signalName: "screenshotTriggered"
66 signalName: "screenshotTriggered"
70+ name: "PhysicalKeysMapper"
47− function init() {
73+ function init() {
48− Powerd.setStatus(Powerd.On, Powerd.Unknown);
74+ Powerd.setStatus(Powerd.On, Powerd.Unknown);
49− loader.active = true;
75+ loader.active = true;
50− tryCompare(loader.status == Loader.Ready);
76+ tryCompare(loader.status == Loader.Ready);
77+ inputCatcher.pressedKeys = [];
78+ inputCatcher.releasedKeys = [];
53− function cleanup() {
81+ function cleanup() {
54− loader.active = false;
82+ loader.active = false;
55− powerSpy.clear();
83+ powerSpy.clear();
56− screenshotSpy.clear();
84+ screenshotSpy.clear();
59− function test_powerKeyLongPressed_data() {
87+ function test_powerKeyLongPressed_data() {
61− { tag: "screenOn", status: Powerd.On },
89+ { tag: "screenOn", status: Powerd.On },
62− { tag: "screenOff", status: Powerd.Off },
90+ { tag: "screenOff", status: Powerd.Off },
66− function test_powerKeyLongPressed(data) {
94+ function test_powerKeyLongPressed(data) {
67− Powerd.setStatus(data.status, Powerd.Unknown);
95+ Powerd.setStatus(data.status, Powerd.Unknown);
68− physicalKeysMapper.powerKeyLongPressTime = 500;
96+ physicalKeysMapper.powerKeyLongPressTime = 500;
70− physicalKeysMapper.onKeyPressed({ key: Qt.Key_PowerDown, isAutoRepeat: false }, 100);
98+ physicalKeysMapper.onKeyPressed({ key: Qt.Key_PowerDown, isAutoRepeat: false }, 100);
72− // After the first key press the screen is always on
100+ // After the first key press the screen is always on
73− // and the rest of keypresses are auto repeat
101+ // and the rest of keypresses are auto repeat
74− Powerd.setStatus(Powerd.On, Powerd.Unknown);
102+ Powerd.setStatus(Powerd.On, Powerd.Unknown);
76− physicalKeysMapper.onKeyPressed({ key: Qt.Key_PowerDown, isAutoRepeat: true}, 300);
104+ physicalKeysMapper.onKeyPressed({ key: Qt.Key_PowerDown, isAutoRepeat: true}, 300);
77− physicalKeysMapper.onKeyPressed({ key: Qt.Key_PowerDown, isAutoRepeat: true}, 400);
105+ physicalKeysMapper.onKeyPressed({ key: Qt.Key_PowerDown, isAutoRepeat: true}, 400);
78− physicalKeysMapper.onKeyPressed({ key: Qt.Key_PowerDown, isAutoRepeat: true}, 500);
106+ physicalKeysMapper.onKeyPressed({ key: Qt.Key_PowerDown, isAutoRepeat: true}, 500);
79− physicalKeysMapper.onKeyPressed({ key: Qt.Key_PowerDown, isAutoRepeat: true}, 599);
107+ physicalKeysMapper.onKeyPressed({ key: Qt.Key_PowerDown, isAutoRepeat: true}, 599);
81− // powerKeyLongPressed should not have been emitted yet.
109+ // powerKeyLongPressed should not have been emitted yet.
82− compare(powerSpy.count, 0);
110+ compare(powerSpy.count, 0);
84− physicalKeysMapper.onKeyPressed({ key: Qt.Key_PowerDown, isAutoRepeat: true}, 600);
112+ physicalKeysMapper.onKeyPressed({ key: Qt.Key_PowerDown, isAutoRepeat: true}, 600);
86− compare(powerSpy.count, 1);
114+ compare(powerSpy.count, 1);
88− // Confirm we only emit once
116+ // Confirm we only emit once
89− physicalKeysMapper.onKeyPressed({ key: Qt.Key_PowerDown, isAutoRepeat: true}, 601);
117+ physicalKeysMapper.onKeyPressed({ key: Qt.Key_PowerDown, isAutoRepeat: true}, 601);
90− compare(powerSpy.count, 1);
118+ compare(powerSpy.count, 1);
93− function test_screenshotButtons_data() {
121+ function test_screenshotButtons_data() {
94− return [
122+ return [
95− { tag: "UpFirst", first: Qt.Key_VolumeUp, second: Qt.Key_VolumeDown },
123+ { tag: "UpFirst", first: Qt.Key_VolumeUp, second: Qt.Key_VolumeDown },
96− { tag: "DownFirst", first: Qt.Key_VolumeDown, second: Qt.Key_VolumeUp },
124+ { tag: "DownFirst", first: Qt.Key_VolumeDown, second: Qt.Key_VolumeUp },
100− function test_screenshotButtons(data) {
128+ function test_screenshotButtons(data) {
101− physicalKeysMapper.onKeyPressed({ key: data.first });
129+ physicalKeysMapper.onKeyPressed({ key: data.first });
102− physicalKeysMapper.onKeyPressed({ key: data.second });
130+ physicalKeysMapper.onKeyPressed({ key: data.second });
103− screenshotSpy.wait();
131+ screenshotSpy.wait();
104− physicalKeysMapper.onKeyReleased({ key: data.first });
132+ physicalKeysMapper.onKeyReleased({ key: data.first });
105− physicalKeysMapper.onKeyReleased({ key: data.second });
133+ physicalKeysMapper.onKeyReleased({ key: data.second });
106− compare(screenshotSpy.count, 1);
134+ compare(screenshotSpy.count, 1);
137+ function test_altIsDispatchedOnRelease() {
138+ // Press alt, make sure it does *not* end up in inputCatcher (aka, the focused app)
139+ keyPress(Qt.Key_Alt, Qt.NoModifier)
140+ compare(inputCatcher.pressedKeys.length, 0);
141+ // Now release alt. It should cause the previous Alt press to be dispatched along with the release
142+ keyRelease(Qt.Key_Alt, Qt.NoModifier);
143+ compare(inputCatcher.pressedKeys.length, 1);
144+ compare(inputCatcher.pressedKeys[0], Qt.Key_Alt);
145+ compare(inputCatcher.releasedKeys.length, 1);
146+ compare(inputCatcher.releasedKeys[0], Qt.Key_Alt);
149+ function test_altIsNotDispatchedOnAltTab() {
150+ // Press alt, make sure it does *not* end up in inputCatcher (aka, the focused app)
151+ inputCatcher.pressedKeys = [];
152+ keyPress(Qt.Key_Alt, Qt.NoModifier)
153+ compare(inputCatcher.pressedKeys.length, 0);
154+ // Now also press tab. As this should trigger the spread, neither of them should end up in the app
155+ keyPress(Qt.Key_Tab, Qt.NoModifier)
156+ compare(inputCatcher.pressedKeys.length, 0);
158+ // Also the release events should not be dispatched to the app
159+ keyRelease(Qt.Key_Tab, Qt.NoModifier);
160+ keyRelease(Qt.Key_Alt, Qt.NoModifier);
161+ compare(inputCatcher.pressedKeys.length, 0);
162+ compare(inputCatcher.releasedKeys.length, 0);
165+ function test_altComboIsDispatched() {
166+ inputCatcher.pressedKeys = [];
167+ // Press alt, make sure it does *not* yet end up in inputCatcher (aka, the focused app)
168+ keyPress(Qt.Key_Alt, Qt.NoModifier)
169+ compare(inputCatcher.pressedKeys.length, 0);
170+ // Now press F in order to opening the File menu (Alt+F), now the app should get the full combo
171+ keyPress(Qt.Key_F, Qt.NoModifier)
172+ compare(inputCatcher.pressedKeys.length, 2);
173+ compare(inputCatcher.pressedKeys[0], Qt.Key_Alt);
174+ compare(inputCatcher.pressedKeys[1], Qt.Key_F);
176+ // release them both, both are supposed to end up in the app
177+ keyRelease(Qt.Key_F, Qt.NoModifier);
178+ keyRelease(Qt.Key_Alt, Qt.NoModifier);
179+ compare(inputCatcher.pressedKeys.length, 2);