Revert of Update mojo sdk to rev 8af2ccff2eee4bfca1043015abee30482a030b30 (patchset...
[chromium-blink-merge.git] / content / browser / accessibility / dump_accessibility_browsertest_base.h
blob591d5b99f55a339a1e328c4b589d83ea58b57670
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include <string>
6 #include <vector>
8 #include "base/strings/string16.h"
9 #include "content/browser/accessibility/accessibility_tree_formatter.h"
10 #include "content/public/test/content_browser_test.h"
12 namespace content {
14 // Base class for an accessibility browsertest that takes an HTML file as
15 // input, loads it into a tab, dumps some accessibility data in text format,
16 // then compares that text to an expectation file in the same directory.
18 // The system was inspired by WebKit/Blink LayoutTests, but customized for
19 // testing accessibility in Chromium.
20 class DumpAccessibilityTestBase : public ContentBrowserTest {
21 public:
22 DumpAccessibilityTestBase();
23 ~DumpAccessibilityTestBase() override;
25 // Given a path to an HTML file relative to the test directory,
26 // loads the HTML, loads the accessibility tree, calls Dump(), then
27 // compares the output to the expected result and has the test succeed
28 // or fail based on the diff.
29 void RunTest(const base::FilePath file_path, const char* file_dir);
31 protected:
33 // For subclasses to override:
36 // This is called by RunTest after the document has finished loading,
37 // including the load complete accessibility event. The subclass should
38 // dump whatever that specific test wants to dump, returning the result
39 // as a sequence of strings.
40 virtual std::vector<std::string> Dump() = 0;
42 // Add the default filters that are applied to all tests.
43 virtual void AddDefaultFilters(
44 std::vector<AccessibilityTreeFormatter::Filter>* filters) = 0;
46 // This gets called if the diff didn't match; the test can print
47 // additional useful info.
48 virtual void OnDiffFailed() {}
51 // Helpers
54 // Dump the whole accessibility tree, without applying any filters,
55 // and return it as a string.
56 base::string16 DumpUnfilteredAccessibilityTreeAsString();
58 // Utility helper that does a comment-aware equality check.
59 // Returns array of lines from expected file which are different.
60 std::vector<int> DiffLines(const std::vector<std::string>& expected_lines,
61 const std::vector<std::string>& actual_lines);
63 // Parse the test html file and parse special directives, usually
64 // beginning with an '@' and inside an HTML comment, that control how the
65 // test is run and how the results are interpreted.
67 // When the accessibility tree is dumped as text, each attribute is
68 // run through filters before being appended to the string. An "allow"
69 // filter specifies attribute strings that should be dumped, and a "deny"
70 // filter specifies strings that should be suppressed. As an example,
71 // @MAC-ALLOW:AXSubrole=* means that the AXSubrole attribute should be
72 // printed, while @MAC-ALLOW:AXSubrole=AXList* means that any subrole
73 // beginning with the text "AXList" should be printed.
75 // The @WAIT-FOR:text directive allows the test to specify that the document
76 // may dynamically change after initial load, and the test is to wait
77 // until the given string (e.g., "text") appears in the resulting dump.
78 // A test can make some changes to the document, then append a magic string
79 // indicating that the test is done, and this framework will wait for that
80 // string to appear before comparing the results.
81 void ParseHtmlForExtraDirectives(
82 const std::string& test_html,
83 std::vector<AccessibilityTreeFormatter::Filter>* filters,
84 std::string* wait_for);
86 // The default filters plus the filters loaded from the test file.
87 std::vector<AccessibilityTreeFormatter::Filter> filters_;
90 } // namespace content