Commit 21da926d authored by Alexander Surkov's avatar Alexander Surkov Committed by Commit Bot

DumpAccTree testing: test all possible incorrect parameters for parameterized attributes.

Bug: 1095619
Change-Id: Iff442fa0efdb30288648349c6bcfccb33dee3a7f
AX-Relnotes: n/a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2260393Reviewed-by: default avatarDominic Mazzoni <dmazzoni@chromium.org>
Commit-Queue: Alexander Surkov <asurkov@igalia.com>
Cr-Commit-Position: refs/heads/master@{#781952}
parent eeb03d31
...@@ -380,16 +380,14 @@ NSValue* AccessibilityTreeFormatterMac::PropertyNodeToRange( ...@@ -380,16 +380,14 @@ NSValue* AccessibilityTreeFormatterMac::PropertyNodeToRange(
base::Optional<int> loc = dictnode.FindIntKey("loc"); base::Optional<int> loc = dictnode.FindIntKey("loc");
if (!loc) { if (!loc) {
LOG(ERROR) << "Failed to parse " << propnode.original_property LOG(ERROR) << "Failed to parse " << propnode.original_property
<< " to NSRange: no loc key or loc key value " << " to NSRange: no loc or loc is not a number";
<< dictnode.name_or_value << " is not a number";
return nil; return nil;
} }
base::Optional<int> len = dictnode.FindIntKey("len"); base::Optional<int> len = dictnode.FindIntKey("len");
if (!len) { if (!len) {
LOG(ERROR) << "Failed to parse " << propnode.original_property LOG(ERROR) << "Failed to parse " << propnode.original_property
<< " to NSRange: no len key or len key value " << " to NSRange: no len or len is not a number";
<< dictnode.name_or_value << " is not a number";
return nil; return nil;
} }
......
...@@ -32,6 +32,12 @@ class AccessibilityTreeFormatterMacBrowserTest : public ContentBrowserTest { ...@@ -32,6 +32,12 @@ class AccessibilityTreeFormatterMacBrowserTest : public ContentBrowserTest {
const std::vector<const char*>& filters, const std::vector<const char*>& filters,
const char* expected) const; const char* expected) const;
// Tests wrong parameters for an attribute in a single run
void TestWrongParameters(const char* url,
const std::vector<const char*>& parameters,
const char* filter_pattern,
const char* expected_pattern) const;
protected: protected:
BrowserAccessibilityManager* GetManager() const { BrowserAccessibilityManager* GetManager() const {
WebContentsImpl* web_contents = WebContentsImpl* web_contents =
...@@ -79,6 +85,29 @@ void AccessibilityTreeFormatterMacBrowserTest::TestAndCheck( ...@@ -79,6 +85,29 @@ void AccessibilityTreeFormatterMacBrowserTest::TestAndCheck(
EXPECT_EQ(got, expected); EXPECT_EQ(got, expected);
} }
void AccessibilityTreeFormatterMacBrowserTest::TestWrongParameters(
const char* url,
const std::vector<const char*>& parameters,
const char* filter_pattern,
const char* expected_pattern) const {
std::string placeholder("Argument");
size_t expected_pos = std::string(expected_pattern).find(placeholder);
ASSERT_FALSE(expected_pos == std::string::npos);
size_t filter_pos = std::string(filter_pattern).find(placeholder);
ASSERT_FALSE(filter_pos == std::string::npos);
for (const char* parameter : parameters) {
std::string expected(expected_pattern);
expected.replace(expected_pos, placeholder.length(), parameter);
std::string filter(filter_pattern);
filter.replace(filter_pos, placeholder.length(), parameter);
TestAndCheck(url, {filter.c_str()}, expected.c_str());
}
}
} // namespace } // namespace
IN_PROC_BROWSER_TEST_F(AccessibilityTreeFormatterMacBrowserTest, IN_PROC_BROWSER_TEST_F(AccessibilityTreeFormatterMacBrowserTest,
...@@ -140,11 +169,12 @@ IN_PROC_BROWSER_TEST_F(AccessibilityTreeFormatterMacBrowserTest, ...@@ -140,11 +169,12 @@ IN_PROC_BROWSER_TEST_F(AccessibilityTreeFormatterMacBrowserTest,
} }
IN_PROC_BROWSER_TEST_F(AccessibilityTreeFormatterMacBrowserTest, IN_PROC_BROWSER_TEST_F(AccessibilityTreeFormatterMacBrowserTest,
ParameterizedAttributes_Int_WrongArgs) { ParameterizedAttributes_Int_WrongParameters) {
TestAndCheck(R"~~(data:text/html, TestWrongParameters(R"~~(data:text/html,
<p contentEditable='true'>Text</p>)~~", <p contentEditable='true'>Text</p>)~~",
{":2;AXLineForIndex(NaN)=*"}, R"~~(AXWebArea {"1, 2", "NaN"}, ":2;AXLineForIndex(Argument)=*",
++AXTextArea AXLineForIndex(NaN)=ERROR:FAILED_TO_PARSE_ARGS AXValue='Text' R"~~(AXWebArea
++AXTextArea AXLineForIndex(Argument)=ERROR:FAILED_TO_PARSE_ARGS AXValue='Text'
++++AXStaticText AXValue='Text' ++++AXStaticText AXValue='Text'
)~~"); )~~");
} }
...@@ -166,11 +196,22 @@ IN_PROC_BROWSER_TEST_F(AccessibilityTreeFormatterMacBrowserTest, ...@@ -166,11 +196,22 @@ IN_PROC_BROWSER_TEST_F(AccessibilityTreeFormatterMacBrowserTest,
} }
IN_PROC_BROWSER_TEST_F(AccessibilityTreeFormatterMacBrowserTest, IN_PROC_BROWSER_TEST_F(AccessibilityTreeFormatterMacBrowserTest,
ParameterizedAttributes_IntArray_WrongArgs) { ParameterizedAttributes_IntArray_NilValue) {
TestAndCheck(R"~~(data:text/html, TestAndCheck(R"~~(data:text/html,
<table role="grid"><tr><td>CELL</td></tr></table>)~~", <table role="grid"></table>)~~",
{"AXCellForColumnAndRow(0, 0)=*"}, R"~~(AXWebArea {"AXCellForColumnAndRow([0, 0])=*"}, R"~~(AXWebArea
++AXTable AXCellForColumnAndRow(0, 0)=ERROR:FAILED_TO_PARSE_ARGS ++AXTable AXCellForColumnAndRow([0, 0])=NULL
++++AXGroup
)~~");
}
IN_PROC_BROWSER_TEST_F(AccessibilityTreeFormatterMacBrowserTest,
ParameterizedAttributes_IntArray_WrongParameters) {
TestWrongParameters(R"~~(data:text/html,
<table role="grid"><tr><td>CELL</td></tr></table>)~~",
{"0, 0", "{1, 2}", "[1, NaN]", "[NaN, 1]"},
"AXCellForColumnAndRow(Argument)=*", R"~~(AXWebArea
++AXTable AXCellForColumnAndRow(Argument)=ERROR:FAILED_TO_PARSE_ARGS
++++AXRow ++++AXRow
++++++AXCell ++++++AXCell
++++++++AXStaticText AXValue='CELL' ++++++++AXStaticText AXValue='CELL'
...@@ -181,16 +222,6 @@ IN_PROC_BROWSER_TEST_F(AccessibilityTreeFormatterMacBrowserTest, ...@@ -181,16 +222,6 @@ IN_PROC_BROWSER_TEST_F(AccessibilityTreeFormatterMacBrowserTest,
)~~"); )~~");
} }
IN_PROC_BROWSER_TEST_F(AccessibilityTreeFormatterMacBrowserTest,
ParameterizedAttributes_IntArray_NilValue) {
TestAndCheck(R"~~(data:text/html,
<table role="grid"></table>)~~",
{"AXCellForColumnAndRow([0, 0])=*"}, R"~~(AXWebArea
++AXTable AXCellForColumnAndRow([0, 0])=NULL
++++AXGroup
)~~");
}
IN_PROC_BROWSER_TEST_F(AccessibilityTreeFormatterMacBrowserTest, IN_PROC_BROWSER_TEST_F(AccessibilityTreeFormatterMacBrowserTest,
ParameterizedAttributes_NSRange) { ParameterizedAttributes_NSRange) {
TestAndCheck(R"~~(data:text/html, TestAndCheck(R"~~(data:text/html,
...@@ -202,11 +233,13 @@ IN_PROC_BROWSER_TEST_F(AccessibilityTreeFormatterMacBrowserTest, ...@@ -202,11 +233,13 @@ IN_PROC_BROWSER_TEST_F(AccessibilityTreeFormatterMacBrowserTest,
} }
IN_PROC_BROWSER_TEST_F(AccessibilityTreeFormatterMacBrowserTest, IN_PROC_BROWSER_TEST_F(AccessibilityTreeFormatterMacBrowserTest,
ParameterizedAttributes_NSRAnge_WrongArgs) { ParameterizedAttributes_NSRange_WrongParameters) {
TestAndCheck(R"~~(data:text/html, TestWrongParameters(R"~~(data:text/html,
<p contentEditable='true'>Text</p>)~~", <p contentEditable='true'>Text</p>)~~",
{":2;AXStringForRange({loco: 1, leno: 2})=*"}, R"~~(AXWebArea {"1, 2", "[]", "{loc: 1, leno: 2}", "{loco: 1, len: 2}",
++AXTextArea AXStringForRange({loco: 1, leno: 2})=ERROR:FAILED_TO_PARSE_ARGS AXValue='Text' "{loc: NaN, len: 2}", "{loc: 2, len: NaN}"},
":2;AXStringForRange(Argument)=*", R"~~(AXWebArea
++AXTextArea AXStringForRange(Argument)=ERROR:FAILED_TO_PARSE_ARGS AXValue='Text'
++++AXStaticText AXValue='Text' ++++AXStaticText AXValue='Text'
)~~"); )~~");
} }
...@@ -222,11 +255,13 @@ IN_PROC_BROWSER_TEST_F(AccessibilityTreeFormatterMacBrowserTest, ...@@ -222,11 +255,13 @@ IN_PROC_BROWSER_TEST_F(AccessibilityTreeFormatterMacBrowserTest,
} }
IN_PROC_BROWSER_TEST_F(AccessibilityTreeFormatterMacBrowserTest, IN_PROC_BROWSER_TEST_F(AccessibilityTreeFormatterMacBrowserTest,
ParameterizedAttributes_UIElement_WrongArgs) { ParameterizedAttributes_UIElement_WrongParameters) {
TestAndCheck(R"~~(data:text/html, TestWrongParameters(R"~~(data:text/html,
<p contentEditable='true'>Text</p>)~~", <p contentEditable='true'>Text</p>)~~",
{":2;AXIndexForChildUIElement(:4)=*"}, R"~~(AXWebArea {"1, 2", "2", ":4"},
++AXTextArea AXIndexForChildUIElement(:4)=ERROR:FAILED_TO_PARSE_ARGS AXValue='Text' ":2;AXIndexForChildUIElement(Argument)=*",
R"~~(AXWebArea
++AXTextArea AXIndexForChildUIElement(Argument)=ERROR:FAILED_TO_PARSE_ARGS AXValue='Text'
++++AXStaticText AXValue='Text' ++++AXStaticText AXValue='Text'
)~~"); )~~");
} }
......
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