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

Side by Side Diff: content/test/layout_browsertest.cc

Issue 10869061: Make IndexedDB layout browser tests save incorrect results to a file (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix << Created 8 years, 3 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 | « content/test/layout_browsertest.h ('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) 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 "content/test/layout_browsertest.h" 5 #include "content/test/layout_browsertest.h"
6 6
7 #include "base/command_line.h"
7 #include "base/file_path.h" 8 #include "base/file_path.h"
8 #include "base/file_util.h" 9 #include "base/file_util.h"
9 #include "base/path_service.h" 10 #include "base/path_service.h"
10 #include "base/rand_util.h" 11 #include "base/rand_util.h"
11 #include "base/scoped_temp_dir.h" 12 #include "base/scoped_temp_dir.h"
12 #include "base/stringprintf.h" 13 #include "base/stringprintf.h"
13 #include "base/string_util.h" 14 #include "base/string_util.h"
14 #include "base/utf_string_conversions.h" 15 #include "base/utf_string_conversions.h"
15 #include "content/browser/web_contents/web_contents_impl.h" 16 #include "content/browser/web_contents/web_contents_impl.h"
16 #include "content/public/common/content_paths.h" 17 #include "content/public/common/content_paths.h"
17 #include "content/public/test/browser_test_utils.h" 18 #include "content/public/test/browser_test_utils.h"
18 #include "content/shell/shell.h" 19 #include "content/shell/shell.h"
20 #include "content/shell/shell_switches.h"
19 #include "content/test/content_browser_test_utils.h" 21 #include "content/test/content_browser_test_utils.h"
20 #include "content/test/layout_test_http_server.h" 22 #include "content/test/layout_test_http_server.h"
21 #include "net/base/net_util.h" 23 #include "net/base/net_util.h"
22 24
23 #if defined(OS_WIN) 25 #if defined(OS_WIN)
24 static const char kPlatformName[] = "chromium-win"; 26 static const char kPlatformName[] = "chromium-win";
25 #elif defined(OS_MACOSX) 27 #elif defined(OS_MACOSX)
26 static const char kPlatformName[] = "chromium-mac"; 28 static const char kPlatformName[] = "chromium-mac";
27 #elif defined(OS_LINUX) 29 #elif defined(OS_LINUX)
28 static const char kPlatformName[] = "chromium-linux"; 30 static const char kPlatformName[] = "chromium-linux";
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 test_case_file_name, 210 test_case_file_name,
209 &expected_text)) 211 &expected_text))
210 ReadExpectedResult(our_original_layout_test_dir_, 212 ReadExpectedResult(our_original_layout_test_dir_,
211 test_case_file_name, 213 test_case_file_name,
212 &expected_text); 214 &expected_text);
213 } 215 }
214 ASSERT_TRUE(!expected_text.empty()); 216 ASSERT_TRUE(!expected_text.empty());
215 ReplaceSubstringsAfterOffset(&expected_text, 0, "\r", ""); 217 ReplaceSubstringsAfterOffset(&expected_text, 0, "\r", "");
216 TrimString(expected_text, "\n", &expected_text); 218 TrimString(expected_text, "\n", &expected_text);
217 219
218 EXPECT_EQ(expected_text, actual_text); 220 CommandLine* command_line = CommandLine::ForCurrentProcess();
221 if (command_line->HasSwitch(switches::kOutputLayoutTestDifferences)) {
222 EXPECT_EQ(expected_text, actual_text) <<
223 SaveResults(expected_text, actual_text);
224 } else {
225 EXPECT_EQ(expected_text, actual_text);
226 }
219 } 227 }
220 228
221 void InProcessBrowserLayoutTest::AddResourceForLayoutTest( 229 void InProcessBrowserLayoutTest::AddResourceForLayoutTest(
222 const FilePath& parent_dir, 230 const FilePath& parent_dir,
223 const FilePath& resource_name) { 231 const FilePath& resource_name) {
224 FilePath source; 232 FilePath source;
225 ASSERT_TRUE(PathService::Get(content::DIR_LAYOUT_TESTS, &source)); 233 ASSERT_TRUE(PathService::Get(content::DIR_LAYOUT_TESTS, &source));
226 source = source.Append(parent_dir); 234 source = source.Append(parent_dir);
227 source = source.Append(resource_name); 235 source = source.Append(resource_name);
228 236
(...skipping 20 matching lines...) Expand all
249 ASSERT_TRUE(file_util::ReadFileToString(path_to_single_test, &test_html)); 257 ASSERT_TRUE(file_util::ReadFileToString(path_to_single_test, &test_html));
250 258
251 size_t insertion_position = FindInsertPosition(test_html); 259 size_t insertion_position = FindInsertPosition(test_html);
252 test_html.insert(insertion_position, preamble); 260 test_html.insert(insertion_position, preamble);
253 *test_path = our_layout_test_temp_dir_.Append(test_case_dir_); 261 *test_path = our_layout_test_temp_dir_.Append(test_case_dir_);
254 *test_path = test_path->AppendASCII(test_case_file_name); 262 *test_path = test_path->AppendASCII(test_case_file_name);
255 ASSERT_TRUE(file_util::WriteFile(*test_path, 263 ASSERT_TRUE(file_util::WriteFile(*test_path,
256 &test_html.at(0), 264 &test_html.at(0),
257 static_cast<int>(test_html.size()))); 265 static_cast<int>(test_html.size())));
258 } 266 }
267
268 std::string InProcessBrowserLayoutTest::SaveResults(const std::string& expected,
269 const std::string& actual) {
270 FilePath cwd;
271 EXPECT_TRUE(file_util::CreateNewTempDirectory(FILE_PATH_LITERAL(""), &cwd));
272 FilePath expected_filename = cwd.Append(FILE_PATH_LITERAL("expected.txt"));
273 FilePath actual_filename = cwd.Append(FILE_PATH_LITERAL("actual.txt"));
274 EXPECT_NE(-1, file_util::WriteFile(expected_filename,
275 expected.c_str(),
276 expected.size()));
277 EXPECT_NE(-1, file_util::WriteFile(actual_filename,
278 actual.c_str(),
279 actual.size()));
280 return StringPrintf("Wrote %"PRFilePath" %"PRFilePath,
281 expected_filename.value().c_str(),
282 actual_filename.value().c_str());
283 }
OLDNEW
« no previous file with comments | « content/test/layout_browsertest.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698