Skip to content
Snippets Groups Projects
Commit 95de1c95 authored by jianli@chromium.org's avatar jianli@chromium.org
Browse files

Support running http layout tests for workers in UI test framework.

BUG=none
TEST=This is a UI test.

Nicolas, could you please review DEPS? I added a couple of new lines to DEPS in order to fetch a copy the following directory into UI test data directory:
  LayoutTests/http/tests/resources
  LayoutTests/http/tests/workers
  LayoutTests/http/tests/xmlhttprequest


Review URL: http://codereview.chromium.org/147125

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@19502 0039d316-1c4b-4281-b951-d872f2087c98
parent af2fd777
No related branches found
No related tags found
No related merge requests found
......@@ -56,6 +56,12 @@ deps = {
# in ui test.
"src/chrome/test/data/workers/LayoutTests/fast/workers":
Var("webkit_trunk") + "/LayoutTests/fast/workers@" + Var("webkit_revision"),
"src/chrome/test/data/workers/LayoutTests/http/tests/resources":
Var("webkit_trunk") + "/LayoutTests/http/tests/resources@" + Var("webkit_revision"),
"src/chrome/test/data/workers/LayoutTests/http/tests/workers":
Var("webkit_trunk") + "/LayoutTests/http/tests/workers@" + Var("webkit_revision"),
"src/chrome/test/data/workers/LayoutTests/http/tests/xmlhttprequest":
Var("webkit_trunk") + "/LayoutTests/http/tests/xmlhttprequest@" + Var("webkit_revision"),
}
......
......@@ -28,7 +28,7 @@ const char kPlatformName[] = "chromium-linux";
const char kTestCompleteCookie[] = "status";
const char kTestCompleteSuccess[] = "OK";
const int kTestIntervalMs = 250;
const int kTestWaitTimeoutMs = 30 * 1000;
const int kTestWaitTimeoutMs = 60 * 1000;
class WorkerTest : public UITest {
protected:
......@@ -37,11 +37,12 @@ class WorkerTest : public UITest {
void RunTest(const std::wstring& test_case);
void InitializeForLayoutTest(const FilePath& test_case_dir);
void RunLayoutTest(const std::string& test_case_file_name);
void RunHttpTest(const std::string& test_case_name);
void InitializeForLayoutTest(const FilePath& test_parent_dir,
const FilePath& test_case_dir,
bool is_http_test);
void RunLayoutTest(const std::string& test_case_file_name, bool is_http_test);
private:
protected:
bool ReadExpectedResult(const FilePath& result_dir_path,
const std::string test_case_file_name,
std::string* expected_result_value);
......@@ -50,6 +51,8 @@ class WorkerTest : public UITest {
int test_count_;
FilePath temp_test_dir_;
FilePath layout_test_dir_;
FilePath test_case_dir_;
FilePath new_http_root_dir_;
FilePath new_layout_test_dir_;
FilePath rebase_result_dir_;
std::string layout_test_controller_;
......@@ -76,20 +79,9 @@ void WorkerTest::RunTest(const std::wstring& test_case) {
ASSERT_STREQ(kTestCompleteSuccess, value.c_str());
}
void WorkerTest::RunHttpTest(const std::string& test_case_name) {
scoped_refptr<TabProxy> tab(GetActiveTab());
std::string test_url_string(std::string("http://localhost:8080/") +
test_case_name);
GURL url(test_url_string);
ASSERT_TRUE(tab->NavigateToURL(url));
std::string value = WaitUntilCookieNonEmpty(tab.get(), url,
kTestCompleteCookie, kTestIntervalMs, kTestWaitTimeoutMs);
ASSERT_STREQ(kTestCompleteSuccess, value.c_str());
}
void WorkerTest::InitializeForLayoutTest(const FilePath& test_case_dir) {
void WorkerTest::InitializeForLayoutTest(const FilePath& test_parent_dir,
const FilePath& test_case_dir,
bool is_http_test) {
FilePath src_dir;
PathService::Get(base::DIR_SOURCE_ROOT, &src_dir);
......@@ -101,8 +93,21 @@ void WorkerTest::InitializeForLayoutTest(const FilePath& test_case_dir) {
layout_test_dir_ = layout_test_dir_.AppendASCII("test");
layout_test_dir_ = layout_test_dir_.AppendASCII("data");
layout_test_dir_ = layout_test_dir_.AppendASCII("workers");
layout_test_dir_ = layout_test_dir_.Append(test_parent_dir);
layout_test_dir_ = layout_test_dir_.Append(test_case_dir);
// If not found, try to use the original copy of WebKit layout tests for
// workers. For testing only in local machine only.
// webkit/data/layout_tests/LayoutTests/.../workers
if (!file_util::DirectoryExists(layout_test_dir_)) {
layout_test_dir_ = src_dir.AppendASCII("webkit");
layout_test_dir_ = layout_test_dir_.AppendASCII("data");
layout_test_dir_ = layout_test_dir_.AppendASCII("layout_tests");
layout_test_dir_ = layout_test_dir_.Append(test_parent_dir);
layout_test_dir_ = layout_test_dir_.Append(test_case_dir);
ASSERT_TRUE(file_util::DirectoryExists(layout_test_dir_));
}
// Gets the file path to rebased expected result directory for workers.
// webkit/data/layout_tests/platform/chromium_***/LayoutTests/.../workers
rebase_result_dir_ = src_dir.AppendASCII("webkit");
......@@ -110,6 +115,7 @@ void WorkerTest::InitializeForLayoutTest(const FilePath& test_case_dir) {
rebase_result_dir_ = rebase_result_dir_.AppendASCII("layout_tests");
rebase_result_dir_ = rebase_result_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);
// Creates the temporary directory.
......@@ -121,6 +127,11 @@ void WorkerTest::InitializeForLayoutTest(const FilePath& test_case_dir) {
// like .../LayoutTests/fast/workers/.... Otherwise those layout tests
// dealing with location property, like worker-location.html, could fail.
new_layout_test_dir_ = temp_test_dir_;
new_layout_test_dir_ = new_layout_test_dir_.Append(test_parent_dir);
if (is_http_test) {
new_http_root_dir_ = new_layout_test_dir_;
test_case_dir_ = test_case_dir;
}
new_layout_test_dir_ = new_layout_test_dir_.Append(test_case_dir);
ASSERT_TRUE(file_util::CreateDirectory(new_layout_test_dir_));
......@@ -131,10 +142,21 @@ void WorkerTest::InitializeForLayoutTest(const FilePath& test_case_dir) {
FilePath new_layout_test_resource_path(new_layout_test_dir_);
new_layout_test_resource_path =
new_layout_test_resource_path.AppendASCII("resources");
ASSERT_TRUE(file_util::DirectoryExists(layout_test_resource_path));
ASSERT_TRUE(file_util::CopyDirectory(
layout_test_resource_path, new_layout_test_resource_path, true));
// Copies the parent resource subdirectory. This is needed in order to run
// http layout tests.
if (is_http_test) {
FilePath parent_resource_path(layout_test_dir_.DirName());
parent_resource_path = parent_resource_path.AppendASCII("resources");
FilePath new_parent_resource_path(new_layout_test_dir_.DirName());
new_parent_resource_path =
new_parent_resource_path.AppendASCII("resources");
ASSERT_TRUE(file_util::CopyDirectory(
parent_resource_path, new_parent_resource_path, true));
}
// Reads the layout test controller simulation script.
FilePath path;
PathService::Get(chrome::DIR_TEST_DATA, &path);
......@@ -143,7 +165,8 @@ void WorkerTest::InitializeForLayoutTest(const FilePath& test_case_dir) {
ASSERT_TRUE(file_util::ReadFileToString(path, &layout_test_controller_));
}
void WorkerTest::RunLayoutTest(const std::string& test_case_file_name) {
void WorkerTest::RunLayoutTest(const std::string& test_case_file_name,
bool is_http_test) {
SCOPED_TRACE(test_case_file_name.c_str());
ASSERT_TRUE(!layout_test_controller_.empty());
......@@ -171,13 +194,22 @@ void WorkerTest::RunLayoutTest(const std::string& test_case_file_name) {
ASSERT_TRUE(file_util::WriteFile(new_test_file_path,
&test_html.at(0),
static_cast<int>(test_html.size())));
GURL new_test_file_url = net::FilePathToFileURL(new_test_file_path);
scoped_ptr<GURL> new_test_url;
if (is_http_test)
new_test_url.reset(new GURL(
std::string("http://localhost:8080/") +
UTF16ToUTF8(test_case_dir_.ToWStringHack()) +
"/" +
test_case_file_name));
else
new_test_url.reset(new GURL(net::FilePathToFileURL(new_test_file_path)));
// Runs the new layout test.
scoped_refptr<TabProxy> tab(GetActiveTab());
ASSERT_TRUE(tab->NavigateToURL(new_test_file_url));
ASSERT_TRUE(tab->NavigateToURL(*new_test_url.get()));
std::string escaped_value =
WaitUntilCookieNonEmpty(tab.get(), new_test_file_url,
WaitUntilCookieNonEmpty(tab.get(), *new_test_url.get(),
status_cookie.c_str(), kTestIntervalMs, kTestWaitTimeoutMs);
// Unescapes and normalizes the actual result.
......@@ -246,11 +278,59 @@ TEST_F(WorkerTest, WorkerFastLayoutTests) {
FilePath fast_test_dir;
fast_test_dir = fast_test_dir.AppendASCII("LayoutTests");
fast_test_dir = fast_test_dir.AppendASCII("fast");
fast_test_dir = fast_test_dir.AppendASCII("workers");
InitializeForLayoutTest(fast_test_dir);
FilePath worker_test_dir;
worker_test_dir = worker_test_dir.AppendASCII("workers");
InitializeForLayoutTest(fast_test_dir, worker_test_dir, false);
for (int i = 0; i < arraysize(kLayoutTestFiles); ++i)
RunLayoutTest(kLayoutTestFiles[i], false);
}
TEST_F(WorkerTest, WorkerHttpLayoutTests) {
static const char* kLayoutTestFiles[] = {
//"text-encoding.html",
"worker-importScripts.html",
"worker-redirect.html",
};
FilePath http_test_dir;
http_test_dir = http_test_dir.AppendASCII("LayoutTests");
http_test_dir = http_test_dir.AppendASCII("http");
http_test_dir = http_test_dir.AppendASCII("tests");
FilePath worker_test_dir;
worker_test_dir = worker_test_dir.AppendASCII("workers");
InitializeForLayoutTest(http_test_dir, worker_test_dir, true);
StartHttpServer(new_http_root_dir_);
for (int i = 0; i < arraysize(kLayoutTestFiles); ++i)
RunLayoutTest(kLayoutTestFiles[i]);
RunLayoutTest(kLayoutTestFiles[i], true);
StopHttpServer();
}
TEST_F(WorkerTest, WorkerXhrHttpLayoutTests) {
static const char* kLayoutTestFiles[] = {
"abort-exception-assert.html",
//"methods-async.html",
//"methods.html",
"xmlhttprequest-file-not-found.html"
};
FilePath http_test_dir;
http_test_dir = http_test_dir.AppendASCII("LayoutTests");
http_test_dir = http_test_dir.AppendASCII("http");
http_test_dir = http_test_dir.AppendASCII("tests");
FilePath worker_test_dir;
worker_test_dir = worker_test_dir.AppendASCII("xmlhttprequest");
worker_test_dir = worker_test_dir.AppendASCII("workers");
InitializeForLayoutTest(http_test_dir, worker_test_dir, true);
StartHttpServer(new_http_root_dir_);
for (int i = 0; i < arraysize(kLayoutTestFiles); ++i)
RunLayoutTest(kLayoutTestFiles[i], true);
StopHttpServer();
}
TEST_F(WorkerTest, LimitPerPage) {
......@@ -290,12 +370,3 @@ TEST_F(WorkerTest, LimitTotal) {
EXPECT_EQ(total_workers + 1 + (UITest::in_process_renderer() ? 0 : tab_count),
UITest::GetBrowserProcessCount());
}
TEST_F(WorkerTest, TestHttpServer) {
FilePath path;
PathService::Get(chrome::DIR_TEST_DATA, &path);
path = path.AppendASCII("workers");
StartHttpServer(path);
RunHttpTest("test_http_server_up.html");
StopHttpServer();
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment