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_split.h" | 12 #include "base/string_split.h" |
13 #include "base/string_util.h" | 13 #include "base/string_util.h" |
14 #include "base/string16.h" | 14 #include "base/string16.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" | 21 #include "content/public/browser/render_view_host_observer.h" |
22 #include "content/public/browser/notification_types.h" | |
23 #include "content/public/browser/web_contents.h" | 22 #include "content/public/browser/web_contents.h" |
24 #include "content/public/common/content_paths.h" | 23 #include "content/public/common/content_paths.h" |
25 #include "content/public/test/test_utils.h" | 24 #include "content/public/test/test_utils.h" |
26 #include "content/test/content_browser_test.h" | 25 #include "content/test/content_browser_test.h" |
27 #include "content/test/content_browser_test_utils.h" | 26 #include "content/test/content_browser_test_utils.h" |
28 #include "content/shell/shell.h" | 27 #include "content/shell/shell.h" |
29 #include "testing/gtest/include/gtest/gtest.h" | 28 #include "testing/gtest/include/gtest/gtest.h" |
30 | 29 |
| 30 namespace content { |
| 31 |
31 namespace { | 32 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 | 33 |
38 namespace content { | 34 const char kCommentToken = '#'; |
| 35 const char kMarkSkipFile[] = "#<skip"; |
| 36 const char kMarkEndOfFile[] = "<-- End-of-file -->"; |
| 37 const char kSignalDiff[] = "*"; |
| 38 |
| 39 class TestRenderViewHostObserver : public RenderViewHostObserver { |
| 40 public: |
| 41 explicit TestRenderViewHostObserver(RenderViewHost* rvh, |
| 42 const base::Closure& callback) |
| 43 : RenderViewHostObserver(rvh), |
| 44 callback_(callback) { |
| 45 } |
| 46 |
| 47 virtual void AccessibilityLoadComplete() OVERRIDE { |
| 48 callback_.Run(); |
| 49 } |
| 50 |
| 51 private: |
| 52 base::Closure callback_; |
| 53 |
| 54 DISALLOW_COPY_AND_ASSIGN(TestRenderViewHostObserver); |
| 55 }; |
| 56 |
| 57 } // namespace |
39 | 58 |
40 typedef DumpAccessibilityTreeHelper::Filter Filter; | 59 typedef DumpAccessibilityTreeHelper::Filter Filter; |
41 | 60 |
42 // This test takes a snapshot of the platform BrowserAccessibility tree and | 61 // This test takes a snapshot of the platform BrowserAccessibility tree and |
43 // tests it against an expected baseline. | 62 // tests it against an expected baseline. |
44 // | 63 // |
45 // The flow of the test is as outlined below. | 64 // The flow of the test is as outlined below. |
46 // 1. Load an html file from chrome/test/data/accessibility. | 65 // 1. Load an html file from chrome/test/data/accessibility. |
47 // 2. Read the expectation. | 66 // 2. Read the expectation. |
48 // 3. Browse to the page and serialize the platform specific tree into a human | 67 // 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. | 178 // normalize by deleting all \r from the file (if any) to leave only \n. |
160 std::string expected_contents; | 179 std::string expected_contents; |
161 RemoveChars(expected_contents_raw, "\r", &expected_contents); | 180 RemoveChars(expected_contents_raw, "\r", &expected_contents); |
162 | 181 |
163 if (!expected_contents.compare(0, strlen(kMarkSkipFile), kMarkSkipFile)) { | 182 if (!expected_contents.compare(0, strlen(kMarkSkipFile), kMarkSkipFile)) { |
164 printf("Skipping this test on this platform.\n"); | 183 printf("Skipping this test on this platform.\n"); |
165 return; | 184 return; |
166 } | 185 } |
167 | 186 |
168 // Load the page. | 187 // Load the page. |
169 WindowedNotificationObserver tree_updated_observer( | |
170 NOTIFICATION_ACCESSIBILITY_LOAD_COMPLETE, | |
171 NotificationService::AllSources()); | |
172 string16 html_contents16; | 188 string16 html_contents16; |
173 html_contents16 = UTF8ToUTF16(html_contents); | 189 html_contents16 = UTF8ToUTF16(html_contents); |
174 GURL url = GetTestUrl("accessibility", | 190 GURL url = GetTestUrl("accessibility", |
175 html_file.BaseName().MaybeAsASCII().c_str()); | 191 html_file.BaseName().MaybeAsASCII().c_str()); |
| 192 scoped_refptr<MessageLoopRunner> loop_runner(new MessageLoopRunner); |
| 193 TestRenderViewHostObserver observer(view_host, loop_runner->QuitClosure()); |
176 NavigateToURL(shell(), url); | 194 NavigateToURL(shell(), url); |
177 | 195 |
178 // Wait for the tree. | 196 // Wait for the tree. |
179 tree_updated_observer.Wait(); | 197 loop_runner->Run(); |
180 | 198 |
181 // Perform a diff (or write the initial baseline). | 199 // Perform a diff (or write the initial baseline). |
182 string16 actual_contents_utf16; | 200 string16 actual_contents_utf16; |
183 helper_.DumpAccessibilityTree( | 201 helper_.DumpAccessibilityTree( |
184 host_view->GetBrowserAccessibilityManager()->GetRoot(), | 202 host_view->GetBrowserAccessibilityManager()->GetRoot(), |
185 &actual_contents_utf16); | 203 &actual_contents_utf16); |
186 std::string actual_contents = UTF16ToUTF8(actual_contents_utf16); | 204 std::string actual_contents = UTF16ToUTF8(actual_contents_utf16); |
187 std::vector<std::string> actual_lines, expected_lines; | 205 std::vector<std::string> actual_lines, expected_lines; |
188 Tokenize(actual_contents, "\n", &actual_lines); | 206 Tokenize(actual_contents, "\n", &actual_lines); |
189 Tokenize(expected_contents, "\n", &expected_lines); | 207 Tokenize(expected_contents, "\n", &expected_lines); |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
436 | 454 |
437 IN_PROC_BROWSER_TEST_F(DumpAccessibilityTreeTest, AccessibilityUl) { | 455 IN_PROC_BROWSER_TEST_F(DumpAccessibilityTreeTest, AccessibilityUl) { |
438 RunTest(FILE_PATH_LITERAL("ul.html")); | 456 RunTest(FILE_PATH_LITERAL("ul.html")); |
439 } | 457 } |
440 | 458 |
441 IN_PROC_BROWSER_TEST_F(DumpAccessibilityTreeTest, AccessibilityWbr) { | 459 IN_PROC_BROWSER_TEST_F(DumpAccessibilityTreeTest, AccessibilityWbr) { |
442 RunTest(FILE_PATH_LITERAL("wbr.html")); | 460 RunTest(FILE_PATH_LITERAL("wbr.html")); |
443 } | 461 } |
444 | 462 |
445 } // namespace content | 463 } // namespace content |
OLD | NEW |