Home | History | Annotate | Download | only in test
      1 // Copyright 2014 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #ifndef CONTENT_PUBLIC_TEST_ASYNC_FILE_TEST_HELPER_H_
      6 #define CONTENT_PUBLIC_TEST_ASYNC_FILE_TEST_HELPER_H_
      7 
      8 #include "base/basictypes.h"
      9 #include "webkit/browser/fileapi/file_system_operation.h"
     10 #include "webkit/common/fileapi/file_system_types.h"
     11 #include "webkit/common/quota/quota_status_code.h"
     12 
     13 namespace quota {
     14 class QuotaManager;
     15 }
     16 
     17 namespace fileapi {
     18 class FileSystemContext;
     19 class FileSystemURL;
     20 }
     21 
     22 namespace content {
     23 
     24 // A helper class to perform async file operations in a synchronous way.
     25 class AsyncFileTestHelper {
     26  public:
     27   typedef fileapi::FileSystemOperation::FileEntryList FileEntryList;
     28   typedef fileapi::FileSystemOperation::CopyProgressCallback
     29       CopyProgressCallback;
     30 
     31   static const int64 kDontCheckSize;
     32 
     33   // Performs Copy from |src| to |dest| and returns the status code.
     34   static base::File::Error Copy(fileapi::FileSystemContext* context,
     35                                 const fileapi::FileSystemURL& src,
     36                                 const fileapi::FileSystemURL& dest);
     37 
     38   // Same as Copy, but this supports |progress_callback|.
     39   static base::File::Error CopyWithProgress(
     40       fileapi::FileSystemContext* context,
     41       const fileapi::FileSystemURL& src,
     42       const fileapi::FileSystemURL& dest,
     43       const CopyProgressCallback& progress_callback);
     44 
     45   // Performs Move from |src| to |dest| and returns the status code.
     46   static base::File::Error Move(fileapi::FileSystemContext* context,
     47                                 const fileapi::FileSystemURL& src,
     48                                 const fileapi::FileSystemURL& dest);
     49 
     50   // Removes the given |url|.
     51   static base::File::Error Remove(fileapi::FileSystemContext* context,
     52                                   const fileapi::FileSystemURL& url,
     53                                         bool recursive);
     54 
     55   // Performs ReadDirectory on |url|.
     56   static base::File::Error ReadDirectory(fileapi::FileSystemContext* context,
     57                                          const fileapi::FileSystemURL& url,
     58                                          FileEntryList* entries);
     59 
     60   // Creates a directory at |url|.
     61   static base::File::Error CreateDirectory(fileapi::FileSystemContext* context,
     62                                            const fileapi::FileSystemURL& url);
     63 
     64   // Creates a file at |url|.
     65   static base::File::Error CreateFile(fileapi::FileSystemContext* context,
     66                                       const fileapi::FileSystemURL& url);
     67 
     68   // Creates a file at |url| and fills with |buf|.
     69   static base::File::Error CreateFileWithData(
     70       fileapi::FileSystemContext* context,
     71       const fileapi::FileSystemURL& url,
     72       const char* buf,
     73       int buf_size);
     74 
     75   // Truncates the file |url| to |size|.
     76   static base::File::Error TruncateFile(fileapi::FileSystemContext* context,
     77                                         const fileapi::FileSystemURL& url,
     78                                         size_t size);
     79 
     80   // Retrieves File::Info for |url| and populates |file_info|.
     81   static base::File::Error GetMetadata(fileapi::FileSystemContext* context,
     82                                        const fileapi::FileSystemURL& url,
     83                                        base::File::Info* file_info);
     84 
     85   // Retrieves FilePath for |url| and populates |platform_path|.
     86   static base::File::Error GetPlatformPath(fileapi::FileSystemContext* context,
     87                                            const fileapi::FileSystemURL& url,
     88                                            base::FilePath* platform_path);
     89 
     90   // Returns true if a file exists at |url| with |size|. If |size| is
     91   // kDontCheckSize it doesn't check the file size (but just check its
     92   // existence).
     93   static bool FileExists(fileapi::FileSystemContext* context,
     94                          const fileapi::FileSystemURL& url,
     95                          int64 size);
     96 
     97   // Returns true if a directory exists at |url|.
     98   static bool DirectoryExists(fileapi::FileSystemContext* context,
     99                               const fileapi::FileSystemURL& url);
    100 
    101   // Returns usage and quota. It's valid to pass NULL to |usage| and/or |quota|.
    102   static quota::QuotaStatusCode GetUsageAndQuota(
    103       quota::QuotaManager* quota_manager,
    104       const GURL& origin,
    105       fileapi::FileSystemType type,
    106       int64* usage,
    107       int64* quota);
    108 };
    109 
    110 }  // namespace content
    111 
    112 #endif  // CONTENT_PUBLIC_TEST_ASYNC_FILE_TEST_HELPER_H_
    113