Diff
Modified: trunk/Source/WTF/ChangeLog (281069 => 281070)
--- trunk/Source/WTF/ChangeLog 2021-08-16 06:51:32 UTC (rev 281069)
+++ trunk/Source/WTF/ChangeLog 2021-08-16 06:55:58 UTC (rev 281070)
@@ -1,3 +1,16 @@
+2021-08-15 Miguel Gomez <[email protected]>
+
+ [GTK][WPE] Add API to pass WebKitMemoryPressureHandler parameters to the network processes
+ https://bugs.webkit.org/show_bug.cgi?id=228227
+
+ Reviewed by Carlos Garcia Campos.
+
+ Added a new method to MemoryPressureHandler to set the configuration by copying the parameter
+ instead of moving it.
+
+ * wtf/MemoryPressureHandler.h:
+ (WTF::MemoryPressureHandler::setConfiguration):
+
2021-08-11 Chris Dumez <[email protected]>
Add initial support for Cross-Origin-Embedder-Policy (COEP)
Modified: trunk/Source/WTF/wtf/MemoryPressureHandler.h (281069 => 281070)
--- trunk/Source/WTF/wtf/MemoryPressureHandler.h 2021-08-16 06:51:32 UTC (rev 281069)
+++ trunk/Source/WTF/wtf/MemoryPressureHandler.h 2021-08-16 06:55:58 UTC (rev 281070)
@@ -199,6 +199,7 @@
Seconds pollInterval;
};
void setConfiguration(Configuration&& configuration) { m_configuration = WTFMove(configuration); }
+ void setConfiguration(const Configuration& configuration) { m_configuration = configuration; }
WTF_EXPORT_PRIVATE void releaseMemory(Critical, Synchronous = Synchronous::No);
Modified: trunk/Source/WebKit/ChangeLog (281069 => 281070)
--- trunk/Source/WebKit/ChangeLog 2021-08-16 06:51:32 UTC (rev 281069)
+++ trunk/Source/WebKit/ChangeLog 2021-08-16 06:55:58 UTC (rev 281070)
@@ -1,3 +1,35 @@
+2021-08-15 Miguel Gomez <[email protected]>
+
+ [GTK][WPE] Add API to pass WebKitMemoryPressureHandler parameters to the network processes
+ https://bugs.webkit.org/show_bug.cgi?id=228227
+
+ Reviewed by Carlos Garcia Campos.
+
+ Added webkit_website_data_manager_set_memory_pressure_settings() API function to pass a
+ WebKitMemoryPressureSettings instance as the settings to use by all the network processes.
+
+ * NetworkProcess/NetworkProcessCreationParameters.cpp:
+ (WebKit::NetworkProcessCreationParameters::encode const):
+ (WebKit::NetworkProcessCreationParameters::decode):
+ * NetworkProcess/NetworkProcessCreationParameters.h:
+ * NetworkProcess/soup/NetworkProcessSoup.cpp:
+ (WebKit::NetworkProcess::platformInitializeNetworkProcess):
+ * UIProcess/API/glib/WebKitMemoryPressureSettings.cpp:
+ * UIProcess/API/glib/WebKitWebsiteDataManager.cpp:
+ (webkit_website_data_manager_set_memory_pressure_settings):
+ * UIProcess/API/gtk/WebKitWebsiteDataManager.h:
+ * UIProcess/API/gtk/docs/webkit2gtk-4.0-sections.txt:
+ * UIProcess/API/wpe/WebKitWebsiteDataManager.h:
+ * UIProcess/API/wpe/docs/wpe-1.0-sections.txt:
+ * UIProcess/Network/NetworkProcessProxy.cpp:
+ (WebKit::NetworkProcessProxy::didExceedMemoryLimit):
+ * UIProcess/Network/NetworkProcessProxy.h:
+ * UIProcess/Network/NetworkProcessProxy.messages.in:
+ * UIProcess/WebProcessPool.h:
+ * UIProcess/soup/WebProcessPoolSoup.cpp:
+ (WebKit::memoryPressureMonitorDisabled):
+ (WebKit::WebProcessPool::platformInitializeNetworkProcess):
+
2021-08-15 Wenson Hsieh <[email protected]>
[iOS 15] editing/selection/ios/select-all-in-readonly-input-does-not-overflow.html is a flaky timeout
Modified: trunk/Source/WebKit/NetworkProcess/NetworkProcessCreationParameters.cpp (281069 => 281070)
--- trunk/Source/WebKit/NetworkProcess/NetworkProcessCreationParameters.cpp 2021-08-16 06:51:32 UTC (rev 281069)
+++ trunk/Source/WebKit/NetworkProcess/NetworkProcessCreationParameters.cpp 2021-08-16 06:55:58 UTC (rev 281070)
@@ -62,6 +62,7 @@
#if USE(SOUP)
encoder << cookieAcceptPolicy;
encoder << languages;
+ encoder << memoryPressureHandlerConfiguration;
#endif
encoder << urlSchemesRegisteredAsSecure;
@@ -124,6 +125,12 @@
return false;
if (!decoder.decode(result.languages))
return false;
+
+ std::optional<std::optional<MemoryPressureHandler::Configuration>> memoryPressureHandlerConfiguration;
+ decoder >> memoryPressureHandlerConfiguration;
+ if (!memoryPressureHandlerConfiguration)
+ return false;
+ result.memoryPressureHandlerConfiguration = WTFMove(*memoryPressureHandlerConfiguration);
#endif
if (!decoder.decode(result.urlSchemesRegisteredAsSecure))
Modified: trunk/Source/WebKit/NetworkProcess/NetworkProcessCreationParameters.h (281069 => 281070)
--- trunk/Source/WebKit/NetworkProcess/NetworkProcessCreationParameters.h 2021-08-16 06:51:32 UTC (rev 281069)
+++ trunk/Source/WebKit/NetworkProcess/NetworkProcessCreationParameters.h 2021-08-16 06:55:58 UTC (rev 281070)
@@ -34,6 +34,7 @@
#if USE(SOUP)
#include <WebCore/HTTPCookieAcceptPolicy.h>
+#include <wtf/MemoryPressureHandler.h>
#endif
namespace IPC {
@@ -77,6 +78,7 @@
#if USE(SOUP)
WebCore::HTTPCookieAcceptPolicy cookieAcceptPolicy { WebCore::HTTPCookieAcceptPolicy::AlwaysAccept };
Vector<String> languages;
+ std::optional<MemoryPressureHandler::Configuration> memoryPressureHandlerConfiguration;
#endif
Vector<String> urlSchemesRegisteredAsSecure;
Modified: trunk/Source/WebKit/NetworkProcess/soup/NetworkProcessSoup.cpp (281069 => 281070)
--- trunk/Source/WebKit/NetworkProcess/soup/NetworkProcessSoup.cpp 2021-08-16 06:51:32 UTC (rev 281069)
+++ trunk/Source/WebKit/NetworkProcess/soup/NetworkProcessSoup.cpp 2021-08-16 06:55:58 UTC (rev 281070)
@@ -29,6 +29,7 @@
#include "NetworkCache.h"
#include "NetworkProcessCreationParameters.h"
+#include "NetworkProcessProxyMessages.h"
#include "NetworkSessionSoup.h"
#include "WebCookieManager.h"
#include "WebKitCachedResolver.h"
@@ -132,6 +133,20 @@
if (!parameters.languages.isEmpty())
userPreferredLanguagesChanged(parameters.languages);
+
+#if ENABLE(PERIODIC_MEMORY_MONITOR)
+ // The periodic memory monitor is disabled by default in the network process. Enable
+ // it only if MemoryPressureHandler is not suppressed and there is a custom configuration
+ // for it.
+ if (!parameters.shouldSuppressMemoryPressureHandler && parameters.memoryPressureHandlerConfiguration) {
+ auto& memoryPressureHandler = MemoryPressureHandler::singleton();
+ memoryPressureHandler.setConfiguration(*parameters.memoryPressureHandlerConfiguration);
+ memoryPressureHandler.setShouldUsePeriodicMemoryMonitor(true);
+ memoryPressureHandler.setMemoryKillCallback([this] () {
+ parentProcessConnection()->send(Messages::NetworkProcessProxy::DidExceedMemoryLimit(), 0);
+ });
+ }
+#endif
}
void NetworkProcess::setIgnoreTLSErrors(PAL::SessionID sessionID, bool ignoreTLSErrors)
Modified: trunk/Source/WebKit/UIProcess/API/glib/WebKitMemoryPressureSettings.cpp (281069 => 281070)
--- trunk/Source/WebKit/UIProcess/API/glib/WebKitMemoryPressureSettings.cpp 2021-08-16 06:51:32 UTC (rev 281069)
+++ trunk/Source/WebKit/UIProcess/API/glib/WebKitMemoryPressureSettings.cpp 2021-08-16 06:55:58 UTC (rev 281070)
@@ -26,7 +26,7 @@
* SECTION: WebKitMemoryPressureSettings
* @Short_description: A boxed type representing the settings for the MemoryPressureHandler
* @Title: WebKitMemoryPressureSettings
- * @See_also: #WebKitWebContext.
+ * @See_also: #WebKitWebContext, #WebKitWebsiteDataManager
*
* #WebKitMemoryPressureSettings is a boxed type that can be used to provide some custom settings
* to control how the memory pressure situations are handled by the different processes.
@@ -42,6 +42,10 @@
*
* A #WebKitMemoryPressureSettings can be passed to a #WebKitWebContext constructor, and the settings will
* be applied to all the web processes created by that context.
+ *
+ * A #WebKitMemoryPressureSettings can be passed to webkit_website_data_manager_set_memory_pressure_settings(),
+ * and the settings will be applied to all the network processes created after that call by any instance of
+ * #WebKitWebsiteDataManager.
*
* Since: 2.34
*/
Modified: trunk/Source/WebKit/UIProcess/API/glib/WebKitWebsiteDataManager.cpp (281069 => 281070)
--- trunk/Source/WebKit/UIProcess/API/glib/WebKitWebsiteDataManager.cpp 2021-08-16 06:51:32 UTC (rev 281069)
+++ trunk/Source/WebKit/UIProcess/API/glib/WebKitWebsiteDataManager.cpp 2021-08-16 06:55:58 UTC (rev 281070)
@@ -22,10 +22,13 @@
#include "WebKitCookieManagerPrivate.h"
#include "WebKitInitialize.h"
+#include "WebKitMemoryPressureSettings.h"
+#include "WebKitMemoryPressureSettingsPrivate.h"
#include "WebKitNetworkProxySettingsPrivate.h"
#include "WebKitPrivate.h"
#include "WebKitWebsiteDataManagerPrivate.h"
#include "WebKitWebsiteDataPrivate.h"
+#include "WebProcessPool.h"
#include "WebsiteDataFetchOption.h"
#include "WebsiteDataStore.h"
#include <glib/gi18n-lib.h>
@@ -1190,6 +1193,30 @@
int referenceCount { 1 };
};
+/**
+ * webkit_website_data_manager_set_memory_pressure_settings:
+ * @settings: a WebKitMemoryPressureSettings.
+ *
+ * Sets @settings as the #WebKitMemoryPressureSettings to be used by all the network
+ * processes created by any instance of #WebKitWebsiteDataManager after this function
+ * is called.
+ *
+ * Be sure to call this function before creating any #WebKitWebsiteDataManager, as network
+ * processes of existing instances are not guaranteed to receive the passed settings.
+ *
+ * The periodic check for used memory is disabled by default on network processes. This will
+ * be enabled only if custom settings have been set using this function. After that, in order
+ * to remove the custom settings and disable the periodic check, this function must be called
+ * passing %NULL as the value of @settings.
+ *
+ * Since: 2.34
+ */
+void webkit_website_data_manager_set_memory_pressure_settings(WebKitMemoryPressureSettings* settings)
+{
+ std::optional<MemoryPressureHandler::Configuration> config = settings ? std::make_optional(webkitMemoryPressureSettingsGetMemoryPressureHandlerConfiguration(settings)) : std::nullopt;
+ WebProcessPool::setNetworkProcessMemoryPressureHandlerConfiguration(config);
+}
+
G_DEFINE_BOXED_TYPE(WebKitITPFirstParty, webkit_itp_first_party, webkit_itp_first_party_ref, webkit_itp_first_party_unref)
static WebKitITPFirstParty* webkitITPFirstPartyCreate(WebResourceLoadStatisticsStore::ThirdPartyDataForSpecificFirstParty&& data)
Modified: trunk/Source/WebKit/UIProcess/API/gtk/WebKitWebsiteDataManager.h (281069 => 281070)
--- trunk/Source/WebKit/UIProcess/API/gtk/WebKitWebsiteDataManager.h 2021-08-16 06:51:32 UTC (rev 281069)
+++ trunk/Source/WebKit/UIProcess/API/gtk/WebKitWebsiteDataManager.h 2021-08-16 06:55:58 UTC (rev 281070)
@@ -27,6 +27,7 @@
#include <gio/gio.h>
#include <webkit2/WebKitCookieManager.h>
#include <webkit2/WebKitDefines.h>
+#include <webkit2/WebKitMemoryPressureSettings.h>
#include <webkit2/WebKitNetworkProxySettings.h>
#include <webkit2/WebKitWebsiteData.h>
@@ -183,7 +184,10 @@
GAsyncResult *result,
GError **error);
+WEBKIT_API void
+webkit_website_data_manager_set_memory_pressure_settings (WebKitMemoryPressureSettings *settings);
+
#define WEBKIT_TYPE_ITP_FIRST_PARTY (webkit_itp_first_party_get_type())
typedef struct _WebKitITPFirstParty WebKitITPFirstParty;
Modified: trunk/Source/WebKit/UIProcess/API/gtk/docs/webkit2gtk-4.0-sections.txt (281069 => 281070)
--- trunk/Source/WebKit/UIProcess/API/gtk/docs/webkit2gtk-4.0-sections.txt 2021-08-16 06:51:32 UTC (rev 281069)
+++ trunk/Source/WebKit/UIProcess/API/gtk/docs/webkit2gtk-4.0-sections.txt 2021-08-16 06:55:58 UTC (rev 281070)
@@ -1516,6 +1516,7 @@
webkit_website_data_manager_remove_finish
webkit_website_data_manager_clear
webkit_website_data_manager_clear_finish
+webkit_website_data_manager_set_memory_pressure_settings
<SUBSECTION ITP Summary>
WebKitITPFirstParty
Modified: trunk/Source/WebKit/UIProcess/API/wpe/WebKitWebsiteDataManager.h (281069 => 281070)
--- trunk/Source/WebKit/UIProcess/API/wpe/WebKitWebsiteDataManager.h 2021-08-16 06:51:32 UTC (rev 281069)
+++ trunk/Source/WebKit/UIProcess/API/wpe/WebKitWebsiteDataManager.h 2021-08-16 06:55:58 UTC (rev 281070)
@@ -27,6 +27,7 @@
#include <gio/gio.h>
#include <wpe/WebKitCookieManager.h>
#include <wpe/WebKitDefines.h>
+#include <wpe/WebKitMemoryPressureSettings.h>
#include <wpe/WebKitNetworkProxySettings.h>
#include <wpe/WebKitWebsiteData.h>
@@ -183,7 +184,10 @@
GAsyncResult *result,
GError **error);
+WEBKIT_API void
+webkit_website_data_manager_set_memory_pressure_settings (WebKitMemoryPressureSettings *settings);
+
#define WEBKIT_TYPE_ITP_FIRST_PARTY (webkit_itp_first_party_get_type())
typedef struct _WebKitITPFirstParty WebKitITPFirstParty;
Modified: trunk/Source/WebKit/UIProcess/API/wpe/docs/wpe-1.0-sections.txt (281069 => 281070)
--- trunk/Source/WebKit/UIProcess/API/wpe/docs/wpe-1.0-sections.txt 2021-08-16 06:51:32 UTC (rev 281069)
+++ trunk/Source/WebKit/UIProcess/API/wpe/docs/wpe-1.0-sections.txt 2021-08-16 06:55:58 UTC (rev 281070)
@@ -1450,6 +1450,7 @@
webkit_website_data_manager_remove_finish
webkit_website_data_manager_clear
webkit_website_data_manager_clear_finish
+webkit_website_data_manager_set_memory_pressure_settings
<SUBSECTION ITP Summary>
WebKitITPFirstParty
Modified: trunk/Source/WebKit/UIProcess/Network/NetworkProcessProxy.cpp (281069 => 281070)
--- trunk/Source/WebKit/UIProcess/Network/NetworkProcessProxy.cpp 2021-08-16 06:51:32 UTC (rev 281069)
+++ trunk/Source/WebKit/UIProcess/Network/NetworkProcessProxy.cpp 2021-08-16 06:55:58 UTC (rev 281070)
@@ -1590,6 +1590,16 @@
sendWithAsyncReply(Messages::NetworkProcess::ClearBundleIdentifier(), WTFMove(completionHandler));
}
+#if USE(SOUP)
+void NetworkProcessProxy::didExceedMemoryLimit()
+{
+ AuxiliaryProcessProxy::terminate();
+ if (auto* connection = this->connection())
+ connection->invalidate();
+ networkProcessDidTerminate(TerminationReason::ExceededMemoryLimit);
+}
+#endif
+
} // namespace WebKit
#undef MESSAGE_CHECK
Modified: trunk/Source/WebKit/UIProcess/Network/NetworkProcessProxy.h (281069 => 281070)
--- trunk/Source/WebKit/UIProcess/Network/NetworkProcessProxy.h 2021-08-16 06:51:32 UTC (rev 281069)
+++ trunk/Source/WebKit/UIProcess/Network/NetworkProcessProxy.h 2021-08-16 06:55:58 UTC (rev 281070)
@@ -236,7 +236,7 @@
void registerSchemeForLegacyCustomProtocol(const String&);
void unregisterSchemeForLegacyCustomProtocol(const String&);
- enum class TerminationReason { RequestedByClient, Crash };
+ enum class TerminationReason { RequestedByClient, Crash, ExceededMemoryLimit };
void networkProcessDidTerminate(TerminationReason);
void resetQuota(PAL::SessionID, CompletionHandler<void()>&&);
@@ -330,6 +330,10 @@
void processAuthenticationChallenge(PAL::SessionID, Ref<AuthenticationChallengeProxy>&&);
+#if USE(SOUP)
+ void didExceedMemoryLimit();
+#endif
+
std::unique_ptr<DownloadProxyMap> m_downloadProxyMap;
UniqueRef<API::CustomProtocolManagerClient> m_customProtocolManagerClient;
Modified: trunk/Source/WebKit/UIProcess/Network/NetworkProcessProxy.messages.in (281069 => 281070)
--- trunk/Source/WebKit/UIProcess/Network/NetworkProcessProxy.messages.in 2021-08-16 06:51:32 UTC (rev 281069)
+++ trunk/Source/WebKit/UIProcess/Network/NetworkProcessProxy.messages.in 2021-08-16 06:55:58 UTC (rev 281070)
@@ -72,4 +72,8 @@
ResourceLoadDidReceiveChallenge(WebKit::WebPageProxyIdentifier pageIdentifier, struct WebKit::ResourceLoadInfo resourceLoadInfo, WebCore::AuthenticationChallenge challenge)
ResourceLoadDidReceiveResponse(WebKit::WebPageProxyIdentifier pageIdentifier, struct WebKit::ResourceLoadInfo resourceLoadInfo, WebCore::ResourceResponse response)
ResourceLoadDidCompleteWithError(WebKit::WebPageProxyIdentifier pageIdentifier, struct WebKit::ResourceLoadInfo resourceLoadInfo, WebCore::ResourceResponse response, WebCore::ResourceError error)
+
+#if USE(SOUP)
+ DidExceedMemoryLimit()
+#endif
}
Modified: trunk/Source/WebKit/UIProcess/WebProcessPool.h (281069 => 281070)
--- trunk/Source/WebKit/UIProcess/WebProcessPool.h 2021-08-16 06:51:32 UTC (rev 281069)
+++ trunk/Source/WebKit/UIProcess/WebProcessPool.h 2021-08-16 06:55:58 UTC (rev 281070)
@@ -280,6 +280,7 @@
#if USE(SOUP)
void setInitialHTTPCookieAcceptPolicy(WebCore::HTTPCookieAcceptPolicy policy) { m_initialHTTPCookieAcceptPolicy = policy; }
+ static void setNetworkProcessMemoryPressureHandlerConfiguration(const std::optional<MemoryPressureHandler::Configuration>& configuration) { s_networkProcessMemoryPressureHandlerConfiguration = configuration; }
#endif
void setEnhancedAccessibility(bool);
@@ -664,6 +665,7 @@
#if USE(SOUP)
WebCore::HTTPCookieAcceptPolicy m_initialHTTPCookieAcceptPolicy { WebCore::HTTPCookieAcceptPolicy::ExclusivelyFromMainDocumentDomain };
+ static std::optional<MemoryPressureHandler::Configuration> s_networkProcessMemoryPressureHandlerConfiguration;
#endif
#if PLATFORM(MAC)
Modified: trunk/Source/WebKit/UIProcess/soup/WebProcessPoolSoup.cpp (281069 => 281070)
--- trunk/Source/WebKit/UIProcess/soup/WebProcessPoolSoup.cpp 2021-08-16 06:51:32 UTC (rev 281069)
+++ trunk/Source/WebKit/UIProcess/soup/WebProcessPoolSoup.cpp 2021-08-16 06:55:58 UTC (rev 281070)
@@ -35,9 +35,21 @@
namespace WebKit {
+std::optional<MemoryPressureHandler::Configuration> WebProcessPool::s_networkProcessMemoryPressureHandlerConfiguration;
+
+static bool memoryPressureMonitorDisabled()
+{
+ static const char* disableMemoryPressureMonitor = getenv("WEBKIT_DISABLE_MEMORY_PRESSURE_MONITOR");
+ return disableMemoryPressureMonitor && !strcmp(disableMemoryPressureMonitor, "1");
+}
+
void WebProcessPool::platformInitializeNetworkProcess(NetworkProcessCreationParameters& parameters)
{
parameters.languages = userPreferredLanguages();
+ parameters.memoryPressureHandlerConfiguration = s_networkProcessMemoryPressureHandlerConfiguration;
+
+ if (memoryPressureMonitorDisabled())
+ parameters.shouldSuppressMemoryPressureHandler = true;
}
} // namespace WebKit
Modified: trunk/Tools/ChangeLog (281069 => 281070)
--- trunk/Tools/ChangeLog 2021-08-16 06:51:32 UTC (rev 281069)
+++ trunk/Tools/ChangeLog 2021-08-16 06:55:58 UTC (rev 281070)
@@ -1,3 +1,20 @@
+2021-08-15 Miguel Gomez <[email protected]>
+
+ [GTK][WPE] Add API to pass WebKitMemoryPressureHandler parameters to the network processes
+ https://bugs.webkit.org/show_bug.cgi?id=228227
+
+ Reviewed by Carlos Garcia Campos.
+
+ Added an API test for webkit_website_data_manager_set_memory_pressure_settings().
+
+ * TestWebKitAPI/Tests/WebKitGLib/TestWebsiteData.cpp:
+ (MemoryPressureTest::setup):
+ (MemoryPressureTest::teardown):
+ (MemoryPressureTest::loadFailedCallback):
+ (MemoryPressureTest::waitUntilLoadFailed):
+ (testMemoryPressureSettings):
+ (beforeAll):
+
2021-08-15 Wenson Hsieh <[email protected]>
[iOS 15] editing/selection/ios/select-all-in-readonly-input-does-not-overflow.html is a flaky timeout
Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitGLib/TestWebsiteData.cpp (281069 => 281070)
--- trunk/Tools/TestWebKitAPI/Tests/WebKitGLib/TestWebsiteData.cpp 2021-08-16 06:51:32 UTC (rev 281069)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitGLib/TestWebsiteData.cpp 2021-08-16 06:55:58 UTC (rev 281070)
@@ -800,6 +800,54 @@
g_assert_null(dataList);
}
+class MemoryPressureTest : public WebViewTest {
+public:
+ MAKE_GLIB_TEST_FIXTURE_WITH_SETUP_TEARDOWN(MemoryPressureTest, setup, teardown);
+
+ static void setup()
+ {
+ WebKitMemoryPressureSettings* settings = webkit_memory_pressure_settings_new();
+ webkit_memory_pressure_settings_set_memory_limit(settings, 1);
+ webkit_memory_pressure_settings_set_poll_interval(settings, 0.001);
+ webkit_memory_pressure_settings_set_kill_threshold(settings, 1);
+ webkit_memory_pressure_settings_set_strict_threshold(settings, 0.75);
+ webkit_memory_pressure_settings_set_conservative_threshold(settings, 0.5);
+ webkit_website_data_manager_set_memory_pressure_settings(settings);
+ webkit_memory_pressure_settings_free(settings);
+ }
+
+ static void teardown()
+ {
+ webkit_website_data_manager_set_memory_pressure_settings(nullptr);
+ }
+
+ static gboolean loadFailedCallback(WebKitWebView* webView, WebKitLoadEvent loadEvent, const char* failingURI, GError* error, MemoryPressureTest* test)
+ {
+ g_signal_handlers_disconnect_by_func(webView, reinterpret_cast<void*>(loadFailedCallback), test);
+ g_main_loop_quit(test->m_mainLoop);
+
+ return TRUE;
+ }
+
+ void waitUntilLoadFailed()
+ {
+ g_signal_connect(m_webView, "load-failed", G_CALLBACK(MemoryPressureTest::loadFailedCallback), this);
+ g_main_loop_run(m_mainLoop);
+ }
+};
+
+static void testMemoryPressureSettings(MemoryPressureTest* test, gconstpointer)
+{
+ // We have set a memory limit of 1MB with a kill threshold of 1 and a poll interval of 0.001.
+ // The network process will use around 2MB to load the test. The MemoryPressureHandler will
+ // kill the process as soon as it detects that it's using more than 1MB, so the network process
+ // won't be able to complete the resource load. This causes an internal error and the load-failed
+ // signal is emitted.
+ GUniquePtr<char> fileURL(g_strdup_printf("file://%s/simple.html", Test::getResourcesDir(Test::WebKit2Resources).data()));
+ test->loadURI(fileURL.get());
+ test->waitUntilLoadFailed();
+}
+
void beforeAll()
{
kServer = new WebKitTestServer();
@@ -823,6 +871,7 @@
WebsiteDataTest::add("WebKitWebsiteData", "itp", testWebsiteDataITP);
WebsiteDataTest::add("WebKitWebsiteData", "service-worker-registrations", testWebsiteDataServiceWorkerRegistrations);
WebsiteDataTest::add("WebKitWebsiteData", "dom-cache", testWebsiteDataDOMCache);
+ MemoryPressureTest::add("WebKitWebsiteData", "memory-pressure", testMemoryPressureSettings);
}
void afterAll()