mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 10:28:10 +00:00
headless-browser: Use run_dump_test() for single-test runs as well
This avoids having two separate ways to set up the finish callbacks. It also makes it possible to run a single async test on its own.
This commit is contained in:
parent
32a6bf908a
commit
b344d39014
1 changed files with 21 additions and 27 deletions
|
@ -261,6 +261,11 @@ static ErrorOr<TestResult> run_dump_test(HeadlessWebContentView& view, StringVie
|
||||||
if (did_timeout)
|
if (did_timeout)
|
||||||
return TestResult::Timeout;
|
return TestResult::Timeout;
|
||||||
|
|
||||||
|
if (expectation_path.is_empty()) {
|
||||||
|
out("{}", result);
|
||||||
|
return TestResult::Skipped;
|
||||||
|
}
|
||||||
|
|
||||||
auto expectation_file_or_error = Core::File::open(expectation_path, Core::File::OpenMode::Read);
|
auto expectation_file_or_error = Core::File::open(expectation_path, Core::File::OpenMode::Read);
|
||||||
if (expectation_file_or_error.is_error()) {
|
if (expectation_file_or_error.is_error()) {
|
||||||
warnln("Failed opening '{}': {}", expectation_path, expectation_file_or_error.error());
|
warnln("Failed opening '{}': {}", expectation_path, expectation_file_or_error.error());
|
||||||
|
@ -561,42 +566,31 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
}
|
}
|
||||||
|
|
||||||
auto view = TRY(HeadlessWebContentView::create(move(theme), window_size, web_driver_ipc_path, is_layout_test_mode ? Ladybird::IsLayoutTestMode::Yes : Ladybird::IsLayoutTestMode::No));
|
auto view = TRY(HeadlessWebContentView::create(move(theme), window_size, web_driver_ipc_path, is_layout_test_mode ? Ladybird::IsLayoutTestMode::Yes : Ladybird::IsLayoutTestMode::No));
|
||||||
RefPtr<Core::Timer> timer;
|
|
||||||
|
|
||||||
if (!test_root_path.is_empty()) {
|
if (!test_root_path.is_empty()) {
|
||||||
return run_tests(*view, test_root_path, dump_failed_ref_tests);
|
return run_tests(*view, test_root_path, dump_failed_ref_tests);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dump_layout_tree) {
|
|
||||||
view->on_load_finish = [&](auto const&) {
|
|
||||||
(void)view->take_screenshot();
|
|
||||||
auto layout_tree = view->dump_layout_tree().release_value_but_fixme_should_propagate_errors();
|
|
||||||
auto paint_tree = view->dump_paint_tree().release_value_but_fixme_should_propagate_errors();
|
|
||||||
|
|
||||||
out("{}\n{}", layout_tree, paint_tree);
|
|
||||||
fflush(stdout);
|
|
||||||
|
|
||||||
event_loop.quit(0);
|
|
||||||
};
|
|
||||||
} else if (dump_text) {
|
|
||||||
view->on_load_finish = [&](auto const&) {
|
|
||||||
auto text = view->dump_text().release_value_but_fixme_should_propagate_errors();
|
|
||||||
|
|
||||||
out("{}", text);
|
|
||||||
fflush(stdout);
|
|
||||||
|
|
||||||
event_loop.quit(0);
|
|
||||||
};
|
|
||||||
} else if (web_driver_ipc_path.is_empty()) {
|
|
||||||
timer = TRY(load_page_for_screenshot_and_exit(event_loop, *view, screenshot_timeout));
|
|
||||||
}
|
|
||||||
|
|
||||||
auto url = WebView::sanitize_url(raw_url);
|
auto url = WebView::sanitize_url(raw_url);
|
||||||
if (!url.has_value()) {
|
if (!url.has_value()) {
|
||||||
warnln("Invalid URL: \"{}\"", raw_url);
|
warnln("Invalid URL: \"{}\"", raw_url);
|
||||||
return Error::from_string_literal("Invalid URL");
|
return Error::from_string_literal("Invalid URL");
|
||||||
}
|
}
|
||||||
|
|
||||||
view->load(*url);
|
if (dump_layout_tree) {
|
||||||
return event_loop.exec();
|
TRY(run_dump_test(*view, raw_url, ""sv, TestMode::Layout));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dump_text) {
|
||||||
|
TRY(run_dump_test(*view, raw_url, ""sv, TestMode::Text));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (web_driver_ipc_path.is_empty()) {
|
||||||
|
auto timer = TRY(load_page_for_screenshot_and_exit(event_loop, *view, screenshot_timeout));
|
||||||
|
return event_loop.exec();
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue