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

Unified Diff: net/test/embedded_test_server/embedded_test_server.h

Issue 83633004: Do not spawn a thread in browser/interactive ui tests before spawning sandbox host process (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: style fix Created 7 years 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
« no previous file with comments | « content/public/test/browser_test_base.cc ('k') | net/test/embedded_test_server/embedded_test_server.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/test/embedded_test_server/embedded_test_server.h
diff --git a/net/test/embedded_test_server/embedded_test_server.h b/net/test/embedded_test_server/embedded_test_server.h
index d5300b4fe215c160c0df11639e80864bd727e82c..5600e0fabff69809f7456fe33534bb976571e7e7 100644
--- a/net/test/embedded_test_server/embedded_test_server.h
+++ b/net/test/embedded_test_server/embedded_test_server.h
@@ -39,6 +39,10 @@ class HttpListenSocket : public TCPListenSocket {
virtual void Listen();
private:
+ friend class EmbeddedTestServer;
+
+ // Detaches the current from |thread_checker_|.
+ void DetachFromThread();
base::ThreadChecker thread_checker_;
};
@@ -48,18 +52,10 @@ class HttpListenSocket : public TCPListenSocket {
// it assumes that the request syntax is correct. It *does not* support
// a Chunked Transfer Encoding.
//
-// The common use case is below:
-//
-// base::Thread io_thread_;
-// scoped_ptr<EmbeddedTestServer> test_server_;
+// The common use case for unit tests is below:
//
// void SetUp() {
-// base::Thread::Options thread_options;
-// thread_options.message_loop_type = base::MessageLoop::TYPE_IO;
-// ASSERT_TRUE(io_thread_.StartWithOptions(thread_options));
-//
-// test_server_.reset(
-// new EmbeddedTestServer(io_thread_.message_loop_proxy()));
+// test_server_.reset(new EmbeddedTestServer());
// ASSERT_TRUE(test_server_.InitializeAndWaitUntilReady());
// test_server_->RegisterRequestHandler(
// base::Bind(&FooTest::HandleRequest, base::Unretained(this)));
@@ -77,6 +73,24 @@ class HttpListenSocket : public TCPListenSocket {
// return http_response.Pass();
// }
//
+// For a test that spawns another process such as browser_tests, you
+// need to stop the server's thread so that there is no no other
+// threads running while spawning the process. To do so, please follow
+// the following example:
+//
+// void SetUp() {
+// test_server_.reset(new EmbeddedTestServer());
+// // EmbeddedTestServer spawns a thread to initialize socket.
+// // Stop the thread in preparation for fork and exec.
+// test_server_->StopThread();
+// ...
+// InProcessBrowserTest::SetUp();
+// }
+//
+// void SetUpOnMainThread() {
+// test_server_->RestartThreadAndListen();
+// }
+//
class EmbeddedTestServer : public StreamListenSocket::Delegate {
public:
typedef base::Callback<scoped_ptr<HttpResponse>(
@@ -122,10 +136,19 @@ class EmbeddedTestServer : public StreamListenSocket::Delegate {
// on UI thread.
void RegisterRequestHandler(const HandleRequestCallback& callback);
+ // Stops IO thread that handles http requests.
+ void StopThread();
+
+ // Restarts IO thread and listen on the socket.
+ void RestartThreadAndListen();
+
private:
+ void StartThread();
+
// Initializes and starts the server. If initialization succeeds, Starts()
// will return true.
void InitializeOnIOThread();
+ void ListenOnIOThread();
// Shuts down the server.
void ShutdownOnIOThread();
« no previous file with comments | « content/public/test/browser_test_base.cc ('k') | net/test/embedded_test_server/embedded_test_server.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698