From 993488a28d0141c8b9c7a05293cec782c11242c2 Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Tue, 16 Aug 2022 14:32:48 -0700 Subject: [PATCH] [Mac] Add test for AXPlatformNodeCocoa (flutter/engine#35437) Adds an initial test of looking up the macOS-specific AXPlatformNodeMac C++ node wrapper and the AXPlatformNodeCocoa Objective-C wrapper, in addition to the existing platform-agnostic accessibility tests that run on macOS today. This is initial test infrastructure to support authoring tests for an upcoming fix to the issue below. Issue: https://github.com/flutter/flutter/issues/102416 --- .../ci/licenses_golden/licenses_flutter | 2 + .../third_party/accessibility/BUILD.gn | 13 +++++ .../platform/ax_platform_node_mac_unittest.h | 29 +++++++++++ .../platform/ax_platform_node_mac_unittest.mm | 49 +++++++++++++++++++ 4 files changed, 93 insertions(+) create mode 100644 engine/src/flutter/third_party/accessibility/ax/platform/ax_platform_node_mac_unittest.h create mode 100644 engine/src/flutter/third_party/accessibility/ax/platform/ax_platform_node_mac_unittest.mm diff --git a/engine/src/flutter/ci/licenses_golden/licenses_flutter b/engine/src/flutter/ci/licenses_golden/licenses_flutter index 02b295d603..35ee303be2 100644 --- a/engine/src/flutter/ci/licenses_golden/licenses_flutter +++ b/engine/src/flutter/ci/licenses_golden/licenses_flutter @@ -3258,6 +3258,8 @@ ORIGIN: ../../../third_party/icu/scripts/LICENSE TYPE: LicenseType.bsd FILE: ../../../flutter/third_party/accessibility/ax/ax_tree_data.cc FILE: ../../../flutter/third_party/accessibility/ax/ax_tree_data.h +FILE: ../../../flutter/third_party/accessibility/ax/platform/ax_platform_node_mac_unittest.h +FILE: ../../../flutter/third_party/accessibility/ax/platform/ax_platform_node_mac_unittest.mm FILE: ../../../flutter/third_party/accessibility/ax/platform/ax_platform_node_win.cc FILE: ../../../flutter/third_party/accessibility/ax/platform/ax_platform_node_win.h FILE: ../../../flutter/third_party/accessibility/ax/platform/ax_platform_node_win_unittest.cc diff --git a/engine/src/flutter/third_party/accessibility/BUILD.gn b/engine/src/flutter/third_party/accessibility/BUILD.gn index 469849c819..eb217af52f 100644 --- a/engine/src/flutter/third_party/accessibility/BUILD.gn +++ b/engine/src/flutter/third_party/accessibility/BUILD.gn @@ -75,6 +75,19 @@ if (enable_unittests) { "ax/platform/test_ax_node_wrapper.h", ] + if (is_mac) { + sources += [ "ax/platform/ax_platform_node_mac_unittest.mm" ] + frameworks = [ + "AppKit.framework", + "CoreFoundation.framework", + "CoreGraphics.framework", + "CoreText.framework", + "IOSurface.framework", + ] + + cflags_objcc = flutter_cflags_objcc + ldflags = [ "-ObjC" ] + } if (is_win) { sources += [ "ax/platform/ax_fragment_root_win_unittest.cc", diff --git a/engine/src/flutter/third_party/accessibility/ax/platform/ax_platform_node_mac_unittest.h b/engine/src/flutter/third_party/accessibility/ax/platform/ax_platform_node_mac_unittest.h new file mode 100644 index 0000000000..96c34ebb0d --- /dev/null +++ b/engine/src/flutter/third_party/accessibility/ax/platform/ax_platform_node_mac_unittest.h @@ -0,0 +1,29 @@ +// Copyright 2015 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 UI_ACCESSIBILITY_PLATFORM_AX_PLATFORM_NODE_MAC_UNITTEST_H_ +#define UI_ACCESSIBILITY_PLATFORM_AX_PLATFORM_NODE_MAC_UNITTEST_H_ + +#include "ax_platform_node_mac.h" +#include "ax_platform_node_unittest.h" + +namespace ui { + +// A test fixture that supports accessing the macOS-specific node +// implementations for the AXTree under test. +class AXPlatformNodeMacTest : public AXPlatformNodeTest { + public: + AXPlatformNodeMacTest(); + ~AXPlatformNodeMacTest() override; + + void SetUp() override; + void TearDown() override; + + protected: + AXPlatformNode* AXPlatformNodeFromNode(AXNode* node); +}; + +} // namespace ui + +#endif // UI_ACCESSIBILITY_PLATFORM_AX_PLATFORM_NODE_MAC_UNITTEST_H_ diff --git a/engine/src/flutter/third_party/accessibility/ax/platform/ax_platform_node_mac_unittest.mm b/engine/src/flutter/third_party/accessibility/ax/platform/ax_platform_node_mac_unittest.mm new file mode 100644 index 0000000000..7597942518 --- /dev/null +++ b/engine/src/flutter/third_party/accessibility/ax/platform/ax_platform_node_mac_unittest.mm @@ -0,0 +1,49 @@ +// Copyright 2015 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 "ax_platform_node_mac_unittest.h" + +#include "ax_platform_node_mac.h" +#include "gtest/gtest.h" +#include "test_ax_node_wrapper.h" +#include "third_party/accessibility/ax/ax_node_data.h" + +namespace ui { + +AXPlatformNodeMacTest::AXPlatformNodeMacTest() = default; + +AXPlatformNodeMacTest::~AXPlatformNodeMacTest() = default; + +void AXPlatformNodeMacTest::SetUp() {} + +void AXPlatformNodeMacTest::TearDown() { + // Destroy the tree and make sure we're not leaking any objects. + DestroyTree(); + TestAXNodeWrapper::SetGlobalIsWebContent(false); + ASSERT_EQ(0U, AXPlatformNodeBase::GetInstanceCountForTesting()); +} + +AXPlatformNode* AXPlatformNodeMacTest::AXPlatformNodeFromNode(AXNode* node) { + const TestAXNodeWrapper* wrapper = TestAXNodeWrapper::GetOrCreate(GetTree(), node); + return wrapper ? wrapper->ax_platform_node() : nullptr; +} + +// Verify that we can get an AXPlatformNodeMac and AXPlatformNodeCocoa from the tree. +TEST_F(AXPlatformNodeMacTest, CanGetCocoaPlatformNodeFromTree) { + AXNodeData root; + root.id = 1; + root.relative_bounds.bounds = gfx::RectF(0, 0, 40, 40); + + Init(root); + AXNode* root_node = GetRootAsAXNode(); + ASSERT_TRUE(root_node != nullptr); + + AXPlatformNode* platform_node = AXPlatformNodeFromNode(root_node); + ASSERT_TRUE(platform_node != nullptr); + + AXPlatformNodeCocoa* native_root = platform_node->GetNativeViewAccessible(); + EXPECT_TRUE(native_root != nullptr); +} + +} // namespace ui