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

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: Renaming and remove expectation. 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 EqualsWithComments(std::string& expected, std::string& actual) {
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 return i < 0;
72 }
73
49 DumpAccessibilityTreeHelper helper_; 74 DumpAccessibilityTreeHelper helper_;
50 }; 75 };
51 76
52 IN_PROC_BROWSER_TEST_F(DumpAccessibilityTreeTest, 77 IN_PROC_BROWSER_TEST_F(DumpAccessibilityTreeTest,
53 PlatformTreeDifferenceTest) { 78 PlatformTreeDifferenceTest) {
54 content::RenderWidgetHostView* host_view = 79 content::RenderWidgetHostView* host_view =
55 browser()->GetSelectedWebContents()->GetRenderWidgetHostView(); 80 browser()->GetSelectedWebContents()->GetRenderWidgetHostView();
56 RenderWidgetHost* host = host_view->GetRenderWidgetHost(); 81 RenderWidgetHost* host = host_view->GetRenderWidgetHost();
57 // TODO(joi): Remove this dependency 82 // TODO(joi): Remove this dependency
58 RenderViewHostImpl* view_host = 83 RenderViewHostImpl* view_host =
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 137
113 // Wait for the tree. 138 // Wait for the tree.
114 tree_updated_observer.Wait(); 139 tree_updated_observer.Wait();
115 140
116 // Perform a diff (or write the initial baseline). 141 // Perform a diff (or write the initial baseline).
117 string16 actual_contents_utf16; 142 string16 actual_contents_utf16;
118 helper_.DumpAccessibilityTree( 143 helper_.DumpAccessibilityTree(
119 host_view->GetBrowserAccessibilityManager()->GetRoot(), 144 host_view->GetBrowserAccessibilityManager()->GetRoot(),
120 &actual_contents_utf16); 145 &actual_contents_utf16);
121 std::string actual_contents = UTF16ToUTF8(actual_contents_utf16); 146 std::string actual_contents = UTF16ToUTF8(actual_contents_utf16);
122 EXPECT_TRUE(expected_contents == actual_contents); 147 EXPECT_TRUE(EqualsWithComments(expected_contents, actual_contents));
123 if (expected_contents != actual_contents) { 148 if (expected_contents != actual_contents) {
124 printf("*** EXPECTED: ***\n%s\n", expected_contents.c_str()); 149 printf("*** EXPECTED: ***\n%s\n", expected_contents.c_str());
125 printf("*** ACTUAL: ***\n%s\n", actual_contents.c_str()); 150 printf("*** ACTUAL: ***\n%s\n", actual_contents.c_str());
126 } 151 }
127 152
128 if (!file_util::PathExists(expected_file)) { 153 if (!file_util::PathExists(expected_file)) {
129 FilePath actual_file = 154 FilePath actual_file =
130 FilePath(html_file.RemoveExtension().value() + 155 FilePath(html_file.RemoveExtension().value() +
131 helper_.GetActualFileSuffix()); 156 helper_.GetActualFileSuffix());
132 157
133 EXPECT_TRUE(file_util::WriteFile( 158 EXPECT_TRUE(file_util::WriteFile(
134 actual_file, actual_contents.c_str(), actual_contents.size())); 159 actual_file, actual_contents.c_str(), actual_contents.size()));
135 160
136 ADD_FAILURE() << "No expectation found. Create it by doing:\n" 161 ADD_FAILURE() << "No expectation found. Create it by doing:\n"
137 << "mv " << actual_file.LossyDisplayName() << " " 162 << "mv " << actual_file.LossyDisplayName() << " "
138 << expected_file.LossyDisplayName(); 163 << expected_file.LossyDisplayName();
139 } 164 }
140 } while (!(html_file = file_enumerator.Next()).empty()); 165 } while (!(html_file = file_enumerator.Next()).empty());
141 } 166 }
167
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