@@ -0,0 +1,103 @@
1+/*
2+ * Copyright (C) 2014 Canonical, Ltd.
3+ *
4+ * Authors:
5+ * Josh Arenson <joshua.arenson@canonical.com>
6+ *
7+ * This program is free software; you can redistribute it and/or modify
8+ * it under the terms of the GNU General Public License as published by
9+ * the Free Software Foundation; version 3.
10+ *
11+ * This program is distributed in the hope that it will be useful,
12+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+ * GNU General Public License for more details.
15+ *
16+ * You should have received a copy of the GNU General Public License
17+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
18+ */
19+
20+import QtQuick 2.0
21+import QtTest 1.0
22+import "../../../qml/Components"
23+import Unity.Test 0.1 as UT
24+
25+Item {
26+
27+ property int onBothVolumeKeysPressedCount: 0
28+ property int onPowerPressedCount: 0
29+ property int onScreenshotPressedCount: 0
30+ property int onVolumeDownPressedCount: 0
31+ property int onVolumeUpPressedCount: 0
32+
33+ PhysicalKeysFilter {
34+ id: physicalKeysFilter
35+
36+ onBothVolumeKeysPressed: onBothVolumeKeysPressedCount += 1
37+ onPowerPressed: onPowerPressedCount += 1
38+ onScreenshotPressed: onScreenshotPressedCount += 1
39+ onVolumeDownPressed: onVolumeDownPressedCount += 1
40+ onVolumeUpPressed: onVolumeUpPressedCount += 1
41+ }
42+
43+ UT.UnityTestCase {
44+ name: "PhysicalKeyFilter"
45+ when: windowShown
46+
47+ function cleanup() {
48+ physicalKeysFilter.onKeyReleased(Qt.Key_PowerDown);
49+ physicalKeysFilter.onKeyReleased(Qt.Key_PowerOff);
50+ physicalKeysFilter.onKeyReleased(Qt.Key_VolumeDown);
51+ physicalKeysFilter.onKeyReleased(Qt.Key_VolumeUp);
52+
53+ onBothVolumeKeysPressedCount = 0;
54+ onPowerPressedCount = 0;
55+ onScreenshotPressedCount = 0;
56+ onVolumeDownPressedCount = 0;
57+ onVolumeUpPressedCount = 0;
58+ }
59+
60+ function test_both_volume_keys_simultaneously() {
61+ physicalKeysFilter.onKeyPressed(Qt.Key_VolumeDown);
62+ physicalKeysFilter.onKeyPressed(Qt.Key_VolumeUp);
63+
64+ compare(onBothVolumeKeysPressedCount, 1);
65+
66+ // Simulate holding the keys down
67+ sleep(3);
68+ compare(onBothVolumeKeysPressedCount, 1);
69+ }
70+
71+ function test_power_button() {
72+ physicalKeysFilter.onKeyPressed(Qt.Key_PowerDown);
73+ compare(onPowerPressedCount, 1);
74+
75+ sleep(3);
76+ compare(onPowerPressedCount, 1);
77+ }
78+
79+ function test_screenshot_buttons() {
80+ physicalKeysFilter.onKeyPressed(Qt.Key_PowerDown);
81+ physicalKeysFilter.onKeyPressed(Qt.Key_VolumeDown);
82+
83+ compare(onPowerPressedCount, 1);
84+ compare(onScreenshotPressedCount, 1);
85+ compare(onVolumeDownPressedCount, 0);
86+
87+ sleep(3);
88+ compare(onPowerPressedCount, 1);
89+ compare(onScreenshotPressedCount, 1);
90+ compare(onVolumeDownPressedCount, 0);
91+ }
92+
93+ function test_volume_down_button() {
94+ physicalKeysFilter.onKeyPressed(Qt.Key_VolumeDown);
95+ compare(onVolumeDownPressedCount, 1);
96+ }
97+
98+ function test_volume_up_button() {
99+ physicalKeysFilter.onKeyPressed(Qt.Key_VolumeUp);
100+ compare(onVolumeUpPressedCount, 1);
101+ }
102+ }
103+}