~canonical-platform-qa/ubuntu-system-tests/scalability_video_tests

« back to all changes in this revision

Viewing changes to ubuntu_system_tests/tests/test_calls.py

  • Committer: Sergio Cazzolato
  • Date: 2016-03-14 14:17:58 UTC
  • mfrom: (332.2.20 trunk)
  • Revision ID: sergio.cazzolato@canonical.com-20160314141758-ro1wj8lc6fl6pbe1
Merge with trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 
21
21
import shutil
22
22
import time
23
 
 
24
 
from retrying import retry
 
23
from datetime import datetime
 
24
from threading import Event
25
25
 
26
26
from autopilot.exceptions import StateNotFoundError
27
27
from autopilot.matchers import Eventually
28
 
from datetime import datetime
 
28
from retrying import retry
29
29
from testtools import skipUnless
30
30
from testtools.matchers import Equals
31
 
from threading import Event
32
31
 
33
32
from ubuntu_system_tests.helpers import addressbook
 
33
from ubuntu_system_tests.helpers import dialer_app as dialer
 
34
from ubuntu_system_tests.helpers import display
 
35
from ubuntu_system_tests.helpers import media
 
36
from ubuntu_system_tests.helpers import mediaplayer
 
37
from ubuntu_system_tests.helpers import network
 
38
from ubuntu_system_tests.helpers import ofono
 
39
from ubuntu_system_tests.helpers import scopes
 
40
from ubuntu_system_tests.helpers import sensors
 
41
from ubuntu_system_tests.helpers import webbrowser
34
42
from ubuntu_system_tests.helpers.addressbook import(
35
43
    Contact,
36
44
    fixture_setup as address_book_fixture
37
45
)
38
 
from ubuntu_system_tests.helpers import dialer_app as dialer
 
46
from ubuntu_system_tests.helpers.data import load_test_metadata
39
47
from ubuntu_system_tests.helpers.dialer_app import fixture_setup as dialer_fixture_setup  # NOQA
40
 
from ubuntu_system_tests.helpers import display
41
48
from ubuntu_system_tests.helpers import indicators
42
 
from ubuntu_system_tests.helpers import media
43
 
from ubuntu_system_tests.helpers import mediaplayer
 
49
from ubuntu_system_tests.helpers.indicators import(
 
50
    network as network_indicator
 
51
)
44
52
from ubuntu_system_tests.helpers.messaging.fixture_setup import (
45
53
    MessagingTestEnvironment)
46
 
from ubuntu_system_tests.helpers import network
47
 
from ubuntu_system_tests.helpers import ofono
 
54
from ubuntu_system_tests.helpers.music import launch_music_app
 
55
from ubuntu_system_tests.helpers.music.fixture_setup import (
 
56
    MusicAppWelcomeWizard)
48
57
from ubuntu_system_tests.helpers.ofono import fixture_setup as ofono_fixture_setup  # NOQA
49
58
from ubuntu_system_tests.helpers.power.fixture_setup import (
50
59
    EnablePowerdFakeSensors)
51
 
from ubuntu_system_tests.helpers.indicators import(
52
 
    network as network_indicator
53
 
)
54
 
from ubuntu_system_tests.helpers import scopes
55
 
from ubuntu_system_tests.helpers import sensors
56
60
from ubuntu_system_tests.helpers.system_settings.fixture_setup import SilentMode  # NOQA
57
61
from ubuntu_system_tests.helpers.timedate import get_current_utc_time
58
62
from ubuntu_system_tests.helpers.vibration import start_vibration_observer
59
 
from ubuntu_system_tests.helpers import webbrowser
60
 
 
61
63
from ubuntu_system_tests.tests.base import wait_until
62
64
from ubuntu_system_tests.tests.base_telephony import BaseTelephonyTestCase
63
 
from ubuntu_system_tests.tests.scopes.data import (
64
 
    LOCAL_VIDEO_FILE_3, SRC_VIDEO_FILE_3)
65
 
 
 
65
from ubuntu_system_tests.tests.data import (
 
66
    LOCAL_AUDIO_FILE_5, LOCAL_VIDEO_FILE_3, SRC_AUDIO_FILE_5, SRC_VIDEO_FILE_3)
66
67
 
67
68
CONTACT_NAME_1 = 'Fulano de Tal'
68
69
 
96
97
 
97
98
URL_UBUNTU = 'http://www.ubuntu.com/'
98
99
 
 
100
test_data = load_test_metadata()
 
101
 
99
102
 
100
103
class CallsTestCase(BaseTelephonyTestCase):
101
104
 
376
379
        self._assert_proximity_near()
377
380
        self._assert_proximity_far()
378
381
 
 
382
    def _assert_proximity_sensor_inactive(self):
 
383
        """Set proximity sensor to near and check that the display does not
 
384
        turn off.
 
385
        """
 
386
        self.assertTrue(display.is_display_on())
 
387
        sensors.set_proximity_near()
 
388
        self.addCleanup(sensors.set_proximity_far)
 
389
        self.assertFalse(wait_until(
 
390
            display.is_display_off, timeout=5),
 
391
            'Display turned off with near proximity when not expected.')
 
392
 
379
393
    def test_receive_incoming_call_from_contact(self):
380
394
        """
381
395
        Test to recive an incoming call from a contact.
581
595
 
582
596
        """
583
597
        self._create_observers()
584
 
        indicator = indicators.Indicator(
585
 
            self.shell, indicators.SOUND_INDICATOR,
586
 
            indicators.SOUND_INDICATOR_PAGE)
587
 
        indicator_page = indicator.open()
588
 
        self.addCleanup(indicator.ensure_closed)
 
598
        indicator, indicator_page = indicators.open_network_indicator(
 
599
            return_base=True)
589
600
 
590
601
        self.assertFalse(indicator_page.get_silent_mode_switcher().checked)
591
602
        indicator_page.enable_silent_mode()
690
701
 
691
702
    def _turn_off_wifi_enable_mobile_data(self):
692
703
        """Turn off wifi and enable data connection."""
693
 
        network_indicator.turn_off_wifi(self, self.shell)
 
704
        network_indicator.turn_off_wifi()
694
705
        self.addCleanup(self._turn_on_wifi_ensure_internet_connectivity, 30)
695
706
        if not network.is_mobile_data_enabled():
696
707
            network.turn_on_data_connection()
699
710
 
700
711
    def _turn_on_wifi_ensure_internet_connectivity(self, timeout):
701
712
        """Enable wifi and wait for internet availability."""
702
 
        network_indicator.turn_on_wifi(self, self.shell)
 
713
        network_indicator.turn_on_wifi()
703
714
        self.assertTrue(network.ensure_internet_connectivity(timeout=timeout))
704
715
 
705
716
    @skipUnless(ofono.is_sim_registered(0), 'No SIM in slot 1')
867
878
        player.play()
868
879
        self.assertTrue(player.playing)
869
880
 
870
 
        sensors.set_proximity_near()
871
 
        self.addCleanup(sensors.set_proximity_far)
872
 
        self.assertFalse(wait_until(
873
 
            display.is_display_off, timeout=5),
874
 
            'Display turned off with near proximity during video playback.')
 
881
        self._assert_proximity_sensor_inactive()
 
882
 
 
883
    def test_receive_call_during_music_playback(self):
 
884
        """
 
885
        Receive an incoming call during music playback.
 
886
        1. Copy music to the device.
 
887
        2. Launch the Music app and switch to songs view.
 
888
        3. Select the song to start playing.
 
889
        4. Receive incoming call.
 
890
        5. Ensure the music is paused as soon as the notification appears.
 
891
        6. Accept the call and ensure proximity sensor is functional.
 
892
        7. Terminate the call from remote end.
 
893
        8. Ensure music playback resumes when the call is terminated.
 
894
        """
 
895
        self.useFixture(media.BackupRestoreLocalMediaFixture())
 
896
        self.useFixture(MusicAppWelcomeWizard(show_wizard=False))
 
897
        shutil.copy2(SRC_AUDIO_FILE_5, LOCAL_AUDIO_FILE_5)
 
898
 
 
899
        music_app = launch_music_app()
 
900
        songs = music_app.get_songs_page()
 
901
        now_playing = songs.play_track(0)
 
902
        self.assertEqual(
 
903
            now_playing.get_artist(), test_data.audio.noise60.artist)
 
904
        self.assertEqual(
 
905
            now_playing.get_title(), test_data.audio.noise60.title)
 
906
        player = now_playing.player
 
907
        self.assertTrue(player.isPlaying)
 
908
 
 
909
        call = self.telephony.make_phonecall(
 
910
            to=self.get_device_phone_number(),
 
911
            from_=self.contact_1.number,
 
912
            hangup_timeout=10,
 
913
            call_url=CALL_URL_30_SEC)
 
914
        call_notifier = self._get_incoming_call_notification()
 
915
        self.assertFalse(player.isPlaying)
 
916
        stop_time = player.position
 
917
 
 
918
        call_notifier.start_call()
 
919
        call_page = dialer.get_dialer_app_proxy().live_call_page
 
920
        self._validate_call_started(call_page, self.contact_1.name)
 
921
        self.assertTrue(display.is_display_on())
 
922
        self._assert_proximity_sensor()
 
923
 
 
924
        self.telephony.hangup_call(call['sid'])
 
925
        self._validate_call_ended(call_page)
 
926
        self.assertTrue(player.isPlaying)
 
927
        self.assertGreaterEqual(player.position, stop_time)
 
928
 
 
929
        self._assert_proximity_sensor_inactive()