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

Side by Side Diff: content/browser/posix_file_descriptor_info_impl_unittest.cc

Issue 2950153002: Improve process launch handle sharing API. (Closed)
Patch Set: Fix Mojo launcher, review comments Created 3 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/file_descriptor_info_impl.h" 5 #include "content/browser/posix_file_descriptor_info_impl.h"
6 6
7 #include <fcntl.h> 7 #include <fcntl.h>
8 #include <unistd.h> 8 #include <unistd.h>
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/posix/eintr_wrapper.h" 11 #include "base/posix/eintr_wrapper.h"
12 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
13 13
14 namespace { 14 namespace {
15 15
(...skipping 12 matching lines...) Expand all
28 EXPECT_NE(IGNORE_EINTR(close(fd)), -1); 28 EXPECT_NE(IGNORE_EINTR(close(fd)), -1);
29 return false; 29 return false;
30 } 30 }
31 return true; 31 return true;
32 } 32 }
33 33
34 } // namespace 34 } // namespace
35 35
36 namespace content { 36 namespace content {
37 37
38 typedef testing::Test FileDescriptorInfoTest; 38 typedef testing::Test PosixFileDescriptorInfoTest;
39 39
40 TEST_F(FileDescriptorInfoTest, Transfer) { 40 TEST_F(PosixFileDescriptorInfoTest, Transfer) {
41 int testingId = 42; 41 int testingId = 42;
42 std::unique_ptr<FileDescriptorInfo> target(FileDescriptorInfoImpl::Create()); 42 std::unique_ptr<PosixFileDescriptorInfo> target(
43 PosixFileDescriptorInfoImpl::Create());
43 base::ScopedFD fd(GetSafeFd()); 44 base::ScopedFD fd(GetSafeFd());
44 45
45 int raw_fd = fd.get(); 46 int raw_fd = fd.get();
46 target->Transfer(testingId, std::move(fd)); 47 target->Transfer(testingId, std::move(fd));
47 ASSERT_EQ(1U, target->GetMappingSize()); 48 ASSERT_EQ(1U, target->GetMappingSize());
48 ASSERT_EQ(target->GetFDAt(0), raw_fd); 49 ASSERT_EQ(target->GetFDAt(0), raw_fd);
49 ASSERT_EQ(target->GetIDAt(0), testingId); 50 ASSERT_EQ(target->GetIDAt(0), testingId);
50 51
51 target.reset(); 52 target.reset();
52 53
53 ASSERT_TRUE(VerifyClosed(raw_fd)); 54 ASSERT_TRUE(VerifyClosed(raw_fd));
54 } 55 }
55 56
56 TEST_F(FileDescriptorInfoTest, Share) { 57 TEST_F(PosixFileDescriptorInfoTest, Share) {
57 int testingId = 42; 58 int testingId = 42;
58 std::unique_ptr<FileDescriptorInfo> target(FileDescriptorInfoImpl::Create()); 59 std::unique_ptr<PosixFileDescriptorInfo> target(
60 PosixFileDescriptorInfoImpl::Create());
59 base::ScopedFD fd(GetSafeFd()); 61 base::ScopedFD fd(GetSafeFd());
60 62
61 int raw_fd = fd.get(); 63 int raw_fd = fd.get();
62 target->Share(testingId, fd.get()); 64 target->Share(testingId, fd.get());
63 ASSERT_EQ(1U, target->GetMappingSize()); 65 ASSERT_EQ(1U, target->GetMappingSize());
64 ASSERT_EQ(target->GetFDAt(0), raw_fd); 66 ASSERT_EQ(target->GetFDAt(0), raw_fd);
65 ASSERT_EQ(target->GetIDAt(0), testingId); 67 ASSERT_EQ(target->GetIDAt(0), testingId);
66 68
67 target.reset(); 69 target.reset();
68 70
69 ASSERT_TRUE(!VerifyClosed(fd.release())); 71 ASSERT_TRUE(!VerifyClosed(fd.release()));
70 } 72 }
71 73
72 TEST_F(FileDescriptorInfoTest, GetMappingWithIDAdjustment) { 74 TEST_F(PosixFileDescriptorInfoTest, GetMappingWithIDAdjustment) {
73 int testingId1 = 42; 75 int testingId1 = 42;
74 int testingId2 = 43; 76 int testingId2 = 43;
75 std::unique_ptr<FileDescriptorInfo> target(FileDescriptorInfoImpl::Create()); 77 std::unique_ptr<PosixFileDescriptorInfo> target(
78 PosixFileDescriptorInfoImpl::Create());
76 79
77 target->Transfer(testingId1, base::ScopedFD(GetSafeFd())); 80 target->Transfer(testingId1, base::ScopedFD(GetSafeFd()));
78 target->Transfer(testingId2, base::ScopedFD(GetSafeFd())); 81 target->Transfer(testingId2, base::ScopedFD(GetSafeFd()));
79 82
80 std::unique_ptr<base::FileHandleMappingVector> mapping = 83 base::FileHandleMappingVector mapping =
81 target->GetMappingWithIDAdjustment(100); 84 target->GetMappingWithIDAdjustment(100);
82 ASSERT_EQ((*mapping)[0].second, 142); 85 ASSERT_EQ(mapping[0].second, 142);
83 ASSERT_EQ((*mapping)[1].second, 143); 86 ASSERT_EQ(mapping[1].second, 143);
84 } 87 }
85 88
86 } // namespace content 89 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698