1
from mago.test_suite.pidgin import PidginTestSuite
2
from mago.application.pidgin import Pidgin
3
from ConfigParser import ConfigParser
4
import ldtp, ooldtp, ldtputils
5
from time import sleep, time
6
from shutil import copytree, move
7
from os.path import expanduser
9
class PidginNotifyApp(Pidgin):
10
MNU_INDICATOR_SERVER = "mnuPidginInternetMessenger"
11
EMB_INDICATOR_APPLET = "embindicator-applet"
13
def open(self, clean_profile=True, profile_template='',credentials=''):
14
Pidgin.open(self, clean_profile, profile_template, credentials)
15
self.wait_for_account_connect(self.get_account_name('XMPP'), 'XMPP')
17
# The notify plugin only starts working after 15 seconds.
18
# We start waiting from now to be safe.
23
self.buddy.disconnect()
25
if not ldtp.hasstate(self.WINDOW, self.WINDOW, ldtp.state.SHOWING):
26
self._click_in_indicator(self.MNU_INDICATOR_SERVER)
32
class PidginNotifyTest(PidginTestSuite):
33
APPLICATION_FACTORY = PidginNotifyApp
35
alias = self.application.get_account_alias('OtherXMPP')
36
if ldtp.guiexist('frm%s' % alias.replace(' ', '')):
37
self.application.close_conversation('frm%s' % alias.replace(' ', ''))
39
def _click_in_indicator(self, name):
40
objs = ldtp.getobjectlist(self.application.TOP_PANEL)
43
if obj.startswith(name):
44
if self._is_in_indicator(obj):
45
ldtp.selectmenuitem(self.application.TOP_PANEL, obj)
48
raise Exception('%s does not appear in indicator applet' % name)
50
def _is_in_indicator(self, obj):
51
parent = ldtp.getobjectproperty(self.application.TOP_PANEL, obj, 'parent')
52
while parent != self.application.TOP_PANEL:
53
if parent == self.application.EMB_INDICATOR_APPLET:
55
parent = ldtp.getobjectproperty(self.application.TOP_PANEL,
59
def _is_bubble(self, frm_name):
60
return ldtp.getobjectproperty(
61
frm_name, frm_name, 'parent') == 'notify-osd'
63
def _bubble_body(self, frm_name):
64
return ldtp.getobjectproperty(frm_name, frm_name, 'description')
66
def _bubble_name_from_alias(self, name):
67
return 'dlg%s' % name.replace(' ', '')
69
def testIndicatorServer(self):
72
ldtp.hasstate(self.application.WINDOW, self.application.WINDOW, ldtp.state.SHOWING))
74
self._click_in_indicator(self.application.MNU_INDICATOR_SERVER)
78
ldtp.hasstate(self.application.WINDOW, self.application.WINDOW, ldtp.state.SHOWING))
80
self._click_in_indicator(self.application.MNU_INDICATOR_SERVER)
84
ldtp.hasstate(self.application.WINDOW, self.application.WINDOW, ldtp.state.SHOWING))
86
if flipflop not in ([1, 0, 1], [0, 1, 0]):
87
raise AssertionError, \
88
'indicator server menu item did not show/hide the buddy list'
90
def testBuddyLogin(self):
91
self.application.buddy_login()
92
alias = self.application.get_account_alias('OtherXMPP')
99
frm_name = self._bubble_name_from_alias(alias)
101
frm_name += str(count)
102
result = ldtp.waittillguiexist(frm_name)
104
frm = ooldtp.context(frm_name)
105
if self._is_bubble(frm_name) and \
106
self._bubble_body(frm_name) == 'is online':
111
raise AssertionError, 'did not recieve a notification bubble.'
113
ldtp.remap(self.application.TOP_PANEL)
115
self._click_in_indicator('mnu%s' % alias.replace(' ', ''))
117
raise AssertionError(e[-1])
120
result = ldtp.waittillguiexist('frm%s' % alias.replace(' ', ''))
124
'clicking on buddy indicator did not bring up chat dialog'
126
def testRecieveMessageAppend(self, msg1='', msg2='', msg3='', timeout=5):
127
if not self.application.buddy:
128
self.application.buddy_login()
131
jid = self.application.get_account_name('XMPP')
133
alias = self.application.get_account_alias('OtherXMPP')
135
#https://bugs.launchpad.net/ubuntu/+source/pidgin-libnotify/+bug/362248
136
ldtp.waittillguinotexist(self._bubble_name_from_alias(alias))
138
self.application.buddy.send_message(jid, '', msg1)
140
self.application.buddy.send_message(jid, '', msg2)
147
frm_name = self._bubble_name_from_alias(alias)
149
frm_name += str(count)
150
result = ldtp.waittillguiexist(frm_name)
152
if self._is_bubble(frm_name) and \
153
self._bubble_body(frm_name) == msg2:
158
raise AssertionError, \
159
'did not recieve a message notification bubble.'
161
self.application.buddy.send_message(jid, '', msg3)
163
for i in xrange(timeout):
166
if self._bubble_body(frm_name) == '%s\n%s' % (msg2, msg3):
168
except ldtp.LdtpExecutionError:
169
screeny = ldtputils.imagecapture()
170
raise AssertionError(
171
'notification for second message does not exist',
175
raise AssertionError, 'second message was not appended'
177
def testRecieveMessageSimple(self, msg1='', msg2='', timeout=5):
178
if not self.application.buddy:
179
self.application.buddy_login()
182
jid = self.application.get_account_name('XMPP')
184
alias = self.application.get_account_alias('OtherXMPP')
186
#https://bugs.launchpad.net/ubuntu/+source/pidgin-libnotify/+bug/362248
187
ldtp.waittillguinotexist(self._bubble_name_from_alias(alias))
189
self.application.buddy.send_message(jid, '', msg1)
191
self.application.buddy.send_message(jid, '', msg2)
198
frm_name = self._bubble_name_from_alias(alias)
200
frm_name += str(count)
201
result = ldtp.waittillguiexist(frm_name)
203
if self._is_bubble(frm_name) and \
204
self._bubble_body(frm_name) == msg2:
209
raise AssertionError, \
210
'did not recieve a message notification bubble.'