summaryrefslogtreecommitdiffstats
path: root/content/test/layout_browsertest.cc
diff options
context:
space:
mode:
authorjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-29 17:47:14 +0000
committerjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-29 17:47:14 +0000
commit6d0e9ecbcb06eedf6a5937c022eae7f4af673f04 (patch)
tree15bfde0b2ae50e97dd4264f4ef1db865295b1ca4 /content/test/layout_browsertest.cc
parent6d610bbe20885750ca2e689af59910c592208620 (diff)
downloadchromium_src-6d0e9ecbcb06eedf6a5937c022eae7f4af673f04.zip
chromium_src-6d0e9ecbcb06eedf6a5937c022eae7f4af673f04.tar.gz
chromium_src-6d0e9ecbcb06eedf6a5937c022eae7f4af673f04.tar.bz2
Rewrite HTML5 workers ui_tests to browser_tests. Compared to ui_tests, browser_tests are faster, less flaky and sharded. They're also portable to content_browsertests once we have it.
A bunch of these tests have bitrotted because they've been disabled for so long, so there are a number of fixes throughout (some were checked into WebKit). I'll keep an eye out on flakiness of the renabled tests and disable if necessary. I haven't seen any flakiness when running them now dozens of times on my Win/Mac/Linux, so I'm renabling all disabled tests (36!). I'll keep a close eye on the tree and flakiness dashboard afterwards. BUG=98716,48148,69881,70861,59786,36800,35965,36555,101996,34996,16934,22599 Review URL: https://chromiumcodereview.appspot.com/9802025 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@129641 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/test/layout_browsertest.cc')
-rw-r--r--content/test/layout_browsertest.cc149
1 files changed, 124 insertions, 25 deletions
diff --git a/content/test/layout_browsertest.cc b/content/test/layout_browsertest.cc
index c0dfe48..6f8035c 100644
--- a/content/test/layout_browsertest.cc
+++ b/content/test/layout_browsertest.cc
@@ -7,16 +7,31 @@
#include "base/file_path.h"
#include "base/file_util.h"
#include "base/path_service.h"
+#include "base/rand_util.h"
#include "base/scoped_temp_dir.h"
+#include "base/stringprintf.h"
#include "base/string_util.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/test/base/in_process_browser_test.h"
+#include "chrome/test/base/layout_test_http_server.h"
#include "chrome/test/base/ui_test_utils.h"
#include "content/browser/tab_contents/tab_contents.h"
#include "content/public/common/content_paths.h"
#include "net/base/net_util.h"
+#if defined(OS_WIN)
+static const char kPlatformName[] = "chromium-win";
+#elif defined(OS_MACOSX)
+static const char kPlatformName[] = "chromium-mac";
+#elif defined(OS_LINUX)
+static const char kPlatformName[] = "chromium-linux";
+#elif defined(OS_OPENBSD)
+static const char kPlatformName[] = "chromium-openbsd";
+#else
+#error No known OS defined
+#endif
+
namespace {
size_t FindInsertPosition(const std::string& html) {
@@ -29,7 +44,7 @@ size_t FindInsertPosition(const std::string& html) {
return tag_end + 1;
}
-void ReadExpectedResult(const FilePath& result_dir_path,
+bool ReadExpectedResult(const FilePath& result_dir_path,
const std::string test_case_file_name,
std::string* expected_result_value) {
FilePath expected_result_path(result_dir_path);
@@ -38,9 +53,8 @@ void ReadExpectedResult(const FilePath& result_dir_path,
FILE_PATH_LITERAL("-expected"));
expected_result_path =
expected_result_path.ReplaceExtension(FILE_PATH_LITERAL("txt"));
- std::string raw_result;
- EXPECT_TRUE(file_util::ReadFileToString(expected_result_path, &raw_result));
- TrimString(raw_result, "\n", expected_result_value);
+ return file_util::ReadFileToString(
+ expected_result_path, expected_result_value);
}
void ScrapeResultFromBrowser(Browser* browser, std::string* actual_text) {
@@ -59,6 +73,8 @@ static const std::string preamble =
" this.notifyDone = function () {\n"
" document.title = 'done';\n"
" }\n"
+ " this.overridePreference = function () {}\n"
+ " this.workerThreadCount = 0; \n"
"}\n"
"window.layoutTestController = new LayoutTestController();\n"
"</script>";
@@ -66,49 +82,132 @@ static const std::string preamble =
}
InProcessBrowserLayoutTest::InProcessBrowserLayoutTest(
- const FilePath relative_layout_test_path)
- : original_relative_path_(relative_layout_test_path) {
+ const FilePath& test_parent_dir, const FilePath& test_case_dir)
+ : test_parent_dir_(test_parent_dir), test_case_dir_(test_case_dir),
+ port_(-2) {
EnableDOMAutomation();
}
-InProcessBrowserLayoutTest::~InProcessBrowserLayoutTest() {}
+InProcessBrowserLayoutTest::InProcessBrowserLayoutTest(
+ const FilePath& test_parent_dir, const FilePath& test_case_dir, int port)
+ : test_parent_dir_(test_parent_dir), test_case_dir_(test_case_dir),
+ port_(port) {
+ EnableDOMAutomation();
+}
+
+InProcessBrowserLayoutTest::~InProcessBrowserLayoutTest() {
+ if (test_http_server_.get())
+ CHECK(test_http_server_->Stop());
+}
void InProcessBrowserLayoutTest::SetUpInProcessBrowserTestFixture() {
ASSERT_TRUE(scoped_temp_dir_.CreateUniqueTempDir());
- FilePath ThirdParty_WebKit_LayoutTests;
- ASSERT_TRUE(PathService::Get(content::DIR_LAYOUT_TESTS,
- &ThirdParty_WebKit_LayoutTests));
+ FilePath src_dir;
+ ASSERT_TRUE(PathService::Get(content::DIR_LAYOUT_TESTS, &src_dir));
our_original_layout_test_dir_ =
- ThirdParty_WebKit_LayoutTests.Append(original_relative_path_);
+ 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(original_relative_path_);
- ASSERT_TRUE(file_util::CreateDirectory(our_layout_test_temp_dir_));
+ .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_.AppendASCII("resources"),
+ our_layout_test_temp_dir_.Append(test_case_dir_).AppendASCII("resources"),
true /*recursive*/);
+
+ // Gets the file path to rebased expected result directory for the current
+ // platform.
+ // $LayoutTestRoot/platform/chromium_***/...
+ rebase_result_dir_ = src_dir.AppendASCII("platform");
+ rebase_result_dir_ = rebase_result_dir_.AppendASCII(kPlatformName);
+ rebase_result_dir_ = rebase_result_dir_.Append(test_parent_dir_);
+ rebase_result_dir_ = rebase_result_dir_.Append(test_case_dir_);
+
+ // Generic chromium expected results. Not OS-specific. For example,
+ // v8-specific differences go here.
+ // chrome/test/data/layout_tests/LayoutTests/platform/chromium/...
+ rebase_result_chromium_dir_ = src_dir.AppendASCII("platform").
+ AppendASCII("chromium").
+ Append(test_parent_dir_).
+ Append(test_case_dir_);
+
+ // Gets the file path to rebased expected result directory under the
+ // win32 platform. This is used by other non-win32 platform to use the same
+ // rebased expected results.
+#if !defined(OS_WIN)
+ rebase_result_win_dir_ = src_dir.AppendASCII("platform").
+ AppendASCII("chromium-win").
+ Append(test_parent_dir_).
+ Append(test_case_dir_);
+#endif
+
+ if (port_ != -2) {
+ // Layout tests expect that the server points at the
+ // LayoutTests\http\tests directory.
+ if (port_ == -1)
+ port_ = base::RandInt(1024, 65535);
+ test_http_server_.reset(new LayoutTestHttpServer(
+ our_layout_test_temp_dir_, port_));
+ ASSERT_TRUE(test_http_server_->Start());
+ }
}
void InProcessBrowserLayoutTest::RunLayoutTest(
const std::string& test_case_file_name) {
- GURL test_url;
- WriteModifiedFile(test_case_file_name, &test_url);
+ FilePath file_path;
+ WriteModifiedFile(test_case_file_name, &file_path);
+ GURL url = net::FilePathToFileURL(file_path);
+ 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()));
+ RunLayoutTestInternal(test_case_file_name, url);
+}
- LOG(INFO) << "Navigating to URL " << test_url << " and blocking.";
+void InProcessBrowserLayoutTest::RunLayoutTestInternal(
+ const std::string& test_case_file_name, const GURL& url) {
+ LOG(INFO) << "Navigating to URL " << url << " and blocking.";
const string16 expected_title = ASCIIToUTF16("done");
ui_test_utils::TitleWatcher title_watcher(
browser()->GetSelectedWebContents(), expected_title);
- ui_test_utils::NavigateToURL(browser(), test_url);
+ ui_test_utils::NavigateToURL(browser(), url);
string16 final_title = title_watcher.WaitAndGetTitle();
EXPECT_EQ(expected_title, final_title);
std::string actual_text;
ScrapeResultFromBrowser(browser(), &actual_text);
+ ReplaceSubstringsAfterOffset(&actual_text, 0, "\r", "");
+ TrimString(actual_text, "\n", &actual_text);
std::string expected_text;
- ReadExpectedResult(our_original_layout_test_dir_, test_case_file_name,
- &expected_text);
+ // Reads the expected result. First try to read from rebase directory.
+ // If failed, read from original directory.
+ if (!ReadExpectedResult(rebase_result_dir_,
+ test_case_file_name,
+ &expected_text) &&
+ !ReadExpectedResult(rebase_result_chromium_dir_,
+ test_case_file_name,
+ &expected_text)) {
+ if (rebase_result_win_dir_.empty() ||
+ !ReadExpectedResult(rebase_result_win_dir_,
+ test_case_file_name,
+ &expected_text))
+ ReadExpectedResult(our_original_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);
EXPECT_EQ(expected_text, actual_text);
}
@@ -129,6 +228,7 @@ void InProcessBrowserLayoutTest::AddResourceForLayoutTest(
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));
@@ -136,7 +236,7 @@ void InProcessBrowserLayoutTest::AddResourceForLayoutTest(
}
void InProcessBrowserLayoutTest::WriteModifiedFile(
- const std::string& test_case_file_name, GURL* test_url) {
+ 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;
@@ -144,10 +244,9 @@ void InProcessBrowserLayoutTest::WriteModifiedFile(
size_t insertion_position = FindInsertPosition(test_html);
test_html.insert(insertion_position, preamble);
- FilePath new_test_file_path(our_layout_test_temp_dir_);
- new_test_file_path = new_test_file_path.AppendASCII(test_case_file_name);
- ASSERT_TRUE(file_util::WriteFile(new_test_file_path,
+ *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())));
- *test_url = net::FilePathToFileURL(new_test_file_path);
}