From f8031df73cb06c7f541f58b6e353483360d275da Mon Sep 17 00:00:00 2001 From: Charlie Wolfe Date: Mon, 28 Oct 2024 10:52:51 -0700 Subject: [PATCH] Fix `testRunner.clearBackForwardList` for site isolation and remove `WKBundleClearHistoryForTesting` https://bugs.webkit.org/show_bug.cgi?id=282143 rdar://138709373 Reviewed by Alex Christensen. Cached back forward list counts need to be updated for all web processes. * LayoutTests/fast/dom/location-hash.html: * LayoutTests/fast/events/backspace-navigates-back.html: * LayoutTests/fast/history/history-length.html: * LayoutTests/fast/loader/stateobjects/document-destroyed-navigate-back-with-fragment-scroll.html: * LayoutTests/fast/loader/stateobjects/pushstate-with-fragment-urls-and-hashchange.html: * LayoutTests/fast/loader/stateobjects/replacestate-then-pushstate.html: * LayoutTests/http/tests/loading/state-object-security-exception.html: * Source/WebKit/UIProcess/API/C/WKPage.cpp: (WKPageClearBackForwardListForTesting): * Source/WebKit/UIProcess/API/C/WKPagePrivate.h: * Source/WebKit/UIProcess/WebPageProxy.cpp: (WebKit::WebPageProxy::backForwardClear): Deleted. * Source/WebKit/UIProcess/WebPageProxy.h: * Source/WebKit/UIProcess/WebPageProxy.messages.in: * Source/WebKit/UIProcess/WebPageProxyTesting.cpp: (WebKit::WebPageProxyTesting::clearBackForwardList): * Source/WebKit/UIProcess/WebPageProxyTesting.h: * Source/WebKit/WebProcess/InjectedBundle/API/c/WKBundlePage.cpp: (WKBundleClearHistoryForTesting): Deleted. * Source/WebKit/WebProcess/InjectedBundle/API/c/WKBundlePage.h: * Source/WebKit/WebProcess/WebPage/WebBackForwardListProxy.cpp: (WebKit::WebBackForwardListProxy::addItem): (WebKit::WebBackForwardListProxy::clearCachedListCounts): (WebKit::WebBackForwardListProxy::clear): Deleted. * Source/WebKit/WebProcess/WebPage/WebBackForwardListProxy.h: * Source/WebKit/WebProcess/WebPage/WebPage.cpp: (WebKit::WebPage::clearHistory): Deleted. * Source/WebKit/WebProcess/WebPage/WebPage.h: * Source/WebKit/WebProcess/WebPage/WebPageTesting.cpp: (WebKit::WebPageTesting::clearCachedBackForwardListCounts): * Source/WebKit/WebProcess/WebPage/WebPageTesting.h: * Source/WebKit/WebProcess/WebPage/WebPageTesting.messages.in: * Tools/WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl: * Tools/WebKitTestRunner/InjectedBundle/InjectedBundlePage.cpp: (WTR::InjectedBundlePage::prepare): * Tools/WebKitTestRunner/InjectedBundle/TestRunner.cpp: (WTR::TestRunner::clearBackForwardList): * Tools/WebKitTestRunner/InjectedBundle/TestRunner.h: * Tools/WebKitTestRunner/TestController.cpp: (WTR::TestController::resetStateToConsistentValues): (WTR::TestController::didReceiveAsyncMessageFromInjectedBundle): Canonical link: https://commits.webkit.org/285775@main --- LayoutTests/fast/dom/location-hash.html | 4 ++-- .../fast/events/backspace-navigates-back.html | 4 ++-- LayoutTests/fast/history/history-length.html | 4 ++-- ...troyed-navigate-back-with-fragment-scroll.html | 15 ++++++--------- ...shstate-with-fragment-urls-and-hashchange.html | 8 +++----- .../stateobjects/replacestate-then-pushstate.html | 14 ++++++-------- .../loading/state-object-security-exception.html | 12 +++++------- Source/WebKit/UIProcess/API/C/WKPage.cpp | 11 +++++++++++ Source/WebKit/UIProcess/API/C/WKPagePrivate.h | 2 ++ Source/WebKit/UIProcess/WebPageProxy.cpp | 5 ----- Source/WebKit/UIProcess/WebPageProxy.h | 1 - Source/WebKit/UIProcess/WebPageProxy.messages.in | 1 - Source/WebKit/UIProcess/WebPageProxyTesting.cpp | 12 ++++++++++++ Source/WebKit/UIProcess/WebPageProxyTesting.h | 3 +++ .../InjectedBundle/API/c/WKBundlePage.cpp | 5 ----- .../InjectedBundle/API/c/WKBundlePage.h | 1 - .../WebPage/WebBackForwardListProxy.cpp | 10 ++-------- .../WebProcess/WebPage/WebBackForwardListProxy.h | 3 +-- Source/WebKit/WebProcess/WebPage/WebPage.cpp | 8 -------- Source/WebKit/WebProcess/WebPage/WebPage.h | 1 - .../WebKit/WebProcess/WebPage/WebPageTesting.cpp | 12 ++++++++++++ Source/WebKit/WebProcess/WebPage/WebPageTesting.h | 1 + .../WebProcess/WebPage/WebPageTesting.messages.in | 1 + .../InjectedBundle/Bindings/TestRunner.idl | 2 +- .../InjectedBundle/InjectedBundlePage.cpp | 2 -- .../InjectedBundle/TestRunner.cpp | 4 ++-- .../WebKitTestRunner/InjectedBundle/TestRunner.h | 2 +- Tools/WebKitTestRunner/TestController.cpp | 7 ++++++- 28 files changed, 81 insertions(+), 74 deletions(-) diff --git a/LayoutTests/fast/dom/location-hash.html b/LayoutTests/fast/dom/location-hash.html index b0f1d0db6d4e4..f323a196ec181 100644 --- a/LayoutTests/fast/dom/location-hash.html +++ b/LayoutTests/fast/dom/location-hash.html @@ -90,11 +90,11 @@ setTimeout(step, 0); } - function runTests() { + async function runTests() { if (window.testRunner) { - testRunner.clearBackForwardList(); testRunner.dumpAsText(); testRunner.waitUntilDone(); + await testRunner.clearBackForwardList(); } state = 0; diff --git a/LayoutTests/fast/events/backspace-navigates-back.html b/LayoutTests/fast/events/backspace-navigates-back.html index 6a50f3195f930..5aed4be6fecf2 100644 --- a/LayoutTests/fast/events/backspace-navigates-back.html +++ b/LayoutTests/fast/events/backspace-navigates-back.html @@ -83,7 +83,7 @@ } } -window.onpageshow = function() { +window.onpageshow = async function() { if (!window.testRunner || !window.eventSender || !window.internals) { log.innerText = 'This test requires eventSender, testRunner and window.internals. ' + @@ -93,8 +93,8 @@ if (!location.search) { sessionStorage.step = 0; testRunner.dumpAsText(); - testRunner.clearBackForwardList(); testRunner.waitUntilDone(); + await testRunner.clearBackForwardList(); } setTimeout(function() { diff --git a/LayoutTests/fast/history/history-length.html b/LayoutTests/fast/history/history-length.html index 8c92c6f516c3a..f4ca9467808b1 100644 --- a/LayoutTests/fast/history/history-length.html +++ b/LayoutTests/fast/history/history-length.html @@ -1,11 +1,11 @@ diff --git a/Source/WebKit/UIProcess/API/C/WKPage.cpp b/Source/WebKit/UIProcess/API/C/WKPage.cpp index c534a4480dbf8..747f73e265fd9 100644 --- a/Source/WebKit/UIProcess/API/C/WKPage.cpp +++ b/Source/WebKit/UIProcess/API/C/WKPage.cpp @@ -3346,3 +3346,14 @@ void WKPageSetPageScaleFactorForTesting(WKPageRef pageRef, float scaleFactor, WK completionHandler(context); }); } + +void WKPageClearBackForwardListForTesting(WKPageRef pageRef, void* context, WKPageClearBackForwardListForTestingFunction completionHandler) +{ + RefPtr pageForTesting = toImpl(pageRef)->pageForTesting(); + if (!pageForTesting) + return completionHandler(context); + + pageForTesting->clearBackForwardList([context, completionHandler] { + completionHandler(context); + }); +} diff --git a/Source/WebKit/UIProcess/API/C/WKPagePrivate.h b/Source/WebKit/UIProcess/API/C/WKPagePrivate.h index 4ee0b519e6b77..fdd18fdcba4f5 100644 --- a/Source/WebKit/UIProcess/API/C/WKPagePrivate.h +++ b/Source/WebKit/UIProcess/API/C/WKPagePrivate.h @@ -229,6 +229,8 @@ typedef void (*WKPageSetTopContentInsetForTestingFunction)(void* functionContext WK_EXPORT void WKPageSetTopContentInsetForTesting(WKPageRef page, float contentInset, void* context, WKPageSetTopContentInsetForTestingFunction callback); typedef void (*WKPageSetPageScaleFactorForTestingFunction)(void* functionContext); WK_EXPORT void WKPageSetPageScaleFactorForTesting(WKPageRef page, float scaleFactor, WKPoint point, void* context, WKPageSetPageScaleFactorForTestingFunction completionHandler); +typedef void (*WKPageClearBackForwardListForTestingFunction)(void* functionContext); +WK_EXPORT void WKPageClearBackForwardListForTesting(WKPageRef page, void* context, WKPageClearBackForwardListForTestingFunction completionHandler); #ifdef __cplusplus } #endif diff --git a/Source/WebKit/UIProcess/WebPageProxy.cpp b/Source/WebKit/UIProcess/WebPageProxy.cpp index 2abace4adb4c1..319ac56fb0fd1 100644 --- a/Source/WebKit/UIProcess/WebPageProxy.cpp +++ b/Source/WebKit/UIProcess/WebPageProxy.cpp @@ -11402,11 +11402,6 @@ void WebPageProxy::updateAcceleratedCompositingMode(const LayerTreeContext& laye pageClient->updateAcceleratedCompositingMode(layerTreeContext); } -void WebPageProxy::backForwardClear() -{ - protectedBackForwardList()->clear(); -} - #if ENABLE(GAMEPAD) void WebPageProxy::gamepadActivity(const Vector>& gamepadDatas, EventMakesGamepadsVisible eventVisibility) diff --git a/Source/WebKit/UIProcess/WebPageProxy.h b/Source/WebKit/UIProcess/WebPageProxy.h index 1c6787c771977..710273021649b 100644 --- a/Source/WebKit/UIProcess/WebPageProxy.h +++ b/Source/WebKit/UIProcess/WebPageProxy.h @@ -2813,7 +2813,6 @@ class WebPageProxy final : public API::ObjectImpl, publ void backForwardListContainsItem(const WebCore::BackForwardItemIdentifier&, CompletionHandler&&); void backForwardItemAtIndex(int32_t index, WebCore::FrameIdentifier, CompletionHandler&&)>&&); void backForwardListCounts(CompletionHandler&&); - void backForwardClear(); void backForwardGoToProvisionalItem(IPC::Connection&, WebCore::BackForwardItemIdentifier, CompletionHandler&&); void backForwardClearProvisionalItem(IPC::Connection&, WebCore::BackForwardItemIdentifier); diff --git a/Source/WebKit/UIProcess/WebPageProxy.messages.in b/Source/WebKit/UIProcess/WebPageProxy.messages.in index a1ad4a64dce1f..51f53c8879093 100644 --- a/Source/WebKit/UIProcess/WebPageProxy.messages.in +++ b/Source/WebKit/UIProcess/WebPageProxy.messages.in @@ -206,7 +206,6 @@ messages -> WebPageProxy { BackForwardItemAtIndex(int32_t itemIndex, WebCore::FrameIdentifier frameID) -> (RefPtr frameState) Synchronous BackForwardListContainsItem(WebCore::BackForwardItemIdentifier itemID) -> (bool contains) Synchronous BackForwardListCounts() -> (struct WebKit::WebBackForwardListCounts counts) Synchronous - BackForwardClear() WillGoToBackForwardListItem(WebCore::BackForwardItemIdentifier itemID, bool inBackForwardCache) BackForwardGoToProvisionalItem(WebCore::BackForwardItemIdentifier itemID) -> (struct WebKit::WebBackForwardListCounts counts) Synchronous BackForwardClearProvisionalItem(WebCore::BackForwardItemIdentifier itemID) diff --git a/Source/WebKit/UIProcess/WebPageProxyTesting.cpp b/Source/WebKit/UIProcess/WebPageProxyTesting.cpp index ab911e40b1c93..1d0762a797097 100644 --- a/Source/WebKit/UIProcess/WebPageProxyTesting.cpp +++ b/Source/WebKit/UIProcess/WebPageProxyTesting.cpp @@ -30,6 +30,7 @@ #include "MessageSenderInlines.h" #include "NetworkProcessMessages.h" #include "NetworkProcessProxy.h" +#include "WebBackForwardList.h" #include "WebFrameProxy.h" #include "WebPageMessages.h" #include "WebPageProxy.h" @@ -222,4 +223,15 @@ void WebPageProxyTesting::resetStateBetweenTests() }); } +void WebPageProxyTesting::clearBackForwardList(CompletionHandler&& completionHandler) +{ + Ref page = m_page.get(); + page->protectedBackForwardList()->clear(); + + Ref callbackAggregator = CallbackAggregator::create(WTFMove(completionHandler)); + page->forEachWebContentProcess([&](auto& webProcess, auto pageID) { + webProcess.sendWithAsyncReply(Messages::WebPageTesting::ClearCachedBackForwardListCounts(), [callbackAggregator] { }, pageID); + }); +} + } // namespace WebKit diff --git a/Source/WebKit/UIProcess/WebPageProxyTesting.h b/Source/WebKit/UIProcess/WebPageProxyTesting.h index 97956ce461858..5f5566e924111 100644 --- a/Source/WebKit/UIProcess/WebPageProxyTesting.h +++ b/Source/WebKit/UIProcess/WebPageProxyTesting.h @@ -78,6 +78,9 @@ class WebPageProxyTesting : public IPC::MessageSender, public RefCounted&&); + + void clearBackForwardList(CompletionHandler&&); + private: explicit WebPageProxyTesting(WebPageProxy&); diff --git a/Source/WebKit/WebProcess/InjectedBundle/API/c/WKBundlePage.cpp b/Source/WebKit/WebProcess/InjectedBundle/API/c/WKBundlePage.cpp index 3152e18df9618..1d1401189763e 100644 --- a/Source/WebKit/WebProcess/InjectedBundle/API/c/WKBundlePage.cpp +++ b/Source/WebKit/WebProcess/InjectedBundle/API/c/WKBundlePage.cpp @@ -362,11 +362,6 @@ WKStringRef WKBundlePageDumpHistoryForTesting(WKBundlePageRef page, WKStringRef return WebKit::toCopiedAPI(WebKit::toImpl(page)->dumpHistoryForTesting(WebKit::toWTFString(directory))); } -void WKBundleClearHistoryForTesting(WKBundlePageRef page) -{ - WebKit::toImpl(page)->clearHistory(); -} - WKBundleBackForwardListRef WKBundlePageGetBackForwardList(WKBundlePageRef pageRef) { return nullptr; diff --git a/Source/WebKit/WebProcess/InjectedBundle/API/c/WKBundlePage.h b/Source/WebKit/WebProcess/InjectedBundle/API/c/WKBundlePage.h index 5fe2b3693b5c3..e5d311ea36fb9 100644 --- a/Source/WebKit/WebProcess/InjectedBundle/API/c/WKBundlePage.h +++ b/Source/WebKit/WebProcess/InjectedBundle/API/c/WKBundlePage.h @@ -71,7 +71,6 @@ WK_EXPORT WKFrameHandleRef WKBundleFrameCreateFrameHandle(WKBundleFrameRef); WK_EXPORT WKBundleBackForwardListRef WKBundlePageGetBackForwardList(WKBundlePageRef page) WK_C_API_DEPRECATED; WK_EXPORT WKStringRef WKBundlePageDumpHistoryForTesting(WKBundlePageRef page, WKStringRef directory); -WK_EXPORT void WKBundleClearHistoryForTesting(WKBundlePageRef page); WK_EXPORT void WKBundlePageInstallPageOverlay(WKBundlePageRef page, WKBundlePageOverlayRef pageOverlay); WK_EXPORT void WKBundlePageUninstallPageOverlay(WKBundlePageRef page, WKBundlePageOverlayRef pageOverlay); diff --git a/Source/WebKit/WebProcess/WebPage/WebBackForwardListProxy.cpp b/Source/WebKit/WebProcess/WebPage/WebBackForwardListProxy.cpp index bee55dfefae86..9f86a4f347366 100644 --- a/Source/WebKit/WebProcess/WebPage/WebBackForwardListProxy.cpp +++ b/Source/WebKit/WebProcess/WebPage/WebBackForwardListProxy.cpp @@ -66,7 +66,7 @@ void WebBackForwardListProxy::addItem(FrameIdentifier targetFrameID, Refidentifier().toString().utf8().data(), item->urlString().utf8().data()); - clearCachedListCounts(); + m_cachedBackForwardListCounts = std::nullopt; page->send(Messages::WebPageProxy::BackForwardAddItem(targetFrameID, toFrameState(item.get()))); } @@ -152,7 +152,7 @@ const WebBackForwardListCounts& WebBackForwardListProxy::cacheListCountsIfNecess void WebBackForwardListProxy::clearCachedListCounts() { - m_cachedBackForwardListCounts = std::nullopt; + m_cachedBackForwardListCounts = WebBackForwardListCounts { }; } void WebBackForwardListProxy::close() @@ -162,10 +162,4 @@ void WebBackForwardListProxy::close() m_cachedBackForwardListCounts = WebBackForwardListCounts { }; } -void WebBackForwardListProxy::clear() -{ - m_cachedBackForwardListCounts = WebBackForwardListCounts { }; // Clearing the back/forward list will cause the counts to become 0. - m_page->send(Messages::WebPageProxy::BackForwardClear()); -} - } // namespace WebKit diff --git a/Source/WebKit/WebProcess/WebPage/WebBackForwardListProxy.h b/Source/WebKit/WebProcess/WebPage/WebBackForwardListProxy.h index 4c736640dc957..cd3b76a066058 100644 --- a/Source/WebKit/WebProcess/WebPage/WebBackForwardListProxy.h +++ b/Source/WebKit/WebProcess/WebPage/WebBackForwardListProxy.h @@ -41,7 +41,7 @@ class WebBackForwardListProxy : public WebCore::BackForwardClient { static void removeItem(const WebCore::BackForwardItemIdentifier&); - void clear(); + void clearCachedListCounts(); private: WebBackForwardListProxy(WebPage&); @@ -58,7 +58,6 @@ class WebBackForwardListProxy : public WebCore::BackForwardClient { unsigned forwardListCount() const override; bool containsItem(const WebCore::HistoryItem&) const final; const WebBackForwardListCounts& cacheListCountsIfNecessary() const; - void clearCachedListCounts(); void close() override; diff --git a/Source/WebKit/WebProcess/WebPage/WebPage.cpp b/Source/WebKit/WebProcess/WebPage/WebPage.cpp index b66d5cae693f3..e6746085494b2 100644 --- a/Source/WebKit/WebProcess/WebPage/WebPage.cpp +++ b/Source/WebKit/WebProcess/WebPage/WebPage.cpp @@ -2571,14 +2571,6 @@ String WebPage::frameTextForTestingIncludingSubframes(bool includeSubframes) return m_mainFrame->frameTextForTesting(includeSubframes); } -void WebPage::clearHistory() -{ - if (!m_page) - return; - - static_cast(m_page->backForward().client()).clear(); -} - void WebPage::windowScreenDidChange(PlatformDisplayID displayID, std::optional nominalFramesPerSecond) { m_page->chrome().windowScreenDidChange(displayID, nominalFramesPerSecond); diff --git a/Source/WebKit/WebProcess/WebPage/WebPage.h b/Source/WebKit/WebProcess/WebPage/WebPage.h index 1c76c40d24ea1..d412d7628a3ff 100644 --- a/Source/WebKit/WebProcess/WebPage/WebPage.h +++ b/Source/WebKit/WebProcess/WebPage/WebPage.h @@ -708,7 +708,6 @@ class WebPage final : public API::ObjectImpl, pub void didSetPageZoomFactor(double); void windowScreenDidChange(WebCore::PlatformDisplayID, std::optional nominalFramesPerSecond); String dumpHistoryForTesting(const String& directory); - void clearHistory(); void accessibilitySettingsDidChange(); #if PLATFORM(COCOA) diff --git a/Source/WebKit/WebProcess/WebPage/WebPageTesting.cpp b/Source/WebKit/WebProcess/WebPage/WebPageTesting.cpp index 39712f036e220..04a7629b87eb7 100644 --- a/Source/WebKit/WebProcess/WebPage/WebPageTesting.cpp +++ b/Source/WebKit/WebProcess/WebPage/WebPageTesting.cpp @@ -32,6 +32,7 @@ #include "WebPage.h" #include "WebPageTestingMessages.h" #include "WebProcess.h" +#include #include #include #include @@ -134,4 +135,15 @@ void WebPageTesting::resetStateBetweenTests() } } +void WebPageTesting::clearCachedBackForwardListCounts(CompletionHandler&& completionHandler) +{ + RefPtr page = m_page->corePage(); + if (!page) + return completionHandler(); + + Ref backForwardListProxy = static_cast(page->backForward().client()); + backForwardListProxy->clearCachedListCounts(); + completionHandler(); +} + } // namespace WebKit diff --git a/Source/WebKit/WebProcess/WebPage/WebPageTesting.h b/Source/WebKit/WebProcess/WebPage/WebPageTesting.h index c5a3f713132cb..67d5aa754d03d 100644 --- a/Source/WebKit/WebProcess/WebPage/WebPageTesting.h +++ b/Source/WebKit/WebProcess/WebPage/WebPageTesting.h @@ -54,6 +54,7 @@ class WebPageTesting : public IPC::MessageReceiver { void setPermissionLevel(const String& origin, bool allowed); void isEditingCommandEnabled(const String& commandName, CompletionHandler&&); void resetStateBetweenTests(); + void clearCachedBackForwardListCounts(CompletionHandler&&); #if ENABLE(NOTIFICATIONS) void clearNotificationPermissionState(); diff --git a/Source/WebKit/WebProcess/WebPage/WebPageTesting.messages.in b/Source/WebKit/WebProcess/WebPage/WebPageTesting.messages.in index 5ebcfb7542fb3..1075ecd7edcde 100644 --- a/Source/WebKit/WebProcess/WebPage/WebPageTesting.messages.in +++ b/Source/WebKit/WebProcess/WebPage/WebPageTesting.messages.in @@ -33,4 +33,5 @@ messages -> WebPageTesting NotRefCounted { ClearWheelEventTestMonitor() ResetStateBetweenTests() SetTopContentInset(float contentInset) -> () + ClearCachedBackForwardListCounts() -> () } diff --git a/Tools/WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl b/Tools/WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl index a977f5381d706..69e16e0c0ea6a 100644 --- a/Tools/WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl +++ b/Tools/WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl @@ -107,7 +107,7 @@ interface TestRunner { undefined stopLoading(); // Special DOM functions. - undefined clearBackForwardList(); + Promise clearBackForwardList(); undefined execCommand(DOMString name, DOMString showUI, DOMString value); boolean isCommandEnabled(DOMString name); unsigned long windowCount(); diff --git a/Tools/WebKitTestRunner/InjectedBundle/InjectedBundlePage.cpp b/Tools/WebKitTestRunner/InjectedBundle/InjectedBundlePage.cpp index 2ef80cb407abe..898b4cc346c17 100644 --- a/Tools/WebKitTestRunner/InjectedBundle/InjectedBundlePage.cpp +++ b/Tools/WebKitTestRunner/InjectedBundle/InjectedBundlePage.cpp @@ -350,8 +350,6 @@ InjectedBundlePage::~InjectedBundlePage() void InjectedBundlePage::prepare() { - WKBundleClearHistoryForTesting(m_page); - WKBundlePageSetTracksRepaints(m_page, false); } diff --git a/Tools/WebKitTestRunner/InjectedBundle/TestRunner.cpp b/Tools/WebKitTestRunner/InjectedBundle/TestRunner.cpp index 7db1ac20120f3..3b5f3f17a0afc 100644 --- a/Tools/WebKitTestRunner/InjectedBundle/TestRunner.cpp +++ b/Tools/WebKitTestRunner/InjectedBundle/TestRunner.cpp @@ -484,9 +484,9 @@ unsigned TestRunner::windowCount() return InjectedBundle::singleton().pageCount(); } -void TestRunner::clearBackForwardList() +void TestRunner::clearBackForwardList(JSContextRef context, JSValueRef callback) { - WKBundleClearHistoryForTesting(page()); + postMessageWithAsyncReply(context, "ClearBackForwardList", callback); } void TestRunner::makeWindowObject(JSContextRef context) diff --git a/Tools/WebKitTestRunner/InjectedBundle/TestRunner.h b/Tools/WebKitTestRunner/InjectedBundle/TestRunner.h index 76d493f2ddff9..c4bde4be57dbf 100644 --- a/Tools/WebKitTestRunner/InjectedBundle/TestRunner.h +++ b/Tools/WebKitTestRunner/InjectedBundle/TestRunner.h @@ -146,7 +146,7 @@ class TestRunner : public JSWrappable { void setCustomUserAgent(JSStringRef); // Special DOM functions. - void clearBackForwardList(); + void clearBackForwardList(JSContextRef, JSValueRef callback); void execCommand(JSStringRef name, JSStringRef showUI, JSStringRef value); bool isCommandEnabled(JSStringRef name); unsigned windowCount(); diff --git a/Tools/WebKitTestRunner/TestController.cpp b/Tools/WebKitTestRunner/TestController.cpp index 71370cd01eda0..65c25ae69ea93 100644 --- a/Tools/WebKitTestRunner/TestController.cpp +++ b/Tools/WebKitTestRunner/TestController.cpp @@ -1298,7 +1298,9 @@ bool TestController::resetStateToConsistentValues(const TestOptions& options, Re return false; } } - + + WKPageClearBackForwardListForTesting(TestController::singleton().mainWebView()->page(), nullptr, [](void*) { }); + if (resetStage == ResetStage::AfterTest) { updateLiveDocumentsAfterTest(); #if PLATFORM(COCOA) @@ -2191,6 +2193,9 @@ void TestController::didReceiveAsyncMessageFromInjectedBundle(WKStringRef messag if (WKStringIsEqualToUTF8CString(messageName, "SetTopContentInset")) return WKPageSetTopContentInsetForTesting(TestController::singleton().mainWebView()->page(), static_cast(doubleValue(messageBody)), completionHandler.leak(), adoptAndCallCompletionHandler); + if (WKStringIsEqualToUTF8CString(messageName, "ClearBackForwardList")) + return WKPageClearBackForwardListForTesting(TestController::singleton().mainWebView()->page(), completionHandler.leak(), adoptAndCallCompletionHandler); + ASSERT_NOT_REACHED(); }