Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(551)

Unified Diff: chrome/test/base/accessibility_test_helper.cc

Issue 582493002: Enable accessibility testing for the bookmark browser test. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update for Review Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/test/base/accessibility_test_helper.cc
diff --git a/chrome/test/base/accessibility_test_helper.cc b/chrome/test/base/accessibility_test_helper.cc
new file mode 100644
index 0000000000000000000000000000000000000000..dfb58bbc3ef067c3f1320222c3f99aedd2445ed1
--- /dev/null
+++ b/chrome/test/base/accessibility_test_helper.cc
@@ -0,0 +1,96 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
Paweł Hajdan Jr. 2015/01/29 13:01:18 nit: 2015
hcarmona 2015/01/30 22:19:47 Done.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/files/file_util.h"
+#include "base/path_service.h"
+#include "chrome/test/base/accessibility_test_helper.h"
+#include "content/public/test/browser_test_utils.h"
+
+// Library used for testing accessibility.
+const base::FilePath kAXSTesting(
+ FILE_PATH_LITERAL("third_party/accessibility-audit/axs_testing.js"));
+
+// static
+const std::string AccessibilityTestHelper::kExpectedResults = "";
+
+// static
+const std::string AccessibilityTestHelper::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 pass = true;"
+ "for (var i = 0; i < result.length; ++i) {"
+ " if (result[i].result == axs.constants.AuditResult.FAIL) {"
+ " pass = false;"
+ " break;"
+ " }"
+ "}"
+ "if (pass) {"
+ " domAutomationController.send('');"
+ "}"
+ "else {"
+ " domAutomationController.send(axs.Audit.createReport(result));"
+ "}";
+
+bool AccessibilityTestHelper::LoadLibrary(
+ content::WebContents* web_contents) {
+ return LoadScript(web_contents, kAXSTesting);
+}
+
+bool AccessibilityTestHelper::RunAccessibilityTest(
+ content::RenderFrameHost* focused_frame) {
+ // Clear accessibility message in case this method is called multiple times.
+ accessibility_message_ = "";
+
+ // Run the test.
+ return content::ExecuteScriptAndExtractString(
+ focused_frame,
+ kAccessibilityTestString,
+ &accessibility_message_);
+}
+
+std::string AccessibilityTestHelper::accessibility_message() {
+ return accessibility_message_;
+}
+
+bool AccessibilityTestHelper::LoadScript(content::WebContents* web_contents,
+ base::FilePath path) {
+ // All library paths should be relative to the source root.
+ base::FilePath src_dir;
+ if (!PathService::Get(base::DIR_SOURCE_ROOT, &src_dir))
+ return false;
+
+ // Get the full path of the library.
+ base::FilePath script_path = src_dir.Append(path);
+
+ std::string script;
+ if (!base::ReadFileToString(script_path, &script)) {
+ LOG(ERROR) << "Failed to load script " << script_path.value();
+ return false;
+ }
+
+ // Execute the script to load the library.
+ return content::ExecuteScript(web_contents, script);
+}
+

Powered by Google App Engine
This is Rietveld 408576698