Skip to content

Commit

Permalink
Fix testRunner.clearBackForwardList for site isolation and remove `…
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
charliewolfe committed Oct 28, 2024
1 parent 3af977b commit f8031df
Show file tree
Hide file tree
Showing 28 changed files with 81 additions and 74 deletions.
4 changes: 2 additions & 2 deletions LayoutTests/fast/dom/location-hash.html
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions LayoutTests/fast/events/backspace-navigates-back.html
Original file line number Diff line number Diff line change
Expand Up @@ -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. ' +
Expand All @@ -93,8 +93,8 @@
if (!location.search) {
sessionStorage.step = 0;
testRunner.dumpAsText();
testRunner.clearBackForwardList();
testRunner.waitUntilDone();
await testRunner.clearBackForwardList();
}

setTimeout(function() {
Expand Down
4 changes: 2 additions & 2 deletions LayoutTests/fast/history/history-length.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<script>
onload = function() {
onload = async function() {
if (location.search.substring(1).length == 0) {
sessionStorage.testStage = 0;
if (window.testRunner) {
testRunner.dumpAsText();
testRunner.clearBackForwardList();
testRunner.waitUntilDone();
await testRunner.clearBackForwardList();
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
<html>
<head>
<script>

if (window.testRunner) {
if (!sessionStorage.stage)
testRunner.clearBackForwardList();
testRunner.dumpAsText();
testRunner.waitUntilDone();
}

function lastPathComponent(url)
{
return url.split('/').pop();
Expand Down Expand Up @@ -37,8 +29,13 @@
alert("Final stage of test loaded");
}

function runTest()
async function runTest()
{
testRunner?.dumpAsText();
testRunner?.waitUntilDone();
if (!sessionStorage.stage)
await testRunner?.clearBackForwardList();

alert("LOADED");
if (!sessionStorage.stage)
runFirstStageOfTest();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@
<head>
<script src="../../../resources/js-test.js"></script>
<script>

if (window.testRunner)
testRunner.clearBackForwardList();

function runTest()
async function runTest()
{
testRunner?.waitUntilDone();
await testRunner?.clearBackForwardList();
try {
history.pushState(null, null, 'some-other.html');
testFailed("history.pushState(null, null, 'some-other.html') didn't throw");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
<html>
<head>
<script>

if (window.testRunner) {
testRunner.clearBackForwardList();
testRunner.dumpAsText();
testRunner.waitUntilDone();
}

function log(txt)
{
document.getElementById("logger").innerText += txt + "\n";
}

function runTest()
async function runTest()
{
if (window.testRunner) {
testRunner.dumpAsText();
testRunner.waitUntilDone();
await testRunner.clearBackForwardList();
}
history.replaceState("OriginalHistoryItem", "Replaced title");
log("History length is " + history.length);
history.pushState("NewHistoryItem", "Pushed title");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
<html>
<head>
<script>

if (window.testRunner) {
testRunner.clearBackForwardList();
testRunner.dumpAsText();
}

function log(txt)
{
document.getElementById("logger").innerText += txt + "\n";
Expand Down Expand Up @@ -40,10 +34,14 @@
"file://anyfile.html/"
);

function runTest()
async function runTest()
{
testRunner?.dumpAsText();
testRunner?.waitUntilDone();
await testRunner?.clearBackForwardList();
for (n in URLsToTry)
tryURL(URLsToTry[n]);
testRunner?.notifyDone();
}

</script>
Expand Down
11 changes: 11 additions & 0 deletions Source/WebKit/UIProcess/API/C/WKPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}
2 changes: 2 additions & 0 deletions Source/WebKit/UIProcess/API/C/WKPagePrivate.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 0 additions & 5 deletions Source/WebKit/UIProcess/WebPageProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::optional<GamepadData>>& gamepadDatas, EventMakesGamepadsVisible eventVisibility)
Expand Down
1 change: 0 additions & 1 deletion Source/WebKit/UIProcess/WebPageProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -2813,7 +2813,6 @@ class WebPageProxy final : public API::ObjectImpl<API::Object::Type::Page>, publ
void backForwardListContainsItem(const WebCore::BackForwardItemIdentifier&, CompletionHandler<void(bool)>&&);
void backForwardItemAtIndex(int32_t index, WebCore::FrameIdentifier, CompletionHandler<void(RefPtr<FrameState>&&)>&&);
void backForwardListCounts(CompletionHandler<void(WebBackForwardListCounts&&)>&&);
void backForwardClear();
void backForwardGoToProvisionalItem(IPC::Connection&, WebCore::BackForwardItemIdentifier, CompletionHandler<void(const WebBackForwardListCounts&)>&&);
void backForwardClearProvisionalItem(IPC::Connection&, WebCore::BackForwardItemIdentifier);

Expand Down
1 change: 0 additions & 1 deletion Source/WebKit/UIProcess/WebPageProxy.messages.in
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,6 @@ messages -> WebPageProxy {
BackForwardItemAtIndex(int32_t itemIndex, WebCore::FrameIdentifier frameID) -> (RefPtr<WebKit::FrameState> 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)
Expand Down
12 changes: 12 additions & 0 deletions Source/WebKit/UIProcess/WebPageProxyTesting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -222,4 +223,15 @@ void WebPageProxyTesting::resetStateBetweenTests()
});
}

void WebPageProxyTesting::clearBackForwardList(CompletionHandler<void()>&& 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
3 changes: 3 additions & 0 deletions Source/WebKit/UIProcess/WebPageProxyTesting.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ class WebPageProxyTesting : public IPC::MessageSender, public RefCounted<WebPage
#endif

void setTopContentInset(float, CompletionHandler<void()>&&);

void clearBackForwardList(CompletionHandler<void()>&&);

private:
explicit WebPageProxyTesting(WebPageProxy&);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 2 additions & 8 deletions Source/WebKit/WebProcess/WebPage/WebBackForwardListProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ void WebBackForwardListProxy::addItem(FrameIdentifier targetFrameID, Ref<History
return;

LOG(BackForward, "(Back/Forward) WebProcess pid %i setting item %p for id %s with url %s", getCurrentProcessID(), item.ptr(), item->identifier().toString().utf8().data(), item->urlString().utf8().data());
clearCachedListCounts();
m_cachedBackForwardListCounts = std::nullopt;
page->send(Messages::WebPageProxy::BackForwardAddItem(targetFrameID, toFrameState(item.get())));
}

Expand Down Expand Up @@ -152,7 +152,7 @@ const WebBackForwardListCounts& WebBackForwardListProxy::cacheListCountsIfNecess

void WebBackForwardListProxy::clearCachedListCounts()
{
m_cachedBackForwardListCounts = std::nullopt;
m_cachedBackForwardListCounts = WebBackForwardListCounts { };
}

void WebBackForwardListProxy::close()
Expand All @@ -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
3 changes: 1 addition & 2 deletions Source/WebKit/WebProcess/WebPage/WebBackForwardListProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class WebBackForwardListProxy : public WebCore::BackForwardClient {

static void removeItem(const WebCore::BackForwardItemIdentifier&);

void clear();
void clearCachedListCounts();

private:
WebBackForwardListProxy(WebPage&);
Expand All @@ -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;

Expand Down
8 changes: 0 additions & 8 deletions Source/WebKit/WebProcess/WebPage/WebPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2571,14 +2571,6 @@ String WebPage::frameTextForTestingIncludingSubframes(bool includeSubframes)
return m_mainFrame->frameTextForTesting(includeSubframes);
}

void WebPage::clearHistory()
{
if (!m_page)
return;

static_cast<WebBackForwardListProxy&>(m_page->backForward().client()).clear();
}

void WebPage::windowScreenDidChange(PlatformDisplayID displayID, std::optional<unsigned> nominalFramesPerSecond)
{
m_page->chrome().windowScreenDidChange(displayID, nominalFramesPerSecond);
Expand Down
1 change: 0 additions & 1 deletion Source/WebKit/WebProcess/WebPage/WebPage.h
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,6 @@ class WebPage final : public API::ObjectImpl<API::Object::Type::BundlePage>, pub
void didSetPageZoomFactor(double);
void windowScreenDidChange(WebCore::PlatformDisplayID, std::optional<unsigned> nominalFramesPerSecond);
String dumpHistoryForTesting(const String& directory);
void clearHistory();

void accessibilitySettingsDidChange();
#if PLATFORM(COCOA)
Expand Down
12 changes: 12 additions & 0 deletions Source/WebKit/WebProcess/WebPage/WebPageTesting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "WebPage.h"
#include "WebPageTestingMessages.h"
#include "WebProcess.h"
#include <WebCore/BackForwardController.h>
#include <WebCore/Editor.h>
#include <WebCore/FocusController.h>
#include <WebCore/IntPoint.h>
Expand Down Expand Up @@ -134,4 +135,15 @@ void WebPageTesting::resetStateBetweenTests()
}
}

void WebPageTesting::clearCachedBackForwardListCounts(CompletionHandler<void()>&& completionHandler)
{
RefPtr page = m_page->corePage();
if (!page)
return completionHandler();

Ref backForwardListProxy = static_cast<WebBackForwardListProxy&>(page->backForward().client());
backForwardListProxy->clearCachedListCounts();
completionHandler();
}

} // namespace WebKit
1 change: 1 addition & 0 deletions Source/WebKit/WebProcess/WebPage/WebPageTesting.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class WebPageTesting : public IPC::MessageReceiver {
void setPermissionLevel(const String& origin, bool allowed);
void isEditingCommandEnabled(const String& commandName, CompletionHandler<void(bool)>&&);
void resetStateBetweenTests();
void clearCachedBackForwardListCounts(CompletionHandler<void()>&&);

#if ENABLE(NOTIFICATIONS)
void clearNotificationPermissionState();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,5 @@ messages -> WebPageTesting NotRefCounted {
ClearWheelEventTestMonitor()
ResetStateBetweenTests()
SetTopContentInset(float contentInset) -> ()
ClearCachedBackForwardListCounts() -> ()
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ interface TestRunner {
undefined stopLoading();

// Special DOM functions.
undefined clearBackForwardList();
Promise<undefined> clearBackForwardList();
undefined execCommand(DOMString name, DOMString showUI, DOMString value);
boolean isCommandEnabled(DOMString name);
unsigned long windowCount();
Expand Down
2 changes: 0 additions & 2 deletions Tools/WebKitTestRunner/InjectedBundle/InjectedBundlePage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -350,8 +350,6 @@ InjectedBundlePage::~InjectedBundlePage()

void InjectedBundlePage::prepare()
{
WKBundleClearHistoryForTesting(m_page);

WKBundlePageSetTracksRepaints(m_page, false);
}

Expand Down
4 changes: 2 additions & 2 deletions Tools/WebKitTestRunner/InjectedBundle/TestRunner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading

0 comments on commit f8031df

Please sign in to comment.