#include "content/test/content_browser_test_utils_internal.h"
#include <stddef.h>
#include <map>
#include <memory>
#include <set>
#include <utility>
#include <vector>
#include "base/containers/stack.h"
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/ranges/algorithm.h"
#include "base/strings/escape.h"
#include "base/strings/stringprintf.h"
#include "base/task/thread_pool.h"
#include "base/test/bind.h"
#include "base/test/test_future.h"
#include "base/test/test_timeouts.h"
#include "build/build_config.h"
#include "content/browser/preloading/prerender/prerender_host_registry.h"
#include "content/browser/renderer_host/delegated_frame_host.h"
#include "content/browser/renderer_host/frame_tree_node.h"
#include "content/browser/renderer_host/navigation_request.h"
#include "content/browser/renderer_host/navigator.h"
#include "content/browser/renderer_host/render_frame_host_delegate.h"
#include "content/browser/renderer_host/render_frame_proxy_host.h"
#include "content/browser/renderer_host/render_widget_host_factory.h"
#include "content/browser/site_instance_impl.h"
#include "content/browser/web_contents/web_contents_impl.h"
#include "content/common/frame_messages.mojom.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/file_select_listener.h"
#include "content/public/browser/navigation_handle.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/site_isolation_policy.h"
#include "content/public/browser/web_contents.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/content_browser_test_utils.h"
#include "content/public/test/test_frame_navigation_observer.h"
#include "content/public/test/test_navigation_observer.h"
#include "content/shell/browser/shell.h"
#include "content/shell/browser/shell_javascript_dialog_manager.h"
#include "net/test/embedded_test_server/http_request.h"
#include "net/test/embedded_test_server/http_response.h"
#include "net/test/embedded_test_server/request_handler_util.h"
#include "third_party/blink/public/common/frame/frame_visual_properties.h"
#if BUILDFLAG(IS_ANDROID)
#include "cc/slim/layer_tree.h"
#include "content/browser/renderer_host/compositor_impl_android.h"
#include "ui/android/window_android.h"
#include "ui/android/window_android_compositor.h"
#endif
#if BUILDFLAG(IS_MAC)
#include "content/browser/renderer_host/browser_compositor_view_mac.h"
#include "content/browser/renderer_host/test_render_widget_host_view_mac_factory.h"
#endif
#if BUILDFLAG(IS_IOS)
#include "content/browser/renderer_host/browser_compositor_ios.h"
#include "content/browser/renderer_host/test_render_widget_host_view_ios_factory.h"
#endif
#if defined(USE_AURA)
#include "content/browser/renderer_host/render_widget_host_view_aura.h"
#endif
namespace content {
bool NavigateFrameToURL(FrameTreeNode* node, const GURL& url) { … }
void SetShouldProceedOnBeforeUnload(Shell* shell, bool proceed, bool success) { … }
RenderFrameHost* ConvertToRenderFrameHost(FrameTreeNode* frame_tree_node) { … }
bool NavigateToURLInSameBrowsingInstance(Shell* window, const GURL& url) { … }
bool IsExpectedSubframeErrorTransition(SiteInstance* start_site_instance,
SiteInstance* end_site_instance) { … }
RenderFrameHost* CreateSubframe(WebContentsImpl* web_contents,
std::string frame_id,
const GURL& url,
bool wait_for_navigation) { … }
RenderFrameHost* CreateSubframe(RenderFrameHost* parent,
std::string frame_id,
const GURL& url,
bool wait_for_navigation) { … }
RenderFrameHost* CreateSubframe(RenderFrameHost* parent,
std::string frame_id,
const GURL& url,
bool wait_for_navigation,
ExtraParams extra_params) { … }
std::vector<RenderFrameHostImpl*> CollectAllRenderFrameHosts(
RenderFrameHostImpl* starting_rfh) { … }
std::vector<RenderFrameHostImpl*>
CollectAllRenderFrameHostsIncludingSpeculative(
RenderFrameHostImpl* starting_rfh) { … }
std::vector<RenderFrameHostImpl*> CollectAllRenderFrameHosts(
WebContentsImpl* web_contents) { … }
std::vector<RenderFrameHostImpl*>
CollectAllRenderFrameHostsIncludingSpeculative(WebContentsImpl* web_contents) { … }
Shell* OpenBlankWindow(WebContentsImpl* web_contents) { … }
Shell* OpenWindow(WebContentsImpl* web_contents, const GURL& url) { … }
FrameTreeVisualizer::FrameTreeVisualizer() = default;
FrameTreeVisualizer::~FrameTreeVisualizer() = default;
std::string FrameTreeVisualizer::DepictFrameTree(FrameTreeNode* root) { … }
std::string FrameTreeVisualizer::GetName(SiteInstance* site_instance) { … }
std::string FrameTreeVisualizer::GetGroupName(SiteInstanceGroup* group) { … }
GURL FrameTreeVisualizer::GetUrlWithoutPort(const GURL& url) { … }
std::string DepictFrameTree(FrameTreeNode& root) { … }
Shell* OpenPopup(const ToRenderFrameHost& opener,
const GURL& url,
const std::string& name) { … }
Shell* OpenPopup(const ToRenderFrameHost& opener,
const GURL& url,
const std::string& name,
const std::string& features,
bool expect_return_from_window_open) { … }
FileChooserDelegate::FileChooserDelegate(std::vector<base::FilePath> files,
const base::FilePath& base_dir,
base::OnceClosure callback)
: … { … }
FileChooserDelegate::FileChooserDelegate(const base::FilePath& file,
base::OnceClosure callback)
: … { … }
FileChooserDelegate::~FileChooserDelegate() = default;
void FileChooserDelegate::RunFileChooser(
RenderFrameHost* render_frame_host,
scoped_refptr<content::FileSelectListener> listener,
const blink::mojom::FileChooserParams& params) { … }
FrameTestNavigationManager::FrameTestNavigationManager(
int filtering_frame_tree_node_id,
WebContents* web_contents,
const GURL& url)
: … { … }
bool FrameTestNavigationManager::ShouldMonitorNavigation(
NavigationHandle* handle) { … }
UrlCommitObserver::UrlCommitObserver(FrameTreeNode* frame_tree_node,
const GURL& url)
: … { … }
UrlCommitObserver::~UrlCommitObserver() { … }
void UrlCommitObserver::Wait() { … }
void UrlCommitObserver::DidFinishNavigation(
NavigationHandle* navigation_handle) { … }
RenderProcessHostBadIpcMessageWaiter::RenderProcessHostBadIpcMessageWaiter(
RenderProcessHost* render_process_host)
: … { … }
std::optional<bad_message::BadMessageReason>
RenderProcessHostBadIpcMessageWaiter::Wait() { … }
CreateNewPopupWidgetInterceptor::CreateNewPopupWidgetInterceptor(
RenderFrameHostImpl* rfh,
base::OnceCallback<void(RenderWidgetHostImpl*)> did_create_callback)
: … { … }
CreateNewPopupWidgetInterceptor::~CreateNewPopupWidgetInterceptor() = default;
void CreateNewPopupWidgetInterceptor::CreateNewPopupWidget(
mojo::PendingAssociatedReceiver<blink::mojom::PopupWidgetHost>
blink_popup_widget_host,
mojo::PendingAssociatedReceiver<blink::mojom::WidgetHost> blink_widget_host,
mojo::PendingAssociatedRemote<blink::mojom::Widget> blink_widget) { … }
blink::mojom::LocalFrameHost*
CreateNewPopupWidgetInterceptor::GetForwardingInterface() { … }
#if BUILDFLAG(IS_MAC) || BUILDFLAG(IS_ANDROID)
ShowPopupWidgetWaiter::ShowPopupMenuInterceptor::ShowPopupMenuInterceptor(
RenderFrameHostImpl* rfh,
base::OnceCallback<void(const gfx::Rect&)> did_show_popup_menu_callback)
: swapped_impl_(rfh->local_frame_host_receiver_for_testing(), this),
did_show_popup_menu_callback_(std::move(did_show_popup_menu_callback)) {}
ShowPopupWidgetWaiter::ShowPopupMenuInterceptor::~ShowPopupMenuInterceptor() =
default;
void ShowPopupWidgetWaiter::ShowPopupMenuInterceptor::ShowPopupMenu(
mojo::PendingRemote<blink::mojom::PopupMenuClient> popup_client,
const gfx::Rect& bounds,
int32_t item_height,
double font_size,
int32_t selected_item,
std::vector<blink::mojom::MenuItemPtr> menu_items,
bool right_aligned,
bool allow_multiple_selection) {
if (did_show_popup_menu_callback_) {
std::move(did_show_popup_menu_callback_).Run(bounds);
mojo::Remote<blink::mojom::PopupMenuClient>(std::move(popup_client))
->DidCancel();
return;
}
GetForwardingInterface()->ShowPopupMenu(
std::move(popup_client), bounds, item_height, font_size, selected_item,
std::move(menu_items), right_aligned, allow_multiple_selection);
}
blink::mojom::LocalFrameHost*
ShowPopupWidgetWaiter::ShowPopupMenuInterceptor::GetForwardingInterface() {
return swapped_impl_.old_impl();
}
#endif
ShowPopupWidgetWaiter::ShowPopupWidgetWaiter(WebContentsImpl* web_contents,
RenderFrameHostImpl* frame_host)
: … { … }
ShowPopupWidgetWaiter::~ShowPopupWidgetWaiter() { … }
void ShowPopupWidgetWaiter::Wait() { … }
blink::mojom::PopupWidgetHost* ShowPopupWidgetWaiter::GetForwardingInterface() { … }
void ShowPopupWidgetWaiter::ShowPopup(const gfx::Rect& initial_rect,
const gfx::Rect& initial_anchor_rect,
ShowPopupCallback callback) { … }
void ShowPopupWidgetWaiter::DidCreatePopupWidget(
RenderWidgetHostImpl* render_widget_host) { … }
#if BUILDFLAG(IS_MAC) || BUILDFLAG(IS_ANDROID)
void ShowPopupWidgetWaiter::DidShowPopupMenu(const gfx::Rect& bounds) {
initial_rect_ = bounds;
run_loop_.Quit();
}
#endif
UnresponsiveRendererObserver::UnresponsiveRendererObserver(
WebContents* web_contents)
: … { … }
UnresponsiveRendererObserver::~UnresponsiveRendererObserver() = default;
RenderProcessHost* UnresponsiveRendererObserver::Wait(base::TimeDelta timeout) { … }
void UnresponsiveRendererObserver::OnRendererUnresponsive(
RenderProcessHost* render_process_host) { … }
BeforeUnloadBlockingDelegate::BeforeUnloadBlockingDelegate(
WebContentsImpl* web_contents)
: … { … }
BeforeUnloadBlockingDelegate::~BeforeUnloadBlockingDelegate() { … }
void BeforeUnloadBlockingDelegate::Wait() { … }
JavaScriptDialogManager*
BeforeUnloadBlockingDelegate::GetJavaScriptDialogManager(WebContents* source) { … }
bool BeforeUnloadBlockingDelegate::IsBackForwardCacheSupported(
WebContents& web_contents) { … }
void BeforeUnloadBlockingDelegate::RunJavaScriptDialog(
WebContents* web_contents,
RenderFrameHost* render_frame_host,
JavaScriptDialogType dialog_type,
const std::u16string& message_text,
const std::u16string& default_prompt_text,
DialogClosedCallback callback,
bool* did_suppress_message) { … }
void BeforeUnloadBlockingDelegate::RunBeforeUnloadDialog(
WebContents* web_contents,
RenderFrameHost* render_frame_host,
bool is_reload,
DialogClosedCallback callback) { … }
bool BeforeUnloadBlockingDelegate::HandleJavaScriptDialog(
WebContents* web_contents,
bool accept,
const std::u16string* prompt_override) { … }
FrameNavigateParamsCapturer::FrameNavigateParamsCapturer(WebContents* contents)
: … { … }
FrameNavigateParamsCapturer::FrameNavigateParamsCapturer(FrameTreeNode* node)
: … { … }
FrameNavigateParamsCapturer::~FrameNavigateParamsCapturer() = default;
void FrameNavigateParamsCapturer::DidFinishNavigation(
NavigationHandle* navigation_handle) { … }
void FrameNavigateParamsCapturer::Wait() { … }
void FrameNavigateParamsCapturer::DidStopLoading() { … }
RenderFrameHostCreatedObserver::RenderFrameHostCreatedObserver(
WebContents* web_contents)
: … { … }
RenderFrameHostCreatedObserver::RenderFrameHostCreatedObserver(
WebContents* web_contents,
int expected_frame_count)
: … { … }
RenderFrameHostCreatedObserver::RenderFrameHostCreatedObserver(
WebContents* web_contents,
OnRenderFrameHostCreatedCallback on_rfh_created)
: … { … }
RenderFrameHostCreatedObserver::~RenderFrameHostCreatedObserver() = default;
RenderFrameHost* RenderFrameHostCreatedObserver::Wait() { … }
void RenderFrameHostCreatedObserver::RenderFrameCreated(
RenderFrameHost* render_frame_host) { … }
BackForwardCache::DisabledReason RenderFrameHostDisabledForTestingReason() { … }
void DisableBFCacheForRFHForTesting(
content::RenderFrameHost* render_frame_host) { … }
void DisableBFCacheForRFHForTesting(content::GlobalRenderFrameHostId id) { … }
void UserAgentInjector::DidStartNavigation(
NavigationHandle* navigation_handle) { … }
RenderFrameHostImplWrapper::RenderFrameHostImplWrapper(RenderFrameHost* rfh)
: … { … }
RenderFrameHostImpl* RenderFrameHostImplWrapper::get() const { … }
RenderFrameHostImpl& RenderFrameHostImplWrapper::operator*() const { … }
RenderFrameHostImpl* RenderFrameHostImplWrapper::operator->() const { … }
InactiveRenderFrameHostDeletionObserver::
InactiveRenderFrameHostDeletionObserver(WebContents* content)
: … { … }
InactiveRenderFrameHostDeletionObserver::
~InactiveRenderFrameHostDeletionObserver() = default;
void InactiveRenderFrameHostDeletionObserver::Wait() { … }
void InactiveRenderFrameHostDeletionObserver::RenderFrameDeleted(
RenderFrameHost* rfh) { … }
void InactiveRenderFrameHostDeletionObserver::CheckCondition() { … }
void TestNavigationObserverInternal::OnDidFinishNavigation(
NavigationHandle* navigation_handle) { … }
RenderFrameHostImpl* DescendantRenderFrameHostAtInternal(
RenderFrameHostImpl* rfh,
std::string path,
std::vector<size_t>& descendant_indices) { … }
RenderFrameHostImpl* DescendantRenderFrameHostImplAt(
const ToRenderFrameHost& adapter,
std::vector<size_t> descendant_indices) { … }
EffectiveURLContentBrowserTestContentBrowserClient::
EffectiveURLContentBrowserTestContentBrowserClient(
bool requires_dedicated_process)
: … { … }
EffectiveURLContentBrowserTestContentBrowserClient::
EffectiveURLContentBrowserTestContentBrowserClient(
const GURL& url_to_modify,
const GURL& url_to_return,
bool requires_dedicated_process)
: … { … }
EffectiveURLContentBrowserTestContentBrowserClient::
~EffectiveURLContentBrowserTestContentBrowserClient() = default;
void EffectiveURLContentBrowserTestContentBrowserClient::AddTranslation(
const GURL& url_to_modify,
const GURL& url_to_return) { … }
GURL EffectiveURLContentBrowserTestContentBrowserClient::GetEffectiveURL(
BrowserContext* browser_context,
const GURL& url) { … }
bool EffectiveURLContentBrowserTestContentBrowserClient::
DoesSiteRequireDedicatedProcess(BrowserContext* browser_context,
const GURL& effective_site_url) { … }
CustomStoragePartitionBrowserClient::CustomStoragePartitionBrowserClient(
const GURL& site_to_isolate)
: … { … }
StoragePartitionConfig
CustomStoragePartitionBrowserClient::GetStoragePartitionConfigForSite(
BrowserContext* browser_context,
const GURL& site) { … }
CommitNavigationPauser::CommitNavigationPauser(RenderFrameHostImpl* rfh) { … }
CommitNavigationPauser::~CommitNavigationPauser() = default;
void CommitNavigationPauser::WaitForCommitAndPause() { … }
void CommitNavigationPauser::ResumePausedCommit() { … }
bool CommitNavigationPauser::WillProcessDidCommitNavigation(
NavigationRequest* request,
mojom::DidCommitProvisionalLoadParamsPtr* params,
mojom::DidCommitProvisionalLoadInterfaceParamsPtr* interface_params) { … }
void WaitForCopyableViewInWebContents(WebContents* web_contents) { … }
void WaitForCopyableViewInFrame(RenderFrameHost* render_frame_host) { … }
void WaitForBrowserCompositorFramePresented(WebContents* web_contents) { … }
void ForceNewCompositorFrameFromBrowser(WebContents* web_contents) { … }
namespace {
std::unique_ptr<net::test_server::HttpResponse>
RedirectToTargetOnSecondNavigation(
unsigned int& navigation_counter,
const net::test_server::HttpRequest& request) { … }
}
void AddRedirectOnSecondNavigationHandler(net::EmbeddedTestServer* server) { … }
}