Debian Codegraph @

tests/unittest/tst_video_player.qml

raw
1 /*
2 * Copyright (C) 2016 Canonical, Ltd.
3 *
4 * Authors:
5 * Renato Araujo Oliveira Filho <[email protected]>
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
21 import QtQuick 2.4
22 import QtTest 1.0
23 import Lomiri.Test 0.1
24
25 import "../../src/qml/player/"
26
27
28 Item {
29 id: root
30
31 width: 800
32 height: 600
33
34 visible: true
35
36 // Mock Application object
37 QtObject {
38 id: mpApplication
39
40 property bool desktopMode: true
41 property string playUri: ""
42 function getStoredPosition() { return -1 }
43 function storePosition(position) {}
44 }
45
46 Component {
47 id: playerComp
48
49 VideoPlayer {
50 id: player
51 width: 800
52 height: 600
53 }
54 }
55
56 LomiriTestCase {
57 name: "Date tests"
58
59 property var player: null
60 readonly property string videUri: Qt.resolvedUrl("../videos/small.ogg")
61
62 when: windowShown
63
64 function init()
65 {
66 player = playerComp.createObject(root, {})
67 waitForRendering(player)
68 }
69
70 function cleanup()
71 {
72 player.destroy()
73 player = null
74 }
75
76 function test_player_init()
77 {
78 tryCompare(player, 'paused', false)
79 tryCompare(player, 'playing', false)
80 tryCompare(player, 'wasPlaying', false)
81 tryCompare(player, 'isEmpty', true)
82 }
83
84 function test_empty_state()
85 {
86 tryCompare(player, 'isEmpty', true)
87 tryCompare(player, 'controlsActive', true)
88
89 // test if controls stay active after click on empty state
90 mouseClick(player)
91 tryCompare(player, 'controlsActive', true)
92
93 // play any uri should leave empty state
94 player.playUri(videUri)
95 tryCompare(player, 'isEmpty', false)
96 }
97
98 function test_open_video()
99 {
100 player.playUri(videUri)
101 tryCompare(player, 'paused', false)
102 tryCompare(player, 'playing', true)
103 }
104
105 function test_play_pause_video()
106 {
107 player.playUri(videUri)
108
109 tryCompare(player, 'isEmpty', false)
110 tryCompare(player, 'playing', true)
111 player.playPause()
112 tryCompare(player, 'paused', true)
113 player.playPause()
114 tryCompare(player, 'paused', false)
115 }
116
117 function test_click_to_show_and_hide_controls()
118 {
119 player.playUri(videUri)
120 tryCompare(player, 'playing', true)
121 tryCompare(player, 'controlsActive', false)
122
123 mouseClick(player)
124 tryCompare(player, 'controlsActive', true)
125
126 mouseClick(player)
127 tryCompare(player, 'controlsActive', false)
128 }
129
130 function test_pause_button()
131 {
132 // play video
133 player.playUri(videUri)
134 tryCompare(player, 'playing', true)
135
136 var toolbar = findChild(player, "toolbar")
137 tryCompare(toolbar, 'fullVisible', false)
138
139 // show controls
140 mouseClick(player)
141 tryCompare(player, 'controlsActive', true)
142 tryCompare(toolbar, 'fullVisible', true)
143 tryCompare(player, 'paused', false)
144
145 // click to pause
146 player.playPause()
147 tryCompare(player, 'paused', true)
148 }
149
150 function test_play_after_pause()
151 {
152 // play video
153 var toolbar = findChild(player, "toolbar")
154 player.playUri(videUri)
155 tryCompare(player, 'playing', true)
156
157 // show controls
158 mouseClick(player)
159 tryCompare(player, 'controlsActive', true)
160 tryCompare(toolbar, 'fullVisible', true)
161
162 // click to pause
163 player.playPause()
164 tryCompare(player, 'paused', true)
165
166 player.playPause()
167 tryCompare(player, 'paused', false)
168 }
169 }
170 }