~ubuntu-branches/ubuntu/utopic/mediaplayer-app/utopic-proposed

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
# Copyright 2012 Canonical
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 3, as published
# by the Free Software Foundation.

"""Tests for the Mediaplayer App"""

from autopilot.matchers import Eventually
from autopilot.platform import model
from testtools import skipIf
from testtools.matchers import Equals, GreaterThan

from unittest import skip

from mediaplayer_app.tests import MediaplayerAppTestCase


class TestPlayerWithVideo(MediaplayerAppTestCase):
    """Tests the main media player features while playing a video """

    """ This is needed to wait for the application to start.
        In the testfarm, the application may take some time to show up."""
    def setUp(self):
        super(TestPlayerWithVideo, self).setUp()
        print(model())
        if model() in (
                'Nexus 4', 'Galaxy Nexus', "Nexus 7 (2013) Wi-Fi", "Nexus 10"):
            self.launch_app("h264.avi")
        else:
            self.launch_app("small.ogg")
        self.assertThat(
            self.main_window.get_qml_view().visible, Eventually(Equals(True)))
        # wait video player start
        player = self.main_window.get_player()
        self.assertThat(player.playing, Eventually(Equals(True)))

    def show_controls(self):
        video_area = self.main_window.get_video_area()
        self.pointing_device.click_object(video_area)
        toolbar = self.main_window.get_toolbar()
        self.assertThat(toolbar.ready, Eventually(Equals(True)))

    def pause_video(self):
        playback_button = self.main_window.get_playback_button()
        self.pointing_device.click_object(playback_button)

    def test_playback_button_states(self):
        self.show_controls()

        playback_button = self.main_window.get_playback_button()
        player = self.main_window.get_player()

        # Default state after load the video is playing and with pause icon.
        self.assertProperty(player, playing=True, paused=False)
        self.assertProperty(playback_button, icon="pause")

        self.pointing_device.click_object(playback_button)

        # First click must pause the video, change playing state and show play
        # icon.
        self.assertProperty(player, playing=False, paused=True)
        self.assertProperty(playback_button, icon="play")

        self.pointing_device.click()

        # Second click should change the state to playing again
        self.assertProperty(player, playing=True, paused=False)
        self.assertProperty(playback_button, icon="pause")

    @skipIf(model() in ('Nexus 4', 'Galaxy Nexus'),
            'Screen width not enough for seekbar')
    def test_time_display_behavior(self):
        self.show_controls()
        self.pause_video()

        time_line = self.main_window.get_slider()
        time_label = self.main_window.get_time_label()

        # Seek to the midle of the movie
        self.pointing_device.click_object(time_line)

        # Time label must show the current video time (diff from zero or empty)
        self.assertNotEqual(time_label.text, "00:00:00")
        self.assertNotEqual(time_label.text, "")

        # Click in the label to change the state
        self.pointing_device.click_object(time_label)

        # After the click the label must show the remaning time (with '-'
        # signal)
        self.assertEqual(time_label.text[0:1], "-")

    @skipIf(model() in ('Nexus 4', 'Galaxy Nexus'),
            'Screen width not enough for seekbar')
    def test_show_controls_at_end(self):
        controls = self.main_window.get_controls()
        # The controls are invisible by default
        self.assertThat(controls.visible, Eventually(Equals(False)))

        # wait for video ends and control appears
        self.assertThat(controls.visible, Eventually(Equals(True), timeout=35))