OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/test/ui/ui_layout_test.h" | 5 #include "chrome/test/ui/ui_layout_test.h" |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
9 #include "base/string_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
(...skipping 25 matching lines...) Expand all Loading... |
36 UILayoutTest::~UILayoutTest() { | 36 UILayoutTest::~UILayoutTest() { |
37 if (!temp_test_dir_.empty()) { | 37 if (!temp_test_dir_.empty()) { |
38 // The deletion might fail because HTTP server process might not been | 38 // The deletion might fail because HTTP server process might not been |
39 // completely shut down yet and is still holding certain handle to it. | 39 // completely shut down yet and is still holding certain handle to it. |
40 // To work around this problem, we try to repeat the deletion several | 40 // To work around this problem, we try to repeat the deletion several |
41 // times. | 41 // times. |
42 EXPECT_TRUE(file_util::DieFileDie(temp_test_dir_, true)); | 42 EXPECT_TRUE(file_util::DieFileDie(temp_test_dir_, true)); |
43 } | 43 } |
44 } | 44 } |
45 | 45 |
| 46 // Gets layout tests root. For the current git workflow, this is |
| 47 // third_party/WebKit/LayoutTests |
| 48 // On svn workflow (including build machines) and older git workflow, this is |
| 49 // chrome/test/data/layout_tests/LayoutTests |
| 50 // This function probes for the first and then fallbacks to the second. |
| 51 static FilePath GetLayoutTestRoot() { |
| 52 FilePath src_root; |
| 53 PathService::Get(base::DIR_SOURCE_ROOT, &src_root); |
| 54 |
| 55 FilePath webkit_layout_tests = src_root; |
| 56 webkit_layout_tests = webkit_layout_tests.AppendASCII("third_party"); |
| 57 webkit_layout_tests = webkit_layout_tests.AppendASCII("WebKit"); |
| 58 webkit_layout_tests = webkit_layout_tests.AppendASCII("LayoutTests"); |
| 59 if (file_util::DirectoryExists(webkit_layout_tests)) |
| 60 return webkit_layout_tests; |
| 61 |
| 62 FilePath chrome_layout_tests = src_root; |
| 63 chrome_layout_tests = chrome_layout_tests.AppendASCII("chrome"); |
| 64 chrome_layout_tests = chrome_layout_tests.AppendASCII("test"); |
| 65 chrome_layout_tests = chrome_layout_tests.AppendASCII("data"); |
| 66 chrome_layout_tests = chrome_layout_tests.AppendASCII("layout_tests"); |
| 67 chrome_layout_tests = chrome_layout_tests.AppendASCII("LayoutTests"); |
| 68 return chrome_layout_tests; |
| 69 } |
| 70 |
46 void UILayoutTest::InitializeForLayoutTest(const FilePath& test_parent_dir, | 71 void UILayoutTest::InitializeForLayoutTest(const FilePath& test_parent_dir, |
47 const FilePath& test_case_dir, | 72 const FilePath& test_case_dir, |
48 int port) { | 73 int port) { |
49 FilePath src_dir; | 74 FilePath src_dir = GetLayoutTestRoot(); |
50 PathService::Get(base::DIR_SOURCE_ROOT, &src_dir); | |
51 | |
52 src_dir = src_dir.AppendASCII("chrome"); | |
53 src_dir = src_dir.AppendASCII("test"); | |
54 src_dir = src_dir.AppendASCII("data"); | |
55 src_dir = src_dir.AppendASCII("layout_tests"); | |
56 src_dir = src_dir.AppendASCII("LayoutTests"); | |
57 | |
58 // Gets the file path to WebKit ui layout tests, that is, | |
59 // chrome/test/data/ui_tests/LayoutTests/... | |
60 // Note that we have to use our own copy of WebKit layout tests because our | |
61 // build machines do not have WebKit layout tests added. | |
62 layout_test_dir_ = src_dir.Append(test_parent_dir); | 75 layout_test_dir_ = src_dir.Append(test_parent_dir); |
63 layout_test_dir_ = layout_test_dir_.Append(test_case_dir); | 76 layout_test_dir_ = layout_test_dir_.Append(test_case_dir); |
64 ASSERT_TRUE(file_util::DirectoryExists(layout_test_dir_)); | 77 ASSERT_TRUE(file_util::DirectoryExists(layout_test_dir_)); |
65 | 78 |
66 // Gets the file path to rebased expected result directory for the current | 79 // Gets the file path to rebased expected result directory for the current |
67 // platform. | 80 // platform. |
68 // chrome/test/data/layout_tests/LayoutTests/platform/chromium_***/... | 81 // $LayoutTestRoot/platform/chromium_***/... |
69 rebase_result_dir_ = src_dir.AppendASCII("platform"); | 82 rebase_result_dir_ = src_dir.AppendASCII("platform"); |
70 rebase_result_dir_ = rebase_result_dir_.AppendASCII(kPlatformName); | 83 rebase_result_dir_ = rebase_result_dir_.AppendASCII(kPlatformName); |
71 rebase_result_dir_ = rebase_result_dir_.Append(test_parent_dir); | 84 rebase_result_dir_ = rebase_result_dir_.Append(test_parent_dir); |
72 rebase_result_dir_ = rebase_result_dir_.Append(test_case_dir); | 85 rebase_result_dir_ = rebase_result_dir_.Append(test_case_dir); |
73 | 86 |
74 // Generic chromium expected results. Not OS-specific. For example, | 87 // Generic chromium expected results. Not OS-specific. For example, |
75 // v8-specific differences go here. | 88 // v8-specific differences go here. |
76 // chrome/test/data/layout_tests/LayoutTests/platform/chromium/... | 89 // chrome/test/data/layout_tests/LayoutTests/platform/chromium/... |
77 rebase_result_chromium_dir_ = src_dir.AppendASCII("platform") | 90 rebase_result_chromium_dir_ = src_dir.AppendASCII("platform") |
78 .AppendASCII("chromium") | 91 .AppendASCII("chromium") |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 // Reads the layout test controller simulation script. | 145 // Reads the layout test controller simulation script. |
133 FilePath path; | 146 FilePath path; |
134 PathService::Get(chrome::DIR_TEST_DATA, &path); | 147 PathService::Get(chrome::DIR_TEST_DATA, &path); |
135 path = path.AppendASCII("layout_tests"); | 148 path = path.AppendASCII("layout_tests"); |
136 path = path.AppendASCII("layout_test_controller.html"); | 149 path = path.AppendASCII("layout_test_controller.html"); |
137 ASSERT_TRUE(file_util::ReadFileToString(path, &layout_test_controller_)); | 150 ASSERT_TRUE(file_util::ReadFileToString(path, &layout_test_controller_)); |
138 } | 151 } |
139 | 152 |
140 void UILayoutTest::AddResourceForLayoutTest(const FilePath& parent_dir, | 153 void UILayoutTest::AddResourceForLayoutTest(const FilePath& parent_dir, |
141 const FilePath& resource_name) { | 154 const FilePath& resource_name) { |
142 FilePath root_dir; | 155 FilePath source = GetLayoutTestRoot(); |
143 PathService::Get(base::DIR_SOURCE_ROOT, &root_dir); | |
144 | |
145 FilePath source = root_dir.AppendASCII("chrome"); | |
146 source = source.AppendASCII("test"); | |
147 source = source.AppendASCII("data"); | |
148 source = source.AppendASCII("layout_tests"); | |
149 source = source.AppendASCII("LayoutTests"); | |
150 source = source.Append(parent_dir); | 156 source = source.Append(parent_dir); |
151 source = source.Append(resource_name); | 157 source = source.Append(resource_name); |
152 | 158 |
153 ASSERT_TRUE(file_util::PathExists(source)); | 159 ASSERT_TRUE(file_util::PathExists(source)); |
154 | 160 |
155 FilePath dest_parent_dir = temp_test_dir_. | 161 FilePath dest_parent_dir = temp_test_dir_. |
156 AppendASCII("LayoutTests").Append(parent_dir); | 162 AppendASCII("LayoutTests").Append(parent_dir); |
157 ASSERT_TRUE(file_util::CreateDirectory(dest_parent_dir)); | 163 ASSERT_TRUE(file_util::CreateDirectory(dest_parent_dir)); |
158 FilePath dest = dest_parent_dir.Append(resource_name); | 164 FilePath dest = dest_parent_dir.Append(resource_name); |
159 | 165 |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 std::string* expected_result_value) { | 273 std::string* expected_result_value) { |
268 FilePath expected_result_path(result_dir_path); | 274 FilePath expected_result_path(result_dir_path); |
269 expected_result_path = expected_result_path.AppendASCII(test_case_file_name); | 275 expected_result_path = expected_result_path.AppendASCII(test_case_file_name); |
270 expected_result_path = expected_result_path.InsertBeforeExtension( | 276 expected_result_path = expected_result_path.InsertBeforeExtension( |
271 FILE_PATH_LITERAL("-expected")); | 277 FILE_PATH_LITERAL("-expected")); |
272 expected_result_path = | 278 expected_result_path = |
273 expected_result_path.ReplaceExtension(FILE_PATH_LITERAL("txt")); | 279 expected_result_path.ReplaceExtension(FILE_PATH_LITERAL("txt")); |
274 return file_util::ReadFileToString(expected_result_path, | 280 return file_util::ReadFileToString(expected_result_path, |
275 expected_result_value); | 281 expected_result_value); |
276 } | 282 } |
OLD | NEW |