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 "content/test/layout_browsertest.h" | 5 #include "content/test/layout_browsertest.h" |
6 | 6 |
7 #include <sstream> | 7 #include <sstream> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
(...skipping 25 matching lines...) Expand all Loading... |
36 static const char kPlatformName[] = "chromium-openbsd"; | 36 static const char kPlatformName[] = "chromium-openbsd"; |
37 #elif defined(OS_ANDROID) | 37 #elif defined(OS_ANDROID) |
38 static const char kPlatformName[] = "chromium-android"; | 38 static const char kPlatformName[] = "chromium-android"; |
39 #else | 39 #else |
40 #error No known OS defined | 40 #error No known OS defined |
41 #endif | 41 #endif |
42 | 42 |
43 namespace content { | 43 namespace content { |
44 namespace { | 44 namespace { |
45 | 45 |
46 bool ReadExpectedResult(const FilePath& result_dir_path, | 46 bool ReadExpectedResult(const base::FilePath& result_dir_path, |
47 const std::string test_case_file_name, | 47 const std::string test_case_file_name, |
48 std::string* expected_result_value) { | 48 std::string* expected_result_value) { |
49 FilePath expected_result_path(result_dir_path); | 49 base::FilePath expected_result_path(result_dir_path); |
50 expected_result_path = expected_result_path.AppendASCII(test_case_file_name); | 50 expected_result_path = expected_result_path.AppendASCII(test_case_file_name); |
51 expected_result_path = expected_result_path.InsertBeforeExtension( | 51 expected_result_path = expected_result_path.InsertBeforeExtension( |
52 FILE_PATH_LITERAL("-expected")); | 52 FILE_PATH_LITERAL("-expected")); |
53 expected_result_path = | 53 expected_result_path = |
54 expected_result_path.ReplaceExtension(FILE_PATH_LITERAL("txt")); | 54 expected_result_path.ReplaceExtension(FILE_PATH_LITERAL("txt")); |
55 return file_util::ReadFileToString( | 55 return file_util::ReadFileToString( |
56 expected_result_path, expected_result_value); | 56 expected_result_path, expected_result_value); |
57 } | 57 } |
58 | 58 |
59 } // namespace | 59 } // namespace |
60 | 60 |
61 InProcessBrowserLayoutTest::InProcessBrowserLayoutTest( | 61 InProcessBrowserLayoutTest::InProcessBrowserLayoutTest( |
62 const FilePath& test_parent_dir, const FilePath& test_case_dir) | 62 const base::FilePath& test_parent_dir, const base::FilePath& test_case_dir) |
63 : test_parent_dir_(test_parent_dir), test_case_dir_(test_case_dir), | 63 : test_parent_dir_(test_parent_dir), test_case_dir_(test_case_dir), |
64 port_(-2) { | 64 port_(-2) { |
65 } | 65 } |
66 | 66 |
67 InProcessBrowserLayoutTest::InProcessBrowserLayoutTest( | 67 InProcessBrowserLayoutTest::InProcessBrowserLayoutTest( |
68 const FilePath& test_parent_dir, const FilePath& test_case_dir, int port) | 68 const base::FilePath& test_parent_dir, |
| 69 const base::FilePath& test_case_dir, |
| 70 int port) |
69 : test_parent_dir_(test_parent_dir), test_case_dir_(test_case_dir), | 71 : test_parent_dir_(test_parent_dir), test_case_dir_(test_case_dir), |
70 port_(port) { | 72 port_(port) { |
71 } | 73 } |
72 | 74 |
73 InProcessBrowserLayoutTest::~InProcessBrowserLayoutTest() { | 75 InProcessBrowserLayoutTest::~InProcessBrowserLayoutTest() { |
74 if (test_http_server_.get()) | 76 if (test_http_server_.get()) |
75 CHECK(test_http_server_->Stop()); | 77 CHECK(test_http_server_->Stop()); |
76 } | 78 } |
77 | 79 |
78 void InProcessBrowserLayoutTest::SetUpInProcessBrowserTestFixture() { | 80 void InProcessBrowserLayoutTest::SetUpInProcessBrowserTestFixture() { |
79 FilePath src_dir; | 81 base::FilePath src_dir; |
80 ASSERT_TRUE(PathService::Get(DIR_LAYOUT_TESTS, &src_dir)); | 82 ASSERT_TRUE(PathService::Get(DIR_LAYOUT_TESTS, &src_dir)); |
81 FilePath absolute_parent_dir = src_dir.Append(test_parent_dir_); | 83 base::FilePath absolute_parent_dir = src_dir.Append(test_parent_dir_); |
82 ASSERT_TRUE(file_util::DirectoryExists(absolute_parent_dir)); | 84 ASSERT_TRUE(file_util::DirectoryExists(absolute_parent_dir)); |
83 layout_test_dir_ = absolute_parent_dir.Append(test_case_dir_); | 85 layout_test_dir_ = absolute_parent_dir.Append(test_case_dir_); |
84 ASSERT_TRUE(file_util::DirectoryExists(layout_test_dir_)); | 86 ASSERT_TRUE(file_util::DirectoryExists(layout_test_dir_)); |
85 | 87 |
86 // Gets the file path to rebased expected result directory for the current | 88 // Gets the file path to rebased expected result directory for the current |
87 // platform. | 89 // platform. |
88 // $LayoutTestRoot/platform/chromium_***/... | 90 // $LayoutTestRoot/platform/chromium_***/... |
89 rebase_result_dir_ = src_dir.AppendASCII("platform"); | 91 rebase_result_dir_ = src_dir.AppendASCII("platform"); |
90 rebase_result_dir_ = rebase_result_dir_.AppendASCII(kPlatformName); | 92 rebase_result_dir_ = rebase_result_dir_.AppendASCII(kPlatformName); |
91 rebase_result_dir_ = rebase_result_dir_.Append(test_parent_dir_); | 93 rebase_result_dir_ = rebase_result_dir_.Append(test_parent_dir_); |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 if (command_line->HasSwitch(switches::kOutputLayoutTestDifferences)) { | 187 if (command_line->HasSwitch(switches::kOutputLayoutTestDifferences)) { |
186 EXPECT_EQ(expected_text, actual_text) << | 188 EXPECT_EQ(expected_text, actual_text) << |
187 SaveResults(expected_text, actual_text); | 189 SaveResults(expected_text, actual_text); |
188 } else { | 190 } else { |
189 EXPECT_EQ(expected_text, actual_text); | 191 EXPECT_EQ(expected_text, actual_text); |
190 } | 192 } |
191 } | 193 } |
192 | 194 |
193 std::string InProcessBrowserLayoutTest::SaveResults(const std::string& expected, | 195 std::string InProcessBrowserLayoutTest::SaveResults(const std::string& expected, |
194 const std::string& actual) { | 196 const std::string& actual) { |
195 FilePath cwd; | 197 base::FilePath cwd; |
196 EXPECT_TRUE(file_util::CreateNewTempDirectory(FILE_PATH_LITERAL(""), &cwd)); | 198 EXPECT_TRUE(file_util::CreateNewTempDirectory(FILE_PATH_LITERAL(""), &cwd)); |
197 FilePath expected_filename = cwd.Append(FILE_PATH_LITERAL("expected.txt")); | 199 base::FilePath expected_filename = cwd.Append( |
198 FilePath actual_filename = cwd.Append(FILE_PATH_LITERAL("actual.txt")); | 200 FILE_PATH_LITERAL("expected.txt")); |
| 201 base::FilePath actual_filename = cwd.Append(FILE_PATH_LITERAL("actual.txt")); |
199 EXPECT_NE(-1, file_util::WriteFile(expected_filename, | 202 EXPECT_NE(-1, file_util::WriteFile(expected_filename, |
200 expected.c_str(), | 203 expected.c_str(), |
201 expected.size())); | 204 expected.size())); |
202 EXPECT_NE(-1, file_util::WriteFile(actual_filename, | 205 EXPECT_NE(-1, file_util::WriteFile(actual_filename, |
203 actual.c_str(), | 206 actual.c_str(), |
204 actual.size())); | 207 actual.size())); |
205 return StringPrintf("Wrote %"PRFilePath" %"PRFilePath, | 208 return StringPrintf("Wrote %"PRFilePath" %"PRFilePath, |
206 expected_filename.value().c_str(), | 209 expected_filename.value().c_str(), |
207 actual_filename.value().c_str()); | 210 actual_filename.value().c_str()); |
208 } | 211 } |
209 | 212 |
210 } // namespace content | 213 } // namespace content |
OLD | NEW |