~nick-dedekind/unity8/indicator-color-fixes

« back to all changes in this revision

Viewing changes to tests/qmltests/Components/tst_VirtualTouchPad.qml

  • Committer: Nick Dedekind
  • Date: 2016-02-29 14:24:55 UTC
  • mfrom: (2143.1.65 unity8)
  • Revision ID: nick.dedekind@canonical.com-20160229142455-ol76uyr8pin7l5r6
merged with trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2015 Canonical, Ltd.
 
3
 *
 
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
 
6
 * the Free Software Foundation; version 3.
 
7
 *
 
8
 * This program is distributed in the hope that it will be useful,
 
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
 * GNU General Public License for more details.
 
12
 *
 
13
 * You should have received a copy of the GNU General Public License
 
14
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
15
 */
 
16
 
 
17
import QtQuick 2.4
 
18
import QtTest 1.0
 
19
import Unity.Test 0.1
 
20
import UInput 0.1
 
21
import "../../../qml/Components"
 
22
 
 
23
 
 
24
Item {
 
25
    id: root
 
26
    width: units.gu(70)
 
27
    height: units.gu(70)
 
28
 
 
29
    VirtualTouchPad {
 
30
        id: touchScreenPad
 
31
        anchors.fill: parent
 
32
    }
 
33
 
 
34
    SignalSpy {
 
35
        id: mouseEventSpy1
 
36
        target: touchScreenPad.uinput
 
37
    }
 
38
    SignalSpy {
 
39
        id: mouseEventSpy2
 
40
        target: touchScreenPad.uinput
 
41
    }
 
42
 
 
43
    UnityTestCase {
 
44
        id: testCase
 
45
        name: "VirtualTouchPad"
 
46
        when: windowShown
 
47
 
 
48
        function init() {
 
49
            mouseEventSpy1.clear();
 
50
            mouseEventSpy2.clear();
 
51
        }
 
52
 
 
53
        function test_click() {
 
54
            mouseEventSpy1.signalName = "mousePressed"
 
55
            mouseEventSpy2.signalName = "mouseReleased"
 
56
 
 
57
            var touchPadArea = findChild(touchScreenPad, "touchPadArea");
 
58
 
 
59
            tap(touchPadArea)
 
60
            tryCompare(mouseEventSpy1, "count", 1)
 
61
            tryCompare(mouseEventSpy2, "count", 1)
 
62
        }
 
63
 
 
64
        function test_doubleClick() {
 
65
            mouseEventSpy1.signalName = "mousePressed"
 
66
            mouseEventSpy2.signalName = "mouseReleased"
 
67
 
 
68
            var touchPadArea = findChild(touchScreenPad, "touchPadArea");
 
69
 
 
70
            tap(touchPadArea)
 
71
            tap(touchPadArea)
 
72
 
 
73
            tryCompare(mouseEventSpy1, "count", 2)
 
74
            tryCompare(mouseEventSpy2, "count", 2)
 
75
        }
 
76
 
 
77
        function test_move() {
 
78
            mouseEventSpy1.signalName = "mouseMoved"
 
79
 
 
80
            var touchPadArea = findChild(touchScreenPad, "touchPadArea");
 
81
 
 
82
            var moveDiff = units.gu(2);
 
83
            var moveSteps = 5;
 
84
 
 
85
            touchFlick(touchPadArea, units.gu(1), units.gu(1), units.gu(1) + moveDiff, units.gu(1) + moveDiff, true, true, 10, moveSteps)
 
86
 
 
87
            tryCompare(mouseEventSpy1, "count", moveSteps)
 
88
            var movedX = 0;
 
89
            var movedY = 0
 
90
            for (var i = 0; i < 5; i++) {
 
91
                movedX += mouseEventSpy1.signalArguments[i][0]
 
92
                movedY += mouseEventSpy1.signalArguments[i][1]
 
93
            }
 
94
            compare(movedX, moveDiff)
 
95
            compare(movedY, moveDiff)
 
96
        }
 
97
 
 
98
        function test_doubleTapAndHoldToDrag() {
 
99
            mouseEventSpy1.signalName = "mousePressed"
 
100
            mouseEventSpy2.signalName = "mouseReleased"
 
101
 
 
102
            var touchPadArea = findChild(touchScreenPad, "touchPadArea");
 
103
 
 
104
            mouseClick(touchPadArea)
 
105
            mousePress(touchPadArea)
 
106
            mouseMove(touchPadArea, touchPadArea.width / 4, touchPadArea.height / 4)
 
107
 
 
108
            tryCompare(mouseEventSpy1, "count", 1)
 
109
            tryCompare(mouseEventSpy2, "count", 0)
 
110
            mouseRelease(touchPadArea)
 
111
            tryCompare(mouseEventSpy2, "count", 1)
 
112
        }
 
113
 
 
114
        function test_twoFingerScroll() {
 
115
            var touchPadArea = findChild(touchScreenPad, "touchPadArea");
 
116
 
 
117
            mouseEventSpy1.signalName = "mouseScrolled"
 
118
 
 
119
            var startX = touchPadArea.width / 2;
 
120
            var startY = touchPadArea.height / 2;
 
121
 
 
122
            var startX1 = startX - units.gu(1);
 
123
            var startX2 = startX + units.gu(1);
 
124
 
 
125
            var event = touchEvent(touchPadArea)
 
126
            event.press(0, startX1, startY)
 
127
            event.press(1, startX2, startY);
 
128
            event.commit()
 
129
 
 
130
            for (var i = 0; i < 10; i++) {
 
131
                event.move(0, startX1, startY + units.gu(i))
 
132
                event.move(1, startX2, startY + units.gu(i));
 
133
                event.commit();
 
134
 
 
135
                tryCompare(mouseEventSpy1, "count", i + 1);
 
136
            }
 
137
 
 
138
            event.release(0, startX1, startY + units.gu(11))
 
139
            event.release(1, startX2, startY + units.gu(11));
 
140
            event.commit();
 
141
        }
 
142
    }
 
143
}