1
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
2
# Copyright 2012 Canonical
4
# This file is part of phone-app.
6
# phone-app is free software: you can redistribute it and/or modify it
7
# under the terms of the GNU General Public License version 3, as published
8
# by the Free Software Foundation.
10
"""Phone App call/sms testing."""
12
from autopilot.input import Mouse, Touch, Pointer
13
from autopilot.matchers import Eventually
14
from autopilot.platform import model
15
from autopilot.testcase import AutopilotTestCase
16
from testtools.matchers import Equals, GreaterThan
18
from connected_tests.emulators.call_panel import CallPanel
19
from connected_tests.emulators.communication_panel import CommunicationPanel
25
config_file = os.path.expanduser('~/.testnumbers.cfg')
28
class PhoneAppTestCase(AutopilotTestCase):
29
"""A common test case class that provides several useful methods for
34
config = ConfigParser.ConfigParser()
35
config.read(config_file)
37
PHONE_NUMBER = config.get('connected_variables', 'dial_number')
38
SEND_SMS_NUMBER = config.get('connected_variables', 'sms_send_number')
39
RECEIVED_SMS_NUMBER = config.get('connected_variables', 'sms_receive_num')
40
CALL_WAIT = config.getint('connected_variables', 'call_wait_time')
41
CALL_DURATION = config.getint('connected_variables', 'outgoing_call_duration')
42
SEND_SMS_TEXT = config.get('connected_variables', 'sms_send_text')
43
RECEIVED_SMS_TEXT = config.get('connected_variables', 'sms_expect_text')
45
HOME = os.path.expanduser("~")
46
BACKUP = HOME + "/.local/share/TpLogger/logs/ofono_ofono_account0.backup/"
47
ORIGINAL = HOME + "/.local/share/TpLogger/logs/ofono_ofono_account0"
50
if model() == 'Desktop':
51
scenarios = [('with mouse', dict(input_device_class=Mouse))]
53
scenarios = [('with touch', dict(input_device_class=Touch))]
55
local_location = "../../src/phone-app"
58
self.pointing_device = Pointer(self.input_device_class.create())
59
super(PhoneAppTestCase, self).setUp()
60
self.delete_call_sms_logs()
62
self.addCleanup(self.restore_call_sms_logs)
64
if os.path.exists(self.local_location):
65
self.launch_test_local()
67
self.launch_test_installed()
69
main_view = self.get_main_view()
70
self.assertThat(main_view.visible, Eventually(Equals(True)))
72
def launch_test_local(self):
73
self.app = self.launch_test_application(
77
def launch_test_installed(self):
78
if model() == 'Desktop':
79
self.app = self.launch_test_application(
83
self.app = self.launch_test_application(
85
"--desktop_file_hint=/usr/share/applications/phone-app.desktop",
88
def get_main_view(self):
89
return self.app.select_single("QQuickView")
92
"""Returns the top tabs bar."""
93
return self.app.select_single("NewTabBar")
95
def get_conversations_tab_button(self):
96
return self.app.select_single("AbstractButton", buttonIndex=4)
98
def get_conversations_pane(self):
99
return self.app.select_single(
100
"PageStack", objectName="communicationsStack")
102
def switch_to_conversation_tab(self):
103
tabs_bar = self.get_tabs()
104
conversation_pane = self.get_conversations_pane()
105
self.pointing_device.click_object(tabs_bar)
107
conversations_tab_button = self.get_conversations_tab_button()
108
self.assertThat(conversations_tab_button.opacity,
109
Eventually(GreaterThan(0.35)))
110
self.pointing_device.click_object(conversations_tab_button)
112
self.assertThat(conversation_pane.isCurrent, Eventually(Equals(True)))
114
def number_to_object_name(self, string):
128
'buttonAsterisk' : '*'
130
for key, value in keys.items():
134
def dial_number(self, number):
135
for keys in str(number):
136
objectName = self.number_to_object_name(keys)
137
button = self.communication_panel.select_single_retry("KeypadButton", objectName=objectName)
138
self.pointing_device.click_object(button)
140
def reveal_toolbar(self):
141
main_view = self.get_main_view()
142
x_line = main_view.x + main_view.width * 0.5
143
start_y = main_view.y + main_view.height - 1
144
stop_y = start_y - 200
145
self.pointing_device.drag(x_line, start_y, x_line, stop_y)
147
def delete_call_sms_logs(self):
148
if os.path.exists(self.ORIGINAL):
149
shutil.move(self.ORIGINAL, self.BACKUP)
151
lambda: os.path.exists(self.BACKUP), Eventually(Equals(True)))
155
def restore_call_sms_logs(self):
156
if os.path.exists(self.BACKUP):
157
shutil.rmtree(self.ORIGINAL)
158
self.assertThat(lambda: os.path.exists(self.ORIGINAL), Eventually(Equals(False)))
159
shutil.move(self.BACKUP, self.ORIGINAL)
160
self.assertTrue(lambda: os.path.exists(self.ORIGINAL), Eventually(Equals(True)))
165
def call_panel(self):
166
return CallPanel(self.app)
169
def communication_panel(self):
170
return CommunicationPanel(self.app)