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 21 matching lines...) Expand all Loading... |
32 #elif defined(OS_MACOSX) | 32 #elif defined(OS_MACOSX) |
33 static const char kPlatformName[] = "chromium-mac"; | 33 static const char kPlatformName[] = "chromium-mac"; |
34 #elif defined(OS_LINUX) | 34 #elif defined(OS_LINUX) |
35 static const char kPlatformName[] = "chromium-linux"; | 35 static const char kPlatformName[] = "chromium-linux"; |
36 #elif defined(OS_OPENBSD) | 36 #elif defined(OS_OPENBSD) |
37 static const char kPlatformName[] = "chromium-openbsd"; | 37 static const char kPlatformName[] = "chromium-openbsd"; |
38 #else | 38 #else |
39 #error No known OS defined | 39 #error No known OS defined |
40 #endif | 40 #endif |
41 | 41 |
| 42 namespace content { |
42 namespace { | 43 namespace { |
43 | 44 |
44 bool ReadExpectedResult(const FilePath& result_dir_path, | 45 bool ReadExpectedResult(const FilePath& result_dir_path, |
45 const std::string test_case_file_name, | 46 const std::string test_case_file_name, |
46 std::string* expected_result_value) { | 47 std::string* expected_result_value) { |
47 FilePath expected_result_path(result_dir_path); | 48 FilePath expected_result_path(result_dir_path); |
48 expected_result_path = expected_result_path.AppendASCII(test_case_file_name); | 49 expected_result_path = expected_result_path.AppendASCII(test_case_file_name); |
49 expected_result_path = expected_result_path.InsertBeforeExtension( | 50 expected_result_path = expected_result_path.InsertBeforeExtension( |
50 FILE_PATH_LITERAL("-expected")); | 51 FILE_PATH_LITERAL("-expected")); |
51 expected_result_path = | 52 expected_result_path = |
(...skipping 16 matching lines...) Expand all Loading... |
68 port_(port) { | 69 port_(port) { |
69 } | 70 } |
70 | 71 |
71 InProcessBrowserLayoutTest::~InProcessBrowserLayoutTest() { | 72 InProcessBrowserLayoutTest::~InProcessBrowserLayoutTest() { |
72 if (test_http_server_.get()) | 73 if (test_http_server_.get()) |
73 CHECK(test_http_server_->Stop()); | 74 CHECK(test_http_server_->Stop()); |
74 } | 75 } |
75 | 76 |
76 void InProcessBrowserLayoutTest::SetUpInProcessBrowserTestFixture() { | 77 void InProcessBrowserLayoutTest::SetUpInProcessBrowserTestFixture() { |
77 FilePath src_dir; | 78 FilePath src_dir; |
78 ASSERT_TRUE(PathService::Get(content::DIR_LAYOUT_TESTS, &src_dir)); | 79 ASSERT_TRUE(PathService::Get(DIR_LAYOUT_TESTS, &src_dir)); |
79 FilePath absolute_parent_dir = src_dir.Append(test_parent_dir_); | 80 FilePath absolute_parent_dir = src_dir.Append(test_parent_dir_); |
80 ASSERT_TRUE(file_util::DirectoryExists(absolute_parent_dir)); | 81 ASSERT_TRUE(file_util::DirectoryExists(absolute_parent_dir)); |
81 layout_test_dir_ = absolute_parent_dir.Append(test_case_dir_); | 82 layout_test_dir_ = absolute_parent_dir.Append(test_case_dir_); |
82 ASSERT_TRUE(file_util::DirectoryExists(layout_test_dir_)); | 83 ASSERT_TRUE(file_util::DirectoryExists(layout_test_dir_)); |
83 | 84 |
84 // Gets the file path to rebased expected result directory for the current | 85 // Gets the file path to rebased expected result directory for the current |
85 // platform. | 86 // platform. |
86 // $LayoutTestRoot/platform/chromium_***/... | 87 // $LayoutTestRoot/platform/chromium_***/... |
87 rebase_result_dir_ = src_dir.AppendASCII("platform"); | 88 rebase_result_dir_ = src_dir.AppendASCII("platform"); |
88 rebase_result_dir_ = rebase_result_dir_.AppendASCII(kPlatformName); | 89 rebase_result_dir_ = rebase_result_dir_.AppendASCII(kPlatformName); |
(...skipping 28 matching lines...) Expand all Loading... |
117 ASSERT_TRUE(test_http_server_->Start()); | 118 ASSERT_TRUE(test_http_server_->Start()); |
118 } | 119 } |
119 } | 120 } |
120 | 121 |
121 void InProcessBrowserLayoutTest::SetUpCommandLine(CommandLine* command_line) { | 122 void InProcessBrowserLayoutTest::SetUpCommandLine(CommandLine* command_line) { |
122 command_line->AppendSwitch(switches::kDumpRenderTree); | 123 command_line->AppendSwitch(switches::kDumpRenderTree); |
123 command_line->AppendSwitch(switches::kIgnoreCertificateErrors); | 124 command_line->AppendSwitch(switches::kIgnoreCertificateErrors); |
124 } | 125 } |
125 | 126 |
126 void InProcessBrowserLayoutTest::SetUpOnMainThread() { | 127 void InProcessBrowserLayoutTest::SetUpOnMainThread() { |
127 test_controller_.reset(new content::WebKitTestController); | 128 test_controller_.reset(new WebKitTestController); |
128 } | 129 } |
129 | 130 |
130 void InProcessBrowserLayoutTest::RunLayoutTest( | 131 void InProcessBrowserLayoutTest::RunLayoutTest( |
131 const std::string& test_case_file_name) { | 132 const std::string& test_case_file_name) { |
132 GURL url = net::FilePathToFileURL( | 133 GURL url = net::FilePathToFileURL( |
133 layout_test_dir_.AppendASCII(test_case_file_name)); | 134 layout_test_dir_.AppendASCII(test_case_file_name)); |
134 RunLayoutTestInternal(test_case_file_name, url); | 135 RunLayoutTestInternal(test_case_file_name, url); |
135 } | 136 } |
136 | 137 |
137 void InProcessBrowserLayoutTest::RunHttpLayoutTest( | 138 void InProcessBrowserLayoutTest::RunHttpLayoutTest( |
138 const std::string& test_case_file_name) { | 139 const std::string& test_case_file_name) { |
139 DCHECK(test_http_server_.get()); | 140 DCHECK(test_http_server_.get()); |
140 GURL url(StringPrintf( | 141 GURL url(StringPrintf( |
141 "http://127.0.0.1:%d/%s/%s", port_, test_case_dir_.MaybeAsASCII().c_str(), | 142 "http://127.0.0.1:%d/%s/%s", port_, test_case_dir_.MaybeAsASCII().c_str(), |
142 test_case_file_name.c_str())); | 143 test_case_file_name.c_str())); |
143 RunLayoutTestInternal(test_case_file_name, url); | 144 RunLayoutTestInternal(test_case_file_name, url); |
144 } | 145 } |
145 | 146 |
146 void InProcessBrowserLayoutTest::RunLayoutTestInternal( | 147 void InProcessBrowserLayoutTest::RunLayoutTestInternal( |
147 const std::string& test_case_file_name, const GURL& url) { | 148 const std::string& test_case_file_name, const GURL& url) { |
148 std::stringstream result; | 149 std::stringstream result; |
149 scoped_ptr<content::WebKitTestResultPrinter> printer( | 150 scoped_ptr<WebKitTestResultPrinter> printer( |
150 new content::WebKitTestResultPrinter(&result, NULL)); | 151 new WebKitTestResultPrinter(&result, NULL)); |
151 printer->set_capture_text_only(true); | 152 printer->set_capture_text_only(true); |
152 test_controller_->set_printer(printer.release()); | 153 test_controller_->set_printer(printer.release()); |
153 | 154 |
154 LOG(INFO) << "Navigating to URL " << url << " and blocking."; | 155 LOG(INFO) << "Navigating to URL " << url << " and blocking."; |
155 ASSERT_TRUE(test_controller_->PrepareForLayoutTest(url, false, "")); | 156 ASSERT_TRUE(test_controller_->PrepareForLayoutTest(url, false, "")); |
156 base::RunLoop run_loop; | 157 base::RunLoop run_loop; |
157 run_loop.Run(); | 158 run_loop.Run(); |
158 LOG(INFO) << "Navigation completed."; | 159 LOG(INFO) << "Navigation completed."; |
159 ASSERT_TRUE(test_controller_->ResetAfterLayoutTest()); | 160 ASSERT_TRUE(test_controller_->ResetAfterLayoutTest()); |
160 | 161 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 EXPECT_NE(-1, file_util::WriteFile(expected_filename, | 198 EXPECT_NE(-1, file_util::WriteFile(expected_filename, |
198 expected.c_str(), | 199 expected.c_str(), |
199 expected.size())); | 200 expected.size())); |
200 EXPECT_NE(-1, file_util::WriteFile(actual_filename, | 201 EXPECT_NE(-1, file_util::WriteFile(actual_filename, |
201 actual.c_str(), | 202 actual.c_str(), |
202 actual.size())); | 203 actual.size())); |
203 return StringPrintf("Wrote %"PRFilePath" %"PRFilePath, | 204 return StringPrintf("Wrote %"PRFilePath" %"PRFilePath, |
204 expected_filename.value().c_str(), | 205 expected_filename.value().c_str(), |
205 actual_filename.value().c_str()); | 206 actual_filename.value().c_str()); |
206 } | 207 } |
| 208 |
| 209 } // namespace content |
OLD | NEW |