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/test_file_system_context.h" | 12 #include "content/public/test/test_file_system_context.h" |
13 #include "content/public/test/test_file_system_options.h" | 13 #include "content/public/test/test_file_system_options.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
15 #include "webkit/browser/fileapi/async_file_test_helper.h" | 15 #include "webkit/browser/fileapi/async_file_test_helper.h" |
16 #include "webkit/browser/fileapi/file_system_context.h" | 16 #include "webkit/browser/fileapi/file_system_context.h" |
17 #include "webkit/browser/fileapi/isolated_context.h" | 17 #include "webkit/browser/fileapi/isolated_context.h" |
18 #include "webkit/browser/fileapi/obfuscated_file_util.h" | 18 #include "webkit/browser/fileapi/obfuscated_file_util.h" |
19 #include "webkit/browser/fileapi/plugin_private_file_system_backend.h" | 19 #include "webkit/browser/fileapi/plugin_private_file_system_backend.h" |
20 #include "webkit/common/fileapi/file_system_util.h" | 20 #include "webkit/common/fileapi/file_system_util.h" |
21 | 21 |
22 namespace fileapi { | 22 using fileapi::AsyncFileTestHelper; |
| 23 using fileapi::FileSystemContext; |
| 24 using fileapi::FileSystemURL; |
| 25 using fileapi::IsolatedContext; |
| 26 |
| 27 namespace content { |
23 | 28 |
24 namespace { | 29 namespace { |
25 | 30 |
26 const GURL kOrigin("http://www.example.com"); | 31 const GURL kOrigin("http://www.example.com"); |
27 const std::string kPlugin1("plugin1"); | 32 const std::string kPlugin1("plugin1"); |
28 const std::string kPlugin2("plugin2"); | 33 const std::string kPlugin2("plugin2"); |
29 const FileSystemType kType = kFileSystemTypePluginPrivate; | 34 const fileapi::FileSystemType kType = fileapi::kFileSystemTypePluginPrivate; |
30 const std::string kRootName = "pluginprivate"; | 35 const std::string kRootName = "pluginprivate"; |
31 | 36 |
32 void DidOpenFileSystem(base::PlatformFileError* error_out, | 37 void DidOpenFileSystem(base::PlatformFileError* error_out, |
33 base::PlatformFileError error) { | 38 base::PlatformFileError error) { |
34 *error_out = error; | 39 *error_out = error; |
35 } | 40 } |
36 | 41 |
37 std::string RegisterFileSystem() { | 42 std::string RegisterFileSystem() { |
38 return IsolatedContext::GetInstance()->RegisterFileSystemForVirtualPath( | 43 return IsolatedContext::GetInstance()->RegisterFileSystemForVirtualPath( |
39 kType, kRootName, base::FilePath()); | 44 kType, kRootName, base::FilePath()); |
(...skipping 11 matching lines...) Expand all Loading... |
51 } | 56 } |
52 | 57 |
53 FileSystemURL CreateURL(const GURL& root_url, const std::string& relative) { | 58 FileSystemURL CreateURL(const GURL& root_url, const std::string& relative) { |
54 FileSystemURL root = context_->CrackURL(root_url); | 59 FileSystemURL root = context_->CrackURL(root_url); |
55 return context_->CreateCrackedFileSystemURL( | 60 return context_->CreateCrackedFileSystemURL( |
56 root.origin(), | 61 root.origin(), |
57 root.mount_type(), | 62 root.mount_type(), |
58 root.virtual_path().AppendASCII(relative)); | 63 root.virtual_path().AppendASCII(relative)); |
59 } | 64 } |
60 | 65 |
61 PluginPrivateFileSystemBackend* backend() const { | 66 fileapi::PluginPrivateFileSystemBackend* backend() const { |
62 return context_->plugin_private_backend(); | 67 return context_->plugin_private_backend(); |
63 } | 68 } |
64 | 69 |
65 const base::FilePath& base_path() const { return backend()->base_path(); } | 70 const base::FilePath& base_path() const { return backend()->base_path(); } |
66 | 71 |
67 base::ScopedTempDir data_dir_; | 72 base::ScopedTempDir data_dir_; |
68 base::MessageLoop message_loop_; | 73 base::MessageLoop message_loop_; |
69 scoped_refptr<FileSystemContext> context_; | 74 scoped_refptr<FileSystemContext> context_; |
70 std::string filesystem_id_; | 75 std::string filesystem_id_; |
71 }; | 76 }; |
72 | 77 |
73 TEST_F(PluginPrivateFileSystemBackendTest, OpenFileSystemBasic) { | 78 TEST_F(PluginPrivateFileSystemBackendTest, OpenFileSystemBasic) { |
74 const std::string filesystem_id1 = RegisterFileSystem(); | 79 const std::string filesystem_id1 = RegisterFileSystem(); |
75 base::PlatformFileError error = base::PLATFORM_FILE_ERROR_FAILED; | 80 base::PlatformFileError error = base::PLATFORM_FILE_ERROR_FAILED; |
76 backend()->OpenPrivateFileSystem( | 81 backend()->OpenPrivateFileSystem( |
77 kOrigin, kType, filesystem_id1, kPlugin1, | 82 kOrigin, kType, filesystem_id1, kPlugin1, |
78 OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, | 83 fileapi::OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, |
79 base::Bind(&DidOpenFileSystem, &error)); | 84 base::Bind(&DidOpenFileSystem, &error)); |
80 base::RunLoop().RunUntilIdle(); | 85 base::RunLoop().RunUntilIdle(); |
81 ASSERT_EQ(base::PLATFORM_FILE_OK, error); | 86 ASSERT_EQ(base::PLATFORM_FILE_OK, error); |
82 | 87 |
83 // 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. |
84 const std::string filesystem_id2 = RegisterFileSystem(); | 89 const std::string filesystem_id2 = RegisterFileSystem(); |
85 error = base::PLATFORM_FILE_ERROR_FAILED; | 90 error = base::PLATFORM_FILE_ERROR_FAILED; |
86 backend()->OpenPrivateFileSystem( | 91 backend()->OpenPrivateFileSystem( |
87 kOrigin, kType, filesystem_id2, kPlugin1, | 92 kOrigin, kType, filesystem_id2, kPlugin1, |
88 OPEN_FILE_SYSTEM_FAIL_IF_NONEXISTENT, | 93 fileapi::OPEN_FILE_SYSTEM_FAIL_IF_NONEXISTENT, |
89 base::Bind(&DidOpenFileSystem, &error)); | 94 base::Bind(&DidOpenFileSystem, &error)); |
90 base::RunLoop().RunUntilIdle(); | 95 base::RunLoop().RunUntilIdle(); |
91 ASSERT_EQ(base::PLATFORM_FILE_OK, error); | 96 ASSERT_EQ(base::PLATFORM_FILE_OK, error); |
92 | 97 |
93 const GURL root_url( | 98 const GURL root_url( |
94 GetIsolatedFileSystemRootURIString(kOrigin, filesystem_id1, kRootName)); | 99 fileapi::GetIsolatedFileSystemRootURIString( |
| 100 kOrigin, filesystem_id1, kRootName)); |
95 FileSystemURL file = CreateURL(root_url, "foo"); | 101 FileSystemURL file = CreateURL(root_url, "foo"); |
96 base::FilePath platform_path; | 102 base::FilePath platform_path; |
97 EXPECT_EQ(base::PLATFORM_FILE_OK, | 103 EXPECT_EQ(base::PLATFORM_FILE_OK, |
98 AsyncFileTestHelper::CreateFile(context_.get(), file)); | 104 AsyncFileTestHelper::CreateFile(context_.get(), file)); |
99 EXPECT_EQ(base::PLATFORM_FILE_OK, | 105 EXPECT_EQ(base::PLATFORM_FILE_OK, |
100 AsyncFileTestHelper::GetPlatformPath(context_.get(), file, | 106 AsyncFileTestHelper::GetPlatformPath(context_.get(), file, |
101 &platform_path)); | 107 &platform_path)); |
102 EXPECT_TRUE(base_path().AppendASCII("000").AppendASCII(kPlugin1).IsParent( | 108 EXPECT_TRUE(base_path().AppendASCII("000").AppendASCII(kPlugin1).IsParent( |
103 platform_path)); | 109 platform_path)); |
104 } | 110 } |
105 | 111 |
106 TEST_F(PluginPrivateFileSystemBackendTest, PluginIsolation) { | 112 TEST_F(PluginPrivateFileSystemBackendTest, PluginIsolation) { |
107 // Open filesystem for kPlugin1 and kPlugin2. | 113 // Open filesystem for kPlugin1 and kPlugin2. |
108 const std::string filesystem_id1 = RegisterFileSystem(); | 114 const std::string filesystem_id1 = RegisterFileSystem(); |
109 base::PlatformFileError error = base::PLATFORM_FILE_ERROR_FAILED; | 115 base::PlatformFileError error = base::PLATFORM_FILE_ERROR_FAILED; |
110 backend()->OpenPrivateFileSystem( | 116 backend()->OpenPrivateFileSystem( |
111 kOrigin, kType, filesystem_id1, kPlugin1, | 117 kOrigin, kType, filesystem_id1, kPlugin1, |
112 OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, | 118 fileapi::OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, |
113 base::Bind(&DidOpenFileSystem, &error)); | 119 base::Bind(&DidOpenFileSystem, &error)); |
114 base::RunLoop().RunUntilIdle(); | 120 base::RunLoop().RunUntilIdle(); |
115 ASSERT_EQ(base::PLATFORM_FILE_OK, error); | 121 ASSERT_EQ(base::PLATFORM_FILE_OK, error); |
116 | 122 |
117 const std::string filesystem_id2 = RegisterFileSystem(); | 123 const std::string filesystem_id2 = RegisterFileSystem(); |
118 error = base::PLATFORM_FILE_ERROR_FAILED; | 124 error = base::PLATFORM_FILE_ERROR_FAILED; |
119 backend()->OpenPrivateFileSystem( | 125 backend()->OpenPrivateFileSystem( |
120 kOrigin, kType, filesystem_id2, kPlugin2, | 126 kOrigin, kType, filesystem_id2, kPlugin2, |
121 OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, | 127 fileapi::OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, |
122 base::Bind(&DidOpenFileSystem, &error)); | 128 base::Bind(&DidOpenFileSystem, &error)); |
123 base::RunLoop().RunUntilIdle(); | 129 base::RunLoop().RunUntilIdle(); |
124 ASSERT_EQ(base::PLATFORM_FILE_OK, error); | 130 ASSERT_EQ(base::PLATFORM_FILE_OK, error); |
125 | 131 |
126 // Create 'foo' in kPlugin1. | 132 // Create 'foo' in kPlugin1. |
127 const GURL root_url1( | 133 const GURL root_url1( |
128 GetIsolatedFileSystemRootURIString(kOrigin, filesystem_id1, kRootName)); | 134 fileapi::GetIsolatedFileSystemRootURIString( |
| 135 kOrigin, filesystem_id1, kRootName)); |
129 FileSystemURL file1 = CreateURL(root_url1, "foo"); | 136 FileSystemURL file1 = CreateURL(root_url1, "foo"); |
130 base::FilePath platform_path; | 137 base::FilePath platform_path; |
131 EXPECT_EQ(base::PLATFORM_FILE_OK, | 138 EXPECT_EQ(base::PLATFORM_FILE_OK, |
132 AsyncFileTestHelper::CreateFile(context_.get(), file1)); | 139 AsyncFileTestHelper::CreateFile(context_.get(), file1)); |
133 EXPECT_TRUE(AsyncFileTestHelper::FileExists( | 140 EXPECT_TRUE(AsyncFileTestHelper::FileExists( |
134 context_.get(), file1, AsyncFileTestHelper::kDontCheckSize)); | 141 context_.get(), file1, AsyncFileTestHelper::kDontCheckSize)); |
135 | 142 |
136 // See the same path is not available in kPlugin2. | 143 // See the same path is not available in kPlugin2. |
137 const GURL root_url2( | 144 const GURL root_url2( |
138 GetIsolatedFileSystemRootURIString(kOrigin, filesystem_id2, kRootName)); | 145 fileapi::GetIsolatedFileSystemRootURIString( |
| 146 kOrigin, filesystem_id2, kRootName)); |
139 FileSystemURL file2 = CreateURL(root_url2, "foo"); | 147 FileSystemURL file2 = CreateURL(root_url2, "foo"); |
140 EXPECT_FALSE(AsyncFileTestHelper::FileExists( | 148 EXPECT_FALSE(AsyncFileTestHelper::FileExists( |
141 context_.get(), file2, AsyncFileTestHelper::kDontCheckSize)); | 149 context_.get(), file2, AsyncFileTestHelper::kDontCheckSize)); |
142 } | 150 } |
143 | 151 |
144 // TODO(kinuko,nhiroki): also test if DeleteOriginDataOnFileThread | 152 // TODO(kinuko,nhiroki): also test if DeleteOriginDataOnFileThread |
145 // works fine when there's multiple plugin partitions. | 153 // works fine when there's multiple plugin partitions. |
146 | 154 |
147 } // namespace fileapi | 155 } // namespace content |
OLD | NEW |