Harden XTerm handoff and web event routing
This commit is contained in:
@@ -177,5 +177,137 @@ class CheckedStateRoutingContractTests(unittest.TestCase):
|
||||
)
|
||||
|
||||
|
||||
class ExpandedStateRoutingContractTests(unittest.TestCase):
|
||||
def test_shared_web_owns_expanded_state_without_default_fallback(self):
|
||||
for toolkit_script in (chromium_script, gecko_script):
|
||||
with self.subTest(toolkit=toolkit_script.__name__):
|
||||
test_script = toolkit_script.Script.__new__(toolkit_script.Script)
|
||||
test_script._eventRouter = WebEventRouter()
|
||||
event = object()
|
||||
with (
|
||||
mock.patch.object(
|
||||
web.Script,
|
||||
"onExpandedChanged",
|
||||
return_value=True,
|
||||
) as web_handler,
|
||||
mock.patch.object(
|
||||
default.Script,
|
||||
"onExpandedChanged",
|
||||
) as default_handler,
|
||||
mock.patch(
|
||||
"cthulhu.scripts.web.event_router.debug.printMessage"
|
||||
) as print_message,
|
||||
):
|
||||
toolkit_script.Script.onExpandedChanged(test_script, event)
|
||||
|
||||
web_handler.assert_called_once_with(test_script, event)
|
||||
default_handler.assert_not_called()
|
||||
messages = [call.args[1] for call in print_message.call_args_list]
|
||||
self.assertIn(
|
||||
"WEB EVENT ROUTER: SHARED_WEB -> HANDLED",
|
||||
messages,
|
||||
)
|
||||
|
||||
def test_unhandled_expanded_state_reaches_default_once(self):
|
||||
for toolkit_script in (chromium_script, gecko_script):
|
||||
with self.subTest(toolkit=toolkit_script.__name__):
|
||||
test_script = toolkit_script.Script.__new__(toolkit_script.Script)
|
||||
test_script._eventRouter = WebEventRouter()
|
||||
event = object()
|
||||
with (
|
||||
mock.patch.object(
|
||||
web.Script,
|
||||
"onExpandedChanged",
|
||||
return_value=False,
|
||||
) as web_handler,
|
||||
mock.patch.object(
|
||||
default.Script,
|
||||
"onExpandedChanged",
|
||||
) as default_handler,
|
||||
mock.patch(
|
||||
"cthulhu.scripts.web.event_router.debug.printMessage"
|
||||
) as print_message,
|
||||
):
|
||||
toolkit_script.Script.onExpandedChanged(test_script, event)
|
||||
|
||||
web_handler.assert_called_once_with(test_script, event)
|
||||
default_handler.assert_called_once_with(test_script, event)
|
||||
messages = [call.args[1] for call in print_message.call_args_list]
|
||||
self.assertIn(
|
||||
"WEB EVENT ROUTER: DEFAULT -> HANDLED",
|
||||
messages,
|
||||
)
|
||||
|
||||
|
||||
class TableReorderRoutingContractTests(unittest.TestCase):
|
||||
def test_shared_web_owns_table_reorder_without_default_fallback(self):
|
||||
for toolkit_script in (chromium_script, gecko_script):
|
||||
for handler_name in ("onColumnReordered", "onRowReordered"):
|
||||
with self.subTest(
|
||||
toolkit=toolkit_script.__name__,
|
||||
handler=handler_name,
|
||||
):
|
||||
test_script = toolkit_script.Script.__new__(toolkit_script.Script)
|
||||
test_script._eventRouter = WebEventRouter()
|
||||
event = object()
|
||||
with (
|
||||
mock.patch.object(
|
||||
web.Script,
|
||||
handler_name,
|
||||
return_value=True,
|
||||
) as web_handler,
|
||||
mock.patch.object(
|
||||
default.Script,
|
||||
handler_name,
|
||||
) as default_handler,
|
||||
mock.patch(
|
||||
"cthulhu.scripts.web.event_router.debug.printMessage"
|
||||
) as print_message,
|
||||
):
|
||||
getattr(toolkit_script.Script, handler_name)(test_script, event)
|
||||
|
||||
web_handler.assert_called_once_with(test_script, event)
|
||||
default_handler.assert_not_called()
|
||||
messages = [call.args[1] for call in print_message.call_args_list]
|
||||
self.assertIn(
|
||||
"WEB EVENT ROUTER: SHARED_WEB -> HANDLED",
|
||||
messages,
|
||||
)
|
||||
|
||||
def test_unhandled_table_reorder_reaches_default_once(self):
|
||||
for toolkit_script in (chromium_script, gecko_script):
|
||||
for handler_name in ("onColumnReordered", "onRowReordered"):
|
||||
with self.subTest(
|
||||
toolkit=toolkit_script.__name__,
|
||||
handler=handler_name,
|
||||
):
|
||||
test_script = toolkit_script.Script.__new__(toolkit_script.Script)
|
||||
test_script._eventRouter = WebEventRouter()
|
||||
event = object()
|
||||
with (
|
||||
mock.patch.object(
|
||||
web.Script,
|
||||
handler_name,
|
||||
return_value=False,
|
||||
) as web_handler,
|
||||
mock.patch.object(
|
||||
default.Script,
|
||||
handler_name,
|
||||
) as default_handler,
|
||||
mock.patch(
|
||||
"cthulhu.scripts.web.event_router.debug.printMessage"
|
||||
) as print_message,
|
||||
):
|
||||
getattr(toolkit_script.Script, handler_name)(test_script, event)
|
||||
|
||||
web_handler.assert_called_once_with(test_script, event)
|
||||
default_handler.assert_called_once_with(test_script, event)
|
||||
messages = [call.args[1] for call in print_message.call_args_list]
|
||||
self.assertIn(
|
||||
"WEB EVENT ROUTER: DEFAULT -> HANDLED",
|
||||
messages,
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user