Commit 15b055de authored by Alexander Surkov's avatar Alexander Surkov Committed by Chromium LUCI CQ

a11y inspect scripting: special DumpAccessibilityTestBase implementation for platform scripts

Bug: 1136957
Change-Id: I8840cc3a469c55fbde6a7f78e1ce5158f5afa4c2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2637716
Commit-Queue: Alexander Surkov <asurkov@igalia.com>
Reviewed-by: default avatarDominic Mazzoni <dmazzoni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#845669}
parent b6868309
// Copyright (c) 2021 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 "base/files/file_util.h"
#include "build/build_config.h"
#include "content/browser/accessibility/dump_accessibility_browsertest_base.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/content_browser_test_utils.h"
#include "content/shell/browser/shell.h"
namespace content {
using ui::AXPropertyFilter;
using ui::AXTreeFormatter;
// See content/test/data/accessibility/readme.md for an overview.
//
// This test loads an HTML file, invokes a script, and then
// compares the script output against an expected baseline.
//
// The flow of the test is as outlined below.
// 1. Load an html file from content/test/data/accessibility.
// 2. Read the expectation.
// 3. Browse to the page, executes scripts and format their output.
// 4. Perform a comparison between actual and expected and fail if they do not
// exactly match.
class DumpAccessibilityScriptTest : public DumpAccessibilityTestBase {
public:
void AddDefaultFilters(
std::vector<AXPropertyFilter>* property_filters) override;
void AddPropertyFilter(
std::vector<AXPropertyFilter>* property_filters,
const std::string& filter,
AXPropertyFilter::Type type = AXPropertyFilter::ALLOW) {
property_filters->push_back(AXPropertyFilter(filter, type));
}
std::vector<std::string> Dump(std::vector<std::string>& unused) override {
std::unique_ptr<AXTreeFormatter> formatter(CreateFormatter());
// Set test provided property filters.
formatter->SetPropertyFilters(property_filters_,
AXTreeFormatter::kFiltersDefaultSet);
// No accessible tree nodes, just run scripts.
formatter->SetNodeFilters({{"*", "*"}});
std::string actual_contents =
formatter->Format(GetRootAccessibilityNode(shell()->web_contents()));
return base::SplitString(actual_contents, "\n", base::KEEP_WHITESPACE,
base::SPLIT_WANT_NONEMPTY);
}
void RunMacTextMarkerTest(const base::FilePath::CharType* file_path) {
base::FilePath test_path =
GetTestFilePath("accessibility", "mac/textmarker");
{
base::ScopedAllowBlockingForTesting allow_blocking;
ASSERT_TRUE(base::PathExists(test_path)) << test_path.LossyDisplayName();
}
base::FilePath html_file = test_path.Append(base::FilePath(file_path));
RunTest(html_file, "accessibility/mac/textmarker");
}
};
void DumpAccessibilityScriptTest::AddDefaultFilters(
std::vector<AXPropertyFilter>* property_filters) {}
// Parameterize the tests so that each test-pass is run independently.
struct TestPassToString {
std::string operator()(const ::testing::TestParamInfo<size_t>& i) const {
auto passes = DumpAccessibilityTestHelper::TestPasses();
CHECK_LT(i.param, passes.size());
return std::string(passes[i.param]);
}
};
//
// Scripting supported on Mac only.
//
#if defined(OS_MAC)
INSTANTIATE_TEST_SUITE_P(
All,
DumpAccessibilityScriptTest,
::testing::Values(
1), // mac tree formatter, see DumpAccessibilityTestHelper::TestPasses
TestPassToString());
IN_PROC_BROWSER_TEST_P(DumpAccessibilityScriptTest, AXStartTextMarker) {
RunMacTextMarkerTest(FILE_PATH_LITERAL("ax_start_text_marker.html"));
}
#endif
} // namespace content
...@@ -142,18 +142,6 @@ class DumpAccessibilityTreeTest : public DumpAccessibilityTestBase { ...@@ -142,18 +142,6 @@ class DumpAccessibilityTreeTest : public DumpAccessibilityTestBase {
RunTest(html_file, "accessibility/display-locking"); RunTest(html_file, "accessibility/display-locking");
} }
void RunMacTextMarkerTest(const base::FilePath::CharType* file_path) {
base::FilePath test_path =
GetTestFilePath("accessibility", "mac/textmarker");
{
base::ScopedAllowBlockingForTesting allow_blocking;
ASSERT_TRUE(base::PathExists(test_path)) << test_path.LossyDisplayName();
}
base::FilePath html_file = test_path.Append(base::FilePath(file_path));
RunTest(html_file, "accessibility/mac/textmarker");
}
void RunRegressionTest(const base::FilePath::CharType* file_path) { void RunRegressionTest(const base::FilePath::CharType* file_path) {
base::FilePath test_path = GetTestFilePath("accessibility", "regression"); base::FilePath test_path = GetTestFilePath("accessibility", "regression");
base::FilePath test_file = test_path.Append(base::FilePath(file_path)); base::FilePath test_file = test_path.Append(base::FilePath(file_path));
...@@ -2655,18 +2643,6 @@ IN_PROC_BROWSER_TEST_P(DumpAccessibilityTreeTest, DeleteSelectionCrash) { ...@@ -2655,18 +2643,6 @@ IN_PROC_BROWSER_TEST_P(DumpAccessibilityTreeTest, DeleteSelectionCrash) {
RunHtmlTest(FILE_PATH_LITERAL("delete-selection-crash.html")); RunHtmlTest(FILE_PATH_LITERAL("delete-selection-crash.html"));
} }
#if defined(OS_MAC)
//
// NSAccessibility specific tests
//
IN_PROC_BROWSER_TEST_P(DumpAccessibilityTreeTest, AXStartTextMarker) {
RunMacTextMarkerTest(FILE_PATH_LITERAL("AXStartTextMarker.html"));
}
#endif
// //
// DisplayLocking tests // DisplayLocking tests
// //
......
...@@ -976,6 +976,7 @@ test("content_browsertests") { ...@@ -976,6 +976,7 @@ test("content_browsertests") {
"../browser/accessibility/dump_accessibility_browsertest_base.cc", "../browser/accessibility/dump_accessibility_browsertest_base.cc",
"../browser/accessibility/dump_accessibility_browsertest_base.h", "../browser/accessibility/dump_accessibility_browsertest_base.h",
"../browser/accessibility/dump_accessibility_events_browsertest.cc", "../browser/accessibility/dump_accessibility_events_browsertest.cc",
"../browser/accessibility/dump_accessibility_scripts_browsertest.cc",
"../browser/accessibility/dump_accessibility_tree_browsertest.cc", "../browser/accessibility/dump_accessibility_tree_browsertest.cc",
"../browser/accessibility/fullscreen_browsertest.cc", "../browser/accessibility/fullscreen_browsertest.cc",
"../browser/accessibility/hit_testing_browsertest.cc", "../browser/accessibility/hit_testing_browsertest.cc",
......
<!-- <!--
@MAC-DENY-NODE:*=*
@MAC-SCRIPT:p.AXStartTextMarker @MAC-SCRIPT:p.AXStartTextMarker
--> -->
<!DOCTYPE html> <!DOCTYPE html>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment