Index: mojo/edk/embedder/platform_channel_pair_posix_unittest.cc |
diff --git a/third_party/mojo/src/mojo/edk/embedder/platform_channel_pair_posix_unittest.cc b/mojo/edk/embedder/platform_channel_pair_posix_unittest.cc |
similarity index 89% |
copy from third_party/mojo/src/mojo/edk/embedder/platform_channel_pair_posix_unittest.cc |
copy to mojo/edk/embedder/platform_channel_pair_posix_unittest.cc |
index 4927b4b8745cf6468f848c4bb039c66b16e57886..a0bb7fd4b9168a2174de97b316388d9a72f599a9 100644 |
--- a/third_party/mojo/src/mojo/edk/embedder/platform_channel_pair_posix_unittest.cc |
+++ b/mojo/edk/embedder/platform_channel_pair_posix_unittest.cc |
@@ -2,7 +2,7 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
-#include "third_party/mojo/src/mojo/edk/embedder/platform_channel_pair.h" |
+#include "mojo/edk/embedder/platform_channel_pair.h" |
#include <errno.h> |
#include <poll.h> |
@@ -15,24 +15,21 @@ |
#include <deque> |
+#include "base/files/file_path.h" |
+#include "base/files/file_util.h" |
#include "base/files/scoped_file.h" |
+#include "base/files/scoped_temp_dir.h" |
#include "base/logging.h" |
-#include "build/build_config.h" |
+#include "mojo/edk/embedder/platform_channel_utils_posix.h" |
+#include "mojo/edk/embedder/platform_handle.h" |
+#include "mojo/edk/embedder/platform_handle_vector.h" |
+#include "mojo/edk/embedder/scoped_platform_handle.h" |
+#include "mojo/edk/test/test_utils.h" |
#include "mojo/public/cpp/system/macros.h" |
#include "testing/gtest/include/gtest/gtest.h" |
-#include "third_party/mojo/src/mojo/edk/embedder/platform_channel_utils_posix.h" |
-#include "third_party/mojo/src/mojo/edk/embedder/platform_handle.h" |
-#include "third_party/mojo/src/mojo/edk/embedder/platform_handle_vector.h" |
-#include "third_party/mojo/src/mojo/edk/embedder/scoped_platform_handle.h" |
-#include "third_party/mojo/src/mojo/edk/test/test_utils.h" |
- |
-#if defined(OS_ANDROID) |
-#include "base/android/path_utils.h" |
-#include "base/files/file_path.h" |
-#endif |
namespace mojo { |
-namespace embedder { |
+namespace edk { |
namespace { |
void WaitReadable(PlatformHandle h) { |
@@ -42,22 +39,6 @@ void WaitReadable(PlatformHandle h) { |
CHECK_EQ(poll(&pfds, 1, -1), 1); |
} |
-FILE* NewTmpFile() { |
-#if defined(OS_ANDROID) |
- base::FilePath tmpdir; |
- if (!base::android::GetCacheDirectory(&tmpdir)) |
- return nullptr; |
- std::string templ = tmpdir.Append("XXXXXXXX").value(); |
- int fd = mkstemp(const_cast<char*>(templ.c_str())); |
- if (fd == -1) |
- return nullptr; |
- CHECK(unlink(templ.c_str()) == 0); |
- return fdopen(fd, "w+"); |
-#else |
- return tmpfile(); |
-#endif |
-} |
- |
class PlatformChannelPairPosixTest : public testing::Test { |
public: |
PlatformChannelPairPosixTest() {} |
@@ -147,6 +128,9 @@ TEST_F(PlatformChannelPairPosixTest, SendReceiveData) { |
} |
TEST_F(PlatformChannelPairPosixTest, SendReceiveFDs) { |
+ base::ScopedTempDir temp_dir; |
+ ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
+ |
static const char kHello[] = "hello"; |
PlatformChannelPair channel_pair; |
@@ -166,7 +150,9 @@ TEST_F(PlatformChannelPairPosixTest, SendReceiveFDs) { |
const char c = '0' + (i % 10); |
ScopedPlatformHandleVectorPtr platform_handles(new PlatformHandleVector); |
for (size_t j = 1; j <= i; j++) { |
- base::ScopedFILE fp(NewTmpFile()); |
+ base::FilePath unused; |
+ base::ScopedFILE fp( |
+ base::CreateAndOpenTemporaryFileInDir(temp_dir.path(), &unused)); |
ASSERT_TRUE(fp); |
ASSERT_EQ(j, fwrite(std::string(j, c).data(), 1, j, fp.get())); |
platform_handles->push_back( |
@@ -208,6 +194,9 @@ TEST_F(PlatformChannelPairPosixTest, SendReceiveFDs) { |
} |
TEST_F(PlatformChannelPairPosixTest, AppendReceivedFDs) { |
+ base::ScopedTempDir temp_dir; |
+ ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
+ |
static const char kHello[] = "hello"; |
PlatformChannelPair channel_pair; |
@@ -217,7 +206,9 @@ TEST_F(PlatformChannelPairPosixTest, AppendReceivedFDs) { |
const std::string file_contents("hello world"); |
{ |
- base::ScopedFILE fp(NewTmpFile()); |
+ base::FilePath unused; |
+ base::ScopedFILE fp( |
+ base::CreateAndOpenTemporaryFileInDir(temp_dir.path(), &unused)); |
ASSERT_TRUE(fp); |
ASSERT_EQ(file_contents.size(), |
fwrite(file_contents.data(), 1, file_contents.size(), fp.get())); |
@@ -265,5 +256,5 @@ TEST_F(PlatformChannelPairPosixTest, AppendReceivedFDs) { |
} |
} // namespace |
-} // namespace embedder |
+} // namespace edk |
} // namespace mojo |