Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(191)

Side by Side Diff: content/browser/accessibility/dump_accessibility_tree_browsertest.cc

Issue 10834034: Move accessibility browser tests to content_browsertests. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 <string> 5 #include <string>
6 #include <vector> 6 #include <vector>
7 7
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/path_service.h" 9 #include "base/path_service.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
11 #include "base/string16.h" 11 #include "base/string16.h"
12 #include "base/utf_string_conversions.h" 12 #include "base/utf_string_conversions.h"
13 #include "chrome/browser/ui/browser.h"
14 #include "chrome/browser/ui/browser_tabstrip.h"
15 #include "chrome/test/base/in_process_browser_test.h"
16 #include "content/browser/accessibility/browser_accessibility.h" 13 #include "content/browser/accessibility/browser_accessibility.h"
17 #include "content/browser/accessibility/browser_accessibility_manager.h" 14 #include "content/browser/accessibility/browser_accessibility_manager.h"
18 #include "content/browser/accessibility/dump_accessibility_tree_helper.h" 15 #include "content/browser/accessibility/dump_accessibility_tree_helper.h"
19 #include "content/browser/renderer_host/render_view_host_impl.h" 16 #include "content/browser/renderer_host/render_view_host_impl.h"
20 #include "content/port/browser/render_widget_host_view_port.h" 17 #include "content/port/browser/render_widget_host_view_port.h"
21 #include "content/public/browser/notification_service.h" 18 #include "content/public/browser/notification_service.h"
22 #include "content/public/browser/notification_types.h" 19 #include "content/public/browser/notification_types.h"
23 #include "content/public/browser/web_contents.h" 20 #include "content/public/browser/web_contents.h"
24 #include "content/public/common/content_paths.h" 21 #include "content/public/common/content_paths.h"
25 #include "content/public/test/test_utils.h" 22 #include "content/public/test/test_utils.h"
23 #include "content/test/content_browser_test.h"
24 #include "content/test/content_browser_test_utils.h"
25 #include "content/shell/shell.h"
26 #include "testing/gtest/include/gtest/gtest.h" 26 #include "testing/gtest/include/gtest/gtest.h"
27 27
28 using content::OpenURLParams;
29 using content::RenderViewHostImpl;
30 using content::RenderWidgetHostImpl;
31 using content::RenderWidgetHost;
32 using content::RenderWidgetHostViewPort;
33 using content::Referrer;
34
35 namespace { 28 namespace {
36 // Required to enter html content into a url. 29 // Required to enter html content into a url.
37 static const std::string kUrlPreamble = "data:text/html,\n<!doctype html>"; 30 static const std::string kUrlPreamble = "data:text/html,\n<!doctype html>";
38 static const char kCommentToken = '#'; 31 static const char kCommentToken = '#';
39 static const char* kMarkSkipFile = "#<skip"; 32 static const char* kMarkSkipFile = "#<skip";
40 static const char* kMarkEndOfFile = "<-- End-of-file -->"; 33 static const char* kMarkEndOfFile = "<-- End-of-file -->";
41 static const char* kSignalDiff = "*"; 34 static const char* kSignalDiff = "*";
42 } // namespace 35 } // namespace
43 36
37 namespace content {
38
44 // This test takes a snapshot of the platform BrowserAccessibility tree and 39 // This test takes a snapshot of the platform BrowserAccessibility tree and
45 // tests it against an expected baseline. 40 // tests it against an expected baseline.
46 // 41 //
47 // The flow of the test is as outlined below. 42 // The flow of the test is as outlined below.
48 // 1. Load an html file from chrome/test/data/accessibility. 43 // 1. Load an html file from chrome/test/data/accessibility.
49 // 2. Read the expectation. 44 // 2. Read the expectation.
50 // 3. Browse to the page and serialize the platform specific tree into a human 45 // 3. Browse to the page and serialize the platform specific tree into a human
51 // readable string. 46 // readable string.
52 // 4. Perform a comparison between actual and expected and fail if they do not 47 // 4. Perform a comparison between actual and expected and fail if they do not
53 // exactly match. 48 // exactly match.
54 class DumpAccessibilityTreeTest : public InProcessBrowserTest { 49 class DumpAccessibilityTreeTest : public ContentBrowserTest {
55 public: 50 public:
56 // Utility helper that does a comment aware equality check. 51 // Utility helper that does a comment aware equality check.
57 // Returns array of lines from expected file which are different. 52 // Returns array of lines from expected file which are different.
58 std::vector<int> DiffLines(std::vector<std::string>& expected_lines, 53 std::vector<int> DiffLines(std::vector<std::string>& expected_lines,
59 std::vector<std::string>& actual_lines) { 54 std::vector<std::string>& actual_lines) {
60 int actual_lines_count = actual_lines.size(); 55 int actual_lines_count = actual_lines.size();
61 int expected_lines_count = expected_lines.size(); 56 int expected_lines_count = expected_lines.size();
62 std::vector<int> diff_lines; 57 std::vector<int> diff_lines;
63 int i = 0, j = 0; 58 int i = 0, j = 0;
64 while (i < actual_lines_count && j < expected_lines_count) { 59 while (i < actual_lines_count && j < expected_lines_count) {
(...skipping 13 matching lines...) Expand all
78 // Actual file has been fully checked. 73 // Actual file has been fully checked.
79 return diff_lines; 74 return diff_lines;
80 } 75 }
81 76
82 DumpAccessibilityTreeHelper helper_; 77 DumpAccessibilityTreeHelper helper_;
83 }; 78 };
84 79
85 IN_PROC_BROWSER_TEST_F(DumpAccessibilityTreeTest, 80 IN_PROC_BROWSER_TEST_F(DumpAccessibilityTreeTest,
86 DISABLED_PlatformTreeDifferenceTest) { 81 DISABLED_PlatformTreeDifferenceTest) {
87 RenderWidgetHostViewPort* host_view = static_cast<RenderWidgetHostViewPort*>( 82 RenderWidgetHostViewPort* host_view = static_cast<RenderWidgetHostViewPort*>(
88 chrome::GetActiveWebContents(browser())->GetRenderWidgetHostView()); 83 shell()->web_contents()->GetRenderWidgetHostView());
89 RenderWidgetHost* host = host_view->GetRenderWidgetHost(); 84 RenderWidgetHost* host = host_view->GetRenderWidgetHost();
90 RenderViewHostImpl* view_host = 85 RenderViewHostImpl* view_host =
91 static_cast<RenderViewHostImpl*>(RenderWidgetHostImpl::From(host)); 86 static_cast<RenderViewHostImpl*>(RenderWidgetHostImpl::From(host));
92 view_host->set_save_accessibility_tree_for_testing(true); 87 view_host->set_save_accessibility_tree_for_testing(true);
93 view_host->SetAccessibilityMode(AccessibilityModeComplete); 88 view_host->SetAccessibilityMode(AccessibilityModeComplete);
94 89
95 // Setup test paths. 90 // Setup test paths.
96 FilePath dir_test_data; 91 FilePath dir_test_data;
97 EXPECT_TRUE(PathService::Get(content::DIR_TEST_DATA, &dir_test_data)); 92 EXPECT_TRUE(PathService::Get(DIR_TEST_DATA, &dir_test_data));
98 FilePath test_path(dir_test_data.Append(FILE_PATH_LITERAL("accessibility"))); 93 FilePath test_path(dir_test_data.Append(FILE_PATH_LITERAL("accessibility")));
99 EXPECT_TRUE(file_util::PathExists(test_path)) 94 EXPECT_TRUE(file_util::PathExists(test_path))
100 << test_path.LossyDisplayName(); 95 << test_path.LossyDisplayName();
101 96
102 // Output the test path to help anyone who encounters a failure and needs 97 // Output the test path to help anyone who encounters a failure and needs
103 // to know where to look. 98 // to know where to look.
104 printf("Path to test files: %s\n", test_path.MaybeAsASCII().c_str()); 99 printf("Path to test files: %s\n", test_path.MaybeAsASCII().c_str());
105 100
106 // Grab all HTML files. 101 // Grab all HTML files.
107 file_util::FileEnumerator file_enumerator(test_path, 102 file_util::FileEnumerator file_enumerator(test_path,
(...skipping 23 matching lines...) Expand all
131 RemoveChars(expected_contents_raw, "\r", &expected_contents); 126 RemoveChars(expected_contents_raw, "\r", &expected_contents);
132 127
133 if (!expected_contents.compare(0, strlen(kMarkSkipFile), kMarkSkipFile)) { 128 if (!expected_contents.compare(0, strlen(kMarkSkipFile), kMarkSkipFile)) {
134 printf("Skipping %s\n", html_file.BaseName().MaybeAsASCII().c_str()); 129 printf("Skipping %s\n", html_file.BaseName().MaybeAsASCII().c_str());
135 continue; 130 continue;
136 } 131 }
137 132
138 printf("Testing %s\n", html_file.BaseName().MaybeAsASCII().c_str()); 133 printf("Testing %s\n", html_file.BaseName().MaybeAsASCII().c_str());
139 134
140 // Load the page. 135 // Load the page.
141 content::WindowedNotificationObserver tree_updated_observer( 136 WindowedNotificationObserver tree_updated_observer(
142 content::NOTIFICATION_RENDER_VIEW_HOST_ACCESSIBILITY_TREE_UPDATED, 137 NOTIFICATION_RENDER_VIEW_HOST_ACCESSIBILITY_TREE_UPDATED,
143 content::NotificationService::AllSources()); 138 NotificationService::AllSources());
144 string16 html_contents16; 139 string16 html_contents16;
145 html_contents16 = UTF8ToUTF16(html_contents); 140 html_contents16 = UTF8ToUTF16(html_contents);
146 GURL url(UTF8ToUTF16(kUrlPreamble) + html_contents16); 141 GURL url(UTF8ToUTF16(kUrlPreamble) + html_contents16);
147 browser()->OpenURL(OpenURLParams( 142 NavigateToURL(shell(), url);
148 url, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_TYPED, false));
149 143
150 // Wait for the tree. 144 // Wait for the tree.
151 tree_updated_observer.Wait(); 145 tree_updated_observer.Wait();
152 146
153 // Perform a diff (or write the initial baseline). 147 // Perform a diff (or write the initial baseline).
154 string16 actual_contents_utf16; 148 string16 actual_contents_utf16;
155 helper_.DumpAccessibilityTree( 149 helper_.DumpAccessibilityTree(
156 host_view->GetBrowserAccessibilityManager()->GetRoot(), 150 host_view->GetBrowserAccessibilityManager()->GetRoot(),
157 &actual_contents_utf16); 151 &actual_contents_utf16);
158 std::string actual_contents = UTF16ToUTF8(actual_contents_utf16); 152 std::string actual_contents = UTF16ToUTF8(actual_contents_utf16);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 189
196 EXPECT_TRUE(file_util::WriteFile( 190 EXPECT_TRUE(file_util::WriteFile(
197 actual_file, actual_contents.c_str(), actual_contents.size())); 191 actual_file, actual_contents.c_str(), actual_contents.size()));
198 192
199 ADD_FAILURE() << "No expectation found. Create it by doing:\n" 193 ADD_FAILURE() << "No expectation found. Create it by doing:\n"
200 << "mv " << actual_file.LossyDisplayName() << " " 194 << "mv " << actual_file.LossyDisplayName() << " "
201 << expected_file.LossyDisplayName(); 195 << expected_file.LossyDisplayName();
202 } 196 }
203 } while (!(html_file = file_enumerator.Next()).empty()); 197 } while (!(html_file = file_enumerator.Next()).empty());
204 } 198 }
199
200 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/accessibility/cross_platform_accessibility_browsertest.cc ('k') | content/content_tests.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698