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

Side by Side Diff: chrome/test/ui/ui_layout_test.cc

Issue 2879003: Run appcache layout tests in chrome using the ui test harness. ... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 5 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 | « chrome/test/data/layout_tests/layout_test_controller.html ('k') | no next file » | 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) 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
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
159 void UILayoutTest::RunLayoutTest(const std::string& test_case_file_name, 169 void UILayoutTest::RunLayoutTest(const std::string& test_case_file_name,
160 int port) { 170 int port) {
161 SCOPED_TRACE(test_case_file_name.c_str()); 171 SCOPED_TRACE(test_case_file_name.c_str());
162 172
163 ASSERT_TRUE(!layout_test_controller_.empty()); 173 ASSERT_TRUE(!layout_test_controller_.empty());
164 174
165 // Creates a new cookie name. We will have to use a new cookie because 175 // Creates a new cookie name. We will have to use a new cookie because
166 // this function could be called multiple times. 176 // this function could be called multiple times.
167 std::string status_cookie(kTestCompleteCookie); 177 std::string status_cookie(kTestCompleteCookie);
168 status_cookie += IntToString(test_count_); 178 status_cookie += IntToString(test_count_);
169 test_count_++; 179 test_count_++;
170 180
171 // Reads the layout test HTML file. 181 // Reads the layout test HTML file.
172 FilePath test_file_path(layout_test_dir_); 182 FilePath test_file_path(layout_test_dir_);
173 test_file_path = test_file_path.AppendASCII(test_case_file_name); 183 test_file_path = test_file_path.AppendASCII(test_case_file_name);
174 std::string test_html; 184 std::string test_html;
175 ASSERT_TRUE(file_util::ReadFileToString(test_file_path, &test_html)); 185 ASSERT_TRUE(file_util::ReadFileToString(test_file_path, &test_html));
176 186
177 // Injects the layout test controller into the test HTML. 187 // Injects the layout test controller into the test HTML.
178 test_html.insert(0, layout_test_controller_); 188 size_t insertion_position = FindInsertPosition(test_html);
179 ReplaceSubstringsAfterOffset( 189 test_html.insert(insertion_position, layout_test_controller_);
180 &test_html, 0, "%COOKIE%", status_cookie.c_str()); 190 ReplaceFirstSubstringAfterOffset(
191 &test_html, insertion_position, "%COOKIE%", status_cookie.c_str());
181 192
182 // Creates the new layout test HTML file. 193 // Creates the new layout test HTML file.
183 FilePath new_test_file_path(new_layout_test_dir_); 194 FilePath new_test_file_path(new_layout_test_dir_);
184 new_test_file_path = new_test_file_path.AppendASCII(test_case_file_name); 195 new_test_file_path = new_test_file_path.AppendASCII(test_case_file_name);
185 ASSERT_TRUE(file_util::WriteFile(new_test_file_path, 196 ASSERT_TRUE(file_util::WriteFile(new_test_file_path,
186 &test_html.at(0), 197 &test_html.at(0),
187 static_cast<int>(test_html.size()))); 198 static_cast<int>(test_html.size())));
188 199
189 scoped_ptr<GURL> new_test_url; 200 scoped_ptr<GURL> new_test_url;
190 if (port != kNoHttpPort) 201 if (port != kNoHttpPort)
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 std::string* expected_result_value) { 253 std::string* expected_result_value) {
243 FilePath expected_result_path(result_dir_path); 254 FilePath expected_result_path(result_dir_path);
244 expected_result_path = expected_result_path.AppendASCII(test_case_file_name); 255 expected_result_path = expected_result_path.AppendASCII(test_case_file_name);
245 expected_result_path = expected_result_path.InsertBeforeExtension( 256 expected_result_path = expected_result_path.InsertBeforeExtension(
246 FILE_PATH_LITERAL("-expected")); 257 FILE_PATH_LITERAL("-expected"));
247 expected_result_path = 258 expected_result_path =
248 expected_result_path.ReplaceExtension(FILE_PATH_LITERAL("txt")); 259 expected_result_path.ReplaceExtension(FILE_PATH_LITERAL("txt"));
249 return file_util::ReadFileToString(expected_result_path, 260 return file_util::ReadFileToString(expected_result_path,
250 expected_result_value); 261 expected_result_value);
251 } 262 }
OLDNEW
« no previous file with comments | « chrome/test/data/layout_tests/layout_test_controller.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698