OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 <string.h> | 5 #include <string.h> |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <string> | 8 #include <string> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 18 matching lines...) Expand all Loading... |
29 namespace { | 29 namespace { |
30 | 30 |
31 // URL which returns a file descriptor of a regular file. | 31 // URL which returns a file descriptor of a regular file. |
32 constexpr char kArcUrlFile[] = "content://org.chromium.foo/file"; | 32 constexpr char kArcUrlFile[] = "content://org.chromium.foo/file"; |
33 | 33 |
34 // URL which returns a file descriptor of a pipe's read end. | 34 // URL which returns a file descriptor of a pipe's read end. |
35 constexpr char kArcUrlPipe[] = "content://org.chromium.foo/pipe"; | 35 constexpr char kArcUrlPipe[] = "content://org.chromium.foo/pipe"; |
36 | 36 |
37 constexpr char kData[] = "abcdefghijklmnopqrstuvwxyz"; | 37 constexpr char kData[] = "abcdefghijklmnopqrstuvwxyz"; |
38 | 38 |
| 39 constexpr char kMimeType[] = "application/octet-stream"; |
| 40 |
39 // Reads data from the reader to fill the buffer. | 41 // Reads data from the reader to fill the buffer. |
40 bool ReadData(ArcContentFileSystemFileStreamReader* reader, | 42 bool ReadData(ArcContentFileSystemFileStreamReader* reader, |
41 net::IOBufferWithSize* buffer) { | 43 net::IOBufferWithSize* buffer) { |
42 auto drainable_buffer = | 44 auto drainable_buffer = |
43 make_scoped_refptr(new net::DrainableIOBuffer(buffer, buffer->size())); | 45 make_scoped_refptr(new net::DrainableIOBuffer(buffer, buffer->size())); |
44 while (drainable_buffer->BytesRemaining()) { | 46 while (drainable_buffer->BytesRemaining()) { |
45 net::TestCompletionCallback callback; | 47 net::TestCompletionCallback callback; |
46 int result = callback.GetResult( | 48 int result = callback.GetResult( |
47 reader->Read(drainable_buffer.get(), drainable_buffer->BytesRemaining(), | 49 reader->Read(drainable_buffer.get(), drainable_buffer->BytesRemaining(), |
48 callback.callback())); | 50 callback.callback())); |
49 if (result < 0) { | 51 if (result < 0) { |
50 LOG(ERROR) << "Read failed: " << result; | 52 LOG(ERROR) << "Read failed: " << result; |
51 return false; | 53 return false; |
52 } | 54 } |
53 drainable_buffer->DidConsume(result); | 55 drainable_buffer->DidConsume(result); |
54 } | 56 } |
55 return true; | 57 return true; |
56 } | 58 } |
57 | 59 |
58 class ArcContentFileSystemFileStreamReaderTest : public testing::Test { | 60 class ArcContentFileSystemFileStreamReaderTest : public testing::Test { |
59 public: | 61 public: |
60 ArcContentFileSystemFileStreamReaderTest() = default; | 62 ArcContentFileSystemFileStreamReaderTest() = default; |
61 | 63 |
62 ~ArcContentFileSystemFileStreamReaderTest() override = default; | 64 ~ArcContentFileSystemFileStreamReaderTest() override = default; |
63 | 65 |
64 void SetUp() override { | 66 void SetUp() override { |
65 fake_file_system_.AddFile(File(kArcUrlFile, kData, File::Seekable::YES)); | 67 fake_file_system_.AddFile( |
66 fake_file_system_.AddFile(File(kArcUrlPipe, kData, File::Seekable::NO)); | 68 File(kArcUrlFile, kData, kMimeType, File::Seekable::YES)); |
| 69 fake_file_system_.AddFile( |
| 70 File(kArcUrlPipe, kData, kMimeType, File::Seekable::NO)); |
67 | 71 |
68 arc_service_manager_ = base::MakeUnique<ArcServiceManager>(nullptr); | 72 arc_service_manager_ = base::MakeUnique<ArcServiceManager>(nullptr); |
69 arc_service_manager_->AddService( | 73 arc_service_manager_->AddService( |
70 ArcFileSystemOperationRunner::CreateForTesting( | 74 ArcFileSystemOperationRunner::CreateForTesting( |
71 arc_service_manager_->arc_bridge_service())); | 75 arc_service_manager_->arc_bridge_service())); |
72 arc_service_manager_->arc_bridge_service()->file_system()->SetInstance( | 76 arc_service_manager_->arc_bridge_service()->file_system()->SetInstance( |
73 &fake_file_system_); | 77 &fake_file_system_); |
74 } | 78 } |
75 | 79 |
76 private: | 80 private: |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 | 125 |
122 TEST_F(ArcContentFileSystemFileStreamReaderTest, GetLength) { | 126 TEST_F(ArcContentFileSystemFileStreamReaderTest, GetLength) { |
123 ArcContentFileSystemFileStreamReader reader(GURL(kArcUrlFile), 0); | 127 ArcContentFileSystemFileStreamReader reader(GURL(kArcUrlFile), 0); |
124 | 128 |
125 net::TestInt64CompletionCallback callback; | 129 net::TestInt64CompletionCallback callback; |
126 EXPECT_EQ(static_cast<int64_t>(strlen(kData)), | 130 EXPECT_EQ(static_cast<int64_t>(strlen(kData)), |
127 callback.GetResult(reader.GetLength(callback.callback()))); | 131 callback.GetResult(reader.GetLength(callback.callback()))); |
128 } | 132 } |
129 | 133 |
130 } // namespace arc | 134 } // namespace arc |
OLD | NEW |