diff options
author | vandebo@chromium.org <vandebo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-02-24 01:31:05 +0000 |
---|---|---|
committer | vandebo@chromium.org <vandebo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-02-24 01:31:05 +0000 |
commit | bc95a82163a28b9bf5b17685321a9bf8d6b55113 (patch) | |
tree | 54ced776da79eb5dcfe07b1edcbacf9fc7bb1fd9 /chrome | |
parent | adbfb8df4c5d8b870ce5fbeb31d98734315c7f86 (diff) | |
download | chromium_src-bc95a82163a28b9bf5b17685321a9bf8d6b55113.zip chromium_src-bc95a82163a28b9bf5b17685321a9bf8d6b55113.tar.gz chromium_src-bc95a82163a28b9bf5b17685321a9bf8d6b55113.tar.bz2 |
Revert 123372 - Adds deps file for content/browser/accessibility/
DumpAccessibilityTreeTest.PlatformTreeDifferenceTest fails:
..\content\browser\accessibility\dump_accessibility_tree_browsertest.cc(106): error: Value of: actual_contents8
Actual: "|ROLE_SYSTEM_DOCUMENT||IA2_STATE_HORIZONTAL|IA2_STATE_OPAQUE\n|IA2_ROLE_SECTION||IA2_STATE_HORIZONTAL|IA2_STATE_OPAQUE\n"
Expected: expected_contents
Which is: "|ROLE_SYSTEM_DOCUMENT||IA2_STATE_OPAQUE|IA2_STATE_VERTICAL\n|IA2_ROLE_SECTION||IA2_STATE_HORIZONTAL|IA2_STATE_OPAQUE\n"
Revert "Revert 122617 - Adds dump accessibility tree support in Windows."
This reverts commit ca8de581137b34eb04ca8b68186f143d4bea98e8.
BUG=
TEST=
Review URL: http://codereview.chromium.org/9429026
TBR=dtseng@chromium.org
Review URL: https://chromiumcodereview.appspot.com/9454033
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@123390 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
4 files changed, 151 insertions, 6 deletions
diff --git a/chrome/browser/accessibility/dump_accessibility_tree_browsertest.cc b/chrome/browser/accessibility/dump_accessibility_tree_browsertest.cc new file mode 100644 index 0000000..16e71ad --- /dev/null +++ b/chrome/browser/accessibility/dump_accessibility_tree_browsertest.cc @@ -0,0 +1,141 @@ +// 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 <string> + +#include "base/logging.h" +#include "base/path_service.h" +#include "base/string_util.h" +#include "chrome/browser/ui/browser.h" +#include "chrome/common/chrome_paths.h" +#include "chrome/test/base/in_process_browser_test.h" +#include "chrome/test/base/ui_test_utils.h" +#include "content/browser/accessibility/browser_accessibility.h" +#include "content/browser/accessibility/browser_accessibility_manager.h" +#include "content/browser/renderer_host/render_view_host.h" +#include "content/browser/renderer_host/render_widget_host.h" +#include "content/public/browser/notification_service.h" +#include "content/public/browser/notification_types.h" +#include "content/public/browser/render_widget_host_view.h" +#include "content/public/browser/web_contents.h" +#include "testing/gtest/include/gtest/gtest.h" +#include "ui/base/resource/resource_bundle.h" + +using content::OpenURLParams; +using content::Referrer; + +// Suffix of the expectation file corresponding to html file. +// Example: +// HTML test: test-file.html +// Expected: test-file-expected-mac.txt. +// Auto-generated: test-file-actual-mac.txt +#if defined(OS_WIN) +static const std::string kActualFileSuffix = "-actual-win.txt"; +static const std::string kExpectedFileSuffix = "-expected-win.txt"; +#elif defined(OS_MACOSX) +static const std::string kActualFileSuffix = "-actual-mac.txt"; +static const std::string kExpectedFileSuffix = "-expected-mac.txt"; +#else +#error DumpAccessibilityTree does not support this platform. +#endif + +// HTML id attribute prefix identifying a node to test. +static const std::string kTestId = "test"; + +// Required to enter html content into a url. +static const std::string kUrlPreamble = "data:text/html,\n<!doctype html>"; + +// Dumps a BrowserAccessibility tree into a string. +void DumpAccessibilityTree(BrowserAccessibility* node, + std::string* contents) { + *contents += node->ToString() + "\n"; + for (size_t i = 0; i < node->children().size(); ++i) + DumpAccessibilityTree(node->children()[i], contents); +} + +// This test takes a snapshot of the platform BrowserAccessibility tree and +// tests it against an expected baseline. +// +// The flow of the test is as outlined below. +// 1. Load an html file from chrome/test/data/accessibility. +// 2. Read the expectation. +// 3. Browse to the page and serialize the platform specific tree into a human +// readable string. +// 4. Perform a comparison between actual and expected and fail if they do not +// exactly match. +class DumpAccessibilityTreeTest : public InProcessBrowserTest { + public: + virtual void SetUpInProcessBrowserTestFixture() { + FilePath resources_pack_path; + EXPECT_TRUE(PathService::Get(chrome::FILE_RESOURCES_PACK, + &resources_pack_path)); + ResourceBundle::AddDataPackToSharedInstance(resources_pack_path); + } +}; + +IN_PROC_BROWSER_TEST_F(DumpAccessibilityTreeTest, + PlatformTreeDifferenceTest) { + content::RenderWidgetHostView* host_view = + browser()->GetSelectedWebContents()->GetRenderWidgetHostView(); + RenderWidgetHost* host = host_view->GetRenderWidgetHost(); + RenderViewHost* view_host = static_cast<RenderViewHost*>(host); + view_host->set_save_accessibility_tree_for_testing(true); + view_host->EnableRendererAccessibility(); + + // Setup test paths. + FilePath dir_test_data; + EXPECT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &dir_test_data)); + FilePath test_path(dir_test_data.Append(FilePath("accessibility"))); + EXPECT_TRUE(file_util::PathExists(test_path)) + << test_path.LossyDisplayName(); + + // Grab all HTML files. + file_util::FileEnumerator file_enumerator(test_path, + false, + file_util::FileEnumerator::FILES, + "*.html"); + + // TODO(dtseng): Make each of these a gtest with script. + FilePath html_file; + while (!(html_file = file_enumerator.Next()).empty()) { + std::string html_contents; + file_util::ReadFileToString(html_file, &html_contents); + + std::string expected_contents; + FilePath expected_file = + FilePath(html_file.RemoveExtension().value() + kExpectedFileSuffix); + file_util::ReadFileToString( + expected_file, + &expected_contents); + + // Load the page. + ui_test_utils::WindowedNotificationObserver tree_updated_observer( + content::NOTIFICATION_RENDER_VIEW_HOST_ACCESSIBILITY_TREE_UPDATED, + content::NotificationService::AllSources()); + GURL url(kUrlPreamble + html_contents); + browser()->OpenURL(OpenURLParams( + url, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_TYPED, false)); + + // Wait for the tree. + tree_updated_observer.Wait(); + + // Perform a diff (or write the initial baseline). + std::string actual_contents; + DumpAccessibilityTree( + host_view->GetBrowserAccessibilityManager()->GetRoot(), + &actual_contents); + EXPECT_EQ(expected_contents, actual_contents); + + if (!file_util::PathExists(expected_file)) { + FilePath actual_file = + FilePath(html_file.RemoveExtension().value() + kActualFileSuffix); + EXPECT_TRUE(file_util::WriteFile( + actual_file, actual_contents.c_str(), actual_contents.size())); + + ADD_FAILURE() << "No expectation found. Create it by doing:\n" + << "mv " << actual_file.LossyDisplayName() << " " + << expected_file.LossyDisplayName(); + } + } +} diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi index 696d332..9a46d2f7 100644 --- a/chrome/chrome_tests.gypi +++ b/chrome/chrome_tests.gypi @@ -2513,6 +2513,7 @@ 'app/chrome_dll_resource.h', 'app/chrome_version.rc.version', 'browser/accessibility/accessibility_extension_apitest.cc', + 'browser/accessibility/dump_accessibility_tree_browsertest.cc', 'browser/app_controller_mac_browsertest.mm', 'browser/autocomplete/autocomplete_browsertest.cc', 'browser/autofill/form_structure_browsertest.cc', @@ -2844,9 +2845,6 @@ # is safe to run there. See http://crbug.com/78722 for details. '../base/files/file_path_watcher_browsertest.cc', '../content/app/startup_helper_win.cc', - '../content/browser/accessibility/dump_accessibility_tree_browsertest.cc', - '../content/browser/accessibility/dump_accessibility_tree_helper_mac.mm', - '../content/browser/accessibility/dump_accessibility_tree_helper_win.cc', '../content/browser/accessibility/renderer_accessibility_browsertest.cc', '../content/browser/child_process_security_policy_browsertest.cc', '../content/browser/device_orientation/device_orientation_browsertest.cc', @@ -3000,9 +2998,10 @@ 'browser/ui/gtk/view_id_util_browsertest.cc', ], }], - ['OS=="linux"', { + # TODO(dtseng): Change this to OS=="linux" once Windows support done. + ['OS!="mac"', { 'sources!': [ - '../content/browser/accessibility/dump_accessibility_tree_browsertest.cc', + 'browser/accessibility/dump_accessibility_tree_browsertest.cc', ], }], ['OS=="win"', { @@ -3026,7 +3025,6 @@ 'dependencies': [ 'chrome_version_resources', 'installer_util_strings', - '../third_party/iaccessible2/iaccessible2.gyp:iaccessible2', '../sandbox/sandbox.gyp:sandbox', ], 'conditions': [ diff --git a/chrome/test/data/accessibility/aria-application-expected-mac.txt b/chrome/test/data/accessibility/aria-application-expected-mac.txt new file mode 100644 index 0000000..9112096 --- /dev/null +++ b/chrome/test/data/accessibility/aria-application-expected-mac.txt @@ -0,0 +1,2 @@ +AXWebArea|(null)|| +AXGroup|AXLandmarkApplication|| diff --git a/chrome/test/data/accessibility/aria-application.html b/chrome/test/data/accessibility/aria-application.html new file mode 100644 index 0000000..f2b14b4 --- /dev/null +++ b/chrome/test/data/accessibility/aria-application.html @@ -0,0 +1,4 @@ +<html> +<body role="application" id="testAriaApplication"> +</body> +</html> |