Skip to content
Permalink
Browse files
[Reporting API] WebDriver: Add support for generateTestReport
https://bugs.webkit.org/show_bug.cgi?id=244719
<rdar://problem/99496290>

Reviewed by Patrick Angle.

Add a new Automation interface to support 'generate_test_report' in WPT when
run by WebDriver. This involves the following changes to comply with
https://w3c.github.io/reporting/#generate-test-report-command:

(1) Update ReportingScope to accept a 'group' argument, which will be used in
a future patch (once WPT starts using it).
(2) Update WKTR to accept an optional 'group' argument to generateTestReport,
passing 'default' if not provided.
(3) Provide a UIProcess method to accept generateTestReport from the Automation
interface.
(4) Add a new IPC message for the WebContent Process to generate a test report
at the request of the UIProcess.

* Source/WebCore/Modules/reporting/ReportingScope.cpp:
(WebCore::ReportingScope::generateTestReport): Add 'group' argument.
* Source/WebCore/Modules/reporting/ReportingScope.h:
* Source/WebKit/UIProcess/Automation/Automation.json: Add new method.
* Source/WebKit/UIProcess/Automation/WebAutomationSession.cpp:
(WebKit::WebAutomationSession::generateTestReport): Added.
* Source/WebKit/UIProcess/Automation/WebAutomationSession.h:
* Source/WebKit/UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::generateTestReport): Added.
* Source/WebKit/UIProcess/WebPageProxy.h:
* Source/WebKit/WebProcess/InjectedBundle/API/c/WKBundleFrame.cpp:
(_WKBundleFrameGenerateTestReport): Accept the 'group' argument.
* Source/WebKit/WebProcess/InjectedBundle/API/c/WKBundleFramePrivate.h:
* Source/WebKit/WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::generateTestReport): Added.
* Source/WebKit/WebProcess/WebPage/WebPage.h:
* Source/WebKit/WebProcess/WebPage/WebPage.messages.in:
* Tools/WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl:
* Tools/WebKitTestRunner/InjectedBundle/TestRunner.cpp:
(WTR::TestRunner::generateTestReport): Update to accept an optional
'group' argument, passing "default" if none is provided.
* Tools/WebKitTestRunner/InjectedBundle/TestRunner.h:

Canonical link: https://commits.webkit.org/254122@main
  • Loading branch information
brentfulgham authored and Brent Fulgham committed Sep 3, 2022
1 parent 6be2817 commit 9b7b0a6ad68383e5623c51681ce914bfdfc85d44
Show file tree
Hide file tree
Showing 15 changed files with 49 additions and 9 deletions.
@@ -160,8 +160,10 @@ String ReportingScope::endpointURIForToken(const String& reportTo) const
return m_reportingEndpoints.get(reportTo);
}

void ReportingScope::generateTestReport(String&& message)
void ReportingScope::generateTestReport(String&& message, String&& group)
{
UNUSED_PARAM(group);

String reportURL { ""_s };
if (auto* document = dynamicDowncast<Document>(scriptExecutionContext()))
reportURL = document->url().strippedForUseAsReferrer();
@@ -61,7 +61,7 @@ class WEBCORE_EXPORT ReportingScope final : public RefCounted<ReportingScope>, p

String endpointURIForToken(const String&) const;

void generateTestReport(String&& message);
void generateTestReport(String&& message, String&& group);

private:
explicit ReportingScope(ScriptExecutionContext&);
@@ -854,6 +854,15 @@
{ "name": "authenticatorId", "type": "string", "description": "The virtual authenticator id to fetch all credentials for." },
{ "name": "isUserVerified", "type": "boolean", "description": "The isUserVerified value to set on the given virtual authenticator"}
]
},
{
"name": "generateTestReport",
"description": "generate a test report for the specified browsing context",
"parameters": [
{ "name": "browsingContextHandle", "$ref": "BrowsingContextHandle", "description": "The handle for the browsing context." },
{ "name": "message", "type": "string", "description": "The body message for the generated test report." },
{ "name": "group", "type": "string", "description": "The group value to use when sending a test report."}
]
}
],
"events": [
@@ -1680,6 +1680,17 @@ Inspector::Protocol::ErrorStringOr<void> WebAutomationSession::setVirtualAuthent
SYNC_FAIL_WITH_PREDEFINED_ERROR_AND_DETAILS(NotImplemented, "This method is not yet implemented.");
}

Inspector::Protocol::ErrorStringOr<void> WebAutomationSession::generateTestReport(const String& browsingContextHandle, const String& message, const String& group)
{
WebPageProxy* page = webPageProxyForHandle(browsingContextHandle);
if (!page)
SYNC_FAIL_WITH_PREDEFINED_ERROR(WindowNotFound);

page->generateTestReport(message, group);

return { };
}

bool WebAutomationSession::shouldAllowGetUserMediaForPage(const WebPageProxy&) const
{
return m_permissionForGetUserMedia;
@@ -213,6 +213,7 @@ class WebAutomationSession final : public API::ObjectImpl<API::Object::Type::Aut
Inspector::Protocol::ErrorStringOr<void> removeVirtualAuthenticatorCredential(const String& browsingContextHandle, const String& authenticatorId, const String& credentialId);
Inspector::Protocol::ErrorStringOr<void> removeAllVirtualAuthenticatorCredentials(const String& browsingContextHandle, const String& authenticatorId);
Inspector::Protocol::ErrorStringOr<void> setVirtualAuthenticatorUserVerified(const String& browsingContextHandle, const String& authenticatorId, bool isUserVerified);
Inspector::Protocol::ErrorStringOr<void> generateTestReport(const String& browsingContextHandle, const String& message, const String& group);

#if PLATFORM(MAC)
void inspectBrowsingContext(const Inspector::Protocol::Automation::BrowsingContextHandle&, std::optional<bool>&& enableAutoCapturing, Ref<InspectBrowsingContextCallback>&&);
@@ -11654,6 +11654,11 @@ bool WebPageProxy::shouldAvoidSynchronouslyWaitingToPreventDeadlock() const
return false;
}

void WebPageProxy::generateTestReport(const String& message, const String& group)
{
send(Messages::WebPage::GenerateTestReport(message, group));
}

} // namespace WebKit

#undef WEBPAGEPROXY_RELEASE_LOG
@@ -2146,6 +2146,8 @@ class WebPageProxy final : public API::ObjectImpl<API::Object::Type::Page>

void queryPermission(const WebCore::ClientOrigin&, const WebCore::PermissionDescriptor&, CompletionHandler<void(std::optional<WebCore::PermissionState>)>&&);

void generateTestReport(const String& message, const String& group);

private:
WebPageProxy(PageClient&, WebProcessProxy&, Ref<API::PageConfiguration>&&);
void platformInitialize();
@@ -290,12 +290,12 @@ void WKBundleFrameFocus(WKBundleFrameRef frameRef)
CheckedRef(coreFrame->page()->focusController())->setFocusedFrame(coreFrame.get());
}

void _WKBundleFrameGenerateTestReport(WKBundleFrameRef frameRef, WKStringRef message)
void _WKBundleFrameGenerateTestReport(WKBundleFrameRef frameRef, WKStringRef message, WKStringRef group)
{
RefPtr coreFrame = WebKit::toImpl(frameRef)->coreFrame();
if (!coreFrame)
return;

if (RefPtr document = coreFrame->document())
document->reportingScope().generateTestReport(WebKit::toWTFString(message));
document->reportingScope().generateTestReport(WebKit::toWTFString(message), WebKit::toWTFString(group));
}
@@ -56,7 +56,7 @@ WK_EXPORT bool WKBundleFrameHandlesPageScaleGesture(WKBundleFrameRef frame);

WK_EXPORT void WKBundleFrameFocus(WKBundleFrameRef frame);

WK_EXPORT void _WKBundleFrameGenerateTestReport(WKBundleFrameRef, WKStringRef message);
WK_EXPORT void _WKBundleFrameGenerateTestReport(WKBundleFrameRef, WKStringRef message, WKStringRef group);

#ifdef __cplusplus
}
@@ -8250,6 +8250,12 @@ void WebPage::clearNotificationPermissionState()
}
#endif

void WebPage::generateTestReport(String&& message, String&& group)
{
if (RefPtr document = m_page->mainFrame().document())
document->reportingScope().generateTestReport(WTFMove(message), WTFMove(group));
}

} // namespace WebKit

#undef WEBPAGE_RELEASE_LOG
@@ -1563,6 +1563,8 @@ class WebPage : public API::ObjectImpl<API::Object::Type::BundlePage>, public IP
void setInteractionRegionsEnabled(bool);
#endif

void generateTestReport(String&& message, String&& group);

private:
WebPage(WebCore::PageIdentifier, WebPageCreationParameters&&);

@@ -704,4 +704,6 @@ GenerateSyntheticEditingCommand(enum:uint8_t WebKit::SyntheticEditingCommandType
#if ENABLE(INTERACTION_REGIONS_IN_EVENT_REGION)
SetInteractionRegionsEnabled(bool enable)
#endif

GenerateTestReport(String message, String group);
}
@@ -434,5 +434,5 @@ interface TestRunner {
undefined takeViewPortSnapshot(object callback);

// Reporting API
undefined generateTestReport(DOMString message);
undefined generateTestReport(DOMString message, DOMString group);
};
@@ -2234,9 +2234,9 @@ void TestRunner::viewPortSnapshotTaken(WKStringRef value)
m_takeViewPortSnapshot = false;
}

void TestRunner::generateTestReport(JSStringRef message)
void TestRunner::generateTestReport(JSStringRef message, JSStringRef group)
{
_WKBundleFrameGenerateTestReport(mainFrame(), toWK(message).get());
_WKBundleFrameGenerateTestReport(mainFrame(), toWK(message).get(), toWK(group).get());
}

ALLOW_DEPRECATED_DECLARATIONS_END
@@ -549,7 +549,7 @@ class TestRunner : public JSWrappable {
void viewPortSnapshotTaken(WKStringRef);

// Reporting API
void generateTestReport(JSStringRef message);
void generateTestReport(JSStringRef message, JSStringRef group);

private:
TestRunner();

0 comments on commit 9b7b0a6

Please sign in to comment.