Updated Slovenian translation
[banshee.git] / tests / test-a11y
blob6b0b0947699625dfcb8f84fb92f9b6ef95ffb372
1 #!/usr/bin/env python
2 import os
3 from time import sleep
5 os.environ['NO_GAIL'] = '1'
6 os.environ['NO_AT_BRIDGE'] = '1'
8 import pyatspi, unittest, gtk
10 class TestBansheeAccessibity(unittest.TestCase):
11 neried = None
12 list_views = None
13 def setUp(self):
14 if not self.__class__.neried:
15 self.neried = [app for app in pyatspi.Registry.getDesktop(0) \
16 if getattr(app, 'name', None) == 'Nereid'][0]
18 if not self.__class__.list_views:
19 self.list_views = pyatspi.findAllDescendants(
20 self.neried, lambda x: getattr(x, 'name', None) == 'ListView')
22 def testAnchestry(self):
23 for list_view in self.list_views:
24 self._parent_check(list_view)
25 for i, cell in enumerate(list_view):
26 self._parent_check(cell)
28 def testSelectionAndTable(self):
29 for list_view in self.list_views:
30 tablei = list_view.queryTable()
31 selectioni = list_view.querySelection()
32 for row in xrange(tablei.nRows):
33 for column in xrange(tablei.nColumns):
34 cell = tablei.getAccessibleAt(row, column)
35 selectioni.selectChild(cell.getIndexInParent())
36 self.assertTrue(
37 cell.getState().contains(pyatspi.STATE_SELECTED),
38 "Cell does not have selected state (%s)" % cell)
39 selectioni.clearSelection()
40 sleep(0.001)
42 def testTableColumnHeaders(self):
43 for list_view in self.list_views:
44 tablei = list_view.queryTable()
45 for column in xrange(tablei.nColumns):
46 col_acc = tablei.getColumnHeader(column)
47 self.assertEqual(
48 col_acc.getRole(), pyatspi.ROLE_TABLE_COLUMN_HEADER,
49 "Column header has wrong role (%s)." % col_acc)
50 self.assertFalse(
51 col_acc.getState().contains(pyatspi.STATE_SELECTABLE),
52 "Column header should not be selectable (%s)." % col_acc)
54 def testCellComponentDesktop(self):
55 self._testCellComponent(pyatspi.DESKTOP_COORDS)
57 def testCellComponentWindow(self):
58 self._testCellComponent(pyatspi.WINDOW_COORDS)
60 def testTableRowColumns(self):
61 for list_view in self.list_views:
62 tablei = list_view.queryTable()
63 for i, cell in enumerate(list_view):
64 if cell.getRole() != pyatspi.ROLE_TABLE_CELL:
65 continue
66 index = cell.getIndexInParent()
67 self.assertEqual(
68 index, i,
69 'Recived index, %d, does not equal %d' % (index, i))
71 row = tablei.getRowAtIndex(i)
72 self.assertEqual(
73 row, (index-tablei.nColumns)/tablei.nColumns,
74 'Row recieved through index, %d, does not equal '
75 'calculated row %d' % \
76 (row, (index-tablei.nColumns)/tablei.nColumns))
78 column = tablei.getColumnAtIndex(i)
79 assert(column == (index-tablei.nColumns)%tablei.nColumns)
80 assert(column < tablei.nColumns)
82 assert(tablei.getIndexAt(row, column) == i)
83 assert(tablei.getAccessibleAt(row, column) == cell)
85 def _testCellComponent(self, coord_type):
86 for list_view in self.list_views:
87 list_view_bb = self._get_extents(list_view, coord_type)
88 list_view_ci = list_view.queryComponent()
89 for cell in list_view:
90 if cell.getState().contains(pyatspi.STATE_SHOWING):
91 cell_bb = self._get_extents(cell, coord_type)
92 self.assertEqual(
93 list_view_bb.intersect(cell_bb), cell_bb,
94 'Cell %s is not completely in rectangle %s.' % \
95 (cell_bb, list_view_bb))
96 assert(list_view_bb.intersect(cell_bb) == cell_bb)
97 for n1, n2 in \
98 [(x,y) for x in range(1,4) for y in range(1,4)]:
99 probe_x = cell_bb.x + (cell_bb.width/4)*n1
100 probe_y = cell_bb.y + (cell_bb.height/4)*n2
101 cell_at_point = list_view_ci.getAccessibleAtPoint(
102 probe_x, probe_y, coord_type)
103 self.assertEqual(
104 cell_at_point, cell,
105 'Cell at point, %s, '
106 'does not equal given cell %s' % \
107 (cell_at_point, cell))
109 def _get_extents(self, acc, coord_type):
110 ci = acc.queryComponent()
111 extents = ci.getExtents(coord_type)
112 return gtk.gdk.Rectangle(extents.x, extents.y,
113 extents.width, extents.height)
115 def _parent_check(self, acc):
116 parent = acc.parent
117 for i, child in enumerate(parent):
118 if child == acc:
119 assert (i == acc.getIndexInParent())
120 return
121 raise AssertionError, "child (%s) not in parent (%s)" % (acc, parent)
124 if __name__ == '__main__':
125 unittest.main()