// Copyright 2021 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef CONTENT_PUBLIC_TEST_FENCED_FRAME_TEST_UTIL_H_ #define CONTENT_PUBLIC_TEST_FENCED_FRAME_TEST_UTIL_H_ #include <vector> #include "base/compiler_specific.h" #include "base/test/scoped_feature_list.h" #include "content/public/browser/web_contents.h" #include "net/base/net_errors.h" #include "third_party/blink/public/common/fenced_frame/redacted_fenced_frame_config.h" #include "third_party/blink/public/common/input/web_mouse_event.h" #include "third_party/blink/public/common/input/web_pointer_properties.h" #include "third_party/blink/public/mojom/fenced_frame/fenced_frame.mojom.h" class GURL; namespace gfx { class PointF; } namespace content { class RenderFrameHost; class FencedFrameURLMapping; class FencedFrameReporter; class ToRenderFrameHost; namespace test { // Browser tests can use this class to more conveniently leverage fenced frames. class FencedFrameTestHelper { … }; // Maps a URL to a URN that can be loaded into an opaque-ads fenced frame. This // can be called from outside of `content/` as it does not require access to // `RenderFrameHostImpl`. GURL CreateFencedFrameURLMapping(RenderFrameHost* rfh, const GURL& url); // Helper function that converts a URL to a URN and adds the mapping to a given // fenced frame URL mapping object. This can only be called from inside of // `content/`. GURL AddAndVerifyFencedFrameURL( FencedFrameURLMapping* fenced_frame_url_mapping, const GURL& https_url, scoped_refptr<FencedFrameReporter> fenced_frame_reporter = nullptr); // Exempt the `urls` from fenced frame untrusted network revocation. void ExemptUrlsFromFencedFrameNetworkRevocation(RenderFrameHost* rfh, const std::vector<GURL>& urls); // Simulate a mouse click at the `point` inside fenced frame tree. // // Note: if the click is inside a nested iframe which is same-site with the // root fenced frame, the coordinates of `point` need to be offset by the // top-left coordinates of the nested iframe relative to the fenced frame. See // `GetTopLeftCoordinatesOfElementWithId`. This is because the same-site nested // iframe does not have a `RenderWidgetHost`. The mouse event is forwarded to // the `RenderWidgetHost` of the fenced frame even if the nested iframe // `RenderFrameHost` is passed in. // // However, a cross-site nested iframe becomes an OOPIF in fenced frame tree and // gets its own `RenderWidgetHost`. There is no need to offset the coordinates. // // Note: If the simulation does not take place inside a fenced frame tree, // use `SimulateMouseClickAt` in `content/public/test/browser_test_utils.h`. void SimulateClickInFencedFrameTree(const ToRenderFrameHost& adapter, blink::WebMouseEvent::Button button, const gfx::PointF& point); // Get the top left coordinates of the element with `id`, relative to `adapter`. gfx::PointF GetTopLeftCoordinatesOfElementWithId( const ToRenderFrameHost& adapter, std::string_view id); } // namespace test } // namespace content #endif // CONTENT_PUBLIC_TEST_FENCED_FRAME_TEST_UTIL_H_