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 <string> | 5 #include <string> |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "base/string16.h" | 10 #include "base/string16.h" |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 view_host->set_save_accessibility_tree_for_testing(true); | 60 view_host->set_save_accessibility_tree_for_testing(true); |
61 view_host->EnableRendererAccessibility(); | 61 view_host->EnableRendererAccessibility(); |
62 | 62 |
63 // Setup test paths. | 63 // Setup test paths. |
64 FilePath dir_test_data; | 64 FilePath dir_test_data; |
65 EXPECT_TRUE(PathService::Get(content::DIR_TEST_DATA, &dir_test_data)); | 65 EXPECT_TRUE(PathService::Get(content::DIR_TEST_DATA, &dir_test_data)); |
66 FilePath test_path(dir_test_data.Append(FILE_PATH_LITERAL("accessibility"))); | 66 FilePath test_path(dir_test_data.Append(FILE_PATH_LITERAL("accessibility"))); |
67 EXPECT_TRUE(file_util::PathExists(test_path)) | 67 EXPECT_TRUE(file_util::PathExists(test_path)) |
68 << test_path.LossyDisplayName(); | 68 << test_path.LossyDisplayName(); |
69 | 69 |
| 70 // Output the test path to help anyone who encounters a failure and needs |
| 71 // to know where to look. |
| 72 printf("Path to test files: %s\n", test_path.MaybeAsASCII().c_str()); |
| 73 |
70 // Grab all HTML files. | 74 // Grab all HTML files. |
71 file_util::FileEnumerator file_enumerator(test_path, | 75 file_util::FileEnumerator file_enumerator(test_path, |
72 false, | 76 false, |
73 file_util::FileEnumerator::FILES, | 77 file_util::FileEnumerator::FILES, |
74 FILE_PATH_LITERAL("*.html")); | 78 FILE_PATH_LITERAL("*.html")); |
75 | 79 |
76 // TODO(dtseng): Make each of these a gtest with script. | 80 // TODO(dtseng): Make each of these a gtest with script. |
77 FilePath html_file(file_enumerator.Next()); | 81 FilePath html_file(file_enumerator.Next()); |
78 ASSERT_FALSE(html_file.empty()); | 82 ASSERT_FALSE(html_file.empty()); |
79 do { | 83 do { |
| 84 printf("Testing %s\n", html_file.BaseName().MaybeAsASCII().c_str()); |
| 85 |
80 std::string html_contents; | 86 std::string html_contents; |
81 file_util::ReadFileToString(html_file, &html_contents); | 87 file_util::ReadFileToString(html_file, &html_contents); |
82 | 88 |
83 std::string expected_contents; | 89 // Read the expected file. |
| 90 std::string expected_contents_raw; |
84 FilePath expected_file = | 91 FilePath expected_file = |
85 FilePath(html_file.RemoveExtension().value() + | 92 FilePath(html_file.RemoveExtension().value() + |
86 helper_.GetExpectedFileSuffix()); | 93 helper_.GetExpectedFileSuffix()); |
87 file_util::ReadFileToString( | 94 file_util::ReadFileToString( |
88 expected_file, | 95 expected_file, |
89 &expected_contents); | 96 &expected_contents_raw); |
| 97 |
| 98 // Tolerate Windows-style line endings (\r\n) in the expected file: |
| 99 // normalize by deleting all \r from the file (if any) to leave only \n. |
| 100 std::string expected_contents; |
| 101 RemoveChars(expected_contents_raw, "\r", &expected_contents); |
90 | 102 |
91 // Load the page. | 103 // Load the page. |
92 ui_test_utils::WindowedNotificationObserver tree_updated_observer( | 104 ui_test_utils::WindowedNotificationObserver tree_updated_observer( |
93 content::NOTIFICATION_RENDER_VIEW_HOST_ACCESSIBILITY_TREE_UPDATED, | 105 content::NOTIFICATION_RENDER_VIEW_HOST_ACCESSIBILITY_TREE_UPDATED, |
94 content::NotificationService::AllSources()); | 106 content::NotificationService::AllSources()); |
95 string16 html_contents16; | 107 string16 html_contents16; |
96 html_contents16 = UTF8ToUTF16(html_contents); | 108 html_contents16 = UTF8ToUTF16(html_contents); |
97 GURL url(UTF8ToUTF16(kUrlPreamble) + html_contents16); | 109 GURL url(UTF8ToUTF16(kUrlPreamble) + html_contents16); |
98 browser()->OpenURL(OpenURLParams( | 110 browser()->OpenURL(OpenURLParams( |
99 url, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_TYPED, false)); | 111 url, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_TYPED, false)); |
100 | 112 |
101 // Wait for the tree. | 113 // Wait for the tree. |
102 tree_updated_observer.Wait(); | 114 tree_updated_observer.Wait(); |
103 | 115 |
104 // Perform a diff (or write the initial baseline). | 116 // Perform a diff (or write the initial baseline). |
105 string16 actual_contents; | 117 string16 actual_contents_utf16; |
106 helper_.DumpAccessibilityTree( | 118 helper_.DumpAccessibilityTree( |
107 host_view->GetBrowserAccessibilityManager()->GetRoot(), | 119 host_view->GetBrowserAccessibilityManager()->GetRoot(), |
108 &actual_contents); | 120 &actual_contents_utf16); |
109 std::string actual_contents8 = UTF16ToUTF8(actual_contents); | 121 std::string actual_contents = UTF16ToUTF8(actual_contents_utf16); |
110 EXPECT_EQ(expected_contents, actual_contents8); | 122 EXPECT_TRUE(expected_contents == actual_contents); |
| 123 if (expected_contents != actual_contents) { |
| 124 printf("*** EXPECTED: ***\n%s\n", expected_contents.c_str()); |
| 125 printf("*** ACTUAL: ***\n%s\n", actual_contents.c_str()); |
| 126 } |
111 | 127 |
112 if (!file_util::PathExists(expected_file)) { | 128 if (!file_util::PathExists(expected_file)) { |
113 FilePath actual_file = | 129 FilePath actual_file = |
114 FilePath(html_file.RemoveExtension().value() + | 130 FilePath(html_file.RemoveExtension().value() + |
115 helper_.GetActualFileSuffix()); | 131 helper_.GetActualFileSuffix()); |
116 | 132 |
117 EXPECT_TRUE(file_util::WriteFile( | 133 EXPECT_TRUE(file_util::WriteFile( |
118 actual_file, actual_contents8.c_str(), actual_contents8.size())); | 134 actual_file, actual_contents.c_str(), actual_contents.size())); |
119 | 135 |
120 ADD_FAILURE() << "No expectation found. Create it by doing:\n" | 136 ADD_FAILURE() << "No expectation found. Create it by doing:\n" |
121 << "mv " << actual_file.LossyDisplayName() << " " | 137 << "mv " << actual_file.LossyDisplayName() << " " |
122 << expected_file.LossyDisplayName(); | 138 << expected_file.LossyDisplayName(); |
123 } | 139 } |
124 } while (!(html_file = file_enumerator.Next()).empty()); | 140 } while (!(html_file = file_enumerator.Next()).empty()); |
125 } | 141 } |
OLD | NEW |