Commit 5c7b0986 authored by Aaron Leventhal's avatar Aaron Leventhal Committed by Commit Bot

Remove old webui a11y tests that don't run anymore

These old webui tests don't currently run, and are being
replaced with a new system based on axe-core.
https://www.chromium.org/developers/accessibility/testing/axe-core

There will be additional cleanup to fully removed axs_testing.js.
See crbug.com/807458.

Bug: None
Change-Id: If2bfb17550fb762272173a40f572c3301c40aa4a
Reviewed-on: https://chromium-review.googlesource.com/894146Reviewed-by: default avatarScott Violet <sky@chromium.org>
Reviewed-by: default avatarAlice Boxhall <aboxhall@chromium.org>
Commit-Queue: Aaron Leventhal <aleventhal@chromium.org>
Cr-Commit-Position: refs/heads/master@{#533148}
parent bb6bccba
......@@ -102,53 +102,15 @@ const char kBrowserTestType[] = "browser";
InProcessBrowserTest::SetUpBrowserFunction*
InProcessBrowserTest::global_browser_set_up_function_ = nullptr;
// Library used for testing accessibility.
const base::FilePath::CharType kAXSTesting[] =
FILE_PATH_LITERAL("third_party/accessibility-audit/axs_testing.js");
// JavaScript snippet to configure and run the accessibility audit.
const char kAccessibilityTestString[] =
"var config = new axs.AuditConfiguration();"
"/* Disable warning about rules that cannot be checked. */"
"config.showUnsupportedRulesWarning = false;"
"config.auditRulesToIgnore = ["
" /*"
" * The 'elements with meaningful background image' accessibility"
" * audit (AX_IMAGE_01) does not apply, since Chrome doesn't"
" * disable background images in high-contrast mode like some"
" * browsers do."
" */"
" 'elementsWithMeaningfulBackgroundImage',"
" /*"
" * Most WebUI pages are inside an IFrame, so the 'web page should"
" * have a title that describes topic or purpose' test (AX_TITLE_01)"
" * generally does not apply."
" */"
" 'pageWithoutTitle',"
" /*"
" * Enable when crbug.com/267035 is fixed."
" * Until then it's just noise."
" */"
" 'lowContrastElements'"
"];"
"var result = axs.Audit.run(config);"
"var error = '';"
"for (var i = 0; i < result.length; ++i) {"
" if (result[i].result == axs.constants.AuditResult.FAIL) {"
" error = axs.Audit.createReport(result);"
" break;"
" }"
"}"
"domAutomationController.send(error);";
InProcessBrowserTest::InProcessBrowserTest()
: browser_(NULL),
exit_when_last_browser_closes_(true),
open_about_blank_on_browser_launch_(true),
run_accessibility_checks_for_test_case_(false)
open_about_blank_on_browser_launch_(true)
#if defined(OS_MACOSX)
, autorelease_pool_(NULL)
,
autorelease_pool_(NULL)
#endif // OS_MACOSX
{
{
#if defined(OS_MACOSX)
// TODO(phajdan.jr): Make browser_tests self-contained on Mac, remove this.
// Before we run the browser, we have to hack the path to the exe to match
......@@ -299,57 +261,6 @@ void InProcessBrowserTest::SetUpDefaultCommandLine(
command_line->AppendArg(url::kAboutBlankURL);
}
bool InProcessBrowserTest::RunAccessibilityChecks(std::string* error_message) {
base::ScopedAllowBlockingForTesting allow_blocking;
if (!browser()) {
*error_message = "browser is NULL";
return false;
}
auto* tab_strip = browser()->tab_strip_model();
if (!tab_strip) {
*error_message = "tab_strip is NULL";
return false;
}
auto* web_contents = tab_strip->GetActiveWebContents();
if (!web_contents) {
*error_message = "web_contents is NULL";
return false;
}
auto* focused_frame = web_contents->GetFocusedFrame();
if (!focused_frame) {
*error_message = "focused_frame is NULL";
return false;
}
// Load accessibility library.
base::FilePath src_dir;
if (!PathService::Get(base::DIR_SOURCE_ROOT, &src_dir)) {
*error_message = "PathService::Get failed";
return false;
}
base::FilePath script_path = src_dir.Append(kAXSTesting);
std::string script;
if (!base::ReadFileToString(script_path, &script)) {
*error_message = "Could not read accessibility library";
return false;
}
if (!content::ExecuteScript(web_contents, script)) {
*error_message = "Failed to load accessibility library";
return false;
}
// Run accessibility audit.
if (!content::ExecuteScriptAndExtractString(focused_frame,
kAccessibilityTestString,
error_message)) {
*error_message = "Failed to run accessibility audit";
return false;
}
// Test result should be empty if there are no errors.
return error_message->empty();
}
bool InProcessBrowserTest::CreateUserDataDirectory() {
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
base::FilePath user_data_dir =
......@@ -563,11 +474,6 @@ void InProcessBrowserTest::PreRunTestOnMainThread() {
// browser.
content::RunAllPendingInMessageLoop();
// run_accessibility_checks_for_test_case_ must be set before calling
// SetUpOnMainThread or RunTestOnMainThread so that one or all tests can
// enable/disable the accessibility audit.
run_accessibility_checks_for_test_case_ = false;
if (browser_ && global_browser_set_up_function_)
ASSERT_TRUE(global_browser_set_up_function_(browser_));
......@@ -581,16 +487,6 @@ void InProcessBrowserTest::PreRunTestOnMainThread() {
}
void InProcessBrowserTest::PostRunTestOnMainThread() {
#if defined(OS_MACOSX)
autorelease_pool_->Recycle();
#endif
if (run_accessibility_checks_for_test_case_) {
std::string error_message;
EXPECT_TRUE(RunAccessibilityChecks(&error_message));
EXPECT_EQ("", error_message);
}
#if defined(OS_MACOSX)
autorelease_pool_->Recycle();
#endif
......
......@@ -204,13 +204,6 @@ class InProcessBrowserTest : public content::BrowserTestBase {
// the navigation to complete, and show the browser's window.
void AddBlankTabAndShow(Browser* browser);
// Enables running of accessibility audit for a particular test case.
// - Call in test body to enable/disable for one test case.
// - Call in SetUpOnMainThread() to enable for all test cases.
void EnableAccessibilityChecksForTestCase(bool enabled) {
run_accessibility_checks_for_test_case_ = enabled;
}
#if !defined OS_MACOSX
// Return a CommandLine object that is used to relaunch the browser_test
// binary as a browser process. This function is deliberately not defined on
......@@ -236,9 +229,6 @@ class InProcessBrowserTest : public content::BrowserTestBase {
open_about_blank_on_browser_launch_ = value;
}
// Runs accessibility checks and sets |error_message| if it fails.
bool RunAccessibilityChecks(std::string* error_message);
private:
// Creates a user data directory for the test if one is needed. Returns true
// if successful.
......@@ -262,10 +252,6 @@ class InProcessBrowserTest : public content::BrowserTestBase {
// True if the about:blank tab should be opened when the browser is launched.
bool open_about_blank_on_browser_launch_;
// True if the accessibility test should run for a particular test case.
// This is reset for every test case.
bool run_accessibility_checks_for_test_case_;
// We use hardcoded quota settings to have a consistent testing environment.
storage::QuotaSettings quota_settings_;
......
......@@ -93,61 +93,4 @@ IN_PROC_BROWSER_TEST_F(InProcessBrowserTest, AfterStartupTaskUtils) {
EXPECT_TRUE(AfterStartupTaskUtils::IsBrowserStartupComplete());
}
// Paths are to very simple HTML files. One is accessible, the other is not.
const base::FilePath::CharType kPassHTML[] =
FILE_PATH_LITERAL("chrome/test/data/accessibility_pass.html");
const base::FilePath::CharType kFailHTML[] =
FILE_PATH_LITERAL("chrome/test/data/accessibility_fail.html");
/*
* This class is meant as a test for the accessibility audit in the
* InProcessBrowserTest. These tests do NOT validate the accessibility audit,
* just the ability to run it.
*/
class InProcessAccessibilityBrowserTest : public InProcessBrowserTest {
protected:
// Construct a URL from a file path that can be used to get to a web page.
base::FilePath BuildURLToFile(const base::FilePath::CharType* file_path) {
base::FilePath source_root;
if (!PathService::Get(base::DIR_SOURCE_ROOT, &source_root))
return base::FilePath();
return source_root.Append(file_path);
}
bool NavigateToURL(const base::FilePath::CharType* address) {
GURL url = net::FilePathToFileURL(BuildURLToFile(address));
if (!url.is_valid() || url.is_empty() || !browser())
return false;
ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
browser(), url, 1);
return true;
}
};
// Test that an accessible page doesn't fail the accessibility audit.
IN_PROC_BROWSER_TEST_F(
InProcessAccessibilityBrowserTest, DISABLED_VerifyAccessibilityPass) {
ASSERT_TRUE(NavigateToURL(kPassHTML));
std::string test_result;
EXPECT_TRUE(RunAccessibilityChecks(&test_result));
// No error message on success.
EXPECT_EQ("", test_result);
}
// Test that a page that is not accessible will fail the accessibility audit.
IN_PROC_BROWSER_TEST_F(
InProcessAccessibilityBrowserTest, VerifyAccessibilityFail) {
ASSERT_TRUE(NavigateToURL(kFailHTML));
std::string test_result;
EXPECT_FALSE(RunAccessibilityChecks(&test_result));
// Error should NOT be empty on failure.
EXPECT_NE("", test_result);
}
} // namespace
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment