| 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/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 diff_lines.push_back(j); | 81 diff_lines.push_back(j); |
| 82 ++i; | 82 ++i; |
| 83 ++j; | 83 ++j; |
| 84 } | 84 } |
| 85 | 85 |
| 86 // Actual file has been fully checked. | 86 // Actual file has been fully checked. |
| 87 return diff_lines; | 87 return diff_lines; |
| 88 } | 88 } |
| 89 | 89 |
| 90 void AddDefaultFilters(std::vector<Filter>* filters) { | 90 void AddDefaultFilters(std::vector<Filter>* filters) { |
| 91 filters->push_back(Filter(ASCIIToUTF16("FOCUSABLE"), Filter::ALLOW)); | 91 filters->push_back(Filter(base::ASCIIToUTF16("FOCUSABLE"), Filter::ALLOW)); |
| 92 filters->push_back(Filter(ASCIIToUTF16("READONLY"), Filter::ALLOW)); | 92 filters->push_back(Filter(base::ASCIIToUTF16("READONLY"), Filter::ALLOW)); |
| 93 filters->push_back(Filter(ASCIIToUTF16("*=''"), Filter::DENY)); | 93 filters->push_back(Filter(base::ASCIIToUTF16("*=''"), Filter::DENY)); |
| 94 } | 94 } |
| 95 | 95 |
| 96 void ParseFilters(const std::string& test_html, | 96 void ParseFilters(const std::string& test_html, |
| 97 std::vector<Filter>* filters) { | 97 std::vector<Filter>* filters) { |
| 98 std::vector<std::string> lines; | 98 std::vector<std::string> lines; |
| 99 base::SplitString(test_html, '\n', &lines); | 99 base::SplitString(test_html, '\n', &lines); |
| 100 for (std::vector<std::string>::const_iterator iter = lines.begin(); | 100 for (std::vector<std::string>::const_iterator iter = lines.begin(); |
| 101 iter != lines.end(); | 101 iter != lines.end(); |
| 102 ++iter) { | 102 ++iter) { |
| 103 const std::string& line = *iter; | 103 const std::string& line = *iter; |
| 104 const std::string& allow_empty_str = | 104 const std::string& allow_empty_str = |
| 105 AccessibilityTreeFormatter::GetAllowEmptyString(); | 105 AccessibilityTreeFormatter::GetAllowEmptyString(); |
| 106 const std::string& allow_str = | 106 const std::string& allow_str = |
| 107 AccessibilityTreeFormatter::GetAllowString(); | 107 AccessibilityTreeFormatter::GetAllowString(); |
| 108 const std::string& deny_str = | 108 const std::string& deny_str = |
| 109 AccessibilityTreeFormatter::GetDenyString(); | 109 AccessibilityTreeFormatter::GetDenyString(); |
| 110 if (StartsWithASCII(line, allow_empty_str, true)) { | 110 if (StartsWithASCII(line, allow_empty_str, true)) { |
| 111 filters->push_back( | 111 filters->push_back( |
| 112 Filter(UTF8ToUTF16(line.substr(allow_empty_str.size())), | 112 Filter(base::UTF8ToUTF16(line.substr(allow_empty_str.size())), |
| 113 Filter::ALLOW_EMPTY)); | 113 Filter::ALLOW_EMPTY)); |
| 114 } else if (StartsWithASCII(line, allow_str, true)) { | 114 } else if (StartsWithASCII(line, allow_str, true)) { |
| 115 filters->push_back(Filter(UTF8ToUTF16(line.substr(allow_str.size())), | 115 filters->push_back(Filter(base::UTF8ToUTF16( |
| 116 line.substr(allow_str.size())), |
| 116 Filter::ALLOW)); | 117 Filter::ALLOW)); |
| 117 } else if (StartsWithASCII(line, deny_str, true)) { | 118 } else if (StartsWithASCII(line, deny_str, true)) { |
| 118 filters->push_back(Filter(UTF8ToUTF16(line.substr(deny_str.size())), | 119 filters->push_back(Filter(base::UTF8ToUTF16( |
| 120 line.substr(deny_str.size())), |
| 119 Filter::DENY)); | 121 Filter::DENY)); |
| 120 } | 122 } |
| 121 } | 123 } |
| 122 } | 124 } |
| 123 | 125 |
| 124 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 126 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| 125 ContentBrowserTest::SetUpCommandLine(command_line); | 127 ContentBrowserTest::SetUpCommandLine(command_line); |
| 126 // Enable <dialog>, which is used in some tests. | 128 // Enable <dialog>, which is used in some tests. |
| 127 CommandLine::ForCurrentProcess()->AppendSwitch( | 129 CommandLine::ForCurrentProcess()->AppendSwitch( |
| 128 switches::kEnableExperimentalWebPlatformFeatures); | 130 switches::kEnableExperimentalWebPlatformFeatures); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 std::string expected_contents; | 165 std::string expected_contents; |
| 164 base::RemoveChars(expected_contents_raw, "\r", &expected_contents); | 166 base::RemoveChars(expected_contents_raw, "\r", &expected_contents); |
| 165 | 167 |
| 166 if (!expected_contents.compare(0, strlen(kMarkSkipFile), kMarkSkipFile)) { | 168 if (!expected_contents.compare(0, strlen(kMarkSkipFile), kMarkSkipFile)) { |
| 167 printf("Skipping this test on this platform.\n"); | 169 printf("Skipping this test on this platform.\n"); |
| 168 return; | 170 return; |
| 169 } | 171 } |
| 170 | 172 |
| 171 // Load the page. | 173 // Load the page. |
| 172 base::string16 html_contents16; | 174 base::string16 html_contents16; |
| 173 html_contents16 = UTF8ToUTF16(html_contents); | 175 html_contents16 = base::UTF8ToUTF16(html_contents); |
| 174 GURL url = GetTestUrl("accessibility", | 176 GURL url = GetTestUrl("accessibility", |
| 175 html_file.BaseName().MaybeAsASCII().c_str()); | 177 html_file.BaseName().MaybeAsASCII().c_str()); |
| 176 AccessibilityNotificationWaiter waiter( | 178 AccessibilityNotificationWaiter waiter( |
| 177 shell(), AccessibilityModeComplete, | 179 shell(), AccessibilityModeComplete, |
| 178 blink::WebAXEventLoadComplete); | 180 blink::WebAXEventLoadComplete); |
| 179 NavigateToURL(shell(), url); | 181 NavigateToURL(shell(), url); |
| 180 waiter.WaitForNotification(); | 182 waiter.WaitForNotification(); |
| 181 | 183 |
| 182 RenderWidgetHostViewPort* host_view = RenderWidgetHostViewPort::FromRWHV( | 184 RenderWidgetHostViewPort* host_view = RenderWidgetHostViewPort::FromRWHV( |
| 183 shell()->web_contents()->GetRenderWidgetHostView()); | 185 shell()->web_contents()->GetRenderWidgetHostView()); |
| 184 AccessibilityTreeFormatter formatter( | 186 AccessibilityTreeFormatter formatter( |
| 185 host_view->GetBrowserAccessibilityManager()->GetRoot()); | 187 host_view->GetBrowserAccessibilityManager()->GetRoot()); |
| 186 | 188 |
| 187 // Parse filters in the test file. | 189 // Parse filters in the test file. |
| 188 std::vector<Filter> filters; | 190 std::vector<Filter> filters; |
| 189 AddDefaultFilters(&filters); | 191 AddDefaultFilters(&filters); |
| 190 ParseFilters(html_contents, &filters); | 192 ParseFilters(html_contents, &filters); |
| 191 formatter.SetFilters(filters); | 193 formatter.SetFilters(filters); |
| 192 | 194 |
| 193 // Perform a diff (or write the initial baseline). | 195 // Perform a diff (or write the initial baseline). |
| 194 base::string16 actual_contents_utf16; | 196 base::string16 actual_contents_utf16; |
| 195 formatter.FormatAccessibilityTree(&actual_contents_utf16); | 197 formatter.FormatAccessibilityTree(&actual_contents_utf16); |
| 196 std::string actual_contents = UTF16ToUTF8(actual_contents_utf16); | 198 std::string actual_contents = base::UTF16ToUTF8(actual_contents_utf16); |
| 197 std::vector<std::string> actual_lines, expected_lines; | 199 std::vector<std::string> actual_lines, expected_lines; |
| 198 Tokenize(actual_contents, "\n", &actual_lines); | 200 Tokenize(actual_contents, "\n", &actual_lines); |
| 199 Tokenize(expected_contents, "\n", &expected_lines); | 201 Tokenize(expected_contents, "\n", &expected_lines); |
| 200 // Marking the end of the file with a line of text ensures that | 202 // Marking the end of the file with a line of text ensures that |
| 201 // file length differences are found. | 203 // file length differences are found. |
| 202 expected_lines.push_back(kMarkEndOfFile); | 204 expected_lines.push_back(kMarkEndOfFile); |
| 203 actual_lines.push_back(kMarkEndOfFile); | 205 actual_lines.push_back(kMarkEndOfFile); |
| 204 | 206 |
| 205 std::vector<int> diff_lines = DiffLines(expected_lines, actual_lines); | 207 std::vector<int> diff_lines = DiffLines(expected_lines, actual_lines); |
| 206 bool is_different = diff_lines.size() > 0; | 208 bool is_different = diff_lines.size() > 0; |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 489 | 491 |
| 490 IN_PROC_BROWSER_TEST_F(DumpAccessibilityTreeTest, AccessibilityUl) { | 492 IN_PROC_BROWSER_TEST_F(DumpAccessibilityTreeTest, AccessibilityUl) { |
| 491 RunTest(FILE_PATH_LITERAL("ul.html")); | 493 RunTest(FILE_PATH_LITERAL("ul.html")); |
| 492 } | 494 } |
| 493 | 495 |
| 494 IN_PROC_BROWSER_TEST_F(DumpAccessibilityTreeTest, AccessibilityWbr) { | 496 IN_PROC_BROWSER_TEST_F(DumpAccessibilityTreeTest, AccessibilityWbr) { |
| 495 RunTest(FILE_PATH_LITERAL("wbr.html")); | 497 RunTest(FILE_PATH_LITERAL("wbr.html")); |
| 496 } | 498 } |
| 497 | 499 |
| 498 } // namespace content | 500 } // namespace content |
| OLD | NEW |