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

Unified Diff: ipc/ipc_channel_posix_unittest.cc

Issue 10443021: Android: Get the cache directory using path service. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 7 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ipc/ipc_channel_posix_unittest.cc
diff --git a/ipc/ipc_channel_posix_unittest.cc b/ipc/ipc_channel_posix_unittest.cc
index b4ec401210b9b13bee32388a73327b71b4aa96eb..c0ba94afcb81aa06f1d521b24c6188a79de7f805 100644
--- a/ipc/ipc_channel_posix_unittest.cc
+++ b/ipc/ipc_channel_posix_unittest.cc
@@ -17,6 +17,7 @@
#include "base/file_util.h"
#include "base/memory/scoped_ptr.h"
#include "base/message_loop.h"
+#include "base/path_service.h"
#include "base/test/multiprocess_test.h"
#include "base/test/test_timeouts.h"
#include "testing/multiprocess_func_list.h"
@@ -94,10 +95,11 @@ class IPCChannelPosixTestListener : public IPC::Channel::Listener {
class IPCChannelPosixTest : public base::MultiProcessTest {
public:
- static const char kConnectionSocketTestName[];
static void SetUpSocket(IPC::ChannelHandle *handle,
IPC::Channel::Mode mode);
static void SpinRunLoop(int milliseconds);
+ static std::string GetConnectionSocketName();
John Grabowski 2012/05/24 21:48:18 these should return 'const std::string&'
nilesh 2012/05/24 22:27:51 They are not returning a reference to a member var
+ static std::string GetChannelDirName();
protected:
virtual void SetUp();
@@ -107,13 +109,19 @@ private:
scoped_ptr<MessageLoopForIO> message_loop_;
};
+std::string IPCChannelPosixTest::GetChannelDirName() {
#if defined(OS_ANDROID)
-const char IPCChannelPosixTest::kConnectionSocketTestName[] =
- "/data/local/chrome_IPCChannelPosixTest__ConnectionSocket";
+ FilePath tmp_dir;
+ PathService::Get(base::DIR_CACHE, &tmp_dir);
+ return tmp_dir.value();
#else
-const char IPCChannelPosixTest::kConnectionSocketTestName[] =
- "/var/tmp/chrome_IPCChannelPosixTest__ConnectionSocket";
+ return "/var/tmp";
#endif
+}
+
+std::string IPCChannelPosixTest::GetConnectionSocketName() {
+ return GetChannelDirName() + "/chrome_IPCChannelPosixTest__ConnectionSocket";
+}
void IPCChannelPosixTest::SetUp() {
MultiProcessTest::SetUp();
@@ -185,12 +193,9 @@ void IPCChannelPosixTest::SpinRunLoop(int milliseconds) {
}
TEST_F(IPCChannelPosixTest, BasicListen) {
+ const std::string kChannelName =
+ GetChannelDirName() + "/IPCChannelPosixTest_BasicListen";
-#if defined(OS_ANDROID)
- const char* kChannelName = "/data/local/IPCChannelPosixTest_BasicListen";
-#else
- const char* kChannelName = "/var/tmp/IPCChannelPosixTest_BasicListen";
-#endif
// Test creating a socket that is listening.
IPC::ChannelHandle handle(kChannelName);
SetUpSocket(&handle, IPC::Channel::MODE_NAMED_SERVER);
@@ -228,7 +233,7 @@ TEST_F(IPCChannelPosixTest, BasicConnected) {
TEST_F(IPCChannelPosixTest, AdvancedConnected) {
// Test creating a connection to an external process.
IPCChannelPosixTestListener listener(false);
- IPC::ChannelHandle chan_handle(kConnectionSocketTestName);
+ IPC::ChannelHandle chan_handle(GetConnectionSocketName());
SetUpSocket(&chan_handle, IPC::Channel::MODE_NAMED_SERVER);
IPC::Channel channel(chan_handle, IPC::Channel::MODE_NAMED_SERVER, &listener);
ASSERT_TRUE(channel.Connect());
@@ -258,7 +263,7 @@ TEST_F(IPCChannelPosixTest, ResetState) {
// but continue to listen and make sure another external process can connect
// to us.
IPCChannelPosixTestListener listener(false);
- IPC::ChannelHandle chan_handle(kConnectionSocketTestName);
+ IPC::ChannelHandle chan_handle(GetConnectionSocketName());
SetUpSocket(&chan_handle, IPC::Channel::MODE_NAMED_SERVER);
IPC::Channel channel(chan_handle, IPC::Channel::MODE_NAMED_SERVER, &listener);
ASSERT_TRUE(channel.Connect());
@@ -317,7 +322,7 @@ TEST_F(IPCChannelPosixTest, MultiConnection) {
// Test setting up a connection to an external process, and then have
// another external process attempt to connect to us.
IPCChannelPosixTestListener listener(false);
- IPC::ChannelHandle chan_handle(kConnectionSocketTestName);
+ IPC::ChannelHandle chan_handle(GetConnectionSocketName());
SetUpSocket(&chan_handle, IPC::Channel::MODE_NAMED_SERVER);
IPC::Channel channel(chan_handle, IPC::Channel::MODE_NAMED_SERVER, &listener);
ASSERT_TRUE(channel.Connect());
@@ -354,7 +359,7 @@ TEST_F(IPCChannelPosixTest, DoubleServer) {
// Test setting up two servers with the same name.
IPCChannelPosixTestListener listener(false);
IPCChannelPosixTestListener listener2(false);
- IPC::ChannelHandle chan_handle(kConnectionSocketTestName);
+ IPC::ChannelHandle chan_handle(GetConnectionSocketName());
IPC::Channel channel(chan_handle, IPC::Channel::MODE_SERVER, &listener);
IPC::Channel channel2(chan_handle, IPC::Channel::MODE_SERVER, &listener2);
ASSERT_TRUE(channel.Connect());
@@ -364,30 +369,30 @@ TEST_F(IPCChannelPosixTest, DoubleServer) {
TEST_F(IPCChannelPosixTest, BadMode) {
// Test setting up two servers with a bad mode.
IPCChannelPosixTestListener listener(false);
- IPC::ChannelHandle chan_handle(kConnectionSocketTestName);
+ IPC::ChannelHandle chan_handle(GetConnectionSocketName());
IPC::Channel channel(chan_handle, IPC::Channel::MODE_NONE, &listener);
ASSERT_FALSE(channel.Connect());
}
TEST_F(IPCChannelPosixTest, IsNamedServerInitialized) {
IPCChannelPosixTestListener listener(false);
- IPC::ChannelHandle chan_handle(kConnectionSocketTestName);
- ASSERT_TRUE(file_util::Delete(FilePath(kConnectionSocketTestName), false));
+ IPC::ChannelHandle chan_handle(GetConnectionSocketName());
+ ASSERT_TRUE(file_util::Delete(FilePath(GetConnectionSocketName()), false));
ASSERT_FALSE(IPC::Channel::IsNamedServerInitialized(
- kConnectionSocketTestName));
+ GetConnectionSocketName()));
IPC::Channel channel(chan_handle, IPC::Channel::MODE_NAMED_SERVER, &listener);
ASSERT_TRUE(IPC::Channel::IsNamedServerInitialized(
- kConnectionSocketTestName));
+ GetConnectionSocketName()));
channel.Close();
ASSERT_FALSE(IPC::Channel::IsNamedServerInitialized(
- kConnectionSocketTestName));
+ GetConnectionSocketName()));
}
// A long running process that connects to us
MULTIPROCESS_TEST_MAIN(IPCChannelPosixTestConnectionProc) {
MessageLoopForIO message_loop;
IPCChannelPosixTestListener listener(true);
- IPC::ChannelHandle handle(IPCChannelPosixTest::kConnectionSocketTestName);
+ IPC::ChannelHandle handle(IPCChannelPosixTest::GetConnectionSocketName());
IPCChannelPosixTest::SetUpSocket(&handle, IPC::Channel::MODE_NAMED_CLIENT);
IPC::Channel channel(handle, IPC::Channel::MODE_NAMED_CLIENT, &listener);
EXPECT_TRUE(channel.Connect());
@@ -400,7 +405,7 @@ MULTIPROCESS_TEST_MAIN(IPCChannelPosixTestConnectionProc) {
MULTIPROCESS_TEST_MAIN(IPCChannelPosixFailConnectionProc) {
MessageLoopForIO message_loop;
IPCChannelPosixTestListener listener(false);
- IPC::ChannelHandle handle(IPCChannelPosixTest::kConnectionSocketTestName);
+ IPC::ChannelHandle handle(IPCChannelPosixTest::GetConnectionSocketName());
IPCChannelPosixTest::SetUpSocket(&handle, IPC::Channel::MODE_NAMED_CLIENT);
IPC::Channel channel(handle, IPC::Channel::MODE_NAMED_CLIENT, &listener);
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698