Repository: servo/servo
File: python/servo/devtools_tests.py (Python)

Code before:
                        "sourceUrl": f"{self.base_urls[0]}/breakpoint/breakpoint_hit.html",
                        "line": line,
                        "column": column,
                    },
                }
            )

            # Listen for paused event
            paused_future = Future()

            def on_paused(data):
                paused_future.set_result(data)

            devtools.client.add_event_listener(thread_actor, "paused", on_paused)

            # Trigger breakpoint
            console = WebConsoleActor(devtools.client, devtools.targets[0]["consoleActor"])
            console.evaluate_js_async("testBreakpointHit()")

            # Verify pause
            paused_data = paused_future.result(3)
            self.assertEqual(paused_data.get("type"), "paused")
            self.assertEqual(paused_data.get("why", {}).get("type"), "breakpoint")

    def test_manual_pause(self):
        self.run_servoshell(url=f"{self.base_urls[0]}/breakpoint/manual_pause.html")
        with Devtools.connect() as devtools:
            thread_actor = devtools.targets[0]["threadActor"]
            devtools.client.send_receive({"to": thread_actor, "type": "attach"})

            # Listen for paused event
            paused_future = Future()

            def on_paused(data):
                paused_future.set_result(data)

            devtools.client.add_event_listener(thread_actor, "paused", on_paused)

            # Interrupt when entering the next frame
            devtools.client.send_receive(
                {
                    "to": thread_actor,
                    "type": "interrupt",
                    "when": "onNext",
                }
            )

            # Verify pause
            paused_data = paused_future.result(3)
            self.assertEqual(paused_data.get("type"), "paused")
            why = paused_data.get("why", {})

Review comment (suggestion):
Maybe we could use the same html in both pause related tests? Either we could use the existing `breakpoint_hit.html` here or this `manual_pause.html` in `test_breakpoint_pause` test, whatever makes more sense?

using `manual_pause.html` in `test_breakpoint_pause` might be easier, we could set a breakpoint in the `repeat()` function, and wait for the breakpoint to hit (since `repeat()` runs every 200ms anyway).

I think this should remove the need for the `evaluate_js_async("testBreakpointHit()")` call in `test_breakpoint_pause`

Code after:
                        "sourceUrl": f"{self.base_urls[0]}/debugger/loop.html",
                        "line": line,
                        "column": column,
                    },
                }
            )

            # Listen for paused event
            paused_future = Future()

            def on_paused(data):
                paused_future.set_result(data)

            devtools.client.add_event_listener(thread_actor, "paused", on_paused)

            # Verify pause
            paused_data = paused_future.result(3)
            self.assertEqual(paused_data.get("type"), "paused")
            self.assertEqual(paused_data.get("why", {}).get("type"), "breakpoint")

    def test_manual_pause(self):
        self.run_servoshell(url=f"{self.base_urls[0]}/debugger/loop.html")
        with Devtools.connect() as devtools:
            thread_actor = devtools.targets[0]["threadActor"]
            devtools.client.send_receive({"to": thread_actor, "type": "attach"})

            # Listen for paused event
            paused_future = Future()

            def on_paused(data):
                paused_future.set_result(data)

            devtools.client.add_event_listener(thread_actor, "paused", on_paused)

            # Interrupt when entering the next frame
            devtools.client.send_receive(
                {
                    "to": thread_actor,
                    "type": "interrupt",
                    "when": "onNext",
                }
            )

            # Verify pause
            paused_data = paused_future.result(3)
            self.assertEqual(paused_data.get("type"), "paused")
            why = paused_data.get("why", {})
            self.assertEqual(why.get("type"), "interrupted")
            self.assertEqual(why.get("onNext"), True)

    # Sources list