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

Unified Diff: net/socket/unix_domain_listen_socket_posix_unittest.cc

Issue 376323002: Refactor unix domain socket. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix unittests because of incomplete reversion Created 6 years, 5 months 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
Index: net/socket/unix_domain_listen_socket_posix_unittest.cc
diff --git a/net/socket/unix_domain_socket_posix_unittest.cc b/net/socket/unix_domain_listen_socket_posix_unittest.cc
similarity index 80%
rename from net/socket/unix_domain_socket_posix_unittest.cc
rename to net/socket/unix_domain_listen_socket_posix_unittest.cc
index b1857e62e0e19df8f1d226def89fc954d4f8f951..720b4ab41b7b327b394b300cebaa099152d01bbb 100644
--- a/net/socket/unix_domain_socket_posix_unittest.cc
+++ b/net/socket/unix_domain_listen_socket_posix_unittest.cc
@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "net/socket/unix_domain_listen_socket_posix.h"
+
#include <errno.h>
#include <fcntl.h>
#include <poll.h>
@@ -30,7 +32,6 @@
#include "base/threading/platform_thread.h"
#include "base/threading/thread.h"
#include "net/socket/socket_descriptor.h"
-#include "net/socket/unix_domain_socket_posix.h"
#include "testing/gtest/include/gtest/gtest.h"
using std::queue;
@@ -52,6 +53,8 @@ enum EventType {
EVENT_READ,
};
+// TODO(byungchul): Use ScopedTempDir not to interfere other unittests with
+// same socket path when multiple unittests are running in parallel.
string MakeSocketPath(const string& socket_file_name) {
base::FilePath temp_dir;
base::GetTempDir(&temp_dir);
@@ -151,16 +154,16 @@ bool UserCanConnectCallback(
return allow_user;
}
-class UnixDomainSocketTestHelper : public testing::Test {
+class UnixDomainListenSocketTestHelper : public testing::Test {
public:
void CreateAndListen() {
- socket_ = UnixDomainSocket::CreateAndListen(
+ socket_ = UnixDomainListenSocket::CreateAndListen(
file_path_.value(), socket_delegate_.get(), MakeAuthCallback());
socket_delegate_->OnListenCompleted();
}
protected:
- UnixDomainSocketTestHelper(const string& path, bool allow_user)
+ UnixDomainListenSocketTestHelper(const string& path, bool allow_user)
: file_path_(path),
allow_user_(allow_user) {}
@@ -177,7 +180,7 @@ class UnixDomainSocketTestHelper : public testing::Test {
event_manager_ = NULL;
}
- UnixDomainSocket::AuthCallback MakeAuthCallback() {
+ UnixDomainListenSocket::AuthCallback MakeAuthCallback() {
return base::Bind(&UserCanConnectCallback, allow_user_, event_manager_);
}
@@ -212,7 +215,7 @@ class UnixDomainSocketTestHelper : public testing::Test {
thread->StartWithOptions(options);
thread->message_loop()->PostTask(
FROM_HERE,
- base::Bind(&UnixDomainSocketTestHelper::CreateAndListen,
+ base::Bind(&UnixDomainListenSocketTestHelper::CreateAndListen,
base::Unretained(this)));
return thread.Pass();
}
@@ -221,34 +224,38 @@ class UnixDomainSocketTestHelper : public testing::Test {
const bool allow_user_;
scoped_refptr<EventManager> event_manager_;
scoped_ptr<TestListenSocketDelegate> socket_delegate_;
- scoped_ptr<UnixDomainSocket> socket_;
+ scoped_ptr<UnixDomainListenSocket> socket_;
};
-class UnixDomainSocketTest : public UnixDomainSocketTestHelper {
+class UnixDomainListenSocketTest : public UnixDomainListenSocketTestHelper {
protected:
- UnixDomainSocketTest()
- : UnixDomainSocketTestHelper(MakeSocketPath(), true /* allow user */) {}
+ UnixDomainListenSocketTest()
+ : UnixDomainListenSocketTestHelper(MakeSocketPath(),
+ true /* allow user */) {}
};
-class UnixDomainSocketTestWithInvalidPath : public UnixDomainSocketTestHelper {
+class UnixDomainListenSocketTestWithInvalidPath
+ : public UnixDomainListenSocketTestHelper {
protected:
- UnixDomainSocketTestWithInvalidPath()
- : UnixDomainSocketTestHelper(kInvalidSocketPath, true) {}
+ UnixDomainListenSocketTestWithInvalidPath()
+ : UnixDomainListenSocketTestHelper(kInvalidSocketPath, true) {}
};
-class UnixDomainSocketTestWithForbiddenUser
- : public UnixDomainSocketTestHelper {
+class UnixDomainListenSocketTestWithForbiddenUser
+ : public UnixDomainListenSocketTestHelper {
protected:
- UnixDomainSocketTestWithForbiddenUser()
- : UnixDomainSocketTestHelper(MakeSocketPath(), false /* forbid user */) {}
+ UnixDomainListenSocketTestWithForbiddenUser()
+ : UnixDomainListenSocketTestHelper(MakeSocketPath(),
+ false /* forbid user */) {}
};
-TEST_F(UnixDomainSocketTest, CreateAndListen) {
+TEST_F(UnixDomainListenSocketTest, CreateAndListen) {
CreateAndListen();
EXPECT_FALSE(socket_.get() == NULL);
}
-TEST_F(UnixDomainSocketTestWithInvalidPath, CreateAndListenWithInvalidPath) {
+TEST_F(UnixDomainListenSocketTestWithInvalidPath,
+ CreateAndListenWithInvalidPath) {
CreateAndListen();
EXPECT_TRUE(socket_.get() == NULL);
}
@@ -256,26 +263,26 @@ TEST_F(UnixDomainSocketTestWithInvalidPath, CreateAndListenWithInvalidPath) {
#ifdef SOCKET_ABSTRACT_NAMESPACE_SUPPORTED
// Test with an invalid path to make sure that the socket is not backed by a
// file.
-TEST_F(UnixDomainSocketTestWithInvalidPath,
+TEST_F(UnixDomainListenSocketTestWithInvalidPath,
CreateAndListenWithAbstractNamespace) {
- socket_ = UnixDomainSocket::CreateAndListenWithAbstractNamespace(
+ socket_ = UnixDomainListenSocket::CreateAndListenWithAbstractNamespace(
file_path_.value(), "", socket_delegate_.get(), MakeAuthCallback());
EXPECT_FALSE(socket_.get() == NULL);
}
-TEST_F(UnixDomainSocketTest, TestFallbackName) {
- scoped_ptr<UnixDomainSocket> existing_socket =
- UnixDomainSocket::CreateAndListenWithAbstractNamespace(
+TEST_F(UnixDomainListenSocketTest, TestFallbackName) {
+ scoped_ptr<UnixDomainListenSocket> existing_socket =
+ UnixDomainListenSocket::CreateAndListenWithAbstractNamespace(
file_path_.value(), "", socket_delegate_.get(), MakeAuthCallback());
EXPECT_FALSE(existing_socket.get() == NULL);
// First, try to bind socket with the same name with no fallback name.
socket_ =
- UnixDomainSocket::CreateAndListenWithAbstractNamespace(
+ UnixDomainListenSocket::CreateAndListenWithAbstractNamespace(
file_path_.value(), "", socket_delegate_.get(), MakeAuthCallback());
EXPECT_TRUE(socket_.get() == NULL);
// Now with a fallback name.
const char kFallbackSocketName[] = "unix_domain_socket_for_testing_2";
- socket_ = UnixDomainSocket::CreateAndListenWithAbstractNamespace(
+ socket_ = UnixDomainListenSocket::CreateAndListenWithAbstractNamespace(
file_path_.value(),
MakeSocketPath(kFallbackSocketName),
socket_delegate_.get(),
@@ -284,7 +291,7 @@ TEST_F(UnixDomainSocketTest, TestFallbackName) {
}
#endif
-TEST_F(UnixDomainSocketTest, TestWithClient) {
+TEST_F(UnixDomainListenSocketTest, TestWithClient) {
const scoped_ptr<base::Thread> server_thread = CreateAndRunServerThread();
EventType event = event_manager_->WaitForEvent();
ASSERT_EQ(EVENT_LISTEN, event);
@@ -311,7 +318,7 @@ TEST_F(UnixDomainSocketTest, TestWithClient) {
ASSERT_EQ(EVENT_CLOSE, event);
}
-TEST_F(UnixDomainSocketTestWithForbiddenUser, TestWithForbiddenUser) {
+TEST_F(UnixDomainListenSocketTestWithForbiddenUser, TestWithForbiddenUser) {
const scoped_ptr<base::Thread> server_thread = CreateAndRunServerThread();
EventType event = event_manager_->WaitForEvent();
ASSERT_EQ(EVENT_LISTEN, event);

Powered by Google App Engine
This is Rietveld 408576698