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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 DOMElementProxyRef doc = ui_test_utils::GetActiveDOMDocument(browser); | 61 DOMElementProxyRef doc = ui_test_utils::GetActiveDOMDocument(browser); |
62 DOMElementProxyRef body = | 62 DOMElementProxyRef body = |
63 doc->FindElement(DOMElementProxy::By::XPath("//body")); | 63 doc->FindElement(DOMElementProxy::By::XPath("//body")); |
64 ASSERT_TRUE(body.get()); | 64 ASSERT_TRUE(body.get()); |
65 ASSERT_TRUE(body->GetInnerText(actual_text)); | 65 ASSERT_TRUE(body->GetInnerText(actual_text)); |
66 } | 66 } |
67 | 67 |
68 static const std::string preamble = | 68 static const std::string preamble = |
69 "\n<script>\n" | 69 "\n<script>\n" |
70 "function LayoutTestController() {\n" | 70 "function LayoutTestController() {\n" |
| 71 " this.wait_until_done_ = false;\n" |
71 " this.dumpAsText = function () {};\n" | 72 " this.dumpAsText = function () {};\n" |
72 " this.waitUntilDone = function () {};\n" | 73 " this.waitUntilDone = function () {\n" |
| 74 " this.wait_until_done_ = true;\n" |
| 75 " }\n" |
73 " this.notifyDone = function () {\n" | 76 " this.notifyDone = function () {\n" |
74 " document.title = 'done';\n" | 77 " document.title = 'done';\n" |
75 " }\n" | 78 " }\n" |
76 " this.overridePreference = function () {}\n" | 79 " this.overridePreference = function () {}\n" |
| 80 " this.OnEvent = function () {\n" |
| 81 " if (!layoutTestController.wait_until_done_)\n" |
| 82 " layoutTestController.notifyDone();\n" |
| 83 " }\n" |
77 " this.workerThreadCount = 0; \n" | 84 " this.workerThreadCount = 0; \n" |
78 "}\n" | 85 "}\n" |
79 "window.layoutTestController = new LayoutTestController();\n" | 86 "window.layoutTestController = new LayoutTestController();\n" |
| 87 "window.addEventListener('load', layoutTestController.OnEvent, false);\n" |
80 "</script>"; | 88 "</script>"; |
81 | 89 |
82 } | 90 } |
83 | 91 |
84 InProcessBrowserLayoutTest::InProcessBrowserLayoutTest( | 92 InProcessBrowserLayoutTest::InProcessBrowserLayoutTest( |
85 const FilePath& test_parent_dir, const FilePath& test_case_dir) | 93 const FilePath& test_parent_dir, const FilePath& test_case_dir) |
86 : test_parent_dir_(test_parent_dir), test_case_dir_(test_case_dir), | 94 : test_parent_dir_(test_parent_dir), test_case_dir_(test_case_dir), |
87 port_(-2) { | 95 port_(-2) { |
88 EnableDOMAutomation(); | 96 EnableDOMAutomation(); |
89 } | 97 } |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 RunLayoutTestInternal(test_case_file_name, url); | 181 RunLayoutTestInternal(test_case_file_name, url); |
174 } | 182 } |
175 | 183 |
176 void InProcessBrowserLayoutTest::RunLayoutTestInternal( | 184 void InProcessBrowserLayoutTest::RunLayoutTestInternal( |
177 const std::string& test_case_file_name, const GURL& url) { | 185 const std::string& test_case_file_name, const GURL& url) { |
178 LOG(INFO) << "Navigating to URL " << url << " and blocking."; | 186 LOG(INFO) << "Navigating to URL " << url << " and blocking."; |
179 const string16 expected_title = ASCIIToUTF16("done"); | 187 const string16 expected_title = ASCIIToUTF16("done"); |
180 ui_test_utils::TitleWatcher title_watcher( | 188 ui_test_utils::TitleWatcher title_watcher( |
181 browser()->GetSelectedWebContents(), expected_title); | 189 browser()->GetSelectedWebContents(), expected_title); |
182 ui_test_utils::NavigateToURL(browser(), url); | 190 ui_test_utils::NavigateToURL(browser(), url); |
| 191 |
183 LOG(INFO) << "Navigation completed, now waiting for title."; | 192 LOG(INFO) << "Navigation completed, now waiting for title."; |
184 string16 final_title = title_watcher.WaitAndGetTitle(); | 193 string16 final_title = title_watcher.WaitAndGetTitle(); |
185 EXPECT_EQ(expected_title, final_title); | 194 EXPECT_EQ(expected_title, final_title); |
186 | 195 |
187 std::string actual_text; | 196 std::string actual_text; |
188 ScrapeResultFromBrowser(browser(), &actual_text); | 197 ScrapeResultFromBrowser(browser(), &actual_text); |
189 ReplaceSubstringsAfterOffset(&actual_text, 0, "\r", ""); | 198 ReplaceSubstringsAfterOffset(&actual_text, 0, "\r", ""); |
190 TrimString(actual_text, "\n", &actual_text); | 199 TrimString(actual_text, "\n", &actual_text); |
191 | 200 |
192 std::string expected_text; | 201 std::string expected_text; |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 ASSERT_TRUE(file_util::ReadFileToString(path_to_single_test, &test_html)); | 253 ASSERT_TRUE(file_util::ReadFileToString(path_to_single_test, &test_html)); |
245 | 254 |
246 size_t insertion_position = FindInsertPosition(test_html); | 255 size_t insertion_position = FindInsertPosition(test_html); |
247 test_html.insert(insertion_position, preamble); | 256 test_html.insert(insertion_position, preamble); |
248 *test_path = our_layout_test_temp_dir_.Append(test_case_dir_); | 257 *test_path = our_layout_test_temp_dir_.Append(test_case_dir_); |
249 *test_path = test_path->AppendASCII(test_case_file_name); | 258 *test_path = test_path->AppendASCII(test_case_file_name); |
250 ASSERT_TRUE(file_util::WriteFile(*test_path, | 259 ASSERT_TRUE(file_util::WriteFile(*test_path, |
251 &test_html.at(0), | 260 &test_html.at(0), |
252 static_cast<int>(test_html.size()))); | 261 static_cast<int>(test_html.size()))); |
253 } | 262 } |
OLD | NEW |