summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/chrome_tests.gypi2
-rw-r--r--chrome/test/automation/extension_proxy_uitest.cc9
-rw-r--r--chrome/test/layout_test_http_server.cc103
-rw-r--r--chrome/test/layout_test_http_server.h43
-rw-r--r--chrome/test/nacl/nacl_test.cc11
-rw-r--r--chrome/test/nacl/nacl_test.h5
-rw-r--r--chrome/test/ui/ui_test.cc86
-rw-r--r--chrome/test/ui/ui_test.h8
-rw-r--r--content/browser/appcache/appcache_ui_test.cc6
-rw-r--r--content/worker/worker_uitest.cc21
10 files changed, 182 insertions, 112 deletions
diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi
index 73fd01b..cb768d3 100644
--- a/chrome/chrome_tests.gypi
+++ b/chrome/chrome_tests.gypi
@@ -248,6 +248,8 @@
'test/automated_ui_tests/automated_ui_test_base.h',
'test/automation/proxy_launcher.cc',
'test/automation/proxy_launcher.h',
+ 'test/layout_test_http_server.cc',
+ 'test/layout_test_http_server.h',
'test/ui/javascript_test_util.cc',
'test/ui/npapi_test_helper.cc',
'test/ui/npapi_test_helper.h',
diff --git a/chrome/test/automation/extension_proxy_uitest.cc b/chrome/test/automation/extension_proxy_uitest.cc
index 2ee5c47..68825ed 100644
--- a/chrome/test/automation/extension_proxy_uitest.cc
+++ b/chrome/test/automation/extension_proxy_uitest.cc
@@ -9,6 +9,7 @@
#include "chrome/test/automation/browser_proxy.h"
#include "chrome/test/automation/extension_proxy.h"
#include "chrome/test/automation/tab_proxy.h"
+#include "chrome/test/layout_test_http_server.h"
#include "chrome/test/ui/ui_test.h"
namespace {
@@ -108,8 +109,10 @@ TEST_F(ExtensionProxyUITest, DISABLED_ExecuteBrowserActionInActiveTabAsync) {
FilePath path;
// The root directory for the http server does not matter in this case,
// but we have to pick something.
- PathService::Get(chrome::DIR_TEST_DATA, &path);
- StartHttpServerWithPort(path, 1365);
+ ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &path));
+ // TODO(phajdan.jr): Use net/test/test_server instead of layout test server.
+ LayoutTestHttpServer http_server(path, 1365);
+ ASSERT_TRUE(http_server.Start());
GURL localhost = GURL("http://localhost:1365");
NavigateToURL(localhost);
@@ -136,7 +139,7 @@ TEST_F(ExtensionProxyUITest, DISABLED_ExecuteBrowserActionInActiveTabAsync) {
ASSERT_STREQ(L"1", title_wstring.c_str());
// Do not forget to stop the server.
- StopHttpServer();
+ ASSERT_TRUE(http_server.Stop());
}
// Flaky, http://crbug.com/59441.
diff --git a/chrome/test/layout_test_http_server.cc b/chrome/test/layout_test_http_server.cc
new file mode 100644
index 0000000..cac126a
--- /dev/null
+++ b/chrome/test/layout_test_http_server.cc
@@ -0,0 +1,103 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/test/layout_test_http_server.h"
+
+#include "base/command_line.h"
+#include "base/logging.h"
+#include "base/path_service.h"
+#include "base/process_util.h"
+#include "base/string_number_conversions.h"
+
+#if defined(OS_WIN)
+#include "base/win/windows_version.h"
+#endif
+
+namespace {
+
+bool PrepareCommandLine(CommandLine* cmd_line) {
+ FilePath src_path;
+ if (!PathService::Get(base::DIR_SOURCE_ROOT, &src_path))
+ return false;
+
+ cmd_line->SetProgram(FilePath(FILE_PATH_LITERAL("python")));
+
+ FilePath script_path(src_path);
+ script_path = script_path.AppendASCII("third_party");
+ script_path = script_path.AppendASCII("WebKit");
+ script_path = script_path.AppendASCII("Tools");
+ script_path = script_path.AppendASCII("Scripts");
+ script_path = script_path.AppendASCII("new-run-webkit-httpd");
+
+ cmd_line->AppendArgPath(script_path);
+ return true;
+}
+
+} // namespace
+
+LayoutTestHttpServer::LayoutTestHttpServer(const FilePath& root_directory,
+ int port)
+ : root_directory_(root_directory),
+ port_(port),
+ running_(false) {
+}
+
+LayoutTestHttpServer::~LayoutTestHttpServer() {
+ if (running_ && !Stop())
+ LOG(ERROR) << "LayoutTestHttpServer failed to stop.";
+}
+
+bool LayoutTestHttpServer::Start() {
+ if (running_) {
+ LOG(ERROR) << "LayoutTestHttpServer already running.";
+ return false;
+ }
+
+ CommandLine cmd_line(CommandLine::NO_PROGRAM);
+ if (!PrepareCommandLine(&cmd_line))
+ return false;
+ cmd_line.AppendArg("--server=start");
+ cmd_line.AppendArg("--register_cygwin");
+ cmd_line.AppendArgNative(FILE_PATH_LITERAL("--root=") +
+ root_directory_.value());
+ cmd_line.AppendArg("--port=" + base::IntToString(port_));
+
+ FilePath layout_tests_dir;
+ if (!PathService::Get(base::DIR_SOURCE_ROOT, &layout_tests_dir))
+ return false;
+ layout_tests_dir = layout_tests_dir.AppendASCII("chrome")
+ .AppendASCII("test")
+ .AppendASCII("data")
+ .AppendASCII("layout_tests")
+ .AppendASCII("LayoutTests");
+ cmd_line.AppendArgNative(FILE_PATH_LITERAL("--layout_tests_dir=") +
+ layout_tests_dir.value());
+
+ // For Windows 7, if we start the lighttpd server on the foreground mode,
+ // it will mess up with the command window and cause conhost.exe to crash. To
+ // work around this, we start the http server on the background mode.
+#if defined(OS_WIN)
+ if (base::win::GetVersion() >= base::win::VERSION_WIN7)
+ cmd_line.AppendArg("--run_background");
+#endif
+
+ running_ = base::LaunchApp(cmd_line, true, false, NULL);
+ return running_;
+}
+
+bool LayoutTestHttpServer::Stop() {
+ if (!running_) {
+ LOG(ERROR) << "LayoutTestHttpServer not running.";
+ return false;
+ }
+
+ CommandLine cmd_line(CommandLine::NO_PROGRAM);
+ if (!PrepareCommandLine(&cmd_line))
+ return false;
+ cmd_line.AppendArg("--server=stop");
+ bool stopped = base::LaunchApp(cmd_line, true, false, NULL);
+ running_ = !stopped;
+ return stopped;
+}
+
diff --git a/chrome/test/layout_test_http_server.h b/chrome/test/layout_test_http_server.h
new file mode 100644
index 0000000..52f196c
--- /dev/null
+++ b/chrome/test/layout_test_http_server.h
@@ -0,0 +1,43 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_TEST_LAYOUT_TEST_HTTP_SERVER_H_
+#define CHROME_TEST_LAYOUT_TEST_HTTP_SERVER_H_
+#pragma once
+
+#include "base/compiler_specific.h"
+#include "base/file_path.h"
+
+// This object bounds the lifetime of an external HTTP server
+// used for layout tests.
+//
+// NOTE: If you're not running a layout test, you probably want
+// a more lightweight net/test/test_server HTTP server.
+class LayoutTestHttpServer {
+ public:
+ LayoutTestHttpServer(const FilePath& root_directory, int port);
+ ~LayoutTestHttpServer();
+
+ // Starts the server. Returns true on success.
+ bool Start() WARN_UNUSED_RESULT;
+
+ // Stops the server. Returns true on success.
+ //
+ // NOTE: It is recommended to explicitly call Stop and check its return value.
+ // If Stop fails, the server is most likely still running and future attempts
+ // to bind to the same port will fail, possibly resulting in further test
+ // failures.
+ bool Stop() WARN_UNUSED_RESULT;
+
+ private:
+ FilePath root_directory_; // Root directory of the server.
+
+ int port_; // Port on which the server should listen.
+
+ bool running_; // True if the server is currently running.
+
+ DISALLOW_COPY_AND_ASSIGN(LayoutTestHttpServer);
+};
+
+#endif // CHROME_TEST_LAYOUT_TEST_HTTP_SERVER_H_
diff --git a/chrome/test/nacl/nacl_test.cc b/chrome/test/nacl/nacl_test.cc
index 8df1128..eb33697 100644
--- a/chrome/test/nacl/nacl_test.cc
+++ b/chrome/test/nacl/nacl_test.cc
@@ -24,7 +24,9 @@ const FilePath::CharType kBaseUrl[] =
} // namespace
NaClTest::NaClTest()
- : UITest(), use_x64_nexes_(false), multiarch_test_(false) {
+ : use_x64_nexes_(false),
+ multiarch_test_(false),
+ http_server_(GetTestRootDir(), 5103) {
launch_arguments_.AppendSwitch(switches::kEnableNaCl);
// Currently we disable some of the sandboxes. See:
@@ -38,9 +40,10 @@ NaClTest::NaClTest()
NaClTest::~NaClTest() {}
+// static
FilePath NaClTest::GetTestRootDir() {
FilePath path;
- PathService::Get(base::DIR_SOURCE_ROOT, &path);
+ EXPECT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &path));
return path.AppendASCII("native_client");
}
@@ -92,10 +95,10 @@ void NaClTest::SetUp() {
UITest::SetUp();
- StartHttpServerWithPort(nacl_test_dir, 5103);
+ ASSERT_TRUE(http_server_.Start());
}
void NaClTest::TearDown() {
- StopHttpServer();
+ ASSERT_TRUE(http_server_.Stop());
UITest::TearDown();
}
diff --git a/chrome/test/nacl/nacl_test.h b/chrome/test/nacl/nacl_test.h
index 962c897..6cf21ec 100644
--- a/chrome/test/nacl/nacl_test.h
+++ b/chrome/test/nacl/nacl_test.h
@@ -6,6 +6,7 @@
#define CHROME_TEST_NACL_NACL_TEST_H_
#pragma once
+#include "chrome/test/layout_test_http_server.h"
#include "chrome/test/ui/ui_test.h"
class FilePath;
@@ -24,7 +25,7 @@ class NaClTest : public UITest {
// Get the path to the native_client/tests directory, the root of testing
// data.
- FilePath GetTestRootDir();
+ static FilePath GetTestRootDir();
// Waits for a test case (identified by path) to finish.
void WaitForFinish(const FilePath& filename, int wait_time);
@@ -54,6 +55,8 @@ class NaClTest : public UITest {
// in the "nexes" property
bool multiarch_test_;
+ LayoutTestHttpServer http_server_;
+
DISALLOW_COPY_AND_ASSIGN(NaClTest);
};
diff --git a/chrome/test/ui/ui_test.cc b/chrome/test/ui/ui_test.cc
index 2bda934..cc5917a 100644
--- a/chrome/test/ui/ui_test.cc
+++ b/chrome/test/ui/ui_test.cc
@@ -524,92 +524,6 @@ ProxyLauncher* UITest::CreateProxyLauncher() {
return new AnonymousProxyLauncher(true);
}
-static CommandLine* CreatePythonCommandLine() {
- // Note: Python's first argument must be the script; do not append CommandLine
- // switches, as they would precede the script path and break this CommandLine.
- return new CommandLine(FilePath(FILE_PATH_LITERAL("python")));
-}
-
-static CommandLine* CreateHttpServerCommandLine() {
- FilePath src_path;
- // Get to 'src' dir.
- PathService::Get(base::DIR_SOURCE_ROOT, &src_path);
-
- FilePath script_path(src_path);
- script_path = script_path.AppendASCII("third_party");
- script_path = script_path.AppendASCII("WebKit");
- script_path = script_path.AppendASCII("Tools");
- script_path = script_path.AppendASCII("Scripts");
- script_path = script_path.AppendASCII("new-run-webkit-httpd");
-
- CommandLine* cmd_line = CreatePythonCommandLine();
- cmd_line->AppendArgPath(script_path);
- return cmd_line;
-}
-
-void UITest::StartHttpServer(const FilePath& root_directory) {
- StartHttpServerWithPort(root_directory, 0);
-}
-
-void UITest::StartHttpServerWithPort(const FilePath& root_directory,
- int port) {
- // Append CommandLine arguments after the server script, switches won't work.
- scoped_ptr<CommandLine> cmd_line(CreateHttpServerCommandLine());
- ASSERT_TRUE(cmd_line.get());
- cmd_line->AppendArg("--server=start");
- cmd_line->AppendArg("--register_cygwin");
- cmd_line->AppendArgNative(FILE_PATH_LITERAL("--root=") +
- root_directory.value());
-
- FilePath layout_tests_dir;
- PathService::Get(base::DIR_SOURCE_ROOT, &layout_tests_dir);
- layout_tests_dir = layout_tests_dir.AppendASCII("chrome")
- .AppendASCII("test")
- .AppendASCII("data")
- .AppendASCII("layout_tests")
- .AppendASCII("LayoutTests");
- cmd_line->AppendArgNative(FILE_PATH_LITERAL("--layout_tests_dir=") +
- layout_tests_dir.value());
-
- // For Windows 7, if we start the lighttpd server on the foreground mode,
- // it will mess up with the command window and cause conhost.exe to crash. To
- // work around this, we start the http server on the background mode.
-#if defined(OS_WIN)
- if (base::win::GetVersion() >= base::win::VERSION_WIN7)
- cmd_line->AppendArg("--run_background");
-#endif
-
- if (port)
- cmd_line->AppendArg("--port=" + base::IntToString(port));
-
-#if defined(OS_WIN)
- // TODO(phajdan.jr): is this needed?
- base::LaunchAppWithHandleInheritance(cmd_line->command_line_string(),
- true,
- false,
- NULL);
-#else
- base::LaunchApp(*cmd_line.get(), true, false, NULL);
-#endif
-}
-
-void UITest::StopHttpServer() {
- // Append CommandLine arguments after the server script, switches won't work.
- scoped_ptr<CommandLine> cmd_line(CreateHttpServerCommandLine());
- ASSERT_TRUE(cmd_line.get());
- cmd_line->AppendArg("--server=stop");
-
-#if defined(OS_WIN)
- // TODO(phajdan.jr): is this needed?
- base::LaunchAppWithHandleInheritance(cmd_line->command_line_string(),
- true,
- false,
- NULL);
-#else
- base::LaunchApp(*cmd_line.get(), true, false, NULL);
-#endif
-}
-
bool UITest::GetBrowserProcessCount(int* count) {
*count = 0;
if (!automation()->WaitForProcessLauncherThreadToGoIdle())
diff --git a/chrome/test/ui/ui_test.h b/chrome/test/ui/ui_test.h
index 85b8215..e6d00c8 100644
--- a/chrome/test/ui/ui_test.h
+++ b/chrome/test/ui/ui_test.h
@@ -351,14 +351,6 @@ class UITest : public UITestBase, public PlatformTest {
virtual ProxyLauncher* CreateProxyLauncher();
- // Synchronously launches local http server normally used to run LayoutTests.
- void StartHttpServer(const FilePath& root_directory);
-
- // Launches local http server on the specified port.
- void StartHttpServerWithPort(const FilePath& root_directory, int port);
-
- void StopHttpServer();
-
// Count the number of active browser processes launched by this test.
// The count includes browser sub-processes.
bool GetBrowserProcessCount(int* count) WARN_UNUSED_RESULT;
diff --git a/content/browser/appcache/appcache_ui_test.cc b/content/browser/appcache/appcache_ui_test.cc
index 58ca32b..6200226 100644
--- a/content/browser/appcache/appcache_ui_test.cc
+++ b/content/browser/appcache/appcache_ui_test.cc
@@ -3,6 +3,7 @@
// found in the LICENSE file.
#include "base/file_path.h"
+#include "chrome/test/layout_test_http_server.h"
#include "chrome/test/ui/ui_layout_test.h"
class AppCacheUITest : public UILayoutTest {
@@ -16,10 +17,11 @@ class AppCacheUITest : public UILayoutTest {
appcache_test_dir = appcache_test_dir.AppendASCII("appcache");
InitializeForLayoutTest(http_test_dir, appcache_test_dir, kHttpPort);
- StartHttpServer(new_http_root_dir_);
+ LayoutTestHttpServer http_server(new_http_root_dir_, kHttpPort);
+ ASSERT_TRUE(http_server.Start());
for (int i = 0; i < num_tests; ++i)
RunLayoutTest(tests[i], kHttpPort);
- StopHttpServer();
+ ASSERT_TRUE(http_server.Stop());
}
protected:
diff --git a/content/worker/worker_uitest.cc b/content/worker/worker_uitest.cc
index 5b2f4a2..6099a05 100644
--- a/content/worker/worker_uitest.cc
+++ b/content/worker/worker_uitest.cc
@@ -9,6 +9,7 @@
#include "chrome/app/chrome_command_ids.h"
#include "chrome/test/automation/browser_proxy.h"
#include "chrome/test/automation/tab_proxy.h"
+#include "chrome/test/layout_test_http_server.h"
#include "chrome/test/ui/ui_layout_test.h"
#include "chrome/test/ui_test_utils.h"
#include "content/browser/worker_host/worker_service.h"
@@ -437,10 +438,11 @@ TEST_F(WorkerTest, DISABLED_WorkerHttpLayoutTests) {
worker_test_dir = worker_test_dir.AppendASCII("workers");
InitializeForLayoutTest(http_test_dir, worker_test_dir, kHttpPort);
- StartHttpServer(new_http_root_dir_);
+ LayoutTestHttpServer http_server(new_http_root_dir_, kHttpPort);
+ ASSERT_TRUE(http_server.Start());
for (size_t i = 0; i < arraysize(kLayoutTestFiles); ++i)
RunLayoutTest(kLayoutTestFiles[i], kHttpPort);
- StopHttpServer();
+ ASSERT_TRUE(http_server.Stop());
}
TEST_F(WorkerTest, WorkerWebSocketLayoutTests) {
@@ -468,10 +470,11 @@ TEST_F(WorkerTest, WorkerWebSocketLayoutTests) {
ui_test_utils::TestWebSocketServer websocket_server;
ASSERT_TRUE(websocket_server.Start(websocket_root_dir));
- StartHttpServer(new_http_root_dir_);
+ LayoutTestHttpServer http_server(new_http_root_dir_, kHttpPort);
+ ASSERT_TRUE(http_server.Start());
for (size_t i = 0; i < arraysize(kLayoutTestFiles); ++i)
RunLayoutTest(kLayoutTestFiles[i], kHttpPort);
- StopHttpServer();
+ ASSERT_TRUE(http_server.Stop());
}
TEST_F(WorkerTest, DISABLED_WorkerXhrHttpLayoutTests) {
@@ -506,10 +509,11 @@ TEST_F(WorkerTest, DISABLED_WorkerXhrHttpLayoutTests) {
worker_test_dir = worker_test_dir.AppendASCII("workers");
InitializeForLayoutTest(http_test_dir, worker_test_dir, kHttpPort);
- StartHttpServer(new_http_root_dir_);
+ LayoutTestHttpServer http_server(new_http_root_dir_, kHttpPort);
+ ASSERT_TRUE(http_server.Start());
for (size_t i = 0; i < arraysize(kLayoutTestFiles); ++i)
RunLayoutTest(kLayoutTestFiles[i], kHttpPort);
- StopHttpServer();
+ ASSERT_TRUE(http_server.Stop());
}
// Flaky, http://crbug.com/34996.
@@ -740,10 +744,11 @@ class WorkerFileSystemTest : public WorkerTest {
FilePath().AppendASCII("workers")
.AppendASCII("script-tests"));
- StartHttpServer(new_http_root_dir_);
+ LayoutTestHttpServer http_server(new_http_root_dir_, 8000);
+ ASSERT_TRUE(http_server.Start());
for (int i = 0; i < num_tests; ++i)
RunLayoutTest(tests[i], 8000);
- StopHttpServer();
+ ASSERT_TRUE(http_server.Stop());
// Navigate to a blank page so that any workers are cleaned up.
// This helps leaks trackers do a better job of reporting.