#include "content/browser/renderer_host/render_widget_host_view_aura.h"
#include "base/functional/bind.h"
#include "base/run_loop.h"
#include "base/task/single_thread_task_runner.h"
#include "base/test/run_until.h"
#include "base/test/test_timeouts.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "content/browser/devtools/protocol/devtools_protocol_test_support.h"
#include "content/browser/renderer_host/delegated_frame_host.h"
#include "content/browser/renderer_host/frame_tree_node.h"
#include "content/browser/renderer_host/render_widget_host_impl.h"
#include "content/browser/web_contents/web_contents_impl.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_contents_delegate.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/content_browser_test.h"
#include "content/public/test/content_browser_test_utils.h"
#include "content/shell/browser/shell.h"
#include "content/shell/common/shell_switches.h"
#include "net/dns/mock_host_resolver.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "ui/aura/window.h"
#include "ui/aura/window_tree_host.h"
#include "ui/display/screen.h"
#include "ui/events/event_utils.h"
#include "ui/events/test/event_generator.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/size.h"
#include "ui/gfx/geometry/vector2d.h"
#if BUILDFLAG(IS_WIN)
#include "content/browser/renderer_host/legacy_render_widget_host_win.h"
#endif
namespace content {
namespace {
#if BUILDFLAG(IS_CHROMEOS_ASH)
const char kMinimalPageDataURL[] =
"data:text/html,<html><head></head><body>Hello, world</body></html>";
void GiveItSomeTime() {
base::RunLoop run_loop;
base::SingleThreadTaskRunner::GetCurrentDefault()->PostDelayedTask(
FROM_HERE, run_loop.QuitClosure(), base::Milliseconds(250));
run_loop.Run();
}
#endif
class FakeWebContentsDelegate : public WebContentsDelegate { … };
}
class RenderWidgetHostViewAuraBrowserTest : public ContentBrowserTest { … };
#if BUILDFLAG(IS_WIN)
IN_PROC_BROWSER_TEST_F(RenderWidgetHostViewAuraBrowserTest, AuraWindowLookup) {
EXPECT_TRUE(NavigateToURL(shell(), GURL("about:blank")));
aura::Window* window = GetRenderWidgetHostView()->GetNativeView();
ASSERT_TRUE(GetLegacyRenderWidgetHostHWND());
HWND hwnd = GetLegacyRenderWidgetHostHWND()->hwnd();
EXPECT_TRUE(hwnd);
auto* window_tree_host = aura::WindowTreeHost::GetForAcceleratedWidget(hwnd);
EXPECT_TRUE(window_tree_host);
EXPECT_EQ(window->GetHost(), window_tree_host);
}
#endif
#if BUILDFLAG(IS_CHROMEOS_ASH)
IN_PROC_BROWSER_TEST_F(RenderWidgetHostViewAuraBrowserTest,
DISABLED_StaleFrameContentOnEvictionNormal) {
EXPECT_TRUE(NavigateToURL(shell(), GURL(kMinimalPageDataURL)));
RenderFrameSubmissionObserver submission_observer(shell()->web_contents());
if (!submission_observer.render_frame_count())
submission_observer.WaitForAnyFrameSubmission();
FakeWebContentsDelegate delegate;
delegate.SetShowStaleContentOnEviction(true);
shell()->web_contents()->SetDelegate(&delegate);
EXPECT_FALSE(
GetDelegatedFrameHost()->stale_content_layer_->has_external_content());
EXPECT_EQ(GetDelegatedFrameHost()->frame_eviction_state_,
DelegatedFrameHost::FrameEvictionState::kNotStarted);
GetRenderWidgetHostView()->Hide();
auto* dfh = GetDelegatedFrameHost();
static_cast<viz::FrameEvictorClient*>(dfh)->EvictDelegatedFrame(
dfh->GetFrameEvictorForTesting()->CollectSurfaceIdsForEviction());
EXPECT_EQ(GetDelegatedFrameHost()->frame_eviction_state_,
DelegatedFrameHost::FrameEvictionState::kPendingEvictionRequests);
while (!GetDelegatedFrameHost()->stale_content_layer_->has_external_content())
GiveItSomeTime();
EXPECT_EQ(GetDelegatedFrameHost()->frame_eviction_state_,
DelegatedFrameHost::FrameEvictionState::kNotStarted);
GetRenderWidgetHostView()->Show();
EXPECT_FALSE(
GetDelegatedFrameHost()->stale_content_layer_->has_external_content());
}
IN_PROC_BROWSER_TEST_F(RenderWidgetHostViewAuraBrowserTest,
StaleFrameContentOnEvictionRejected) {
EXPECT_TRUE(NavigateToURL(shell(), GURL(kMinimalPageDataURL)));
while (!GetDelegatedFrameHost()->HasSavedFrame())
GiveItSomeTime();
FakeWebContentsDelegate delegate;
delegate.SetShowStaleContentOnEviction(true);
shell()->web_contents()->SetDelegate(&delegate);
EXPECT_FALSE(
GetDelegatedFrameHost()->stale_content_layer_->has_external_content());
EXPECT_EQ(GetDelegatedFrameHost()->frame_eviction_state_,
DelegatedFrameHost::FrameEvictionState::kNotStarted);
GetRenderWidgetHostView()->Hide();
auto* dfh = GetDelegatedFrameHost();
static_cast<viz::FrameEvictorClient*>(dfh)->EvictDelegatedFrame(
dfh->GetFrameEvictorForTesting()->CollectSurfaceIdsForEviction());
EXPECT_EQ(GetDelegatedFrameHost()->frame_eviction_state_,
DelegatedFrameHost::FrameEvictionState::kPendingEvictionRequests);
GetRenderWidgetHostView()->Show();
EXPECT_EQ(GetDelegatedFrameHost()->frame_eviction_state_,
DelegatedFrameHost::FrameEvictionState::kNotStarted);
GiveItSomeTime();
EXPECT_FALSE(
GetDelegatedFrameHost()->stale_content_layer_->has_external_content());
}
IN_PROC_BROWSER_TEST_F(RenderWidgetHostViewAuraBrowserTest,
StaleFrameContentOnEvictionNone) {
EXPECT_TRUE(NavigateToURL(shell(), GURL(kMinimalPageDataURL)));
while (!GetDelegatedFrameHost()->HasSavedFrame())
GiveItSomeTime();
FakeWebContentsDelegate delegate;
delegate.SetShowStaleContentOnEviction(false);
shell()->web_contents()->SetDelegate(&delegate);
EXPECT_FALSE(
GetDelegatedFrameHost()->stale_content_layer_->has_external_content());
EXPECT_EQ(GetDelegatedFrameHost()->frame_eviction_state_,
DelegatedFrameHost::FrameEvictionState::kNotStarted);
GetRenderWidgetHostView()->Hide();
auto* dfh = GetDelegatedFrameHost();
static_cast<viz::FrameEvictorClient*>(dfh)->EvictDelegatedFrame(
dfh->GetFrameEvictorForTesting()->CollectSurfaceIdsForEviction());
EXPECT_EQ(GetDelegatedFrameHost()->frame_eviction_state_,
DelegatedFrameHost::FrameEvictionState::kNotStarted);
GiveItSomeTime();
EXPECT_FALSE(
GetDelegatedFrameHost()->stale_content_layer_->has_external_content());
}
#endif
#if BUILDFLAG(IS_CHROMEOS_LACROS)
#define MAYBE_SetKeyboardFocusOnTapAfterDismissingPopup …
#else
#define MAYBE_SetKeyboardFocusOnTapAfterDismissingPopup …
#endif
IN_PROC_BROWSER_TEST_F(RenderWidgetHostViewAuraBrowserTest,
MAYBE_SetKeyboardFocusOnTapAfterDismissingPopup) { … }
IN_PROC_BROWSER_TEST_F(RenderWidgetHostViewAuraBrowserTest,
UpdatesCaretBoundsAfterFrameScroll) { … }
IN_PROC_BROWSER_TEST_F(RenderWidgetHostViewAuraBrowserTest,
UpdatesCaretBoundsAfterOverflowScroll) { … }
class RenderWidgetHostViewAuraDevtoolsBrowserTest
: public content::DevToolsProtocolTest { … };
IN_PROC_BROWSER_TEST_F(RenderWidgetHostViewAuraDevtoolsBrowserTest,
NoCrashOnSelect) { … }
class RenderWidgetHostViewAuraDSFBrowserTest
: public RenderWidgetHostViewAuraBrowserTest { … };
IN_PROC_BROWSER_TEST_F(RenderWidgetHostViewAuraDSFBrowserTest,
SelectionRegionBoundingBox) { … }
class RenderWidgetHostViewAuraActiveWidgetTest : public ContentBrowserTest { … };
IN_PROC_BROWSER_TEST_F(RenderWidgetHostViewAuraActiveWidgetTest,
FocusIsInactive) { … }
#if BUILDFLAG(IS_CHROMEOS_ASH)
IN_PROC_BROWSER_TEST_F(RenderWidgetHostViewAuraActiveWidgetTest,
DISABLED_TextControlBoundingRegionInIframe) {
GURL page(
embedded_test_server()->GetURL("example.com", "/input_in_iframe.html"));
EXPECT_TRUE(NavigateToURL(shell(), page));
FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents())
->GetPrimaryFrameTree()
.root();
ASSERT_EQ("OUTER_LOADED",
EvalJs(root->current_frame_host(), "notifyWhenLoaded()"));
ASSERT_EQ("LOADED", EvalJs(root->current_frame_host(),
"document.querySelector(\"iframe\").contentWindow."
"notifyWhenLoaded();"));
GiveItSomeTime();
std::optional<gfx::Rect> control_bounds;
std::optional<gfx::Rect> selection_bounds;
GetRenderWidgetHostView()->GetActiveTextInputControlLayoutBounds(
&control_bounds, &selection_bounds);
EXPECT_TRUE(control_bounds.has_value());
ASSERT_EQ(4200, control_bounds->origin().y());
}
#endif
}