OLD | NEW |
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/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 |
(...skipping 21 matching lines...) Expand all Loading... |
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 FileDescriptorInfoTest; |
39 | 39 |
40 TEST_F(FileDescriptorInfoTest, Transfer) { | 40 TEST_F(FileDescriptorInfoTest, Transfer) { |
41 int testingId = 42; | 41 int testingId = 42; |
42 scoped_ptr<FileDescriptorInfo> target(FileDescriptorInfoImpl::Create()); | 42 std::unique_ptr<FileDescriptorInfo> target(FileDescriptorInfoImpl::Create()); |
43 base::ScopedFD fd(GetSafeFd()); | 43 base::ScopedFD fd(GetSafeFd()); |
44 | 44 |
45 int raw_fd = fd.get(); | 45 int raw_fd = fd.get(); |
46 target->Transfer(testingId, std::move(fd)); | 46 target->Transfer(testingId, std::move(fd)); |
47 ASSERT_EQ(1U, target->GetMappingSize()); | 47 ASSERT_EQ(1U, target->GetMappingSize()); |
48 ASSERT_EQ(target->GetFDAt(0), raw_fd); | 48 ASSERT_EQ(target->GetFDAt(0), raw_fd); |
49 ASSERT_EQ(target->GetIDAt(0), testingId); | 49 ASSERT_EQ(target->GetIDAt(0), testingId); |
50 | 50 |
51 target.reset(); | 51 target.reset(); |
52 | 52 |
53 ASSERT_TRUE(VerifyClosed(raw_fd)); | 53 ASSERT_TRUE(VerifyClosed(raw_fd)); |
54 } | 54 } |
55 | 55 |
56 TEST_F(FileDescriptorInfoTest, Share) { | 56 TEST_F(FileDescriptorInfoTest, Share) { |
57 int testingId = 42; | 57 int testingId = 42; |
58 scoped_ptr<FileDescriptorInfo> target(FileDescriptorInfoImpl::Create()); | 58 std::unique_ptr<FileDescriptorInfo> target(FileDescriptorInfoImpl::Create()); |
59 base::ScopedFD fd(GetSafeFd()); | 59 base::ScopedFD fd(GetSafeFd()); |
60 | 60 |
61 int raw_fd = fd.get(); | 61 int raw_fd = fd.get(); |
62 target->Share(testingId, fd.get()); | 62 target->Share(testingId, fd.get()); |
63 ASSERT_EQ(1U, target->GetMappingSize()); | 63 ASSERT_EQ(1U, target->GetMappingSize()); |
64 ASSERT_EQ(target->GetFDAt(0), raw_fd); | 64 ASSERT_EQ(target->GetFDAt(0), raw_fd); |
65 ASSERT_EQ(target->GetIDAt(0), testingId); | 65 ASSERT_EQ(target->GetIDAt(0), testingId); |
66 | 66 |
67 target.reset(); | 67 target.reset(); |
68 | 68 |
69 ASSERT_TRUE(!VerifyClosed(fd.release())); | 69 ASSERT_TRUE(!VerifyClosed(fd.release())); |
70 } | 70 } |
71 | 71 |
72 TEST_F(FileDescriptorInfoTest, GetMappingWithIDAdjustment) { | 72 TEST_F(FileDescriptorInfoTest, GetMappingWithIDAdjustment) { |
73 int testingId1 = 42; | 73 int testingId1 = 42; |
74 int testingId2 = 43; | 74 int testingId2 = 43; |
75 scoped_ptr<FileDescriptorInfo> target(FileDescriptorInfoImpl::Create()); | 75 std::unique_ptr<FileDescriptorInfo> target(FileDescriptorInfoImpl::Create()); |
76 | 76 |
77 target->Transfer(testingId1, base::ScopedFD(GetSafeFd())); | 77 target->Transfer(testingId1, base::ScopedFD(GetSafeFd())); |
78 target->Transfer(testingId2, base::ScopedFD(GetSafeFd())); | 78 target->Transfer(testingId2, base::ScopedFD(GetSafeFd())); |
79 | 79 |
80 base::FileHandleMappingVector mapping = | 80 base::FileHandleMappingVector mapping = |
81 target->GetMappingWithIDAdjustment(100); | 81 target->GetMappingWithIDAdjustment(100); |
82 ASSERT_EQ(mapping[0].second, 142); | 82 ASSERT_EQ(mapping[0].second, 142); |
83 ASSERT_EQ(mapping[1].second, 143); | 83 ASSERT_EQ(mapping[1].second, 143); |
84 } | 84 } |
85 | 85 |
86 } // namespace content | 86 } // namespace content |
OLD | NEW |