Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(162)

Unified Diff: content/test/layout_browsertest.cc

Issue 10941011: Rewrite layout_browsertests to use content_shell --dump-render-tree to execute layout tests (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: updates Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/test/layout_browsertest.cc
diff --git a/content/test/layout_browsertest.cc b/content/test/layout_browsertest.cc
index d8fc383eee2e65066dc7c5e0e0704159973ee4a5..8b8771a196e7d3c2440f22bd52bd0a42c841ebdb 100644
--- a/content/test/layout_browsertest.cc
+++ b/content/test/layout_browsertest.cc
@@ -4,11 +4,14 @@
#include "content/test/layout_browsertest.h"
+#include <sstream>
+
#include "base/command_line.h"
#include "base/file_path.h"
#include "base/file_util.h"
#include "base/path_service.h"
#include "base/rand_util.h"
+#include "base/run_loop.h"
#include "base/scoped_temp_dir.h"
#include "base/stringprintf.h"
#include "base/string_util.h"
@@ -18,6 +21,7 @@
#include "content/public/test/browser_test_utils.h"
#include "content/shell/shell.h"
#include "content/shell/shell_switches.h"
+#include "content/shell/webkit_test_runner_host.h"
#include "content/test/content_browser_test_utils.h"
#include "content/test/layout_test_http_server.h"
#include "net/base/net_util.h"
@@ -36,16 +40,6 @@ static const char kPlatformName[] = "chromium-openbsd";
namespace {
-size_t FindInsertPosition(const std::string& html) {
- size_t tag_start = html.find("<html");
- if (tag_start == std::string::npos)
- return 0;
- size_t tag_end = html.find(">", tag_start);
- if (tag_end == std::string::npos)
- return 0;
- return tag_end + 1;
-}
-
bool ReadExpectedResult(const FilePath& result_dir_path,
const std::string test_case_file_name,
std::string* expected_result_value) {
@@ -59,37 +53,7 @@ bool ReadExpectedResult(const FilePath& result_dir_path,
expected_result_path, expected_result_value);
}
-void ScrapeResultFromBrowser(content::Shell* window, std::string* actual_text) {
- ASSERT_TRUE(content::ExecuteJavaScriptAndExtractString(
- window->web_contents()->GetRenderViewHost(),
- L"",
- L"window.domAutomationController.send(document.body.innerText);",
- actual_text));
-}
-
-static const std::string preamble =
- "\n<script>\n"
- "function TestRunner() {\n"
- " this.wait_until_done_ = false;\n"
- " this.dumpAsText = function () {};\n"
- " this.waitUntilDone = function () {\n"
- " this.wait_until_done_ = true;\n"
- " }\n"
- " this.notifyDone = function () {\n"
- " document.title = 'done';\n"
- " }\n"
- " this.overridePreference = function () {}\n"
- " this.OnEvent = function () {\n"
- " if (!testRunner.wait_until_done_)\n"
- " testRunner.notifyDone();\n"
- " }\n"
- " this.workerThreadCount = 0; \n"
- "}\n"
- "window.testRunner = new TestRunner();\n"
- "window.addEventListener('load', testRunner.OnEvent, false);\n"
- "</script>";
-
-}
+} // namespace
InProcessBrowserLayoutTest::InProcessBrowserLayoutTest(
const FilePath& test_parent_dir, const FilePath& test_case_dir)
@@ -109,20 +73,12 @@ InProcessBrowserLayoutTest::~InProcessBrowserLayoutTest() {
}
void InProcessBrowserLayoutTest::SetUpInProcessBrowserTestFixture() {
- ASSERT_TRUE(scoped_temp_dir_.CreateUniqueTempDir());
FilePath src_dir;
ASSERT_TRUE(PathService::Get(content::DIR_LAYOUT_TESTS, &src_dir));
- our_original_layout_test_dir_ =
- src_dir.Append(test_parent_dir_).Append(test_case_dir_);
- ASSERT_TRUE(file_util::DirectoryExists(our_original_layout_test_dir_));
- our_layout_test_temp_dir_ = scoped_temp_dir_.path()
- .AppendASCII("LayoutTests").Append(test_parent_dir_);
- ASSERT_TRUE(file_util::CreateDirectory(
- our_layout_test_temp_dir_.Append(test_case_dir_)));
- file_util::CopyDirectory(
- our_original_layout_test_dir_.AppendASCII("resources"),
- our_layout_test_temp_dir_.Append(test_case_dir_).AppendASCII("resources"),
- true /*recursive*/);
+ FilePath absolute_parent_dir = src_dir.Append(test_parent_dir_);
+ ASSERT_TRUE(file_util::DirectoryExists(absolute_parent_dir));
+ layout_test_dir_ = absolute_parent_dir.Append(test_case_dir_);
+ ASSERT_TRUE(file_util::DirectoryExists(layout_test_dir_));
// Gets the file path to rebased expected result directory for the current
// platform.
@@ -156,25 +112,29 @@ void InProcessBrowserLayoutTest::SetUpInProcessBrowserTestFixture() {
if (port_ == -1)
port_ = base::RandInt(1024, 65535);
test_http_server_.reset(new LayoutTestHttpServer(
- our_layout_test_temp_dir_, port_));
+ absolute_parent_dir, port_));
ASSERT_TRUE(test_http_server_->Start());
}
}
+void InProcessBrowserLayoutTest::SetUpCommandLine(CommandLine* command_line) {
+ command_line->AppendSwitch(switches::kDumpRenderTree);
+}
+
+void InProcessBrowserLayoutTest::SetUpOnMainThread() {
+ test_controller_.reset(new content::WebKitTestController);
+}
+
void InProcessBrowserLayoutTest::RunLayoutTest(
const std::string& test_case_file_name) {
- FilePath file_path;
- WriteModifiedFile(test_case_file_name, &file_path);
- GURL url = net::FilePathToFileURL(file_path);
+ GURL url = net::FilePathToFileURL(
+ layout_test_dir_.AppendASCII(test_case_file_name));
RunLayoutTestInternal(test_case_file_name, url);
}
void InProcessBrowserLayoutTest::RunHttpLayoutTest(
const std::string& test_case_file_name) {
DCHECK(test_http_server_.get());
- FilePath file_path;
- WriteModifiedFile(test_case_file_name, &file_path);
-
GURL url(StringPrintf(
"http://127.0.0.1:%d/%s/%s", port_, test_case_dir_.MaybeAsASCII().c_str(),
test_case_file_name.c_str()));
@@ -183,18 +143,20 @@ void InProcessBrowserLayoutTest::RunHttpLayoutTest(
void InProcessBrowserLayoutTest::RunLayoutTestInternal(
const std::string& test_case_file_name, const GURL& url) {
+ std::stringstream result;
+ scoped_ptr<content::WebKitTestResultPrinter> printer(
+ new content::WebKitTestResultPrinter(&result, NULL));
+ printer->set_capture_text_only(true);
+ test_controller_->set_printer(printer.release());
+
LOG(INFO) << "Navigating to URL " << url << " and blocking.";
- const string16 expected_title = ASCIIToUTF16("done");
- content::TitleWatcher title_watcher(shell()->web_contents(), expected_title);
- content::NavigateToURL(shell(), url);
- LOG(INFO) << "Navigation completed, now waiting for title.";
- string16 final_title = title_watcher.WaitAndGetTitle();
- EXPECT_EQ(expected_title, final_title);
+ ASSERT_TRUE(test_controller_->PrepareForLayoutTest(url, false, ""));
+ base::RunLoop run_loop;
+ run_loop.Run();
+ LOG(INFO) << "Navigation completed.";
+ ASSERT_TRUE(test_controller_->ResetAfterLayoutTest());
- std::string actual_text;
- ScrapeResultFromBrowser(shell(), &actual_text);
- ReplaceSubstringsAfterOffset(&actual_text, 0, "\r", "");
dgrogan 2012/09/25 18:04:31 Looks like we now need this on the expected_text
- TrimString(actual_text, "\n", &actual_text);
+ std::string actual_text = result.str();;
std::string expected_text;
// Reads the expected result. First try to read from rebase directory.
@@ -209,13 +171,11 @@ void InProcessBrowserLayoutTest::RunLayoutTestInternal(
!ReadExpectedResult(rebase_result_win_dir_,
test_case_file_name,
&expected_text))
- ReadExpectedResult(our_original_layout_test_dir_,
+ ReadExpectedResult(layout_test_dir_,
test_case_file_name,
&expected_text);
}
ASSERT_TRUE(!expected_text.empty());
- ReplaceSubstringsAfterOffset(&expected_text, 0, "\r", "");
- TrimString(expected_text, "\n", &expected_text);
CommandLine* command_line = CommandLine::ForCurrentProcess();
if (command_line->HasSwitch(switches::kOutputLayoutTestDifferences)) {
@@ -226,45 +186,6 @@ void InProcessBrowserLayoutTest::RunLayoutTestInternal(
}
}
-void InProcessBrowserLayoutTest::AddResourceForLayoutTest(
- const FilePath& parent_dir,
- const FilePath& resource_name) {
- FilePath source;
- ASSERT_TRUE(PathService::Get(content::DIR_LAYOUT_TESTS, &source));
- source = source.Append(parent_dir);
- source = source.Append(resource_name);
-
- ASSERT_TRUE(file_util::PathExists(source));
-
- FilePath dest_parent_dir = scoped_temp_dir_.path().
- AppendASCII("LayoutTests").Append(parent_dir);
- ASSERT_TRUE(file_util::CreateDirectory(dest_parent_dir));
- FilePath dest = dest_parent_dir.Append(resource_name);
-
- if (file_util::DirectoryExists(source)) {
- ASSERT_TRUE(file_util::CreateDirectory(dest.DirName()));
- ASSERT_TRUE(file_util::CopyDirectory(source, dest, true));
- } else {
- ASSERT_TRUE(file_util::CopyFile(source, dest));
- }
-}
-
-void InProcessBrowserLayoutTest::WriteModifiedFile(
- const std::string& test_case_file_name, FilePath* test_path) {
- FilePath path_to_single_test =
- our_original_layout_test_dir_.AppendASCII(test_case_file_name);
- std::string test_html;
- ASSERT_TRUE(file_util::ReadFileToString(path_to_single_test, &test_html));
-
- size_t insertion_position = FindInsertPosition(test_html);
- test_html.insert(insertion_position, preamble);
- *test_path = our_layout_test_temp_dir_.Append(test_case_dir_);
- *test_path = test_path->AppendASCII(test_case_file_name);
- ASSERT_TRUE(file_util::WriteFile(*test_path,
- &test_html.at(0),
- static_cast<int>(test_html.size())));
-}
-
std::string InProcessBrowserLayoutTest::SaveResults(const std::string& expected,
const std::string& actual) {
FilePath cwd;
« content/browser/worker_host/test/worker_browsertest.cc ('K') | « content/test/layout_browsertest.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698