~ubuntu-branches/ubuntu/natty/mago/natty

« back to all changes in this revision

Viewing changes to mago/application/gnome.py

  • Committer: Bazaar Package Importer
  • Author(s): Ara Pulido
  • Date: 2009-08-04 09:21:40 UTC
  • Revision ID: james.westby@ubuntu.com-20090804092140-mnc0rm2tr7smo107
Tags: upstream-0.1
ImportĀ upstreamĀ versionĀ 0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
"""
 
2
This is the "gnome" module.
 
3
 
 
4
The gnome module provides wrappers for LDTP to make the write of Gnome tests easier. 
 
5
"""
 
6
import ooldtp
 
7
import ldtp 
 
8
from .main import Application
 
9
 
 
10
class Seahorse(Application):
 
11
    """
 
12
    Seahorse manages the Seahorse application.
 
13
    """
 
14
    WINDOW       = "frmPasswordsandEncryptionKeys"
 
15
    LAUNCHER     = "seahorse"
 
16
    MNU_NEWKEY   = "mnuNew"
 
17
    NEWKEY_DLG   = "Create New ..."
 
18
    BTN_CONTINUE = "btnContinue"
 
19
    TYPE_PGP            = "PGP Key"
 
20
    NEWPGP_DLG          = "dlgCreateaPGPKey"
 
21
    DLG_NEWPGP_FULLNAME = "txtFullName"
 
22
    DLG_NEWPGP_EMAIL    = "txtEmailAddress"
 
23
    DLG_NEWPGP_COMMENT  = "txtComment"
 
24
    BTN_NEWPGP_CREATE   = "btnCreate"
 
25
    DLG_NEWKEY_PASS     = "dlgPassphrasefor*"
 
26
    BTN_PASS_OK         = "btnOK"
 
27
    DLG_GENERATING_KEY  = "dlgGeneratingkey"
 
28
    DLG_CREATING_SSH    = "dlgCreatingSecureShellKey"
 
29
    TYPE_SSH            = "Secure Shell Key"
 
30
    NEWSSH_DLG          = "New Secure Shell Key" 
 
31
    DLG_NEWSSH_DESC     = "txtKeyDescription"
 
32
    BTN_NEWSSH_CREATE_AND_SETUP = "Create and Set Up"
 
33
    DLG_SET_UP          = "Set Up Computer for SSH Connection"
 
34
    TXT_SET_UP_COMPUTER = "txtThehostnameoraddressoftheserver."
 
35
    TXT_SET_UP_LOGIN    = "txtLoginName"
 
36
    BTN_SET_UP          = "btnSetUp"
 
37
    BTN_NEWSSH_CREATE   = "Just Create Key"
 
38
    TAB_PERSONAL_KEYS   = "My Personal Keys"
 
39
    TAB_LIST            = "ptl0"
 
40
    TBL_PERSONAL_KEYS   = "tbl0"
 
41
    LBL_DELETE_KEY_Q   = "lblOneormoreofthedeletedkeysareprivatekeys.Areyousureyouwanttoproceed?"
 
42
 
 
43
    def __init__(self):
 
44
        Application.__init__(self)
 
45
        self.generated_keys = []
 
46
 
 
47
    def new_key(self, key_type):
 
48
        """
 
49
        It opens up the list of available new keys, and select the one to create.
 
50
        
 
51
        @type key_type: string
 
52
        @param key_type: The type of key to create. 
 
53
        """
 
54
        
 
55
        seahorse = ooldtp.context(self.name)
 
56
        
 
57
        try:
 
58
            mnu_new_key = seahorse.getchild(self.MNU_NEWKEY)
 
59
        except ldtp.LdtpExecutionError:
 
60
            raise ldtp.LdtpExecutionError, "The new key menu was not found."
 
61
 
 
62
        try:
 
63
            mnu_new_key.selectmenuitem() 
 
64
        except ldtp.LdtpExecutionError:
 
65
            raise ldtp.LdtpExecutionError, "There was a problem when selecting new key menu item."
 
66
 
 
67
        try:
 
68
            ldtp.waittillguiexist(self.NEWKEY_DLG)
 
69
            dlg_new_key = ooldtp.context(self.NEWKEY_DLG)
 
70
        except ldtp.LdtpExecutionError:
 
71
            raise ldtp.LdtpExecutionError, "The new key dialog was not found."
 
72
 
 
73
        try:
 
74
            table  = dlg_new_key.getchild(role = 'table')
 
75
            types_table = table[0]
 
76
 
 
77
            for i in range(0, types_table.getrowcount(), 1):
 
78
                text = types_table.getcellvalue(i, 1)
 
79
                candidate = text.split('\n')[0]
 
80
                if candidate == key_type:
 
81
                    types_table.selectrowindex(i)
 
82
                    break
 
83
                ldtp.wait(1)
 
84
        except ldtp.LdtpExecutionError:
 
85
            raise ldtp.LdtpExecutionError, "Error getting the key types table."
 
86
 
 
87
        try:
 
88
            btn_continue = dlg_new_key.getchild(self.BTN_CONTINUE)
 
89
        except ldtp.LdtpExecutionError:
 
90
            raise ldtp.LdtpExecutionError, "The continue button at the new key dialog was not found."
 
91
 
 
92
        try:
 
93
            btn_continue.click() 
 
94
        except ldtp.LdtpExecutionError:
 
95
            raise ldtp.LdtpExecutionError, "There was a problem when clicking the continue button."
 
96
        
 
97
    def new_pgp_key(self, full_name, email, comment, passphrase):
 
98
        """
 
99
        It creates a new PGP key with the default settings.
 
100
 
 
101
        TODO: Allow advanced options
 
102
        TODO: Check the list afterwards for the newly created key
 
103
 
 
104
        @type full_name: string 
 
105
        @param full_name: Full name to type for the PGP key
 
106
 
 
107
        @type email: string 
 
108
        @param email: Email to type for the PGP key
 
109
 
 
110
        @type comment: string 
 
111
        @param comment: Comment to type for the PGP key
 
112
 
 
113
        @type passphrase: string 
 
114
        @param passphrase: Passphrase to type for the PGP key
 
115
        """
 
116
        
 
117
        self.new_key(self.TYPE_PGP)
 
118
 
 
119
        try:
 
120
            ldtp.waittillguiexist(self.NEWPGP_DLG)
 
121
            dlg_new_pgp = ooldtp.context(self.NEWPGP_DLG)
 
122
        except ldtp.LdtpExecutionError:
 
123
            raise ldtp.LdtpExecutionError, "The new key dialog was not found."
 
124
 
 
125
        try:
 
126
            txt_field = dlg_new_pgp.getchild(self.DLG_NEWPGP_FULLNAME)
 
127
        except ldtp.LdtpExecutionError:
 
128
            raise ldtp.LdtpExecutionError, "The " + txt_field + " text field was not found."
 
129
        try:
 
130
            txt_field.settextvalue(full_name)
 
131
        except ldtp.LdtpExecutionError:
 
132
            raise ldtp.LdtpExecutionError, "There was an error when writing the text."
 
133
 
 
134
        try:
 
135
            txt_field = dlg_new_pgp.getchild(self.DLG_NEWPGP_EMAIL)
 
136
        except ldtp.LdtpExecutionError:
 
137
            raise ldtp.LdtpExecutionError, "The " + txt_field + " text field was not found."
 
138
        try:
 
139
            txt_field.settextvalue(email)
 
140
        except ldtp.LdtpExecutionError:
 
141
            raise ldtp.LdtpExecutionError, "There was a problem when writing the text."
 
142
   
 
143
        try:
 
144
            txt_field = dlg_new_pgp.getchild(self.DLG_NEWPGP_COMMENT)
 
145
        except ldtp.LdtpExecutionError:
 
146
            raise ldtp.LdtpExecutionError, "The " + txt_field + " text field was not found."
 
147
        try:
 
148
            txt_field.settextvalue(comment)
 
149
        except ldtp.LdtpExecutionError:
 
150
            raise ldtp.LdtpExecutionError, "There was a problem when writing the text."
 
151
 
 
152
        try:
 
153
            btn_create = dlg_new_pgp.getchild(self.BTN_NEWPGP_CREATE)
 
154
        except ldtp.LdtpExecutionError:
 
155
            raise ldtp.LdtpExecutionError, "The create button at the new PGP key dialog was not found."
 
156
 
 
157
        try:
 
158
            btn_create.click() 
 
159
        except ldtp.LdtpExecutionError:
 
160
            raise ldtp.LdtpExecutionError, "There was a problem when clicking the create button."
 
161
       
 
162
        try:
 
163
            ldtp.waittillguiexist(self.DLG_NEWKEY_PASS)
 
164
            dlg_new_pgp_pass = ooldtp.context(self.DLG_NEWKEY_PASS)
 
165
        except ldtp.LdtpExecutionError:
 
166
            raise ldtp.LdtpExecutionError, "The new pgp key passphrase dialog was not found."
 
167
 
 
168
        try:
 
169
            ldtp.enterstring(passphrase)
 
170
            ldtp.enterstring("<tab>")
 
171
            ldtp.enterstring(passphrase)
 
172
        except ldtp.LdtpExecutionError:
 
173
            raise ldtp.LdtpExecutionError, "Error entering passphrase."
 
174
 
 
175
        try:
 
176
            btn_pass_ok = dlg_new_pgp_pass.getchild(self.BTN_PASS_OK)
 
177
        except ldtp.LdtpExecutionError:
 
178
            raise ldtp.LdtpExecutionError, "The OK button at the new PGP key passphrase dialog was not found."
 
179
 
 
180
        try:
 
181
            btn_pass_ok.click() 
 
182
        except ldtp.LdtpExecutionError:
 
183
            raise ldtp.LdtpExecutionError, "There was a problem when clicking the OK button."
 
184
 
 
185
        try:
 
186
            ldtp.waittillguiexist(self.DLG_GENERATING_KEY)
 
187
            while ldtp.guiexist(self.DLG_GENERATING_KEY) == 1:
 
188
                ldtp.wait(1)
 
189
        except ldtp.LdtpExecutionError:
 
190
            raise ldtp.LdtpExecutionError, "The new pgp generating key dialog was not found."
 
191
 
 
192
        # Add key name to generated key list, so we know to delete it later.
 
193
        self.generated_keys.append('  '.join([full_name, email, "'"+comment+"'"]))
 
194
 
 
195
    def new_ssh_key(self, description, passphrase, set_up = False, computer = '', login = ''):
 
196
        """
 
197
        It creates a new SSH key with the default settings.
 
198
 
 
199
        TODO: Setting up the key is not working yet
 
200
 
 
201
        @type description: string 
 
202
        @param description: Description to type in the SSH key
 
203
 
 
204
        @type passphrase: string 
 
205
        @param passphrase: Passphrase to type for the SSH key
 
206
 
 
207
        @type set_up: boolean 
 
208
        @param passphrase: True, to set up the SSH key
 
209
 
 
210
        @type computer: string 
 
211
        @param computer: URL or IP of the computer to set up the key
 
212
        
 
213
        @type login: string
 
214
        @param login: Login to use in the remote computer
 
215
        """
 
216
        
 
217
        self.new_key(self.TYPE_SSH)
 
218
 
 
219
        try:
 
220
            ldtp.waittillguiexist(self.NEWSSH_DLG)
 
221
            dlg_new_ssh = ooldtp.context(self.NEWSSH_DLG)
 
222
        except ldtp.LdtpExecutionError:
 
223
            raise ldtp.LdtpExecutionError, "The new key dialog was not found."
 
224
 
 
225
        try:
 
226
            txt_field = dlg_new_ssh.getchild(self.DLG_NEWSSH_DESC)
 
227
        except ldtp.LdtpExecutionError:
 
228
            raise ldtp.LdtpExecutionError, "The " + self.DLG_NEWSSH_DESC + " text field was not found."
 
229
        try:
 
230
            txt_field.settextvalue(description)
 
231
        except ldtp.LdtpExecutionError:
 
232
            raise ldtp.LdtpExecutionError, "There was an error when writing the text."
 
233
 
 
234
        if set_up == True:
 
235
            try:
 
236
                btn_create = dlg_new_ssh.getchild(self.BTN_NEWSSH_CREATE_AND_SETUP)
 
237
            except ldtp.LdtpExecutionError:
 
238
                raise ldtp.LdtpExecutionError, "The create button at the new PGP key dialog was not found."
 
239
 
 
240
        else:
 
241
            try:
 
242
                btn_create = dlg_new_ssh.getchild(self.BTN_NEWSSH_CREATE)
 
243
            except ldtp.LdtpExecutionError:
 
244
                raise ldtp.LdtpExecutionError, "The create button at the new PGP key dialog was not found."
 
245
 
 
246
        try:
 
247
            btn_create.click() 
 
248
        except ldtp.LdtpExecutionError:
 
249
            raise ldtp.LdtpExecutionError, "There was a problem when clicking the create button."
 
250
      
 
251
 
 
252
        try:
 
253
            ldtp.waittillguiexist(self.DLG_NEWKEY_PASS)
 
254
            dlg_new_key_pass = ooldtp.context(self.DLG_NEWKEY_PASS)
 
255
        except ldtp.LdtpExecutionError:
 
256
            raise ldtp.LdtpExecutionError, "The new key passphrase dialog was not found."
 
257
 
 
258
        try:
 
259
            ldtp.enterstring(passphrase)
 
260
            ldtp.enterstring("<tab>")
 
261
            ldtp.enterstring(passphrase)
 
262
        except ldtp.LdtpExecutionError:
 
263
            raise ldtp.LdtpExecutionError, "Error entering passphrase."
 
264
 
 
265
        try:
 
266
            btn_pass_ok = dlg_new_key_pass.getchild(self.BTN_PASS_OK)
 
267
        except ldtp.LdtpExecutionError:
 
268
            raise ldtp.LdtpExecutionError, "The OK button at the new key passphrase dialog was not found."
 
269
 
 
270
        try:
 
271
            btn_pass_ok.click() 
 
272
        except ldtp.LdtpExecutionError:
 
273
            raise ldtp.LdtpExecutionError, "There was a problem when clicking the OK button."
 
274
 
 
275
        if set_up == True and login is not None:
 
276
 
 
277
            try:
 
278
                ldtp.waittillguiexist(self.DLG_SET_UP)
 
279
                dlg_set_up_computer = ooldtp.context(self.DLG_SET_UP)
 
280
            except ldtp.LdtpExecutionError:
 
281
                raise ldtp.LdtpExecutionError, "The set up computer dialog was not found."
 
282
 
 
283
            try:
 
284
                txt_field = dlg_set_up_computer.getchild(self.TXT_SET_UP_LOGIN)
 
285
            except ldtp.LdtpExecutionError:
 
286
                raise ldtp.LdtpExecutionError, "The " + self.TXT_SET_UP_LOGIN + " text field was not found."
 
287
            try:
 
288
                txt_field.settextvalue(login)
 
289
            except ldtp.LdtpExecutionError:
 
290
                raise ldtp.LdtpExecutionError, "There was an error when writing the text."
 
291
 
 
292
        if set_up == True:
 
293
            try:
 
294
                txt_field = dlg_set_up_computer.getchild(self.TXT_SET_UP_COMPUTER)
 
295
            except ldtp.LdtpExecutionError:
 
296
                raise ldtp.LdtpExecutionError, "The " + self.TXT_SET_UP_COMPUTER + " text field was not found."
 
297
            try:
 
298
                txt_field.settextvalue(computer)
 
299
            except ldtp.LdtpExecutionError:
 
300
                raise ldtp.LdtpExecutionError, "There was an error when writing the text."
 
301
 
 
302
            try:
 
303
                btn_set_up = dlg_set_up_computer.getchild(self.BTN_SET_UP)
 
304
            except ldtp.LdtpExecutionError:
 
305
                raise ldtp.LdtpExecutionError, "The set up button was not found."
 
306
 
 
307
            try:
 
308
                btn_set_up.click() 
 
309
            except ldtp.LdtpExecutionError:
 
310
                raise ldtp.LdtpExecutionError, "There was a problem when clicking the set up button."
 
311
            
 
312
        try:
 
313
            while ldtp.guiexist(self.DLG_CREATING_SSH) == 1:
 
314
                ldtp.wait(1)
 
315
            
 
316
        except ldtp.LdtpExecutionError:
 
317
            raise ldtp.LdtpExecutionError, "The creating key dialog was not found."
 
318
        # Add key name to generated key list, so we know to delete it later.
 
319
        self.generated_keys.append(description)
 
320
 
 
321
        # It is too fast to grab the main window afterwards
 
322
        ldtp.wait(3)
 
323
 
 
324
    def go_to_tab(self, tab_name):
 
325
        """
 
326
        Go to the specified tab.
 
327
        """
 
328
        seahorse = ooldtp.context(self.name)
 
329
        page_list = seahorse.getchild(self.TAB_LIST)
 
330
        page_list.selecttab(self.TAB_PERSONAL_KEYS)
 
331
        
 
332
 
 
333
    def assert_exists_key(self, name, tab_name = None):
 
334
        """
 
335
        It checks that the KEY with description 'description' is
 
336
        part of the keys of the current user
 
337
 
 
338
        @type name: string
 
339
        @param name: The name of the key to search
 
340
        
 
341
        @type tab_name: string
 
342
        @param tab_name: The tab name to search for the key.
 
343
        """
 
344
        if not tab_name:
 
345
            tab_name = self.TAB_PERSONAL_KEYS
 
346
 
 
347
        self.go_to_tab(tab_name)
 
348
        seahorse = ooldtp.context(self.name)
 
349
        return bool(seahorse.doesrowexist(self.TBL_PERSONAL_KEYS, name))
 
350
 
 
351
    def remove_key(self, key):
 
352
        seahorse = ooldtp.context(self.name)
 
353
 
 
354
        tbl_personal_keys = seahorse.getchild(self.TBL_PERSONAL_KEYS)
 
355
        mnu_delete = seahorse.getchild('mnuDelete')
 
356
        dlg_question = ooldtp.context('dlgQuestion')
 
357
        
 
358
        try:
 
359
            tbl_personal_keys.selectrow(key)
 
360
        except ldtp.LdtpExecutionError:
 
361
            # Doesn't exist, return False.
 
362
            return False
 
363
 
 
364
        mnu_delete.selectmenuitem()
 
365
        # General 'private key' verification.
 
366
        dlg_question.waittillguiexist(self.LBL_DELETE_KEY_Q)
 
367
        dlg_question.click('btnDelete')
 
368
        dlg_question.waittillguinotexist(self.LBL_DELETE_KEY_Q)
 
369
 
 
370
        # Specific key type verification.
 
371
        dlg_question.waittillguiexist()
 
372
        dlg_question.click('btnDelete')
 
373
        dlg_question.waittillguinotexist()
 
374
        
 
375
        return True
 
376
 
 
377
    def remove_keys(self, keys=None, tab_name=None):
 
378
        self.go_to_tab(tab_name or self.TAB_PERSONAL_KEYS)
 
379
 
 
380
        keys = keys or self.generated_keys
 
381
 
 
382
        for key in keys:
 
383
            self.remove_key(key)
 
384
        
 
385
class GEdit(Application):
 
386
    """
 
387
    GEdit manages the Gedit application.
 
388
    """
 
389
    WINDOW     = "frm*gedit"
 
390
    TXT_FIELD  = "txt1"
 
391
    LAUNCHER   = "gedit"
 
392
    SAVE_DLG   = "dlgSave*"
 
393
    SAVE_DLG_TXT_NAME = "txtName"
 
394
    SAVE_DLG_BTN_SAVE = "btnSave"
 
395
    QUESTION_DLG = "dlgQuestion"
 
396
    QUESTION_DLG_BTN_SAVE = "btnSave"
 
397
    QUESTION_DLG_BTN_SAVE_AS = "btnSaveAs"
 
398
    QUESTION_DLG_BTN_CLOSE = "btnClosewithoutSaving"
 
399
    MNU_QUIT = "mnuQuit"
 
400
    MNU_CLOSE = "mnuClose"
 
401
    MNU_NEW = "mnuNew"
 
402
 
 
403
    def __init__(self):
 
404
        Application.__init__(self)
 
405
 
 
406
 
 
407
    def write_text(self, text):
 
408
        """
 
409
        It writes text to the current buffer of the Gedit window.
 
410
 
 
411
        @type text: string
 
412
        @param text: The text string to be written to the current buffer.
 
413
        """
 
414
        Application.write_text(self, text, self.TXT_FIELD)
 
415
 
 
416
    def save(self, filename):
 
417
        """
 
418
        It tries to save the current opened buffer to the filename passed as parameter.
 
419
 
 
420
        TODO: It does not manage the overwrite dialog yet.
 
421
 
 
422
        @type filename: string
 
423
        @param filename: The name of the file to save the buffer to.
 
424
        """
 
425
        Application.save(self)
 
426
        ooldtp.context(self.name)
 
427
 
 
428
        try:
 
429
            ldtp.waittillguiexist(self.SAVE_DLG)
 
430
            save_dialog = ooldtp.context(self.SAVE_DLG)
 
431
        except ldtp.LdtpExecutionError:
 
432
            raise ldtp.LdtpExecutionError, "The Gedit save dialog was not found."
 
433
        try:
 
434
            save_dlg_txt_filename = save_dialog.getchild(self.SAVE_DLG_TXT_NAME)
 
435
        except ldtp.LdtpExecutionError:
 
436
            raise ldtp.LdtpExecutionError, "The filename txt field in Gedit save dialog was not found."
 
437
        try:
 
438
            ldtp.wait(2)
 
439
            save_dlg_txt_filename.settextvalue(filename)
 
440
        except ldtp.LdtpExecutionError:
 
441
           raise ldtp.LdtpExecutionError, "We couldn't write text."
 
442
 
 
443
        try:
 
444
            save_dlg_btn_save = save_dialog.getchild(self.SAVE_DLG_BTN_SAVE)
 
445
        except ldtp.LdtpExecutionError:
 
446
            raise ldtp.LdtpExecutionError, "The button Save in Gedit save dialog was not found."
 
447
        
 
448
        try:
 
449
            save_dlg_btn_save.click()
 
450
        except ldtp.LdtpExecutionError:
 
451
            raise ldtp.LdtpExecutionError, "There was an error when pushing the Save button."
 
452
 
 
453
        ldtp.waittillguinotexist(self.SAVE_DLG)
 
454
        ldtp.wait(1)
 
455
 
 
456
    def close(self, save=False, filename=''):
 
457
        """
 
458
        Given a gedit window, it tries to close the application.
 
459
        By default, it closes without saving. This behaviour can be changed to save (or save as) on close.
 
460
         
 
461
        @type save: boolean
 
462
        @param save: If True, the edited file will be saved on close.
 
463
 
 
464
        @type filename: string
 
465
        @param filename: The file name to save the buffer to 
 
466
        """
 
467
 
 
468
        # Exit using the Quit menu 
 
469
        try:
 
470
            gedit = ooldtp.context(self.name)
 
471
            try:
 
472
                quit_menu = gedit.getchild(self.MNU_QUIT)
 
473
            except ldtp.LdtpExecutionError:
 
474
                raise ldtp.LdtpExecutionError, "The quit menu was not found."
 
475
            quit_menu.selectmenuitem()
 
476
        except ldtp.LdtpExecutionError:
 
477
            raise ldtp.LdtpExecutionError, "Mmm, something went wrong when closing the application."
 
478
 
 
479
        question_dialog = None
 
480
        count = 0
 
481
        while not gedit.waittillguinotexist(guiTimeOut=1) and \
 
482
                count < 10:
 
483
            try:
 
484
                question_dialog = ooldtp.context(self.QUESTION_DLG)
 
485
            except:
 
486
                count += 1
 
487
            else:
 
488
                break
 
489
 
 
490
        # If the text has changed, the save dialog will appear
 
491
        if question_dialog:
 
492
            # Test if the file needs to be saved
 
493
            if save:
 
494
                try:
 
495
                    question_dlg_btn_save = question_dialog.getchild(self.QUESTION_DLG_BTN_SAVE)
 
496
                    question_dlg_btn_save.click()
 
497
                except ldtp.LdtpExecutionError:
 
498
                    # If the Save button was not found, we will try to find the Save As
 
499
                    try:
 
500
                        question_dlg_btn_save = question_dialog.getchild(self.QUESTION_DLG_BTN_SAVE_AS)
 
501
                        question_dlg_btn_save.click()
 
502
                    except ldtp.LdtpExecutionError:
 
503
                        raise ldtp.LdtpExecutionError, "The save or save as buttons in Gedit question dialog were not found."
 
504
 
 
505
                    try:
 
506
                        ldtp.waittillguiexist(self.SAVE_DLG)
 
507
                        save_dialog = ooldtp.context(self.SAVE_DLG)
 
508
                    except ldtp.LdtpExecutionError:
 
509
                        raise ldtp.LdtpExecutionError, "The Gedit save dialog was not found."
 
510
                    try:
 
511
                        save_dlg_txt_filename = save_dialog.getchild(self.SAVE_DLG_TXT_NAME)
 
512
                    except ldtp.LdtpExecutionError:
 
513
                        raise ldtp.LdtpExecutionError, "The filename txt field in Gedit save dialog was not found."
 
514
                    try:
 
515
                        ldtp.wait(2)
 
516
                        save_dlg_txt_filename.settextvalue(filename)
 
517
                    except ldtp.LdtpExecutionError:
 
518
                        raise ldtp.LdtpExecutionError, "There was an error when writing the text."
 
519
 
 
520
                    try:
 
521
                        save_dlg_btn_save = save_dialog.getchild(self.SAVE_DLG_BTN_SAVE)
 
522
                    except ldtp.LdtpExecutionError:
 
523
                        raise ldtp.LdtpExecutionError, "The save button in Gedit save dialog was not found."
 
524
        
 
525
                    try:
 
526
                        save_dlg_btn_save.click()
 
527
                    except ldtp.LdtpExecutionError:
 
528
                        raise ldtp.LdtpExecutionError, "There was an error when pushing the Save button."
 
529
 
 
530
                    ldtp.waittillguinotexist(self.SAVE_DLG)
 
531
            
 
532
            else:
 
533
                try:
 
534
                    question_dlg_btn_close = question_dialog.getchild(self.QUESTION_DLG_BTN_CLOSE)
 
535
                    question_dlg_btn_close.click()
 
536
                except ldtp.LdtpExecutionError:
 
537
                    raise ldtp.LdtpExecutionError, "It was not possible to click the close button."
 
538
 
 
539
            gedit.waittillguinotexist(guiTimeOut=20)
 
540
 
 
541
class PolicyKit(Application):
 
542
    """
 
543
    PolicyKit class manages the GNOME pop up that ask for password for admin activities.
 
544
    """
 
545
    WINDOW     = "dlg0"
 
546
    TXT_PASS   = "txtPassword"
 
547
    BTN_OK     = "btnOK"
 
548
    BTN_CANCEL = "btnCancel"
 
549
 
 
550
 
 
551
    def __init__(self, password):
 
552
        """
 
553
        UpdateManager class main constructor
 
554
        
 
555
        @type password: string
 
556
        @param password: User's password for administrative tasks.
 
557
 
 
558
        """
 
559
        Application.__init__(self)
 
560
        self.password = password
 
561
    
 
562
    def wait(self):
 
563
        """
 
564
        Wait for the pop up window asking for the password to appear.
 
565
 
 
566
        @return 1, if the gksu window exists, 0 otherwise.
 
567
        """
 
568
        return ldtp.waittillguiexist(self.name)
 
569
        
 
570
    def set_password(self):
 
571
        """
 
572
        It enters the password in the text field and clicks enter. 
 
573
        """
 
574
        
 
575
        ooldtp.context(self.name)
 
576
        
 
577
        try:
 
578
            ldtp.enterstring (self.password)
 
579
            ldtp.enterstring ("<enter>")
 
580
            
 
581
        except ldtp.LdtpExecutionError:
 
582
            raise ldtp.LdtpExecutionError, "The PolicyKit txt field for the password was not found."
 
583
   
 
584
# TODO: Change this to use ooldtp
 
585
#        try:
 
586
#            btnOK = polKit.getchild(self.BTN_OK)
 
587
#        except ldtp.LdtpExecutionError, msg:
 
588
#            raise ldtp.LdtpExecutionError, "The GtkSudo OK button was not found."
 
589
#          
 
590
#        btnOK.click()
 
591
    
 
592
        #This also have problems because of the lack of accesibiliy information
 
593
        #ldtp.waittillguinotexist (self.name)
 
594
        
 
595
    def cancel(self):
 
596
        polKit = ooldtp.context(self.name)
 
597
 
 
598
        try:
 
599
            cancelButton = polKit.getchild(self.BTN_CANCEL)
 
600
        except ldtp.LdtpExecutionError:
 
601
            raise ldtp.LdtpExecutionError, "The PolicyKit cancel button was not found."
 
602
          
 
603
        cancelButton.click()
 
604
        ldtp.waittillguinotexist (self.name)