1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-14 09:24:57 +00:00

LibWeb+WebContent+headless-browser: Support async text tests

Previously, we used `on_load_finish` to determine when the text test
was completed. This method did not allow testing of async functions
because there was no way to indicate that the runner should wait for
the async call to end.

This change introduces a function in the `internals` object that is
intended to be called when the text test execution is completed. The
text test runner will now ignore `on_load_finish` which means a test
will timeout if this new function is never called.

`test(f)` function in `include.js` has been modified to automatically
terminate a test once `load` event is fired on `window`.
new `asyncTest(f)` function has been introduces. `f` receives function
that will terminate a test as a first argument.

Every test is expected to call either `test()` or `asyncTest()` to
complete. If not, it will remain hanging until a timeout occurs.
This commit is contained in:
Aliaksandr Kalenik 2023-09-14 19:17:32 +02:00 committed by Andreas Kling
parent c74f7e5f2a
commit 6f8be44c0e
20 changed files with 98 additions and 40 deletions

View file

@ -196,8 +196,10 @@ static ErrorOr<TestResult> run_dump_test(HeadlessWebContentView& view, StringVie
result = builder.to_string().release_value_but_fixme_should_propagate_errors();
loop.quit(0);
};
view.on_text_test_finish = {};
} else if (mode == TestMode::Text) {
view.on_load_finish = [&](auto const&) {
view.on_load_finish = {};
view.on_text_test_finish = [&]() {
result = view.dump_text().release_value_but_fixme_should_propagate_errors();
loop.quit(0);
};