#include "content/browser/accessibility/browser_accessibility.h"
#include "content/browser/accessibility/browser_accessibility_manager.h"
#include "content/browser/renderer_host/render_view_host_impl.h"
-#include "content/port/browser/render_widget_host_view_port.h"
+#include "content/browser/renderer_host/render_widget_host_view_base.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/content_paths.h"
#include "content/public/common/content_switches.h"
filters->push_back(Filter(base::ASCIIToUTF16("*=''"), Filter::DENY));
}
- void ParseFilters(const std::string& test_html,
- std::vector<Filter>* filters) {
+ // 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<Filter>* filters,
+ std::string* wait_for) {
std::vector<std::string> lines;
base::SplitString(test_html, '\n', &lines);
for (std::vector<std::string>::const_iterator iter = lines.begin();
AccessibilityTreeFormatter::GetAllowString();
const std::string& deny_str =
AccessibilityTreeFormatter::GetDenyString();
+ const std::string& wait_str = "@WAIT-FOR:";
if (StartsWithASCII(line, allow_empty_str, true)) {
filters->push_back(
Filter(base::UTF8ToUTF16(line.substr(allow_empty_str.size())),
filters->push_back(Filter(base::UTF8ToUTF16(
line.substr(deny_str.size())),
Filter::DENY));
+ } else if (StartsWithASCII(line, wait_str, true)) {
+ *wait_for = line.substr(wait_str.size());
}
}
}
void DumpAccessibilityTreeTest::RunTest(
const base::FilePath::CharType* file_path) {
- NavigateToURL(shell(), GURL(kAboutBlankURL));
+ NavigateToURL(shell(), GURL(url::kAboutBlankURL));
// Setup test paths.
base::FilePath dir_test_data;
return;
}
+ // Parse filters and other directives in the test file.
+ std::vector<Filter> filters;
+ std::string wait_for;
+ AddDefaultFilters(&filters);
+ ParseHtmlForExtraDirectives(html_contents, &filters, &wait_for);
+
// Load the page.
base::string16 html_contents16;
html_contents16 = base::UTF8ToUTF16(html_contents);
GURL url = GetTestUrl("accessibility",
html_file.BaseName().MaybeAsASCII().c_str());
- AccessibilityNotificationWaiter waiter(
- shell(), AccessibilityModeComplete,
- ui::AX_EVENT_LOAD_COMPLETE);
+
+ // If there's a @WAIT-FOR directive, set up an accessibility notification
+ // waiter that returns on any event; we'll stop when we get the text we're
+ // waiting for, or time out. Otherwise just wait specifically for
+ // the "load complete" event.
+ scoped_ptr<AccessibilityNotificationWaiter> waiter;
+ if (!wait_for.empty()) {
+ waiter.reset(new AccessibilityNotificationWaiter(
+ shell(), AccessibilityModeComplete, ui::AX_EVENT_NONE));
+ } else {
+ waiter.reset(new AccessibilityNotificationWaiter(
+ shell(), AccessibilityModeComplete, ui::AX_EVENT_LOAD_COMPLETE));
+ }
+
+ // Load the test html.
NavigateToURL(shell(), url);
- waiter.WaitForNotification();
- RenderWidgetHostViewPort* host_view = RenderWidgetHostViewPort::FromRWHV(
+ // Wait for notifications. If there's a @WAIT-FOR directive, break when
+ // the text we're waiting for appears in the dump, otherwise break after
+ // the first notification, which will be a load complete.
+ RenderWidgetHostViewBase* host_view = static_cast<RenderWidgetHostViewBase*>(
shell()->web_contents()->GetRenderWidgetHostView());
- AccessibilityTreeFormatter formatter(
- host_view->GetBrowserAccessibilityManager()->GetRoot());
-
- // Parse filters in the test file.
- std::vector<Filter> filters;
- AddDefaultFilters(&filters);
- ParseFilters(html_contents, &filters);
- formatter.SetFilters(filters);
+ std::string actual_contents;
+ do {
+ waiter->WaitForNotification();
+ base::string16 actual_contents_utf16;
+ AccessibilityTreeFormatter formatter(
+ host_view->GetBrowserAccessibilityManager()->GetRoot());
+ formatter.SetFilters(filters);
+ formatter.FormatAccessibilityTree(&actual_contents_utf16);
+ actual_contents = base::UTF16ToUTF8(actual_contents_utf16);
+ } while (!wait_for.empty() &&
+ actual_contents.find(wait_for) == std::string::npos);
// Perform a diff (or write the initial baseline).
- base::string16 actual_contents_utf16;
- formatter.FormatAccessibilityTree(&actual_contents_utf16);
- std::string actual_contents = base::UTF16ToUTF8(actual_contents_utf16);
std::vector<std::string> actual_lines, expected_lines;
Tokenize(actual_contents, "\n", &actual_lines);
Tokenize(expected_contents, "\n", &expected_lines);
RunTest(FILE_PATH_LITERAL("a-name.html"));
}
+IN_PROC_BROWSER_TEST_F(DumpAccessibilityTreeTest, AccessibilityANoText) {
+ RunTest(FILE_PATH_LITERAL("a-no-text.html"));
+}
+
IN_PROC_BROWSER_TEST_F(DumpAccessibilityTreeTest, AccessibilityAOnclick) {
RunTest(FILE_PATH_LITERAL("a-onclick.html"));
}
RunTest(FILE_PATH_LITERAL("aria-invalid.html"));
}
+IN_PROC_BROWSER_TEST_F(DumpAccessibilityTreeTest,
+ AccessibilityAriaLabelledByHeading) {
+ RunTest(FILE_PATH_LITERAL("aria-labelledby-heading.html"));
+}
+
IN_PROC_BROWSER_TEST_F(DumpAccessibilityTreeTest, AccessibilityAriaLevel) {
RunTest(FILE_PATH_LITERAL("aria-level.html"));
}
+IN_PROC_BROWSER_TEST_F(DumpAccessibilityTreeTest, AccessibilityAriaList) {
+ RunTest(FILE_PATH_LITERAL("aria-list.html"));
+}
+
IN_PROC_BROWSER_TEST_F(DumpAccessibilityTreeTest, AccessibilityAriaMenu) {
RunTest(FILE_PATH_LITERAL("aria-menu.html"));
}
RunTest(FILE_PATH_LITERAL("hr.html"));
}
-// crbug.com/179717 and crbug.com/224659
IN_PROC_BROWSER_TEST_F(DumpAccessibilityTreeTest,
- DISABLED_AccessibilityIframeCoordinates) {
+ AccessibilityIframeCoordinates) {
RunTest(FILE_PATH_LITERAL("iframe-coordinates.html"));
}
RunTest(FILE_PATH_LITERAL("modal-dialog-in-iframe-closed.html"));
}
-// TODO(dmazzoni): fix this test after Blink change that broke it lands.
-// http://crbug.com/353067
IN_PROC_BROWSER_TEST_F(DumpAccessibilityTreeTest,
- DISABLED_AccessibilityModalDialogInIframeOpened) {
+ AccessibilityModalDialogInIframeOpened) {
RunTest(FILE_PATH_LITERAL("modal-dialog-in-iframe-opened.html"));
}
RunTest(FILE_PATH_LITERAL("table-spans.html"));
}
+IN_PROC_BROWSER_TEST_F(DumpAccessibilityTreeTest, AccessibilityTransition) {
+ RunTest(FILE_PATH_LITERAL("transition.html"));
+}
+
IN_PROC_BROWSER_TEST_F(DumpAccessibilityTreeTest,
AccessibilityToggleButton) {
RunTest(FILE_PATH_LITERAL("togglebutton.html"));
RunTest(FILE_PATH_LITERAL("wbr.html"));
}
+IN_PROC_BROWSER_TEST_F(DumpAccessibilityTreeTest,
+ AccessibilityAriaActivedescendant) {
+ RunTest(FILE_PATH_LITERAL("aria-activedescendant.html"));
+}
+
} // namespace content