mirror of
https://github.com/RGBCube/serenity
synced 2025-05-20 11:55:08 +00:00
headless-browser: Await on_load_finish()
while running Text tests
Before this change, it was possible for a text test to finish before on_load_finish() was triggered, resulting in the subsequent test receiving the load event from the previous test.
This commit is contained in:
parent
6ccdb1dc72
commit
2f09bfeff2
1 changed files with 17 additions and 4 deletions
|
@ -214,12 +214,17 @@ static ErrorOr<TestResult> run_dump_test(HeadlessWebContentView& view, StringVie
|
||||||
loop.quit(0);
|
loop.quit(0);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
view.load(URL::create_with_file_scheme(TRY(FileSystem::real_path(input_path)).to_byte_string()));
|
auto url = URL::create_with_file_scheme(TRY(FileSystem::real_path(input_path)).to_byte_string());
|
||||||
|
view.load(url);
|
||||||
|
|
||||||
String result;
|
String result;
|
||||||
|
auto did_finish_test = false;
|
||||||
|
auto did_finish_loading = false;
|
||||||
|
|
||||||
if (mode == TestMode::Layout) {
|
if (mode == TestMode::Layout) {
|
||||||
view.on_load_finish = [&](auto const&) {
|
view.on_load_finish = [&](auto const& loaded_url) {
|
||||||
|
VERIFY(url.equals(loaded_url, URL::ExcludeFragment::Yes));
|
||||||
|
|
||||||
// NOTE: We take a screenshot here to force the lazy layout of SVG-as-image documents to happen.
|
// NOTE: We take a screenshot here to force the lazy layout of SVG-as-image documents to happen.
|
||||||
// It also causes a lot more code to run, which is good for finding bugs. :^)
|
// It also causes a lot more code to run, which is good for finding bugs. :^)
|
||||||
(void)view.take_screenshot();
|
(void)view.take_screenshot();
|
||||||
|
@ -233,10 +238,18 @@ static ErrorOr<TestResult> run_dump_test(HeadlessWebContentView& view, StringVie
|
||||||
};
|
};
|
||||||
view.on_text_test_finish = {};
|
view.on_text_test_finish = {};
|
||||||
} else if (mode == TestMode::Text) {
|
} else if (mode == TestMode::Text) {
|
||||||
view.on_load_finish = {};
|
|
||||||
|
view.on_load_finish = [&](auto const& loaded_url) {
|
||||||
|
VERIFY(url.equals(loaded_url, URL::ExcludeFragment::Yes));
|
||||||
|
did_finish_loading = true;
|
||||||
|
if (did_finish_test)
|
||||||
|
loop.quit(0);
|
||||||
|
};
|
||||||
view.on_text_test_finish = [&]() {
|
view.on_text_test_finish = [&]() {
|
||||||
result = view.dump_text().release_value_but_fixme_should_propagate_errors();
|
result = view.dump_text().release_value_but_fixme_should_propagate_errors();
|
||||||
loop.quit(0);
|
did_finish_test = true;
|
||||||
|
if (did_finish_loading)
|
||||||
|
loop.quit(0);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue