aboutsummaryrefslogtreecommitdiffstats
path: root/tests/test_procedural.py
blob: 820678a37b15869e1c2b8ac01baaa66e373962ba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
#!/usr/bin/python
"""
Unit tests for the dogtail.procedural API
"""
__author__ = "Zack Cerza <zcerza@redhat.com>"

from dogtail.procedural import focus, keyCombo, deselect, select, click, tree, FocusError, run, config, type
config.logDebugToFile = False
config.logDebugToStdOut = True
import pyatspi
from gtkdemotest import GtkDemoTest, trap_stdout
from nose.tools import nottest


class GtkDemoTest(GtkDemoTest):

    def setUp(self):
        self.pid = run('gtk3-demo')
        self.app = focus.application.node

    # FIXME: Implement doubleclick() in d.procedural and override the other
    # methods of Node.GtkDemoTest


class TestFocusApplication(GtkDemoTest):

    def testFocusingBogusNameWithoutAFatalError(self):
        config.fatalErrors = False
        output = trap_stdout(focus.application, "should not be found")
        self.assertTrue(
            'The requested widget could not be focused: "should not be found" application' in output)

    def testThrowExceptionOnFocusingBogusName(self):
        config.fatalErrors = True
        self.assertRaises(FocusError, focus.application, "should not be found")

    def testFocusingBasic(self):
        "Ensure that focus.application() sets focus.application.node properly"
        focus.application.node = None
        focus.application("gtk3-demo")
        self.assertEquals(focus.application.node, self.app)


class TestFocusWindow(GtkDemoTest):

    def testFocusingBogusNameWithoutAFatalError(self):
        config.fatalErrors = False
        output = trap_stdout(focus.window, "should not be found")
        self.assertEquals(focus.window.node, None)
        self.assertTrue(
            'The requested widget could not be focused: "should not be found" window' in output)

    def testThrowExceptionOnFocusingBogusName(self):
        config.fatalErrors = True
        self.assertRaises(FocusError, focus.window, "should not be found")


class TestFocusDialog(GtkDemoTest):

    def testFocusingBogusNameWithoutAFatalError(self):
        config.fatalErrors = False
        output = trap_stdout(focus.dialog, "should not be found")
        self.assertEquals(focus.dialog.node, None)
        self.assertTrue(
            'The requested widget could not be focused: "should not be found" dialog' in output)

    def testThrowExceptionOnFocusingBogusName(self):
        config.fatalErrors = True
        self.assertRaises(FocusError, focus.dialog, "should not be found")


class TestFocusWidget(GtkDemoTest):

    def testFocusingEmptyName(self):
        self.assertRaises(TypeError, focus.widget)

    def testFocusingBogusNameWithoutAFatalError(self):
        config.fatalErrors = False
        output = trap_stdout(focus.widget, "should not be found")
        self.assertEquals(focus.widget.node, None)
        self.assertTrue(
            'The requested widget could not be focused: child with name="should not be found"' in output)

    def testThrowExceptionOnFocusingBogusName(self):
        config.fatalErrors = True
        self.assertRaises(FocusError, focus.widget, "should not be found")

    def testFocusingBasic(self):
        "Ensure that focus.widget('foo') finds a node with name 'foo'"
        focus.widget("Application window")
        self.assertEquals(focus.widget.name, "Application window")


class TestFocus(GtkDemoTest):

    def testInitialState(self):
        "Ensure that focus.widget, focus.dialog and focus.window are None " + \
            "initially."
        self.assertEquals(focus.widget.node, None)
        self.assertEquals(focus.dialog.node, None)
        self.assertEquals(focus.window.node, None)

    def testFocusingApp(self):
        "Ensure that focus.app() works"
        focus.app.node = None
        focus.app('gtk3-demo')
        self.assertEquals(focus.app.node, self.app)

    def testFocusingAppViaApplication(self):
        "Ensure that focus.application() works"
        focus.app.node = None
        focus.application('gtk3-demo')
        self.assertEquals(focus.app.node, self.app)

    def testFocusGettingBogusAttribute(self):
        self.assertRaises(AttributeError, getattr, focus, 'nosuchtype')

    def testFocusSettingBogusAttribute(self):
        self.assertRaises(
            AttributeError, setattr, focus, 'nosuchtype', 'nothing')

    def testFocusingRoleName(self):
        "Ensure that focus.widget(roleName=...) works."
        focus.widget(roleName='page tab')
        self.assert_(isinstance(focus.widget.node, tree.Node))
        self.assertEquals(focus.widget.node.role, pyatspi.ROLE_PAGE_TAB)

    def testFocusMenu(self):
        self.runDemo('Application window')
        focus.window('Application Window')
        focus.menu('File')
        self.assert_(isinstance(focus.widget.node, tree.Node))
        self.assertEquals(focus.widget.node.role, pyatspi.ROLE_MENU)

    def testFocusMenuItem(self):
        self.runDemo('Application window')
        focus.window('Application Window')
        click.menu('File')
        focus.menuItem('New')
        self.assert_(isinstance(focus.widget.node, tree.Node))
        self.assertEquals(focus.widget.node.role, pyatspi.ROLE_MENU_ITEM)

    def testFocusButton(self):
        self.runDemo('Application window')
        focus.window('Application Window')
        focus.button('Open')
        self.assert_(isinstance(focus.widget.node, tree.Node))
        self.assertEquals(focus.widget.node.role, pyatspi.ROLE_PUSH_BUTTON)

    def testFocusTable(self):
        self.runDemo('Builder')
        focus.window('GtkBuilder demo')
        focus.table('')
        self.assert_(isinstance(focus.widget.node, tree.Node))
        self.assertEquals(focus.widget.node.role, pyatspi.ROLE_TABLE)

    def testFocusTableCell(self):
        self.runDemo('Builder')
        focus.window('GtkBuilder demo')
        focus.tableCell('')
        self.assert_(isinstance(focus.widget.node, tree.Node))
        self.assertEquals(focus.widget.node.role, pyatspi.ROLE_TABLE_CELL)

    def testFocusText(self):
        self.runDemo('Application window')
        focus.window('Application Window')
        focus.text('')
        self.assert_(isinstance(focus.widget.node, tree.Node))
        self.assertEquals(focus.widget.node.role, pyatspi.ROLE_TEXT)


class TestKeyCombo(GtkDemoTest):

    def testKeyCombo(self):
        self.runDemo('Application window')
        focus.window('Application Window')
        keyCombo("<ctrl>a")
        focus.dialog('About GTK+ Code Demos')


class TestActions(GtkDemoTest):

    def testClick(self):
        click('Source')
        self.assertTrue(focus.widget.isSelected)

    def testClickWithRaw(self):
        click('Source', raw=True)
        self.assertTrue(focus.widget.isSelected)

    def testSelect(self):
        select('Source')
        self.assertTrue(focus.widget.isSelected)

    @nottest
    def testDeselect(self):
        type('Icon View')
        click('Icon View')
        type('+')
        self.runDemo('Icon View Basics')
        focus.window('GtkIconView demo')

        focus.widget(roleName='icon')
        select()
        deselect()
        self.assertFalse(focus.widget.isSelected)

    def testTyping(self):
        self.runDemo('Dialog and Message Boxes')
        focus.window('Dialogs')
        focus.widget(roleName='text')
        type("hello world")
        self.assertEquals(focus.widget.node.text, 'hello world')