OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "components/filesystem/public/interfaces/file_system.mojom.h" | 5 #include "components/filesystem/public/interfaces/file_system.mojom.h" |
6 #include "mojo/application/public/cpp/application_impl.h" | 6 #include "mojo/application/public/cpp/application_impl.h" |
7 #include "mojo/application/public/cpp/application_test_base.h" | 7 #include "mojo/application/public/cpp/application_test_base.h" |
8 #include "mojo/util/capture_util.h" | 8 #include "mojo/util/capture_util.h" |
9 #include "sql/mojo/mojo_vfs.h" | 9 #include "sql/mojo/mojo_vfs.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 delete [] reinterpret_cast<uint8_t*>(ptr); | 23 delete [] reinterpret_cast<uint8_t*>(ptr); |
24 } | 24 } |
25 }; | 25 }; |
26 | 26 |
27 } // namespace base | 27 } // namespace base |
28 | 28 |
29 namespace sql { | 29 namespace sql { |
30 | 30 |
31 const char kFileName[] = "TestingDatabase.db"; | 31 const char kFileName[] = "TestingDatabase.db"; |
32 | 32 |
33 class VFSTest : public mojo::test::ApplicationTestBase { | 33 class VFSTest : public mojo::test::ApplicationTestBase, |
| 34 public filesystem::FileSystemClient { |
34 public: | 35 public: |
35 VFSTest() {} | 36 VFSTest() : binding_(this) {} |
36 ~VFSTest() override {} | 37 ~VFSTest() override {} |
37 | 38 |
38 sqlite3_vfs* vfs() { | 39 sqlite3_vfs* vfs() { |
39 return sqlite3_vfs_find(NULL); | 40 return sqlite3_vfs_find(NULL); |
40 } | 41 } |
41 | 42 |
42 scoped_ptr<sqlite3_file> MakeFile() { | 43 scoped_ptr<sqlite3_file> MakeFile() { |
43 return scoped_ptr<sqlite3_file>(reinterpret_cast<sqlite3_file*>( | 44 return scoped_ptr<sqlite3_file>(reinterpret_cast<sqlite3_file*>( |
44 new uint8_t[vfs()->szOsFile])); | 45 new uint8_t[vfs()->szOsFile])); |
45 } | 46 } |
46 | 47 |
47 void SetUp() override { | 48 void SetUp() override { |
48 mojo::test::ApplicationTestBase::SetUp(); | 49 mojo::test::ApplicationTestBase::SetUp(); |
49 | 50 |
50 mojo::URLRequestPtr request(mojo::URLRequest::New()); | 51 mojo::URLRequestPtr request(mojo::URLRequest::New()); |
51 request->url = mojo::String::From("mojo:filesystem"); | 52 request->url = mojo::String::From("mojo:filesystem"); |
52 application_impl()->ConnectToService(request.Pass(), &files_); | 53 application_impl()->ConnectToService(request.Pass(), &files_); |
53 | 54 |
| 55 filesystem::FileSystemClientPtr client; |
| 56 binding_.Bind(GetProxy(&client)); |
| 57 |
54 filesystem::FileError error = filesystem::FILE_ERROR_FAILED; | 58 filesystem::FileError error = filesystem::FILE_ERROR_FAILED; |
55 filesystem::DirectoryPtr directory; | 59 filesystem::DirectoryPtr directory; |
56 files_->OpenFileSystem("temp", GetProxy(&directory), mojo::Capture(&error)); | 60 files_->OpenFileSystem("temp", GetProxy(&directory), client.Pass(), |
| 61 mojo::Capture(&error)); |
57 ASSERT_TRUE(files_.WaitForIncomingResponse()); | 62 ASSERT_TRUE(files_.WaitForIncomingResponse()); |
58 ASSERT_EQ(filesystem::FILE_ERROR_OK, error); | 63 ASSERT_EQ(filesystem::FILE_ERROR_OK, error); |
59 | 64 |
60 vfs_.reset(new ScopedMojoFilesystemVFS(directory.Pass())); | 65 vfs_.reset(new ScopedMojoFilesystemVFS(directory.Pass())); |
61 } | 66 } |
62 | 67 |
63 void TearDown() override { | 68 void TearDown() override { |
64 vfs_.reset(); | 69 vfs_.reset(); |
65 mojo::test::ApplicationTestBase::TearDown(); | 70 mojo::test::ApplicationTestBase::TearDown(); |
66 } | 71 } |
67 | 72 |
| 73 void OnFileSystemShutdown() override { |
| 74 } |
| 75 |
68 private: | 76 private: |
69 filesystem::FileSystemPtr files_; | 77 filesystem::FileSystemPtr files_; |
70 scoped_ptr<ScopedMojoFilesystemVFS> vfs_; | 78 scoped_ptr<ScopedMojoFilesystemVFS> vfs_; |
| 79 mojo::Binding<filesystem::FileSystemClient> binding_; |
71 | 80 |
72 DISALLOW_COPY_AND_ASSIGN(VFSTest); | 81 DISALLOW_COPY_AND_ASSIGN(VFSTest); |
73 }; | 82 }; |
74 | 83 |
75 TEST_F(VFSTest, TestInstalled) { | 84 TEST_F(VFSTest, TestInstalled) { |
76 EXPECT_EQ("mojo", vfs()->zName); | 85 EXPECT_EQ("mojo", vfs()->zName); |
77 } | 86 } |
78 | 87 |
79 TEST_F(VFSTest, ExclusiveOpen) { | 88 TEST_F(VFSTest, ExclusiveOpen) { |
80 // Opening a non-existent file exclusively should work. | 89 // Opening a non-existent file exclusively should work. |
(...skipping 27 matching lines...) Expand all Loading... |
108 scoped_ptr<sqlite3_file> file2(MakeFile()); | 117 scoped_ptr<sqlite3_file> file2(MakeFile()); |
109 rc = vfs()->xOpen(vfs(), kFileName, file2.get(), | 118 rc = vfs()->xOpen(vfs(), kFileName, file2.get(), |
110 SQLITE_OPEN_CREATE | SQLITE_OPEN_READWRITE, | 119 SQLITE_OPEN_CREATE | SQLITE_OPEN_READWRITE, |
111 &out_flags); | 120 &out_flags); |
112 EXPECT_EQ(SQLITE_OK, rc); | 121 EXPECT_EQ(SQLITE_OK, rc); |
113 | 122 |
114 file->pMethods->xClose(file.get()); | 123 file->pMethods->xClose(file.get()); |
115 file->pMethods->xClose(file2.get()); | 124 file->pMethods->xClose(file2.get()); |
116 } | 125 } |
117 | 126 |
| 127 TEST_F(VFSTest, NullFilenameOpen) { |
| 128 // Opening a file with a null filename should return a valid file object. |
| 129 scoped_ptr<sqlite3_file> file(MakeFile()); |
| 130 int out_flags; |
| 131 int rc = vfs()->xOpen( |
| 132 vfs(), nullptr, file.get(), |
| 133 SQLITE_OPEN_DELETEONCLOSE | SQLITE_OPEN_CREATE | SQLITE_OPEN_READWRITE, |
| 134 &out_flags); |
| 135 EXPECT_EQ(SQLITE_OK, rc); |
| 136 |
| 137 file->pMethods->xClose(file.get()); |
| 138 } |
| 139 |
118 TEST_F(VFSTest, DeleteOnClose) { | 140 TEST_F(VFSTest, DeleteOnClose) { |
119 { | 141 { |
120 scoped_ptr<sqlite3_file> file(MakeFile()); | 142 scoped_ptr<sqlite3_file> file(MakeFile()); |
121 int out_flags; | 143 int out_flags; |
122 int rc = vfs()->xOpen( | 144 int rc = vfs()->xOpen( |
123 vfs(), kFileName, file.get(), | 145 vfs(), kFileName, file.get(), |
124 SQLITE_OPEN_DELETEONCLOSE | SQLITE_OPEN_CREATE | SQLITE_OPEN_READWRITE, | 146 SQLITE_OPEN_DELETEONCLOSE | SQLITE_OPEN_CREATE | SQLITE_OPEN_READWRITE, |
125 &out_flags); | 147 &out_flags); |
126 EXPECT_EQ(SQLITE_OK, rc); | 148 EXPECT_EQ(SQLITE_OK, rc); |
127 file->pMethods->xClose(file.get()); | 149 file->pMethods->xClose(file.get()); |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 EXPECT_EQ(SQLITE_OK, rc); | 330 EXPECT_EQ(SQLITE_OK, rc); |
309 | 331 |
310 rc = file->pMethods->xFileSize(file.get(), &size); | 332 rc = file->pMethods->xFileSize(file.get(), &size); |
311 EXPECT_EQ(SQLITE_OK, rc); | 333 EXPECT_EQ(SQLITE_OK, rc); |
312 EXPECT_EQ(kCharsToThree, size); | 334 EXPECT_EQ(kCharsToThree, size); |
313 | 335 |
314 file->pMethods->xClose(file.get()); | 336 file->pMethods->xClose(file.get()); |
315 } | 337 } |
316 | 338 |
317 } // namespace sql | 339 } // namespace sql |
OLD | NEW |