Skip to content

Truly independent web browser

Tests/LibWeb: Remove TestDownloadReader

Andreas Kling34f4910024a0
diff --git a/Tests/LibWeb/CMakeLists.txt b/Tests/LibWeb/CMakeLists.txt
index 8095350ead1..c4443c9f19d 100644
--- a/Tests/LibWeb/CMakeLists.txt
+++ b/Tests/LibWeb/CMakeLists.txt
@@ -20,7 +20,6 @@ set(TEST_SOURCES
TestCSSIDSpeed.cpp
TestCSSInheritedProperty.cpp
TestCSSPropertyList.cpp
- TestDownloadReader.cpp
TestDump.cpp
TestEventLoop.cpp
TestFaviconDecoding.cpp
diff --git a/Tests/LibWeb/TestDownloadReader.cpp b/Tests/LibWeb/TestDownloadReader.cpp
deleted file mode 100644
index 380765231a7..00000000000
--- a/Tests/LibWeb/TestDownloadReader.cpp
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
- * Copyright (c) 2026-present, the Ladybird developers.
- *
- * SPDX-License-Identifier: BSD-2-Clause
- */
-
-#include <LibTest/TestCase.h>
-#include <LibWeb/Bindings/MainThreadVM.h>
-#include <LibWeb/Bindings/PrincipalHostDefined.h>
-#include <LibWeb/Fetch/Infrastructure/HTTP/Bodies.h>
-#include <LibWeb/Fetch/Infrastructure/HTTP/ResponseView.h>
-#include <LibWeb/HTML/LocalTraversableNavigable.h>
-#include <LibWeb/Page/Page.h>
-#include <LibWeb/Platform/FontPlugin.h>
-#include <LibWeb/Streams/ReadableStreamDefaultReader.h>
-
-namespace {
-
-class TestPageClient final : public Web::PageClient {
- GC_CELL(TestPageClient, Web::PageClient);
- GC_DECLARE_ALLOCATOR(TestPageClient);
-
-public:
- virtual Web::PageId id() const override { return Web::PageId { 1 }; }
- virtual Web::Page& page() override { return *m_page; }
- virtual Web::Page const& page() const override { return *m_page; }
- virtual bool is_connection_open() const override { return true; }
- virtual Gfx::Palette palette() const override { VERIFY_NOT_REACHED(); }
- virtual Web::DevicePixelRect screen_rect() const override { return {}; }
- virtual double zoom_level() const override { return 1; }
- virtual double device_pixel_ratio() const override { return 1; }
- virtual double device_pixels_per_css_pixel() const override { return 1; }
- virtual Web::CSS::PreferredColorScheme preferred_color_scheme() const override { return Web::CSS::PreferredColorScheme::Auto; }
- virtual Web::CSS::PreferredContrast preferred_contrast() const override { return Web::CSS::PreferredContrast::Auto; }
- virtual Web::CSS::PreferredMotion preferred_motion() const override { return Web::CSS::PreferredMotion::NoPreference; }
- virtual size_t screen_count() const override { return 1; }
- virtual Queue<Web::QueuedInputEvent>& input_event_queue() override { VERIFY_NOT_REACHED(); }
- virtual void report_finished_handling_input_event(Web::PageId, u64, Web::EventResult) override { }
- virtual Web::HTML::CrossProcessId allocate_cross_process_id() override { return { 1, m_next_cross_process_id++ }; }
- virtual void request_frame() override { }
- virtual void request_file(Web::FileRequest) override { }
- virtual bool is_headless() const override { return true; }
-
- virtual Optional<u64> page_did_start_download(URL::URL const&, ByteString const&, Optional<u64>) override
- {
- return 42;
- }
-
- virtual void page_did_register_download_reader(u64 download_id, GC::Ref<Web::Streams::ReadableStreamDefaultReader> reader) override
- {
- m_registered_download_id = download_id;
- m_download_reader = reader;
- }
-
- virtual void visit_edges(Visitor& visitor) override
- {
- Base::visit_edges(visitor);
- visitor.visit(m_page);
- visitor.visit(m_download_reader);
- }
-
- GC::Ptr<Web::Page> m_page;
- GC::Ptr<Web::Streams::ReadableStreamDefaultReader> m_download_reader;
- Optional<u64> m_registered_download_id;
- u64 m_next_cross_process_id { 1 };
-};
-
-GC_DEFINE_ALLOCATOR(TestPageClient);
-
-}
-
-TEST_CASE(download_reader_is_registered_with_page_client)
-{
- Web::Platform::FontPlugin font_plugin(false);
- Web::Platform::FontPlugin::install(font_plugin);
-
- auto realm = Web::Bindings::create_a_principal_javascript_realm();
- auto& vm = Web::Bindings::main_thread_vm();
- auto client = vm.heap().allocate<TestPageClient>();
- auto page = Web::Page::create(client);
- client->m_page = page.ptr();
-
- auto traversable = Web::HTML::LocalTraversableNavigable::create_a_new_top_level_traversable(page, nullptr, {});
- page->set_top_level_traversable(traversable);
-
- auto response = Web::Fetch::Infrastructure::Response::create();
- response->set_body(Web::Fetch::Infrastructure::byte_sequence_as_response_body("download contents"sv.bytes()));
- traversable->handle_as_a_download(Web::Fetch::Infrastructure::ResponseView::create(*realm, response), URL::about_blank(), nullptr, "download.txt", {});
-
- EXPECT(client->m_registered_download_id.has_value());
- if (!client->m_registered_download_id.has_value())
- return;
- EXPECT_EQ(client->m_registered_download_id.value(), 42u);
- EXPECT(client->m_download_reader);
-}