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" |
11 #include "base/scoped_temp_dir.h" | 11 #include "base/scoped_temp_dir.h" |
12 #include "base/stringprintf.h" | 12 #include "base/stringprintf.h" |
13 #include "base/string_util.h" | 13 #include "base/string_util.h" |
14 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
15 #include "chrome/browser/ui/browser.h" | |
16 #include "chrome/browser/ui/browser_tabstrip.h" | |
17 #include "chrome/test/base/in_process_browser_test.h" | |
18 #include "chrome/test/base/layout_test_http_server.h" | |
19 #include "chrome/test/base/ui_test_utils.h" | |
20 #include "content/browser/web_contents/web_contents_impl.h" | 15 #include "content/browser/web_contents/web_contents_impl.h" |
21 #include "content/public/common/content_paths.h" | 16 #include "content/public/common/content_paths.h" |
22 #include "content/public/test/browser_test_utils.h" | 17 #include "content/public/test/browser_test_utils.h" |
| 18 #include "content/shell/shell.h" |
| 19 #include "content/test/content_browser_test_utils.h" |
| 20 #include "content/test/layout_test_http_server.h" |
23 #include "net/base/net_util.h" | 21 #include "net/base/net_util.h" |
24 | 22 |
25 #if defined(OS_WIN) | 23 #if defined(OS_WIN) |
26 static const char kPlatformName[] = "chromium-win"; | 24 static const char kPlatformName[] = "chromium-win"; |
27 #elif defined(OS_MACOSX) | 25 #elif defined(OS_MACOSX) |
28 static const char kPlatformName[] = "chromium-mac"; | 26 static const char kPlatformName[] = "chromium-mac"; |
29 #elif defined(OS_LINUX) | 27 #elif defined(OS_LINUX) |
30 static const char kPlatformName[] = "chromium-linux"; | 28 static const char kPlatformName[] = "chromium-linux"; |
31 #elif defined(OS_OPENBSD) | 29 #elif defined(OS_OPENBSD) |
32 static const char kPlatformName[] = "chromium-openbsd"; | 30 static const char kPlatformName[] = "chromium-openbsd"; |
(...skipping 19 matching lines...) Expand all Loading... |
52 FilePath expected_result_path(result_dir_path); | 50 FilePath expected_result_path(result_dir_path); |
53 expected_result_path = expected_result_path.AppendASCII(test_case_file_name); | 51 expected_result_path = expected_result_path.AppendASCII(test_case_file_name); |
54 expected_result_path = expected_result_path.InsertBeforeExtension( | 52 expected_result_path = expected_result_path.InsertBeforeExtension( |
55 FILE_PATH_LITERAL("-expected")); | 53 FILE_PATH_LITERAL("-expected")); |
56 expected_result_path = | 54 expected_result_path = |
57 expected_result_path.ReplaceExtension(FILE_PATH_LITERAL("txt")); | 55 expected_result_path.ReplaceExtension(FILE_PATH_LITERAL("txt")); |
58 return file_util::ReadFileToString( | 56 return file_util::ReadFileToString( |
59 expected_result_path, expected_result_value); | 57 expected_result_path, expected_result_value); |
60 } | 58 } |
61 | 59 |
62 void ScrapeResultFromBrowser(Browser* browser, std::string* actual_text) { | 60 void ScrapeResultFromBrowser(content::Shell* window, std::string* actual_text) { |
63 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractString( | 61 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractString( |
64 chrome::GetActiveWebContents(browser)->GetRenderViewHost(), | 62 window->web_contents()->GetRenderViewHost(), |
65 L"", | 63 L"", |
66 L"window.domAutomationController.send(document.body.innerText);", | 64 L"window.domAutomationController.send(document.body.innerText);", |
67 actual_text)); | 65 actual_text)); |
68 } | 66 } |
69 | 67 |
70 static const std::string preamble = | 68 static const std::string preamble = |
71 "\n<script>\n" | 69 "\n<script>\n" |
72 "function LayoutTestController() {\n" | 70 "function LayoutTestController() {\n" |
73 " this.wait_until_done_ = false;\n" | 71 " this.wait_until_done_ = false;\n" |
74 " this.dumpAsText = function () {};\n" | 72 " this.dumpAsText = function () {};\n" |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 GURL url(StringPrintf( | 177 GURL url(StringPrintf( |
180 "http://127.0.0.1:%d/%s/%s", port_, test_case_dir_.MaybeAsASCII().c_str(), | 178 "http://127.0.0.1:%d/%s/%s", port_, test_case_dir_.MaybeAsASCII().c_str(), |
181 test_case_file_name.c_str())); | 179 test_case_file_name.c_str())); |
182 RunLayoutTestInternal(test_case_file_name, url); | 180 RunLayoutTestInternal(test_case_file_name, url); |
183 } | 181 } |
184 | 182 |
185 void InProcessBrowserLayoutTest::RunLayoutTestInternal( | 183 void InProcessBrowserLayoutTest::RunLayoutTestInternal( |
186 const std::string& test_case_file_name, const GURL& url) { | 184 const std::string& test_case_file_name, const GURL& url) { |
187 LOG(INFO) << "Navigating to URL " << url << " and blocking."; | 185 LOG(INFO) << "Navigating to URL " << url << " and blocking."; |
188 const string16 expected_title = ASCIIToUTF16("done"); | 186 const string16 expected_title = ASCIIToUTF16("done"); |
189 content::TitleWatcher title_watcher( | 187 content::TitleWatcher title_watcher(shell()->web_contents(), expected_title); |
190 chrome::GetActiveWebContents(browser()), expected_title); | 188 content::NavigateToURL(shell(), url); |
191 ui_test_utils::NavigateToURL(browser(), url); | |
192 LOG(INFO) << "Navigation completed, now waiting for title."; | 189 LOG(INFO) << "Navigation completed, now waiting for title."; |
193 string16 final_title = title_watcher.WaitAndGetTitle(); | 190 string16 final_title = title_watcher.WaitAndGetTitle(); |
194 EXPECT_EQ(expected_title, final_title); | 191 EXPECT_EQ(expected_title, final_title); |
195 | 192 |
196 std::string actual_text; | 193 std::string actual_text; |
197 ScrapeResultFromBrowser(browser(), &actual_text); | 194 ScrapeResultFromBrowser(shell(), &actual_text); |
198 ReplaceSubstringsAfterOffset(&actual_text, 0, "\r", ""); | 195 ReplaceSubstringsAfterOffset(&actual_text, 0, "\r", ""); |
199 TrimString(actual_text, "\n", &actual_text); | 196 TrimString(actual_text, "\n", &actual_text); |
200 | 197 |
201 std::string expected_text; | 198 std::string expected_text; |
202 // Reads the expected result. First try to read from rebase directory. | 199 // Reads the expected result. First try to read from rebase directory. |
203 // If failed, read from original directory. | 200 // If failed, read from original directory. |
204 if (!ReadExpectedResult(rebase_result_dir_, | 201 if (!ReadExpectedResult(rebase_result_dir_, |
205 test_case_file_name, | 202 test_case_file_name, |
206 &expected_text) && | 203 &expected_text) && |
207 !ReadExpectedResult(rebase_result_chromium_dir_, | 204 !ReadExpectedResult(rebase_result_chromium_dir_, |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 ASSERT_TRUE(file_util::ReadFileToString(path_to_single_test, &test_html)); | 250 ASSERT_TRUE(file_util::ReadFileToString(path_to_single_test, &test_html)); |
254 | 251 |
255 size_t insertion_position = FindInsertPosition(test_html); | 252 size_t insertion_position = FindInsertPosition(test_html); |
256 test_html.insert(insertion_position, preamble); | 253 test_html.insert(insertion_position, preamble); |
257 *test_path = our_layout_test_temp_dir_.Append(test_case_dir_); | 254 *test_path = our_layout_test_temp_dir_.Append(test_case_dir_); |
258 *test_path = test_path->AppendASCII(test_case_file_name); | 255 *test_path = test_path->AppendASCII(test_case_file_name); |
259 ASSERT_TRUE(file_util::WriteFile(*test_path, | 256 ASSERT_TRUE(file_util::WriteFile(*test_path, |
260 &test_html.at(0), | 257 &test_html.at(0), |
261 static_cast<int>(test_html.size()))); | 258 static_cast<int>(test_html.size()))); |
262 } | 259 } |
OLD | NEW |