OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <set> | 5 #include <set> |
6 #include <string> | 6 #include <string> |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/path_service.h" | 11 #include "base/path_service.h" |
12 #include "base/strings/string16.h" | 12 #include "base/strings/string16.h" |
13 #include "base/strings/string_split.h" | 13 #include "base/strings/string_split.h" |
14 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
15 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
16 #include "content/browser/accessibility/accessibility_tree_formatter.h" | 16 #include "content/browser/accessibility/accessibility_tree_formatter.h" |
17 #include "content/browser/accessibility/browser_accessibility.h" | 17 #include "content/browser/accessibility/browser_accessibility.h" |
18 #include "content/browser/accessibility/browser_accessibility_manager.h" | 18 #include "content/browser/accessibility/browser_accessibility_manager.h" |
19 #include "content/browser/renderer_host/render_view_host_impl.h" | 19 #include "content/browser/renderer_host/render_view_host_impl.h" |
20 #include "content/port/browser/render_widget_host_view_port.h" | 20 #include "content/port/browser/render_widget_host_view_port.h" |
21 #include "content/public/browser/web_contents.h" | 21 #include "content/public/browser/web_contents.h" |
22 #include "content/public/common/content_paths.h" | 22 #include "content/public/common/content_paths.h" |
| 23 #include "content/public/common/url_constants.h" |
23 #include "content/shell/shell.h" | 24 #include "content/shell/shell.h" |
24 #include "content/test/accessibility_browser_test_utils.h" | 25 #include "content/test/accessibility_browser_test_utils.h" |
25 #include "content/test/content_browser_test.h" | 26 #include "content/test/content_browser_test.h" |
26 #include "content/test/content_browser_test_utils.h" | 27 #include "content/test/content_browser_test_utils.h" |
27 #include "testing/gtest/include/gtest/gtest.h" | 28 #include "testing/gtest/include/gtest/gtest.h" |
28 | 29 |
29 // TODO(dmazzoni): Disabled accessibility tests on Win64. crbug.com/179717 | 30 // TODO(dmazzoni): Disabled accessibility tests on Win64. crbug.com/179717 |
30 #if defined(OS_WIN) && defined(ARCH_CPU_X86_64) | 31 #if defined(OS_WIN) && defined(ARCH_CPU_X86_64) |
31 #define MAYBE(x) DISABLED_##x | 32 #define MAYBE(x) DISABLED_##x |
32 #else | 33 #else |
(...skipping 20 matching lines...) Expand all Loading... |
53 // 1. Load an html file from chrome/test/data/accessibility. | 54 // 1. Load an html file from chrome/test/data/accessibility. |
54 // 2. Read the expectation. | 55 // 2. Read the expectation. |
55 // 3. Browse to the page and serialize the platform specific tree into a human | 56 // 3. Browse to the page and serialize the platform specific tree into a human |
56 // readable string. | 57 // readable string. |
57 // 4. Perform a comparison between actual and expected and fail if they do not | 58 // 4. Perform a comparison between actual and expected and fail if they do not |
58 // exactly match. | 59 // exactly match. |
59 class DumpAccessibilityTreeTest : public ContentBrowserTest { | 60 class DumpAccessibilityTreeTest : public ContentBrowserTest { |
60 public: | 61 public: |
61 // Utility helper that does a comment aware equality check. | 62 // Utility helper that does a comment aware equality check. |
62 // Returns array of lines from expected file which are different. | 63 // Returns array of lines from expected file which are different. |
63 std::vector<int> DiffLines(std::vector<std::string>& expected_lines, | 64 std::vector<int> DiffLines(const std::vector<std::string>& expected_lines, |
64 std::vector<std::string>& actual_lines) { | 65 const std::vector<std::string>& actual_lines) { |
65 int actual_lines_count = actual_lines.size(); | 66 int actual_lines_count = actual_lines.size(); |
66 int expected_lines_count = expected_lines.size(); | 67 int expected_lines_count = expected_lines.size(); |
67 std::vector<int> diff_lines; | 68 std::vector<int> diff_lines; |
68 int i = 0, j = 0; | 69 int i = 0, j = 0; |
69 while (i < actual_lines_count && j < expected_lines_count) { | 70 while (i < actual_lines_count && j < expected_lines_count) { |
70 if (expected_lines[j].size() == 0 || | 71 if (expected_lines[j].size() == 0 || |
71 expected_lines[j][0] == kCommentToken) { | 72 expected_lines[j][0] == kCommentToken) { |
72 // Skip comment lines and blank lines in expected output. | 73 // Skip comment lines and blank lines in expected output. |
73 ++j; | 74 ++j; |
74 continue; | 75 continue; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 Filter::DENY)); | 117 Filter::DENY)); |
117 } | 118 } |
118 } | 119 } |
119 } | 120 } |
120 | 121 |
121 void RunTest(const base::FilePath::CharType* file_path); | 122 void RunTest(const base::FilePath::CharType* file_path); |
122 }; | 123 }; |
123 | 124 |
124 void DumpAccessibilityTreeTest::RunTest( | 125 void DumpAccessibilityTreeTest::RunTest( |
125 const base::FilePath::CharType* file_path) { | 126 const base::FilePath::CharType* file_path) { |
126 NavigateToURL(shell(), GURL("about:blank")); | 127 NavigateToURL(shell(), GURL(kAboutBlankURL)); |
127 | 128 |
128 // Setup test paths. | 129 // Setup test paths. |
129 base::FilePath dir_test_data; | 130 base::FilePath dir_test_data; |
130 ASSERT_TRUE(PathService::Get(DIR_TEST_DATA, &dir_test_data)); | 131 ASSERT_TRUE(PathService::Get(DIR_TEST_DATA, &dir_test_data)); |
131 base::FilePath test_path( | 132 base::FilePath test_path( |
132 dir_test_data.Append(FILE_PATH_LITERAL("accessibility"))); | 133 dir_test_data.Append(FILE_PATH_LITERAL("accessibility"))); |
133 ASSERT_TRUE(base::PathExists(test_path)) | 134 ASSERT_TRUE(base::PathExists(test_path)) |
134 << test_path.LossyDisplayName(); | 135 << test_path.LossyDisplayName(); |
135 | 136 |
136 base::FilePath html_file = test_path.Append(base::FilePath(file_path)); | 137 base::FilePath html_file = test_path.Append(base::FilePath(file_path)); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 // Mark the expected lines which did not match actual output with a *. | 200 // Mark the expected lines which did not match actual output with a *. |
200 printf("* Line Expected\n"); | 201 printf("* Line Expected\n"); |
201 printf("- ---- --------\n"); | 202 printf("- ---- --------\n"); |
202 for (int line = 0, diff_index = 0; | 203 for (int line = 0, diff_index = 0; |
203 line < static_cast<int>(expected_lines.size()); | 204 line < static_cast<int>(expected_lines.size()); |
204 ++line) { | 205 ++line) { |
205 bool is_diff = false; | 206 bool is_diff = false; |
206 if (diff_index < static_cast<int>(diff_lines.size()) && | 207 if (diff_index < static_cast<int>(diff_lines.size()) && |
207 diff_lines[diff_index] == line) { | 208 diff_lines[diff_index] == line) { |
208 is_diff = true; | 209 is_diff = true; |
209 ++ diff_index; | 210 ++diff_index; |
210 } | 211 } |
211 printf("%1s %4d %s\n", is_diff? kSignalDiff : "", line + 1, | 212 printf("%1s %4d %s\n", is_diff? kSignalDiff : "", line + 1, |
212 expected_lines[line].c_str()); | 213 expected_lines[line].c_str()); |
213 } | 214 } |
214 printf("\nActual\n"); | 215 printf("\nActual\n"); |
215 printf("------\n"); | 216 printf("------\n"); |
216 printf("%s\n", actual_contents.c_str()); | 217 printf("%s\n", actual_contents.c_str()); |
217 } | 218 } |
218 | 219 |
219 if (!base::PathExists(expected_file)) { | 220 if (!base::PathExists(expected_file)) { |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
446 | 447 |
447 IN_PROC_BROWSER_TEST_F(DumpAccessibilityTreeTest, AccessibilityUl) { | 448 IN_PROC_BROWSER_TEST_F(DumpAccessibilityTreeTest, AccessibilityUl) { |
448 RunTest(FILE_PATH_LITERAL("ul.html")); | 449 RunTest(FILE_PATH_LITERAL("ul.html")); |
449 } | 450 } |
450 | 451 |
451 IN_PROC_BROWSER_TEST_F(DumpAccessibilityTreeTest, AccessibilityWbr) { | 452 IN_PROC_BROWSER_TEST_F(DumpAccessibilityTreeTest, AccessibilityWbr) { |
452 RunTest(FILE_PATH_LITERAL("wbr.html")); | 453 RunTest(FILE_PATH_LITERAL("wbr.html")); |
453 } | 454 } |
454 | 455 |
455 } // namespace content | 456 } // namespace content |
OLD | NEW |