Skip to content

Commit

Permalink
[ui][test] Fail loudly in scene provider error cases
Browse files Browse the repository at this point in the history
Bug: 112582
Test: ran tests in //src/ui/tests
Change-Id: I36c03453e9587801f0f3c446ea6d7f004504f7a6
Reviewed-on: https://fuchsia-review.googlesource.com/c/fuchsia/+/755102
Commit-Queue: Alexander Brusher <[email protected]>
Reviewed-by: Caroline Liu <[email protected]>
  • Loading branch information
abrush21 authored and CQ Bot committed Nov 8, 2022
1 parent 82f8395 commit bfda95c
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 39 deletions.
75 changes: 36 additions & 39 deletions src/ui/testing/scene_provider/scene_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ SceneProvider::SceneProvider(sys::ComponentContext* context) : context_(context)
auto scene_provider_config = scene_provider_config_lib::Config::TakeFromStartupHandle();
use_flatland_ = scene_provider_config.use_flatland();
use_scene_manager_ = scene_provider_config.use_scene_manager();

FX_CHECK(!use_flatland_ || use_scene_manager_) << "flatland x root presenter not supported";

if (use_scene_manager_) {
context_->svc()->Connect(scene_manager_.NewRequest());
} else {
context_->svc()->Connect(root_presenter_.NewRequest());
}
}

void SceneProvider::AttachClientView(
Expand All @@ -32,27 +40,19 @@ void SceneProvider::AttachClientView(
fuchsia::ui::views::ViewRef client_view_ref;

if (use_scene_manager_) {
fuchsia::session::scene::ManagerSyncPtr scene_manager;
context_->svc()->Connect(scene_manager.NewRequest());

fuchsia::session::scene::Manager_SetRootView_Result set_root_view_result;
scene_manager->SetRootView(std::move(*request.mutable_view_provider()), &set_root_view_result);
if (set_root_view_result.is_response()) {
client_view_ref = std::move(set_root_view_result.response().view_ref);
} else {
FX_LOGS(ERROR) << "Got a PresentRootViewError when trying to attach the client view";
}
scene_manager_->SetRootView(std::move(*request.mutable_view_provider()), &set_root_view_result);
FX_CHECK(set_root_view_result.is_response())
<< "Failed to attach client view due to internal error in scene manager";
client_view_ref = std::move(set_root_view_result.response().view_ref);
} else {
fuchsia::ui::policy::PresenterPtr root_presenter;
context_->svc()->Connect(root_presenter.NewRequest());

auto client_view_tokens = scenic::ViewTokenPair::New();
auto [client_control_ref, view_ref] = scenic::ViewRefPair::New();
client_view_ref = fidl::Clone(view_ref);

root_presenter->PresentOrReplaceView2(std::move(client_view_tokens.view_holder_token),
fidl::Clone(client_view_ref),
/* presentation */ nullptr);
root_presenter_->PresentOrReplaceView2(std::move(client_view_tokens.view_holder_token),
fidl::Clone(client_view_ref),
/* presentation */ nullptr);

auto client_view_provider = request.mutable_view_provider()->Bind();
client_view_provider->CreateViewWithViewRef(std::move(client_view_tokens.view_token.value),
Expand Down Expand Up @@ -96,30 +96,27 @@ void SceneProvider::PresentView(
// set. On flatland, it will have the `viewport_creation_token` field set.
// Any other combination thereof is invalid.
if (view_spec.has_view_ref() && view_spec.has_view_holder_token()) {
FX_CHECK(!use_flatland_)
<< "Client attempted to present a view using GFX tokens when flatland is enabled";
if (use_scene_manager_) {
fuchsia::session::scene::ManagerSyncPtr scene_manager;
context_->svc()->Connect(scene_manager.NewRequest());

fuchsia::session::scene::Manager_PresentRootViewLegacy_Result set_root_view_result;
scene_manager->PresentRootViewLegacy(std::move(*view_spec.mutable_view_holder_token()),
std::move(*view_spec.mutable_view_ref()),
&set_root_view_result);
} else {
fuchsia::ui::policy::PresenterPtr root_presenter;
context_->svc()->Connect(root_presenter.NewRequest());
root_presenter->PresentOrReplaceView2(std::move(*view_spec.mutable_view_holder_token()),
scene_manager_->PresentRootViewLegacy(std::move(*view_spec.mutable_view_holder_token()),
std::move(*view_spec.mutable_view_ref()),
/* presentation */ nullptr);
&set_root_view_result);
FX_CHECK(!set_root_view_result.is_err())
<< "Failed to present view due to internal error in scene manager";
} else {
root_presenter_->PresentOrReplaceView2(std::move(*view_spec.mutable_view_holder_token()),
std::move(*view_spec.mutable_view_ref()),
/* presentation */ nullptr);
}
} else if (view_spec.has_viewport_creation_token()) {
FX_CHECK(use_scene_manager_) << "Flatland not supported on root presenter";

fuchsia::session::scene::ManagerSyncPtr scene_manager;
context_->svc()->Connect(scene_manager.NewRequest());
FX_CHECK(use_flatland_)
<< "Client attempted to present a view using a flatland token when GFX is enabled";

fuchsia::session::scene::Manager_PresentRootView_Result set_root_view_result;
scene_manager->PresentRootView(std::move(*view_spec.mutable_viewport_creation_token()),
&set_root_view_result);
scene_manager_->PresentRootView(std::move(*view_spec.mutable_viewport_creation_token()),
&set_root_view_result);
} else {
FX_LOGS(FATAL) << "Invalid view spec";
}
Expand All @@ -140,19 +137,19 @@ SceneProvider::GetGraphicalPresenterHandler() {
}

void SceneProvider::DismissView() {
FX_CHECK(!use_flatland_)
<< "Dismissing views on flatland is not yet supported (fxbug.dev/114431)";

// Give the scene provider a new ViewHolderToken to drop the existing view.
auto client_view_tokens = scenic::ViewTokenPair::New();
auto [client_control_ref, client_view_ref] = scenic::ViewRefPair::New();
fuchsia::session::scene::ManagerSyncPtr scene_manager;
context_->svc()->Connect(scene_manager.NewRequest());

fuchsia::session::scene::Manager_PresentRootViewLegacy_Result set_root_view_result;

scene_manager->PresentRootViewLegacy(std::move(client_view_tokens.view_holder_token),
fidl::Clone(client_view_ref), &set_root_view_result);
if (set_root_view_result.is_err()) {
FX_LOGS(ERROR) << "Got a PresentRootViewLegacyError when trying to attach an empty view";
}
scene_manager_->PresentRootViewLegacy(std::move(client_view_tokens.view_holder_token),
fidl::Clone(client_view_ref), &set_root_view_result);
FX_CHECK(!set_root_view_result.is_err())
<< "Got a PresentRootViewLegacyError when trying to attach an empty view";
}

} // namespace ui_testing
4 changes: 4 additions & 0 deletions src/ui/testing/scene_provider/scene_provider.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
#define SRC_UI_TESTING_SCENE_PROVIDER_SCENE_PROVIDER_H_

#include <fuchsia/element/cpp/fidl.h>
#include <fuchsia/session/scene/cpp/fidl.h>
#include <fuchsia/ui/observation/test/cpp/fidl.h>
#include <fuchsia/ui/policy/cpp/fidl.h>
#include <fuchsia/ui/test/scene/cpp/fidl.h>
#include <lib/fidl/cpp/binding_set.h>
#include <lib/sys/cpp/component_context.h>
Expand Down Expand Up @@ -69,6 +71,8 @@ class SceneProvider : public fuchsia::ui::test::scene::Controller,
private:
fidl::BindingSet<fuchsia::ui::test::scene::Controller> scene_controller_bindings_;
fidl::BindingSet<fuchsia::element::GraphicalPresenter> graphical_presenter_bindings_;
fuchsia::session::scene::ManagerSyncPtr scene_manager_;
fuchsia::ui::policy::PresenterSyncPtr root_presenter_;
std::optional<FakeViewController> fake_view_controller_;
fuchsia::element::AnnotationControllerPtr annotation_controller_;
sys::ComponentContext* context_ = nullptr;
Expand Down

0 comments on commit bfda95c

Please sign in to comment.