0

Reland "[fuchsia] Switch browsertests to Flatland"

This is a reland of commit c537ce7cc0

Previously this broke component builds because FrameWindowTreeHost was
not exported.

Original change's description:
> [fuchsia] Switch browsertests to Flatland
>
> Switch Browsertests to run with the Flatland TestUiStack, and remove
> scenic hardcoding in WebEngineTestLauncher. WebEngineBrowserMainParts
> picks the appropriate Ozone platform based on
> fuchsia.ui.scenic/Scenic.UseFlatland. Test configurations that cannot
> use Scenic or Flatland should use Headless instead with
> --ozone-platform=headless. See crrev.com/c/4001000 for example.
>
> * web_engine_browsertests now runs with the Flatland TestUiStack.
> * cast_runner_browsertests now runs with the same Flatland TestUiStack
>   to detect Scenic.
> * FrameImplTest.VisibilityState is migrated to CreateView2 because
>   GraphicalPresenter no longer accepts GFX parameters.
> * VirtualKeyboardTest and KeyboardInputTest are migrated to CreateView2
>   because they assert the KOID of the ViewRef.
> * VirtualKeyboardTest and KeyboardInputTest are skipped when ran with
>   headless Ozone because keyboard events are ignored.
>
> Tests can continue to use Frame.CreateView and
> Frame.CreateViewWithViewRef for now, since GFX APIs are still present.
> Future CLs will migrate these to CreateView2.
>
>
> Bug: 1300993
> Change-Id: I9655bf1ec5185cf6949e21b89db54490ef28e58a
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4371128
> Code-Coverage: Findit <findit-for-me@appspot.gserviceaccount.com>
> Commit-Queue: David Song <wintermelons@google.com>
> Reviewed-by: Sergey Ulanov <sergeyu@chromium.org>
> Cr-Commit-Position: refs/heads/main@{#1148204}

Bug: 1300993
Change-Id: I59bafd3981ab4223b402ec717041898bf44c3ecd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4757320
Reviewed-by: Sergey Ulanov <sergeyu@chromium.org>
Commit-Queue: David Song <wintermelons@google.com>
Cr-Commit-Position: refs/heads/main@{#1181764}
This commit is contained in:
David Song
2023-08-09 23:41:58 +00:00
committed by Chromium LUCI CQ
parent 02cd9b3c87
commit a6510cd992
9 changed files with 58 additions and 43 deletions

@ -240,6 +240,7 @@ test("cast_runner_browsertests") {
additional_manifest_fragments = [
"//build/config/fuchsia/test/mark_vmo_executable.shard.test-cml",
"//build/config/fuchsia/test/network.shard.test-cml",
"//build/config/fuchsia/test/test_ui_stack.shard.test-cml",
"//third_party/fuchsia-sdk/sdk/pkg/vulkan/client.shard.cml",
]
}

@ -596,6 +596,7 @@ test("web_engine_browsertests") {
":browsertest_core",
":switches",
":web_engine_core",
"//components/fuchsia_component_support:annotations_manager",
"//components/policy/content:safe_sites_navigation_throttle",
"//components/safe_search_api:safe_search_api",
"//components/safe_search_api:test_support",
@ -622,7 +623,7 @@ test("web_engine_browsertests") {
"//build/config/fuchsia/test/fonts.shard.test-cml",
"//build/config/fuchsia/test/mark_vmo_executable.shard.test-cml",
"//build/config/fuchsia/test/network.shard.test-cml",
"//build/config/fuchsia/test/gfx_test_ui_stack.shard.test-cml",
"//build/config/fuchsia/test/test_ui_stack.shard.test-cml",
"//third_party/fuchsia-sdk/sdk/pkg/vulkan/client.shard.cml",
]

@ -3,6 +3,7 @@
// found in the LICENSE file.
#include <fuchsia/element/cpp/fidl.h>
#include <lib/ui/scenic/cpp/view_creation_tokens.h>
#include <lib/ui/scenic/cpp/view_token_pair.h>
#include <lib/zx/time.h>
@ -12,6 +13,7 @@
#include "base/test/test_future.h"
#include "base/test/test_timeouts.h"
#include "build/build_config.h"
#include "components/fuchsia_component_support/annotations_manager.h"
#include "content/public/browser/navigation_handle.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/test_utils.h"
@ -131,9 +133,9 @@ class FrameImplTest : public FrameImplTestBase {
#define MAYBE_VisibilityState VisibilityState
#endif
IN_PROC_BROWSER_TEST_F(FrameImplTest, MAYBE_VisibilityState) {
// This test uses the `fuchsia.ui.gfx` variant of `Frame.CreateView*()`.
ASSERT_EQ(ui::OzonePlatform::GetInstance()->GetPlatformNameForTest(),
"scenic");
// This test uses the `fuchsia.ui.composition` variant of
// `Frame.CreateView*()`.
ASSERT_EQ(ui::OzonePlatform::GetPlatformNameForTest(), "flatland");
net::test_server::EmbeddedTestServerHandle test_server_handle;
ASSERT_TRUE(test_server_handle =
@ -158,16 +160,19 @@ IN_PROC_BROWSER_TEST_F(FrameImplTest, MAYBE_VisibilityState) {
// Query the document.visibilityState after creating the View, but without it
// actually "attached" to the view tree.
auto view_tokens = scenic::ViewTokenPair::New();
auto view_ref_pair = scenic::ViewRefPair::New();
frame->CreateViewWithViewRef(std::move(view_tokens.view_token),
std::move(view_ref_pair.control_ref),
CloneViewRef(view_ref_pair.view_ref));
scenic::ViewCreationTokenPair token_pair =
scenic::ViewCreationTokenPair::New();
fuchsia::web::CreateView2Args create_view_args;
create_view_args.set_view_creation_token(std::move(token_pair.view_token));
frame->CreateView2(std::move(create_view_args));
base::RunLoop().RunUntilIdle();
EXPECT_EQ(GetDocumentVisibilityState(frame.ptr().get()), "\"hidden\"");
// Attach the View to a Presenter, the page should be visible.
auto annotations_manager =
std::make_unique<fuchsia_component_support::AnnotationsManager>();
fuchsia::element::AnnotationControllerHandle annotation_controller;
annotations_manager->Connect(annotation_controller.NewRequest());
auto presenter = base::ComponentContextForProcess()
->svc()
->Connect<::fuchsia::element::GraphicalPresenter>();
@ -175,20 +180,22 @@ IN_PROC_BROWSER_TEST_F(FrameImplTest, MAYBE_VisibilityState) {
ZX_LOG(ERROR, status) << "GraphicalPresenter disconnected.";
ADD_FAILURE();
});
::fuchsia::element::ViewSpec view_spec;
view_spec.set_view_holder_token(std::move(view_tokens.view_holder_token));
view_spec.set_view_ref(std::move(view_ref_pair.view_ref));
::fuchsia::element::ViewControllerPtr view_controller;
presenter->PresentView(std::move(view_spec), nullptr,
fuchsia::element::ViewSpec view_spec;
view_spec.set_viewport_creation_token(std::move(token_pair.viewport_token));
view_spec.set_annotations({});
fuchsia::element::ViewControllerPtr view_controller;
presenter->PresentView(std::move(view_spec), std::move(annotation_controller),
view_controller.NewRequest(),
[](auto result) { EXPECT_FALSE(result.is_err()); });
frame.navigation_listener().RunUntilTitleEquals("visible");
// Detach the ViewController, causing the View to be detached.
// This is a regression test for crbug.com/1141093, verifying that the page
// receives a "not visible" event as a result.
view_controller->Dismiss();
frame.navigation_listener().RunUntilTitleEquals("hidden");
// TODO(fxbug.dev/114431): Flatland does not support dismissing a view through
// the ViewController.
// Detach the ViewController, causing the View to be
// detached. This is a regression test for crbug.com/1141093, verifying that
// the page receives a "not visible" event as a result.
// view_controller->Dismiss();
// frame.navigation_listener().RunUntilTitleEquals("hidden");
}
// Verifies that the browser will navigate and generate a navigation listener

@ -7,6 +7,7 @@
#include <lib/ui/scenic/cpp/view_ref_pair.h>
#include "fuchsia_web/webengine/web_engine_export.h"
#include "ui/aura/window_tree_host_platform.h"
#include "ui/platform_window/fuchsia/scenic_window_delegate.h"
@ -16,8 +17,9 @@ class WebContents;
// aura::WindowTreeHost implementation used to present web content inside
// web.Frame.
class FrameWindowTreeHost final : public aura::WindowTreeHostPlatform,
public ui::ScenicWindowDelegate {
class WEB_ENGINE_EXPORT FrameWindowTreeHost final
: public aura::WindowTreeHostPlatform,
public ui::ScenicWindowDelegate {
public:
using OnPixelScaleUpdateCallback = base::RepeatingCallback<void(float)>;

@ -23,6 +23,7 @@
#include "fuchsia_web/webengine/test/test_data.h"
#include "fuchsia_web/webengine/test/web_engine_browser_test.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/ozone/public/ozone_platform.h"
using fuchsia_input::Key;
using fuchsia_ui_input3::KeyEvent;
@ -193,6 +194,10 @@ class KeyboardInputTest : public WebEngineBrowserTest {
}
void SetUp() override {
if (ui::OzonePlatform::GetPlatformNameForTest() == "headless") {
GTEST_SKIP() << "Keyboard inputs are ignored in headless mode.";
}
scoped_feature_list_.InitWithFeatures({features::kKeyboardInput}, {});
WebEngineBrowserTest::SetUp();
}

@ -27,6 +27,7 @@
#include "fuchsia_web/webengine/test/test_data.h"
#include "fuchsia_web/webengine/test/web_engine_browser_test.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/ozone/public/ozone_platform.h"
namespace virtualkeyboard = fuchsia_input_virtualkeyboard;
@ -53,6 +54,10 @@ class VirtualKeyboardTest : public WebEngineBrowserTest {
~VirtualKeyboardTest() override = default;
void SetUp() override {
if (ui::OzonePlatform::GetPlatformNameForTest() == "headless") {
GTEST_SKIP() << "Keyboard inputs are ignored in headless mode.";
}
scoped_feature_list_.InitWithFeatures(
{features::kVirtualKeyboard, features::kKeyboardInput}, {});
WebEngineBrowserTest::SetUp();

@ -4,8 +4,8 @@
#include "fuchsia_web/webengine/test/scenic_test_helper.h"
#include <lib/ui/scenic/cpp/view_ref_pair.h>
#include <lib/ui/scenic/cpp/view_token_pair.h>
#include <fuchsia/web/cpp/fidl.h>
#include <lib/ui/scenic/cpp/view_creation_tokens.h>
#include "base/fuchsia/fuchsia_logging.h"
#include "base/run_loop.h"
@ -19,7 +19,7 @@ namespace {
const gfx::Rect kBounds = {1000, 1000};
} // namespace
ScenicTestHelper::ScenicTestHelper() {}
ScenicTestHelper::ScenicTestHelper() = default;
ScenicTestHelper::~ScenicTestHelper() = default;
// Simulate the creation of a Scenic View, except bypassing the actual
@ -27,19 +27,17 @@ ScenicTestHelper::~ScenicTestHelper() = default;
// StubWindow.
void ScenicTestHelper::CreateScenicView(FrameImpl* frame_impl,
fuchsia::web::FramePtr& frame) {
scenic::ViewRefPair view_ref_pair = scenic::ViewRefPair::New();
view_ref_ = std::move(view_ref_pair.view_ref);
fuchsia::ui::views::ViewRef view_ref_dup;
zx_status_t status = view_ref_.reference.duplicate(ZX_RIGHT_SAME_RIGHTS,
&view_ref_dup.reference);
ZX_CHECK(status == ZX_OK, status) << "zx_object_duplicate";
DCHECK(frame_impl);
frame_impl_ = frame_impl;
scenic::ViewCreationTokenPair token_pair =
scenic::ViewCreationTokenPair::New();
fuchsia::web::CreateView2Args create_view_args;
create_view_args.set_view_creation_token(std::move(token_pair.view_token));
frame->CreateView2(std::move(create_view_args));
auto view_tokens = scenic::ViewTokenPair::New();
frame->CreateViewWithViewRef(std::move(view_tokens.view_token),
std::move(view_ref_pair.control_ref),
std::move(view_ref_dup));
base::RunLoop().RunUntilIdle();
frame_impl->window_tree_host_for_test()->Show();
frame_impl_->window_tree_host_for_test()->Show();
}
void ScenicTestHelper::SetUpViewForInteraction(
@ -52,9 +50,6 @@ void ScenicTestHelper::SetUpViewForInteraction(
}
fuchsia::ui::views::ViewRef ScenicTestHelper::CloneViewRef() {
fuchsia::ui::views::ViewRef dup;
zx_status_t status =
view_ref_.reference.duplicate(ZX_RIGHT_SAME_RIGHTS, &dup.reference);
ZX_CHECK(status == ZX_OK, status) << "zx_object_duplicate";
return dup;
DCHECK(frame_impl_);
return frame_impl_->window_tree_host_for_test()->CreateViewRef();
}

@ -29,7 +29,7 @@ class ScenicTestHelper {
fuchsia::ui::views::ViewRef CloneViewRef();
protected:
fuchsia::ui::views::ViewRef view_ref_;
FrameImpl* frame_impl_;
};
#endif // FUCHSIA_WEB_WEBENGINE_TEST_SCENIC_TEST_HELPER_H_

@ -45,7 +45,6 @@ class WebEngineTestLauncherDelegate : public content::TestLauncherDelegate {
int main(int argc, char** argv) {
base::CommandLine::Init(argc, argv);
auto* command_line = base::CommandLine::ForCurrentProcess();
command_line->AppendSwitchASCII(switches::kOzonePlatform, "scenic");
command_line->AppendSwitchASCII(switches::kEnableLogging, "stderr");
// Indicate to all processes that they are being run as part of a browser