Skip to content

Truly independent web browser

LibWeb: Reset manual rendering controls between tests

Andreas Kling5eb77e315aac
diff --git a/Libraries/LibWebView/ViewImplementation.cpp b/Libraries/LibWebView/ViewImplementation.cpp
index cfd1d285676..d6d38c96823 100644
--- a/Libraries/LibWebView/ViewImplementation.cpp
+++ b/Libraries/LibWebView/ViewImplementation.cpp
@@ -3782,30 +3782,31 @@ void ViewImplementation::notify_session_history_changed()
m_session->session_store->update_tab_state(move(update));
}
-NonnullRefPtr<Core::Promise<Empty>> ViewImplementation::reset_session_history_for_testing()
+NonnullRefPtr<Core::Promise<Empty>> ViewImplementation::reset_state_for_testing()
{
- m_pending_session_history_reset_for_testing = Core::Promise<Empty>::construct();
+ m_pending_test_state_reset = Core::Promise<Empty>::construct();
// The algorithms this test control replaces run on the session history traversal queue. Keep that ordering by
// sending the reset at its queue position, and hold the queue until WebContent returns the retained active
- // entry so canonical history is reset before anything queued behind the reset runs.
+ // entry so canonical history is reset before anything queued behind the reset runs. WebContent also restores
+ // automatic rendering before acknowledging the reset.
traversable().append_history_queue_steps([this](NonnullRefPtr<Core::Promise<Empty>> promise) {
- m_pending_session_history_reset_queue_promise = move(promise);
- page().reset_session_history_for_testing();
+ m_pending_test_state_reset_queue_promise = move(promise);
+ page().reset_state_for_testing();
});
- return *m_pending_session_history_reset_for_testing;
+ return *m_pending_test_state_reset;
}
-void ViewImplementation::did_reset_session_history_for_testing(
+void ViewImplementation::did_reset_state_for_testing(
Badge<WebContentPage>, Web::HTML::SessionHistoryEntryDescriptor active_entry)
{
- auto promise = move(m_pending_session_history_reset_for_testing);
+ auto promise = move(m_pending_test_state_reset);
traversable().reset_session_history_for_testing(move(active_entry));
m_webdriver_navigation_observation.clear();
// The reset installed the process's own active entry as the canonical current entry.
traversable().active_document().set_host(page());
update_navigation_action_state();
- if (auto queue_promise = move(m_pending_session_history_reset_queue_promise))
+ if (auto queue_promise = move(m_pending_test_state_reset_queue_promise))
queue_promise->resolve({});
if (promise)
promise->resolve({});
@@ -3933,8 +3934,8 @@ void ViewImplementation::respawn_web_content_process_after_crash()
// Nothing answers the crashed page's requests.
fail_pending_debugger_requests();
reject_pending_selection_requests();
- // A queued session-history reset awaiting the crashed process's reply can never complete.
- if (auto queue_promise = move(m_pending_session_history_reset_queue_promise))
+ // A queued test-state reset awaiting the crashed process's reply can never complete.
+ if (auto queue_promise = move(m_pending_test_state_reset_queue_promise))
queue_promise->resolve({});
cancel_all_native_geolocation_requests();
// Don't keep a stale backup bitmap around.
diff --git a/Libraries/LibWebView/ViewImplementation.h b/Libraries/LibWebView/ViewImplementation.h
index 72feafdf6ba..45e48cf3344 100644
--- a/Libraries/LibWebView/ViewImplementation.h
+++ b/Libraries/LibWebView/ViewImplementation.h
@@ -423,7 +423,7 @@ public:
Web::HTML::AudioPlayState audio_play_state() const { return m_audio_play_state; }
void did_change_screen_wake_lock_state(Badge<WebContentPage>, Web::ScreenWakeLockState);
- void did_reset_session_history_for_testing(Badge<WebContentPage>, Web::HTML::SessionHistoryEntryDescriptor);
+ void did_reset_state_for_testing(Badge<WebContentPage>, Web::HTML::SessionHistoryEntryDescriptor);
bool capture_session_history_snapshot_for_testing(Badge<WebContentPage>);
bool restore_captured_session_history_snapshot_for_testing(Badge<WebContentPage>);
bool register_session_store_tab_for_testing(Badge<WebContentPage>);
@@ -674,7 +674,7 @@ protected:
void dump_session_history(StringView reason, SessionHistoryDumpMode = SessionHistoryDumpMode::IfDebuggingEnabled) const;
void recover_current_session_history_entry_with_history_operation();
void reconstruct_current_session_history_entry_with_history_operation(StringView reason);
- NonnullRefPtr<Core::Promise<Empty>> reset_session_history_for_testing();
+ NonnullRefPtr<Core::Promise<Empty>> reset_state_for_testing();
virtual void update_zoom();
@@ -1032,8 +1032,8 @@ protected:
CanonicalTraversable* m_top_level_traversable { nullptr };
Optional<SessionTabId> m_session_tab_id;
Optional<SessionHistorySnapshot> m_captured_session_history_snapshot_for_testing;
- RefPtr<Core::Promise<Empty>> m_pending_session_history_reset_for_testing;
- RefPtr<Core::Promise<Empty>> m_pending_session_history_reset_queue_promise;
+ RefPtr<Core::Promise<Empty>> m_pending_test_state_reset;
+ RefPtr<Core::Promise<Empty>> m_pending_test_state_reset_queue_promise;
struct WebDriverNavigationCompletionRequest {
AK_ALLOC_WITH_KMALLOC;
diff --git a/Libraries/LibWebView/WebContentPage.cpp b/Libraries/LibWebView/WebContentPage.cpp
index a4dcf936c83..c2a0c831373 100644
--- a/Libraries/LibWebView/WebContentPage.cpp
+++ b/Libraries/LibWebView/WebContentPage.cpp
@@ -2911,19 +2911,19 @@ void WebContentPage::did_request_traverse_history_by_delta_for_testing(i32 delta
view().traverse_the_history_by_delta(delta);
}
-void WebContentPage::reset_session_history_for_testing()
+void WebContentPage::reset_state_for_testing()
{
auto* client = routed_connection();
if (!client || !client->test_connection())
return;
client->transport().flush();
- client->test_connection()->async_reset_session_history_for_testing(m_id);
+ client->test_connection()->async_reset_state_for_testing(m_id);
}
-void WebContentPage::did_reset_session_history_for_testing(Web::HTML::SessionHistoryEntryDescriptor active_entry)
+void WebContentPage::did_reset_state_for_testing(Web::HTML::SessionHistoryEntryDescriptor active_entry)
{
if (displays_tab())
- view().did_reset_session_history_for_testing({}, move(active_entry));
+ view().did_reset_state_for_testing({}, move(active_entry));
}
Messages::WebContentTestClient::DidRequestCaptureSessionHistorySnapshotForTestingResponse WebContentPage::did_request_capture_session_history_snapshot_for_testing()
diff --git a/Libraries/LibWebView/WebContentPage.h b/Libraries/LibWebView/WebContentPage.h
index e8ba1b3420c..927fee235f3 100644
--- a/Libraries/LibWebView/WebContentPage.h
+++ b/Libraries/LibWebView/WebContentPage.h
@@ -159,7 +159,7 @@ public:
Optional<PresentedBackingStores> take_presented_backing_stores();
void release_presented_bitmap(i32 bitmap_id);
void fail_renderer_owned_downloads();
- void reset_session_history_for_testing();
+ void reset_state_for_testing();
private:
void relay_finished_input_event(WebContentPage const& reporting_page, u64 event_id, Web::EventResult);
@@ -372,7 +372,7 @@ private:
virtual void did_request_stop_loading_for_testing() override;
virtual void did_request_reload_for_testing(bool bypass_cache) override;
virtual void did_request_traverse_history_by_delta_for_testing(i32 delta) override;
- virtual void did_reset_session_history_for_testing(Web::HTML::SessionHistoryEntryDescriptor) override;
+ virtual void did_reset_state_for_testing(Web::HTML::SessionHistoryEntryDescriptor) override;
Messages::WebContentTestClient::DidRequestHasPopulatedDocumentForTestingResponse did_request_has_populated_document_for_testing(Web::HTML::CrossProcessId navigable_id) const;
Messages::WebContentTestClient::DidRequestCaptureSessionHistorySnapshotForTestingResponse did_request_capture_session_history_snapshot_for_testing();
Messages::WebContentTestClient::DidRequestRestoreSessionHistorySnapshotForTestingResponse did_request_restore_session_history_snapshot_for_testing();
diff --git a/Services/WebContent/TestConnection.cpp b/Services/WebContent/TestConnection.cpp
index d6db2697e77..246a4e85b83 100644
--- a/Services/WebContent/TestConnection.cpp
+++ b/Services/WebContent/TestConnection.cpp
@@ -4,6 +4,7 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
+#include <LibWeb/Compositor/RenderClock.h>
#include <LibWeb/HTML/LocalTraversableNavigable.h>
#include <WebContent/ConnectionFromClient.h>
#include <WebContent/PageClient.h>
@@ -29,15 +30,19 @@ void TestConnection::die()
{
}
-void TestConnection::reset_session_history_for_testing(Web::PageId page_id)
+void TestConnection::reset_state_for_testing(Web::PageId page_id)
{
m_client.dispatch_pending_messages();
if (auto page = m_client.page(page_id); page.has_value()) {
+ // A test that times out may never restore automatic rendering in its finally block. Both controls outlive
+ // the document, so restore them at the test boundary before acknowledging the reset.
+ Web::Compositor::RenderClock::the().set_manual_for_testing(false);
+ page->page().client().set_manual_rendering_opportunities(false);
as<Web::HTML::LocalTraversableNavigable>(*page->page().local_traversable()).reset_session_history_for_testing();
auto active_entry = page->page().local_traversable()->active_session_history_entry();
VERIFY(active_entry);
- async_did_reset_session_history_for_testing(page_id, Web::HTML::create_session_history_entry_descriptor(*active_entry));
+ async_did_reset_state_for_testing(page_id, Web::HTML::create_session_history_entry_descriptor(*active_entry));
}
}
diff --git a/Services/WebContent/TestConnection.h b/Services/WebContent/TestConnection.h
index 3cdd51d0763..dfc18b1cbbf 100644
--- a/Services/WebContent/TestConnection.h
+++ b/Services/WebContent/TestConnection.h
@@ -30,7 +30,7 @@ public:
private:
TestConnection(NonnullOwnPtr<IPC::Transport>, WebContent::ConnectionFromClient&);
- virtual void reset_session_history_for_testing(Web::PageId page_id) override;
+ virtual void reset_state_for_testing(Web::PageId page_id) override;
WebContent::ConnectionFromClient& m_client;
};
diff --git a/Services/WebContent/WebContentTestClient.ipc b/Services/WebContent/WebContentTestClient.ipc
index db3e671e23c..5ad724373c3 100644
--- a/Services/WebContent/WebContentTestClient.ipc
+++ b/Services/WebContent/WebContentTestClient.ipc
@@ -27,7 +27,7 @@ endpoint WebContentTestClient routed by Web::PageId page_id
did_request_reload_for_testing(Web::PageId page_id, bool bypass_cache) =|
did_request_traverse_history_by_delta_for_testing(Web::PageId page_id, i32 delta) =|
- did_reset_session_history_for_testing(Web::PageId page_id, Web::HTML::SessionHistoryEntryDescriptor active_entry) =|
+ did_reset_state_for_testing(Web::PageId page_id, Web::HTML::SessionHistoryEntryDescriptor active_entry) =|
[NotRouted] did_request_capture_session_history_snapshot_for_testing(Web::PageId page_id) => (bool captured)
[NotRouted] did_request_restore_session_history_snapshot_for_testing(Web::PageId page_id) => (bool restored)
[NotRouted] did_request_register_session_store_tab_for_testing(Web::PageId page_id) => (bool registered)
diff --git a/Services/WebContent/WebContentTestServer.ipc b/Services/WebContent/WebContentTestServer.ipc
index 790caea1d1d..f376c696689 100644
--- a/Services/WebContent/WebContentTestServer.ipc
+++ b/Services/WebContent/WebContentTestServer.ipc
@@ -2,5 +2,5 @@
endpoint WebContentTestServer
{
- reset_session_history_for_testing(Web::PageId page_id) =|
+ reset_state_for_testing(Web::PageId page_id) =|
}
diff --git a/Tests/LibWeb/test-web/CMakeLists.txt b/Tests/LibWeb/test-web/CMakeLists.txt
index 30619464a35..5d4c24d88ac 100644
--- a/Tests/LibWeb/test-web/CMakeLists.txt
+++ b/Tests/LibWeb/test-web/CMakeLists.txt
@@ -30,6 +30,13 @@ if (WIN32)
endif()
if (BUILD_TESTING)
+ add_test(
+ NAME LibWebManualRenderingReset
+ COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test-manual-rendering-reset.py
+ $<TARGET_FILE:test-web> ${LADYBIRD_SOURCE_DIR}
+ )
+ set_tests_properties(LibWebManualRenderingReset PROPERTIES TIMEOUT 240)
+
add_test(
NAME LibWeb
COMMAND $<TARGET_FILE:test-web> --python-executable ${Python3_EXECUTABLE} --per-test-timeout 120 -v -v
diff --git a/Tests/LibWeb/test-web/TestWebView.cpp b/Tests/LibWeb/test-web/TestWebView.cpp
index 8258ecbba43..a9a8bc8f5c4 100644
--- a/Tests/LibWeb/test-web/TestWebView.cpp
+++ b/Tests/LibWeb/test-web/TestWebView.cpp
@@ -57,9 +57,9 @@ void TestWebView::reset_geolocation_emulated_position()
geolocation_settings_changed();
}
-NonnullRefPtr<Core::Promise<Empty>> TestWebView::reset_session_history()
+NonnullRefPtr<Core::Promise<Empty>> TestWebView::reset_state_for_next_test()
{
- return WebView::ViewImplementation::reset_session_history_for_testing();
+ return WebView::ViewImplementation::reset_state_for_testing();
}
NonnullRefPtr<Core::Promise<RefPtr<Gfx::Bitmap const>>> TestWebView::take_screenshot()
diff --git a/Tests/LibWeb/test-web/TestWebView.h b/Tests/LibWeb/test-web/TestWebView.h
index b27012aa291..f3aeb2dbc95 100644
--- a/Tests/LibWeb/test-web/TestWebView.h
+++ b/Tests/LibWeb/test-web/TestWebView.h
@@ -27,7 +27,7 @@ public:
void reset_line_box_borders();
void reset_user_style();
void reset_geolocation_emulated_position();
- NonnullRefPtr<Core::Promise<Empty>> reset_session_history();
+ NonnullRefPtr<Core::Promise<Empty>> reset_state_for_next_test();
NonnullRefPtr<Core::Promise<RefPtr<Gfx::Bitmap const>>> take_screenshot();
diff --git a/Tests/LibWeb/test-web/main.cpp b/Tests/LibWeb/test-web/main.cpp
index d76b6bafe97..2d3906ec5be 100644
--- a/Tests/LibWeb/test-web/main.cpp
+++ b/Tests/LibWeb/test-web/main.cpp
@@ -951,7 +951,7 @@ static void run_test(TestWebView& view, TestRunContext& context, size_t test_ind
view.on_test_finish = {};
promise->when_resolved([&view, test_index, &app, &context](auto) {
- view.reset_session_history()->when_resolved([&view, test_index, &app, &context](auto) {
+ view.reset_state_for_next_test()->when_resolved([&view, test_index, &app, &context](auto) {
auto& test = context.tests[test_index];
test.did_start_test = true;
diff --git a/Tests/LibWeb/test-web/test-manual-rendering-reset.py b/Tests/LibWeb/test-web/test-manual-rendering-reset.py
new file mode 100644
index 00000000000..0775bac2b9d
--- /dev/null
+++ b/Tests/LibWeb/test-web/test-manual-rendering-reset.py
@@ -0,0 +1,102 @@
+#!/usr/bin/env python3
+#
+# Copyright (c) 2026-present, the Ladybird developers.
+#
+# SPDX-License-Identifier: BSD-2-Clause
+
+import argparse
+import os
+import re
+import shutil
+import subprocess
+import sys
+import tempfile
+
+from pathlib import Path
+
+
+def run_case(binary, source, root, name, manual, timeout):
+ root = root / name
+ for directory in ("Accessibility", "Layout", "Text", "Ref", "Screenshot"):
+ for kind in ("input", "expected"):
+ (root / directory / kind).mkdir(parents=True)
+ (root / "Crash").mkdir()
+ (root / "TestConfig.ini").write_text("")
+ (root / "Fixtures").symlink_to(source / "Tests/LibWeb/Fixtures", target_is_directory=True)
+ (root / "test-web").symlink_to(source / "Tests/LibWeb/test-web", target_is_directory=True)
+ (root / "Text/input/wpt-import").mkdir()
+ shutil.copyfile(source / "Tests/LibWeb/Text/input/include.js", root / "Text/input/include.js")
+ finish = "internals.setTestTimeout(100);" if timeout else 'println("armed"); done();'
+ (root / "Text/input/poison.html").write_text(
+ '<!doctype html><script src="include.js"></script><script>asyncTest(done => {'
+ 'console.log("MANUAL_RESET_POISON");'
+ f"internals.setManualRenderingOpportunities({str(manual).lower()}); {finish}"
+ "});</script>"
+ )
+ (root / "Text/expected/poison.txt").write_text("" if timeout else "armed\n")
+ # Text tests precede reference tests. At -j1 these two files use the same view, without relying on directory order.
+ (root / "Ref/input/consumer.html").write_text(
+ '<!doctype html><html class="reftest-wait">'
+ '<link rel="match" href="../expected/green.html">'
+ "<style>html,body{margin:0;background:green}</style>"
+ '<script>console.log("MANUAL_RESET_CONSUMER");'
+ 'requestAnimationFrame(() => document.documentElement.classList.remove("reftest-wait"));'
+ "</script></html>"
+ )
+ (root / "Ref/expected/green.html").write_text("<!doctype html><style>html,body{margin:0;background:green}</style>")
+ results = root / "results"
+ env = os.environ.copy()
+ env["LADYBIRD_SOURCE_DIR"] = str(source)
+ # The echo server imports its vendored tools even though these fixtures use only file URLs. Keep those tools
+ # outside the private input tree so test discovery cannot collect their own HTML fixtures.
+ wpt = source / "Tests/LibWeb/Text/input/wpt-import"
+ env["PYTHONPATH"] = os.pathsep.join((str(wpt), str(wpt / "_wpttools")))
+ process = subprocess.run(
+ [
+ str(binary),
+ "--test-path",
+ str(root),
+ "-j1",
+ "-v",
+ "-v",
+ "--per-test-timeout",
+ "30",
+ "--python-executable",
+ sys.executable,
+ "--results-dir",
+ str(results),
+ ],
+ env=env,
+ stdout=subprocess.PIPE,
+ stderr=subprocess.STDOUT,
+ text=True,
+ timeout=100,
+ )
+ print(f"{name}:\n{process.stdout}", flush=True)
+ # A deadline deliberately completes only the first fixture in the timeout case. It never synchronizes a frame.
+ assert process.returncode == int(timeout), f"{name}: unexpected exit status {process.returncode}"
+ status = dict(
+ line.split(": ", 1) for line in (results / "harness-status.txt").read_text().splitlines() if ": " in line
+ )
+ assert status["completed"] == "2/2" and status["remaining"] == "0", status
+ assert status["pass"] == str(2 - int(timeout)), status
+ assert status["timeout"] == str(int(timeout)) and status["fail"] == "0" and status["crashed"] == "0", status
+ processes = re.findall(r"WebContent\((\d+)\).*MANUAL_RESET_(POISON|CONSUMER)", process.stdout)
+ assert len(processes) == 2 and processes[0][1] == "POISON" and processes[1][1] == "CONSUMER", processes
+ assert processes[0][0] == processes[1][0], f"{name}: WebContent was not reused: {processes}"
+
+
+def main():
+ parser = argparse.ArgumentParser()
+ parser.add_argument("test_web", type=Path)
+ parser.add_argument("source", type=Path)
+ args = parser.parse_args()
+ with tempfile.TemporaryDirectory(prefix="test-web-manual-reset-") as temporary:
+ root = Path(temporary)
+ run_case(args.test_web.resolve(), args.source.resolve(), root, "control", False, False)
+ run_case(args.test_web.resolve(), args.source.resolve(), root, "normal-completion", True, False)
+ run_case(args.test_web.resolve(), args.source.resolve(), root, "timeout", True, True)
+
+
+if __name__ == "__main__":
+ main()