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

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

Issue 9639016: Adds ability to comment expected files in DumpAccessibilityTests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments. Created 8 years, 9 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
« no previous file with comments | « no previous file | content/test/data/accessibility/aria-application-expected-win.txt » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 7
7 #include "base/logging.h" 8 #include "base/logging.h"
8 #include "base/path_service.h" 9 #include "base/path_service.h"
9 #include "base/string_util.h" 10 #include "base/string_util.h"
10 #include "base/string16.h" 11 #include "base/string16.h"
11 #include "base/utf_string_conversions.h" 12 #include "base/utf_string_conversions.h"
12 #include "chrome/browser/ui/browser.h" 13 #include "chrome/browser/ui/browser.h"
13 #include "chrome/test/base/in_process_browser_test.h" 14 #include "chrome/test/base/in_process_browser_test.h"
14 #include "chrome/test/base/ui_test_utils.h" 15 #include "chrome/test/base/ui_test_utils.h"
15 #include "content/browser/accessibility/browser_accessibility.h" 16 #include "content/browser/accessibility/browser_accessibility.h"
16 #include "content/browser/accessibility/browser_accessibility_manager.h" 17 #include "content/browser/accessibility/browser_accessibility_manager.h"
17 #include "content/browser/accessibility/dump_accessibility_tree_helper.h" 18 #include "content/browser/accessibility/dump_accessibility_tree_helper.h"
18 #include "content/browser/renderer_host/render_view_host_impl.h" 19 #include "content/browser/renderer_host/render_view_host_impl.h"
19 #include "content/public/browser/notification_service.h" 20 #include "content/public/browser/notification_service.h"
20 #include "content/public/browser/notification_types.h" 21 #include "content/public/browser/notification_types.h"
21 #include "content/public/browser/render_widget_host_view.h" 22 #include "content/public/browser/render_widget_host_view.h"
22 #include "content/public/browser/web_contents.h" 23 #include "content/public/browser/web_contents.h"
23 #include "content/public/common/content_paths.h" 24 #include "content/public/common/content_paths.h"
24 #include "testing/gtest/include/gtest/gtest.h" 25 #include "testing/gtest/include/gtest/gtest.h"
25 26
26 using content::OpenURLParams; 27 using content::OpenURLParams;
27 using content::RenderViewHostImpl; 28 using content::RenderViewHostImpl;
28 using content::RenderWidgetHostImpl; 29 using content::RenderWidgetHostImpl;
29 using content::RenderWidgetHost; 30 using content::RenderWidgetHost;
30 using content::Referrer; 31 using content::Referrer;
31 32
32 namespace { 33 namespace {
33 // Required to enter html content into a url. 34 // Required to enter html content into a url.
34 static const std::string kUrlPreamble = "data:text/html,\n<!doctype html>"; 35 static const std::string kUrlPreamble = "data:text/html,\n<!doctype html>";
36 static const char kCommentToken = '#';
35 } // namespace 37 } // namespace
36 38
37 // This test takes a snapshot of the platform BrowserAccessibility tree and 39 // This test takes a snapshot of the platform BrowserAccessibility tree and
38 // tests it against an expected baseline. 40 // tests it against an expected baseline.
39 // 41 //
40 // The flow of the test is as outlined below. 42 // The flow of the test is as outlined below.
41 // 1. Load an html file from chrome/test/data/accessibility. 43 // 1. Load an html file from chrome/test/data/accessibility.
42 // 2. Read the expectation. 44 // 2. Read the expectation.
43 // 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
44 // readable string. 46 // readable string.
45 // 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
46 // exactly match. 48 // exactly match.
47 class DumpAccessibilityTreeTest : public InProcessBrowserTest { 49 class DumpAccessibilityTreeTest : public InProcessBrowserTest {
48 public: 50 public:
51 // Utility helper that does a comment aware equality check.
52 bool ExpectEqualsWithComments(std::string& expected, std::string& actual) {
dmazzoni 2012/03/12 19:03:28 Rename to EqualsWithComments
David Tseng 2012/03/12 20:44:22 Done.
53 std::vector<std::string> actual_lines, expected_lines;
54 int actual_lines_count = Tokenize(actual, "\n", &actual_lines);
55 int expected_lines_count = Tokenize(expected, "\n", &expected_lines);
56 int i = actual_lines_count - 1, j = expected_lines_count - 1;
57 while (i >= 0 && j >= 0) {
58 if (expected_lines[j].size() > 0 &&
59 expected_lines[j][0] == kCommentToken) {
60 --j;
61 continue;
62 }
63
64 if (actual_lines[i] != expected_lines[j])
65 return false;
66 --i;
67 --j;
68 }
69
70 // Actual file has been fully checked.
71 EXPECT_LT(i, 0);
dmazzoni 2012/03/12 19:03:28 If it fails, you'll get two EXPECT failures - how
David Tseng 2012/03/12 20:44:22 Done.
72 return true;
73 }
74
49 DumpAccessibilityTreeHelper helper_; 75 DumpAccessibilityTreeHelper helper_;
50 }; 76 };
51 77
52 IN_PROC_BROWSER_TEST_F(DumpAccessibilityTreeTest, 78 IN_PROC_BROWSER_TEST_F(DumpAccessibilityTreeTest,
53 PlatformTreeDifferenceTest) { 79 PlatformTreeDifferenceTest) {
54 content::RenderWidgetHostView* host_view = 80 content::RenderWidgetHostView* host_view =
55 browser()->GetSelectedWebContents()->GetRenderWidgetHostView(); 81 browser()->GetSelectedWebContents()->GetRenderWidgetHostView();
56 RenderWidgetHost* host = host_view->GetRenderWidgetHost(); 82 RenderWidgetHost* host = host_view->GetRenderWidgetHost();
57 // TODO(joi): Remove this dependency 83 // TODO(joi): Remove this dependency
58 RenderViewHostImpl* view_host = 84 RenderViewHostImpl* view_host =
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 138
113 // Wait for the tree. 139 // Wait for the tree.
114 tree_updated_observer.Wait(); 140 tree_updated_observer.Wait();
115 141
116 // Perform a diff (or write the initial baseline). 142 // Perform a diff (or write the initial baseline).
117 string16 actual_contents_utf16; 143 string16 actual_contents_utf16;
118 helper_.DumpAccessibilityTree( 144 helper_.DumpAccessibilityTree(
119 host_view->GetBrowserAccessibilityManager()->GetRoot(), 145 host_view->GetBrowserAccessibilityManager()->GetRoot(),
120 &actual_contents_utf16); 146 &actual_contents_utf16);
121 std::string actual_contents = UTF16ToUTF8(actual_contents_utf16); 147 std::string actual_contents = UTF16ToUTF8(actual_contents_utf16);
122 EXPECT_TRUE(expected_contents == actual_contents); 148 EXPECT_TRUE(ExpectEqualsWithComments(expected_contents, actual_contents));
123 if (expected_contents != actual_contents) { 149 if (expected_contents != actual_contents) {
124 printf("*** EXPECTED: ***\n%s\n", expected_contents.c_str()); 150 printf("*** EXPECTED: ***\n%s\n", expected_contents.c_str());
125 printf("*** ACTUAL: ***\n%s\n", actual_contents.c_str()); 151 printf("*** ACTUAL: ***\n%s\n", actual_contents.c_str());
126 } 152 }
127 153
128 if (!file_util::PathExists(expected_file)) { 154 if (!file_util::PathExists(expected_file)) {
129 FilePath actual_file = 155 FilePath actual_file =
130 FilePath(html_file.RemoveExtension().value() + 156 FilePath(html_file.RemoveExtension().value() +
131 helper_.GetActualFileSuffix()); 157 helper_.GetActualFileSuffix());
132 158
133 EXPECT_TRUE(file_util::WriteFile( 159 EXPECT_TRUE(file_util::WriteFile(
134 actual_file, actual_contents.c_str(), actual_contents.size())); 160 actual_file, actual_contents.c_str(), actual_contents.size()));
135 161
136 ADD_FAILURE() << "No expectation found. Create it by doing:\n" 162 ADD_FAILURE() << "No expectation found. Create it by doing:\n"
137 << "mv " << actual_file.LossyDisplayName() << " " 163 << "mv " << actual_file.LossyDisplayName() << " "
138 << expected_file.LossyDisplayName(); 164 << expected_file.LossyDisplayName();
139 } 165 }
140 } while (!(html_file = file_enumerator.Next()).empty()); 166 } while (!(html_file = file_enumerator.Next()).empty());
141 } 167 }
168
OLDNEW
« no previous file with comments | « no previous file | content/test/data/accessibility/aria-application-expected-win.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698