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 "base/file_path.h" | 7 #include "base/file_path.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
10 #include "base/rand_util.h" | 10 #include "base/rand_util.h" |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 " this.workerThreadCount = 0; \n" | 77 " this.workerThreadCount = 0; \n" |
78 "}\n" | 78 "}\n" |
79 "window.layoutTestController = new LayoutTestController();\n" | 79 "window.layoutTestController = new LayoutTestController();\n" |
80 "</script>"; | 80 "</script>"; |
81 | 81 |
82 } | 82 } |
83 | 83 |
84 InProcessBrowserLayoutTest::InProcessBrowserLayoutTest( | 84 InProcessBrowserLayoutTest::InProcessBrowserLayoutTest( |
85 const FilePath& test_parent_dir, const FilePath& test_case_dir) | 85 const FilePath& test_parent_dir, const FilePath& test_case_dir) |
86 : test_parent_dir_(test_parent_dir), test_case_dir_(test_case_dir), | 86 : test_parent_dir_(test_parent_dir), test_case_dir_(test_case_dir), |
87 port_(-2) { | 87 port_(-2), wait_until_done_(true) { |
88 EnableDOMAutomation(); | 88 EnableDOMAutomation(); |
89 } | 89 } |
90 | 90 |
91 InProcessBrowserLayoutTest::InProcessBrowserLayoutTest( | 91 InProcessBrowserLayoutTest::InProcessBrowserLayoutTest( |
92 const FilePath& test_parent_dir, const FilePath& test_case_dir, int port) | 92 const FilePath& test_parent_dir, const FilePath& test_case_dir, int port) |
93 : test_parent_dir_(test_parent_dir), test_case_dir_(test_case_dir), | 93 : test_parent_dir_(test_parent_dir), test_case_dir_(test_case_dir), |
94 port_(port) { | 94 port_(port), wait_until_done_(true) { |
95 EnableDOMAutomation(); | 95 EnableDOMAutomation(); |
96 } | 96 } |
97 | 97 |
98 InProcessBrowserLayoutTest::~InProcessBrowserLayoutTest() { | 98 InProcessBrowserLayoutTest::~InProcessBrowserLayoutTest() { |
99 if (test_http_server_.get()) | 99 if (test_http_server_.get()) |
100 CHECK(test_http_server_->Stop()); | 100 CHECK(test_http_server_->Stop()); |
101 } | 101 } |
102 | 102 |
103 void InProcessBrowserLayoutTest::SetUpInProcessBrowserTestFixture() { | 103 void InProcessBrowserLayoutTest::SetUpInProcessBrowserTestFixture() { |
104 ASSERT_TRUE(scoped_temp_dir_.CreateUniqueTempDir()); | 104 ASSERT_TRUE(scoped_temp_dir_.CreateUniqueTempDir()); |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 RunLayoutTestInternal(test_case_file_name, url); | 173 RunLayoutTestInternal(test_case_file_name, url); |
174 } | 174 } |
175 | 175 |
176 void InProcessBrowserLayoutTest::RunLayoutTestInternal( | 176 void InProcessBrowserLayoutTest::RunLayoutTestInternal( |
177 const std::string& test_case_file_name, const GURL& url) { | 177 const std::string& test_case_file_name, const GURL& url) { |
178 LOG(INFO) << "Navigating to URL " << url << " and blocking."; | 178 LOG(INFO) << "Navigating to URL " << url << " and blocking."; |
179 const string16 expected_title = ASCIIToUTF16("done"); | 179 const string16 expected_title = ASCIIToUTF16("done"); |
180 ui_test_utils::TitleWatcher title_watcher( | 180 ui_test_utils::TitleWatcher title_watcher( |
181 browser()->GetSelectedWebContents(), expected_title); | 181 browser()->GetSelectedWebContents(), expected_title); |
182 ui_test_utils::NavigateToURL(browser(), url); | 182 ui_test_utils::NavigateToURL(browser(), url); |
183 LOG(INFO) << "Navigation completed, now waiting for title."; | 183 |
184 string16 final_title = title_watcher.WaitAndGetTitle(); | 184 if (wait_until_done_) { |
185 EXPECT_EQ(expected_title, final_title); | 185 LOG(INFO) << "Navigation completed, now waiting for notifyDone."; |
| 186 string16 final_title = title_watcher.WaitAndGetTitle(); |
| 187 EXPECT_EQ(expected_title, final_title); |
| 188 } |
186 | 189 |
187 std::string actual_text; | 190 std::string actual_text; |
188 ScrapeResultFromBrowser(browser(), &actual_text); | 191 ScrapeResultFromBrowser(browser(), &actual_text); |
189 ReplaceSubstringsAfterOffset(&actual_text, 0, "\r", ""); | 192 ReplaceSubstringsAfterOffset(&actual_text, 0, "\r", ""); |
190 TrimString(actual_text, "\n", &actual_text); | 193 TrimString(actual_text, "\n", &actual_text); |
191 | 194 |
192 std::string expected_text; | 195 std::string expected_text; |
193 // Reads the expected result. First try to read from rebase directory. | 196 // Reads the expected result. First try to read from rebase directory. |
194 // If failed, read from original directory. | 197 // If failed, read from original directory. |
195 if (!ReadExpectedResult(rebase_result_dir_, | 198 if (!ReadExpectedResult(rebase_result_dir_, |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 ASSERT_TRUE(file_util::ReadFileToString(path_to_single_test, &test_html)); | 247 ASSERT_TRUE(file_util::ReadFileToString(path_to_single_test, &test_html)); |
245 | 248 |
246 size_t insertion_position = FindInsertPosition(test_html); | 249 size_t insertion_position = FindInsertPosition(test_html); |
247 test_html.insert(insertion_position, preamble); | 250 test_html.insert(insertion_position, preamble); |
248 *test_path = our_layout_test_temp_dir_.Append(test_case_dir_); | 251 *test_path = our_layout_test_temp_dir_.Append(test_case_dir_); |
249 *test_path = test_path->AppendASCII(test_case_file_name); | 252 *test_path = test_path->AppendASCII(test_case_file_name); |
250 ASSERT_TRUE(file_util::WriteFile(*test_path, | 253 ASSERT_TRUE(file_util::WriteFile(*test_path, |
251 &test_html.at(0), | 254 &test_html.at(0), |
252 static_cast<int>(test_html.size()))); | 255 static_cast<int>(test_html.size()))); |
253 } | 256 } |
OLD | NEW |