Commit 5ec739fd authored by Dominic Mazzoni's avatar Dominic Mazzoni Committed by Commit Bot

Re-land: Fix accessibility dump tree tests to not need an end-of-file sentinel.

Original: http://crrev.com/c/2109458
Reverted: http://crrev.com/c/2111771

This change depended on fixing all of the -expected*.txt files in
content/test/data/accessibility, but another one landed before this
one.

The DumpAccessibilityTree tests generate an output text file and diff
the results against an expected file. Previously, the way that the
algorithm handled files of different lengths was by adding an
end-of-file sentinel to the end. This resulted in that sentinel
getting checked in, which was just confusing.

Fix this by modifying the DiffLines helper function to properly compare
files that don't have the same number of lines. Add full unit tests for
DiffLines so we can be confident it works.

Continue to LOG the end-of-file sentinel, because it's needed by
running rebase_dump_accessibility_tree_test.py to parse actual output
files from remote logs.

Bug: 1063167
Tbr: aleventhal@chromium.org
Change-Id: I6c52bc77c3e4bb6e07d77971a5d748d9bf0d1f75
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2112116Reviewed-by: default avatarDominic Mazzoni <dmazzoni@chromium.org>
Commit-Queue: Dominic Mazzoni <dmazzoni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#751945}
parent cdb3b07a
...@@ -367,7 +367,6 @@ void DumpAccessibilityTestBase::RunTestForPlatform( ...@@ -367,7 +367,6 @@ void DumpAccessibilityTestBase::RunTestForPlatform(
} }
// Validate against the expectation file. // Validate against the expectation file.
actual_lines.push_back(kMarkEndOfFile);
bool matches_expectation = test_helper.ValidateAgainstExpectation( bool matches_expectation = test_helper.ValidateAgainstExpectation(
file_path, expected_file, actual_lines, *expected_lines); file_path, expected_file, actual_lines, *expected_lines);
EXPECT_TRUE(matches_expectation); EXPECT_TRUE(matches_expectation);
......
...@@ -19,9 +19,8 @@ namespace { ...@@ -19,9 +19,8 @@ namespace {
const char kCommentToken = '#'; const char kCommentToken = '#';
const char kMarkSkipFile[] = "#<skip"; const char kMarkSkipFile[] = "#<skip";
const char kSignalDiff[] = "*"; const char kSignalDiff[] = "*";
} // namespace
const char kMarkEndOfFile[] = "<-- End-of-file -->"; const char kMarkEndOfFile[] = "<-- End-of-file -->";
} // namespace
DumpAccessibilityTestHelper::DumpAccessibilityTestHelper( DumpAccessibilityTestHelper::DumpAccessibilityTestHelper(
AccessibilityTestExpectationsLocator* test_locator) AccessibilityTestExpectationsLocator* test_locator)
...@@ -80,10 +79,6 @@ DumpAccessibilityTestHelper::LoadExpectationFile( ...@@ -80,10 +79,6 @@ DumpAccessibilityTestHelper::LoadExpectationFile(
base::SplitString(expected_contents, "\n", base::KEEP_WHITESPACE, base::SplitString(expected_contents, "\n", base::KEEP_WHITESPACE,
base::SPLIT_WANT_NONEMPTY); base::SPLIT_WANT_NONEMPTY);
// Marking the end of the file with a line of text ensures that
// file length differences are found.
expected_lines.push_back(kMarkEndOfFile);
return expected_lines; return expected_lines;
} }
...@@ -123,6 +118,11 @@ bool DumpAccessibilityTestHelper::ValidateAgainstExpectation( ...@@ -123,6 +118,11 @@ bool DumpAccessibilityTestHelper::ValidateAgainstExpectation(
diff += "------\n"; diff += "------\n";
diff += base::JoinString(actual_lines, "\n"); diff += base::JoinString(actual_lines, "\n");
diff += "\n"; diff += "\n";
// This is used by rebase_dump_accessibility_tree_test.py to signify
// the end of the file when parsing the actual output from remote logs.
diff += kMarkEndOfFile;
diff += "\n";
LOG(ERROR) << "Diff:\n" << diff; LOG(ERROR) << "Diff:\n" << diff;
} else { } else {
LOG(INFO) << "Test output matches expectations."; LOG(INFO) << "Test output matches expectations.";
...@@ -163,6 +163,20 @@ std::vector<int> DumpAccessibilityTestHelper::DiffLines( ...@@ -163,6 +163,20 @@ std::vector<int> DumpAccessibilityTestHelper::DiffLines(
++j; ++j;
} }
// Report a failure if there are additional expected lines or
// actual lines.
if (i < actual_lines_count) {
diff_lines.push_back(j);
} else {
while (j < expected_lines_count) {
if (expected_lines[j].size() > 0 &&
expected_lines[j][0] != kCommentToken) {
diff_lines.push_back(j);
}
j++;
}
}
// Actual file has been fully checked. // Actual file has been fully checked.
return diff_lines; return diff_lines;
} }
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#ifndef CONTENT_PUBLIC_TEST_DUMP_ACCESSIBILITY_TEST_HELPER_H_ #ifndef CONTENT_PUBLIC_TEST_DUMP_ACCESSIBILITY_TEST_HELPER_H_
#define CONTENT_PUBLIC_TEST_DUMP_ACCESSIBILITY_TEST_HELPER_H_ #define CONTENT_PUBLIC_TEST_DUMP_ACCESSIBILITY_TEST_HELPER_H_
#include "base/gtest_prod_util.h"
#include "base/optional.h" #include "base/optional.h"
namespace base { namespace base {
...@@ -13,9 +14,6 @@ class FilePath; ...@@ -13,9 +14,6 @@ class FilePath;
namespace content { namespace content {
// Sentinal value to mark end of actual/expected results.
extern const char kMarkEndOfFile[];
class AccessibilityTestExpectationsLocator; class AccessibilityTestExpectationsLocator;
// A helper class for writing accessibility tree dump tests. // A helper class for writing accessibility tree dump tests.
...@@ -46,6 +44,8 @@ class DumpAccessibilityTestHelper { ...@@ -46,6 +44,8 @@ class DumpAccessibilityTestHelper {
const std::vector<std::string>& expected_lines); const std::vector<std::string>& expected_lines);
private: private:
FRIEND_TEST_ALL_PREFIXES(DumpAccessibilityTestHelperTest, TestDiffLines);
// Utility helper that does a comment-aware equality check. // Utility helper that does a comment-aware equality check.
// Returns array of lines from expected file which are different. // Returns array of lines from expected file which are different.
static std::vector<int> DiffLines( static std::vector<int> DiffLines(
......
// Copyright 2020 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 "content/public/test/dump_accessibility_test_helper.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
using testing::ElementsAre;
namespace content {
TEST(DumpAccessibilityTestHelperTest, TestDiffLines) {
// Files with the same lines should have an empty diff.
EXPECT_THAT(DumpAccessibilityTestHelper::DiffLines({"broccoli", "turnip"},
{"broccoli", "turnip"}),
ElementsAre());
// Empty files should have an empty diff.
EXPECT_THAT(DumpAccessibilityTestHelper::DiffLines({}, {}), ElementsAre());
// If one line differs, that line number should be returned as the diff.
EXPECT_THAT(DumpAccessibilityTestHelper::DiffLines({"broccoli", "turnip"},
{"watermelon", "turnip"}),
ElementsAre(0));
EXPECT_THAT(DumpAccessibilityTestHelper::DiffLines({"broccoli", "turnip"},
{"broccoli", "rutabaga"}),
ElementsAre(1));
// Multiple lines can differ.
EXPECT_THAT(DumpAccessibilityTestHelper::DiffLines(
{"broccoli", "turnip", "carrot", "squash"},
{"broccoli", "aspartame", "carrot", "toothbrush"}),
ElementsAre(1, 3));
// Blank lines in the expected file are allowed.
EXPECT_THAT(DumpAccessibilityTestHelper::DiffLines(
{"", "broccoli", "turnip", "carrot", "", "squash"},
{"broccoli", "turnip", "carrot", "squash"}),
ElementsAre());
// Comments in the expected file are allowed.
EXPECT_THAT(
DumpAccessibilityTestHelper::DiffLines(
{"#Vegetables:", "broccoli", "turnip", "carrot", "", "squash"},
{"broccoli", "turnip", "carrot", "squash"}),
ElementsAre());
// Comments or blank lines in the actual file are NOT allowed, that's a diff.
EXPECT_THAT(
DumpAccessibilityTestHelper::DiffLines(
{"broccoli", "turnip", "carrot", "squash"},
{"#vegetables", "broccoli", "turnip", "carrot", "", "squash"}),
ElementsAre(0, 1, 2, 3, 4));
// If the expected file has an extra line, that's a diff.
EXPECT_THAT(DumpAccessibilityTestHelper::DiffLines(
{"broccoli", "turnip", "cow"}, {"broccoli", "turnip"}),
ElementsAre(2));
// If the actual file has an extra line, that's a diff.
EXPECT_THAT(DumpAccessibilityTestHelper::DiffLines(
{"broccoli", "turnip"}, {"broccoli", "turnip", "horse"}),
ElementsAre(2));
// If the expected file has an extra blank line, that's okay.
EXPECT_THAT(DumpAccessibilityTestHelper::DiffLines({"broccoli", "turnip", ""},
{"broccoli", "turnip"}),
ElementsAre());
}
} // namespace content
...@@ -1916,6 +1916,7 @@ test("content_unittests") { ...@@ -1916,6 +1916,7 @@ test("content_unittests") {
"../public/common/url_utils_unittest.cc", "../public/common/url_utils_unittest.cc",
"../public/test/browser_task_environment_unittest.cc", "../public/test/browser_task_environment_unittest.cc",
"../public/test/devtools_permission_overrides_unittest.cc", "../public/test/devtools_permission_overrides_unittest.cc",
"../public/test/dump_accessibility_test_helper_unittest.cc",
"../public/test/no_renderer_crashes_assertion_unittest.cc", "../public/test/no_renderer_crashes_assertion_unittest.cc",
"../public/test/permission_type_unittest.cc", "../public/test/permission_type_unittest.cc",
"../public/test/referrer_unittest.cc", "../public/test/referrer_unittest.cc",
......
...@@ -3,4 +3,3 @@ AutomationFocusChanged on role=combobox ...@@ -3,4 +3,3 @@ AutomationFocusChanged on role=combobox
AutomationFocusChanged on role=combobox AutomationFocusChanged on role=combobox
AutomationFocusChanged on role=option, name=Orange AutomationFocusChanged on role=option, name=Orange
ExpandCollapseExpandCollapseState changed on role=combobox ExpandCollapseExpandCollapseState changed on role=combobox
<-- End-of-file -->
...@@ -5,4 +5,3 @@ AutomationFocusChanged on role=option, name=Apple ...@@ -5,4 +5,3 @@ AutomationFocusChanged on role=option, name=Apple
AutomationFocusChanged on role=option, name=Apple AutomationFocusChanged on role=option, name=Apple
ExpandCollapseExpandCollapseState changed on role=combobox ExpandCollapseExpandCollapseState changed on role=combobox
SelectionItem_ElementSelected on role=option, name=Apple SelectionItem_ElementSelected on role=option, name=Apple
<-- End-of-file -->
...@@ -11,4 +11,3 @@ AutomationFocusChanged on role=option, name=Banana ...@@ -11,4 +11,3 @@ AutomationFocusChanged on role=option, name=Banana
AutomationFocusChanged on role=option, name=Banana AutomationFocusChanged on role=option, name=Banana
AutomationFocusChanged on role=option, name=Orange AutomationFocusChanged on role=option, name=Orange
SelectionItem_ElementSelected on role=option, name=Banana SelectionItem_ElementSelected on role=option, name=Banana
<-- End-of-file -->
...@@ -4,4 +4,3 @@ AutomationFocusChanged on role=option, name=Apple ...@@ -4,4 +4,3 @@ AutomationFocusChanged on role=option, name=Apple
AutomationFocusChanged on role=option, name=Orange AutomationFocusChanged on role=option, name=Orange
AutomationFocusChanged on role=option, name=Orange AutomationFocusChanged on role=option, name=Orange
SelectionItem_ElementSelected on role=option, name=Orange SelectionItem_ElementSelected on role=option, name=Orange
<-- End-of-file -->
...@@ -2,4 +2,3 @@ AXFocusedUIElementChanged on AXPopUpButton AXValue="Apple" ...@@ -2,4 +2,3 @@ AXFocusedUIElementChanged on AXPopUpButton AXValue="Apple"
=== Start Continuation === === Start Continuation ===
AXSelectedChildrenChanged on AXMenu AXSelectedChildrenChanged on AXMenu
AXValueChanged on AXPopUpButton AXValueChanged on AXPopUpButton
<-- End-of-file -->
...@@ -4,4 +4,3 @@ AutomationFocusChanged on role=combobox ...@@ -4,4 +4,3 @@ AutomationFocusChanged on role=combobox
AriaProperties changed on role=listitem, name=Apple AriaProperties changed on role=listitem, name=Apple
SelectionItem_ElementRemovedFromSelection on role=listitem, name=Apple SelectionItem_ElementRemovedFromSelection on role=listitem, name=Apple
ValueValue changed on role=combobox ValueValue changed on role=combobox
<-- End-of-file -->
...@@ -5,4 +5,3 @@ AriaProperties changed on role=listitem, name=Apple ...@@ -5,4 +5,3 @@ AriaProperties changed on role=listitem, name=Apple
AutomationFocusChanged on role=combobox AutomationFocusChanged on role=combobox
SelectionItem_ElementRemovedFromSelection on role=listitem, name=Apple SelectionItem_ElementRemovedFromSelection on role=listitem, name=Apple
ValueValue changed on role=combobox ValueValue changed on role=combobox
<-- End-of-file -->
...@@ -4,4 +4,3 @@ EVENT_OBJECT_SELECTIONREMOVE on <option> role=ROLE_SYSTEM_LISTITEM name="Apple" ...@@ -4,4 +4,3 @@ EVENT_OBJECT_SELECTIONREMOVE on <option> role=ROLE_SYSTEM_LISTITEM name="Apple"
EVENT_OBJECT_SELECTIONWITHIN on role=ROLE_SYSTEM_LIST INVISIBLE SetSize=3 EVENT_OBJECT_SELECTIONWITHIN on role=ROLE_SYSTEM_LIST INVISIBLE SetSize=3
EVENT_OBJECT_STATECHANGE on <option> role=ROLE_SYSTEM_LISTITEM name="Apple" INVISIBLE,FOCUSABLE,SELECTABLE PosInSet=1 SetSize=3 EVENT_OBJECT_STATECHANGE on <option> role=ROLE_SYSTEM_LISTITEM name="Apple" INVISIBLE,FOCUSABLE,SELECTABLE PosInSet=1 SetSize=3
EVENT_OBJECT_VALUECHANGE on <select> role=ROLE_SYSTEM_COMBOBOX FOCUSED,COLLAPSED,FOCUSABLE,HASPOPUP SetSize=3 EVENT_OBJECT_VALUECHANGE on <select> role=ROLE_SYSTEM_COMBOBOX FOCUSED,COLLAPSED,FOCUSABLE,HASPOPUP SetSize=3
<-- End-of-file -->
...@@ -5,4 +5,3 @@ STATE-CHANGE:FOCUSED:TRUE role=ROLE_COMBO_BOX name='(null)' ENABLED,EXPANDABLE,F ...@@ -5,4 +5,3 @@ STATE-CHANGE:FOCUSED:TRUE role=ROLE_COMBO_BOX name='(null)' ENABLED,EXPANDABLE,F
=== Start Continuation === === Start Continuation ===
SELECTION-CHANGED role=ROLE_MENU name='(null)' ENABLED,SENSITIVE SELECTION-CHANGED role=ROLE_MENU name='(null)' ENABLED,SENSITIVE
STATE-CHANGE:SELECTED:TRUE role=ROLE_MENU_ITEM name='Orange' ENABLED,FOCUSABLE,SELECTABLE,SELECTED,SENSITIVE,SHOWING,VISIBLE STATE-CHANGE:SELECTED:TRUE role=ROLE_MENU_ITEM name='Orange' ENABLED,FOCUSABLE,SELECTABLE,SELECTED,SENSITIVE,SHOWING,VISIBLE
<-- End-of-file -->
\ No newline at end of file
...@@ -2,4 +2,3 @@ AXFocusedUIElementChanged on AXPopUpButton AXValue="Apple" ...@@ -2,4 +2,3 @@ AXFocusedUIElementChanged on AXPopUpButton AXValue="Apple"
=== Start Continuation === === Start Continuation ===
AXSelectedChildrenChanged on AXMenu AXSelectedChildrenChanged on AXMenu
AXValueChanged on AXPopUpButton AXValue="Orange" AXValueChanged on AXPopUpButton AXValue="Orange"
<-- End-of-file -->
\ No newline at end of file
...@@ -5,4 +5,3 @@ AriaProperties changed on role=listitem, name=Apple ...@@ -5,4 +5,3 @@ AriaProperties changed on role=listitem, name=Apple
AriaProperties changed on role=listitem, name=Orange AriaProperties changed on role=listitem, name=Orange
SelectionItem_ElementSelected on role=listitem, name=Orange SelectionItem_ElementSelected on role=listitem, name=Orange
ValueValue changed on role=combobox ValueValue changed on role=combobox
<-- End-of-file -->
...@@ -6,4 +6,3 @@ AriaProperties changed on role=listitem, name=Orange ...@@ -6,4 +6,3 @@ AriaProperties changed on role=listitem, name=Orange
AutomationFocusChanged on role=combobox AutomationFocusChanged on role=combobox
SelectionItem_ElementSelected on role=listitem, name=Orange SelectionItem_ElementSelected on role=listitem, name=Orange
ValueValue changed on role=combobox ValueValue changed on role=combobox
<-- End-of-file -->
...@@ -5,4 +5,3 @@ EVENT_OBJECT_SELECTIONWITHIN on role=ROLE_SYSTEM_LIST INVISIBLE SetSize=3 ...@@ -5,4 +5,3 @@ EVENT_OBJECT_SELECTIONWITHIN on role=ROLE_SYSTEM_LIST INVISIBLE SetSize=3
EVENT_OBJECT_STATECHANGE on <option> role=ROLE_SYSTEM_LISTITEM name="Apple" INVISIBLE,FOCUSABLE,SELECTABLE PosInSet=1 SetSize=3 EVENT_OBJECT_STATECHANGE on <option> role=ROLE_SYSTEM_LISTITEM name="Apple" INVISIBLE,FOCUSABLE,SELECTABLE PosInSet=1 SetSize=3
EVENT_OBJECT_STATECHANGE on <option> role=ROLE_SYSTEM_LISTITEM name="Orange" SELECTED,FOCUSABLE,SELECTABLE PosInSet=2 SetSize=3 EVENT_OBJECT_STATECHANGE on <option> role=ROLE_SYSTEM_LISTITEM name="Orange" SELECTED,FOCUSABLE,SELECTABLE PosInSet=2 SetSize=3
EVENT_OBJECT_VALUECHANGE on <select> role=ROLE_SYSTEM_COMBOBOX value="Orange" FOCUSED,COLLAPSED,FOCUSABLE,HASPOPUP SetSize=3 EVENT_OBJECT_VALUECHANGE on <select> role=ROLE_SYSTEM_COMBOBOX value="Orange" FOCUSED,COLLAPSED,FOCUSABLE,HASPOPUP SetSize=3
<-- End-of-file -->
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