Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: eaf77a3bea205399e1e83395b5b20cc2fac8f347
      
https://github.com/WebKit/WebKit/commit/eaf77a3bea205399e1e83395b5b20cc2fac8f347
  Author: Cole Carley <[email protected]>
  Date:   2026-07-09 (Thu, 09 Jul 2026)

  Changed paths:
    M Source/WebCore/CMakeLists.txt
    M Source/WebCore/Headers.cmake
    M Source/WebCore/WebCore.xcodeproj/project.pbxproj
    M Source/WebCore/editing/CachedMatchFinder.h
    M Source/WebCore/loader/DocumentWriter.h
    M Source/WebCore/page/LocalFrameView.h
    A Source/WebCore/testing/TestPage.cpp
    A Source/WebCore/testing/TestPage.h
    M Tools/TestWebKitAPI/CMakeLists.txt
    M Tools/TestWebKitAPI/PlatformMac.cmake
    M Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
    A Tools/TestWebKitAPI/Tests/WebCore/CachedMatchFinder.cpp
    A Tools/TestWebKitAPI/Tests/WebCore/TestPageHarness.h
    A Tools/TestWebKitAPI/Tests/WebCore/TestPlatformStrategies.cpp
    A Tools/TestWebKitAPI/Tests/WebCore/TestPlatformStrategies.h

  Log Message:
  -----------
  Add a test page for unit tests
https://bugs.webkit.org/show_bug.cgi?id=318499
rdar://181282877

Reviewed by Sammy Gill.

TestPageHarness creates a headless WebCore::Page (with a LocalFrame,
LocalFrameView, and Document) for unit testing WebCore code that
depends on layout, e.g. anything that needs a Document, Frame, or
Page to operate on.

Basic usage:

     auto testPage = TestPageHarness::create();
     testPage.loadHTML("<p>Hello, world.</p>"_s);
     SomeClassUnderTest instance(testPage.document());

By default, script, accelerated compositing, and media are disabled,
and the viewport is 800x600. Pass a WebCore::TestPageOptions to
override these settings.

Call loadHTML() again on an existing harness to load new content into
the same Page/Frame/Settings.

You can test behavior across multiple loads without paying for a new
Page each time.

Now, components/classes/functions that need a document, page, or
frame can effectively be unit tested.

This pattern should be used in place of exposing internal structures
via Internals.idl. This is quicker and more ergonomic than a layout
test in this case.

Tests: Tools/TestWebKitAPI/Tests/WebCore/TestPageExample.cpp
       Tools/TestWebKitAPI/Tests/WebCore/TestPageHarness.h
       Tools/TestWebKitAPI/Tests/WebCore/TestPlatformStrategies.cpp
       Tools/TestWebKitAPI/Tests/WebCore/TestPlatformStrategies.h

* Source/WebCore/CMakeLists.txt:
* Source/WebCore/Headers.cmake:
* Source/WebCore/WebCore.xcodeproj/project.pbxproj:
* Source/WebCore/editing/CachedMatchFinder.h:
* Source/WebCore/loader/DocumentWriter.h:
* Source/WebCore/page/LocalFrameView.h:
* Source/WebCore/testing/TestPage.cpp: Added.
(WebCore::createTestPage):
(WebCore::loadHTMLIntoTestPage):
* Source/WebCore/testing/TestPage.h: Added.
(WebCore::createTestPage):
* Tools/TestWebKitAPI/CMakeLists.txt:
* Tools/TestWebKitAPI/PlatformMac.cmake:
* Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* Tools/TestWebKitAPI/Tests/WebCore/CachedMatchFinder.cpp: Added.
(TestWebKitAPI::TEST(CachedMatchFinder, CountMatchesFindsMatches)):
* Tools/TestWebKitAPI/Tests/WebCore/TestPageHarness.h: Added.
(TestWebKitAPI::TestPageHarness::create):
(TestWebKitAPI::TestPageHarness::page):
(TestWebKitAPI::TestPageHarness::frame):
(TestWebKitAPI::TestPageHarness::document):
(TestWebKitAPI::TestPageHarness::loadHTML):
(TestWebKitAPI::TestPageHarness::TestPageHarness):
* Tools/TestWebKitAPI/Tests/WebCore/TestPlatformStrategies.cpp: Added.
(TestWebKitAPI::ensureTestPlatformStrategiesInstalled):
* Tools/TestWebKitAPI/Tests/WebCore/TestPlatformStrategies.h: Added.

Canonical link: https://commits.webkit.org/316845@main



To unsubscribe from these emails, change your notification settings at 
https://github.com/WebKit/WebKit/settings/notifications

Reply via email to