diff options
Diffstat (limited to 'content')
10 files changed, 118 insertions, 39 deletions
diff --git a/content/browser/accessibility/dump_accessibility_tree_browsertest.cc b/content/browser/accessibility/dump_accessibility_tree_browsertest.cc index b915669..38cd454 100644 --- a/content/browser/accessibility/dump_accessibility_tree_browsertest.cc +++ b/content/browser/accessibility/dump_accessibility_tree_browsertest.cc @@ -67,6 +67,10 @@ IN_PROC_BROWSER_TEST_F(DumpAccessibilityTreeTest, EXPECT_TRUE(file_util::PathExists(test_path)) << test_path.LossyDisplayName(); + // Output the test path to help anyone who encounters a failure and needs + // to know where to look. + printf("Path to test files: %s\n", test_path.MaybeAsASCII().c_str()); + // Grab all HTML files. file_util::FileEnumerator file_enumerator(test_path, false, @@ -77,16 +81,24 @@ IN_PROC_BROWSER_TEST_F(DumpAccessibilityTreeTest, FilePath html_file(file_enumerator.Next()); ASSERT_FALSE(html_file.empty()); do { + printf("Testing %s\n", html_file.BaseName().MaybeAsASCII().c_str()); + std::string html_contents; file_util::ReadFileToString(html_file, &html_contents); - std::string expected_contents; + // Read the expected file. + std::string expected_contents_raw; FilePath expected_file = FilePath(html_file.RemoveExtension().value() + helper_.GetExpectedFileSuffix()); file_util::ReadFileToString( expected_file, - &expected_contents); + &expected_contents_raw); + + // Tolerate Windows-style line endings (\r\n) in the expected file: + // normalize by deleting all \r from the file (if any) to leave only \n. + std::string expected_contents; + RemoveChars(expected_contents_raw, "\r", &expected_contents); // Load the page. ui_test_utils::WindowedNotificationObserver tree_updated_observer( @@ -102,12 +114,16 @@ IN_PROC_BROWSER_TEST_F(DumpAccessibilityTreeTest, tree_updated_observer.Wait(); // Perform a diff (or write the initial baseline). - string16 actual_contents; + string16 actual_contents_utf16; helper_.DumpAccessibilityTree( host_view->GetBrowserAccessibilityManager()->GetRoot(), - &actual_contents); - std::string actual_contents8 = UTF16ToUTF8(actual_contents); - EXPECT_EQ(expected_contents, actual_contents8); + &actual_contents_utf16); + std::string actual_contents = UTF16ToUTF8(actual_contents_utf16); + EXPECT_TRUE(expected_contents == actual_contents); + if (expected_contents != actual_contents) { + printf("*** EXPECTED: ***\n%s\n", expected_contents.c_str()); + printf("*** ACTUAL: ***\n%s\n", actual_contents.c_str()); + } if (!file_util::PathExists(expected_file)) { FilePath actual_file = @@ -115,7 +131,7 @@ IN_PROC_BROWSER_TEST_F(DumpAccessibilityTreeTest, helper_.GetActualFileSuffix()); EXPECT_TRUE(file_util::WriteFile( - actual_file, actual_contents8.c_str(), actual_contents8.size())); + actual_file, actual_contents.c_str(), actual_contents.size())); ADD_FAILURE() << "No expectation found. Create it by doing:\n" << "mv " << actual_file.LossyDisplayName() << " " diff --git a/content/browser/accessibility/dump_accessibility_tree_helper.cc b/content/browser/accessibility/dump_accessibility_tree_helper.cc new file mode 100644 index 0000000..1d667c9 --- /dev/null +++ b/content/browser/accessibility/dump_accessibility_tree_helper.cc @@ -0,0 +1,30 @@ +// Copyright (c) 2012 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/browser/accessibility/dump_accessibility_tree_helper.h" + +#include "base/memory/scoped_ptr.h" + +namespace { +const int kIndentSpaces = 4; +} + +void DumpAccessibilityTreeHelper::DumpAccessibilityTree( + BrowserAccessibility* node, string16* contents) { + RecursiveDumpAccessibilityTree(node, contents, 0); +} + +void DumpAccessibilityTreeHelper::RecursiveDumpAccessibilityTree( + BrowserAccessibility* node, string16* contents, int indent) { + scoped_array<char> prefix(new char[indent + 1]); + for (int i = 0; i < indent; ++i) + prefix[i] = ' '; + prefix[indent] = '\0'; + + *contents += ToString(node, prefix.get()); + for (size_t i = 0; i < node->children().size(); ++i) { + RecursiveDumpAccessibilityTree(node->children()[i], contents, + indent + kIndentSpaces); + } +} diff --git a/content/browser/accessibility/dump_accessibility_tree_helper.h b/content/browser/accessibility/dump_accessibility_tree_helper.h index 9033206..314ef74 100644 --- a/content/browser/accessibility/dump_accessibility_tree_helper.h +++ b/content/browser/accessibility/dump_accessibility_tree_helper.h @@ -11,15 +11,13 @@ #include "content/browser/accessibility/browser_accessibility.h" // A utility class for retrieving platform specific accessibility information. +// This is extended by a subclass for each platform where accessibility is +// implemented. class DumpAccessibilityTreeHelper { public: // Dumps a BrowserAccessibility tree into a string. void DumpAccessibilityTree(BrowserAccessibility* node, - string16* contents) { - *contents += ToString(node) + GetLineEnding(); - for (size_t i = 0; i < node->children().size(); ++i) - DumpAccessibilityTree(node->children()[i], contents); - } + string16* contents); // Suffix of the expectation file corresponding to html file. // Example: @@ -29,12 +27,15 @@ class DumpAccessibilityTreeHelper { const FilePath::StringType GetActualFileSuffix() const; const FilePath::StringType GetExpectedFileSuffix() const; - // Line ending to use in our dump. - const string16 GetLineEnding() const; - protected: + void RecursiveDumpAccessibilityTree(BrowserAccessibility* node, + string16* contents, + int indent); + // Returns a platform specific representation of a BrowserAccessibility. - string16 ToString(BrowserAccessibility* node); + // Should be zero or more complete lines, each with |prefix| prepended + // (to indent each line). + string16 ToString(BrowserAccessibility* node, char* prefix); void Initialize(); }; diff --git a/content/browser/accessibility/dump_accessibility_tree_helper_mac.mm b/content/browser/accessibility/dump_accessibility_tree_helper_mac.mm index 949fe9c..6105adc 100644 --- a/content/browser/accessibility/dump_accessibility_tree_helper_mac.mm +++ b/content/browser/accessibility/dump_accessibility_tree_helper_mac.mm @@ -13,13 +13,16 @@ void DumpAccessibilityTreeHelper::Initialize() {} -string16 DumpAccessibilityTreeHelper::ToString(BrowserAccessibility* node) { +string16 DumpAccessibilityTreeHelper::ToString(BrowserAccessibility* node, + char* prefix) { BrowserAccessibilityCocoa* cocoa_node = node->toBrowserAccessibilityCocoa(); - NSString* dump = [NSString stringWithFormat:@"%@|%@|%@|%@", - [cocoa_node role], - [cocoa_node subrole], - [cocoa_node title], - [cocoa_node value]]; + NSString* dump = + [NSString stringWithFormat:@"%s%@ subrole=%@ title='%@' value='%@'\n", + prefix, + [cocoa_node role], + [cocoa_node subrole], + [cocoa_node title], + [cocoa_node value]]; std::string tempVal = [dump cStringUsingEncoding:NSUTF8StringEncoding]; return UTF8ToUTF16(tempVal); @@ -34,7 +37,3 @@ const FilePath::StringType DumpAccessibilityTreeHelper::GetExpectedFileSuffix() const { return FILE_PATH_LITERAL("-expected-mac.txt"); } - -const string16 DumpAccessibilityTreeHelper::GetLineEnding() const { - return UTF8ToUTF16("\n"); -} diff --git a/content/browser/accessibility/dump_accessibility_tree_helper_win.cc b/content/browser/accessibility/dump_accessibility_tree_helper_win.cc index 33dac19..05fc874 100644 --- a/content/browser/accessibility/dump_accessibility_tree_helper_win.cc +++ b/content/browser/accessibility/dump_accessibility_tree_helper_win.cc @@ -155,7 +155,8 @@ void DumpAccessibilityTreeHelper::Initialize() { // STATE_MAP(IA2_STATE_VERTICAL) // Untested. } -string16 DumpAccessibilityTreeHelper::ToString(BrowserAccessibility* node) { +string16 DumpAccessibilityTreeHelper::ToString( + BrowserAccessibility* node, char* prefix) { if (role_string_map.empty()) Initialize(); @@ -164,11 +165,16 @@ string16 DumpAccessibilityTreeHelper::ToString(BrowserAccessibility* node) { std::map<int32, string16>::iterator it; for (it = state_string_map.begin(); it != state_string_map.end(); ++it) { - if (it->first & acc_obj->ia2_state()) - state += it->second + L"|"; + if (it->first & acc_obj->ia2_state()) { + if (!state.empty()) + state += L","; + state += it->second; + } } - return acc_obj->name() + L"|" + role_string_map[acc_obj->ia2_role()] + L"|" + - state; + return UTF8ToUTF16(prefix) + + role_string_map[acc_obj->ia2_role()] + + L" name='" + acc_obj->name() + + L"' state=" + state + L"\n"; } const FilePath::StringType DumpAccessibilityTreeHelper::GetActualFileSuffix() @@ -180,7 +186,3 @@ const FilePath::StringType DumpAccessibilityTreeHelper::GetExpectedFileSuffix() const { return FILE_PATH_LITERAL("-expected-win.txt"); } - -const string16 DumpAccessibilityTreeHelper::GetLineEnding() const { - return L"\r\n"; -} diff --git a/content/test/data/accessibility/aria-application-expected-mac.txt b/content/test/data/accessibility/aria-application-expected-mac.txt index 9112096..c34bc90 100644 --- a/content/test/data/accessibility/aria-application-expected-mac.txt +++ b/content/test/data/accessibility/aria-application-expected-mac.txt @@ -1,2 +1,2 @@ -AXWebArea|(null)|| -AXGroup|AXLandmarkApplication|| +AXWebArea subrole=(null) title='' value='' + AXGroup subrole=AXLandmarkApplication title='' value='' diff --git a/content/test/data/accessibility/aria-application-expected-win.txt b/content/test/data/accessibility/aria-application-expected-win.txt index 4b2c02b..a2b8c49 100644 --- a/content/test/data/accessibility/aria-application-expected-win.txt +++ b/content/test/data/accessibility/aria-application-expected-win.txt @@ -1,2 +1,2 @@ -|ROLE_SYSTEM_DOCUMENT|IA2_STATE_OPAQUE|
-|IA2_ROLE_SECTION|IA2_STATE_OPAQUE|
+ROLE_SYSTEM_DOCUMENT name='' state=IA2_STATE_OPAQUE + IA2_ROLE_SECTION name='' state=IA2_STATE_OPAQUE diff --git a/content/test/data/accessibility/ul-expected-mac.txt b/content/test/data/accessibility/ul-expected-mac.txt new file mode 100644 index 0000000..361776f --- /dev/null +++ b/content/test/data/accessibility/ul-expected-mac.txt @@ -0,0 +1,11 @@ +AXWebArea subrole=(null) title='' value='' + AXList subrole=AXContentList title='' value='' + AXGroup subrole=(null) title='' value='' + AXGroup subrole=(null) title='' value='•' + AXStaticText subrole=(null) title='' value='Item 1' + AXGroup subrole=(null) title='' value='' + AXGroup subrole=(null) title='' value='•' + AXStaticText subrole=(null) title='' value='Item 2' + AXGroup subrole=(null) title='' value='' + AXGroup subrole=(null) title='' value='•' + AXStaticText subrole=(null) title='' value='Item 3' diff --git a/content/test/data/accessibility/ul-expected-win.txt b/content/test/data/accessibility/ul-expected-win.txt new file mode 100644 index 0000000..4d8a941 --- /dev/null +++ b/content/test/data/accessibility/ul-expected-win.txt @@ -0,0 +1,11 @@ +ROLE_SYSTEM_DOCUMENT name='' state=IA2_STATE_OPAQUE + ROLE_SYSTEM_LIST name='' state=IA2_STATE_OPAQUE + ROLE_SYSTEM_LISTITEM name='' state=IA2_STATE_OPAQUE + ROLE_SYSTEM_TEXT name='' state=IA2_STATE_OPAQUE + ROLE_SYSTEM_TEXT name='Item 1' state=IA2_STATE_OPAQUE + ROLE_SYSTEM_LISTITEM name='' state=IA2_STATE_OPAQUE + ROLE_SYSTEM_TEXT name='' state=IA2_STATE_OPAQUE + ROLE_SYSTEM_TEXT name='Item 2' state=IA2_STATE_OPAQUE + ROLE_SYSTEM_LISTITEM name='' state=IA2_STATE_OPAQUE + ROLE_SYSTEM_TEXT name='' state=IA2_STATE_OPAQUE + ROLE_SYSTEM_TEXT name='Item 3' state=IA2_STATE_OPAQUE diff --git a/content/test/data/accessibility/ul.html b/content/test/data/accessibility/ul.html new file mode 100644 index 0000000..4ba8a9c --- /dev/null +++ b/content/test/data/accessibility/ul.html @@ -0,0 +1,9 @@ +<html> +<body> +<ul> +<li>Item 1 +<li>Item 2 +<li>Item 3 +</ul> +</body> +</html> |