OLD | NEW |
---|---|
(Empty) | |
1 // 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.
| |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "base/files/file_util.h" | |
6 #include "base/path_service.h" | |
7 #include "chrome/test/base/accessibility_test_helper.h" | |
8 #include "content/public/test/browser_test_utils.h" | |
9 | |
10 // Library used for testing accessibility. | |
11 const base::FilePath kAXSTesting( | |
12 FILE_PATH_LITERAL("third_party/accessibility-audit/axs_testing.js")); | |
13 | |
14 // static | |
15 const std::string AccessibilityTestHelper::kExpectedResults = ""; | |
16 | |
17 // static | |
18 const std::string AccessibilityTestHelper::kAccessibilityTestString = | |
19 "var config = new axs.AuditConfiguration();" | |
20 "/* Disable warning about rules that cannot be checked. */" | |
21 "config.showUnsupportedRulesWarning = false;" | |
22 "config.auditRulesToIgnore = [" | |
23 " /* " | |
24 " * The 'elements with meaningful background image' accessibility" | |
25 " * audit (AX_IMAGE_01) does not apply, since Chrome doesn't" | |
26 " * disable background images in high-contrast mode like some" | |
27 " * browsers do." | |
28 " */" | |
29 " 'elementsWithMeaningfulBackgroundImage'," | |
30 " /* " | |
31 " * Most WebUI pages are inside an IFrame, so the 'web page should" | |
32 " * have a title that describes topic or purpose' test (AX_TITLE_01)" | |
33 " * generally does not apply." | |
34 " */" | |
35 " 'pageWithoutTitle'," | |
36 " /* " | |
37 " * Enable when crbug.com/267035 is fixed." | |
38 " * Until then it's just noise." | |
39 " */" | |
40 " 'lowContrastElements'];" | |
41 "var result = axs.Audit.run(config);" | |
42 "var pass = true;" | |
43 "for (var i = 0; i < result.length; ++i) {" | |
44 " if (result[i].result == axs.constants.AuditResult.FAIL) {" | |
45 " pass = false;" | |
46 " break;" | |
47 " }" | |
48 "}" | |
49 "if (pass) {" | |
50 " domAutomationController.send('');" | |
51 "}" | |
52 "else {" | |
53 " domAutomationController.send(axs.Audit.createReport(result));" | |
54 "}"; | |
55 | |
56 bool AccessibilityTestHelper::LoadLibrary( | |
57 content::WebContents* web_contents) { | |
58 return LoadScript(web_contents, kAXSTesting); | |
59 } | |
60 | |
61 bool AccessibilityTestHelper::RunAccessibilityTest( | |
62 content::RenderFrameHost* focused_frame) { | |
63 // Clear accessibility message in case this method is called multiple times. | |
64 accessibility_message_ = ""; | |
65 | |
66 // Run the test. | |
67 return content::ExecuteScriptAndExtractString( | |
68 focused_frame, | |
69 kAccessibilityTestString, | |
70 &accessibility_message_); | |
71 } | |
72 | |
73 std::string AccessibilityTestHelper::accessibility_message() { | |
74 return accessibility_message_; | |
75 } | |
76 | |
77 bool AccessibilityTestHelper::LoadScript(content::WebContents* web_contents, | |
78 base::FilePath path) { | |
79 // All library paths should be relative to the source root. | |
80 base::FilePath src_dir; | |
81 if (!PathService::Get(base::DIR_SOURCE_ROOT, &src_dir)) | |
82 return false; | |
83 | |
84 // Get the full path of the library. | |
85 base::FilePath script_path = src_dir.Append(path); | |
86 | |
87 std::string script; | |
88 if (!base::ReadFileToString(script_path, &script)) { | |
89 LOG(ERROR) << "Failed to load script " << script_path.value(); | |
90 return false; | |
91 } | |
92 | |
93 // Execute the script to load the library. | |
94 return content::ExecuteScript(web_contents, script); | |
95 } | |
96 | |
OLD | NEW |