Index: content/browser/accessibility/dump_accessibility_browsertest_base.h |
diff --git a/content/browser/accessibility/dump_accessibility_browsertest_base.h b/content/browser/accessibility/dump_accessibility_browsertest_base.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..cc2a5a09d44e0cd14b24786e6b80fcc27633859a |
--- /dev/null |
+++ b/content/browser/accessibility/dump_accessibility_browsertest_base.h |
@@ -0,0 +1,88 @@ |
+// Copyright (c) 2014 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 <string> |
+#include <vector> |
+ |
+#include "base/strings/string16.h" |
+#include "content/browser/accessibility/accessibility_tree_formatter.h" |
+#include "content/public/test/content_browser_test.h" |
+ |
+namespace content { |
+ |
+// Base class for an accessibility browsertest that takes an HTML file as |
+// input, loads it into a tab, dumps some accessibility data in text format, |
+// then compares that text to an expectation file in the same directory. |
+// |
+// The system was inspired by WebKit/Blink LayoutTests, but customized for |
+// testing accessibility in Chromium. |
+class DumpAccessibilityTestBase : public ContentBrowserTest { |
+ public: |
+ // Given a path to an HTML file relative to the test directory, |
+ // loads the HTML, loads the accessibility tree, calls Dump(), then |
+ // compares the output to the expected result and has the test succeed |
+ // or fail based on the diff. |
+ void RunTest(const base::FilePath::CharType* file_path); |
+ |
+ protected: |
+ // |
+ // For subclasses to override: |
+ // |
+ |
+ // This is called by RunTest after the document has finished loading, |
+ // including the load complete accessibility event. The subclass should |
David Tseng
2014/12/17 01:03:32
Now that we test events, would we ever want to sta
dmazzoni
2014/12/17 07:04:51
Sure - not a super high priority for me right now
|
+ // dump whatever that specific test wants to dump, returning the result |
+ // as a sequence of strings. |
+ virtual std::vector<std::string> Dump() = 0; |
+ |
+ // Add the default filters that are applied to all tests. Each subclass |
+ // should override this. |
David Tseng
2014/12/17 01:03:32
Since this method is pure virtual, this comment is
dmazzoni
2014/12/17 07:04:50
Done.
|
+ virtual void AddDefaultFilters( |
+ std::vector<AccessibilityTreeFormatter::Filter>* filters) = 0; |
+ |
+ // This gets called if the diff didn't match; the test can print |
+ // additional useful info. |
+ virtual void AdditionalErrorLogging() {} |
David Tseng
2014/12/17 01:03:32
Name of this method should reflect the comment mor
dmazzoni
2014/12/17 07:04:51
Done.
|
+ |
+ // |
+ // Helpers |
+ // |
+ |
+ // Dump the whole accessibility tree, without applying any filters, |
+ // and return it as a string. |
+ base::string16 DumpUnfilteredAccessibilityTreeAsString(); |
+ |
+ // Utility helper that does a comment-aware equality check. |
+ // Returns array of lines from expected file which are different. |
+ std::vector<int> DiffLines(const std::vector<std::string>& expected_lines, |
+ const std::vector<std::string>& actual_lines); |
+ |
+ // Parse the test html file and parse special directives, usually |
+ // beginning with an '@' and inside an HTML comment, that control how the |
+ // test is run and how the results are interpreted. |
+ // |
+ // When the accessibility tree is dumped as text, each attribute is |
+ // run through filters before being appended to the string. An "allow" |
+ // filter specifies attribute strings that should be dumped, and a "deny" |
+ // filter specifies strings that should be suppressed. As an example, |
+ // @MAC-ALLOW:AXSubrole=* means that the AXSubrole attribute should be |
+ // printed, while @MAC-ALLOW:AXSubrole=AXList* means that any subrole |
+ // beginning with the text "AXList" should be printed. |
+ // |
+ // The @WAIT-FOR:text directive allows the test to specify that the document |
+ // may dynamically change after initial load, and the test is to wait |
+ // until the given string (e.g., "text") appears in the resulting dump. |
+ // A test can make some changes to the document, then append a magic string |
+ // indicating that the test is done, and this framework will wait for that |
+ // string to appear before comparing the results. |
+ void ParseHtmlForExtraDirectives( |
+ const std::string& test_html, |
+ std::vector<AccessibilityTreeFormatter::Filter>* filters, |
+ std::string* wait_for); |
+ |
+ // The default filters plus the filters loaded from the test file. |
+ std::vector<AccessibilityTreeFormatter::Filter> filters_; |
+}; |
+ |
+} // namespace content |