1
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
2
# Copyright 2013 Canonical
3
# Author: Martin Pitt <martin.pitt@ubuntu.com>
5
# This file is part of dialer-app.
7
# dialer-app is free software: you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License version 3, as published
9
# by the Free Software Foundation.
11
"""Tests for the Dialer App using ofono-phonesim"""
13
from __future__ import absolute_import
19
from autopilot.matchers import Eventually
20
from testtools.matchers import Equals, NotEquals
21
from testtools import skipUnless
23
from dialer_app.tests import DialerAppTestCase
25
# determine whether we are running with phonesim
27
out = subprocess.check_output(["/usr/share/ofono/scripts/list-modems"],
28
stderr=subprocess.PIPE)
29
have_phonesim = out.startswith("[ /phonesim ]")
30
except subprocess.CalledProcessError:
34
@skipUnless(have_phonesim,
35
"this test needs to run under with-ofono-phonesim")
36
class TestCalls(DialerAppTestCase):
37
"""Tests for simulated phone calls."""
40
# provide clean history
41
self.history = os.path.expanduser(
42
"~/.local/share/history-service/history.sqlite")
43
if os.path.exists(self.history):
44
subprocess.call(["pkill", "history-daemon"])
45
os.rename(self.history, self.history + ".orig")
47
super(TestCalls, self).setUp()
48
self.entry = self.main_view.dialer_page.get_keypad_entry()
49
self.call_button = self.main_view.dialer_page.get_call_button()
50
self.hangup_button = None
52
# should have an empty history at the beginning of each test
53
self.history_list = self.app.select_single(objectName="historyList")
54
self.assertThat(self.history_list.visible, Equals(False))
55
self.assertThat(self.history_list.count, Equals(0))
59
self.keys.append(self.main_view.dialer_page.get_keypad_key(str(i)))
62
super(TestCalls, self).tearDown()
64
# ensure that there are no leftover calls in case of failed tests
65
subprocess.call(["/usr/share/ofono/scripts/hangup-all"])
68
if os.path.exists(self.history + ".orig"):
69
subprocess.call(["pkill", "history-daemon"])
70
os.rename(self.history + ".orig", self.history)
72
def test_outgoing_noanswer(self):
73
"""Outgoing call to a normal number, no answer"""
75
self.keypad_dial("144")
76
self.wait_live_call_page("144")
79
# log should show call to "Unknown"
80
self.assertThat(self.history_list.count, Equals(1))
81
self.assertThat(self.history_list.select_single(
82
"Label", text="Unknown"), NotEquals(None))
84
def test_outgoing_answer_local_hangup(self):
85
"""Outgoing call, remote answers, local hangs up"""
87
# 06123xx causes accept after xx seconds
88
self.keypad_dial("0612302")
89
self.wait_live_call_page("0612302")
91
# stop watch should start counting
92
stop_watch = self.app.select_single(objectName="stopWatch")
93
self.assertIn("00:0", stop_watch.elapsed)
95
# should still be connected after some time
97
self.assertIn("00:0", stop_watch.elapsed)
101
def test_outgoing_answer_remote_hangup(self):
102
"""Outgoing call, remote answers and hangs up"""
104
# 05123xx causes immediate accept and hangup after xx seconds
105
self.keypad_dial("0512303")
106
self.wait_live_call_page("0512303")
108
# stop watch should start counting
109
stop_watch = self.app.select_single(objectName="stopWatch")
110
self.assertIn("00:0", stop_watch.elapsed)
112
# after remote hangs up, should switch to call log page and show call
114
fn = lambda: self.app.select_single(objectName="hangupButton")
115
self.assertThat(fn, Eventually(Equals(None)))
116
self.assertThat(self.history_list.visible, Eventually(Equals(True)))
117
self.assertThat(self.history_list.count, Equals(1))
118
self.assertThat(self.history_list.select_single(
119
"Label", text="Unknown"), NotEquals(None))
121
def test_incoming(self):
124
# magic number 199 will cause a callback from 1234567; dialing 199
125
# itself will fail, so quiesce the error
126
subprocess.call(["/usr/share/ofono/scripts/dial-number", "199"],
127
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
129
# wait for incoming call, accept; it would be nicer to fake-click the
130
# popup notification, but as this isn't generated by dialer-app it
131
# isn't exposed to autopilot
132
self.wait_for_incoming_call()
133
subprocess.call(["/usr/share/ofono/scripts/answer-calls"],
134
stdout=subprocess.PIPE)
136
# call back is from that number
137
self.wait_live_call_page("1234567")
139
# stop watch should start counting
140
stop_watch = self.app.select_single(objectName="stopWatch")
141
self.assertIn("00:0", stop_watch.elapsed)
149
def keypad_dial(self, number):
150
"""Dial given number (string) on the keypad and call"""
152
self.pointing_device.click_object(self.keys[int(digit)])
153
self.assertThat(self.entry.value, Eventually(Equals(number)))
155
self.pointing_device.click_object(self.call_button)
157
def wait_live_call_page(self, number):
158
"""Wait until live call page gets visible
160
Sets self.hangup_button.
162
fn = lambda: self.app.select_single(objectName="hangupButton")
163
self.assertThat(fn, Eventually(NotEquals(None)))
164
self.hangup_button = self.app.select_single(objectName="hangupButton")
165
self.assertThat(self.hangup_button.visible, Eventually(Equals(True)))
166
self.assertThat(self.call_button.visible, Equals(False))
168
# should show called number in title page
169
lcp = self.app.select_single(objectName="pageLiveCall")
170
self.assertThat(lcp.title, Equals(number))
172
def wait_for_incoming_call(self):
173
"""Wait up to 5 s for an incoming phone call"""
177
out = subprocess.check_output(
178
["/usr/share/ofono/scripts/list-calls"],
179
stderr=subprocess.PIPE)
180
if "State = incoming" in out:
185
self.fail("timed out waiting for incoming phonesim call")
188
self.pointing_device.click_object(self.hangup_button)
189
fn = lambda: self.app.select_single(objectName="hangupButton")
190
self.assertThat(fn, Eventually(Equals(None)))
192
# should switch to call log page
193
self.assertThat(self.history_list.visible, Eventually(Equals(True)))