on xenial help sign in
* Refactor code
ae03088Josh Arenson
qml/Components/PhysicalKeysMapper.qml+6−18
@@ -36,14 +36,15 @@ Item {
36 id: root
36 id: root
37
37
38 signal powerKeyLongPress();
38 signal powerKeyLongPress();
39− signal screenshotPressed();
39+
40− signal volumeDownPressed();
40+ property bool screenshotPressed: d.powerKeyPressed && d.volumeDownKeyPressed
41+ property bool volumeDownPressed: d.volumeDownKeyPressed && !d.powerKeyPressed
41− signal volumeUpPressed();
42+ property bool volumeUpPressed: d.volumeUpKeyPressed
43+ property int powerKeyLongPressTimeMs: 2000 // Is writable for testing purposes
42
44
43 QtObject {
45 QtObject {
44 id: d
46 id: d
45
47
46− property bool aPowerKeyWasReleased: true
47 property bool powerKeyPressed: false
48 property bool powerKeyPressed: false
48
49
49 property bool volumeDownKeyPressed: false
50 property bool volumeDownKeyPressed: false
@@ -56,7 +57,7 @@ Item {
56 Timer {
57 Timer {
57 id: powerKeyLongPressTimer
58 id: powerKeyLongPressTimer
58
59
59− interval: 2000
60+ interval: powerKeyLongPressTimeMs
60 repeat: false
61 repeat: false
61 triggeredOnStart: false
62 triggeredOnStart: false
62 onTriggered: powerKeyLongPress();
63 onTriggered: powerKeyLongPress();
@@ -92,18 +93,6 @@ Item {
92 d.volumeUpKeyPressed = true;
93 d.volumeUpKeyPressed = true;
93 }
94 }
94
95
95− /* Determine how to handle it */
96− if (d.volumeDownKeyPressed) {
97− if (d.powerKeyPressed && d.aPowerKeyWasReleased) {
98− screenshotPressed();
99− d.aPowerKeyWasReleased = false;
100− // Don't emit volumeDownPressed if power key is held
101− } else if (d.aPowerKeyWasReleased){
102− volumeDownPressed();
103− }
104− } else if (d.volumeUpKeyPressed) {
105− volumeUpPressed();
106− }
107 return eventAccepted;
96 return eventAccepted;
108 }
97 }
109
98
@@ -113,7 +102,6 @@ Item {
113 if (key == Qt.Key_PowerDown || key == Qt.Key_PowerOff) {
102 if (key == Qt.Key_PowerDown || key == Qt.Key_PowerOff) {
114 powerKeyLongPressTimer.stop();
103 powerKeyLongPressTimer.stop();
115 d.powerKeyPressed = false;
104 d.powerKeyPressed = false;
116− d.aPowerKeyWasReleased = true;
117 eventAccepted = true;
105 eventAccepted = true;
118 } else if (key == Qt.Key_VolumeDown) {
106 } else if (key == Qt.Key_VolumeDown) {
119 d.volumeDownKeyPressed = false;
107 d.volumeDownKeyPressed = false;
qml/Shell.qml+3−3
@@ -163,9 +163,9 @@ Item {
163 id: physicalKeysMapper
163 id: physicalKeysMapper
164
164
165 onPowerKeyLongPress: dialogs.showPowerDialog()
165 onPowerKeyLongPress: dialogs.showPowerDialog()
166− onVolumeDownPressed: volumeControl.volumeDown()
166+ onVolumeDownPressedChanged: if (volumeDownPressed) { volumeControl.volumeDown(); }
167− onVolumeUpPressed: volumeControl.volumeUp()
167+ onVolumeUpPressedChanged: if (volumeUpPressed) { volumeControl.volumeUp(); }
168− onScreenshotPressed: screenGrabber.capture()
168+ onScreenshotPressedChanged: if (screenshotPressed) { screenGrabber.capture(); }
169
169
170 }
170 }
171
171
tests/autopilot/unity8/shell/tests/test_screenshots.pydeleted−69
@@ -1,69 +0,0 @@
1−# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
2−#
3−# Unity Autopilot Test Suite
4−# Copyright (C) 2014 Canonical
5−#
6−# This program is free software: you can redistribute it and/or modify
7−# it under the terms of the GNU General Public License as published by
8−# the Free Software Foundation, either version 3 of the License, or
9−# (at your option) any later version.
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 evdev
21−import os
22−import time
23−
24−from gi.repository import Notify
25−from testtools.matchers import Equals
26−
27−from unity8.shell import (
28− fixture_setup,
29− tests
30−)
31−
32−from unity8.process_helpers import unlock_unity
33−
34−class ScreenShotTestCase(tests.UnityTestCase):
35−
36− AP_SCREENSHOT_DIR = '/home/phablet/Pictures/Screenshots'
37− SCREENSHOT_DELAY_SECS = 2
38−
39− def setUp(self):
40− super(ScreenShotTestCase, self).setUp()
41− unity_proxy = self.launch_unity()
42− unlock_unity(unity_proxy)
43−
44− def test_volume_is_hidden(self):
45− uinput = evdev.UInput(name='apinput', devnode='/dev/autopilot-uinput')
46− uinput.write(evdev.ecodes.EV_KEY, evdev.ecodes.KEY_VOLUMEDOWN, 1)
47− uinput.write(evdev.ecodes.EV_KEY, evdev.ecodes.KEY_VOLUMEDOWN, 0)
48− uinput.syn()
49− a=self.main_window.select_single("Notification", objectName="notification1")
50− print (a.icon)
51−
52− def test_take_screenshot(self):
53− num_screenshots_pre = len(os.listdir(self.AP_SCREENSHOT_DIR))
54− self._take_screenshot()
55− num_screenshots_post = len(os.listdir(self.AP_SCREENSHOT_DIR))
56− self.assertThat(num_screenshots_pre + 1, Equals(num_screenshots_post))
57−
58− def _take_screenshot(self):
59− uinput = evdev.UInput(name='apinput', devnode='/dev/autopilot-uinput')
60− uinput.write(evdev.ecodes.EV_KEY, evdev.ecodes.KEY_POWER, 1)
61− uinput.write(evdev.ecodes.EV_KEY, evdev.ecodes.KEY_VOLUMEDOWN, 1)
62− uinput.syn()
63−
64− time.sleep(self.SCREENSHOT_DELAY_SECS)
65−
66− uinput.write(evdev.ecodes.EV_KEY, evdev.ecodes.KEY_POWER, 0)
67− uinput.write(evdev.ecodes.EV_KEY, evdev.ecodes.KEY_VOLUMEDOWN, 0)
68− uinput.syn()
69−
tests/qmltests/Components/tst_PhysicalKeysMapper.qml+24−17
@@ -22,17 +22,16 @@ TestCase {
22 name: "PhysicalKeysMapper"
22 name: "PhysicalKeysMapper"
23
23
24 property int onPowerKeyLongPressCount: 0
24 property int onPowerKeyLongPressCount: 0
25− property int onScreenshotPressedCount: 0
25+ property int initialLongPressTimerValue
26− property int onVolumeDownPressedCount: 0
27− property int onVolumeUpPressedCount: 0
28
26
29 PhysicalKeysMapper {
27 PhysicalKeysMapper {
30 id: physicalKeysMapper
28 id: physicalKeysMapper
31
29
32 onPowerKeyLongPress: onPowerKeyLongPressCount += 1
30 onPowerKeyLongPress: onPowerKeyLongPressCount += 1
33− onScreenshotPressed: onScreenshotPressedCount += 1
31+ }
34− onVolumeDownPressed: onVolumeDownPressedCount += 1
32+
35− onVolumeUpPressed: onVolumeUpPressedCount += 1
33+ function initTestCase() {
34+ initialLongPressTimerValue = physicalKeysMapper.powerKeyLongPressTimeMs
36 }
35 }
37
36
38 function cleanup() {
37 function cleanup() {
@@ -42,37 +41,45 @@ TestCase {
42 physicalKeysMapper.onKeyReleased(Qt.Key_VolumeUp);
41 physicalKeysMapper.onKeyReleased(Qt.Key_VolumeUp);
43
42
44 onPowerKeyLongPressCount = 0;
43 onPowerKeyLongPressCount = 0;
45− onScreenshotPressedCount = 0;
44+
46− onVolumeDownPressedCount = 0;
45+ physicalKeysMapper.powerKeyLongPressTimeMs = initialLongPressTimerValue
47− onVolumeUpPressedCount = 0;
48 }
46 }
49
47
50 function test_LongPressPowerButton() {
48 function test_LongPressPowerButton() {
49+ // Delays chosen are lowest reliable values
50+ physicalKeysMapper.powerKeyLongPressTimeMs = 2
51 physicalKeysMapper.onKeyPressed(Qt.Key_PowerDown);
51 physicalKeysMapper.onKeyPressed(Qt.Key_PowerDown);
52− wait(3000);
52+ wait(15);
53
53
54 compare(onPowerKeyLongPressCount, 1);
54 compare(onPowerKeyLongPressCount, 1);
55 }
55 }
56
56
57 function test_ScreenshotButtons() {
57 function test_ScreenshotButtons() {
58+ /* Behavior when Power is pressed 1st */
58 physicalKeysMapper.onKeyPressed(Qt.Key_PowerDown);
59 physicalKeysMapper.onKeyPressed(Qt.Key_PowerDown);
59 physicalKeysMapper.onKeyPressed(Qt.Key_VolumeDown);
60 physicalKeysMapper.onKeyPressed(Qt.Key_VolumeDown);
61+ compare(physicalKeysMapper.screenshotPressed, true);
62+ compare(physicalKeysMapper.volumeDownPressed, false);
60
63
61− compare(onScreenshotPressedCount, 1);
64+ physicalKeysMapper.onKeyReleased(Qt.Key_PowerDown);
62− compare(onVolumeDownPressedCount, 0);
65+ physicalKeysMapper.onKeyReleased(Qt.Key_VolumeDown);
63
66
64− wait(3000);
67+ /* Behavior when VolumeDown is pressed 1st */
65− compare(onScreenshotPressedCount, 1);
68+ physicalKeysMapper.onKeyPressed(Qt.Key_VolumeDown);
66− compare(onVolumeDownPressedCount, 0);
69+ compare(physicalKeysMapper.volumeDownPressed, true);
70+ physicalKeysMapper.onKeyPressed(Qt.Key_PowerDown);
71+ compare(physicalKeysMapper.screenshotPressed, true);
67 }
72 }
68
73
69 function test_VolumeDownButton() {
74 function test_VolumeDownButton() {
75+ compare(physicalKeysMapper.volumeDownPressed, false);
70 physicalKeysMapper.onKeyPressed(Qt.Key_VolumeDown);
76 physicalKeysMapper.onKeyPressed(Qt.Key_VolumeDown);
71− compare(onVolumeDownPressedCount, 1);
77+ compare(physicalKeysMapper.volumeDownPressed, true);
72 }
78 }
73
79
74 function test_VolumeUpButton() {
80 function test_VolumeUpButton() {
81+ compare(physicalKeysMapper.volumeUpPressed, false);
75 physicalKeysMapper.onKeyPressed(Qt.Key_VolumeUp);
82 physicalKeysMapper.onKeyPressed(Qt.Key_VolumeUp);
76− compare(onVolumeUpPressedCount, 1);
83+ compare(physicalKeysMapper.volumeUpPressed, true);
77 }
84 }
78}
85}