headless-browser: Let tests set their own timeout duration

Some tests take longer than others, and so may want to set a custom
timeout so that they pass, without increasing the timeout for all other
tests. For example, this is done in WPT.

Add an `internals.setTestTimeout(milliseconds)` method that overrides
the test runner's default timeout for the currently-run test.
This commit is contained in:
Sam Atkins 2024-12-19 14:16:05 +00:00
parent 9164c9784d
commit be6a9940ad
Notes: github-actions[bot] 2024-12-19 17:28:47 +00:00
11 changed files with 42 additions and 0 deletions

View file

@ -112,6 +112,7 @@ void run_dump_test(HeadlessWebView& view, Test& test, URL::URL const& url, int t
auto timer = Core::Timer::create_single_shot(timeout_in_milliseconds, [&view, &test]() {
view.on_load_finish = {};
view.on_text_test_finish = {};
view.on_set_test_timeout = {};
view.on_test_complete({ test, TestResult::Timeout });
});
@ -233,6 +234,13 @@ void run_dump_test(HeadlessWebView& view, Test& test, URL::URL const& url, int t
};
}
view.on_set_test_timeout = [timer, timeout_in_milliseconds](double milliseconds) {
if (milliseconds <= timeout_in_milliseconds)
return;
timer->stop();
timer->start(milliseconds);
};
view.load(url);
timer->start();
}
@ -242,6 +250,7 @@ static void run_ref_test(HeadlessWebView& view, Test& test, URL::URL const& url,
auto timer = Core::Timer::create_single_shot(timeout_in_milliseconds, [&view, &test]() {
view.on_load_finish = {};
view.on_text_test_finish = {};
view.on_set_test_timeout = {};
view.on_test_complete({ test, TestResult::Timeout });
});
@ -315,6 +324,13 @@ static void run_ref_test(HeadlessWebView& view, Test& test, URL::URL const& url,
dbgln("Unexpected text test finished during ref test for {}", url);
};
view.on_set_test_timeout = [timer, timeout_in_milliseconds](double milliseconds) {
if (milliseconds <= timeout_in_milliseconds)
return;
timer->stop();
timer->start(milliseconds);
};
view.load(url);
timer->start();
}