Skip to content
Permalink
Browse files

[fuchsia] Register Views with Fuchsia Accessibility APIs

* Add the AccessibilityBridge class skeleton, which will eventually
handle the logic for conversion between Chromium and Fuchsia
accessibility data structures.
* Register a ViewRef to the Fuchsia SemanticsManager.

Test: Added AccessibilityBridgeUnitTest.*

Bug: 973095
Change-Id: Ie8eb6a8cdd68e0082d3479b9b1288f8aaa68a600
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1708043
Commit-Queue: Sharon Yang <yangsharon@chromium.org>
Reviewed-by: Sergey Ulanov <sergeyu@chromium.org>
Reviewed-by: Wez <wez@chromium.org>
Cr-Commit-Position: refs/heads/master@{#693914}
  • Loading branch information
Sharon Yang Commit Bot
Sharon Yang authored and Commit Bot committed Sep 5, 2019
1 parent 8832bce commit b02a397f538eb408e18f2486686e23a294467bc1
@@ -85,6 +85,8 @@ component("web_engine_core") {
"//services/service_manager/sandbox",
"//skia/public/mojom",
"//third_party/blink/public/common",
"//third_party/fuchsia-sdk/sdk:accessibility_semantics",
"//third_party/fuchsia-sdk/sdk:math",
"//third_party/fuchsia-sdk/sdk:scenic_cpp",
"//third_party/fuchsia-sdk/sdk:sys_cpp",
"//third_party/fuchsia-sdk/sdk:web",
@@ -109,6 +111,8 @@ component("web_engine_core") {
]
configs += [ ":web_engine_implementation" ]
sources = [
"browser/accessibility_bridge.cc",
"browser/accessibility_bridge.h",
"browser/content_directory_loader_factory.cc",
"browser/content_directory_loader_factory.h",
"browser/context_impl.cc",
@@ -240,6 +244,7 @@ test("web_engine_browsertests") {

test("web_engine_unittests") {
sources = [
"browser/accessibility_bridge_unittest.cc",
"browser/cookie_manager_impl_unittest.cc",
"browser/frame_impl_unittest.cc",
"context_provider_impl_unittest.cc",
@@ -256,6 +261,7 @@ test("web_engine_unittests") {
"//services/network/public/mojom",
"//testing/gmock",
"//testing/gtest",
"//third_party/fuchsia-sdk/sdk:scenic_cpp",
"//third_party/fuchsia-sdk/sdk:web",
]
}
@@ -0,0 +1,35 @@
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "fuchsia/engine/browser/accessibility_bridge.h"

#include "base/logging.h"

AccessibilityBridge::AccessibilityBridge(
fuchsia::accessibility::semantics::SemanticsManagerPtr semantics_manager,
fuchsia::ui::views::ViewRef view_ref)
: binding_(this) {
semantics_manager->RegisterViewForSemantics(
std::move(view_ref), binding_.NewBinding(), tree_ptr_.NewRequest());
}

AccessibilityBridge::~AccessibilityBridge() = default;

void AccessibilityBridge::OnAccessibilityActionRequested(
uint32_t node_id,
fuchsia::accessibility::semantics::Action action,
OnAccessibilityActionRequestedCallback callback) {
NOTIMPLEMENTED();
}

void AccessibilityBridge::HitTest(fuchsia::math::PointF local_point,
HitTestCallback callback) {
NOTIMPLEMENTED();
}

void AccessibilityBridge::OnSemanticsModeChanged(
bool updates_enabled,
OnSemanticsModeChangedCallback callback) {
NOTIMPLEMENTED();
}
@@ -0,0 +1,47 @@
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef FUCHSIA_ENGINE_BROWSER_ACCESSIBILITY_BRIDGE_H_
#define FUCHSIA_ENGINE_BROWSER_ACCESSIBILITY_BRIDGE_H_

#include <fuchsia/accessibility/semantics/cpp/fidl.h>
#include <fuchsia/math/cpp/fidl.h>
#include <fuchsia/ui/views/cpp/fidl.h>
#include <lib/fidl/cpp/binding.h>

#include "base/macros.h"

// This class is the intermediate for accessibility between Chrome and Fuchsia.
// It handles registration to the Fuchsia Semantics Manager, translating events
// and data structures between the two services, and forwarding actions and
// events.
// The lifetime of an instance of AccessibilityBridge is the same as that of a
// View created by FrameImpl. This class refers to the View via the
// caller-supplied ViewRef.
class AccessibilityBridge
: public fuchsia::accessibility::semantics::SemanticListener {
public:
AccessibilityBridge(
fuchsia::accessibility::semantics::SemanticsManagerPtr semantics_manager,
fuchsia::ui::views::ViewRef view_ref);
~AccessibilityBridge() final;

private:
// fuchsia::accessibility::semantics::SemanticListener implementation.
void OnAccessibilityActionRequested(
uint32_t node_id,
fuchsia::accessibility::semantics::Action action,
OnAccessibilityActionRequestedCallback callback) final;
void HitTest(fuchsia::math::PointF local_point,
HitTestCallback callback) final;
void OnSemanticsModeChanged(bool updates_enabled,
OnSemanticsModeChangedCallback callback) final;

fuchsia::accessibility::semantics::SemanticTreePtr tree_ptr_;
fidl::Binding<fuchsia::accessibility::semantics::SemanticListener> binding_;

DISALLOW_COPY_AND_ASSIGN(AccessibilityBridge);
};

#endif // FUCHSIA_ENGINE_BROWSER_ACCESSIBILITY_BRIDGE_H_
@@ -0,0 +1,102 @@
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "fuchsia/engine/browser/accessibility_bridge.h"

#include <fuchsia/accessibility/semantics/cpp/fidl.h>
#include <fuchsia/accessibility/semantics/cpp/fidl_test_base.h>
#include <lib/sys/cpp/component_context.h>
#include <lib/ui/scenic/cpp/view_ref_pair.h>
#include <zircon/types.h>

#include "base/fuchsia/default_context.h"
#include "base/fuchsia/scoped_service_binding.h"
#include "base/fuchsia/service_directory_client.h"
#include "base/logging.h"
#include "base/test/task_environment.h"
#include "testing/gtest/include/gtest/gtest.h"

using fuchsia::accessibility::semantics::SemanticListener;
using fuchsia::accessibility::semantics::SemanticsManager;

namespace {

class FakeSemanticsManager : public fuchsia::accessibility::semantics::testing::
SemanticsManager_TestBase {
public:
explicit FakeSemanticsManager() = default;
~FakeSemanticsManager() override = default;

// fuchsia::accessibility::semantics::SemanticsManager implementation.
void RegisterViewForSemantics(
fuchsia::ui::views::ViewRef view_ref,
fidl::InterfaceHandle<SemanticListener> listener,
fidl::InterfaceRequest<fuchsia::accessibility::semantics::SemanticTree>
semantic_tree) final {
view_ref_ = std::move(view_ref);
listener_ = std::move(listener);
semantic_tree_ = std::move(semantic_tree);
}

bool is_view_registered() const { return view_ref_.reference.is_valid(); }

bool is_listener_handle_valid() const { return listener_.is_valid(); }

bool is_semantic_tree_handle_valid() const {
return semantic_tree_.is_valid();
}

void NotImplemented_(const std::string& name) final {
NOTIMPLEMENTED() << name;
}

private:
fuchsia::ui::views::ViewRef view_ref_;
fidl::InterfaceHandle<SemanticListener> listener_;
fidl::InterfaceRequest<fuchsia::accessibility::semantics::SemanticTree>
semantic_tree_;

DISALLOW_COPY_AND_ASSIGN(FakeSemanticsManager);
};

} // namespace

class AccessibilityBridgeTest : public testing::Test {
public:
AccessibilityBridgeTest()
: task_environment_(
base::test::ScopedTaskEnvironment::MainThreadType::IO),
semantics_manager_binding_(&semantics_manager_) {}
~AccessibilityBridgeTest() override = default;

void CreateAccessibilityBridge() {
auto view_ref_pair = scenic::ViewRefPair::New();
control_ref_ = std::move(view_ref_pair.control_ref);
fuchsia::accessibility::semantics::SemanticsManagerPtr
semantics_manager_ptr;
semantics_manager_binding_.Bind(semantics_manager_ptr.NewRequest());
accessibility_bridge_ = std::make_unique<AccessibilityBridge>(
std::move(semantics_manager_ptr), std::move(view_ref_pair.view_ref));
}

protected:
base::test::SingleThreadTaskEnvironment task_environment_;
std::unique_ptr<AccessibilityBridge> accessibility_bridge_;
FakeSemanticsManager semantics_manager_;
fidl::Binding<fuchsia::accessibility::semantics::SemanticsManager>
semantics_manager_binding_;
fuchsia::ui::views::ViewRefControl control_ref_;

DISALLOW_COPY_AND_ASSIGN(AccessibilityBridgeTest);
};

// Test registration to the SemanticsManager.
TEST_F(AccessibilityBridgeTest, RegisterViewRef) {
CreateAccessibilityBridge();
// Run loop so FIDL registration requests are processed.
task_environment_.RunUntilIdle();
EXPECT_TRUE(semantics_manager_.is_view_registered());
EXPECT_TRUE(semantics_manager_.is_listener_handle_valid());
EXPECT_TRUE(semantics_manager_.is_semantic_tree_handle_valid());
}

0 comments on commit b02a397

Please sign in to comment.
You can’t perform that action at this time.