Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(462)

Side by Side Diff: chrome/browser/media_galleries/fileapi/media_file_validator_browsertest.cc

Issue 442383002: Move storage-related files from webkit/ to new top-level directory storage/ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/bind.h" 6 #include "base/bind.h"
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/files/scoped_temp_dir.h" 9 #include "base/files/scoped_temp_dir.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
11 #include "base/message_loop/message_loop_proxy.h" 11 #include "base/message_loop/message_loop_proxy.h"
12 #include "base/path_service.h" 12 #include "base/path_service.h"
13 #include "chrome/browser/media_galleries/fileapi/media_file_system_backend.h" 13 #include "chrome/browser/media_galleries/fileapi/media_file_system_backend.h"
14 #include "chrome/test/base/in_process_browser_test.h" 14 #include "chrome/test/base/in_process_browser_test.h"
15 #include "content/public/test/browser_test.h" 15 #include "content/public/test/browser_test.h"
16 #include "content/public/test/test_file_system_backend.h" 16 #include "content/public/test/test_file_system_backend.h"
17 #include "content/public/test/test_file_system_context.h" 17 #include "content/public/test/test_file_system_context.h"
18 #include "content/public/test/test_utils.h" 18 #include "content/public/test/test_utils.h"
19 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
20 #include "webkit/browser/fileapi/copy_or_move_file_validator.h" 20 #include "storage/browser/fileapi/copy_or_move_file_validator.h"
21 #include "webkit/browser/fileapi/file_system_backend.h" 21 #include "storage/browser/fileapi/file_system_backend.h"
22 #include "webkit/browser/fileapi/file_system_context.h" 22 #include "storage/browser/fileapi/file_system_context.h"
23 #include "webkit/browser/fileapi/file_system_operation_runner.h" 23 #include "storage/browser/fileapi/file_system_operation_runner.h"
24 #include "webkit/browser/fileapi/file_system_url.h" 24 #include "storage/browser/fileapi/file_system_url.h"
25 #include "webkit/browser/fileapi/isolated_context.h" 25 #include "storage/browser/fileapi/isolated_context.h"
26 #include "webkit/common/fileapi/file_system_types.h" 26 #include "storage/common/fileapi/file_system_types.h"
27 27
28 namespace { 28 namespace {
29 29
30 const char kOrigin[] = "http://foo"; 30 const char kOrigin[] = "http://foo";
31 31
32 const char kValidImage[] = "RIFF0\0\0\0WEBPVP8 $\0\0\0\xB2\x02\0\x9D\x01\x2A" 32 const char kValidImage[] = "RIFF0\0\0\0WEBPVP8 $\0\0\0\xB2\x02\0\x9D\x01\x2A"
33 "\x01\0\x01\0\x2F\x9D\xCE\xE7s\xA8((((\x01\x9CK(\0" 33 "\x01\0\x01\0\x2F\x9D\xCE\xE7s\xA8((((\x01\x9CK(\0"
34 "\x05\xCE\xB3l\0\0\xFE\xD8\x80\0\0"; 34 "\x05\xCE\xB3l\0\0\xFE\xD8\x80\0\0";
35 35
36 const char kInvalidMediaFile[] = "Not a media file"; 36 const char kInvalidMediaFile[] = "Not a media file";
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 private: 100 private:
101 // Create the test files, filesystem objects, etc. 101 // Create the test files, filesystem objects, etc.
102 void SetupOnFileThread(const std::string& filename, 102 void SetupOnFileThread(const std::string& filename,
103 const std::string& content, 103 const std::string& content,
104 bool expected_result) { 104 bool expected_result) {
105 ASSERT_TRUE(base_dir_.CreateUniqueTempDir()); 105 ASSERT_TRUE(base_dir_.CreateUniqueTempDir());
106 base::FilePath base = base_dir_.path(); 106 base::FilePath base = base_dir_.path();
107 base::FilePath src_path = base.AppendASCII("src_fs"); 107 base::FilePath src_path = base.AppendASCII("src_fs");
108 ASSERT_TRUE(base::CreateDirectory(src_path)); 108 ASSERT_TRUE(base::CreateDirectory(src_path));
109 109
110 ScopedVector<fileapi::FileSystemBackend> additional_providers; 110 ScopedVector<storage::FileSystemBackend> additional_providers;
111 additional_providers.push_back(new content::TestFileSystemBackend( 111 additional_providers.push_back(new content::TestFileSystemBackend(
112 base::MessageLoopProxy::current().get(), src_path)); 112 base::MessageLoopProxy::current().get(), src_path));
113 additional_providers.push_back(new MediaFileSystemBackend( 113 additional_providers.push_back(new MediaFileSystemBackend(
114 base, base::MessageLoopProxy::current().get())); 114 base, base::MessageLoopProxy::current().get()));
115 file_system_context_ = 115 file_system_context_ =
116 content::CreateFileSystemContextWithAdditionalProvidersForTesting( 116 content::CreateFileSystemContextWithAdditionalProvidersForTesting(
117 NULL, additional_providers.Pass(), base); 117 NULL, additional_providers.Pass(), base);
118 118
119 move_src_ = file_system_context_->CreateCrackedFileSystemURL( 119 move_src_ = file_system_context_->CreateCrackedFileSystemURL(
120 GURL(kOrigin), fileapi::kFileSystemTypeTest, 120 GURL(kOrigin),
121 storage::kFileSystemTypeTest,
121 base::FilePath::FromUTF8Unsafe(filename)); 122 base::FilePath::FromUTF8Unsafe(filename));
122 123
123 test_file_size_ = content.size(); 124 test_file_size_ = content.size();
124 base::FilePath test_file = src_path.AppendASCII(filename); 125 base::FilePath test_file = src_path.AppendASCII(filename);
125 ASSERT_EQ(test_file_size_, 126 ASSERT_EQ(test_file_size_,
126 base::WriteFile(test_file, content.data(), test_file_size_)); 127 base::WriteFile(test_file, content.data(), test_file_size_));
127 128
128 base::FilePath dest_path = base.AppendASCII("dest_fs"); 129 base::FilePath dest_path = base.AppendASCII("dest_fs");
129 ASSERT_TRUE(base::CreateDirectory(dest_path)); 130 ASSERT_TRUE(base::CreateDirectory(dest_path));
130 std::string dest_fsid = 131 std::string dest_fsid =
131 fileapi::IsolatedContext::GetInstance()->RegisterFileSystemForPath( 132 storage::IsolatedContext::GetInstance()->RegisterFileSystemForPath(
132 fileapi::kFileSystemTypeNativeMedia, std::string(), dest_path, 133 storage::kFileSystemTypeNativeMedia,
134 std::string(),
135 dest_path,
133 NULL); 136 NULL);
134 137
135 size_t extension_index = filename.find_last_of("."); 138 size_t extension_index = filename.find_last_of(".");
136 ASSERT_NE(std::string::npos, extension_index); 139 ASSERT_NE(std::string::npos, extension_index);
137 std::string extension = filename.substr(extension_index); 140 std::string extension = filename.substr(extension_index);
138 std::string dest_root_fs_url = fileapi::GetIsolatedFileSystemRootURIString( 141 std::string dest_root_fs_url = storage::GetIsolatedFileSystemRootURIString(
139 GURL(kOrigin), dest_fsid, "dest_fs/"); 142 GURL(kOrigin), dest_fsid, "dest_fs/");
140 move_dest_ = file_system_context_->CrackURL(GURL( 143 move_dest_ = file_system_context_->CrackURL(GURL(
141 dest_root_fs_url + "move_dest" + extension)); 144 dest_root_fs_url + "move_dest" + extension));
142 145
143 content::BrowserThread::PostTask( 146 content::BrowserThread::PostTask(
144 content::BrowserThread::IO, 147 content::BrowserThread::IO,
145 FROM_HERE, 148 FROM_HERE,
146 base::Bind(&MediaFileValidatorTest::CheckFiles, 149 base::Bind(&MediaFileValidatorTest::CheckFiles,
147 base::Unretained(this), true, 150 base::Unretained(this), true,
148 base::Bind(&MediaFileValidatorTest::OnTestFilesReady, 151 base::Bind(&MediaFileValidatorTest::OnTestFilesReady,
(...skipping 14 matching lines...) Expand all
163 void CheckFiles(bool src_expected, 166 void CheckFiles(bool src_expected,
164 const base::Callback<void(bool success)>& callback) { 167 const base::Callback<void(bool success)>& callback) {
165 CheckFile(move_src_, src_expected ? test_file_size_ : kNoFileSize, 168 CheckFile(move_src_, src_expected ? test_file_size_ : kNoFileSize,
166 base::Bind(&MediaFileValidatorTest::OnCheckFilesFirstResult, 169 base::Bind(&MediaFileValidatorTest::OnCheckFilesFirstResult,
167 base::Unretained(this), !src_expected, callback)); 170 base::Unretained(this), !src_expected, callback));
168 } 171 }
169 172
170 // Helper that checks a file has the |expected_size|, which may be 173 // Helper that checks a file has the |expected_size|, which may be
171 // |kNoFileSize| if the file should not exist. |callback| is called 174 // |kNoFileSize| if the file should not exist. |callback| is called
172 // with success/failure. 175 // with success/failure.
173 void CheckFile(fileapi::FileSystemURL url, 176 void CheckFile(storage::FileSystemURL url,
174 int64 expected_size, 177 int64 expected_size,
175 const base::Callback<void(bool success)>& callback) { 178 const base::Callback<void(bool success)>& callback) {
176 operation_runner()->GetMetadata(url, 179 operation_runner()->GetMetadata(url,
177 base::Bind(&HandleCheckFileResult, 180 base::Bind(&HandleCheckFileResult,
178 expected_size, callback)); 181 expected_size, callback));
179 } 182 }
180 183
181 // Helper that checks the result of |move_src_| lookup and then checks 184 // Helper that checks the result of |move_src_| lookup and then checks
182 // |move_dest_| if all is as expected. 185 // |move_dest_| if all is as expected.
183 void OnCheckFilesFirstResult(bool dest_expected, 186 void OnCheckFilesFirstResult(bool dest_expected,
184 const base::Callback<void(bool)>& callback, 187 const base::Callback<void(bool)>& callback,
185 bool src_result) { 188 bool src_result) {
186 EXPECT_TRUE(src_result); 189 EXPECT_TRUE(src_result);
187 if (!src_result) { 190 if (!src_result) {
188 callback.Run(false); 191 callback.Run(false);
189 return; 192 return;
190 } 193 }
191 CheckFile(move_dest_, dest_expected ? test_file_size_ : kNoFileSize, 194 CheckFile(move_dest_, dest_expected ? test_file_size_ : kNoFileSize,
192 callback); 195 callback);
193 } 196 }
194 197
195 // Assert |test_files_ready| and then do the actual test of moving 198 // Assert |test_files_ready| and then do the actual test of moving
196 // |move_src_| to |move_dest_|. 199 // |move_src_| to |move_dest_|.
197 void OnTestFilesReady(bool expected_result, bool test_files_ready) { 200 void OnTestFilesReady(bool expected_result, bool test_files_ready) {
198 ASSERT_TRUE(test_files_ready); 201 ASSERT_TRUE(test_files_ready);
199 operation_runner()->Move( 202 operation_runner()->Move(move_src_,
200 move_src_, move_dest_, fileapi::FileSystemOperation::OPTION_NONE, 203 move_dest_,
201 base::Bind(&MediaFileValidatorTest::OnMoveResult, 204 storage::FileSystemOperation::OPTION_NONE,
202 base::Unretained(this), expected_result)); 205 base::Bind(&MediaFileValidatorTest::OnMoveResult,
206 base::Unretained(this),
207 expected_result));
203 } 208 }
204 209
205 // Check that the move succeeded/failed based on expectation and then 210 // Check that the move succeeded/failed based on expectation and then
206 // check that the right file exists. 211 // check that the right file exists.
207 void OnMoveResult(bool expected_result, base::File::Error result) { 212 void OnMoveResult(bool expected_result, base::File::Error result) {
208 if (expected_result) 213 if (expected_result)
209 EXPECT_EQ(base::File::FILE_OK, result); 214 EXPECT_EQ(base::File::FILE_OK, result);
210 else 215 else
211 EXPECT_EQ(base::File::FILE_ERROR_SECURITY, result); 216 EXPECT_EQ(base::File::FILE_ERROR_SECURITY, result);
212 CheckFiles(!expected_result, 217 CheckFiles(!expected_result,
213 base::Bind(&MediaFileValidatorTest::OnTestFilesCheckResult, 218 base::Bind(&MediaFileValidatorTest::OnTestFilesCheckResult,
214 base::Unretained(this))); 219 base::Unretained(this)));
215 } 220 }
216 221
217 // Check that the correct test file exists and then post the result back 222 // Check that the correct test file exists and then post the result back
218 // to the UI thread. 223 // to the UI thread.
219 void OnTestFilesCheckResult(bool result) { 224 void OnTestFilesCheckResult(bool result) {
220 EXPECT_TRUE(result); 225 EXPECT_TRUE(result);
221 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, 226 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE,
222 loop_runner_->QuitClosure()); 227 loop_runner_->QuitClosure());
223 } 228 }
224 229
225 fileapi::FileSystemOperationRunner* operation_runner() { 230 storage::FileSystemOperationRunner* operation_runner() {
226 return file_system_context_->operation_runner(); 231 return file_system_context_->operation_runner();
227 } 232 }
228 233
229 base::ScopedTempDir base_dir_; 234 base::ScopedTempDir base_dir_;
230 235
231 scoped_refptr<fileapi::FileSystemContext> file_system_context_; 236 scoped_refptr<storage::FileSystemContext> file_system_context_;
232 237
233 int test_file_size_; 238 int test_file_size_;
234 239
235 fileapi::FileSystemURL move_src_; 240 storage::FileSystemURL move_src_;
236 fileapi::FileSystemURL move_dest_; 241 storage::FileSystemURL move_dest_;
237 242
238 scoped_refptr<content::MessageLoopRunner> loop_runner_; 243 scoped_refptr<content::MessageLoopRunner> loop_runner_;
239 244
240 DISALLOW_COPY_AND_ASSIGN(MediaFileValidatorTest); 245 DISALLOW_COPY_AND_ASSIGN(MediaFileValidatorTest);
241 }; 246 };
242 247
243 IN_PROC_BROWSER_TEST_F(MediaFileValidatorTest, UnsupportedExtension) { 248 IN_PROC_BROWSER_TEST_F(MediaFileValidatorTest, UnsupportedExtension) {
244 MoveTest("a.txt", std::string(kValidImage, arraysize(kValidImage)), false); 249 MoveTest("a.txt", std::string(kValidImage, arraysize(kValidImage)), false);
245 } 250 }
246 251
(...skipping 24 matching lines...) Expand all
271 test_file = test_file.AppendASCII("no_streams.webm"); 276 test_file = test_file.AppendASCII("no_streams.webm");
272 MoveTestFromFile("no_streams.webm", test_file, false); 277 MoveTestFromFile("no_streams.webm", test_file, false);
273 } 278 }
274 279
275 IN_PROC_BROWSER_TEST_F(MediaFileValidatorTest, ValidVideo) { 280 IN_PROC_BROWSER_TEST_F(MediaFileValidatorTest, ValidVideo) {
276 base::FilePath test_file = GetMediaTestDir(); 281 base::FilePath test_file = GetMediaTestDir();
277 ASSERT_FALSE(test_file.empty()); 282 ASSERT_FALSE(test_file.empty());
278 test_file = test_file.AppendASCII("bear-320x240-multitrack.webm"); 283 test_file = test_file.AppendASCII("bear-320x240-multitrack.webm");
279 MoveTestFromFile("multitrack.webm", test_file, true); 284 MoveTestFromFile("multitrack.webm", test_file, true);
280 } 285 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698