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" |
11 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
12 #include "content/public/test/async_file_test_helper.h" | 12 #include "content/public/test/async_file_test_helper.h" |
13 #include "content/public/test/test_file_system_context.h" | 13 #include "content/public/test/test_file_system_context.h" |
14 #include "content/public/test/test_file_system_options.h" | 14 #include "content/public/test/test_file_system_options.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
16 #include "webkit/browser/fileapi/file_system_context.h" | 16 #include "storage/browser/fileapi/file_system_context.h" |
17 #include "webkit/browser/fileapi/isolated_context.h" | 17 #include "storage/browser/fileapi/isolated_context.h" |
18 #include "webkit/browser/fileapi/obfuscated_file_util.h" | 18 #include "storage/browser/fileapi/obfuscated_file_util.h" |
19 #include "webkit/browser/fileapi/plugin_private_file_system_backend.h" | 19 #include "storage/browser/fileapi/plugin_private_file_system_backend.h" |
20 #include "webkit/common/fileapi/file_system_util.h" | 20 #include "storage/common/fileapi/file_system_util.h" |
21 | 21 |
22 using content::AsyncFileTestHelper; | 22 using content::AsyncFileTestHelper; |
23 using fileapi::FileSystemContext; | 23 using storage::FileSystemContext; |
24 using fileapi::FileSystemURL; | 24 using storage::FileSystemURL; |
25 using fileapi::IsolatedContext; | 25 using storage::IsolatedContext; |
26 | 26 |
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 storage::FileSystemType kType = storage::kFileSystemTypePluginPrivate; |
35 const std::string kRootName = "pluginprivate"; | 35 const std::string kRootName = "pluginprivate"; |
36 | 36 |
37 void DidOpenFileSystem(base::File::Error* error_out, | 37 void DidOpenFileSystem(base::File::Error* error_out, |
38 base::File::Error 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()); |
(...skipping 11 matching lines...) Expand all Loading... |
56 } | 56 } |
57 | 57 |
58 FileSystemURL CreateURL(const GURL& root_url, const std::string& relative) { | 58 FileSystemURL CreateURL(const GURL& root_url, const std::string& relative) { |
59 FileSystemURL root = context_->CrackURL(root_url); | 59 FileSystemURL root = context_->CrackURL(root_url); |
60 return context_->CreateCrackedFileSystemURL( | 60 return context_->CreateCrackedFileSystemURL( |
61 root.origin(), | 61 root.origin(), |
62 root.mount_type(), | 62 root.mount_type(), |
63 root.virtual_path().AppendASCII(relative)); | 63 root.virtual_path().AppendASCII(relative)); |
64 } | 64 } |
65 | 65 |
66 fileapi::PluginPrivateFileSystemBackend* backend() const { | 66 storage::PluginPrivateFileSystemBackend* backend() const { |
67 return context_->plugin_private_backend(); | 67 return context_->plugin_private_backend(); |
68 } | 68 } |
69 | 69 |
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::File::Error error = base::File::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, |
83 fileapi::OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, | 83 kType, |
| 84 filesystem_id1, |
| 85 kPlugin1, |
| 86 storage::OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, |
84 base::Bind(&DidOpenFileSystem, &error)); | 87 base::Bind(&DidOpenFileSystem, &error)); |
85 base::RunLoop().RunUntilIdle(); | 88 base::RunLoop().RunUntilIdle(); |
86 ASSERT_EQ(base::File::FILE_OK, error); | 89 ASSERT_EQ(base::File::FILE_OK, error); |
87 | 90 |
88 // Run this again with FAIL_IF_NONEXISTENT to see if it succeeds. | 91 // Run this again with FAIL_IF_NONEXISTENT to see if it succeeds. |
89 const std::string filesystem_id2 = RegisterFileSystem(); | 92 const std::string filesystem_id2 = RegisterFileSystem(); |
90 error = base::File::FILE_ERROR_FAILED; | 93 error = base::File::FILE_ERROR_FAILED; |
91 backend()->OpenPrivateFileSystem( | 94 backend()->OpenPrivateFileSystem( |
92 kOrigin, kType, filesystem_id2, kPlugin1, | 95 kOrigin, |
93 fileapi::OPEN_FILE_SYSTEM_FAIL_IF_NONEXISTENT, | 96 kType, |
| 97 filesystem_id2, |
| 98 kPlugin1, |
| 99 storage::OPEN_FILE_SYSTEM_FAIL_IF_NONEXISTENT, |
94 base::Bind(&DidOpenFileSystem, &error)); | 100 base::Bind(&DidOpenFileSystem, &error)); |
95 base::RunLoop().RunUntilIdle(); | 101 base::RunLoop().RunUntilIdle(); |
96 ASSERT_EQ(base::File::FILE_OK, error); | 102 ASSERT_EQ(base::File::FILE_OK, error); |
97 | 103 |
98 const GURL root_url( | 104 const GURL root_url(storage::GetIsolatedFileSystemRootURIString( |
99 fileapi::GetIsolatedFileSystemRootURIString( | 105 kOrigin, filesystem_id1, kRootName)); |
100 kOrigin, filesystem_id1, kRootName)); | |
101 FileSystemURL file = CreateURL(root_url, "foo"); | 106 FileSystemURL file = CreateURL(root_url, "foo"); |
102 base::FilePath platform_path; | 107 base::FilePath platform_path; |
103 EXPECT_EQ(base::File::FILE_OK, | 108 EXPECT_EQ(base::File::FILE_OK, |
104 AsyncFileTestHelper::CreateFile(context_.get(), file)); | 109 AsyncFileTestHelper::CreateFile(context_.get(), file)); |
105 EXPECT_EQ(base::File::FILE_OK, | 110 EXPECT_EQ(base::File::FILE_OK, |
106 AsyncFileTestHelper::GetPlatformPath(context_.get(), file, | 111 AsyncFileTestHelper::GetPlatformPath(context_.get(), file, |
107 &platform_path)); | 112 &platform_path)); |
108 EXPECT_TRUE(base_path().AppendASCII("000").AppendASCII(kPlugin1).IsParent( | 113 EXPECT_TRUE(base_path().AppendASCII("000").AppendASCII(kPlugin1).IsParent( |
109 platform_path)); | 114 platform_path)); |
110 } | 115 } |
111 | 116 |
112 TEST_F(PluginPrivateFileSystemBackendTest, PluginIsolation) { | 117 TEST_F(PluginPrivateFileSystemBackendTest, PluginIsolation) { |
113 // Open filesystem for kPlugin1 and kPlugin2. | 118 // Open filesystem for kPlugin1 and kPlugin2. |
114 const std::string filesystem_id1 = RegisterFileSystem(); | 119 const std::string filesystem_id1 = RegisterFileSystem(); |
115 base::File::Error error = base::File::FILE_ERROR_FAILED; | 120 base::File::Error error = base::File::FILE_ERROR_FAILED; |
116 backend()->OpenPrivateFileSystem( | 121 backend()->OpenPrivateFileSystem( |
117 kOrigin, kType, filesystem_id1, kPlugin1, | 122 kOrigin, |
118 fileapi::OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, | 123 kType, |
| 124 filesystem_id1, |
| 125 kPlugin1, |
| 126 storage::OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, |
119 base::Bind(&DidOpenFileSystem, &error)); | 127 base::Bind(&DidOpenFileSystem, &error)); |
120 base::RunLoop().RunUntilIdle(); | 128 base::RunLoop().RunUntilIdle(); |
121 ASSERT_EQ(base::File::FILE_OK, error); | 129 ASSERT_EQ(base::File::FILE_OK, error); |
122 | 130 |
123 const std::string filesystem_id2 = RegisterFileSystem(); | 131 const std::string filesystem_id2 = RegisterFileSystem(); |
124 error = base::File::FILE_ERROR_FAILED; | 132 error = base::File::FILE_ERROR_FAILED; |
125 backend()->OpenPrivateFileSystem( | 133 backend()->OpenPrivateFileSystem( |
126 kOrigin, kType, filesystem_id2, kPlugin2, | 134 kOrigin, |
127 fileapi::OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, | 135 kType, |
| 136 filesystem_id2, |
| 137 kPlugin2, |
| 138 storage::OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, |
128 base::Bind(&DidOpenFileSystem, &error)); | 139 base::Bind(&DidOpenFileSystem, &error)); |
129 base::RunLoop().RunUntilIdle(); | 140 base::RunLoop().RunUntilIdle(); |
130 ASSERT_EQ(base::File::FILE_OK, error); | 141 ASSERT_EQ(base::File::FILE_OK, error); |
131 | 142 |
132 // Create 'foo' in kPlugin1. | 143 // Create 'foo' in kPlugin1. |
133 const GURL root_url1( | 144 const GURL root_url1(storage::GetIsolatedFileSystemRootURIString( |
134 fileapi::GetIsolatedFileSystemRootURIString( | 145 kOrigin, filesystem_id1, kRootName)); |
135 kOrigin, filesystem_id1, kRootName)); | |
136 FileSystemURL file1 = CreateURL(root_url1, "foo"); | 146 FileSystemURL file1 = CreateURL(root_url1, "foo"); |
137 base::FilePath platform_path; | 147 base::FilePath platform_path; |
138 EXPECT_EQ(base::File::FILE_OK, | 148 EXPECT_EQ(base::File::FILE_OK, |
139 AsyncFileTestHelper::CreateFile(context_.get(), file1)); | 149 AsyncFileTestHelper::CreateFile(context_.get(), file1)); |
140 EXPECT_TRUE(AsyncFileTestHelper::FileExists( | 150 EXPECT_TRUE(AsyncFileTestHelper::FileExists( |
141 context_.get(), file1, AsyncFileTestHelper::kDontCheckSize)); | 151 context_.get(), file1, AsyncFileTestHelper::kDontCheckSize)); |
142 | 152 |
143 // See the same path is not available in kPlugin2. | 153 // See the same path is not available in kPlugin2. |
144 const GURL root_url2( | 154 const GURL root_url2(storage::GetIsolatedFileSystemRootURIString( |
145 fileapi::GetIsolatedFileSystemRootURIString( | 155 kOrigin, filesystem_id2, kRootName)); |
146 kOrigin, filesystem_id2, kRootName)); | |
147 FileSystemURL file2 = CreateURL(root_url2, "foo"); | 156 FileSystemURL file2 = CreateURL(root_url2, "foo"); |
148 EXPECT_FALSE(AsyncFileTestHelper::FileExists( | 157 EXPECT_FALSE(AsyncFileTestHelper::FileExists( |
149 context_.get(), file2, AsyncFileTestHelper::kDontCheckSize)); | 158 context_.get(), file2, AsyncFileTestHelper::kDontCheckSize)); |
150 } | 159 } |
151 | 160 |
152 // TODO(kinuko,nhiroki): also test if DeleteOriginDataOnFileThread | 161 // TODO(kinuko,nhiroki): also test if DeleteOriginDataOnFileThread |
153 // works fine when there's multiple plugin partitions. | 162 // works fine when there's multiple plugin partitions. |
154 | 163 |
155 } // namespace content | 164 } // namespace content |
OLD | NEW |