~3v1n0/unity8/indicators-client-modernize

« back to all changes in this revision

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

  • Committer: Marco Trevisan (Treviño)
  • Date: 2016-09-08 16:48:59 UTC
  • mfrom: (2445.1.4 fake-indicators-model)
  • Revision ID: mail@3v1n0.net-20160908164859-9m8cqbb2ra0s02l6
Merging with lp:~3v1n0/unity8/fake-indicators-model

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2016 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 "../../../qml/Components/MediaServices"
 
20
import Unity.Test 0.1 as UT
 
21
import Ubuntu.Components 1.3
 
22
import QtMultimedia 5.0
 
23
 
 
24
Rectangle {
 
25
    id: root
 
26
    width: units.gu(70)
 
27
    height: units.gu(80)
 
28
    color: "lightgrey"
 
29
 
 
30
    property var sourceData: {
 
31
        // TODO do we want a video or make this fake
 
32
        "source": "file:///home/nick/Videos/test-mpeg.ogv",
 
33
        "screenshot": Qt.resolvedUrl("../Dash/artwork/avatar.png")
 
34
    }
 
35
 
 
36
    property var sourceData2: {
 
37
        // TODO do we want a video or make this fake
 
38
        "source": "file:///home/nick/Videos/test-mpeg2.ogv",
 
39
        "screenshot": Qt.resolvedUrl("../Dash/artwork/checkers.png")
 
40
    }
 
41
 
 
42
    MediaDataSource {
 
43
        source: root.sourceData["source"]
 
44
        duration: 60000
 
45
        metaData: {
 
46
            "title" : "TEST MPEG",
 
47
            "resolution" : { "width": 160, "height": 90 }
 
48
        }
 
49
    }
 
50
 
 
51
    MediaDataSource {
 
52
        source: root.sourceData2["source"]
 
53
        duration: 30000
 
54
        metaData: {
 
55
            "title" : "TEST MPEG",
 
56
            "resolution" : { "width": 90, "height": 240 }
 
57
        }
 
58
    }
 
59
 
 
60
    Item {
 
61
        anchors.fill: parent
 
62
 
 
63
        Rectangle {
 
64
            anchors {
 
65
                top: parent.top
 
66
                bottom: parent.bottom
 
67
                left: parent.left
 
68
                right: controls.left
 
69
            }
 
70
            color: "darkblue"
 
71
 
 
72
            MediaServices {
 
73
                id: services
 
74
                fullscreen: false
 
75
                width: parent.width
 
76
                sourceData: root.sourceData
 
77
                context: "video"
 
78
 
 
79
                rootItem: parent
 
80
                maximumEmbeddedHeight: undefined
 
81
            }
 
82
        }
 
83
 
 
84
        Rectangle {
 
85
            id: controls
 
86
            color: "darkgrey"
 
87
            anchors {
 
88
                top: parent.top
 
89
                bottom: parent.bottom
 
90
                right: parent.right
 
91
            }
 
92
            width: units.gu(30)
 
93
 
 
94
            Column {
 
95
                anchors { left: parent.left; right: parent.right; top: parent.top; margins: units.gu(1) }
 
96
 
 
97
                Button {
 
98
                    text: "Fullscreen"
 
99
                    onClicked: services.fullscreen = !services.fullscreen
 
100
                }
 
101
                UT.MouseTouchEmulationCheckbox {}
 
102
            }
 
103
        }
 
104
    }
 
105
 
 
106
    SignalSpy {
 
107
        id: serviceCloseSpy
 
108
        target: services
 
109
        signalName: "close"
 
110
    }
 
111
 
 
112
    UT.UnityTestCase {
 
113
        name: "VideoMediaServices"
 
114
        when: windowShown
 
115
 
 
116
        property int oldControlTimerInterval: 0;
 
117
 
 
118
        function init() {
 
119
            services.sourceData = root.sourceData
 
120
            services.context = "video";
 
121
 
 
122
            var controlHideTimer = findInvisibleChild(services, "controlHideTimer");
 
123
            verify(controlHideTimer !== null);
 
124
            oldControlTimerInterval = controlHideTimer.interval;
 
125
        }
 
126
 
 
127
        function cleanup() {
 
128
            serviceCloseSpy.clear();
 
129
            services.context = "";
 
130
            services.fullscreen = false;
 
131
            services.maximumEmbeddedHeight = undefined;
 
132
            tryCompareFunction(function() { return services.header ? services.header.visible : false }, false);
 
133
            tryCompareFunction(function() { return services.footer ? services.footer.visible : false }, false);
 
134
 
 
135
            var controlHideTimer = findInvisibleChild(services, "controlHideTimer");
 
136
            controlHideTimer.interval = oldControlTimerInterval;
 
137
        }
 
138
 
 
139
        function test_videoWidget() {
 
140
            var videoPlayer = findChild(services, "videoPlayer");
 
141
            verify(videoPlayer !== null);
 
142
 
 
143
            var videoControls = findChild(services, "videoControls");
 
144
            verify(videoControls !== null);
 
145
        }
 
146
 
 
147
        function test_tapVideoPlayerToPlayAndPause() {
 
148
            var videoPlayer = findChild(services, "videoPlayer");
 
149
            verify(videoPlayer !== null)
 
150
            tap(videoPlayer, videoPlayer.width/2, videoPlayer.height/2);
 
151
 
 
152
            var mediaPlayer = findInvisibleChild(services, "mediaPlayer");
 
153
            verify(mediaPlayer !== null);
 
154
            compare(mediaPlayer.playbackState, MediaPlayer.PlayingState, "Media player should be playing");
 
155
 
 
156
            tap(videoPlayer, videoPlayer.width/2, videoPlayer.height/2);
 
157
            compare(mediaPlayer.playbackState, MediaPlayer.PausedState, "Media player should be playing");
 
158
        }
 
159
 
 
160
        function test_fullscreenSwitch() {
 
161
            var mediaPlayer = findInvisibleChild(services, "mediaPlayer");
 
162
            verify(mediaPlayer !== null);
 
163
            mediaPlayer.play();
 
164
            wait(UbuntuAnimation.BriskDuration); // animation
 
165
 
 
166
            var button = findChild(services, "viewActionButton");
 
167
            verify(button !== null);
 
168
            tap(button);
 
169
 
 
170
            compare(services.fullscreen, true, "Should have switched to fullscreen mode.");
 
171
        }
 
172
 
 
173
        function test_HeaderVisibleOnlyWhenFullscreen() {
 
174
            services.fullscreen = false;
 
175
            compare(services.header, null, "Header should be null when not fullscreen");
 
176
            services.fullscreen = true;
 
177
            tryCompareFunction(function() { return services.header !== null }, true);
 
178
        }
 
179
 
 
180
        function test_ControlsShowAndHideWhenPlayed() {
 
181
            services.fullscreen = true;
 
182
            var controlHideTimer = findInvisibleChild(services, "controlHideTimer");
 
183
            controlHideTimer.interval = 100;
 
184
 
 
185
            var mediaPlayer = findInvisibleChild(services, "mediaPlayer");
 
186
            mediaPlayer.play();
 
187
 
 
188
            tryCompare(services.header, "visible", true);
 
189
            tryCompare(services.footer, "visible", true);
 
190
 
 
191
            tryCompare(services.header, "visible", false);
 
192
            tryCompare(services.footer, "visible", false);
 
193
        }
 
194
 
 
195
        function test_ControlsDontTimeOutWhenPaused() {
 
196
            services.fullscreen = true;
 
197
            var controlHideTimer = findInvisibleChild(services, "controlHideTimer");
 
198
            controlHideTimer.interval = 100;
 
199
 
 
200
            var mediaPlayer = findInvisibleChild(services, "mediaPlayer");
 
201
            mediaPlayer.play();
 
202
            mediaPlayer.pause();
 
203
            wait(300);
 
204
 
 
205
            compare(services.header.visible, true, "Header should still be visible");
 
206
            compare(services.footer.visible, true, "Footer should still be visible");
 
207
        }
 
208
 
 
209
        function test_close() {
 
210
            services.fullscreen = true;
 
211
            var mediaPlayer = findInvisibleChild(services, "mediaPlayer");
 
212
            mediaPlayer.play();
 
213
            mediaPlayer.pause();
 
214
            wait(UbuntuAnimation.BriskDuration); // animation
 
215
 
 
216
            var navigationButton = findChild(services, "navigationButton");
 
217
            verify(navigationButton !== null);
 
218
 
 
219
            tap(navigationButton);
 
220
            compare(serviceCloseSpy.count, 1, "close was not called");
 
221
        }
 
222
 
 
223
        function test_maximumVideoSize() {
 
224
            services.maximumEmbeddedHeight = root.height / 2
 
225
            services.sourceData = root.sourceData2
 
226
            verify(services.content !== null);
 
227
            tryCompare(services.content, "height", root.height/2);
 
228
        }
 
229
    }
 
230
}