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

Side by Side Diff: chrome/browser/media_galleries/fileapi/native_media_file_util_unittest.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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <set> 5 #include <set>
6 #include <string> 6 #include <string>
7 7
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/files/scoped_temp_dir.h" 10 #include "base/files/scoped_temp_dir.h"
11 #include "base/format_macros.h" 11 #include "base/format_macros.h"
12 #include "base/message_loop/message_loop.h" 12 #include "base/message_loop/message_loop.h"
13 #include "base/message_loop/message_loop_proxy.h" 13 #include "base/message_loop/message_loop_proxy.h"
14 #include "base/strings/stringprintf.h" 14 #include "base/strings/stringprintf.h"
15 #include "base/time/time.h" 15 #include "base/time/time.h"
16 #include "chrome/browser/media_galleries/fileapi/media_file_system_backend.h" 16 #include "chrome/browser/media_galleries/fileapi/media_file_system_backend.h"
17 #include "chrome/browser/media_galleries/fileapi/native_media_file_util.h" 17 #include "chrome/browser/media_galleries/fileapi/native_media_file_util.h"
18 #include "content/public/test/mock_special_storage_policy.h" 18 #include "content/public/test/mock_special_storage_policy.h"
19 #include "content/public/test/test_browser_thread.h" 19 #include "content/public/test/test_browser_thread.h"
20 #include "content/public/test/test_file_system_options.h" 20 #include "content/public/test/test_file_system_options.h"
21 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
22 #include "webkit/browser/fileapi/external_mount_points.h" 22 #include "storage/browser/fileapi/external_mount_points.h"
23 #include "webkit/browser/fileapi/file_system_backend.h" 23 #include "storage/browser/fileapi/file_system_backend.h"
24 #include "webkit/browser/fileapi/file_system_context.h" 24 #include "storage/browser/fileapi/file_system_context.h"
25 #include "webkit/browser/fileapi/file_system_operation_runner.h" 25 #include "storage/browser/fileapi/file_system_operation_runner.h"
26 #include "webkit/browser/fileapi/file_system_url.h" 26 #include "storage/browser/fileapi/file_system_url.h"
27 #include "webkit/browser/fileapi/isolated_context.h" 27 #include "storage/browser/fileapi/isolated_context.h"
28 #include "webkit/browser/fileapi/native_file_util.h" 28 #include "storage/browser/fileapi/native_file_util.h"
29 29
30 #define FPL(x) FILE_PATH_LITERAL(x) 30 #define FPL(x) FILE_PATH_LITERAL(x)
31 31
32 using fileapi::FileSystemOperation; 32 using storage::FileSystemOperation;
33 using fileapi::FileSystemURL; 33 using storage::FileSystemURL;
34 34
35 namespace { 35 namespace {
36 36
37 typedef FileSystemOperation::FileEntryList FileEntryList; 37 typedef FileSystemOperation::FileEntryList FileEntryList;
38 38
39 struct FilteringTestCase { 39 struct FilteringTestCase {
40 const base::FilePath::CharType* path; 40 const base::FilePath::CharType* path;
41 bool is_directory; 41 bool is_directory;
42 bool visible; 42 bool visible;
43 bool media_file; 43 bool media_file;
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 : io_thread_(content::BrowserThread::IO, &message_loop_) { 115 : io_thread_(content::BrowserThread::IO, &message_loop_) {
116 } 116 }
117 117
118 virtual void SetUp() { 118 virtual void SetUp() {
119 ASSERT_TRUE(data_dir_.CreateUniqueTempDir()); 119 ASSERT_TRUE(data_dir_.CreateUniqueTempDir());
120 ASSERT_TRUE(base::CreateDirectory(root_path())); 120 ASSERT_TRUE(base::CreateDirectory(root_path()));
121 121
122 scoped_refptr<quota::SpecialStoragePolicy> storage_policy = 122 scoped_refptr<quota::SpecialStoragePolicy> storage_policy =
123 new content::MockSpecialStoragePolicy(); 123 new content::MockSpecialStoragePolicy();
124 124
125 ScopedVector<fileapi::FileSystemBackend> additional_providers; 125 ScopedVector<storage::FileSystemBackend> additional_providers;
126 additional_providers.push_back(new MediaFileSystemBackend( 126 additional_providers.push_back(new MediaFileSystemBackend(
127 data_dir_.path(), base::MessageLoopProxy::current().get())); 127 data_dir_.path(), base::MessageLoopProxy::current().get()));
128 128
129 file_system_context_ = new fileapi::FileSystemContext( 129 file_system_context_ = new storage::FileSystemContext(
130 base::MessageLoopProxy::current().get(), 130 base::MessageLoopProxy::current().get(),
131 base::MessageLoopProxy::current().get(), 131 base::MessageLoopProxy::current().get(),
132 fileapi::ExternalMountPoints::CreateRefCounted().get(), 132 storage::ExternalMountPoints::CreateRefCounted().get(),
133 storage_policy.get(), 133 storage_policy.get(),
134 NULL, 134 NULL,
135 additional_providers.Pass(), 135 additional_providers.Pass(),
136 std::vector<fileapi::URLRequestAutoMountHandler>(), 136 std::vector<storage::URLRequestAutoMountHandler>(),
137 data_dir_.path(), 137 data_dir_.path(),
138 content::CreateAllowFileAccessOptions()); 138 content::CreateAllowFileAccessOptions());
139 139
140 filesystem_id_ = isolated_context()->RegisterFileSystemForPath( 140 filesystem_id_ = isolated_context()->RegisterFileSystemForPath(
141 fileapi::kFileSystemTypeNativeMedia, std::string(), root_path(), NULL); 141 storage::kFileSystemTypeNativeMedia, std::string(), root_path(), NULL);
142 142
143 isolated_context()->AddReference(filesystem_id_); 143 isolated_context()->AddReference(filesystem_id_);
144 } 144 }
145 145
146 virtual void TearDown() { 146 virtual void TearDown() {
147 isolated_context()->RemoveReference(filesystem_id_); 147 isolated_context()->RemoveReference(filesystem_id_);
148 file_system_context_ = NULL; 148 file_system_context_ = NULL;
149 } 149 }
150 150
151 protected: 151 protected:
152 fileapi::FileSystemContext* file_system_context() { 152 storage::FileSystemContext* file_system_context() {
153 return file_system_context_.get(); 153 return file_system_context_.get();
154 } 154 }
155 155
156 FileSystemURL CreateURL(const base::FilePath::CharType* test_case_path) { 156 FileSystemURL CreateURL(const base::FilePath::CharType* test_case_path) {
157 return file_system_context_->CreateCrackedFileSystemURL( 157 return file_system_context_->CreateCrackedFileSystemURL(
158 origin(), 158 origin(),
159 fileapi::kFileSystemTypeIsolated, 159 storage::kFileSystemTypeIsolated,
160 GetVirtualPath(test_case_path)); 160 GetVirtualPath(test_case_path));
161 } 161 }
162 162
163 fileapi::IsolatedContext* isolated_context() { 163 storage::IsolatedContext* isolated_context() {
164 return fileapi::IsolatedContext::GetInstance(); 164 return storage::IsolatedContext::GetInstance();
165 } 165 }
166 166
167 base::FilePath root_path() { 167 base::FilePath root_path() {
168 return data_dir_.path().Append(FPL("Media Directory")); 168 return data_dir_.path().Append(FPL("Media Directory"));
169 } 169 }
170 170
171 base::FilePath GetVirtualPath( 171 base::FilePath GetVirtualPath(
172 const base::FilePath::CharType* test_case_path) { 172 const base::FilePath::CharType* test_case_path) {
173 return base::FilePath::FromUTF8Unsafe(filesystem_id_). 173 return base::FilePath::FromUTF8Unsafe(filesystem_id_).
174 Append(FPL("Media Directory")). 174 Append(FPL("Media Directory")).
175 Append(base::FilePath(test_case_path)); 175 Append(base::FilePath(test_case_path));
176 } 176 }
177 177
178 GURL origin() { 178 GURL origin() {
179 return GURL("http://example.com"); 179 return GURL("http://example.com");
180 } 180 }
181 181
182 fileapi::FileSystemType type() { 182 storage::FileSystemType type() { return storage::kFileSystemTypeNativeMedia; }
183 return fileapi::kFileSystemTypeNativeMedia;
184 }
185 183
186 fileapi::FileSystemOperationRunner* operation_runner() { 184 storage::FileSystemOperationRunner* operation_runner() {
187 return file_system_context_->operation_runner(); 185 return file_system_context_->operation_runner();
188 } 186 }
189 187
190 private: 188 private:
191 base::MessageLoop message_loop_; 189 base::MessageLoop message_loop_;
192 content::TestBrowserThread io_thread_; 190 content::TestBrowserThread io_thread_;
193 191
194 base::ScopedTempDir data_dir_; 192 base::ScopedTempDir data_dir_;
195 scoped_refptr<fileapi::FileSystemContext> file_system_context_; 193 scoped_refptr<storage::FileSystemContext> file_system_context_;
196 194
197 std::string filesystem_id_; 195 std::string filesystem_id_;
198 196
199 DISALLOW_COPY_AND_ASSIGN(NativeMediaFileUtilTest); 197 DISALLOW_COPY_AND_ASSIGN(NativeMediaFileUtilTest);
200 }; 198 };
201 199
202 TEST_F(NativeMediaFileUtilTest, DirectoryExistsAndFileExistsFiltering) { 200 TEST_F(NativeMediaFileUtilTest, DirectoryExistsAndFileExistsFiltering) {
203 PopulateDirectoryWithTestCases(root_path(), 201 PopulateDirectoryWithTestCases(root_path(),
204 kFilteringTestCases, 202 kFilteringTestCases,
205 arraysize(kFilteringTestCases)); 203 arraysize(kFilteringTestCases));
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 "CopySourceFiltering run %d test %" PRIuS, loop_count, i); 295 "CopySourceFiltering run %d test %" PRIuS, loop_count, i);
298 base::File::Error expectation = base::File::FILE_OK; 296 base::File::Error expectation = base::File::FILE_OK;
299 if (loop_count == 0 || !kFilteringTestCases[i].visible) { 297 if (loop_count == 0 || !kFilteringTestCases[i].visible) {
300 // If the source does not exist or is not visible. 298 // If the source does not exist or is not visible.
301 expectation = base::File::FILE_ERROR_NOT_FOUND; 299 expectation = base::File::FILE_ERROR_NOT_FOUND;
302 } else if (!kFilteringTestCases[i].is_directory) { 300 } else if (!kFilteringTestCases[i].is_directory) {
303 // Cannot copy a visible file to a directory. 301 // Cannot copy a visible file to a directory.
304 expectation = base::File::FILE_ERROR_INVALID_OPERATION; 302 expectation = base::File::FILE_ERROR_INVALID_OPERATION;
305 } 303 }
306 operation_runner()->Copy( 304 operation_runner()->Copy(
307 url, dest_url, 305 url,
308 fileapi::FileSystemOperation::OPTION_NONE, 306 dest_url,
309 fileapi::FileSystemOperationRunner::CopyProgressCallback(), 307 storage::FileSystemOperation::OPTION_NONE,
308 storage::FileSystemOperationRunner::CopyProgressCallback(),
310 base::Bind(&ExpectEqHelper, test_name, expectation)); 309 base::Bind(&ExpectEqHelper, test_name, expectation));
311 base::MessageLoop::current()->RunUntilIdle(); 310 base::MessageLoop::current()->RunUntilIdle();
312 } 311 }
313 } 312 }
314 } 313 }
315 314
316 TEST_F(NativeMediaFileUtilTest, CopyDestFiltering) { 315 TEST_F(NativeMediaFileUtilTest, CopyDestFiltering) {
317 // Run the loop twice. The first run has no destination files. 316 // Run the loop twice. The first run has no destination files.
318 // The second run does. 317 // The second run does.
319 for (int loop_count = 0; loop_count < 2; ++loop_count) { 318 for (int loop_count = 0; loop_count < 2; ++loop_count) {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 expectation = base::File::FILE_ERROR_SECURITY; 361 expectation = base::File::FILE_ERROR_SECURITY;
363 } else if (kFilteringTestCases[i].is_directory) { 362 } else if (kFilteringTestCases[i].is_directory) {
364 // Cannot copy a file to a directory. 363 // Cannot copy a file to a directory.
365 expectation = base::File::FILE_ERROR_INVALID_OPERATION; 364 expectation = base::File::FILE_ERROR_INVALID_OPERATION;
366 } else { 365 } else {
367 // Copying from a file to a visible file that exists is ok. 366 // Copying from a file to a visible file that exists is ok.
368 expectation = base::File::FILE_OK; 367 expectation = base::File::FILE_OK;
369 } 368 }
370 } 369 }
371 operation_runner()->Copy( 370 operation_runner()->Copy(
372 src_url, url, 371 src_url,
373 fileapi::FileSystemOperation::OPTION_NONE, 372 url,
374 fileapi::FileSystemOperationRunner::CopyProgressCallback(), 373 storage::FileSystemOperation::OPTION_NONE,
374 storage::FileSystemOperationRunner::CopyProgressCallback(),
375 base::Bind(&ExpectEqHelper, test_name, expectation)); 375 base::Bind(&ExpectEqHelper, test_name, expectation));
376 base::MessageLoop::current()->RunUntilIdle(); 376 base::MessageLoop::current()->RunUntilIdle();
377 } 377 }
378 } 378 }
379 } 379 }
380 380
381 TEST_F(NativeMediaFileUtilTest, MoveSourceFiltering) { 381 TEST_F(NativeMediaFileUtilTest, MoveSourceFiltering) {
382 base::FilePath dest_path = root_path().AppendASCII("dest"); 382 base::FilePath dest_path = root_path().AppendASCII("dest");
383 FileSystemURL dest_url = CreateURL(FPL("dest")); 383 FileSystemURL dest_url = CreateURL(FPL("dest"));
384 384
(...skipping 17 matching lines...) Expand all
402 "MoveSourceFiltering run %d test %" PRIuS, loop_count, i); 402 "MoveSourceFiltering run %d test %" PRIuS, loop_count, i);
403 base::File::Error expectation = base::File::FILE_OK; 403 base::File::Error expectation = base::File::FILE_OK;
404 if (loop_count == 0 || !kFilteringTestCases[i].visible) { 404 if (loop_count == 0 || !kFilteringTestCases[i].visible) {
405 // If the source does not exist or is not visible. 405 // If the source does not exist or is not visible.
406 expectation = base::File::FILE_ERROR_NOT_FOUND; 406 expectation = base::File::FILE_ERROR_NOT_FOUND;
407 } else if (!kFilteringTestCases[i].is_directory) { 407 } else if (!kFilteringTestCases[i].is_directory) {
408 // Cannot move a visible file to a directory. 408 // Cannot move a visible file to a directory.
409 expectation = base::File::FILE_ERROR_INVALID_OPERATION; 409 expectation = base::File::FILE_ERROR_INVALID_OPERATION;
410 } 410 }
411 operation_runner()->Move( 411 operation_runner()->Move(
412 url, dest_url, fileapi::FileSystemOperation::OPTION_NONE, 412 url,
413 dest_url,
414 storage::FileSystemOperation::OPTION_NONE,
413 base::Bind(&ExpectEqHelper, test_name, expectation)); 415 base::Bind(&ExpectEqHelper, test_name, expectation));
414 base::MessageLoop::current()->RunUntilIdle(); 416 base::MessageLoop::current()->RunUntilIdle();
415 } 417 }
416 } 418 }
417 } 419 }
418 420
419 TEST_F(NativeMediaFileUtilTest, MoveDestFiltering) { 421 TEST_F(NativeMediaFileUtilTest, MoveDestFiltering) {
420 // Run the loop twice. The first run has no destination files. 422 // Run the loop twice. The first run has no destination files.
421 // The second run does. 423 // The second run does.
422 for (int loop_count = 0; loop_count < 2; ++loop_count) { 424 for (int loop_count = 0; loop_count < 2; ++loop_count) {
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
467 expectation = base::File::FILE_ERROR_SECURITY; 469 expectation = base::File::FILE_ERROR_SECURITY;
468 } else if (kFilteringTestCases[i].is_directory) { 470 } else if (kFilteringTestCases[i].is_directory) {
469 // Cannot move a file to a directory. 471 // Cannot move a file to a directory.
470 expectation = base::File::FILE_ERROR_INVALID_OPERATION; 472 expectation = base::File::FILE_ERROR_INVALID_OPERATION;
471 } else { 473 } else {
472 // Moving from a file to a visible file that exists is ok. 474 // Moving from a file to a visible file that exists is ok.
473 expectation = base::File::FILE_OK; 475 expectation = base::File::FILE_OK;
474 } 476 }
475 } 477 }
476 operation_runner()->Move( 478 operation_runner()->Move(
477 src_url, url, fileapi::FileSystemOperation::OPTION_NONE, 479 src_url,
480 url,
481 storage::FileSystemOperation::OPTION_NONE,
478 base::Bind(&ExpectEqHelper, test_name, expectation)); 482 base::Bind(&ExpectEqHelper, test_name, expectation));
479 base::MessageLoop::current()->RunUntilIdle(); 483 base::MessageLoop::current()->RunUntilIdle();
480 } 484 }
481 } 485 }
482 } 486 }
483 487
484 TEST_F(NativeMediaFileUtilTest, GetMetadataFiltering) { 488 TEST_F(NativeMediaFileUtilTest, GetMetadataFiltering) {
485 // Run the loop twice. The first run has no files. The second run does. 489 // Run the loop twice. The first run has no files. The second run does.
486 for (int loop_count = 0; loop_count < 2; ++loop_count) { 490 for (int loop_count = 0; loop_count < 2; ++loop_count) {
487 if (loop_count == 1) { 491 if (loop_count == 1) {
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
537 base::MessageLoop::current()->RunUntilIdle(); 541 base::MessageLoop::current()->RunUntilIdle();
538 } 542 }
539 } 543 }
540 } 544 }
541 545
542 void CreateSnapshotCallback( 546 void CreateSnapshotCallback(
543 base::File::Error* error, 547 base::File::Error* error,
544 base::File::Error result, 548 base::File::Error result,
545 const base::File::Info&, 549 const base::File::Info&,
546 const base::FilePath&, 550 const base::FilePath&,
547 const scoped_refptr<webkit_blob::ShareableFileReference>&) { 551 const scoped_refptr<storage::ShareableFileReference>&) {
548 *error = result; 552 *error = result;
549 } 553 }
550 554
551 TEST_F(NativeMediaFileUtilTest, CreateSnapshot) { 555 TEST_F(NativeMediaFileUtilTest, CreateSnapshot) {
552 PopulateDirectoryWithTestCases(root_path(), 556 PopulateDirectoryWithTestCases(root_path(),
553 kFilteringTestCases, 557 kFilteringTestCases,
554 arraysize(kFilteringTestCases)); 558 arraysize(kFilteringTestCases));
555 for (size_t i = 0; i < arraysize(kFilteringTestCases); ++i) { 559 for (size_t i = 0; i < arraysize(kFilteringTestCases); ++i) {
556 if (kFilteringTestCases[i].is_directory || 560 if (kFilteringTestCases[i].is_directory ||
557 !kFilteringTestCases[i].visible) { 561 !kFilteringTestCases[i].visible) {
558 continue; 562 continue;
559 } 563 }
560 FileSystemURL root_url = CreateURL(FPL("")); 564 FileSystemURL root_url = CreateURL(FPL(""));
561 FileSystemURL url = CreateURL(kFilteringTestCases[i].path); 565 FileSystemURL url = CreateURL(kFilteringTestCases[i].path);
562 base::File::Error expected_error, error; 566 base::File::Error expected_error, error;
563 if (kFilteringTestCases[i].media_file) 567 if (kFilteringTestCases[i].media_file)
564 expected_error = base::File::FILE_OK; 568 expected_error = base::File::FILE_OK;
565 else 569 else
566 expected_error = base::File::FILE_ERROR_SECURITY; 570 expected_error = base::File::FILE_ERROR_SECURITY;
567 error = base::File::FILE_ERROR_FAILED; 571 error = base::File::FILE_ERROR_FAILED;
568 operation_runner()->CreateSnapshotFile(url, 572 operation_runner()->CreateSnapshotFile(url,
569 base::Bind(CreateSnapshotCallback, &error)); 573 base::Bind(CreateSnapshotCallback, &error));
570 base::MessageLoop::current()->RunUntilIdle(); 574 base::MessageLoop::current()->RunUntilIdle();
571 ASSERT_EQ(expected_error, error); 575 ASSERT_EQ(expected_error, error);
572 } 576 }
573 } 577 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698