Upstream version 9.37.195.0
[platform/framework/web/crosswalk.git] / src / content / browser / accessibility / dump_accessibility_tree_browsertest.cc
index 520215a..85169bd 100644 (file)
@@ -93,8 +93,27 @@ class DumpAccessibilityTreeTest : public ContentBrowserTest {
     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();
@@ -107,6 +126,7 @@ class DumpAccessibilityTreeTest : public ContentBrowserTest {
           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())),
@@ -119,6 +139,8 @@ class DumpAccessibilityTreeTest : public ContentBrowserTest {
         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());
       }
     }
   }
@@ -135,7 +157,7 @@ class DumpAccessibilityTreeTest : public ContentBrowserTest {
 
 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;
@@ -170,32 +192,52 @@ void DumpAccessibilityTreeTest::RunTest(
     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();
 
+  // 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);
@@ -288,10 +330,19 @@ IN_PROC_BROWSER_TEST_F(DumpAccessibilityTreeTest, AccessibilityAriaInvalid) {
   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"));
 }
@@ -506,6 +557,10 @@ IN_PROC_BROWSER_TEST_F(DumpAccessibilityTreeTest, AccessibilityTableSpans) {
   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"));