| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
| 6 #include "base/file_util.h" | 6 #include "base/file_util.h" |
| 7 #include "base/files/scoped_temp_dir.h" | 7 #include "base/files/scoped_temp_dir.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/message_loop/message_loop_proxy.h" | 10 #include "base/message_loop/message_loop_proxy.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 namespace content { | 27 namespace content { |
| 28 | 28 |
| 29 namespace { | 29 namespace { |
| 30 | 30 |
| 31 const GURL kOrigin("http://www.example.com"); | 31 const GURL kOrigin("http://www.example.com"); |
| 32 const std::string kPlugin1("plugin1"); | 32 const std::string kPlugin1("plugin1"); |
| 33 const std::string kPlugin2("plugin2"); | 33 const std::string kPlugin2("plugin2"); |
| 34 const fileapi::FileSystemType kType = fileapi::kFileSystemTypePluginPrivate; | 34 const fileapi::FileSystemType kType = fileapi::kFileSystemTypePluginPrivate; |
| 35 const std::string kRootName = "pluginprivate"; | 35 const std::string kRootName = "pluginprivate"; |
| 36 | 36 |
| 37 void DidOpenFileSystem(base::PlatformFileError* error_out, | 37 void DidOpenFileSystem(base::File::Error* error_out, |
| 38 base::PlatformFileError error) { | 38 base::File::Error error) { |
| 39 *error_out = error; | 39 *error_out = error; |
| 40 } | 40 } |
| 41 | 41 |
| 42 std::string RegisterFileSystem() { | 42 std::string RegisterFileSystem() { |
| 43 return IsolatedContext::GetInstance()->RegisterFileSystemForVirtualPath( | 43 return IsolatedContext::GetInstance()->RegisterFileSystemForVirtualPath( |
| 44 kType, kRootName, base::FilePath()); | 44 kType, kRootName, base::FilePath()); |
| 45 } | 45 } |
| 46 | 46 |
| 47 } // namespace | 47 } // namespace |
| 48 | 48 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 70 const base::FilePath& base_path() const { return backend()->base_path(); } | 70 const base::FilePath& base_path() const { return backend()->base_path(); } |
| 71 | 71 |
| 72 base::ScopedTempDir data_dir_; | 72 base::ScopedTempDir data_dir_; |
| 73 base::MessageLoop message_loop_; | 73 base::MessageLoop message_loop_; |
| 74 scoped_refptr<FileSystemContext> context_; | 74 scoped_refptr<FileSystemContext> context_; |
| 75 std::string filesystem_id_; | 75 std::string filesystem_id_; |
| 76 }; | 76 }; |
| 77 | 77 |
| 78 TEST_F(PluginPrivateFileSystemBackendTest, OpenFileSystemBasic) { | 78 TEST_F(PluginPrivateFileSystemBackendTest, OpenFileSystemBasic) { |
| 79 const std::string filesystem_id1 = RegisterFileSystem(); | 79 const std::string filesystem_id1 = RegisterFileSystem(); |
| 80 base::PlatformFileError error = base::PLATFORM_FILE_ERROR_FAILED; | 80 base::File::Error error = base::File::FILE_ERROR_FAILED; |
| 81 backend()->OpenPrivateFileSystem( | 81 backend()->OpenPrivateFileSystem( |
| 82 kOrigin, kType, filesystem_id1, kPlugin1, | 82 kOrigin, kType, filesystem_id1, kPlugin1, |
| 83 fileapi::OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, | 83 fileapi::OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, |
| 84 base::Bind(&DidOpenFileSystem, &error)); | 84 base::Bind(&DidOpenFileSystem, &error)); |
| 85 base::RunLoop().RunUntilIdle(); | 85 base::RunLoop().RunUntilIdle(); |
| 86 ASSERT_EQ(base::PLATFORM_FILE_OK, error); | 86 ASSERT_EQ(base::File::FILE_OK, error); |
| 87 | 87 |
| 88 // Run this again with FAIL_IF_NONEXISTENT to see if it succeeds. | 88 // Run this again with FAIL_IF_NONEXISTENT to see if it succeeds. |
| 89 const std::string filesystem_id2 = RegisterFileSystem(); | 89 const std::string filesystem_id2 = RegisterFileSystem(); |
| 90 error = base::PLATFORM_FILE_ERROR_FAILED; | 90 error = base::File::FILE_ERROR_FAILED; |
| 91 backend()->OpenPrivateFileSystem( | 91 backend()->OpenPrivateFileSystem( |
| 92 kOrigin, kType, filesystem_id2, kPlugin1, | 92 kOrigin, kType, filesystem_id2, kPlugin1, |
| 93 fileapi::OPEN_FILE_SYSTEM_FAIL_IF_NONEXISTENT, | 93 fileapi::OPEN_FILE_SYSTEM_FAIL_IF_NONEXISTENT, |
| 94 base::Bind(&DidOpenFileSystem, &error)); | 94 base::Bind(&DidOpenFileSystem, &error)); |
| 95 base::RunLoop().RunUntilIdle(); | 95 base::RunLoop().RunUntilIdle(); |
| 96 ASSERT_EQ(base::PLATFORM_FILE_OK, error); | 96 ASSERT_EQ(base::File::FILE_OK, error); |
| 97 | 97 |
| 98 const GURL root_url( | 98 const GURL root_url( |
| 99 fileapi::GetIsolatedFileSystemRootURIString( | 99 fileapi::GetIsolatedFileSystemRootURIString( |
| 100 kOrigin, filesystem_id1, kRootName)); | 100 kOrigin, filesystem_id1, kRootName)); |
| 101 FileSystemURL file = CreateURL(root_url, "foo"); | 101 FileSystemURL file = CreateURL(root_url, "foo"); |
| 102 base::FilePath platform_path; | 102 base::FilePath platform_path; |
| 103 EXPECT_EQ(base::PLATFORM_FILE_OK, | 103 EXPECT_EQ(base::File::FILE_OK, |
| 104 AsyncFileTestHelper::CreateFile(context_.get(), file)); | 104 AsyncFileTestHelper::CreateFile(context_.get(), file)); |
| 105 EXPECT_EQ(base::PLATFORM_FILE_OK, | 105 EXPECT_EQ(base::File::FILE_OK, |
| 106 AsyncFileTestHelper::GetPlatformPath(context_.get(), file, | 106 AsyncFileTestHelper::GetPlatformPath(context_.get(), file, |
| 107 &platform_path)); | 107 &platform_path)); |
| 108 EXPECT_TRUE(base_path().AppendASCII("000").AppendASCII(kPlugin1).IsParent( | 108 EXPECT_TRUE(base_path().AppendASCII("000").AppendASCII(kPlugin1).IsParent( |
| 109 platform_path)); | 109 platform_path)); |
| 110 } | 110 } |
| 111 | 111 |
| 112 TEST_F(PluginPrivateFileSystemBackendTest, PluginIsolation) { | 112 TEST_F(PluginPrivateFileSystemBackendTest, PluginIsolation) { |
| 113 // Open filesystem for kPlugin1 and kPlugin2. | 113 // Open filesystem for kPlugin1 and kPlugin2. |
| 114 const std::string filesystem_id1 = RegisterFileSystem(); | 114 const std::string filesystem_id1 = RegisterFileSystem(); |
| 115 base::PlatformFileError error = base::PLATFORM_FILE_ERROR_FAILED; | 115 base::File::Error error = base::File::FILE_ERROR_FAILED; |
| 116 backend()->OpenPrivateFileSystem( | 116 backend()->OpenPrivateFileSystem( |
| 117 kOrigin, kType, filesystem_id1, kPlugin1, | 117 kOrigin, kType, filesystem_id1, kPlugin1, |
| 118 fileapi::OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, | 118 fileapi::OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, |
| 119 base::Bind(&DidOpenFileSystem, &error)); | 119 base::Bind(&DidOpenFileSystem, &error)); |
| 120 base::RunLoop().RunUntilIdle(); | 120 base::RunLoop().RunUntilIdle(); |
| 121 ASSERT_EQ(base::PLATFORM_FILE_OK, error); | 121 ASSERT_EQ(base::File::FILE_OK, error); |
| 122 | 122 |
| 123 const std::string filesystem_id2 = RegisterFileSystem(); | 123 const std::string filesystem_id2 = RegisterFileSystem(); |
| 124 error = base::PLATFORM_FILE_ERROR_FAILED; | 124 error = base::File::FILE_ERROR_FAILED; |
| 125 backend()->OpenPrivateFileSystem( | 125 backend()->OpenPrivateFileSystem( |
| 126 kOrigin, kType, filesystem_id2, kPlugin2, | 126 kOrigin, kType, filesystem_id2, kPlugin2, |
| 127 fileapi::OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, | 127 fileapi::OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, |
| 128 base::Bind(&DidOpenFileSystem, &error)); | 128 base::Bind(&DidOpenFileSystem, &error)); |
| 129 base::RunLoop().RunUntilIdle(); | 129 base::RunLoop().RunUntilIdle(); |
| 130 ASSERT_EQ(base::PLATFORM_FILE_OK, error); | 130 ASSERT_EQ(base::File::FILE_OK, error); |
| 131 | 131 |
| 132 // Create 'foo' in kPlugin1. | 132 // Create 'foo' in kPlugin1. |
| 133 const GURL root_url1( | 133 const GURL root_url1( |
| 134 fileapi::GetIsolatedFileSystemRootURIString( | 134 fileapi::GetIsolatedFileSystemRootURIString( |
| 135 kOrigin, filesystem_id1, kRootName)); | 135 kOrigin, filesystem_id1, kRootName)); |
| 136 FileSystemURL file1 = CreateURL(root_url1, "foo"); | 136 FileSystemURL file1 = CreateURL(root_url1, "foo"); |
| 137 base::FilePath platform_path; | 137 base::FilePath platform_path; |
| 138 EXPECT_EQ(base::PLATFORM_FILE_OK, | 138 EXPECT_EQ(base::File::FILE_OK, |
| 139 AsyncFileTestHelper::CreateFile(context_.get(), file1)); | 139 AsyncFileTestHelper::CreateFile(context_.get(), file1)); |
| 140 EXPECT_TRUE(AsyncFileTestHelper::FileExists( | 140 EXPECT_TRUE(AsyncFileTestHelper::FileExists( |
| 141 context_.get(), file1, AsyncFileTestHelper::kDontCheckSize)); | 141 context_.get(), file1, AsyncFileTestHelper::kDontCheckSize)); |
| 142 | 142 |
| 143 // See the same path is not available in kPlugin2. | 143 // See the same path is not available in kPlugin2. |
| 144 const GURL root_url2( | 144 const GURL root_url2( |
| 145 fileapi::GetIsolatedFileSystemRootURIString( | 145 fileapi::GetIsolatedFileSystemRootURIString( |
| 146 kOrigin, filesystem_id2, kRootName)); | 146 kOrigin, filesystem_id2, kRootName)); |
| 147 FileSystemURL file2 = CreateURL(root_url2, "foo"); | 147 FileSystemURL file2 = CreateURL(root_url2, "foo"); |
| 148 EXPECT_FALSE(AsyncFileTestHelper::FileExists( | 148 EXPECT_FALSE(AsyncFileTestHelper::FileExists( |
| 149 context_.get(), file2, AsyncFileTestHelper::kDontCheckSize)); | 149 context_.get(), file2, AsyncFileTestHelper::kDontCheckSize)); |
| 150 } | 150 } |
| 151 | 151 |
| 152 // TODO(kinuko,nhiroki): also test if DeleteOriginDataOnFileThread | 152 // TODO(kinuko,nhiroki): also test if DeleteOriginDataOnFileThread |
| 153 // works fine when there's multiple plugin partitions. | 153 // works fine when there's multiple plugin partitions. |
| 154 | 154 |
| 155 } // namespace content | 155 } // namespace content |
| OLD | NEW |