@@ -1,5 +1,5 @@
2− * Copyright (C) 2015 Canonical, Ltd.
2+ * Copyright (C) 2015-2016 Canonical, Ltd.
4 * This program is free software; you can redistribute it and/or modify
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
5 * it under the terms of the GNU General Public License as published by
@@ -71,6 +71,8 @@ public:
72using namespace UnityUtil;
72using namespace UnityUtil;
74+Q_DECLARE_METATYPE(Qt::Key) // because of QTest::addColumn<Qt::Key>
74class WindowInputMonitorTest : public QObject {
76class WindowInputMonitorTest : public QObject {
76private Q_SLOTS:
78private Q_SLOTS:
@@ -81,6 +83,7 @@ private Q_SLOTS:
81 void touchTapTouch();
83 void touchTapTouch();
83 void tapWhileTouching();
85 void tapWhileTouching();
86+ void multipleHomeKeys();
86 void passTime(qint64 timeSpanMs);
89 void passTime(qint64 timeSpanMs);
@@ -112,13 +115,15 @@ void WindowInputMonitorTest::touchTapTouch_data()
112 QTest::addColumn<int>("tapDuration");
115 QTest::addColumn<int>("tapDuration");
113 QTest::addColumn<int>("silenceAfterTap");
116 QTest::addColumn<int>("silenceAfterTap");
114 QTest::addColumn<int>("expectedActivatedCount");
117 QTest::addColumn<int>("expectedActivatedCount");
115−
118+ QTest::addColumn<Qt::Key>("key");
116− QTest::newRow("tap followed by touch") << 2000 << 50 << 10 << 0;
120+ QTest::newRow("tap followed by touch") << 2000 << 50 << 10 << 0 << Qt::Key_Super_L;
117− QTest::newRow("touch, tap and touch") << 10 << 50 << 10 << 0;
121+ QTest::newRow("touch, tap and touch") << 10 << 50 << 10 << 0 << Qt::Key_Super_L;
118− QTest::newRow("touch followed by tap") << 10 << 50 << 2000 << 0;
122+ QTest::newRow("touch followed by tap") << 10 << 50 << 2000 << 0 << Qt::Key_Super_L;
119− QTest::newRow("touch followed by long tap") << 10 << 500 << 2000 << 0;
123+ QTest::newRow("touch followed by long tap") << 10 << 500 << 2000 << 0 << Qt::Key_Super_L;
120− QTest::newRow("isolated tap") << 1000 << 50 << 1000 << 1;
124+ QTest::newRow("isolated tap, Super_L") << 1000 << 50 << 1000 << 1 << Qt::Key_Super_L;
125+ QTest::newRow("isolated tap, HomePage") << 1000 << 50 << 1000 << 1 << Qt::Key_HomePage;
121− QTest::newRow("isolated long press") << 1000 << 200 << 1000 << 0;
126+ QTest::newRow("isolated long press") << 1000 << 200 << 1000 << 0 << Qt::Key_Super_L;
124void WindowInputMonitorTest::touchTapTouch()
129void WindowInputMonitorTest::touchTapTouch()
@@ -127,6 +132,7 @@ void WindowInputMonitorTest::touchTapTouch()
127 QFETCH(int, tapDuration);
132 QFETCH(int, tapDuration);
128 QFETCH(int, silenceAfterTap);
133 QFETCH(int, silenceAfterTap);
129 QFETCH(int, expectedActivatedCount);
134 QFETCH(int, expectedActivatedCount);
135+ QFETCH(Qt::Key, key);
130 WindowInputMonitor homeKeyWatcher(m_fakeTimerFactory->create(), new FakeElapsedTimer);
136 WindowInputMonitor homeKeyWatcher(m_fakeTimerFactory->create(), new FakeElapsedTimer);
131 QSignalSpy activatedSpy(&homeKeyWatcher, &WindowInputMonitor::homeKeyActivated);
137 QSignalSpy activatedSpy(&homeKeyWatcher, &WindowInputMonitor::homeKeyActivated);
132 QVERIFY(activatedSpy.isValid());
138 QVERIFY(activatedSpy.isValid());
@@ -149,7 +155,7 @@ void WindowInputMonitorTest::touchTapTouch()
149 passTime(silenceBeforeTap);
155 passTime(silenceBeforeTap);
152− QKeyEvent keyEvent(QEvent::KeyPress, Qt::Key_Super_L, Qt::NoModifier);
158+ QKeyEvent keyEvent(QEvent::KeyPress, key, Qt::NoModifier);
153 homeKeyWatcher.update(&keyEvent);
159 homeKeyWatcher.update(&keyEvent);
155 int tapTime = 0;
161 int tapTime = 0;
@@ -157,10 +163,10 @@ void WindowInputMonitorTest::touchTapTouch()
157 passTime(10);
163 passTime(10);
158 tapTime += 10;
164 tapTime += 10;
159 if (tapTime + 10 >= tapDuration) {
165 if (tapTime + 10 >= tapDuration) {
160− QKeyEvent keyEvent(QEvent::KeyRelease, Qt::Key_Super_L, Qt::NoModifier);
166+ QKeyEvent keyEvent(QEvent::KeyRelease, key, Qt::NoModifier);
161 homeKeyWatcher.update(&keyEvent);
167 homeKeyWatcher.update(&keyEvent);
163− QKeyEvent keyEvent(QEvent::KeyPress, Qt::Key_Super_L, Qt::NoModifier, QString(), true /*autorepeat*/);
169+ QKeyEvent keyEvent(QEvent::KeyPress, key, Qt::NoModifier, QString(), true /*autorepeat*/);
164 homeKeyWatcher.update(&keyEvent);
170 homeKeyWatcher.update(&keyEvent);
@@ -217,6 +223,41 @@ void WindowInputMonitorTest::tapWhileTouching()
217 QCOMPARE(activatedSpy.count(), 0);
223 QCOMPARE(activatedSpy.count(), 0);
227+ Press multiple of the mapped home keys roughly at the same time.
228+ The first pressed will be recognized and the other ignored
230+void WindowInputMonitorTest::multipleHomeKeys()
232+ WindowInputMonitor homeKeyWatcher(m_fakeTimerFactory->create(), new FakeElapsedTimer);
233+ QSignalSpy activatedSpy(&homeKeyWatcher, &WindowInputMonitor::homeKeyActivated);
234+ QVERIFY(activatedSpy.isValid());
238+ QKeyEvent keyEvent(QEvent::KeyPress, Qt::Key_HomePage, Qt::NoModifier);
239+ homeKeyWatcher.update(&keyEvent);
243+ QKeyEvent keyEvent(QEvent::KeyPress, Qt::Key_Super_L, Qt::NoModifier);
244+ homeKeyWatcher.update(&keyEvent);
248+ QKeyEvent keyEvent(QEvent::KeyRelease, Qt::Key_HomePage, Qt::NoModifier);
249+ homeKeyWatcher.update(&keyEvent);
253+ QKeyEvent keyEvent(QEvent::KeyRelease, Qt::Key_Super_L, Qt::NoModifier);
254+ homeKeyWatcher.update(&keyEvent);
258+ QCOMPARE(activatedSpy.count(), 1);
220/////////////////////////////////// FakeTimer //////////////////////////////////
261/////////////////////////////////// FakeTimer //////////////////////////////////
222FakeTimer::FakeTimer(QObject *parent)
263FakeTimer::FakeTimer(QObject *parent)