| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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_util.h" | 9 #include "base/string_util.h" |
| 10 #include "base/test/test_file_util.h" | 10 #include "base/test/test_file_util.h" |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 src_dir = src_dir.Append(resource_dir); | 149 src_dir = src_dir.Append(resource_dir); |
| 150 ASSERT_TRUE(file_util::DirectoryExists(src_dir)); | 150 ASSERT_TRUE(file_util::DirectoryExists(src_dir)); |
| 151 | 151 |
| 152 FilePath dest_parent_dir = temp_test_dir_. | 152 FilePath dest_parent_dir = temp_test_dir_. |
| 153 AppendASCII("LayoutTests").Append(parent_dir); | 153 AppendASCII("LayoutTests").Append(parent_dir); |
| 154 ASSERT_TRUE(file_util::CreateDirectory(dest_parent_dir)); | 154 ASSERT_TRUE(file_util::CreateDirectory(dest_parent_dir)); |
| 155 FilePath dest_dir = dest_parent_dir.Append(resource_dir); | 155 FilePath dest_dir = dest_parent_dir.Append(resource_dir); |
| 156 ASSERT_TRUE(file_util::CopyDirectory(src_dir, dest_dir, true)); | 156 ASSERT_TRUE(file_util::CopyDirectory(src_dir, dest_dir, true)); |
| 157 } | 157 } |
| 158 | 158 |
| 159 static size_t FindInsertPosition(const std::string& html) { | |
| 160 size_t tag_start = html.find("<html"); | |
| 161 if (tag_start == std::string::npos) | |
| 162 return 0; | |
| 163 size_t tag_end = html.find(">", tag_start); | |
| 164 if (tag_end == std::string::npos) | |
| 165 return 0; | |
| 166 return tag_end + 1; | |
| 167 } | |
| 168 | |
| 169 void UILayoutTest::RunLayoutTest(const std::string& test_case_file_name, | 159 void UILayoutTest::RunLayoutTest(const std::string& test_case_file_name, |
| 170 int port) { | 160 int port) { |
| 171 SCOPED_TRACE(test_case_file_name.c_str()); | 161 SCOPED_TRACE(test_case_file_name.c_str()); |
| 172 | 162 |
| 173 ASSERT_TRUE(!layout_test_controller_.empty()); | 163 ASSERT_TRUE(!layout_test_controller_.empty()); |
| 174 | 164 |
| 175 // Creates a new cookie name. We will have to use a new cookie because | 165 // Creates a new cookie name. We will have to use a new cookie because |
| 176 // this function could be called multiple times. | 166 // this function could be called multiple times. |
| 177 std::string status_cookie(kTestCompleteCookie); | 167 std::string status_cookie(kTestCompleteCookie); |
| 178 status_cookie += IntToString(test_count_); | 168 status_cookie += IntToString(test_count_); |
| 179 test_count_++; | 169 test_count_++; |
| 180 | 170 |
| 181 // Reads the layout test HTML file. | 171 // Reads the layout test HTML file. |
| 182 FilePath test_file_path(layout_test_dir_); | 172 FilePath test_file_path(layout_test_dir_); |
| 183 test_file_path = test_file_path.AppendASCII(test_case_file_name); | 173 test_file_path = test_file_path.AppendASCII(test_case_file_name); |
| 184 std::string test_html; | 174 std::string test_html; |
| 185 ASSERT_TRUE(file_util::ReadFileToString(test_file_path, &test_html)); | 175 ASSERT_TRUE(file_util::ReadFileToString(test_file_path, &test_html)); |
| 186 | 176 |
| 187 // Injects the layout test controller into the test HTML. | 177 // Injects the layout test controller into the test HTML. |
| 188 size_t insertion_position = FindInsertPosition(test_html); | 178 test_html.insert(0, layout_test_controller_); |
| 189 test_html.insert(insertion_position, layout_test_controller_); | 179 ReplaceSubstringsAfterOffset( |
| 190 ReplaceFirstSubstringAfterOffset( | 180 &test_html, 0, "%COOKIE%", status_cookie.c_str()); |
| 191 &test_html, insertion_position, "%COOKIE%", status_cookie.c_str()); | |
| 192 | 181 |
| 193 // Creates the new layout test HTML file. | 182 // Creates the new layout test HTML file. |
| 194 FilePath new_test_file_path(new_layout_test_dir_); | 183 FilePath new_test_file_path(new_layout_test_dir_); |
| 195 new_test_file_path = new_test_file_path.AppendASCII(test_case_file_name); | 184 new_test_file_path = new_test_file_path.AppendASCII(test_case_file_name); |
| 196 ASSERT_TRUE(file_util::WriteFile(new_test_file_path, | 185 ASSERT_TRUE(file_util::WriteFile(new_test_file_path, |
| 197 &test_html.at(0), | 186 &test_html.at(0), |
| 198 static_cast<int>(test_html.size()))); | 187 static_cast<int>(test_html.size()))); |
| 199 | 188 |
| 200 scoped_ptr<GURL> new_test_url; | 189 scoped_ptr<GURL> new_test_url; |
| 201 if (port != kNoHttpPort) | 190 if (port != kNoHttpPort) |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 std::string* expected_result_value) { | 242 std::string* expected_result_value) { |
| 254 FilePath expected_result_path(result_dir_path); | 243 FilePath expected_result_path(result_dir_path); |
| 255 expected_result_path = expected_result_path.AppendASCII(test_case_file_name); | 244 expected_result_path = expected_result_path.AppendASCII(test_case_file_name); |
| 256 expected_result_path = expected_result_path.InsertBeforeExtension( | 245 expected_result_path = expected_result_path.InsertBeforeExtension( |
| 257 FILE_PATH_LITERAL("-expected")); | 246 FILE_PATH_LITERAL("-expected")); |
| 258 expected_result_path = | 247 expected_result_path = |
| 259 expected_result_path.ReplaceExtension(FILE_PATH_LITERAL("txt")); | 248 expected_result_path.ReplaceExtension(FILE_PATH_LITERAL("txt")); |
| 260 return file_util::ReadFileToString(expected_result_path, | 249 return file_util::ReadFileToString(expected_result_path, |
| 261 expected_result_value); | 250 expected_result_value); |
| 262 } | 251 } |
| OLD | NEW |