summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/extensions/extension_apitest.cc3
-rw-r--r--chrome/browser/extensions/extension_apitest.h9
-rw-r--r--chrome/browser/ssl/ssl_browser_tests.cc2
-rw-r--r--chrome/test/base/ui_test_utils.cc151
-rw-r--r--chrome/test/base/ui_test_utils.h71
-rw-r--r--chrome/test/ppapi/ppapi_test.cc3
6 files changed, 10 insertions, 229 deletions
diff --git a/chrome/browser/extensions/extension_apitest.cc b/chrome/browser/extensions/extension_apitest.cc
index 39ae50d..4d89f85 100644
--- a/chrome/browser/extensions/extension_apitest.cc
+++ b/chrome/browser/extensions/extension_apitest.cc
@@ -17,6 +17,7 @@
#include "chrome/test/base/ui_test_utils.h"
#include "content/public/browser/notification_registrar.h"
#include "content/public/browser/notification_service.h"
+#include "content/public/test/browser_test_utils.h"
#include "net/base/net_util.h"
namespace {
@@ -269,7 +270,7 @@ bool ExtensionApiTest::StartTestServer() {
}
bool ExtensionApiTest::StartWebSocketServer(const FilePath& root_directory) {
- websocket_server_.reset(new ui_test_utils::TestWebSocketServer());
+ websocket_server_.reset(new content::TestWebSocketServer());
int port = websocket_server_->UseRandomPort();
if (!websocket_server_->Start(root_directory))
return false;
diff --git a/chrome/browser/extensions/extension_apitest.h b/chrome/browser/extensions/extension_apitest.h
index 92a3298..9d3277a 100644
--- a/chrome/browser/extensions/extension_apitest.h
+++ b/chrome/browser/extensions/extension_apitest.h
@@ -15,13 +15,14 @@
class FilePath;
+namespace content {
+class TestWebSocketServer;
+}
+
namespace extensions {
class Extension;
}
-namespace ui_test_utils {
-class TestWebSocketServer;
-}
// The general flow of these API tests should work like this:
// (1) Setup initial browser state (e.g. create some bookmarks for the
@@ -169,7 +170,7 @@ class ExtensionApiTest : public ExtensionBrowserTest {
scoped_ptr<DictionaryValue> test_config_;
// Hold the test WebSocket server.
- scoped_ptr<ui_test_utils::TestWebSocketServer> websocket_server_;
+ scoped_ptr<content::TestWebSocketServer> websocket_server_;
};
// PlatformAppApiTest sets up the command-line flags necessary for platform
diff --git a/chrome/browser/ssl/ssl_browser_tests.cc b/chrome/browser/ssl/ssl_browser_tests.cc
index ba39602..39610f4 100644
--- a/chrome/browser/ssl/ssl_browser_tests.cc
+++ b/chrome/browser/ssl/ssl_browser_tests.cc
@@ -570,7 +570,7 @@ IN_PROC_BROWSER_TEST_F(SSLUITest, TestWSSInvalidCertAndGoForward) {
ASSERT_TRUE(https_server_expired_.Start());
// Start pywebsocket with TLS.
- ui_test_utils::TestWebSocketServer wss_server;
+ content::TestWebSocketServer wss_server;
int port = wss_server.UseRandomPort();
wss_server.UseTLS();
FilePath wss_root_dir;
diff --git a/chrome/test/base/ui_test_utils.cc b/chrome/test/base/ui_test_utils.cc
index 538f4c6..d702a48 100644
--- a/chrome/test/base/ui_test_utils.cc
+++ b/chrome/test/base/ui_test_utils.cc
@@ -19,9 +19,6 @@
#include "base/memory/scoped_ptr.h"
#include "base/message_loop.h"
#include "base/path_service.h"
-#include "base/process_util.h"
-#include "base/rand_util.h"
-#include "base/string_number_conversions.h"
#include "base/test/test_timeouts.h"
#include "base/time.h"
#include "base/utf_string_conversions.h"
@@ -89,8 +86,6 @@ using content::RenderWidgetHost;
using content::Referrer;
using content::WebContents;
-static const int kDefaultWsPort = 8880;
-
namespace ui_test_utils {
namespace {
@@ -552,152 +547,6 @@ bool SendMouseEventsSync(ui_controls::MouseButton type, int state) {
return !testing::Test::HasFatalFailure();
}
-TestWebSocketServer::TestWebSocketServer()
- : started_(false),
- port_(kDefaultWsPort),
- secure_(false) {
-#if defined(OS_POSIX)
- process_group_id_ = base::kNullProcessHandle;
-#endif
-}
-
-int TestWebSocketServer::UseRandomPort() {
- port_ = base::RandInt(1024, 65535);
- return port_;
-}
-
-void TestWebSocketServer::UseTLS() {
- secure_ = true;
-}
-
-bool TestWebSocketServer::Start(const FilePath& root_directory) {
- if (started_)
- return true;
- // Append CommandLine arguments after the server script, switches won't work.
- scoped_ptr<CommandLine> cmd_line(CreateWebSocketServerCommandLine());
- cmd_line->AppendArg("--server=start");
- cmd_line->AppendArg("--chromium");
- cmd_line->AppendArg("--register_cygwin");
- cmd_line->AppendArgNative(FILE_PATH_LITERAL("--root=") +
- root_directory.value());
- cmd_line->AppendArg("--port=" + base::IntToString(port_));
- if (secure_)
- cmd_line->AppendArg("--tls");
- if (!temp_dir_.CreateUniqueTempDir()) {
- LOG(ERROR) << "Unable to create a temporary directory.";
- return false;
- }
- cmd_line->AppendArgNative(FILE_PATH_LITERAL("--output-dir=") +
- temp_dir_.path().value());
- websocket_pid_file_ = temp_dir_.path().AppendASCII("websocket.pid");
- cmd_line->AppendArgNative(FILE_PATH_LITERAL("--pidfile=") +
- websocket_pid_file_.value());
- SetPythonPath();
-
- base::LaunchOptions options;
- base::ProcessHandle process_handle;
-
-#if defined(OS_POSIX)
- options.new_process_group = true;
-#elif defined(OS_WIN)
- job_handle_.Set(CreateJobObject(NULL, NULL));
- if (!job_handle_.IsValid()) {
- LOG(ERROR) << "Could not create JobObject.";
- return false;
- }
-
- if (!base::SetJobObjectAsKillOnJobClose(job_handle_.Get())) {
- LOG(ERROR) << "Could not SetInformationJobObject.";
- return false;
- }
-
- options.inherit_handles = true;
- options.job_handle = job_handle_.Get();
-#endif
-
- // Launch a new WebSocket server process.
- if (!base::LaunchProcess(*cmd_line.get(), options, &process_handle)) {
- LOG(ERROR) << "Unable to launch websocket server.";
- return false;
- }
-#if defined(OS_POSIX)
- process_group_id_ = process_handle;
-#endif
- int exit_code;
- bool wait_success = base::WaitForExitCodeWithTimeout(
- process_handle,
- &exit_code,
- TestTimeouts::action_max_timeout());
- base::CloseProcessHandle(process_handle);
-
- if (!wait_success || exit_code != 0) {
- LOG(ERROR) << "Failed to run new-run-webkit-websocketserver: "
- << "wait_success = " << wait_success << ", "
- << "exit_code = " << exit_code;
- return false;
- }
-
- started_ = true;
- return true;
-}
-
-CommandLine* TestWebSocketServer::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.
- FilePath path;
- CHECK(GetPythonRunTime(&path));
- return new CommandLine(path);
-}
-
-void TestWebSocketServer::SetPythonPath() {
- FilePath scripts_path;
- PathService::Get(base::DIR_SOURCE_ROOT, &scripts_path);
-
- scripts_path = scripts_path
- .Append(FILE_PATH_LITERAL("third_party"))
- .Append(FILE_PATH_LITERAL("WebKit"))
- .Append(FILE_PATH_LITERAL("Tools"))
- .Append(FILE_PATH_LITERAL("Scripts"));
- AppendToPythonPath(scripts_path);
-}
-
-CommandLine* TestWebSocketServer::CreateWebSocketServerCommandLine() {
- 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-websocketserver");
-
- CommandLine* cmd_line = CreatePythonCommandLine();
- cmd_line->AppendArgPath(script_path);
- return cmd_line;
-}
-
-TestWebSocketServer::~TestWebSocketServer() {
- if (!started_)
- return;
- // Append CommandLine arguments after the server script, switches won't work.
- scoped_ptr<CommandLine> cmd_line(CreateWebSocketServerCommandLine());
- cmd_line->AppendArg("--server=stop");
- cmd_line->AppendArg("--chromium");
- cmd_line->AppendArgNative(FILE_PATH_LITERAL("--pidfile=") +
- websocket_pid_file_.value());
- base::LaunchOptions options;
- options.wait = true;
- base::LaunchProcess(*cmd_line.get(), options, NULL);
-
-#if defined(OS_POSIX)
- // Just to make sure that the server process terminates certainly.
- if (process_group_id_ != base::kNullProcessHandle)
- base::KillProcessGroup(process_group_id_);
-#endif
-}
-
WindowedTabAddedNotificationObserver::WindowedTabAddedNotificationObserver(
const content::NotificationSource& source)
: WindowedNotificationObserver(chrome::NOTIFICATION_TAB_ADDED, source),
diff --git a/chrome/test/base/ui_test_utils.h b/chrome/test/base/ui_test_utils.h
index 039972e..32e59fc 100644
--- a/chrome/test/base/ui_test_utils.h
+++ b/chrome/test/base/ui_test_utils.h
@@ -12,8 +12,6 @@
#include <vector>
#include "base/basictypes.h"
-#include "base/process.h"
-#include "base/scoped_temp_dir.h"
#include "base/string16.h"
#include "chrome/browser/ui/view_ids.h"
#include "content/public/browser/browser_thread.h"
@@ -29,10 +27,6 @@
#include "ui/ui_controls/ui_controls.h"
#include "webkit/glue/window_open_disposition.h"
-#if defined(OS_WIN)
-#include "base/win/scoped_handle.h"
-#endif
-
#if defined(TOOLKIT_VIEWS)
#include "ui/views/view.h"
#endif
@@ -46,7 +40,6 @@ class FilePath;
class HistoryService;
class MessageLoop;
class Profile;
-class ScopedTempDir;
class SkBitmap;
class TabContents;
class TemplateURLService;
@@ -238,70 +231,6 @@ bool SendMouseMoveSync(const gfx::Point& location) WARN_UNUSED_RESULT;
bool SendMouseEventsSync(ui_controls::MouseButton type,
int state) WARN_UNUSED_RESULT;
-// This is a utility class for running a python websocket server
-// during tests. The server is started during the construction of the
-// object, and is stopped when the destructor is called. Note that
-// because of the underlying script that is used:
-//
-// third_paty/WebKit/Tools/Scripts/new-run-webkit-websocketserver
-//
-// Only *_wsh.py handlers found under "http/tests/websocket/tests" from the
-// |root_directory| will be found and active while running the test
-// server.
-class TestWebSocketServer {
- public:
- TestWebSocketServer();
-
- // Stops the python websocket server if it was already started.
- ~TestWebSocketServer();
-
- // Use a random port, useful for tests that are sharded. Returns the port.
- int UseRandomPort();
-
- // Serves with TLS.
- void UseTLS();
-
- // Starts the python websocket server using |root_directory|. Returns whether
- // the server was successfully started.
- bool Start(const FilePath& root_directory);
-
- private:
- // Sets up PYTHONPATH to run websocket_server.py.
- void SetPythonPath();
-
- // Creates a CommandLine for invoking the python interpreter.
- CommandLine* CreatePythonCommandLine();
-
- // Creates a CommandLine for invoking the python websocker server.
- CommandLine* CreateWebSocketServerCommandLine();
-
- // Has the server been started?
- bool started_;
-
- // A Scoped temporary directory for holding the python pid file.
- ScopedTempDir temp_dir_;
-
- // Used to close the same python interpreter when server falls out
- // scope.
- FilePath websocket_pid_file_;
-
-#if defined(OS_POSIX)
- // ProcessHandle used to terminate child process.
- base::ProcessHandle process_group_id_;
-#elif defined(OS_WIN)
- // JobObject used to clean up orphaned child process.
- base::win::ScopedHandle job_handle_;
-#endif
-
- // Holds port number which the python websocket server uses.
- int port_;
-
- // If the python websocket server serves with TLS.
- bool secure_;
-
- DISALLOW_COPY_AND_ASSIGN(TestWebSocketServer);
-};
-
// A WindowedNotificationObserver hard-wired to observe
// chrome::NOTIFICATION_TAB_ADDED.
class WindowedTabAddedNotificationObserver
diff --git a/chrome/test/ppapi/ppapi_test.cc b/chrome/test/ppapi/ppapi_test.cc
index 056b6ad..ba9639f 100644
--- a/chrome/test/ppapi/ppapi_test.cc
+++ b/chrome/test/ppapi/ppapi_test.cc
@@ -24,6 +24,7 @@
#include "content/public/browser/web_contents.h"
#include "content/public/common/content_paths.h"
#include "content/public/common/content_switches.h"
+#include "content/public/test/browser_test_utils.h"
#include "content/test/gpu/test_switches.h"
#include "media/audio/audio_manager.h"
#include "net/base/net_util.h"
@@ -184,7 +185,7 @@ void PPAPITestBase::RunTestWithWebSocketServer(const std::string& test_case) {
FilePath websocket_root_dir;
ASSERT_TRUE(
PathService::Get(content::DIR_LAYOUT_TESTS, &websocket_root_dir));
- ui_test_utils::TestWebSocketServer server;
+ content::TestWebSocketServer server;
int port = server.UseRandomPort();
ASSERT_TRUE(server.Start(websocket_root_dir));
FilePath http_document_root;