Debian Codegraph @

tests/unit_tests/test_table_navigator.py

raw
1 # Unit tests for table_navigator.py methods.
2 #
3 # Copyright 2025 Igalia, S.L.
4 # Author: Joanmarie Diggs <[email protected]>
5 #
6 # This library is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU Lesser General Public
8 # License as published by the Free Software Foundation; either
9 # version 2.1 of the License, or (at your option) any later version.
10 #
11 # This library is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # Lesser General Public License for more details.
15 #
16 # You should have received a copy of the GNU Lesser General Public
17 # License along with this library; if not, write to the
18 # Free Software Foundation, Inc., Franklin Street, Fifth Floor,
19 # Boston MA 02110-1301 USA.
20
21 # pylint: disable=wrong-import-position
22 # pylint: disable=import-outside-toplevel
23 # pylint: disable=too-many-public-methods
24 # pylint: disable=too-many-statements
25 # pylint: disable=protected-access
26 # pylint: disable=too-many-arguments
27 # pylint: disable=too-many-positional-arguments
28 # pylint: disable=too-many-locals
29 # pylint: disable=too-many-lines
30
31 """Unit tests for table_navigator.py methods."""
32
33 from __future__ import annotations
34
35 from typing import TYPE_CHECKING
36
37 import gi
38 import pytest
39
40 gi.require_version("Atspi", "2.0")
41 from gi.repository import Atspi
42
43 if TYPE_CHECKING:
44 from unittest.mock import MagicMock
45
46 from .orca_test_context import OrcaTestContext
47
48
49 @pytest.mark.unit
50 class TestTableNavigator:
51 """Test TableNavigator class methods."""
52
53 def _setup_dependencies(self, test_context: OrcaTestContext) -> dict[str, MagicMock]:
54 """Set up dependencies for table_navigator module testing."""
55
56 additional_modules = [
57 "orca.command_manager",
58 "orca.guilabels",
59 "orca.input_event_manager",
60 "orca.cmdnames",
61 "orca.messages",
62 "orca.object_properties",
63 "orca.orca_gui_navlist",
64 "orca.orca_i18n",
65 "orca.AXHypertext",
66 "orca.AXObject",
67 "orca.AXTable",
68 "orca.AXText",
69 "orca.AXUtilities",
70 "orca.input_event",
71 "orca.braille_presenter",
72 "orca.presentation_manager",
73 ]
74 essential_modules = test_context.setup_shared_dependencies(additional_modules)
75
76 # Set up cmdnames with all required values for structural_navigator
77 cmdnames = essential_modules["orca.cmdnames"]
78 cmdnames.STRUCTURAL_NAVIGATION_MODE_CYCLE = "cycle_mode"
79 cmdnames.BLOCKQUOTE_PREV = "previous_blockquote"
80 cmdnames.BLOCKQUOTE_NEXT = "next_blockquote"
81 cmdnames.BLOCKQUOTE_LIST = "list_blockquotes"
82 cmdnames.BUTTON_PREV = "previous_button"
83 cmdnames.BUTTON_NEXT = "next_button"
84 cmdnames.BUTTON_LIST = "list_buttons"
85 cmdnames.CHECK_BOX_PREV = "previous_checkbox"
86 cmdnames.CHECK_BOX_NEXT = "next_checkbox"
87 cmdnames.CHECK_BOX_LIST = "list_checkboxes"
88 cmdnames.COMBO_BOX_PREV = "previous_combobox"
89 cmdnames.COMBO_BOX_NEXT = "next_combobox"
90 cmdnames.COMBO_BOX_LIST = "list_comboboxes"
91 cmdnames.ENTRY_PREV = "previous_entry"
92 cmdnames.ENTRY_NEXT = "next_entry"
93 cmdnames.ENTRY_LIST = "list_entries"
94 cmdnames.FORM_FIELD_PREV = "previous_form_field"
95 cmdnames.FORM_FIELD_NEXT = "next_form_field"
96 cmdnames.FORM_FIELD_LIST = "list_form_fields"
97 cmdnames.HEADING_PREV = "previous_heading"
98 cmdnames.HEADING_NEXT = "next_heading"
99 cmdnames.HEADING_LIST = "list_headings"
100 cmdnames.HEADING_AT_LEVEL_PREV = "previous_heading_level_%d"
101 cmdnames.HEADING_AT_LEVEL_NEXT = "next_heading_level_%d"
102 cmdnames.HEADING_AT_LEVEL_LIST = "list_headings_level_%d"
103 cmdnames.IFRAME_PREV = "previous_iframe"
104 cmdnames.IFRAME_NEXT = "next_iframe"
105 cmdnames.IFRAME_LIST = "list_iframes"
106 cmdnames.IMAGE_PREV = "previous_image"
107 cmdnames.IMAGE_NEXT = "next_image"
108 cmdnames.IMAGE_LIST = "list_images"
109 cmdnames.LANDMARK_PREV = "previous_landmark"
110 cmdnames.LANDMARK_NEXT = "next_landmark"
111 cmdnames.LANDMARK_LIST = "list_landmarks"
112 cmdnames.LIST_PREV = "previous_list"
113 cmdnames.LIST_NEXT = "next_list"
114 cmdnames.LIST_LIST = "list_lists"
115 cmdnames.LIST_ITEM_PREV = "previous_list_item"
116 cmdnames.LIST_ITEM_NEXT = "next_list_item"
117 cmdnames.LIST_ITEM_LIST = "list_list_items"
118 cmdnames.LIVE_REGION_PREV = "previous_live_region"
119 cmdnames.LIVE_REGION_NEXT = "next_live_region"
120 cmdnames.LIVE_REGION_LAST = "last_live_region"
121 cmdnames.PARAGRAPH_PREV = "previous_paragraph"
122 cmdnames.PARAGRAPH_NEXT = "next_paragraph"
123 cmdnames.PARAGRAPH_LIST = "list_paragraphs"
124 cmdnames.RADIO_BUTTON_PREV = "previous_radio_button"
125 cmdnames.RADIO_BUTTON_NEXT = "next_radio_button"
126 cmdnames.RADIO_BUTTON_LIST = "list_radio_buttons"
127 cmdnames.SEPARATOR_PREV = "previous_separator"
128 cmdnames.SEPARATOR_NEXT = "next_separator"
129 cmdnames.TABLE_PREV = "previous_table"
130 cmdnames.TABLE_NEXT = "next_table"
131 cmdnames.TABLE_LIST = "list_tables"
132 cmdnames.UNVISITED_LINK_PREV = "previous_unvisited_link"
133 cmdnames.UNVISITED_LINK_NEXT = "next_unvisited_link"
134 cmdnames.UNVISITED_LINK_LIST = "list_unvisited_links"
135 cmdnames.VISITED_LINK_PREV = "previous_visited_link"
136 cmdnames.VISITED_LINK_NEXT = "next_visited_link"
137 cmdnames.VISITED_LINK_LIST = "list_visited_links"
138 cmdnames.LINK_PREV = "previous_link"
139 cmdnames.LINK_NEXT = "next_link"
140 cmdnames.LINK_LIST = "list_links"
141 cmdnames.CLICKABLE_PREV = "previous_clickable"
142 cmdnames.CLICKABLE_NEXT = "next_clickable"
143 cmdnames.CLICKABLE_LIST = "list_clickables"
144 cmdnames.LARGE_OBJECT_PREV = "previous_large_object"
145 cmdnames.LARGE_OBJECT_NEXT = "next_large_object"
146 cmdnames.LARGE_OBJECT_LIST = "list_large_objects"
147 cmdnames.CONTAINER_START = "container_start"
148 cmdnames.CONTAINER_END = "container_end"
149
150 essential_modules["orca.orca_i18n"]._ = lambda x: x
151 essential_modules["orca.debug"].print_message = test_context.Mock()
152 essential_modules["orca.debug"].LEVEL_INFO = 800
153
154 controller_mock = test_context.Mock()
155 controller_mock.register_decorated_module.return_value = None
156 essential_modules["orca.dbus_service"].get_remote_controller.return_value = controller_mock
157
158 focus_manager_instance = test_context.Mock()
159 focus_manager_instance.get_locus_of_focus.return_value = None
160 essential_modules["orca.focus_manager"].get_manager.return_value = focus_manager_instance
161
162 essential_modules["orca.AXObject"].supports_collection.return_value = True
163 essential_modules["orca.AXUtilities"].is_heading.return_value = False
164
165 return essential_modules
166
167 def test_init(self, test_context: OrcaTestContext) -> None:
168 """Test TableNavigator.__init__ creates instance with correct default values."""
169
170 essential_modules = self._setup_dependencies(test_context)
171 mock_controller = test_context.Mock()
172 essential_modules["orca.dbus_service"].get_remote_controller.return_value = mock_controller
173 mock_keybindings_class = test_context.Mock()
174 mock_keybindings_instance = test_context.Mock()
175 mock_keybindings_class.return_value = mock_keybindings_instance
176 test_context.patch(
177 "orca.table_navigator.keybindings.KeyBindings",
178 new=mock_keybindings_class,
179 )
180 from orca import command_manager
181 from orca.table_navigator import TableNavigator
182
183 navigator = TableNavigator()
184 assert navigator._previous_reported_row is None
185 assert navigator._previous_reported_col is None
186 assert navigator._last_input_event is None
187 assert navigator.get_is_enabled() is True
188 # D-Bus registration and commands are registered during setup()
189 navigator.set_up_commands()
190 # Verify commands are registered in CommandManager
191 cmd_manager = command_manager.get_manager()
192 assert cmd_manager.get_command("table_navigator_toggle_enabled") is not None
193 assert cmd_manager.get_command("table_cell_down") is not None
194 mock_controller.register_decorated_module.assert_called_with("TableNavigator", navigator)
195
196 def test_is_enabled_default_true(self, test_context: OrcaTestContext) -> None:
197 """Test TableNavigator.is_enabled returns True by default."""
198
199 essential_modules = self._setup_dependencies(test_context)
200 mock_controller = test_context.Mock()
201 essential_modules["orca.dbus_service"].get_remote_controller.return_value = mock_controller
202 mock_keybindings_class = test_context.Mock()
203 mock_keybindings_instance = test_context.Mock()
204 mock_keybindings_class.return_value = mock_keybindings_instance
205 test_context.patch(
206 "orca.table_navigator.keybindings.KeyBindings",
207 new=mock_keybindings_class,
208 )
209 from orca.table_navigator import TableNavigator
210
211 navigator = TableNavigator()
212 assert navigator.get_is_enabled() is True
213
214 def test_is_enabled_after_disable(self, test_context: OrcaTestContext) -> None:
215 """Test TableNavigator.get_is_enabled returns False when disabled."""
216
217 essential_modules = self._setup_dependencies(test_context)
218 mock_controller = test_context.Mock()
219 essential_modules["orca.dbus_service"].get_remote_controller.return_value = mock_controller
220 mock_keybindings_class = test_context.Mock()
221 mock_keybindings_instance = test_context.Mock()
222 mock_keybindings_class.return_value = mock_keybindings_instance
223 test_context.patch(
224 "orca.table_navigator.keybindings.KeyBindings",
225 new=mock_keybindings_class,
226 )
227 from orca import gsettings_registry
228 from orca.table_navigator import TableNavigator
229
230 gsettings_registry.get_registry().set_runtime_value("table-navigation", "enabled", False)
231 navigator = TableNavigator()
232 assert navigator.get_is_enabled() is False
233
234 def test_last_input_event_was_navigation_command_none(
235 self,
236 test_context: OrcaTestContext,
237 ) -> None:
238 """Test last_input_event_was_navigation_command with None event returns False."""
239
240 essential_modules = self._setup_dependencies(test_context)
241 mock_controller = test_context.Mock()
242 essential_modules["orca.dbus_service"].get_remote_controller.return_value = mock_controller
243 mock_keybindings_class = test_context.Mock()
244 mock_keybindings_instance = test_context.Mock()
245 mock_keybindings_class.return_value = mock_keybindings_instance
246 test_context.patch(
247 "orca.table_navigator.keybindings.KeyBindings",
248 new=mock_keybindings_class,
249 )
250 mock_manager = test_context.Mock()
251 essential_modules["orca.input_event_manager"].get_manager.return_value = mock_manager
252 mock_manager.last_event_equals_or_is_release_for_event.return_value = False
253 from orca.table_navigator import TableNavigator
254
255 navigator = TableNavigator()
256 result = navigator.last_input_event_was_navigation_command()
257 assert result is False
258 mock_manager.last_event_equals_or_is_release_for_event.assert_not_called()
259
260 def test_last_input_event_was_navigation_command_with_event(
261 self,
262 test_context: OrcaTestContext,
263 ) -> None:
264 """Test last_input_event_was_navigation_command with event returns True when matching."""
265
266 essential_modules = self._setup_dependencies(test_context)
267 mock_controller = test_context.Mock()
268 essential_modules["orca.dbus_service"].get_remote_controller.return_value = mock_controller
269 mock_keybindings_class = test_context.Mock()
270 mock_keybindings_instance = test_context.Mock()
271 mock_keybindings_class.return_value = mock_keybindings_instance
272 test_context.patch(
273 "orca.table_navigator.keybindings.KeyBindings",
274 new=mock_keybindings_class,
275 )
276 mock_manager = test_context.Mock()
277 essential_modules["orca.input_event_manager"].get_manager.return_value = mock_manager
278 mock_manager.last_event_equals_or_is_release_for_event.return_value = True
279 mock_event = test_context.Mock()
280 mock_event.as_single_line_string.return_value = "test_event"
281 from orca.table_navigator import TableNavigator
282
283 navigator = TableNavigator()
284 navigator._last_input_event = mock_event
285 result = navigator.last_input_event_was_navigation_command()
286 assert result is True
287 mock_manager.last_event_equals_or_is_release_for_event.assert_called_once_with(mock_event)
288
289 @pytest.mark.parametrize(
290 "initial_enabled,expected_enabled,expected_message_attr",
291 [
292 (False, True, "TABLE_NAVIGATION_ENABLED"),
293 (True, False, "TABLE_NAVIGATION_DISABLED"),
294 ],
295 )
296 def test_toggle_enabled(
297 self,
298 test_context: OrcaTestContext,
299 initial_enabled: bool,
300 expected_enabled: bool,
301 expected_message_attr: str,
302 ) -> None:
303 """Test TableNavigator.toggle_enabled toggles state and presents appropriate message."""
304
305 essential_modules = self._setup_dependencies(test_context)
306 mock_controller = test_context.Mock()
307 essential_modules["orca.dbus_service"].get_remote_controller.return_value = mock_controller
308 mock_keybindings_class = test_context.Mock()
309 mock_keybindings_instance = test_context.Mock()
310 mock_keybindings_class.return_value = mock_keybindings_instance
311 test_context.patch(
312 "orca.table_navigator.keybindings.KeyBindings",
313 new=mock_keybindings_class,
314 )
315 mock_cmd_mgr = test_context.Mock()
316 essential_modules["orca.command_manager"].get_manager.return_value = mock_cmd_mgr
317 from orca.table_navigator import TableNavigator
318
319 guilabels_mock = essential_modules["orca.guilabels"]
320 guilabels_mock.KB_GROUP_TABLE_NAVIGATION = "Table navigation"
321
322 navigator = TableNavigator()
323 mock_cmd_mgr.is_group_enabled.return_value = initial_enabled
324 mock_script = test_context.Mock()
325 mock_event = test_context.Mock()
326 pres_manager = essential_modules["orca.presentation_manager"].get_manager()
327 pres_manager.present_message.reset_mock()
328 result = navigator.toggle_enabled(mock_script, mock_event, notify_user=True)
329 assert result is True
330 expected_message = getattr(essential_modules["orca.messages"], expected_message_attr)
331 pres_manager.present_message.assert_called_once_with(expected_message)
332
333 def test_toggle_enabled_no_notify(self, test_context: OrcaTestContext) -> None:
334 """Test TableNavigator.toggle_enabled does not present message when notify_user=False."""
335
336 essential_modules = self._setup_dependencies(test_context)
337 mock_controller = test_context.Mock()
338 essential_modules["orca.dbus_service"].get_remote_controller.return_value = mock_controller
339 mock_keybindings_class = test_context.Mock()
340 mock_keybindings_instance = test_context.Mock()
341 mock_keybindings_class.return_value = mock_keybindings_instance
342 test_context.patch(
343 "orca.table_navigator.keybindings.KeyBindings",
344 new=mock_keybindings_class,
345 )
346 mock_cmd_mgr = test_context.Mock()
347 essential_modules["orca.command_manager"].get_manager.return_value = mock_cmd_mgr
348 from orca.table_navigator import TableNavigator
349
350 guilabels_mock = essential_modules["orca.guilabels"]
351 guilabels_mock.KB_GROUP_TABLE_NAVIGATION = "Table navigation"
352
353 navigator = TableNavigator()
354 mock_cmd_mgr.is_group_enabled.return_value = False
355 mock_script = test_context.Mock()
356 mock_event = test_context.Mock()
357 pres_manager = essential_modules["orca.presentation_manager"].get_manager()
358 pres_manager.present_message.reset_mock()
359 result = navigator.toggle_enabled(mock_script, mock_event, notify_user=False)
360 assert result is True
361 pres_manager.present_message.assert_not_called()
362
363 @pytest.mark.parametrize(
364 "is_focusable, has_name, has_children, is_whitespace, expected_result",
365 [
366 pytest.param(True, False, False, True, False, id="focusable_object"),
367 pytest.param(False, True, False, True, False, id="object_with_name"),
368 pytest.param(False, False, True, True, False, id="object_with_non_blank_children"),
369 pytest.param(False, False, False, False, False, id="object_with_text"),
370 pytest.param(False, False, False, True, True, id="blank_object"),
371 pytest.param(False, False, True, True, True, id="object_with_only_blank_children"),
372 ],
373 )
374 def test_is_blank(
375 self,
376 test_context,
377 is_focusable,
378 has_name,
379 has_children,
380 is_whitespace,
381 expected_result,
382 ) -> None:
383 """Test _is_blank correctly identifies blank objects based on various criteria."""
384
385 essential_modules = self._setup_dependencies(test_context)
386 test_context.patch(
387 "orca.table_navigator.AXUtilities.is_focusable",
388 return_value=is_focusable,
389 )
390 test_context.patch(
391 "orca.table_navigator.AXObject.get_name",
392 return_value="name" if has_name else "",
393 )
394 test_context.patch(
395 "orca.table_navigator.AXObject.get_child_count",
396 return_value=1 if has_children else 0,
397 )
398 test_context.patch(
399 "orca.table_navigator.AXUtilities.is_whitespace_or_empty",
400 return_value=is_whitespace,
401 )
402 if has_children:
403 mock_child = test_context.Mock()
404 test_context.patch(
405 "orca.table_navigator.AXObject.iter_children",
406 return_value=[mock_child],
407 )
408 # For the recursive call on child, configure mock to handle both expected cases
409 if expected_result and not is_focusable and not has_name:
410 # Child should also be blank - override child-specific mocking
411 test_context.patch(
412 "orca.table_navigator.AXUtilities.is_focusable",
413 side_effect=lambda obj: False if obj == mock_child else is_focusable,
414 )
415 test_context.patch(
416 "orca.table_navigator.AXObject.get_name",
417 side_effect=lambda obj: (
418 "" if obj == mock_child else ("name" if has_name else "")
419 ),
420 )
421 test_context.patch(
422 "orca.table_navigator.AXObject.get_child_count",
423 side_effect=lambda obj: 0 if obj == mock_child else (1 if has_children else 0),
424 )
425 test_context.patch(
426 "orca.table_navigator.AXUtilities.is_whitespace_or_empty",
427 side_effect=lambda obj: True if obj == mock_child else is_whitespace,
428 )
429 else:
430 # Child should not be blank - make it focusable to stop recursion
431 test_context.patch(
432 "orca.table_navigator.AXUtilities.is_focusable",
433 side_effect=lambda obj: True if obj == mock_child else is_focusable,
434 )
435 else:
436 test_context.patch("orca.table_navigator.AXObject.iter_children", return_value=[])
437 mock_controller = test_context.Mock()
438 essential_modules["orca.dbus_service"].get_remote_controller.return_value = mock_controller
439 mock_keybindings_class = test_context.Mock()
440 mock_keybindings_instance = test_context.Mock()
441 mock_keybindings_class.return_value = mock_keybindings_instance
442 test_context.patch(
443 "orca.table_navigator.keybindings.KeyBindings",
444 new=mock_keybindings_class,
445 )
446 from orca.table_navigator import TableNavigator
447
448 navigator = TableNavigator()
449 mock_obj = test_context.Mock(spec=Atspi.Accessible)
450 result = navigator._is_blank(mock_obj)
451 assert result == expected_result
452
453 def test_get_current_cell_basic(self, test_context: OrcaTestContext) -> None:
454 """Test TableNavigator._get_current_cell returns focus manager's locus when it is a cell."""
455
456 essential_modules = self._setup_dependencies(test_context)
457 mock_cell = test_context.Mock(spec=Atspi.Accessible)
458 mock_focus_manager = test_context.Mock()
459 mock_focus_manager.get_locus_of_focus.return_value = mock_cell
460 test_context.patch(
461 "orca.table_navigator.focus_manager.get_manager",
462 return_value=mock_focus_manager,
463 )
464 test_context.patch("orca.table_navigator.AXObject.get_parent", return_value=None)
465
466 def mock_is_cell_or_header(obj):
467 return obj == mock_cell
468
469 test_context.patch(
470 "orca.table_navigator.AXUtilities.is_table_cell_or_header",
471 new=mock_is_cell_or_header,
472 )
473 test_context.patch("orca.table_navigator.AXUtilities.find_ancestor", return_value=None)
474 test_context.patch("orca.table_navigator.debug.print_tokens", return_value=None)
475 mock_controller = test_context.Mock()
476 essential_modules["orca.dbus_service"].get_remote_controller.return_value = mock_controller
477 mock_keybindings_class = test_context.Mock()
478 mock_keybindings_instance = test_context.Mock()
479 mock_keybindings_class.return_value = mock_keybindings_instance
480 test_context.patch(
481 "orca.table_navigator.keybindings.KeyBindings",
482 new=mock_keybindings_class,
483 )
484 from orca.table_navigator import TableNavigator
485
486 navigator = TableNavigator()
487 result = navigator._get_current_cell()
488 assert result == mock_cell
489
490 def test_get_current_cell_nested(self, test_context: OrcaTestContext) -> None:
491 """Test TableNavigator._get_current_cell returns parent when it is also a table cell."""
492
493 essential_modules = self._setup_dependencies(test_context)
494 mock_focus_manager = test_context.Mock()
495 essential_modules["orca.focus_manager"].get_manager.return_value = mock_focus_manager
496 mock_inner_cell = test_context.Mock(spec=Atspi.Accessible)
497 mock_parent_cell = test_context.Mock(spec=Atspi.Accessible)
498 mock_focus_manager.get_locus_of_focus.return_value = mock_inner_cell
499 test_context.patch(
500 "orca.table_navigator.AXObject.get_parent",
501 side_effect=lambda obj: mock_parent_cell if obj == mock_inner_cell else None,
502 )
503
504 def mock_is_table_cell(obj):
505 return obj in [mock_inner_cell, mock_parent_cell]
506
507 test_context.patch(
508 "orca.table_navigator.AXUtilities.is_table_cell_or_header",
509 new=mock_is_table_cell,
510 )
511 mock_controller = test_context.Mock()
512 essential_modules["orca.dbus_service"].get_remote_controller.return_value = mock_controller
513 mock_keybindings_class = test_context.Mock()
514 mock_keybindings_instance = test_context.Mock()
515 mock_keybindings_class.return_value = mock_keybindings_instance
516 test_context.patch(
517 "orca.table_navigator.keybindings.KeyBindings",
518 new=mock_keybindings_class,
519 )
520 from orca.table_navigator import TableNavigator
521
522 navigator = TableNavigator()
523 result = navigator._get_current_cell()
524 assert result == mock_parent_cell
525
526 def test_get_cell_coordinates_basic(self, test_context: OrcaTestContext) -> None:
527 """Test TableNavigator._get_cell_coordinates returns coordinates from AXTable."""
528
529 essential_modules = self._setup_dependencies(test_context)
530 test_context.patch(
531 "orca.table_navigator.AXTable.get_cell_coordinates",
532 return_value=(2, 3),
533 )
534 mock_controller = test_context.Mock()
535 essential_modules["orca.dbus_service"].get_remote_controller.return_value = mock_controller
536 mock_keybindings_class = test_context.Mock()
537 mock_keybindings_instance = test_context.Mock()
538 mock_keybindings_class.return_value = mock_keybindings_instance
539 test_context.patch(
540 "orca.table_navigator.keybindings.KeyBindings",
541 new=mock_keybindings_class,
542 )
543 from orca.table_navigator import TableNavigator
544
545 navigator = TableNavigator()
546 mock_cell = test_context.Mock(spec=Atspi.Accessible)
547 result = navigator._get_cell_coordinates(mock_cell)
548 assert result == (2, 3)
549
550 def test_get_cell_coordinates_with_previous(self, test_context: OrcaTestContext) -> None:
551 """Test _get_cell_coordinates returns previous coordinates when cell matches."""
552
553 essential_modules = self._setup_dependencies(test_context)
554 mock_cell = test_context.Mock(spec=Atspi.Accessible)
555 mock_table = test_context.Mock(spec=Atspi.Accessible)
556 test_context.patch(
557 "orca.table_navigator.AXTable.get_cell_coordinates",
558 return_value=(2, 3),
559 )
560 test_context.patch("orca.table_navigator.AXUtilities.get_table", return_value=mock_table)
561 test_context.patch("orca.table_navigator.AXTable.get_cell_at", return_value=mock_cell)
562 mock_controller = test_context.Mock()
563 essential_modules["orca.dbus_service"].get_remote_controller.return_value = mock_controller
564 mock_keybindings_class = test_context.Mock()
565 mock_keybindings_instance = test_context.Mock()
566 mock_keybindings_class.return_value = mock_keybindings_instance
567 test_context.patch(
568 "orca.table_navigator.keybindings.KeyBindings",
569 new=mock_keybindings_class,
570 )
571 from orca.table_navigator import TableNavigator
572
573 navigator = TableNavigator()
574 navigator._previous_reported_row = 1
575 navigator._previous_reported_col = 2
576 result = navigator._get_cell_coordinates(mock_cell)
577 assert result == (1, 2)
578
579 @pytest.mark.parametrize(
580 "direction, boundary_check, boundary_message, get_next_cell_method",
581 [
582 pytest.param(
583 "left",
584 "is_start_of_row",
585 "TABLE_ROW_BEGINNING",
586 "get_cell_on_left",
587 id="move_left",
588 ),
589 pytest.param(
590 "right",
591 "is_end_of_row",
592 "TABLE_ROW_END",
593 "get_cell_on_right",
594 id="move_right",
595 ),
596 pytest.param(
597 "up",
598 "is_top_of_column",
599 "TABLE_COLUMN_TOP",
600 "get_cell_above",
601 id="move_up",
602 ),
603 pytest.param(
604 "down",
605 "is_bottom_of_column",
606 "TABLE_COLUMN_BOTTOM",
607 "get_cell_below",
608 id="move_down",
609 ),
610 ],
611 )
612 def test_move_direction_scenarios(
613 self,
614 test_context: OrcaTestContext,
615 direction: str,
616 boundary_check: str,
617 boundary_message: str,
618 get_next_cell_method: str,
619 ) -> None:
620 """Test TableNavigator move methods for various scenarios."""
621
622 essential_modules = self._setup_dependencies(test_context)
623 mock_controller = test_context.Mock()
624 essential_modules["orca.dbus_service"].get_remote_controller.return_value = mock_controller
625 mock_keybindings_class = test_context.Mock()
626 mock_keybindings_instance = test_context.Mock()
627 mock_keybindings_class.return_value = mock_keybindings_instance
628 test_context.patch(
629 "orca.table_navigator.keybindings.KeyBindings",
630 new=mock_keybindings_class,
631 )
632 from orca.table_navigator import TableNavigator
633
634 navigator = TableNavigator()
635 mock_script = test_context.Mock()
636 mock_event = test_context.Mock()
637 move_method = getattr(navigator, f"move_{direction}")
638 pres_manager = essential_modules["orca.presentation_manager"].get_manager()
639
640 navigator._get_current_cell = test_context.Mock(return_value=None)
641 pres_manager.present_message.reset_mock()
642 result = move_method(mock_script, mock_event)
643 assert result is True
644 pres_manager.present_message.assert_called_with(
645 essential_modules["orca.messages"].TABLE_NOT_IN_A,
646 )
647 assert navigator._last_input_event == mock_event
648
649 mock_cell = test_context.Mock(spec=Atspi.Accessible)
650 test_context.patch(f"orca.table_navigator.AXTable.{boundary_check}", return_value=True)
651 navigator._get_current_cell = test_context.Mock(return_value=mock_cell)
652 pres_manager.present_message.reset_mock()
653 result = move_method(mock_script, mock_event)
654 assert result is True
655 pres_manager.present_message.assert_called_with(
656 getattr(essential_modules["orca.messages"], boundary_message),
657 )
658
659 mock_current_cell = test_context.Mock(spec=Atspi.Accessible)
660 mock_next_cell = test_context.Mock(spec=Atspi.Accessible)
661 test_context.patch(f"orca.table_navigator.AXTable.{boundary_check}", return_value=False)
662 test_context.patch(
663 f"orca.table_navigator.AXTable.{get_next_cell_method}",
664 return_value=mock_next_cell,
665 )
666 navigator._get_current_cell = test_context.Mock(return_value=mock_current_cell)
667 navigator._get_cell_coordinates = test_context.Mock(return_value=(1, 2))
668 mock_present_cell = test_context.Mock()
669 navigator._present_cell = mock_present_cell
670 mock_script.reset_mock()
671 result = move_method(mock_script, mock_event)
672 assert result is True
673 mock_present_cell.assert_called_once()
674 call_args = mock_present_cell.call_args[0]
675 assert call_args[0] == mock_script
676 assert call_args[1] == mock_next_cell
677 assert call_args[4] == mock_current_cell
678 assert call_args[5] is True
679
680 def test_move_left_successful(self, test_context: OrcaTestContext) -> None:
681 """Test TableNavigator.move_left successfully moves to left cell and presents it."""
682
683 essential_modules = self._setup_dependencies(test_context)
684 mock_controller = test_context.Mock()
685 essential_modules["orca.dbus_service"].get_remote_controller.return_value = mock_controller
686 mock_keybindings_class = test_context.Mock()
687 mock_keybindings_instance = test_context.Mock()
688 mock_keybindings_class.return_value = mock_keybindings_instance
689 test_context.patch(
690 "orca.table_navigator.keybindings.KeyBindings",
691 new=mock_keybindings_class,
692 )
693 mock_current_cell = test_context.Mock(spec=Atspi.Accessible)
694 mock_left_cell = test_context.Mock(spec=Atspi.Accessible)
695 test_context.patch("orca.table_navigator.AXTable.is_start_of_row", return_value=False)
696 test_context.patch(
697 "orca.table_navigator.AXTable.get_cell_on_left",
698 return_value=mock_left_cell,
699 )
700 from orca.table_navigator import TableNavigator
701
702 navigator = TableNavigator()
703 navigator._get_current_cell = test_context.Mock(return_value=mock_current_cell)
704 navigator._get_cell_coordinates = test_context.Mock(return_value=(1, 2))
705 mock_present_cell = test_context.Mock()
706 navigator._present_cell = mock_present_cell
707 mock_script = test_context.Mock()
708 mock_event = test_context.Mock()
709 result = navigator.move_left(mock_script, mock_event)
710 assert result is True
711 mock_present_cell.assert_called_once_with(
712 mock_script,
713 mock_left_cell,
714 1,
715 1,
716 mock_current_cell,
717 True,
718 )
719
720 def test_move_right_successful(self, test_context: OrcaTestContext) -> None:
721 """Test TableNavigator.move_right successfully moves to right cell and presents it."""
722
723 essential_modules = self._setup_dependencies(test_context)
724 mock_controller = test_context.Mock()
725 essential_modules["orca.dbus_service"].get_remote_controller.return_value = mock_controller
726 mock_keybindings_class = test_context.Mock()
727 mock_keybindings_instance = test_context.Mock()
728 mock_keybindings_class.return_value = mock_keybindings_instance
729 test_context.patch(
730 "orca.table_navigator.keybindings.KeyBindings",
731 new=mock_keybindings_class,
732 )
733 mock_current_cell = test_context.Mock(spec=Atspi.Accessible)
734 mock_right_cell = test_context.Mock(spec=Atspi.Accessible)
735 test_context.patch("orca.table_navigator.AXTable.is_end_of_row", return_value=False)
736 test_context.patch(
737 "orca.table_navigator.AXTable.get_cell_on_right",
738 return_value=mock_right_cell,
739 )
740 from orca.table_navigator import TableNavigator
741
742 navigator = TableNavigator()
743 navigator._get_current_cell = test_context.Mock(return_value=mock_current_cell)
744 navigator._get_cell_coordinates = test_context.Mock(return_value=(1, 2))
745 mock_present_cell = test_context.Mock()
746 navigator._present_cell = mock_present_cell
747 mock_script = test_context.Mock()
748 mock_event = test_context.Mock()
749 result = navigator.move_right(mock_script, mock_event)
750 assert result is True
751 mock_present_cell.assert_called_once_with(
752 mock_script,
753 mock_right_cell,
754 1,
755 3,
756 mock_current_cell,
757 True,
758 )
759
760 def test_move_up_not_in_table(self, test_context: OrcaTestContext) -> None:
761 """Test TableNavigator.move_up presents not in table message when current cell is None."""
762
763 essential_modules = self._setup_dependencies(test_context)
764 mock_controller = test_context.Mock()
765 essential_modules["orca.dbus_service"].get_remote_controller.return_value = mock_controller
766 mock_keybindings_class = test_context.Mock()
767 mock_keybindings_instance = test_context.Mock()
768 mock_keybindings_class.return_value = mock_keybindings_instance
769 test_context.patch(
770 "orca.table_navigator.keybindings.KeyBindings",
771 new=mock_keybindings_class,
772 )
773 from orca.table_navigator import TableNavigator
774
775 navigator = TableNavigator()
776 navigator._get_current_cell = test_context.Mock(return_value=None)
777 mock_script = test_context.Mock()
778 mock_event = test_context.Mock()
779 pres_manager = essential_modules["orca.presentation_manager"].get_manager()
780 pres_manager.present_message.reset_mock()
781 result = navigator.move_up(mock_script, mock_event)
782 assert result is True
783 pres_manager.present_message.assert_called_once_with(
784 essential_modules["orca.messages"].TABLE_NOT_IN_A,
785 )
786 assert navigator._last_input_event == mock_event
787
788 def test_move_up_at_top_of_column(self, test_context: OrcaTestContext) -> None:
789 """Test TableNavigator.move_up presents column top message when at top of column."""
790
791 essential_modules = self._setup_dependencies(test_context)
792 mock_controller = test_context.Mock()
793 essential_modules["orca.dbus_service"].get_remote_controller.return_value = mock_controller
794 mock_keybindings_class = test_context.Mock()
795 mock_keybindings_instance = test_context.Mock()
796 mock_keybindings_class.return_value = mock_keybindings_instance
797 test_context.patch(
798 "orca.table_navigator.keybindings.KeyBindings",
799 new=mock_keybindings_class,
800 )
801 mock_cell = test_context.Mock(spec=Atspi.Accessible)
802 test_context.patch("orca.table_navigator.AXTable.is_top_of_column", return_value=True)
803 from orca.table_navigator import TableNavigator
804
805 navigator = TableNavigator()
806 navigator._get_current_cell = test_context.Mock(return_value=mock_cell)
807 mock_script = test_context.Mock()
808 mock_event = test_context.Mock()
809 pres_manager = essential_modules["orca.presentation_manager"].get_manager()
810 pres_manager.present_message.reset_mock()
811 result = navigator.move_up(mock_script, mock_event)
812 assert result is True
813 pres_manager.present_message.assert_called_once_with(
814 essential_modules["orca.messages"].TABLE_COLUMN_TOP,
815 )
816
817 def test_move_up_successful(self, test_context: OrcaTestContext) -> None:
818 """Test TableNavigator.move_up successfully moves to cell above and presents it."""
819
820 essential_modules = self._setup_dependencies(test_context)
821 mock_controller = test_context.Mock()
822 essential_modules["orca.dbus_service"].get_remote_controller.return_value = mock_controller
823 mock_keybindings_class = test_context.Mock()
824 mock_keybindings_instance = test_context.Mock()
825 mock_keybindings_class.return_value = mock_keybindings_instance
826 test_context.patch(
827 "orca.table_navigator.keybindings.KeyBindings",
828 new=mock_keybindings_class,
829 )
830 mock_current_cell = test_context.Mock(spec=Atspi.Accessible)
831 mock_up_cell = test_context.Mock(spec=Atspi.Accessible)
832 test_context.patch("orca.table_navigator.AXTable.is_top_of_column", return_value=False)
833 test_context.patch(
834 "orca.table_navigator.AXTable.get_cell_above",
835 return_value=mock_up_cell,
836 )
837 from orca.table_navigator import TableNavigator
838
839 navigator = TableNavigator()
840 navigator._get_current_cell = test_context.Mock(return_value=mock_current_cell)
841 navigator._get_cell_coordinates = test_context.Mock(return_value=(2, 1))
842 mock_present_cell = test_context.Mock()
843 navigator._present_cell = mock_present_cell
844 mock_script = test_context.Mock()
845 mock_event = test_context.Mock()
846 result = navigator.move_up(mock_script, mock_event)
847 assert result is True
848 mock_present_cell.assert_called_once_with(
849 mock_script,
850 mock_up_cell,
851 1,
852 1,
853 mock_current_cell,
854 True,
855 )
856
857 def test_move_down_successful(self, test_context: OrcaTestContext) -> None:
858 """Test TableNavigator.move_down successfully moves to cell below and presents it."""
859
860 essential_modules = self._setup_dependencies(test_context)
861 mock_controller = test_context.Mock()
862 essential_modules["orca.dbus_service"].get_remote_controller.return_value = mock_controller
863 mock_keybindings_class = test_context.Mock()
864 mock_keybindings_instance = test_context.Mock()
865 mock_keybindings_class.return_value = mock_keybindings_instance
866 test_context.patch(
867 "orca.table_navigator.keybindings.KeyBindings",
868 new=mock_keybindings_class,
869 )
870 mock_current_cell = test_context.Mock(spec=Atspi.Accessible)
871 mock_down_cell = test_context.Mock(spec=Atspi.Accessible)
872 test_context.patch(
873 "orca.table_navigator.AXTable.is_bottom_of_column",
874 return_value=False,
875 )
876 test_context.patch(
877 "orca.table_navigator.AXTable.get_cell_below",
878 return_value=mock_down_cell,
879 )
880 from orca.table_navigator import TableNavigator
881
882 navigator = TableNavigator()
883 navigator._get_current_cell = test_context.Mock(return_value=mock_current_cell)
884 navigator._get_cell_coordinates = test_context.Mock(return_value=(1, 1))
885 mock_present_cell = test_context.Mock()
886 navigator._present_cell = mock_present_cell
887 mock_script = test_context.Mock()
888 mock_event = test_context.Mock()
889 result = navigator.move_down(mock_script, mock_event)
890 assert result is True
891 mock_present_cell.assert_called_once_with(
892 mock_script,
893 mock_down_cell,
894 2,
895 1,
896 mock_current_cell,
897 True,
898 )
899
900 def test_move_to_first_cell_not_in_table(self, test_context: OrcaTestContext) -> None:
901 """Test move_to_first_cell presents not in table message when current cell is None."""
902
903 essential_modules = self._setup_dependencies(test_context)
904 mock_controller = test_context.Mock()
905 essential_modules["orca.dbus_service"].get_remote_controller.return_value = mock_controller
906 mock_keybindings_class = test_context.Mock()
907 mock_keybindings_instance = test_context.Mock()
908 mock_keybindings_class.return_value = mock_keybindings_instance
909 test_context.patch(
910 "orca.table_navigator.keybindings.KeyBindings",
911 new=mock_keybindings_class,
912 )
913 from orca.table_navigator import TableNavigator
914
915 navigator = TableNavigator()
916 navigator._get_current_cell = test_context.Mock(return_value=None)
917 mock_script = test_context.Mock()
918 mock_event = test_context.Mock()
919 pres_manager = essential_modules["orca.presentation_manager"].get_manager()
920 pres_manager.present_message.reset_mock()
921 result = navigator.move_to_first_cell(mock_script, mock_event)
922 assert result is True
923 pres_manager.present_message.assert_called_once_with(
924 essential_modules["orca.messages"].TABLE_NOT_IN_A,
925 )
926
927 def test_move_to_first_cell_successful(self, test_context: OrcaTestContext) -> None:
928 """Test move_to_first_cell successfully moves to first cell and presents it."""
929
930 essential_modules = self._setup_dependencies(test_context)
931 mock_controller = test_context.Mock()
932 essential_modules["orca.dbus_service"].get_remote_controller.return_value = mock_controller
933 mock_keybindings_class = test_context.Mock()
934 mock_keybindings_instance = test_context.Mock()
935 mock_keybindings_class.return_value = mock_keybindings_instance
936 test_context.patch(
937 "orca.table_navigator.keybindings.KeyBindings",
938 new=mock_keybindings_class,
939 )
940 mock_current_cell = test_context.Mock(spec=Atspi.Accessible)
941 mock_table = test_context.Mock(spec=Atspi.Accessible)
942 mock_first_cell = test_context.Mock(spec=Atspi.Accessible)
943 test_context.patch("orca.table_navigator.AXUtilities.get_table", return_value=mock_table)
944 test_context.patch(
945 "orca.table_navigator.AXTable.get_first_cell",
946 return_value=mock_first_cell,
947 )
948 from orca.table_navigator import TableNavigator
949
950 navigator = TableNavigator()
951 navigator._get_current_cell = test_context.Mock(return_value=mock_current_cell)
952 mock_present_cell = test_context.Mock()
953 navigator._present_cell = mock_present_cell
954 mock_script = test_context.Mock()
955 mock_event = test_context.Mock()
956 result = navigator.move_to_first_cell(mock_script, mock_event)
957 assert result is True
958 mock_present_cell.assert_called_once_with(
959 mock_script,
960 mock_first_cell,
961 0,
962 0,
963 mock_current_cell,
964 True,
965 )
966
967 def test_present_cell_not_cell_or_header(self, test_context: OrcaTestContext) -> None:
968 """Test TableNavigator._present_cell returns early when object is not a cell or header."""
969
970 essential_modules = self._setup_dependencies(test_context)
971 test_context.patch(
972 "orca.table_navigator.AXUtilities.is_table_cell_or_header",
973 return_value=False,
974 )
975 mock_controller = test_context.Mock()
976 essential_modules["orca.dbus_service"].get_remote_controller.return_value = mock_controller
977 mock_keybindings_class = test_context.Mock()
978 mock_keybindings_instance = test_context.Mock()
979 mock_keybindings_class.return_value = mock_keybindings_instance
980 test_context.patch(
981 "orca.table_navigator.keybindings.KeyBindings",
982 new=mock_keybindings_class,
983 )
984 from orca.table_navigator import TableNavigator
985
986 navigator = TableNavigator()
987 mock_script = test_context.Mock()
988 mock_cell = test_context.Mock(spec=Atspi.Accessible)
989 mock_previous_cell = test_context.Mock(spec=Atspi.Accessible)
990 navigator._present_cell(mock_script, mock_cell, 1, 2, mock_previous_cell)
991 assert navigator._previous_reported_row != 1
992 assert navigator._previous_reported_col != 2
993
994 def test_present_cell_successful(self, test_context: OrcaTestContext) -> None:
995 """Test TableNavigator._present_cell sets focus, coordinates, and presents cell."""
996
997 essential_modules = self._setup_dependencies(test_context)
998 test_context.patch(
999 "orca.table_navigator.AXUtilities.is_table_cell_or_header",
1000 return_value=True,
1001 )
1002 test_context.patch("orca.table_navigator.AXObject.grab_focus", return_value=None)
1003 test_context.patch(
1004 "orca.table_navigator.AXUtilities.get_descendant_supporting_text", return_value=None
1005 )
1006 test_context.patch("orca.table_navigator.AXObject.supports_text", return_value=False)
1007 test_context.patch("orca.table_navigator.AXTable.get_cell_spans", return_value=(1, 1))
1008 mock_focus_manager = test_context.Mock()
1009 essential_modules["orca.focus_manager"].get_manager.return_value = mock_focus_manager
1010 mock_controller = test_context.Mock()
1011 essential_modules["orca.dbus_service"].get_remote_controller.return_value = mock_controller
1012 mock_keybindings_class = test_context.Mock()
1013 mock_keybindings_instance = test_context.Mock()
1014 mock_keybindings_class.return_value = mock_keybindings_instance
1015 test_context.patch(
1016 "orca.table_navigator.keybindings.KeyBindings",
1017 new=mock_keybindings_class,
1018 )
1019
1020 from orca import gsettings_registry
1021 from orca.table_navigator import TableNavigator
1022
1023 registry = gsettings_registry.get_registry()
1024 registry.set_runtime_value("speech", "announce-cell-coordinates", False)
1025 registry.set_runtime_value("speech", "announce-cell-span", False)
1026
1027 navigator = TableNavigator()
1028 mock_script = test_context.Mock()
1029 mock_script.utilities.grab_focus_when_setting_caret.return_value = False
1030 test_context.patch("orca.table_navigator.AXUtilities.is_gui_cell", return_value=False)
1031 mock_script.present_object = test_context.Mock()
1032 mock_cell = test_context.Mock(spec=Atspi.Accessible)
1033 mock_previous_cell = test_context.Mock(spec=Atspi.Accessible)
1034 navigator._present_cell(mock_script, mock_cell, 1, 2, mock_previous_cell)
1035 assert navigator._previous_reported_row == 1
1036 assert navigator._previous_reported_col == 2
1037 mock_focus_manager.set_locus_of_focus.assert_called()
1038 mock_script.present_object.assert_called_once_with(
1039 mock_cell,
1040 offset=0,
1041 priorObj=mock_previous_cell,
1042 interrupt=True,
1043 )
1044
1045 def test_get_navigator(self, test_context: OrcaTestContext) -> None:
1046 """Test table_navigator.get_navigator returns singleton TableNavigator instance."""
1047
1048 essential_modules = self._setup_dependencies(test_context)
1049 mock_controller = test_context.Mock()
1050 essential_modules["orca.dbus_service"].get_remote_controller.return_value = mock_controller
1051 mock_keybindings_class = test_context.Mock()
1052 mock_keybindings_instance = test_context.Mock()
1053 mock_keybindings_class.return_value = mock_keybindings_instance
1054 test_context.patch(
1055 "orca.table_navigator.keybindings.KeyBindings",
1056 new=mock_keybindings_class,
1057 )
1058 from orca import table_navigator
1059
1060 navigator1 = table_navigator.get_navigator()
1061 navigator2 = table_navigator.get_navigator()
1062 assert navigator1 is navigator2
1063 assert isinstance(navigator1, table_navigator.TableNavigator)
1064
1065 def test_get_current_cell_needs_ancestor_search(self, test_context: OrcaTestContext) -> None:
1066 """Test _get_current_cell when cell is not table cell and needs ancestor search."""
1067
1068 essential_modules = self._setup_dependencies(test_context)
1069 mock_initial_cell = test_context.Mock(spec=Atspi.Accessible)
1070 mock_ancestor_cell = test_context.Mock(spec=Atspi.Accessible)
1071 mock_focus_manager = test_context.Mock()
1072 mock_focus_manager.get_locus_of_focus.return_value = mock_initial_cell
1073 test_context.patch(
1074 "orca.table_navigator.focus_manager.get_manager",
1075 return_value=mock_focus_manager,
1076 )
1077 test_context.patch("orca.table_navigator.AXObject.get_parent", return_value=None)
1078
1079 def mock_is_cell_or_header(obj):
1080 return obj == mock_ancestor_cell
1081
1082 test_context.patch(
1083 "orca.table_navigator.AXUtilities.is_table_cell_or_header",
1084 new=mock_is_cell_or_header,
1085 )
1086 test_context.patch(
1087 "orca.table_navigator.AXUtilities.find_ancestor",
1088 return_value=mock_ancestor_cell,
1089 )
1090 test_context.patch("orca.table_navigator.debug.print_tokens", return_value=None)
1091 mock_controller = test_context.Mock()
1092 essential_modules["orca.dbus_service"].get_remote_controller.return_value = mock_controller
1093 mock_keybindings_class = test_context.Mock()
1094 mock_keybindings_instance = test_context.Mock()
1095 mock_keybindings_class.return_value = mock_keybindings_instance
1096 test_context.patch(
1097 "orca.table_navigator.keybindings.KeyBindings",
1098 new=mock_keybindings_class,
1099 )
1100 from orca.table_navigator import TableNavigator
1101
1102 navigator = TableNavigator()
1103 result = navigator._get_current_cell()
1104 assert result == mock_ancestor_cell
1105
1106 def test_move_left_skip_blank_cells(self, test_context: OrcaTestContext) -> None:
1107 """Test TableNavigator.move_left skipping blank cells when setting is enabled."""
1108
1109 essential_modules = self._setup_dependencies(test_context)
1110
1111 from orca import gsettings_registry
1112
1113 gsettings_registry.get_registry().set_runtime_value(
1114 "table-navigation",
1115 "skip-blank-cells",
1116 True,
1117 )
1118 mock_script = test_context.Mock()
1119 mock_current_cell = test_context.Mock(spec=Atspi.Accessible)
1120 mock_blank_cell = test_context.Mock(spec=Atspi.Accessible)
1121 mock_final_cell = test_context.Mock(spec=Atspi.Accessible)
1122 test_context.patch(
1123 "orca.table_navigator.AXTable.get_cell_coordinates",
1124 return_value=(1, 1),
1125 )
1126 test_context.patch(
1127 "orca.table_navigator.AXTable.is_start_of_row",
1128 side_effect=lambda cell: cell == mock_final_cell,
1129 )
1130 cell_sequence = [mock_blank_cell, mock_final_cell]
1131 call_count = [0]
1132
1133 def mock_get_cell_on_left(_cell):
1134 if call_count[0] < len(cell_sequence):
1135 result = cell_sequence[call_count[0]]
1136 call_count[0] += 1
1137 return result
1138 return None
1139
1140 test_context.patch(
1141 "orca.table_navigator.AXTable.get_cell_on_left",
1142 new=mock_get_cell_on_left,
1143 )
1144
1145 def mock_is_blank(cell):
1146 return cell == mock_blank_cell
1147
1148 test_context.patch("orca.table_navigator.debug.print_tokens", return_value=None)
1149 test_context.patch("orca.table_navigator.TableNavigator._present_cell", return_value=None)
1150 mock_controller = test_context.Mock()
1151 essential_modules["orca.dbus_service"].get_remote_controller.return_value = mock_controller
1152 mock_keybindings_class = test_context.Mock()
1153 mock_keybindings_instance = test_context.Mock()
1154 mock_keybindings_class.return_value = mock_keybindings_instance
1155 test_context.patch(
1156 "orca.table_navigator.keybindings.KeyBindings",
1157 new=mock_keybindings_class,
1158 )
1159 from orca.table_navigator import TableNavigator
1160
1161 navigator = TableNavigator()
1162 navigator._is_blank = mock_is_blank
1163 result = navigator.move_left(mock_script, mock_current_cell)
1164 assert result is True
1165
1166 def test_move_right_at_end_of_row(self, test_context: OrcaTestContext) -> None:
1167 """Test TableNavigator.move_right when at end of row returns True and notifies user."""
1168
1169 essential_modules = self._setup_dependencies(test_context)
1170 mock_script = test_context.Mock()
1171 mock_current_cell = test_context.Mock(spec=Atspi.Accessible)
1172 test_context.patch(
1173 "orca.table_navigator.AXTable.get_cell_coordinates",
1174 return_value=(1, 5),
1175 )
1176 test_context.patch("orca.table_navigator.AXTable.get_cell_on_right", return_value=None)
1177 test_context.patch("orca.table_navigator.AXTable.is_end_of_row", return_value=True)
1178 test_context.patch("orca.table_navigator.debug.print_tokens", return_value=None)
1179 test_context.patch("orca.table_navigator.TableNavigator._present_cell", return_value=None)
1180 mock_focus_manager = test_context.Mock()
1181 mock_focus_manager.get_locus_of_focus.return_value = mock_current_cell
1182 test_context.patch(
1183 "orca.table_navigator.focus_manager.get_manager",
1184 return_value=mock_focus_manager,
1185 )
1186 test_context.patch("orca.table_navigator.AXObject.get_parent", return_value=None)
1187 test_context.patch(
1188 "orca.table_navigator.AXUtilities.is_table_cell_or_header",
1189 return_value=True,
1190 )
1191 test_context.patch("orca.table_navigator.AXUtilities.find_ancestor", return_value=None)
1192 mock_controller = test_context.Mock()
1193 essential_modules["orca.dbus_service"].get_remote_controller.return_value = mock_controller
1194 mock_keybindings_class = test_context.Mock()
1195 mock_keybindings_instance = test_context.Mock()
1196 mock_keybindings_class.return_value = mock_keybindings_instance
1197 test_context.patch(
1198 "orca.table_navigator.keybindings.KeyBindings",
1199 new=mock_keybindings_class,
1200 )
1201 from orca.table_navigator import TableNavigator
1202
1203 navigator = TableNavigator()
1204 pres_manager = essential_modules["orca.presentation_manager"].get_manager()
1205 pres_manager.present_message.reset_mock()
1206 result = navigator.move_right(mock_script)
1207 # move_right returns True even at end of row, but presents a message
1208 assert result is True
1209 pres_manager.present_message.assert_called_once()
1210
1211 def test_move_to_last_cell_not_in_table(self, test_context: OrcaTestContext) -> None:
1212 """Test move_to_last_cell presents not in table message when current cell is None."""
1213
1214 essential_modules = self._setup_dependencies(test_context)
1215 mock_controller = test_context.Mock()
1216 essential_modules["orca.dbus_service"].get_remote_controller.return_value = mock_controller
1217 mock_keybindings_class = test_context.Mock()
1218 mock_keybindings_instance = test_context.Mock()
1219 mock_keybindings_class.return_value = mock_keybindings_instance
1220 test_context.patch(
1221 "orca.table_navigator.keybindings.KeyBindings",
1222 new=mock_keybindings_class,
1223 )
1224 from orca.table_navigator import TableNavigator
1225
1226 navigator = TableNavigator()
1227 navigator._get_current_cell = test_context.Mock(return_value=None)
1228 mock_script = test_context.Mock()
1229 mock_event = test_context.Mock()
1230 pres_manager = essential_modules["orca.presentation_manager"].get_manager()
1231 pres_manager.present_message.reset_mock()
1232 result = navigator.move_to_last_cell(mock_script, mock_event)
1233 assert result is True
1234 pres_manager.present_message.assert_called_once_with(
1235 essential_modules["orca.messages"].TABLE_NOT_IN_A,
1236 )
1237 assert navigator._last_input_event == mock_event
1238
1239 def test_move_to_last_cell_successful(self, test_context: OrcaTestContext) -> None:
1240 """Test TableNavigator.move_to_last_cell successfully moves to last cell and presents it."""
1241
1242 essential_modules = self._setup_dependencies(test_context)
1243 mock_controller = test_context.Mock()
1244 essential_modules["orca.dbus_service"].get_remote_controller.return_value = mock_controller
1245 mock_keybindings_class = test_context.Mock()
1246 mock_keybindings_instance = test_context.Mock()
1247 mock_keybindings_class.return_value = mock_keybindings_instance
1248 test_context.patch(
1249 "orca.table_navigator.keybindings.KeyBindings",
1250 new=mock_keybindings_class,
1251 )
1252 mock_current_cell = test_context.Mock(spec=Atspi.Accessible)
1253 mock_table = test_context.Mock(spec=Atspi.Accessible)
1254 mock_last_cell = test_context.Mock(spec=Atspi.Accessible)
1255 test_context.patch("orca.table_navigator.AXUtilities.get_table", return_value=mock_table)
1256 test_context.patch(
1257 "orca.table_navigator.AXTable.get_last_cell",
1258 return_value=mock_last_cell,
1259 )
1260 test_context.patch("orca.table_navigator.AXTable.get_row_count", return_value=5)
1261 test_context.patch("orca.table_navigator.AXTable.get_column_count", return_value=3)
1262 from orca.table_navigator import TableNavigator
1263
1264 navigator = TableNavigator()
1265 navigator._get_current_cell = test_context.Mock(return_value=mock_current_cell)
1266 mock_present_cell = test_context.Mock()
1267 navigator._present_cell = mock_present_cell
1268 mock_script = test_context.Mock()
1269 mock_event = test_context.Mock()
1270 result = navigator.move_to_last_cell(mock_script, mock_event)
1271 assert result is True
1272 mock_present_cell.assert_called_once_with(
1273 mock_script,
1274 mock_last_cell,
1275 5,
1276 3,
1277 mock_current_cell,
1278 True,
1279 )
1280
1281 def test_move_to_top_of_column_not_in_table(self, test_context: OrcaTestContext) -> None:
1282 """Test move_to_top_of_column presents not in table message when current cell is None."""
1283
1284 essential_modules = self._setup_dependencies(test_context)
1285 mock_controller = test_context.Mock()
1286 essential_modules["orca.dbus_service"].get_remote_controller.return_value = mock_controller
1287 mock_keybindings_class = test_context.Mock()
1288 mock_keybindings_instance = test_context.Mock()
1289 mock_keybindings_class.return_value = mock_keybindings_instance
1290 test_context.patch(
1291 "orca.table_navigator.keybindings.KeyBindings",
1292 new=mock_keybindings_class,
1293 )
1294 from orca.table_navigator import TableNavigator
1295
1296 navigator = TableNavigator()
1297 navigator._get_current_cell = test_context.Mock(return_value=None)
1298 mock_script = test_context.Mock()
1299 mock_event = test_context.Mock()
1300 pres_manager = essential_modules["orca.presentation_manager"].get_manager()
1301 pres_manager.present_message.reset_mock()
1302 result = navigator.move_to_top_of_column(mock_script, mock_event)
1303 assert result is True
1304 pres_manager.present_message.assert_called_once_with(
1305 essential_modules["orca.messages"].TABLE_NOT_IN_A,
1306 )
1307
1308 def test_move_to_top_of_column_already_at_top(self, test_context: OrcaTestContext) -> None:
1309 """Test move_to_top_of_column presents column top message when already at top."""
1310
1311 essential_modules = self._setup_dependencies(test_context)
1312 mock_controller = test_context.Mock()
1313 essential_modules["orca.dbus_service"].get_remote_controller.return_value = mock_controller
1314 mock_keybindings_class = test_context.Mock()
1315 mock_keybindings_instance = test_context.Mock()
1316 mock_keybindings_class.return_value = mock_keybindings_instance
1317 test_context.patch(
1318 "orca.table_navigator.keybindings.KeyBindings",
1319 new=mock_keybindings_class,
1320 )
1321 mock_cell = test_context.Mock(spec=Atspi.Accessible)
1322 test_context.patch("orca.table_navigator.AXTable.is_top_of_column", return_value=True)
1323 from orca.table_navigator import TableNavigator
1324
1325 navigator = TableNavigator()
1326 navigator._get_current_cell = test_context.Mock(return_value=mock_cell)
1327 mock_script = test_context.Mock()
1328 mock_event = test_context.Mock()
1329 pres_manager = essential_modules["orca.presentation_manager"].get_manager()
1330 pres_manager.present_message.reset_mock()
1331 result = navigator.move_to_top_of_column(mock_script, mock_event)
1332 assert result is True
1333 pres_manager.present_message.assert_called_once_with(
1334 essential_modules["orca.messages"].TABLE_COLUMN_TOP,
1335 )
1336
1337 def test_move_to_top_of_column_successful(self, test_context: OrcaTestContext) -> None:
1338 """Test move_to_top_of_column successfully moves to top of column and presents it."""
1339
1340 essential_modules = self._setup_dependencies(test_context)
1341 mock_controller = test_context.Mock()
1342 essential_modules["orca.dbus_service"].get_remote_controller.return_value = mock_controller
1343 mock_keybindings_class = test_context.Mock()
1344 mock_keybindings_instance = test_context.Mock()
1345 mock_keybindings_class.return_value = mock_keybindings_instance
1346 test_context.patch(
1347 "orca.table_navigator.keybindings.KeyBindings",
1348 new=mock_keybindings_class,
1349 )
1350 mock_current_cell = test_context.Mock(spec=Atspi.Accessible)
1351 mock_top_cell = test_context.Mock(spec=Atspi.Accessible)
1352 test_context.patch("orca.table_navigator.AXTable.is_top_of_column", return_value=False)
1353 test_context.patch(
1354 "orca.table_navigator.AXTable.get_top_of_column",
1355 return_value=mock_top_cell,
1356 )
1357
1358 def mock_get_cell_coordinates(cell, prefer_attribute=False): # pylint: disable=unused-argument
1359 if cell == mock_current_cell:
1360 return (3, 1)
1361 if cell == mock_top_cell:
1362 return (0, 1)
1363 return (0, 0)
1364
1365 test_context.patch(
1366 "orca.table_navigator.AXTable.get_cell_coordinates",
1367 new=mock_get_cell_coordinates,
1368 )
1369 from orca.table_navigator import TableNavigator
1370
1371 navigator = TableNavigator()
1372 navigator._get_current_cell = test_context.Mock(return_value=mock_current_cell)
1373 mock_present_cell = test_context.Mock()
1374 navigator._present_cell = mock_present_cell
1375 mock_script = test_context.Mock()
1376 mock_event = test_context.Mock()
1377 result = navigator.move_to_top_of_column(mock_script, mock_event)
1378 assert result is True
1379 mock_present_cell.assert_called_once_with(
1380 mock_script,
1381 mock_top_cell,
1382 3,
1383 1,
1384 mock_current_cell,
1385 True,
1386 )
1387
1388 def test_move_to_bottom_of_column_not_in_table(self, test_context: OrcaTestContext) -> None:
1389 """Test move_to_bottom_of_column presents not in table message when current cell is None."""
1390
1391 essential_modules = self._setup_dependencies(test_context)
1392 mock_controller = test_context.Mock()
1393 essential_modules["orca.dbus_service"].get_remote_controller.return_value = mock_controller
1394 mock_keybindings_class = test_context.Mock()
1395 mock_keybindings_instance = test_context.Mock()
1396 mock_keybindings_class.return_value = mock_keybindings_instance
1397 test_context.patch(
1398 "orca.table_navigator.keybindings.KeyBindings",
1399 new=mock_keybindings_class,
1400 )
1401 from orca.table_navigator import TableNavigator
1402
1403 navigator = TableNavigator()
1404 navigator._get_current_cell = test_context.Mock(return_value=None)
1405 mock_script = test_context.Mock()
1406 mock_event = test_context.Mock()
1407 pres_manager = essential_modules["orca.presentation_manager"].get_manager()
1408 pres_manager.present_message.reset_mock()
1409 result = navigator.move_to_bottom_of_column(mock_script, mock_event)
1410 assert result is True
1411 pres_manager.present_message.assert_called_once_with(
1412 essential_modules["orca.messages"].TABLE_NOT_IN_A,
1413 )
1414
1415 def test_move_to_bottom_of_column_already_at_bottom(
1416 self,
1417 test_context: OrcaTestContext,
1418 ) -> None:
1419 """Test move_to_bottom_of_column presents column bottom message when already at bottom."""
1420
1421 essential_modules = self._setup_dependencies(test_context)
1422 mock_controller = test_context.Mock()
1423 essential_modules["orca.dbus_service"].get_remote_controller.return_value = mock_controller
1424 mock_keybindings_class = test_context.Mock()
1425 mock_keybindings_instance = test_context.Mock()
1426 mock_keybindings_class.return_value = mock_keybindings_instance
1427 test_context.patch(
1428 "orca.table_navigator.keybindings.KeyBindings",
1429 new=mock_keybindings_class,
1430 )
1431 mock_cell = test_context.Mock(spec=Atspi.Accessible)
1432 test_context.patch(
1433 "orca.table_navigator.AXTable.is_bottom_of_column",
1434 return_value=True,
1435 )
1436 from orca.table_navigator import TableNavigator
1437
1438 navigator = TableNavigator()
1439 navigator._get_current_cell = test_context.Mock(return_value=mock_cell)
1440 mock_script = test_context.Mock()
1441 mock_event = test_context.Mock()
1442 pres_manager = essential_modules["orca.presentation_manager"].get_manager()
1443 pres_manager.present_message.reset_mock()
1444 result = navigator.move_to_bottom_of_column(mock_script, mock_event)
1445 assert result is True
1446 pres_manager.present_message.assert_called_once_with(
1447 essential_modules["orca.messages"].TABLE_COLUMN_BOTTOM,
1448 )
1449
1450 def test_move_to_bottom_of_column_successful(self, test_context: OrcaTestContext) -> None:
1451 """Test move_to_bottom_of_column successfully moves to bottom of column and presents it."""
1452
1453 essential_modules = self._setup_dependencies(test_context)
1454 mock_controller = test_context.Mock()
1455 essential_modules["orca.dbus_service"].get_remote_controller.return_value = mock_controller
1456 mock_keybindings_class = test_context.Mock()
1457 mock_keybindings_instance = test_context.Mock()
1458 mock_keybindings_class.return_value = mock_keybindings_instance
1459 test_context.patch(
1460 "orca.table_navigator.keybindings.KeyBindings",
1461 new=mock_keybindings_class,
1462 )
1463 mock_current_cell = test_context.Mock(spec=Atspi.Accessible)
1464 mock_bottom_cell = test_context.Mock(spec=Atspi.Accessible)
1465 test_context.patch(
1466 "orca.table_navigator.AXTable.is_bottom_of_column",
1467 return_value=False,
1468 )
1469 test_context.patch(
1470 "orca.table_navigator.AXTable.get_bottom_of_column",
1471 return_value=mock_bottom_cell,
1472 )
1473
1474 def mock_get_cell_coordinates(cell, prefer_attribute=False): # pylint: disable=unused-argument
1475 if cell == mock_current_cell:
1476 return (1, 2)
1477 if cell == mock_bottom_cell:
1478 return (4, 2)
1479 return (0, 0)
1480
1481 test_context.patch(
1482 "orca.table_navigator.AXTable.get_cell_coordinates",
1483 new=mock_get_cell_coordinates,
1484 )
1485 from orca.table_navigator import TableNavigator
1486
1487 navigator = TableNavigator()
1488 navigator._get_current_cell = test_context.Mock(return_value=mock_current_cell)
1489 mock_present_cell = test_context.Mock()
1490 navigator._present_cell = mock_present_cell
1491 mock_script = test_context.Mock()
1492 mock_event = test_context.Mock()
1493 result = navigator.move_to_bottom_of_column(mock_script, mock_event)
1494 assert result is True
1495 mock_present_cell.assert_called_once_with(
1496 mock_script,
1497 mock_bottom_cell,
1498 1,
1499 2,
1500 mock_current_cell,
1501 True,
1502 )
1503
1504 def test_move_to_beginning_of_row_not_in_table(self, test_context: OrcaTestContext) -> None:
1505 """Test move_to_beginning_of_row presents not in table message when current cell is None."""
1506
1507 essential_modules = self._setup_dependencies(test_context)
1508 mock_controller = test_context.Mock()
1509 essential_modules["orca.dbus_service"].get_remote_controller.return_value = mock_controller
1510 mock_keybindings_class = test_context.Mock()
1511 mock_keybindings_instance = test_context.Mock()
1512 mock_keybindings_class.return_value = mock_keybindings_instance
1513 test_context.patch(
1514 "orca.table_navigator.keybindings.KeyBindings",
1515 new=mock_keybindings_class,
1516 )
1517 from orca.table_navigator import TableNavigator
1518
1519 navigator = TableNavigator()
1520 navigator._get_current_cell = test_context.Mock(return_value=None)
1521 mock_script = test_context.Mock()
1522 mock_event = test_context.Mock()
1523 pres_manager = essential_modules["orca.presentation_manager"].get_manager()
1524 pres_manager.present_message.reset_mock()
1525 result = navigator.move_to_beginning_of_row(mock_script, mock_event)
1526 assert result is True
1527 pres_manager.present_message.assert_called_once_with(
1528 essential_modules["orca.messages"].TABLE_NOT_IN_A,
1529 )
1530
1531 def test_move_to_beginning_of_row_already_at_start(self, test_context: OrcaTestContext) -> None:
1532 """Test move_to_beginning_of_row presents row beginning message when already at start."""
1533
1534 essential_modules = self._setup_dependencies(test_context)
1535 mock_controller = test_context.Mock()
1536 essential_modules["orca.dbus_service"].get_remote_controller.return_value = mock_controller
1537 mock_keybindings_class = test_context.Mock()
1538 mock_keybindings_instance = test_context.Mock()
1539 mock_keybindings_class.return_value = mock_keybindings_instance
1540 test_context.patch(
1541 "orca.table_navigator.keybindings.KeyBindings",
1542 new=mock_keybindings_class,
1543 )
1544 mock_cell = test_context.Mock(spec=Atspi.Accessible)
1545 test_context.patch("orca.table_navigator.AXTable.is_start_of_row", return_value=True)
1546 from orca.table_navigator import TableNavigator
1547
1548 navigator = TableNavigator()
1549 navigator._get_current_cell = test_context.Mock(return_value=mock_cell)
1550 mock_script = test_context.Mock()
1551 mock_event = test_context.Mock()
1552 pres_manager = essential_modules["orca.presentation_manager"].get_manager()
1553 pres_manager.present_message.reset_mock()
1554 result = navigator.move_to_beginning_of_row(mock_script, mock_event)
1555 assert result is True
1556 pres_manager.present_message.assert_called_once_with(
1557 essential_modules["orca.messages"].TABLE_ROW_BEGINNING,
1558 )
1559
1560 def test_move_to_beginning_of_row_successful(self, test_context: OrcaTestContext) -> None:
1561 """Test move_to_beginning_of_row successfully moves to beginning of row and presents it."""
1562
1563 essential_modules = self._setup_dependencies(test_context)
1564 mock_controller = test_context.Mock()
1565 essential_modules["orca.dbus_service"].get_remote_controller.return_value = mock_controller
1566 mock_keybindings_class = test_context.Mock()
1567 mock_keybindings_instance = test_context.Mock()
1568 mock_keybindings_class.return_value = mock_keybindings_instance
1569 test_context.patch(
1570 "orca.table_navigator.keybindings.KeyBindings",
1571 new=mock_keybindings_class,
1572 )
1573 mock_current_cell = test_context.Mock(spec=Atspi.Accessible)
1574 mock_start_cell = test_context.Mock(spec=Atspi.Accessible)
1575 test_context.patch("orca.table_navigator.AXTable.is_start_of_row", return_value=False)
1576 test_context.patch(
1577 "orca.table_navigator.AXTable.get_start_of_row",
1578 return_value=mock_start_cell,
1579 )
1580
1581 def mock_get_cell_coordinates(cell, prefer_attribute=False): # pylint: disable=unused-argument
1582 if cell == mock_start_cell:
1583 return (2, 0)
1584 return (2, 3)
1585
1586 test_context.patch(
1587 "orca.table_navigator.AXTable.get_cell_coordinates",
1588 new=mock_get_cell_coordinates,
1589 )
1590 from orca.table_navigator import TableNavigator
1591
1592 navigator = TableNavigator()
1593 navigator._get_current_cell = test_context.Mock(return_value=mock_current_cell)
1594 mock_present_cell = test_context.Mock()
1595 navigator._present_cell = mock_present_cell
1596 mock_script = test_context.Mock()
1597 mock_event = test_context.Mock()
1598 result = navigator.move_to_beginning_of_row(mock_script, mock_event)
1599 assert result is True
1600 mock_present_cell.assert_called_once_with(
1601 mock_script,
1602 mock_start_cell,
1603 2,
1604 0,
1605 mock_current_cell,
1606 True,
1607 )
1608
1609 def test_move_to_end_of_row_not_in_table(self, test_context: OrcaTestContext) -> None:
1610 """Test move_to_end_of_row presents not in table message when current cell is None."""
1611
1612 essential_modules = self._setup_dependencies(test_context)
1613 mock_controller = test_context.Mock()
1614 essential_modules["orca.dbus_service"].get_remote_controller.return_value = mock_controller
1615 mock_keybindings_class = test_context.Mock()
1616 mock_keybindings_instance = test_context.Mock()
1617 mock_keybindings_class.return_value = mock_keybindings_instance
1618 test_context.patch(
1619 "orca.table_navigator.keybindings.KeyBindings",
1620 new=mock_keybindings_class,
1621 )
1622 from orca.table_navigator import TableNavigator
1623
1624 navigator = TableNavigator()
1625 navigator._get_current_cell = test_context.Mock(return_value=None)
1626 mock_script = test_context.Mock()
1627 mock_event = test_context.Mock()
1628 pres_manager = essential_modules["orca.presentation_manager"].get_manager()
1629 pres_manager.present_message.reset_mock()
1630 result = navigator.move_to_end_of_row(mock_script, mock_event)
1631 assert result is True
1632 pres_manager.present_message.assert_called_once_with(
1633 essential_modules["orca.messages"].TABLE_NOT_IN_A,
1634 )
1635
1636 def test_move_to_end_of_row_already_at_end(self, test_context: OrcaTestContext) -> None:
1637 """Test move_to_end_of_row presents row end message when already at end."""
1638
1639 essential_modules = self._setup_dependencies(test_context)
1640 mock_controller = test_context.Mock()
1641 essential_modules["orca.dbus_service"].get_remote_controller.return_value = mock_controller
1642 mock_keybindings_class = test_context.Mock()
1643 mock_keybindings_instance = test_context.Mock()
1644 mock_keybindings_class.return_value = mock_keybindings_instance
1645 test_context.patch(
1646 "orca.table_navigator.keybindings.KeyBindings",
1647 new=mock_keybindings_class,
1648 )
1649 mock_cell = test_context.Mock(spec=Atspi.Accessible)
1650 test_context.patch("orca.table_navigator.AXTable.is_end_of_row", return_value=True)
1651 from orca.table_navigator import TableNavigator
1652
1653 navigator = TableNavigator()
1654 navigator._get_current_cell = test_context.Mock(return_value=mock_cell)
1655 mock_script = test_context.Mock()
1656 mock_event = test_context.Mock()
1657 pres_manager = essential_modules["orca.presentation_manager"].get_manager()
1658 pres_manager.present_message.reset_mock()
1659 result = navigator.move_to_end_of_row(mock_script, mock_event)
1660 assert result is True
1661 pres_manager.present_message.assert_called_once_with(
1662 essential_modules["orca.messages"].TABLE_ROW_END,
1663 )
1664
1665 def test_move_to_end_of_row_successful(self, test_context: OrcaTestContext) -> None:
1666 """Test move_to_end_of_row successfully moves to end of row and presents it."""
1667
1668 essential_modules = self._setup_dependencies(test_context)
1669 mock_controller = test_context.Mock()
1670 essential_modules["orca.dbus_service"].get_remote_controller.return_value = mock_controller
1671 mock_keybindings_class = test_context.Mock()
1672 mock_keybindings_instance = test_context.Mock()
1673 mock_keybindings_class.return_value = mock_keybindings_instance
1674 test_context.patch(
1675 "orca.table_navigator.keybindings.KeyBindings",
1676 new=mock_keybindings_class,
1677 )
1678 mock_current_cell = test_context.Mock(spec=Atspi.Accessible)
1679 mock_end_cell = test_context.Mock(spec=Atspi.Accessible)
1680 test_context.patch("orca.table_navigator.AXTable.is_end_of_row", return_value=False)
1681 test_context.patch(
1682 "orca.table_navigator.AXTable.get_end_of_row",
1683 return_value=mock_end_cell,
1684 )
1685
1686 def mock_get_cell_coordinates(cell, prefer_attribute=False): # pylint: disable=unused-argument
1687 if cell == mock_end_cell:
1688 return (2, 4)
1689 return (2, 1)
1690
1691 test_context.patch(
1692 "orca.table_navigator.AXTable.get_cell_coordinates",
1693 new=mock_get_cell_coordinates,
1694 )
1695 from orca.table_navigator import TableNavigator
1696
1697 navigator = TableNavigator()
1698 navigator._get_current_cell = test_context.Mock(return_value=mock_current_cell)
1699 mock_present_cell = test_context.Mock()
1700 navigator._present_cell = mock_present_cell
1701 mock_script = test_context.Mock()
1702 mock_event = test_context.Mock()
1703 result = navigator.move_to_end_of_row(mock_script, mock_event)
1704 assert result is True
1705 mock_present_cell.assert_called_once_with(
1706 mock_script,
1707 mock_end_cell,
1708 2,
1709 4,
1710 mock_current_cell,
1711 True,
1712 )
1713
1714 def test_set_dynamic_column_headers_row_not_in_table(
1715 self,
1716 test_context: OrcaTestContext,
1717 ) -> None:
1718 """Test set_dynamic_column_headers_row presents not in table message.
1719
1720 Test case when current cell is None.
1721 """
1722
1723 essential_modules = self._setup_dependencies(test_context)
1724 mock_controller = test_context.Mock()
1725 essential_modules["orca.dbus_service"].get_remote_controller.return_value = mock_controller
1726 mock_keybindings_class = test_context.Mock()
1727 mock_keybindings_instance = test_context.Mock()
1728 mock_keybindings_class.return_value = mock_keybindings_instance
1729 test_context.patch(
1730 "orca.table_navigator.keybindings.KeyBindings",
1731 new=mock_keybindings_class,
1732 )
1733 from orca.table_navigator import TableNavigator
1734
1735 navigator = TableNavigator()
1736 navigator._get_current_cell = test_context.Mock(return_value=None)
1737 mock_script = test_context.Mock()
1738 mock_event = test_context.Mock()
1739 pres_manager = essential_modules["orca.presentation_manager"].get_manager()
1740 pres_manager.present_message.reset_mock()
1741 result = navigator.set_dynamic_column_headers_row(mock_script, mock_event)
1742 assert result is True
1743 pres_manager.present_message.assert_called_once_with(
1744 essential_modules["orca.messages"].TABLE_NOT_IN_A,
1745 )
1746
1747 def test_set_dynamic_column_headers_row_successful(self, test_context: OrcaTestContext) -> None:
1748 """Test set_dynamic_column_headers_row successfully sets column headers row."""
1749
1750 essential_modules = self._setup_dependencies(test_context)
1751 mock_controller = test_context.Mock()
1752 essential_modules["orca.dbus_service"].get_remote_controller.return_value = mock_controller
1753 mock_keybindings_class = test_context.Mock()
1754 mock_keybindings_instance = test_context.Mock()
1755 mock_keybindings_class.return_value = mock_keybindings_instance
1756 test_context.patch(
1757 "orca.table_navigator.keybindings.KeyBindings",
1758 new=mock_keybindings_class,
1759 )
1760 mock_current_cell = test_context.Mock(spec=Atspi.Accessible)
1761 mock_table = test_context.Mock(spec=Atspi.Accessible)
1762 test_context.patch("orca.table_navigator.AXUtilities.get_table", return_value=mock_table)
1763 test_context.patch(
1764 "orca.table_navigator.AXTable.get_cell_coordinates",
1765 return_value=(1, 2),
1766 )
1767 test_context.patch(
1768 "orca.table_navigator.AXUtilities.set_dynamic_column_headers_row",
1769 return_value=None,
1770 )
1771 essential_modules["orca.messages"].DYNAMIC_COLUMN_HEADER_SET = "Column header row set to %d"
1772 from orca.table_navigator import TableNavigator
1773
1774 navigator = TableNavigator()
1775 navigator._get_current_cell = test_context.Mock(return_value=mock_current_cell)
1776 mock_script = test_context.Mock()
1777 mock_event = test_context.Mock()
1778 pres_manager = essential_modules["orca.presentation_manager"].get_manager()
1779 pres_manager.present_message.reset_mock()
1780 result = navigator.set_dynamic_column_headers_row(mock_script, mock_event)
1781 assert result is True
1782 pres_manager.present_message.assert_called_once_with("Column header row set to 2")
1783
1784 def test_clear_dynamic_column_headers_row_not_in_table(
1785 self,
1786 test_context: OrcaTestContext,
1787 ) -> None:
1788 """Test clear_dynamic_column_headers_row presents not in table message.
1789
1790 Test case when current cell is None.
1791 """
1792
1793 essential_modules = self._setup_dependencies(test_context)
1794 mock_controller = test_context.Mock()
1795 essential_modules["orca.dbus_service"].get_remote_controller.return_value = mock_controller
1796 mock_keybindings_class = test_context.Mock()
1797 mock_keybindings_instance = test_context.Mock()
1798 mock_keybindings_class.return_value = mock_keybindings_instance
1799 test_context.patch(
1800 "orca.table_navigator.keybindings.KeyBindings",
1801 new=mock_keybindings_class,
1802 )
1803 from orca.table_navigator import TableNavigator
1804
1805 navigator = TableNavigator()
1806 navigator._get_current_cell = test_context.Mock(return_value=None)
1807 mock_script = test_context.Mock()
1808 mock_event = test_context.Mock()
1809 pres_manager = essential_modules["orca.presentation_manager"].get_manager()
1810 pres_manager.present_message.reset_mock()
1811 result = navigator.clear_dynamic_column_headers_row(mock_script, mock_event)
1812 assert result is True
1813 pres_manager.present_message.assert_called_once_with(
1814 essential_modules["orca.messages"].TABLE_NOT_IN_A,
1815 )
1816
1817 def test_clear_dynamic_column_headers_row_successful(
1818 self,
1819 test_context: OrcaTestContext,
1820 ) -> None:
1821 """Test clear_dynamic_column_headers_row successfully clears column headers row."""
1822
1823 essential_modules = self._setup_dependencies(test_context)
1824 mock_controller = test_context.Mock()
1825 essential_modules["orca.dbus_service"].get_remote_controller.return_value = mock_controller
1826 mock_keybindings_class = test_context.Mock()
1827 mock_keybindings_instance = test_context.Mock()
1828 mock_keybindings_class.return_value = mock_keybindings_instance
1829 test_context.patch(
1830 "orca.table_navigator.keybindings.KeyBindings",
1831 new=mock_keybindings_class,
1832 )
1833 mock_current_cell = test_context.Mock(spec=Atspi.Accessible)
1834 mock_table = test_context.Mock(spec=Atspi.Accessible)
1835 mock_focus_manager = test_context.Mock()
1836 essential_modules["orca.focus_manager"].get_manager.return_value = mock_focus_manager
1837 mock_focus_manager.get_locus_of_focus.return_value = mock_current_cell
1838 test_context.patch("orca.table_navigator.AXUtilities.get_table", return_value=mock_table)
1839 test_context.patch(
1840 "orca.table_navigator.AXUtilities.clear_dynamic_column_headers_row",
1841 return_value=None,
1842 )
1843 from orca.table_navigator import TableNavigator
1844
1845 navigator = TableNavigator()
1846 navigator._get_current_cell = test_context.Mock(return_value=mock_current_cell)
1847 mock_script = test_context.Mock()
1848 mock_event = test_context.Mock()
1849 pres_manager = essential_modules["orca.presentation_manager"].get_manager()
1850 pres_manager.present_message.reset_mock()
1851 pres_manager.interrupt_presentation.reset_mock()
1852 result = navigator.clear_dynamic_column_headers_row(mock_script, mock_event)
1853 assert result is True
1854 pres_manager.interrupt_presentation.assert_called_once()
1855 pres_manager.present_message.assert_called_once_with(
1856 essential_modules["orca.messages"].DYNAMIC_COLUMN_HEADER_CLEARED,
1857 )
1858
1859 def test_set_dynamic_row_headers_column_not_in_table(
1860 self,
1861 test_context: OrcaTestContext,
1862 ) -> None:
1863 """Test set_dynamic_row_headers_column presents not in table message.
1864
1865 Test case when current cell is None.
1866 """
1867
1868 essential_modules = self._setup_dependencies(test_context)
1869 mock_controller = test_context.Mock()
1870 essential_modules["orca.dbus_service"].get_remote_controller.return_value = mock_controller
1871 mock_keybindings_class = test_context.Mock()
1872 mock_keybindings_instance = test_context.Mock()
1873 mock_keybindings_class.return_value = mock_keybindings_instance
1874 test_context.patch(
1875 "orca.table_navigator.keybindings.KeyBindings",
1876 new=mock_keybindings_class,
1877 )
1878 from orca.table_navigator import TableNavigator
1879
1880 navigator = TableNavigator()
1881 navigator._get_current_cell = test_context.Mock(return_value=None)
1882 mock_script = test_context.Mock()
1883 mock_event = test_context.Mock()
1884 pres_manager = essential_modules["orca.presentation_manager"].get_manager()
1885 pres_manager.present_message.reset_mock()
1886 result = navigator.set_dynamic_row_headers_column(mock_script, mock_event)
1887 assert result is True
1888 pres_manager.present_message.assert_called_once_with(
1889 essential_modules["orca.messages"].TABLE_NOT_IN_A,
1890 )
1891
1892 def test_set_dynamic_row_headers_column_successful(self, test_context: OrcaTestContext) -> None:
1893 """Test set_dynamic_row_headers_column successfully sets row headers column."""
1894
1895 essential_modules = self._setup_dependencies(test_context)
1896 mock_controller = test_context.Mock()
1897 essential_modules["orca.dbus_service"].get_remote_controller.return_value = mock_controller
1898 mock_keybindings_class = test_context.Mock()
1899 mock_keybindings_instance = test_context.Mock()
1900 mock_keybindings_class.return_value = mock_keybindings_instance
1901 test_context.patch(
1902 "orca.table_navigator.keybindings.KeyBindings",
1903 new=mock_keybindings_class,
1904 )
1905 mock_current_cell = test_context.Mock(spec=Atspi.Accessible)
1906 mock_table = test_context.Mock(spec=Atspi.Accessible)
1907 test_context.patch("orca.table_navigator.AXUtilities.get_table", return_value=mock_table)
1908 test_context.patch(
1909 "orca.table_navigator.AXTable.get_cell_coordinates",
1910 return_value=(2, 1),
1911 )
1912 test_context.patch(
1913 "orca.table_navigator.AXUtilities.set_dynamic_row_headers_column",
1914 return_value=None,
1915 )
1916 essential_modules["orca.messages"].DYNAMIC_ROW_HEADER_SET = "Row header column set to %s"
1917 test_context.patch(
1918 "orca.table_navigator.AXUtilities.get_column_label",
1919 create=True,
1920 return_value="B",
1921 )
1922 from orca.table_navigator import TableNavigator
1923
1924 navigator = TableNavigator()
1925 navigator._get_current_cell = test_context.Mock(return_value=mock_current_cell)
1926 mock_script = test_context.Mock()
1927 mock_event = test_context.Mock()
1928 pres_manager = essential_modules["orca.presentation_manager"].get_manager()
1929 pres_manager.present_message.reset_mock()
1930 result = navigator.set_dynamic_row_headers_column(mock_script, mock_event)
1931 assert result is True
1932 pres_manager.present_message.assert_called_once_with("Row header column set to B")
1933
1934 def test_clear_dynamic_row_headers_column_not_in_table(
1935 self,
1936 test_context: OrcaTestContext,
1937 ) -> None:
1938 """Test clear_dynamic_row_headers_column presents not in table message.
1939
1940 Test case when current cell is None.
1941 """
1942
1943 essential_modules = self._setup_dependencies(test_context)
1944 mock_controller = test_context.Mock()
1945 essential_modules["orca.dbus_service"].get_remote_controller.return_value = mock_controller
1946 mock_keybindings_class = test_context.Mock()
1947 mock_keybindings_instance = test_context.Mock()
1948 mock_keybindings_class.return_value = mock_keybindings_instance
1949 test_context.patch(
1950 "orca.table_navigator.keybindings.KeyBindings",
1951 new=mock_keybindings_class,
1952 )
1953 from orca.table_navigator import TableNavigator
1954
1955 navigator = TableNavigator()
1956 navigator._get_current_cell = test_context.Mock(return_value=None)
1957 mock_script = test_context.Mock()
1958 mock_event = test_context.Mock()
1959 pres_manager = essential_modules["orca.presentation_manager"].get_manager()
1960 pres_manager.present_message.reset_mock()
1961 result = navigator.clear_dynamic_row_headers_column(mock_script, mock_event)
1962 assert result is True
1963 pres_manager.present_message.assert_called_once_with(
1964 essential_modules["orca.messages"].TABLE_NOT_IN_A,
1965 )
1966
1967 def test_clear_dynamic_row_headers_column_successful(
1968 self,
1969 test_context: OrcaTestContext,
1970 ) -> None:
1971 """Test clear_dynamic_row_headers_column successfully clears row headers column."""
1972
1973 essential_modules = self._setup_dependencies(test_context)
1974 mock_controller = test_context.Mock()
1975 essential_modules["orca.dbus_service"].get_remote_controller.return_value = mock_controller
1976 mock_keybindings_class = test_context.Mock()
1977 mock_keybindings_instance = test_context.Mock()
1978 mock_keybindings_class.return_value = mock_keybindings_instance
1979 test_context.patch(
1980 "orca.table_navigator.keybindings.KeyBindings",
1981 new=mock_keybindings_class,
1982 )
1983 mock_current_cell = test_context.Mock(spec=Atspi.Accessible)
1984 mock_table = test_context.Mock(spec=Atspi.Accessible)
1985 mock_focus_manager = test_context.Mock()
1986 essential_modules["orca.focus_manager"].get_manager.return_value = mock_focus_manager
1987 mock_focus_manager.get_locus_of_focus.return_value = mock_current_cell
1988 test_context.patch("orca.table_navigator.AXUtilities.get_table", return_value=mock_table)
1989 test_context.patch(
1990 "orca.table_navigator.AXUtilities.clear_dynamic_row_headers_column",
1991 return_value=None,
1992 )
1993 from orca.table_navigator import TableNavigator
1994
1995 navigator = TableNavigator()
1996 navigator._get_current_cell = test_context.Mock(return_value=mock_current_cell)
1997 mock_script = test_context.Mock()
1998 mock_event = test_context.Mock()
1999 pres_manager = essential_modules["orca.presentation_manager"].get_manager()
2000 pres_manager.present_message.reset_mock()
2001 pres_manager.interrupt_presentation.reset_mock()
2002 result = navigator.clear_dynamic_row_headers_column(mock_script, mock_event)
2003 assert result is True
2004 pres_manager.interrupt_presentation.assert_called_once()
2005 pres_manager.present_message.assert_called_once_with(
2006 essential_modules["orca.messages"].DYNAMIC_ROW_HEADER_CLEARED,
2007 )
2008
2009 def test_get_cell_coordinates_with_different_previous_cell(
2010 self,
2011 test_context: OrcaTestContext,
2012 ) -> None:
2013 """Test _get_cell_coordinates returns actual coordinates when previous cell differs."""
2014
2015 essential_modules = self._setup_dependencies(test_context)
2016 mock_cell = test_context.Mock(spec=Atspi.Accessible)
2017 mock_table = test_context.Mock(spec=Atspi.Accessible)
2018 mock_different_cell = test_context.Mock(spec=Atspi.Accessible)
2019 test_context.patch(
2020 "orca.table_navigator.AXTable.get_cell_coordinates",
2021 return_value=(2, 3),
2022 )
2023 test_context.patch("orca.table_navigator.AXUtilities.get_table", return_value=mock_table)
2024 test_context.patch(
2025 "orca.table_navigator.AXTable.get_cell_at",
2026 return_value=mock_different_cell,
2027 )
2028 mock_controller = test_context.Mock()
2029 essential_modules["orca.dbus_service"].get_remote_controller.return_value = mock_controller
2030 mock_keybindings_class = test_context.Mock()
2031 mock_keybindings_instance = test_context.Mock()
2032 mock_keybindings_class.return_value = mock_keybindings_instance
2033 test_context.patch(
2034 "orca.table_navigator.keybindings.KeyBindings",
2035 new=mock_keybindings_class,
2036 )
2037 from orca.table_navigator import TableNavigator
2038
2039 navigator = TableNavigator()
2040 navigator._previous_reported_row = 1
2041 navigator._previous_reported_col = 2
2042 result = navigator._get_cell_coordinates(mock_cell)
2043 assert result == (2, 3)
2044
2045 def test_present_cell_with_settings_enabled(self, test_context: OrcaTestContext) -> None:
2046 """Test _present_cell with speakCellCoordinates and speakCellSpan enabled."""
2047
2048 essential_modules = self._setup_dependencies(test_context)
2049 test_context.patch(
2050 "orca.table_navigator.AXUtilities.is_table_cell_or_header",
2051 return_value=True,
2052 )
2053 test_context.patch("orca.table_navigator.AXObject.grab_focus", return_value=None)
2054 test_context.patch(
2055 "orca.table_navigator.AXUtilities.get_descendant_supporting_text", return_value=None
2056 )
2057 test_context.patch("orca.table_navigator.AXObject.supports_text", return_value=False)
2058 test_context.patch("orca.table_navigator.AXTable.get_cell_spans", return_value=(2, 3))
2059 mock_focus_manager = test_context.Mock()
2060 essential_modules["orca.focus_manager"].get_manager.return_value = mock_focus_manager
2061 essential_modules["orca.messages"].TABLE_CELL_COORDINATES = "Row %(row)s, column %(column)s"
2062 essential_modules["orca.messages"].cell_span.return_value = "spans 2 rows and 3 columns"
2063 mock_controller = test_context.Mock()
2064 essential_modules["orca.dbus_service"].get_remote_controller.return_value = mock_controller
2065 mock_keybindings_class = test_context.Mock()
2066 mock_keybindings_instance = test_context.Mock()
2067 mock_keybindings_class.return_value = mock_keybindings_instance
2068 test_context.patch(
2069 "orca.table_navigator.keybindings.KeyBindings",
2070 new=mock_keybindings_class,
2071 )
2072 from orca.table_navigator import TableNavigator
2073
2074 navigator = TableNavigator()
2075 mock_script = test_context.Mock()
2076 mock_script.utilities.grab_focus_when_setting_caret.return_value = False
2077 test_context.patch("orca.table_navigator.AXUtilities.is_gui_cell", return_value=False)
2078 mock_script.present_object = test_context.Mock()
2079 mock_cell = test_context.Mock(spec=Atspi.Accessible)
2080 mock_previous_cell = test_context.Mock(spec=Atspi.Accessible)
2081 pres_manager = essential_modules["orca.presentation_manager"].get_manager()
2082 pres_manager.present_message.reset_mock()
2083 navigator._present_cell(mock_script, mock_cell, 1, 2, mock_previous_cell)
2084 assert navigator._previous_reported_row == 1
2085 assert navigator._previous_reported_col == 2
2086 mock_focus_manager.set_locus_of_focus.assert_called()
2087 mock_script.present_object.assert_called_once_with(
2088 mock_cell,
2089 offset=0,
2090 priorObj=mock_previous_cell,
2091 interrupt=True,
2092 )
2093 assert pres_manager.present_message.call_count == 2
2094
2095 def test_present_cell_with_text_descendant_and_gui_cell(
2096 self,
2097 test_context: OrcaTestContext,
2098 ) -> None:
2099 """Test _present_cell when cell has text descendant and is gui cell."""
2100
2101 essential_modules = self._setup_dependencies(test_context)
2102 mock_text_obj = test_context.Mock(spec=Atspi.Accessible)
2103 test_context.patch(
2104 "orca.table_navigator.AXUtilities.is_table_cell_or_header",
2105 return_value=True,
2106 )
2107 test_context.patch("orca.table_navigator.AXObject.grab_focus", return_value=None)
2108 test_context.patch(
2109 "orca.table_navigator.AXUtilities.get_descendant_supporting_text",
2110 return_value=mock_text_obj,
2111 )
2112 test_context.patch(
2113 "orca.table_navigator.AXObject.supports_text",
2114 side_effect=lambda obj: obj == mock_text_obj,
2115 )
2116 test_context.patch("orca.table_navigator.AXTable.get_cell_spans", return_value=(1, 1))
2117 mock_focus_manager = test_context.Mock()
2118 essential_modules["orca.focus_manager"].get_manager.return_value = mock_focus_manager
2119 mock_controller = test_context.Mock()
2120 essential_modules["orca.dbus_service"].get_remote_controller.return_value = mock_controller
2121 mock_keybindings_class = test_context.Mock()
2122 mock_keybindings_instance = test_context.Mock()
2123 mock_keybindings_class.return_value = mock_keybindings_instance
2124 test_context.patch(
2125 "orca.table_navigator.keybindings.KeyBindings",
2126 new=mock_keybindings_class,
2127 )
2128
2129 from orca import gsettings_registry
2130 from orca.table_navigator import TableNavigator
2131
2132 registry = gsettings_registry.get_registry()
2133 registry.set_runtime_value("speech", "announce-cell-coordinates", False)
2134 registry.set_runtime_value("speech", "announce-cell-span", False)
2135
2136 navigator = TableNavigator()
2137 mock_script = test_context.Mock()
2138 mock_script.utilities.grab_focus_when_setting_caret.return_value = True
2139 test_context.patch("orca.table_navigator.AXUtilities.is_gui_cell", return_value=True)
2140 mock_script.utilities.set_caret_position = test_context.Mock()
2141 mock_script.present_object = test_context.Mock()
2142 mock_cell = test_context.Mock(spec=Atspi.Accessible)
2143 mock_previous_cell = test_context.Mock(spec=Atspi.Accessible)
2144 navigator._present_cell(mock_script, mock_cell, 1, 2, mock_previous_cell)
2145 mock_focus_manager.set_locus_of_focus.assert_called_with(None, mock_text_obj, False)
2146 assert navigator._previous_reported_row == 1
2147 assert navigator._previous_reported_col == 2
2148
2149 def test_get_skip_blank_cells(self, test_context: OrcaTestContext) -> None:
2150 """Test TableNavigator.get_skip_blank_cells returns setting value."""
2151
2152 self._setup_dependencies(test_context)
2153
2154 from orca import gsettings_registry
2155 from orca.table_navigator import get_navigator
2156
2157 gsettings_registry.get_registry().set_runtime_value(
2158 "table-navigation",
2159 "skip-blank-cells",
2160 True,
2161 )
2162 nav = get_navigator()
2163 result = nav.get_skip_blank_cells()
2164 assert result is True
2165
2166 def test_set_skip_blank_cells(self, test_context: OrcaTestContext) -> None:
2167 """Test TableNavigator.set_skip_blank_cells updates setting."""
2168
2169 self._setup_dependencies(test_context)
2170 from orca.table_navigator import get_navigator
2171
2172 nav = get_navigator()
2173 result = nav.set_skip_blank_cells(True)
2174 assert result is True
2175 assert nav.get_skip_blank_cells() is True
2176
2177 def test_set_skip_blank_cells_no_change(self, test_context: OrcaTestContext) -> None:
2178 """Test TableNavigator.set_skip_blank_cells returns early if value unchanged."""
2179
2180 self._setup_dependencies(test_context)
2181
2182 from orca import gsettings_registry
2183 from orca.table_navigator import get_navigator
2184
2185 gsettings_registry.get_registry().set_runtime_value(
2186 "table-navigation",
2187 "skip-blank-cells",
2188 True,
2189 )
2190 nav = get_navigator()
2191 result = nav.set_skip_blank_cells(True)
2192 assert result is True
2193
2194 def test_present_cell_emits_region_changed(self, test_context: OrcaTestContext) -> None:
2195 """Test _present_cell emits region_changed with TABLE_NAVIGATOR mode."""
2196
2197 essential_modules = self._setup_dependencies(test_context)
2198 test_context.patch(
2199 "orca.table_navigator.AXUtilities.is_table_cell_or_header",
2200 return_value=True,
2201 )
2202 test_context.patch("orca.table_navigator.AXObject.grab_focus", return_value=None)
2203 test_context.patch(
2204 "orca.table_navigator.AXUtilities.get_descendant_supporting_text", return_value=None
2205 )
2206 test_context.patch("orca.table_navigator.AXObject.supports_text", return_value=False)
2207 test_context.patch("orca.table_navigator.AXTable.get_cell_spans", return_value=(1, 1))
2208 mock_focus_manager = test_context.Mock()
2209 essential_modules["orca.focus_manager"].get_manager.return_value = mock_focus_manager
2210
2211 from orca import focus_manager, gsettings_registry
2212
2213 essential_modules["orca.focus_manager"].TABLE_NAVIGATOR = focus_manager.TABLE_NAVIGATOR
2214 registry = gsettings_registry.get_registry()
2215 registry.set_runtime_value("speech", "announce-cell-coordinates", False)
2216 registry.set_runtime_value("speech", "announce-cell-span", False)
2217
2218 mock_controller = test_context.Mock()
2219 essential_modules["orca.dbus_service"].get_remote_controller.return_value = mock_controller
2220 mock_keybindings_class = test_context.Mock()
2221 mock_keybindings_instance = test_context.Mock()
2222 mock_keybindings_class.return_value = mock_keybindings_instance
2223 test_context.patch(
2224 "orca.table_navigator.keybindings.KeyBindings",
2225 new=mock_keybindings_class,
2226 )
2227 from orca.table_navigator import TableNavigator
2228
2229 navigator = TableNavigator()
2230 mock_script = test_context.Mock()
2231 mock_script.utilities.grab_focus_when_setting_caret.return_value = False
2232 test_context.patch("orca.table_navigator.AXUtilities.is_gui_cell", return_value=False)
2233 mock_script.present_object = test_context.Mock()
2234 mock_cell = test_context.Mock(spec=Atspi.Accessible)
2235 mock_previous_cell = test_context.Mock(spec=Atspi.Accessible)
2236
2237 navigator._present_cell(mock_script, mock_cell, 1, 2, mock_previous_cell)
2238
2239 mock_focus_manager.emit_region_changed.assert_called()
2240 call_kwargs = mock_focus_manager.emit_region_changed.call_args
2241 assert call_kwargs.kwargs.get("mode") == focus_manager.TABLE_NAVIGATOR