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/string_util.h" | 12 #include "base/string_util.h" |
13 #include "base/string16.h" | 13 #include "base/string16.h" |
14 #include "base/strings/string_split.h" | 14 #include "base/strings/string_split.h" |
15 #include "base/utf_string_conversions.h" | 15 #include "base/utf_string_conversions.h" |
16 #include "content/browser/accessibility/browser_accessibility.h" | 16 #include "content/browser/accessibility/browser_accessibility.h" |
17 #include "content/browser/accessibility/browser_accessibility_manager.h" | 17 #include "content/browser/accessibility/browser_accessibility_manager.h" |
18 #include "content/browser/accessibility/dump_accessibility_tree_helper.h" | 18 #include "content/browser/accessibility/dump_accessibility_tree_helper.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/notification_service.h" | |
22 #include "content/public/browser/notification_types.h" | |
23 #include "content/public/browser/web_contents.h" | 21 #include "content/public/browser/web_contents.h" |
24 #include "content/public/common/content_paths.h" | 22 #include "content/public/common/content_paths.h" |
25 #include "content/public/test/test_utils.h" | 23 #include "content/public/test/test_utils.h" |
26 #include "content/shell/shell.h" | 24 #include "content/shell/shell.h" |
27 #include "content/test/content_browser_test.h" | 25 #include "content/test/content_browser_test.h" |
28 #include "content/test/content_browser_test_utils.h" | 26 #include "content/test/content_browser_test_utils.h" |
29 #include "testing/gtest/include/gtest/gtest.h" | 27 #include "testing/gtest/include/gtest/gtest.h" |
30 | 28 |
| 29 namespace content { |
| 30 |
31 namespace { | 31 namespace { |
32 static const char kCommentToken = '#'; | |
33 static const char* kMarkSkipFile = "#<skip"; | |
34 static const char* kMarkEndOfFile = "<-- End-of-file -->"; | |
35 static const char* kSignalDiff = "*"; | |
36 } // namespace | |
37 | 32 |
38 namespace content { | 33 const char kCommentToken = '#'; |
| 34 const char kMarkSkipFile[] = "#<skip"; |
| 35 const char kMarkEndOfFile[] = "<-- End-of-file -->"; |
| 36 const char kSignalDiff[] = "*"; |
| 37 |
| 38 } // namespace |
39 | 39 |
40 typedef DumpAccessibilityTreeHelper::Filter Filter; | 40 typedef DumpAccessibilityTreeHelper::Filter Filter; |
41 | 41 |
42 // This test takes a snapshot of the platform BrowserAccessibility tree and | 42 // This test takes a snapshot of the platform BrowserAccessibility tree and |
43 // tests it against an expected baseline. | 43 // tests it against an expected baseline. |
44 // | 44 // |
45 // The flow of the test is as outlined below. | 45 // The flow of the test is as outlined below. |
46 // 1. Load an html file from chrome/test/data/accessibility. | 46 // 1. Load an html file from chrome/test/data/accessibility. |
47 // 2. Read the expectation. | 47 // 2. Read the expectation. |
48 // 3. Browse to the page and serialize the platform specific tree into a human | 48 // 3. Browse to the page and serialize the platform specific tree into a human |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 // normalize by deleting all \r from the file (if any) to leave only \n. | 159 // normalize by deleting all \r from the file (if any) to leave only \n. |
160 std::string expected_contents; | 160 std::string expected_contents; |
161 RemoveChars(expected_contents_raw, "\r", &expected_contents); | 161 RemoveChars(expected_contents_raw, "\r", &expected_contents); |
162 | 162 |
163 if (!expected_contents.compare(0, strlen(kMarkSkipFile), kMarkSkipFile)) { | 163 if (!expected_contents.compare(0, strlen(kMarkSkipFile), kMarkSkipFile)) { |
164 printf("Skipping this test on this platform.\n"); | 164 printf("Skipping this test on this platform.\n"); |
165 return; | 165 return; |
166 } | 166 } |
167 | 167 |
168 // Load the page. | 168 // Load the page. |
169 WindowedNotificationObserver tree_updated_observer( | |
170 NOTIFICATION_ACCESSIBILITY_LOAD_COMPLETE, | |
171 NotificationService::AllSources()); | |
172 string16 html_contents16; | 169 string16 html_contents16; |
173 html_contents16 = UTF8ToUTF16(html_contents); | 170 html_contents16 = UTF8ToUTF16(html_contents); |
174 GURL url = GetTestUrl("accessibility", | 171 GURL url = GetTestUrl("accessibility", |
175 html_file.BaseName().MaybeAsASCII().c_str()); | 172 html_file.BaseName().MaybeAsASCII().c_str()); |
| 173 scoped_refptr<MessageLoopRunner> loop_runner(new MessageLoopRunner); |
| 174 view_host->SetAccessibilityLoadCompleteCallbackForTesting( |
| 175 loop_runner->QuitClosure()); |
176 NavigateToURL(shell(), url); | 176 NavigateToURL(shell(), url); |
177 | 177 |
178 // Wait for the tree. | 178 // Wait for the tree. |
179 tree_updated_observer.Wait(); | 179 loop_runner->Run(); |
180 | 180 |
181 // Perform a diff (or write the initial baseline). | 181 // Perform a diff (or write the initial baseline). |
182 string16 actual_contents_utf16; | 182 string16 actual_contents_utf16; |
183 helper_.DumpAccessibilityTree( | 183 helper_.DumpAccessibilityTree( |
184 host_view->GetBrowserAccessibilityManager()->GetRoot(), | 184 host_view->GetBrowserAccessibilityManager()->GetRoot(), |
185 &actual_contents_utf16); | 185 &actual_contents_utf16); |
186 std::string actual_contents = UTF16ToUTF8(actual_contents_utf16); | 186 std::string actual_contents = UTF16ToUTF8(actual_contents_utf16); |
187 std::vector<std::string> actual_lines, expected_lines; | 187 std::vector<std::string> actual_lines, expected_lines; |
188 Tokenize(actual_contents, "\n", &actual_lines); | 188 Tokenize(actual_contents, "\n", &actual_lines); |
189 Tokenize(expected_contents, "\n", &expected_lines); | 189 Tokenize(expected_contents, "\n", &expected_lines); |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
435 | 435 |
436 IN_PROC_BROWSER_TEST_F(DumpAccessibilityTreeTest, AccessibilityUl) { | 436 IN_PROC_BROWSER_TEST_F(DumpAccessibilityTreeTest, AccessibilityUl) { |
437 RunTest(FILE_PATH_LITERAL("ul.html")); | 437 RunTest(FILE_PATH_LITERAL("ul.html")); |
438 } | 438 } |
439 | 439 |
440 IN_PROC_BROWSER_TEST_F(DumpAccessibilityTreeTest, AccessibilityWbr) { | 440 IN_PROC_BROWSER_TEST_F(DumpAccessibilityTreeTest, AccessibilityWbr) { |
441 RunTest(FILE_PATH_LITERAL("wbr.html")); | 441 RunTest(FILE_PATH_LITERAL("wbr.html")); |
442 } | 442 } |
443 | 443 |
444 } // namespace content | 444 } // namespace content |
OLD | NEW |